[PATCH] D156693: [clang][ASTImporter]Skip check depth of friend template parameter

2023-08-18 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky added a comment.

In D156693#4584657 , @balazske wrote:

> A simple test should be added to StructuralEquivalenceTest.cpp too to check 
> if ignore (and not ignore) depth works.
>
> I think this solution is not always correct, but is still an improvement.

As a friend template declaration, compared to the template class definition, 
the only difference is the depth of the `NonTypeTemplateParam`. If the template 
class definition is equivalent to the class in `From` context, there is no 
probelm. Otherwise, the friend template declaration is also can't equivalent  
to it. Because the friend template declaration is equivalent to its definition 
when ignore the depth. To make a counterexample, we should put the friend 
declaration in different depth, but they are all equivalent in these cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156693

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


[clang] df8d33f - [OpenMP][AMDGPU] Add "amdgpu-flat-work-group-size" for known thread counts

2023-08-18 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2023-08-18T21:47:57-07:00
New Revision: df8d33fa7a22df3be34da5c6837031d897fa479b

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

LOG: [OpenMP][AMDGPU] Add "amdgpu-flat-work-group-size" for known thread counts

If we know the thread count statically and it is a constant, we can set
the "amdgpu-flat-work-group-size" kernel attribute.

Fixes https://github.com/llvm/llvm-project/issues/64816 in parts.

Added: 


Modified: 
clang/test/OpenMP/amdgcn-attributes.cpp
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Removed: 




diff  --git a/clang/test/OpenMP/amdgcn-attributes.cpp 
b/clang/test/OpenMP/amdgcn-attributes.cpp
index 46c8c53b47b53d..5ddc34537d12fb 100644
--- a/clang/test/OpenMP/amdgcn-attributes.cpp
+++ b/clang/test/OpenMP/amdgcn-attributes.cpp
@@ -19,7 +19,7 @@ int func() {
 
   int arr[N];
 
-#pragma omp target
+#pragma omp target teams thread_limit(42)
   for (int i = 0; i < N; i++) {
 arr[i] = callable(arr[i]);
   }
@@ -28,16 +28,16 @@ int func() {
 }
 
 int callable(int x) {
-  // ALL-LABEL: @_Z8callablei(i32 noundef %x) #1
+  // ALL-LABEL: @_Z8callablei(i32 noundef %x) #2
   return x + 1;
 }
 
-// DEFAULT: attributes #0 = { convergent mustprogress noinline norecurse 
nounwind optnone "kernel" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
-// CPU: attributes #0 = { convergent mustprogress noinline norecurse nounwind 
optnone "kernel" "no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 "uniform-work-group-size"="true" }
-// NOIEEE: attributes #0 = { convergent mustprogress noinline norecurse 
nounwind optnone "amdgpu-ieee"="false" "kernel" "no-nans-fp-math"="true" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="true" }
-// UNSAFEATOMIC: attributes #0 = { convergent mustprogress noinline norecurse 
nounwind optnone "amdgpu-unsafe-fp-atomics"="true" "kernel" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="true" }
+// DEFAULT: attributes #0 = { convergent mustprogress noinline norecurse 
nounwind optnone "amdgpu-flat-work-group-size"="1,42" "kernel" 
"no-trapping-math"="true" "omp_target_thread_limit"="42" 
"stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
+// CPU: attributes #0 = { convergent mustprogress noinline norecurse nounwind 
optnone "amdgpu-flat-work-group-size"="1,42" "kernel" "no-trapping-math"="true" 
"omp_target_thread_limit"="42" "stack-protector-buffer-size"="8" 
"target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 "uniform-work-group-size"="true" }
+// NOIEEE: attributes #0 = { convergent mustprogress noinline norecurse 
nounwind optnone "amdgpu-flat-work-group-size"="1,42" "amdgpu-ieee"="false" 
"kernel" "no-nans-fp-math"="true" "no-trapping-math"="true" 
"omp_target_thread_limit"="42" "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="true" }
+// UNSAFEATOMIC: attributes #0 = { convergent mustprogress noinline norecurse 
nounwind optnone "amdgpu-flat-work-group-size"="1,42" 
"amdgpu-unsafe-fp-atomics"="true" "kernel" "no-trapping-math"="true" 
"omp_target_thread_limit"="42" "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="true" }
 
-// DEFAULT: attributes #1 = { convergent mustprogress noinline nounwind 
optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
-// CPU: attributes #1 = { convergent mustprogress noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }
-// NOIEEE: attributes #1 = { convergent mustprogress noinline nounwind optnone 
"amdgpu-ieee"="false" "no-nans-fp-math"="true" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }
-// UNSAFEATOMIC: attributes #1 = { convergent mustprogress noinline nounwind 
optnone "amdgpu-unsafe-fp-atomics"="true" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" }
+// DEFAULT: attributes #2 = { convergent mustprogress noinline nounwind 
optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+// CPU: attributes #2 = { convergent mustprogress noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }
+// NOIEEE: attributes #2 = { convergent mustprogress noinline 

[PATCH] D158247: [CUDA][HIP] Fix overloading resolution in global variable initializer

2023-08-18 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 551705.
yaxunl marked 3 inline comments as done.
yaxunl added a comment.

revised by comments


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

https://reviews.llvm.org/D158247

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenCUDA/global-initializers.cu
  clang/test/SemaCUDA/amdgpu-windows-vectorcall.cu
  clang/test/SemaCUDA/function-overload.cu
  clang/test/SemaCUDA/global-initializers-host.cu
  clang/test/SemaCUDA/global-initializers.cu

Index: clang/test/SemaCUDA/global-initializers.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/global-initializers.cu
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 %s -triple x86_64-linux-unknown -fsyntax-only -o - -verify
+// RUN: %clang_cc1 %s -fcuda-is-device -triple nvptx -fsyntax-only -o - -verify
+
+#include "Inputs/cuda.h"
+
+// Check that we get an error if we try to call a __device__ function from a
+// module initializer.
+
+struct S {
+  // expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided}}
+  // expected-note@-2 {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 0 were provided}}
+  __device__ S() {}
+  // expected-note@-1 {{candidate constructor not viable: call to __device__ function from __host__ function}}
+};
+
+S s;
+// expected-error@-1 {{no matching constructor for initialization of 'S'}}
+
+struct T {
+  __host__ __device__ T() {}
+};
+T t;  // No error, this is OK.
+
+struct U {
+  // expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const U' for 1st argument}}
+  // expected-note@-2 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'U' for 1st argument}}
+  __host__ U() {}
+  // expected-note@-1 {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
+  __device__ U(int) {}
+  // expected-note@-1 {{candidate constructor not viable: call to __device__ function from __host__ function}}
+};
+U u(42);
+// expected-error@-1 {{no matching constructor for initialization of 'U'}}
+
+__device__ int device_fn() { return 42; }
+// expected-note@-1 {{candidate function not viable: call to __device__ function from __host__ function}}
+int n = device_fn();
+// expected-error@-1 {{no matching function for call to 'device_fn'}}
+
+// Check host/device-based overloding resolution in global variable initializer.
+double pow(double, double);
+
+__device__ double pow(double, int);
+
+double X = pow(1.0, 1);
+__device__ double Y = pow(2.0, 2); // expected-error{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+
+constexpr double cpow(double, double) { return 1.0; }
+
+constexpr __device__ double cpow(double, int) { return 2.0; }
+
+const double CX = cpow(1.0, 1);
+const __device__ double CY = cpow(2.0, 2);
+
+struct A {
+  double pow(double, double);
+
+  __device__ double pow(double, int);
+
+  constexpr double cpow(double, double) const { return 1.0; }
+
+  constexpr __device__ double cpow(double, int) const { return 1.0; }
+
+};
+
+A a;
+double AX = a.pow(1.0, 1);
+__device__ double AY = a.pow(2.0, 2); // expected-error{{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+
+const A ca;
+const double CAX = ca.cpow(1.0, 1);
+const __device__ double CAY = ca.cpow(2.0, 2);
Index: clang/test/SemaCUDA/global-initializers-host.cu
===
--- clang/test/SemaCUDA/global-initializers-host.cu
+++ /dev/null
@@ -1,32 +0,0 @@
-// RUN: %clang_cc1 %s --std=c++11 -triple x86_64-linux-unknown -fsyntax-only -o - -verify
-
-#include "Inputs/cuda.h"
-
-// Check that we get an error if we try to call a __device__ function from a
-// module initializer.
-
-struct S {
-  __device__ S() {}
-  // expected-note@-1 {{'S' declared here}}
-};
-
-S s;
-// expected-error@-1 {{reference to __device__ function 'S' in global initializer}}
-
-struct T {
-  __host__ __device__ T() {}
-};
-T t;  // No error, this is OK.
-
-struct U {
-  __host__ U() {}
-  __device__ U(int) {}
-  // expected-note@-1 {{'U' declared here}}
-};
-U u(42);
-// expected-error@-1 {{reference to __device__ function 'U' in global initializer}}
-
-__device__ int device_fn() { return 42; }
-// expected-note@-1 {{'device_fn' declared here}}
-int n = device_fn();
-// expected-error@-1 {{reference to __device__ function 'device_fn' in global initializer}}
Index: clang/test/SemaCUDA/function-overload.cu
===
--- clang/test/SemaCUDA/function-overload.cu
+++ 

[libunwind] 22a8402 - MIPS: unwind, don't save/restore hi/lo for R6

2023-08-18 Thread Brad Smith via cfe-commits

Author: YunQiang Su
Date: 2023-08-19T00:35:25-04:00
New Revision: 22a84020d2324ac1f753705497a40c43d8284d94

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

LOG: MIPS: unwind, don't save/restore hi/lo for R6

HI/LO registers have been removed in MIPSr6. Save and restore them only for 
pre-R6.

We keep the memory space for the registers so that we can use the same register 
indexes for
r6 and pre-r6.

Fixes: #60682

Reviewed By: compnerd

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

Added: 


Modified: 
libunwind/include/libunwind.h
libunwind/src/Registers.hpp
libunwind/src/UnwindRegistersRestore.S
libunwind/src/UnwindRegistersSave.S

Removed: 




diff  --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index d2ad5ab8712273..b2dae8feed9a3b 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -876,6 +876,9 @@ enum {
   UNW_MIPS_F29 = 61,
   UNW_MIPS_F30 = 62,
   UNW_MIPS_F31 = 63,
+  // HI,LO have been dropped since r6, we keep them here.
+  // So, when we add DSP/MSA etc, we can use the same register indexes
+  // for r6 and pre-r6.
   UNW_MIPS_HI = 64,
   UNW_MIPS_LO = 65,
 };

diff  --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index c7b875d74ae3c6..fb6e04e50fa1c7 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -2869,7 +2869,7 @@ inline bool Registers_mips_o32::validRegister(int regNum) 
const {
 return false;
   if (regNum <= UNW_MIPS_R31)
 return true;
-#if __mips_isa_rev != 6
+#if __mips_isa_rev < 6
   if (regNum == UNW_MIPS_HI)
 return true;
   if (regNum == UNW_MIPS_LO)
@@ -2903,10 +2903,12 @@ inline uint32_t Registers_mips_o32::getRegister(int 
regNum) const {
 return _registers.__pc;
   case UNW_REG_SP:
 return _registers.__r[29];
+#if __mips_isa_rev < 6
   case UNW_MIPS_HI:
 return _registers.__hi;
   case UNW_MIPS_LO:
 return _registers.__lo;
+#endif
   }
   _LIBUNWIND_ABORT("unsupported mips_o32 register");
 }
@@ -2936,11 +2938,13 @@ inline void Registers_mips_o32::setRegister(int regNum, 
uint32_t value) {
   case UNW_REG_SP:
 _registers.__r[29] = value;
 return;
+#if __mips_isa_rev < 6
   case UNW_MIPS_HI:
 _registers.__hi = value;
 return;
   case UNW_MIPS_LO:
 _registers.__lo = value;
+#endif
 return;
   }
   _LIBUNWIND_ABORT("unsupported mips_o32 register");
@@ -3120,10 +3124,12 @@ inline const char 
*Registers_mips_o32::getRegisterName(int regNum) {
 return "$f30";
   case UNW_MIPS_F31:
 return "$f31";
+#if __mips_isa_rev < 6
   case UNW_MIPS_HI:
 return "$hi";
   case UNW_MIPS_LO:
 return "$lo";
+#endif
   default:
 return "unknown register";
   }
@@ -3193,7 +3199,7 @@ inline bool Registers_mips_newabi::validRegister(int 
regNum) const {
 return false;
   if (regNum <= UNW_MIPS_R31)
 return true;
-#if __mips_isa_rev != 6
+#if __mips_isa_rev < 6
   if (regNum == UNW_MIPS_HI)
 return true;
   if (regNum == UNW_MIPS_LO)
@@ -3212,10 +3218,12 @@ inline uint64_t Registers_mips_newabi::getRegister(int 
regNum) const {
 return _registers.__pc;
   case UNW_REG_SP:
 return _registers.__r[29];
+#if __mips_isa_rev < 6
   case UNW_MIPS_HI:
 return _registers.__hi;
   case UNW_MIPS_LO:
 return _registers.__lo;
+#endif
   }
   _LIBUNWIND_ABORT("unsupported mips_newabi register");
 }
@@ -3233,12 +3241,14 @@ inline void Registers_mips_newabi::setRegister(int 
regNum, uint64_t value) {
   case UNW_REG_SP:
 _registers.__r[29] = value;
 return;
+#if __mips_isa_rev < 6
   case UNW_MIPS_HI:
 _registers.__hi = value;
 return;
   case UNW_MIPS_LO:
 _registers.__lo = value;
 return;
+#endif
   }
   _LIBUNWIND_ABORT("unsupported mips_newabi register");
 }
@@ -3417,10 +3427,12 @@ inline const char 
*Registers_mips_newabi::getRegisterName(int regNum) {
 return "$f30";
   case UNW_MIPS_F31:
 return "$f31";
+#if __mips_isa_rev < 6
   case UNW_MIPS_HI:
 return "$hi";
   case UNW_MIPS_LO:
 return "$lo";
+#endif
   default:
 return "unknown register";
   }

diff  --git a/libunwind/src/UnwindRegistersRestore.S 
b/libunwind/src/UnwindRegistersRestore.S
index 951189ea54dd20..c4471eac73fffc 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -993,11 +993,13 @@ 
DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind18Registers_mips_o326jumptoEv)
   ldc1  $f31, (4 * 36 + 8 * 31)($4)
 #endif
 #endif
+#if __mips_isa_rev < 6
   // restore hi and lo
   lw$8, (4 * 33)($4)
   mthi  $8
   lw$8, (4 * 34)($4)
   mtlo  $8
+#endif
   // r0 is zero
   lw$1, (4 * 1)($4)
   lw$2, (4 * 2)($4)
@@ -1054,11 +1056,13 @@ 
DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind21Registers_mips_newabi6jumptoEv)
 ldc1 

[PATCH] D158247: [CUDA][HIP] Fix overloading resolution in global variable initializer

2023-08-18 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 3 inline comments as done.
yaxunl added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:4753
+  /// Otherwise, use \p D to determiine the host/device target.
   bool CheckCallingConvAttr(const ParsedAttr , CallingConv ,
+const FunctionDecl *FD = nullptr,

tra wrote:
> It appears that `Declarator D` here is only used as an attribute carrier used 
> to identify CUDA calling target.
> Should we pass `CudaTarget ContextTarget` instead and let the caller figure 
> out how to find it?
> 
> I'm just thinking that we're hardcoding just one specific way to find the 
> target, while there may potentially be more.
> The current way is OK, as we have just one use case at the moment.
> 
> 
will do



Comment at: clang/lib/Sema/SemaCUDA.cpp:137
+  // Code that lives outside a function gets the target from CurCUDATargetCtx.
+  if (D == nullptr) {
+return CurCUDATargetCtx.Target;

tra wrote:
> Style nit: no braces around single-statement body.
will fix



Comment at: clang/test/CodeGenCUDA/global-initializers.cu:11-12
+// Check host/device-based overloding resolution in global variable 
initializer.
+template
+T pow(T, U) { return 1.0; }
+

tra wrote:
> We don't really need templates to reproduce the issue. We just need a host 
> function with lower overloading priority. A function requiring type 
> conversion or with an additional default argument should do. E.g.  `float 
> pow(float, int); ` or `double X = pow(double, int, bool 
> lower_priority_host_overload=1);`
> 
> Removing template should unclutter the tests a bit.
> 
will do


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

https://reviews.llvm.org/D158247

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


[PATCH] D112921: [clang] Enable sized deallocation by default in C++14 onwards

2023-08-18 Thread Wang Pengcheng via Phabricator via cfe-commits
wangpc updated this revision to Diff 551702.
wangpc added a comment.

- Rebase.
- Remove abilist changes.
- Add clang-18.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112921

Files:
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/SizedDeallocation.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Driver/ToolChains/ZOS.cpp
  clang/test/AST/ast-dump-expr-json.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-stmt-json.cpp
  clang/test/Analysis/cxxnewexpr-callback.cpp
  
clang/test/CXX/basic/basic.stc/basic.stc.dynamic/basic.stc.dynamic.deallocation/p2.cpp
  clang/test/CXX/expr/expr.unary/expr.new/p14.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
  clang/test/CodeGenCXX/delete-two-arg.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/new.cpp
  clang/test/CodeGenCoroutines/coro-aligned-alloc-2.cpp
  clang/test/CodeGenCoroutines/coro-aligned-alloc.cpp
  clang/test/CodeGenCoroutines/coro-alloc.cpp
  clang/test/CodeGenCoroutines/coro-cleanup.cpp
  clang/test/CodeGenCoroutines/coro-dealloc.cpp
  clang/test/CodeGenCoroutines/coro-gro.cpp
  clang/test/CodeGenCoroutines/pr56919.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/PCH/cxx1z-aligned-alloc.cpp
  clang/test/SemaCXX/MicrosoftExtensions.cpp
  clang/test/SemaCXX/builtin-operator-new-delete.cpp
  clang/test/SemaCXX/cxx1y-sized-deallocation.cpp
  clang/test/SemaCXX/unavailable_aligned_allocation.cpp
  clang/unittests/StaticAnalyzer/CallEventTest.cpp
  clang/www/cxx_status.html
  libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp

Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
@@ -8,11 +8,13 @@
 
 // test sized operator delete replacement.
 
+// TODO(mordante) fix this test after updating clang in Docker
+// UNSUPPORTED: clang-15, clang-16, clang-17, clang-18
 // UNSUPPORTED: sanitizer-new-delete, c++03, c++11
+// XFAIL: apple-clang
 
-// NOTE: Clang does not enable sized-deallocation in C++14 and beyond by
-// default. It is only enabled when -fsized-deallocation is given.
-// XFAIL: clang, apple-clang
+// Sized deallocation was added in macOS 10.12 and aligned OSes.
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11}}
 
 #include 
 #include 
Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
@@ -8,11 +8,13 @@
 
 // test sized operator delete[] replacement.
 
+// TODO(mordante) fix this test after updating clang in Docker
+// UNSUPPORTED: clang-15, clang-16, clang-17, clang-18
 // UNSUPPORTED: sanitizer-new-delete, c++03, c++11
+// XFAIL: apple-clang
 
-// NOTE: Clang does not enable sized-deallocation in C++14 and beyond by
-// default. It is only enabled when -fsized-deallocation is given.
-// XFAIL: clang, apple-clang
+// Sized deallocation was added in macOS 10.12 and aligned OSes.
+// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11}}
 
 #include 
 #include 
Index: libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
===
--- libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
+++ libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp
@@ -25,6 +25,9 @@
 // GCC doesn't support the aligned-allocation flags.
 // XFAIL: gcc
 
+// TODO(mordante) fix this test after updating clang in Docker
+// UNSUPPORTED: clang-15, clang-16, clang-17, clang-18
+
 // RUN: %{build} -faligned-allocation -fsized-deallocation
 // RUN: %{run}
 // RUN: %{build} -faligned-allocation -fno-sized-deallocation -DNO_SIZE
Index: clang/www/cxx_status.html

[PATCH] D158329: [X86] Support arch=x86-64{,-v2,-v3,-v4} for target_clones attribute

2023-08-18 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:13277
+llvm::Value *
+CodeGenFunction::EmitX86CpuSupports(const uint32_t FeaturesMask[4]) {
   Value *Result = Builder.getTrue();

Can this be a std::array instead?  The C array is pretty meaningless here.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:13314
+  continue;
+if (!CpuFeatures2) {
+  CpuFeatures2 = CGM.CreateRuntimeVariable(ATy, "__cpu_features2");

Why is this in the loop?  Is there a good reason to not just always initialize 
it?  



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:2688
+if (Arch.consume_front("x86-64")) {
+  if (Arch.empty()) // FEATURE_X86_64_BASELINE 95=2*32+31
+Mask[2] = 1u << 31;

Can you clarify the comments here on these?  I'm a little confused by their 
meaning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158329

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


[PATCH] D158329: [X86] Support arch=x86-64{,-v2,-v3,-v4} for target/target_clones attributes

2023-08-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: craig.topper, FreddyYe, pengfei, RKSimon, skan.
Herald added subscribers: Enna1, hiraditya.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added projects: clang, Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits.

GCC 12 (https://gcc.gnu.org/PR101696) allows `arch=x86-64`
`arch=x86-64-v2` `arch=x86-64-v3` `arch=x86-64-v4` in target and
target_clones function attributes. This patch ports the feature.

- Set KeyFeature to `x86-64{,-v2,-v3,-v4}` in `Processors[]`, to be used by 
X86TargetInfo::multiVersionSortPriority
- builtins: change `__cpu_features2` to an array like libgcc. Define 
`FEATURE_X86_64_{BASELINE,V2,V3,V4}` and depended ISA feature bits.
- CGBuiltin.cpp: update EmitX86CpuSupports to handle `arch=x86-64*`.

Close https://github.com/llvm/llvm-project/issues/55830


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158329

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/attr-target-clones.c
  clang/test/CodeGen/builtin-cpu-supports.c
  clang/test/Sema/attr-target-clones.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/lib/TargetParser/X86TargetParser.cpp

Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -317,6 +317,7 @@
 // listed here before, which means it doesn't support -march, -mtune and so on.
 // FIXME: Remove OnlyForCPUDispatchSpecific after all CPUs here support both
 // cpu_dispatch/specific() feature and -march, -mtune, and so on.
+// clang-format off
 constexpr ProcInfo Processors[] = {
  // Empty processor. Include X87 and CMPXCHG8 for backwards compatibility.
   { {""}, CK_None, ~0U, FeatureX87 | FeatureCMPXCHG8B, '\0', false },
@@ -482,13 +483,14 @@
   { {"znver3"}, CK_ZNVER3, FEATURE_AVX2, FeaturesZNVER3, '\0', false },
   { {"znver4"}, CK_ZNVER4, FEATURE_AVX512VBMI2, FeaturesZNVER4, '\0', false },
   // Generic 64-bit processor.
-  { {"x86-64"}, CK_x86_64, ~0U, FeaturesX86_64, '\0', false },
-  { {"x86-64-v2"}, CK_x86_64_v2, ~0U, FeaturesX86_64_V2, '\0', false },
-  { {"x86-64-v3"}, CK_x86_64_v3, ~0U, FeaturesX86_64_V3, '\0', false },
-  { {"x86-64-v4"}, CK_x86_64_v4, ~0U, FeaturesX86_64_V4, '\0', false },
+  { {"x86-64"}, CK_x86_64, FEATURE_SSE2 , FeaturesX86_64, '\0', false },
+  { {"x86-64-v2"}, CK_x86_64_v2, FEATURE_SSE4_2 , FeaturesX86_64_V2, '\0', false },
+  { {"x86-64-v3"}, CK_x86_64_v3, FEATURE_AVX2, FeaturesX86_64_V3, '\0', false },
+  { {"x86-64-v4"}, CK_x86_64_v4, FEATURE_AVX512VL, FeaturesX86_64_V4, '\0', false },
   // Geode processors.
   { {"geode"}, CK_Geode, ~0U, FeaturesGeode, '\0', false },
 };
+// clang-format on
 
 constexpr const char *NoTuneList[] = {"x86-64-v2", "x86-64-v3", "x86-64-v4"};
 
Index: compiler-rt/lib/builtins/cpu_model.c
===
--- compiler-rt/lib/builtins/cpu_model.c
+++ compiler-rt/lib/builtins/cpu_model.c
@@ -158,6 +158,19 @@
   FEATURE_AVX512BITALG,
   FEATURE_AVX512BF16,
   FEATURE_AVX512VP2INTERSECT,
+
+  FEATURE_CMPXCHG16B = 46,
+  FEATURE_F16C = 49,
+  FEATURE_LAHF_LM = 54,
+  FEATURE_LM,
+  FEATURE_WP,
+  FEATURE_LZCNT = 57,
+  FEATURE_MOVBE,
+
+  FEATURE_X86_64_BASELINE = 95,
+  FEATURE_X86_64_V2,
+  FEATURE_X86_64_V3,
+  FEATURE_X86_64_V4,
   CPU_FEATURE_MAX
 };
 
@@ -675,6 +688,7 @@
  unsigned *Features) {
   unsigned EAX = 0, EBX = 0;
 
+#define hasFeature(F) ((Features[F / 32] >> (F % 32)) & 1)
 #define setFeature(F)  \
   Features[F / 32] |= 1U << (F % 32)
 
@@ -695,14 +709,20 @@
 setFeature(FEATURE_SSSE3);
   if ((ECX >> 12) & 1)
 setFeature(FEATURE_FMA);
+  if ((ECX >> 13) & 1)
+setFeature(FEATURE_CMPXCHG16B);
   if ((ECX >> 19) & 1)
 setFeature(FEATURE_SSE4_1);
   if ((ECX >> 20) & 1)
 setFeature(FEATURE_SSE4_2);
+  if ((ECX >> 22) & 1)
+setFeature(FEATURE_MOVBE);
   if ((ECX >> 23) & 1)
 setFeature(FEATURE_POPCNT);
   if ((ECX >> 25) & 1)
 setFeature(FEATURE_AES);
+  if ((ECX >> 29) & 1)
+setFeature(FEATURE_F16C);
 
   // If CPUID indicates support for XSAVE, XRESTORE and AVX, and XGETBV
   // indicates that the AVX registers will be saved and restored on context
@@ -784,12 +804,39 @@
 
   bool HasExtLeaf1 = MaxExtLevel >= 0x8001 &&
  !getX86CpuIDAndInfo(0x8001, , , , );
-  if (HasExtLeaf1 && ((ECX >> 6) & 1))
-setFeature(FEATURE_SSE4_A);
-  if (HasExtLeaf1 && ((ECX >> 11) & 1))
-setFeature(FEATURE_XOP);
-  if (HasExtLeaf1 && ((ECX >> 16) & 1))
-setFeature(FEATURE_FMA4);
+  if (HasExtLeaf1) {
+if (ECX & 1)
+  setFeature(FEATURE_LAHF_LM);
+if ((ECX >> 5) & 1)
+  setFeature(FEATURE_LZCNT);
+if (((ECX >> 

[PATCH] D158249: [clangd] Parameter hints for calls through function pointers

2023-08-18 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
nridge marked an inline comment as done.
Closed by commit rG8ee710a40cc5: [clangd] Parameter hints for calls through 
function pointers (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158249

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -919,6 +919,26 @@
   )cpp");
 }
 
+TEST(ParameterHints, FunctionPointer) {
+  assertParameterHints(
+  R"cpp(
+void (*f1)(int param);
+void (__stdcall *f2)(int param);
+using f3_t = void(*)(int param);
+f3_t f3;
+using f4_t = void(__stdcall *)(int param);
+f4_t f4;
+void bar() {
+  f1($f1[[42]]);
+  f2($f2[[42]]);
+  f3($f3[[42]]);
+  f4($f4[[42]]);
+}
+  )cpp",
+  ExpectedHint{"param: ", "f1"}, ExpectedHint{"param: ", "f2"},
+  ExpectedHint{"param: ", "f3"}, ExpectedHint{"param: ", "f4"});
+}
+
 TEST(ParameterHints, ArgMatchesParam) {
   assertParameterHints(R"cpp(
 void foo(int param);
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -485,6 +485,56 @@
   return QT;
 }
 
+// Given a callee expression `Fn`, if the call is through a function pointer,
+// try to find the declaration of the corresponding function pointer type,
+// so that we can recover argument names from it.
+// FIXME: This function is mostly duplicated in SemaCodeComplete.cpp; unify.
+static FunctionProtoTypeLoc getPrototypeLoc(Expr *Fn) {
+  TypeLoc Target;
+  Expr *NakedFn = Fn->IgnoreParenCasts();
+  if (const auto *T = NakedFn->getType().getTypePtr()->getAs()) {
+Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
+  } else if (const auto *DR = dyn_cast(NakedFn)) {
+const auto *D = DR->getDecl();
+if (const auto *const VD = dyn_cast(D)) {
+  Target = VD->getTypeSourceInfo()->getTypeLoc();
+}
+  }
+
+  if (!Target)
+return {};
+
+  // Unwrap types that may be wrapping the function type
+  while (true) {
+if (auto P = Target.getAs()) {
+  Target = P.getPointeeLoc();
+  continue;
+}
+if (auto A = Target.getAs()) {
+  Target = A.getModifiedLoc();
+  continue;
+}
+if (auto P = Target.getAs()) {
+  Target = P.getInnerLoc();
+  continue;
+}
+break;
+  }
+
+  if (auto F = Target.getAs()) {
+return F;
+  }
+
+  return {};
+}
+
+struct Callee {
+  // Only one of Decl or Loc is set.
+  // Loc is for calls through function pointers.
+  const FunctionDecl *Decl = nullptr;
+  FunctionProtoTypeLoc Loc;
+};
+
 class InlayHintVisitor : public RecursiveASTVisitor {
 public:
   InlayHintVisitor(std::vector , ParsedAST ,
@@ -524,7 +574,11 @@
   return true;
 }
 
-processCall(E->getConstructor(), {E->getArgs(), E->getNumArgs()});
+Callee Callee;
+Callee.Decl = E->getConstructor();
+if (!Callee.Decl)
+  return true;
+processCall(Callee, {E->getArgs(), E->getNumArgs()});
 return true;
   }
 
@@ -542,12 +596,15 @@
 auto CalleeDecls = Resolver->resolveCalleeOfCallExpr(E);
 if (CalleeDecls.size() != 1)
   return true;
-const FunctionDecl *Callee = nullptr;
+
+Callee Callee;
 if (const auto *FD = dyn_cast(CalleeDecls[0]))
-  Callee = FD;
+  Callee.Decl = FD;
 else if (const auto *FTD = dyn_cast(CalleeDecls[0]))
-  Callee = FTD->getTemplatedDecl();
-if (!Callee)
+  Callee.Decl = FTD->getTemplatedDecl();
+else if (FunctionProtoTypeLoc Loc = getPrototypeLoc(E->getCallee()))
+  Callee.Loc = Loc;
+else
   return true;
 
 processCall(Callee, {E->getArgs(), E->getNumArgs()});
@@ -762,25 +819,35 @@
 private:
   using NameVec = SmallVector;
 
-  void processCall(const FunctionDecl *Callee,
-   llvm::ArrayRef Args) {
-if (!Cfg.InlayHints.Parameters || Args.size() == 0 || !Callee)
+  void processCall(Callee Callee, llvm::ArrayRef Args) {
+assert(Callee.Decl || Callee.Loc);
+
+if (!Cfg.InlayHints.Parameters || Args.size() == 0)
   return;
 
 // The parameter name of a move or copy constructor is not very interesting.
-if (auto *Ctor = dyn_cast(Callee))
-  if (Ctor->isCopyOrMoveConstructor())
-return;
+if (Callee.Decl)
+  if (auto *Ctor = dyn_cast(Callee.Decl))
+if (Ctor->isCopyOrMoveConstructor())
+  return;
+
+auto Params =
+Callee.Decl ? Callee.Decl->parameters() : Callee.Loc.getParams();
 
 // Resolve 

[clang-tools-extra] 8ee710a - [clangd] Parameter hints for calls through function pointers

2023-08-18 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2023-08-18T23:40:59-04:00
New Revision: 8ee710a40cc51098e6d1249afe9af0e64150f308

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

LOG: [clangd] Parameter hints for calls through function pointers

Fixes https://github.com/clangd/clangd/issues/1734

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

Added: 


Modified: 
clang-tools-extra/clangd/InlayHints.cpp
clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index eaefe0850f9cff..d403269f5a68f4 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -485,6 +485,56 @@ QualType maybeDesugar(ASTContext , QualType QT) {
   return QT;
 }
 
+// Given a callee expression `Fn`, if the call is through a function pointer,
+// try to find the declaration of the corresponding function pointer type,
+// so that we can recover argument names from it.
+// FIXME: This function is mostly duplicated in SemaCodeComplete.cpp; unify.
+static FunctionProtoTypeLoc getPrototypeLoc(Expr *Fn) {
+  TypeLoc Target;
+  Expr *NakedFn = Fn->IgnoreParenCasts();
+  if (const auto *T = NakedFn->getType().getTypePtr()->getAs()) {
+Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
+  } else if (const auto *DR = dyn_cast(NakedFn)) {
+const auto *D = DR->getDecl();
+if (const auto *const VD = dyn_cast(D)) {
+  Target = VD->getTypeSourceInfo()->getTypeLoc();
+}
+  }
+
+  if (!Target)
+return {};
+
+  // Unwrap types that may be wrapping the function type
+  while (true) {
+if (auto P = Target.getAs()) {
+  Target = P.getPointeeLoc();
+  continue;
+}
+if (auto A = Target.getAs()) {
+  Target = A.getModifiedLoc();
+  continue;
+}
+if (auto P = Target.getAs()) {
+  Target = P.getInnerLoc();
+  continue;
+}
+break;
+  }
+
+  if (auto F = Target.getAs()) {
+return F;
+  }
+
+  return {};
+}
+
+struct Callee {
+  // Only one of Decl or Loc is set.
+  // Loc is for calls through function pointers.
+  const FunctionDecl *Decl = nullptr;
+  FunctionProtoTypeLoc Loc;
+};
+
 class InlayHintVisitor : public RecursiveASTVisitor {
 public:
   InlayHintVisitor(std::vector , ParsedAST ,
@@ -524,7 +574,11 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   return true;
 }
 
-processCall(E->getConstructor(), {E->getArgs(), E->getNumArgs()});
+Callee Callee;
+Callee.Decl = E->getConstructor();
+if (!Callee.Decl)
+  return true;
+processCall(Callee, {E->getArgs(), E->getNumArgs()});
 return true;
   }
 
@@ -542,12 +596,15 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 auto CalleeDecls = Resolver->resolveCalleeOfCallExpr(E);
 if (CalleeDecls.size() != 1)
   return true;
-const FunctionDecl *Callee = nullptr;
+
+Callee Callee;
 if (const auto *FD = dyn_cast(CalleeDecls[0]))
-  Callee = FD;
+  Callee.Decl = FD;
 else if (const auto *FTD = dyn_cast(CalleeDecls[0]))
-  Callee = FTD->getTemplatedDecl();
-if (!Callee)
+  Callee.Decl = FTD->getTemplatedDecl();
+else if (FunctionProtoTypeLoc Loc = getPrototypeLoc(E->getCallee()))
+  Callee.Loc = Loc;
+else
   return true;
 
 processCall(Callee, {E->getArgs(), E->getNumArgs()});
@@ -762,25 +819,35 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 private:
   using NameVec = SmallVector;
 
-  void processCall(const FunctionDecl *Callee,
-   llvm::ArrayRef Args) {
-if (!Cfg.InlayHints.Parameters || Args.size() == 0 || !Callee)
+  void processCall(Callee Callee, llvm::ArrayRef Args) {
+assert(Callee.Decl || Callee.Loc);
+
+if (!Cfg.InlayHints.Parameters || Args.size() == 0)
   return;
 
 // The parameter name of a move or copy constructor is not very 
interesting.
-if (auto *Ctor = dyn_cast(Callee))
-  if (Ctor->isCopyOrMoveConstructor())
-return;
+if (Callee.Decl)
+  if (auto *Ctor = dyn_cast(Callee.Decl))
+if (Ctor->isCopyOrMoveConstructor())
+  return;
+
+auto Params =
+Callee.Decl ? Callee.Decl->parameters() : Callee.Loc.getParams();
 
 // Resolve parameter packs to their forwarded parameter
-auto ForwardedParams = resolveForwardingParameters(Callee);
+SmallVector ForwardedParams;
+if (Callee.Decl)
+  ForwardedParams = resolveForwardingParameters(Callee.Decl);
+else
+  ForwardedParams = {Params.begin(), Params.end()};
 
 NameVec ParameterNames = chooseParameterNames(ForwardedParams);
 
 // Exclude setters (i.e. functions with one argument whose name begins with
 // "set"), and builtins like 

[PATCH] D158249: [clangd] Parameter hints for calls through function pointers

2023-08-18 Thread Nathan Ridge via Phabricator via cfe-commits
nridge marked an inline comment as done.
nridge added inline comments.



Comment at: clang-tools-extra/clangd/InlayHints.cpp:508
+  // Only one of Callee or ProtoTypeLoc is set.
+  const FunctionDecl *Callee = nullptr;
+  FunctionProtoTypeLoc ProtoTypeLoc;

sammccall wrote:
> Calling this "callee" confuses me a bit - originally the callee was an expr 
> and always present, so this must be a different idea: `CalleeDecl`?.
> 
> However I also think this struct has an unneccesarily broad scope: we're not 
> really gaining anything by bundling `Args` into it rather than continuing to 
> pass that as a separate param.
> This suggests:
> 
> ```
> struct Callee {
>   Decl *Declaration;
>   FunctionProtoTypeLoc Loc;
> };
> ```
Good point, updated


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158249

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


[PATCH] D158249: [clangd] Parameter hints for calls through function pointers

2023-08-18 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 551696.
nridge added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158249

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -910,6 +910,26 @@
   )cpp");
 }
 
+TEST(ParameterHints, FunctionPointer) {
+  assertParameterHints(
+  R"cpp(
+void (*f1)(int param);
+void (__stdcall *f2)(int param);
+using f3_t = void(*)(int param);
+f3_t f3;
+using f4_t = void(__stdcall *)(int param);
+f4_t f4;
+void bar() {
+  f1($f1[[42]]);
+  f2($f2[[42]]);
+  f3($f3[[42]]);
+  f4($f4[[42]]);
+}
+  )cpp",
+  ExpectedHint{"param: ", "f1"}, ExpectedHint{"param: ", "f2"},
+  ExpectedHint{"param: ", "f3"}, ExpectedHint{"param: ", "f4"});
+}
+
 TEST(ParameterHints, ArgMatchesParam) {
   assertParameterHints(R"cpp(
 void foo(int param);
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -460,6 +460,56 @@
   return QT;
 }
 
+// Given a callee expression `Fn`, if the call is through a function pointer,
+// try to find the declaration of the corresponding function pointer type,
+// so that we can recover argument names from it.
+// FIXME: This function is mostly duplicated in SemaCodeComplete.cpp; unify.
+static FunctionProtoTypeLoc getPrototypeLoc(Expr *Fn) {
+  TypeLoc Target;
+  Expr *NakedFn = Fn->IgnoreParenCasts();
+  if (const auto *T = NakedFn->getType().getTypePtr()->getAs()) {
+Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
+  } else if (const auto *DR = dyn_cast(NakedFn)) {
+const auto *D = DR->getDecl();
+if (const auto *const VD = dyn_cast(D)) {
+  Target = VD->getTypeSourceInfo()->getTypeLoc();
+}
+  }
+
+  if (!Target)
+return {};
+
+  // Unwrap types that may be wrapping the function type
+  while (true) {
+if (auto P = Target.getAs()) {
+  Target = P.getPointeeLoc();
+  continue;
+}
+if (auto A = Target.getAs()) {
+  Target = A.getModifiedLoc();
+  continue;
+}
+if (auto P = Target.getAs()) {
+  Target = P.getInnerLoc();
+  continue;
+}
+break;
+  }
+
+  if (auto F = Target.getAs()) {
+return F;
+  }
+
+  return {};
+}
+
+struct Callee {
+  // Only one of Decl or Loc is set.
+  // Loc is for calls through function pointers.
+  const FunctionDecl *Decl = nullptr;
+  FunctionProtoTypeLoc Loc;
+};
+
 class InlayHintVisitor : public RecursiveASTVisitor {
 public:
   InlayHintVisitor(std::vector , ParsedAST ,
@@ -499,7 +549,11 @@
   return true;
 }
 
-processCall(E->getConstructor(), {E->getArgs(), E->getNumArgs()});
+Callee Callee;
+Callee.Decl = E->getConstructor();
+if (!Callee.Decl)
+  return true;
+processCall(Callee, {E->getArgs(), E->getNumArgs()});
 return true;
   }
 
@@ -517,12 +571,15 @@
 auto CalleeDecls = Resolver->resolveCalleeOfCallExpr(E);
 if (CalleeDecls.size() != 1)
   return true;
-const FunctionDecl *Callee = nullptr;
+
+Callee Callee;
 if (const auto *FD = dyn_cast(CalleeDecls[0]))
-  Callee = FD;
+  Callee.Decl = FD;
 else if (const auto *FTD = dyn_cast(CalleeDecls[0]))
-  Callee = FTD->getTemplatedDecl();
-if (!Callee)
+  Callee.Decl = FTD->getTemplatedDecl();
+else if (FunctionProtoTypeLoc Loc = getPrototypeLoc(E->getCallee()))
+  Callee.Loc = Loc;
+else
   return true;
 
 processCall(Callee, {E->getArgs(), E->getNumArgs()});
@@ -737,25 +794,35 @@
 private:
   using NameVec = SmallVector;
 
-  void processCall(const FunctionDecl *Callee,
-   llvm::ArrayRef Args) {
-if (!Cfg.InlayHints.Parameters || Args.size() == 0 || !Callee)
+  void processCall(Callee Callee, llvm::ArrayRef Args) {
+assert(Callee.Decl || Callee.Loc);
+
+if (!Cfg.InlayHints.Parameters || Args.size() == 0)
   return;
 
 // The parameter name of a move or copy constructor is not very interesting.
-if (auto *Ctor = dyn_cast(Callee))
-  if (Ctor->isCopyOrMoveConstructor())
-return;
+if (Callee.Decl)
+  if (auto *Ctor = dyn_cast(Callee.Decl))
+if (Ctor->isCopyOrMoveConstructor())
+  return;
+
+auto Params =
+Callee.Decl ? Callee.Decl->parameters() : Callee.Loc.getParams();
 
 // Resolve parameter packs to their forwarded parameter
-auto ForwardedParams = resolveForwardingParameters(Callee);
+SmallVector ForwardedParams;
+if (Callee.Decl)
+  ForwardedParams = 

[PATCH] D149236: [clangd] Bail gracefully if given an assembly or IR source file

2023-08-18 Thread Nathan Ridge 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 rG744b111434b2: [clangd] Bail gracefully if given an assembly 
or IR source file (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149236

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp


Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -13,6 +13,7 @@
 
 #include "../../clang-tidy/ClangTidyCheck.h"
 #include "AST.h"
+#include "CompileCommands.h"
 #include "Compiler.h"
 #include "Config.h"
 #include "Diagnostics.h"
@@ -731,6 +732,37 @@
   pragmaTrivia(" End")));
 }
 
+TEST(ParsedASTTest, GracefulFailureOnAssemblyFile) {
+  std::string Filename = "TestTU.S";
+  std::string Code = R"S(
+main:
+# test comment
+bx lr
+  )S";
+
+  // The rest is a simplified version of TestTU::build().
+  // Don't call TestTU::build() itself because it would assert on
+  // failure to build an AST.
+  MockFS FS;
+  std::string FullFilename = testPath(Filename);
+  FS.Files[FullFilename] = Code;
+  ParseInputs Inputs;
+  auto  = Inputs.CompileCommand.CommandLine;
+  Argv = {"clang"};
+  Argv.push_back(FullFilename);
+  Inputs.CompileCommand.Filename = FullFilename;
+  Inputs.CompileCommand.Directory = testRoot();
+  Inputs.Contents = Code;
+  Inputs.TFS = 
+  StoreDiags Diags;
+  auto CI = buildCompilerInvocation(Inputs, Diags);
+  assert(CI && "Failed to build compilation invocation.");
+  auto AST = ParsedAST::build(FullFilename, Inputs, std::move(CI), {}, 
nullptr);
+
+  EXPECT_FALSE(AST.has_value())
+  << "Should not try to build AST for assembly source file";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -396,6 +396,15 @@
 VFS = Preamble->StatCache->getConsumingFS(std::move(VFS));
 
   assert(CI);
+
+  if (CI->getFrontendOpts().Inputs.size() > 0) {
+auto Lang = CI->getFrontendOpts().Inputs[0].getKind().getLanguage();
+if (Lang == Language::Asm || Lang == Language::LLVM_IR) {
+  elog("Clangd does not support assembly or IR source files");
+  return std::nullopt;
+}
+  }
+
   // Command-line parsing sets DisableFree to true by default, but we don't 
want
   // to leak memory in clangd.
   CI->getFrontendOpts().DisableFree = false;


Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -13,6 +13,7 @@
 
 #include "../../clang-tidy/ClangTidyCheck.h"
 #include "AST.h"
+#include "CompileCommands.h"
 #include "Compiler.h"
 #include "Config.h"
 #include "Diagnostics.h"
@@ -731,6 +732,37 @@
   pragmaTrivia(" End")));
 }
 
+TEST(ParsedASTTest, GracefulFailureOnAssemblyFile) {
+  std::string Filename = "TestTU.S";
+  std::string Code = R"S(
+main:
+# test comment
+bx lr
+  )S";
+
+  // The rest is a simplified version of TestTU::build().
+  // Don't call TestTU::build() itself because it would assert on
+  // failure to build an AST.
+  MockFS FS;
+  std::string FullFilename = testPath(Filename);
+  FS.Files[FullFilename] = Code;
+  ParseInputs Inputs;
+  auto  = Inputs.CompileCommand.CommandLine;
+  Argv = {"clang"};
+  Argv.push_back(FullFilename);
+  Inputs.CompileCommand.Filename = FullFilename;
+  Inputs.CompileCommand.Directory = testRoot();
+  Inputs.Contents = Code;
+  Inputs.TFS = 
+  StoreDiags Diags;
+  auto CI = buildCompilerInvocation(Inputs, Diags);
+  assert(CI && "Failed to build compilation invocation.");
+  auto AST = ParsedAST::build(FullFilename, Inputs, std::move(CI), {}, nullptr);
+
+  EXPECT_FALSE(AST.has_value())
+  << "Should not try to build AST for assembly source file";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -396,6 +396,15 @@
 VFS = Preamble->StatCache->getConsumingFS(std::move(VFS));
 
   assert(CI);
+
+  if (CI->getFrontendOpts().Inputs.size() > 0) {
+auto Lang = CI->getFrontendOpts().Inputs[0].getKind().getLanguage();
+if (Lang == Language::Asm || Lang == Language::LLVM_IR) {
+  elog("Clangd does not support assembly or IR source 

[clang-tools-extra] 744b111 - [clangd] Bail gracefully if given an assembly or IR source file

2023-08-18 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2023-08-18T23:26:32-04:00
New Revision: 744b111434b25b1259308050c59062dc4f38a589

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

LOG: [clangd] Bail gracefully if given an assembly or IR source file

The previous behaviour is to try to parse such files, and in some
cases assert or hang in components that don't expect these forms of
input, like TokenBuffer.

Fixes https://github.com/llvm/llvm-project/issues/62090

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

Added: 


Modified: 
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index 81cfe8bb60b3e0..3cf6671be9600e 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -396,6 +396,15 @@ ParsedAST::build(llvm::StringRef Filename, const 
ParseInputs ,
 VFS = Preamble->StatCache->getConsumingFS(std::move(VFS));
 
   assert(CI);
+
+  if (CI->getFrontendOpts().Inputs.size() > 0) {
+auto Lang = CI->getFrontendOpts().Inputs[0].getKind().getLanguage();
+if (Lang == Language::Asm || Lang == Language::LLVM_IR) {
+  elog("Clangd does not support assembly or IR source files");
+  return std::nullopt;
+}
+  }
+
   // Command-line parsing sets DisableFree to true by default, but we don't 
want
   // to leak memory in clangd.
   CI->getFrontendOpts().DisableFree = false;

diff  --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp 
b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
index b0d5bea1d3279e..ec8132645f81fb 100644
--- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -13,6 +13,7 @@
 
 #include "../../clang-tidy/ClangTidyCheck.h"
 #include "AST.h"
+#include "CompileCommands.h"
 #include "Compiler.h"
 #include "Config.h"
 #include "Diagnostics.h"
@@ -731,6 +732,37 @@ TEST(ParsedASTTest, DiscoversPragmaMarks) {
   pragmaTrivia(" End")));
 }
 
+TEST(ParsedASTTest, GracefulFailureOnAssemblyFile) {
+  std::string Filename = "TestTU.S";
+  std::string Code = R"S(
+main:
+# test comment
+bx lr
+  )S";
+
+  // The rest is a simplified version of TestTU::build().
+  // Don't call TestTU::build() itself because it would assert on
+  // failure to build an AST.
+  MockFS FS;
+  std::string FullFilename = testPath(Filename);
+  FS.Files[FullFilename] = Code;
+  ParseInputs Inputs;
+  auto  = Inputs.CompileCommand.CommandLine;
+  Argv = {"clang"};
+  Argv.push_back(FullFilename);
+  Inputs.CompileCommand.Filename = FullFilename;
+  Inputs.CompileCommand.Directory = testRoot();
+  Inputs.Contents = Code;
+  Inputs.TFS = 
+  StoreDiags Diags;
+  auto CI = buildCompilerInvocation(Inputs, Diags);
+  assert(CI && "Failed to build compilation invocation.");
+  auto AST = ParsedAST::build(FullFilename, Inputs, std::move(CI), {}, 
nullptr);
+
+  EXPECT_FALSE(AST.has_value())
+  << "Should not try to build AST for assembly source file";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang



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


[PATCH] D149236: [clangd] Bail gracefully if given an assembly or IR source file

2023-08-18 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 551694.
nridge added a comment.

Address review comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149236

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp


Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -13,6 +13,7 @@
 
 #include "../../clang-tidy/ClangTidyCheck.h"
 #include "AST.h"
+#include "CompileCommands.h"
 #include "Compiler.h"
 #include "Config.h"
 #include "Diagnostics.h"
@@ -731,6 +732,37 @@
   pragmaTrivia(" End")));
 }
 
+TEST(ParsedASTTest, GracefulFailureOnAssemblyFile) {
+  std::string Filename = "TestTU.S";
+  std::string Code = R"S(
+main:
+# test comment
+bx lr
+  )S";
+
+  // The rest is a simplified version of TestTU::build().
+  // Don't call TestTU::build() itself because it would assert on
+  // failure to build an AST.
+  MockFS FS;
+  std::string FullFilename = testPath(Filename);
+  FS.Files[FullFilename] = Code;
+  ParseInputs Inputs;
+  auto  = Inputs.CompileCommand.CommandLine;
+  Argv = {"clang"};
+  Argv.push_back(FullFilename);
+  Inputs.CompileCommand.Filename = FullFilename;
+  Inputs.CompileCommand.Directory = testRoot();
+  Inputs.Contents = Code;
+  Inputs.TFS = 
+  StoreDiags Diags;
+  auto CI = buildCompilerInvocation(Inputs, Diags);
+  assert(CI && "Failed to build compilation invocation.");
+  auto AST = ParsedAST::build(FullFilename, Inputs, std::move(CI), {}, 
nullptr);
+
+  EXPECT_FALSE(AST.has_value())
+  << "Should not try to build AST for assembly source file";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -396,6 +396,15 @@
 VFS = Preamble->StatCache->getConsumingFS(std::move(VFS));
 
   assert(CI);
+
+  if (CI->getFrontendOpts().Inputs.size() > 0) {
+auto Lang = CI->getFrontendOpts().Inputs[0].getKind().getLanguage();
+if (Lang == Language::Asm || Lang == Language::LLVM_IR) {
+  elog("Clangd does not support assembly or IR source files");
+  return std::nullopt;
+}
+  }
+
   // Command-line parsing sets DisableFree to true by default, but we don't 
want
   // to leak memory in clangd.
   CI->getFrontendOpts().DisableFree = false;


Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -13,6 +13,7 @@
 
 #include "../../clang-tidy/ClangTidyCheck.h"
 #include "AST.h"
+#include "CompileCommands.h"
 #include "Compiler.h"
 #include "Config.h"
 #include "Diagnostics.h"
@@ -731,6 +732,37 @@
   pragmaTrivia(" End")));
 }
 
+TEST(ParsedASTTest, GracefulFailureOnAssemblyFile) {
+  std::string Filename = "TestTU.S";
+  std::string Code = R"S(
+main:
+# test comment
+bx lr
+  )S";
+
+  // The rest is a simplified version of TestTU::build().
+  // Don't call TestTU::build() itself because it would assert on
+  // failure to build an AST.
+  MockFS FS;
+  std::string FullFilename = testPath(Filename);
+  FS.Files[FullFilename] = Code;
+  ParseInputs Inputs;
+  auto  = Inputs.CompileCommand.CommandLine;
+  Argv = {"clang"};
+  Argv.push_back(FullFilename);
+  Inputs.CompileCommand.Filename = FullFilename;
+  Inputs.CompileCommand.Directory = testRoot();
+  Inputs.Contents = Code;
+  Inputs.TFS = 
+  StoreDiags Diags;
+  auto CI = buildCompilerInvocation(Inputs, Diags);
+  assert(CI && "Failed to build compilation invocation.");
+  auto AST = ParsedAST::build(FullFilename, Inputs, std::move(CI), {}, nullptr);
+
+  EXPECT_FALSE(AST.has_value())
+  << "Should not try to build AST for assembly source file";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -396,6 +396,15 @@
 VFS = Preamble->StatCache->getConsumingFS(std::move(VFS));
 
   assert(CI);
+
+  if (CI->getFrontendOpts().Inputs.size() > 0) {
+auto Lang = CI->getFrontendOpts().Inputs[0].getKind().getLanguage();
+if (Lang == Language::Asm || Lang == Language::LLVM_IR) {
+  elog("Clangd does not support assembly or IR source files");
+  return std::nullopt;
+}
+  }
+
   // Command-line parsing sets DisableFree to true by default, but we don't want
   // to leak memory in 

[PATCH] D157953: [CGCall][RISCV] Handle function calls with parameter of RVV tuple type

2023-08-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:5278
+  for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
+llvm::Value *LI = Builder.CreateExtractValue(
+StoredStructValue, i, Src.getName() + ".extract" + Twine(i));

`LI` meant LoadInst in the original code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157953

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


[PATCH] D158248: [clangd] Fix incorrect RecursiveASTVisitor usage in summarizeExpr()

2023-08-18 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3e69886dd012: [clangd] Fix incorrect RecursiveASTVisitor 
usage in summarizeExpr() (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158248

Files:
  clang-tools-extra/clangd/InlayHints.cpp


Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -273,7 +273,7 @@
   return getSimpleName(E->getMember()).str();
 }
 std::string
-VisitDependentScopeMemberExpr(const DependentScopeDeclRefExpr *E) {
+VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E) {
   return getSimpleName(E->getDeclName()).str();
 }
 std::string VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *E) {
@@ -534,7 +534,7 @@
 
 // Do not show parameter hints for operator calls written using operator
 // syntax or user-defined literals. (Among other reasons, the resulting
-// hints can look awkard, e.g. the expression can itself be a function
+// hints can look awkward, e.g. the expression can itself be a function
 // argument and then we'd get two hints side by side).
 if (isa(E) || isa(E))
   return true;


Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -273,7 +273,7 @@
   return getSimpleName(E->getMember()).str();
 }
 std::string
-VisitDependentScopeMemberExpr(const DependentScopeDeclRefExpr *E) {
+VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E) {
   return getSimpleName(E->getDeclName()).str();
 }
 std::string VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *E) {
@@ -534,7 +534,7 @@
 
 // Do not show parameter hints for operator calls written using operator
 // syntax or user-defined literals. (Among other reasons, the resulting
-// hints can look awkard, e.g. the expression can itself be a function
+// hints can look awkward, e.g. the expression can itself be a function
 // argument and then we'd get two hints side by side).
 if (isa(E) || isa(E))
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 3e69886 - [clangd] Fix incorrect RecursiveASTVisitor usage in summarizeExpr()

2023-08-18 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2023-08-18T23:02:48-04:00
New Revision: 3e69886dd012fb446936760f0946db4df5223c48

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

LOG: [clangd] Fix incorrect RecursiveASTVisitor usage in summarizeExpr()

Plus bonus typo fix

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

Added: 


Modified: 
clang-tools-extra/clangd/InlayHints.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 1962aa51aef419..eaefe0850f9cff 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -273,7 +273,7 @@ std::string summarizeExpr(const Expr *E) {
   return getSimpleName(E->getMember()).str();
 }
 std::string
-VisitDependentScopeMemberExpr(const DependentScopeDeclRefExpr *E) {
+VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E) {
   return getSimpleName(E->getDeclName()).str();
 }
 std::string VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *E) {
@@ -534,7 +534,7 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 
 // Do not show parameter hints for operator calls written using operator
 // syntax or user-defined literals. (Among other reasons, the resulting
-// hints can look awkard, e.g. the expression can itself be a function
+// hints can look awkward, e.g. the expression can itself be a function
 // argument and then we'd get two hints side by side).
 if (isa(E) || isa(E))
   return true;



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


[PATCH] D158158: [clang] Set FP options in Sema when instantiating CompoundStmt

2023-08-18 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast accepted this revision.
hubert.reinterpretcast added a comment.
This revision is now accepted and ready to land.

LGTM; thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158158

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


[PATCH] D157565: [CodeGen] Add AArch64 behavior to existing MFS tests

2023-08-18 Thread Han Shen 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 rGb9d079d6188b: [clang][test] Refine clang 
machine-function-split tests. (authored by shenhan).
Herald added subscribers: cfe-commits, mattd, asavonic.
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D157565?vs=551617=551688#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157565

Files:
  clang/test/CodeGen/fsplit-machine-functions.c
  clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
  clang/test/Driver/fsplit-machine-functions.c
  llvm/test/CodeGen/Generic/machine-function-splitter.ll

Index: llvm/test/CodeGen/Generic/machine-function-splitter.ll
===
--- llvm/test/CodeGen/Generic/machine-function-splitter.ll
+++ llvm/test/CodeGen/Generic/machine-function-splitter.ll
@@ -16,10 +16,10 @@
 
 ;; Check that MFS is on for X86 targets.
 ; MFS_ON: Machine Function Splitter Transformation
-; MFS_ON_NO: warning: -fsplit-machine-functions is not valid for
+; MFS_ON-NOT: warning:
 ;; Check that MFS is not on for non-X86 targets.
 ; MFS_OFF: warning: -fsplit-machine-functions is not valid for
-; MFS_OFF_NO: Machine Function Splitter Transformation
+; MFS_OFF-NOT: Machine Function Splitter Transformation
 
 define void @foo1(i1 zeroext %0) nounwind !prof !14 !section_prefix !15 {
 ;; Check that cold block is moved to .text.split.
Index: clang/test/Driver/fsplit-machine-functions.c
===
--- clang/test/Driver/fsplit-machine-functions.c
+++ clang/test/Driver/fsplit-machine-functions.c
@@ -1,10 +1,5 @@
-// REQUIRES: arm-registered-target
+// RUN: %clang -### --target=x86_64 -fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK_OPT %s
+// RUN: %clang -### --target=x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK_NOOPT %s
 
-// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
-// RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
-// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
-// RUN: %clang -c -target arm-unknown-linux-gnueabi -fsplit-machine-functions %s -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
-
-// CHECK-OPT:   "-fsplit-machine-functions"
-// CHECK-NOOPT-NOT: "-fsplit-machine-functions"
-// CHECK-TRIPLE:warning: -fsplit-machine-functions is not valid for arm
+// CHECK_OPT:"-fsplit-machine-functions"
+// CHECK_NOOPT-NOT:  "-fsplit-machine-functions"
Index: clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
===
--- clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
+++ clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
@@ -1,68 +1,28 @@
-// REQUIRES: system-linux
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
-// REQUIRES: shell
 
 // Check that -fsplit-machine-functions is passed to both x86 and cuda
 // compilation and does not cause driver error.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
 // RUN: 2>&1 | FileCheck %s --check-prefix=MFS1
 // MFS1: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
 // MFS1: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
 
-// Check that -fsplit-machine-functions is passed to cuda and it
-// causes a warning.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
-// RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS2
-// MFS2: warning: -fsplit-machine-functions is not valid for nvptx
-
 // Check that -Xarch_host -fsplit-machine-functions is passed only to
 // native compilation.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
 // RUN: -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS3
-// MFS3: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
-// MFS3-NOT: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
-
-// Check that 

[clang] b9d079d - [clang][test] Refine clang machine-function-split tests.

2023-08-18 Thread Han Shen via cfe-commits

Author: Han Shen
Date: 2023-08-18T18:05:47-07:00
New Revision: b9d079d6188b50730e0a67267b7fee36008435ce

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

LOG: [clang][test] Refine clang machine-function-split tests.

This CL includes two changes:
1. moved clang backend-warnings test cases from Driver/ to CodeGen/.
2. removed multiple `cd "$(dirname "%t")"` and replaced with `-o %t`.

Reviewed By: maskray (Fangrui Song)
Differential Revision: https://reviews.llvm.org/D157565

Added: 
clang/test/CodeGen/fsplit-machine-functions.c

Modified: 
clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
clang/test/Driver/fsplit-machine-functions.c
llvm/test/CodeGen/Generic/machine-function-splitter.ll

Removed: 




diff  --git a/clang/test/CodeGen/fsplit-machine-functions.c 
b/clang/test/CodeGen/fsplit-machine-functions.c
new file mode 100644
index 00..dd8e4ff333f20d
--- /dev/null
+++ b/clang/test/CodeGen/fsplit-machine-functions.c
@@ -0,0 +1,25 @@
+// REQUIRES: x86-registered-target
+// REQUIRES: arm-registered-target
+// REQUIRES: nvptx-registered-target
+
+// Check -fsplit-machine-functions passed to cuda device causes a warning.
+// RUN: %clang_cc1 -triple nvptx-unknown-unknown -target-cpu sm_70 \
+// RUN: -fcuda-is-device -x cuda -fsplit-machine-functions -S %s \
+// RUN: -o %t 2>&1 | FileCheck %s --check-prefix=MFS1
+// MFS1: warning: -fsplit-machine-functions is not valid for nvptx
+
+// Check -fsplit-machine-functions passed to X86 does not cause any warning.
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsplit-machine-functions \
+// RUN: -o %t -S %s && { echo "empty output causes FileCheck to fail" ; } \
+// RUN: 2>&1 | FileCheck %s --check-prefix=MFS2
+// MFS2-NOT: warning:
+
+// Check -fsplit-machine-functions passed to ARM does cause a warning.
+// RUN: %clang_cc1 -triple arm-unknown-linux-gnueabi \
+// RUN: -fsplit-machine-functions -S %s -o %t \
+// RUN: 2>&1 | FileCheck -check-prefix=MFS3 %s
+// MFS3: warning: -fsplit-machine-functions is not valid for arm
+
+int foo() {
+  return 13;
+}

diff  --git a/clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c 
b/clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
index f2b09e13d80b68..aab1179b3e731e 100644
--- a/clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
+++ b/clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
@@ -1,68 +1,28 @@
-// REQUIRES: system-linux
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
-// REQUIRES: shell
 
 // Check that -fsplit-machine-functions is passed to both x86 and cuda
 // compilation and does not cause driver error.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
 // RUN: 2>&1 | FileCheck %s --check-prefix=MFS1
 // MFS1: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
 // MFS1: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
 
-// Check that -fsplit-machine-functions is passed to cuda and it
-// causes a warning.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
-// RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS2
-// MFS2: warning: -fsplit-machine-functions is not valid for nvptx
-
 // Check that -Xarch_host -fsplit-machine-functions is passed only to
 // native compilation.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
 // RUN: -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS3
-// MFS3: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
-// MFS3-NOT: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
-
-// Check that -Xarch_host -fsplit-machine-functions does not cause any warning.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
-// RUN  --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
-// RUN  -fsplit-machine-functions -S %s || { echo \
-// RUN  "warning: -fsplit-machine-functions is not valid for" ; } \
-// RUN  2>&1 | FileCheck %s --check-prefix=MFS4
-// MFS4-NOT: warning: -fsplit-machine-functions is not valid for
-
-// Check that -Xarch_device -fsplit-machine-functions does cause the warning.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang 

[PATCH] D126586: [InstrProf] Single byte counters in coverage

2023-08-18 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem updated this revision to Diff 551687.
gulfem added a comment.

Remove hyphen between "single counter" for consistency


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126586

Files:
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/CodeGen/CodeGenPGO.h
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/single-byte-counters.cpp

Index: clang/test/CoverageMapping/single-byte-counters.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/single-byte-counters.cpp
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -mllvm -enable-single-byte-coverage=true -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name single-byte-counters.cpp %s | FileCheck %s
+
+// CHECK: testIf
+int testIf(int x) { // CHECK-NEXT: File 0, [[@LINE]]:19 -> [[@LINE+10]]:2 = #0
+// CHECK-NEXT: File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:13 = #0
+// CHECK-NEXT: Gap,File 0, [[@LINE+4]]:14 -> [[@LINE+5]]:5 = #1
+// CHECK-NEXT: File 0, [[@LINE+4]]:5 -> [[@LINE+4]]:16 = #1
+// CHECK-NEXT: File 0, [[@LINE+5]]:3 -> [[@LINE+5]]:16 = #2
+  int result = 0;
+  if (x == 0)
+result = -1;
+
+  return result;
+}
+
+// CHECK-NEXT: testIfElse
+int testIfElse(int x) { // CHECK-NEXT: File 0, [[@LINE]]:23 -> [[@LINE+13]]:2 = #0
+// CHECK-NEXT: File 0, [[@LINE+7]]:7 -> [[@LINE+7]]:12 = #0
+// CHECK-NEXT: Gap,File 0, [[@LINE+6]]:13 -> [[@LINE+7]]:5 = #1
+// CHECK-NEXT: File 0, [[@LINE+6]]:5 -> [[@LINE+6]]:15 = #1
+// CHECK-NEXT: Gap,File 0, [[@LINE+5]]:16 -> [[@LINE+7]]:5 = #2
+// CHECK-NEXT: File 0, [[@LINE+6]]:5 -> [[@LINE+6]]:19 = #2
+// CHECK-NEXT: File 0, [[@LINE+6]]:3 -> [[@LINE+6]]:16 = #3
+  int result = 0;
+  if (x < 0)
+result = 0;
+  else
+result = x * x;
+  return result;
+}
+
+// CHECK-NEXT: testIfElseReturn
+int testIfElseReturn(int x) { // CHECK-NEXT: File 0, [[@LINE]]:29 -> [[@LINE+14]]:2 = #0
+  // CHECK-NEXT: File 0, [[@LINE+8]]:7 -> [[@LINE+8]]:12 = #0
+  // CHECK-NEXT: Gap,File 0, [[@LINE+7]]:13 -> [[@LINE+8]]:5 = #1
+  // CHECK-NEXT: File 0, [[@LINE+7]]:5 -> [[@LINE+7]]:19 = #1
+  // CHECK-NEXT: Gap,File 0, [[@LINE+6]]:20 -> [[@LINE+8]]:5 = #2
+  // CHECK-NEXT: File 0, [[@LINE+7]]:5 -> [[@LINE+7]]:13 = #2
+  // CHECK-NEXT: Gap,File 0, [[@LINE+6]]:14 -> [[@LINE+7]]:3 = #3
+  // CHECK-NEXT: File 0, [[@LINE+6]]:3 -> [[@LINE+6]]:16 = #3
+  int result = 0;
+  if (x > 0)
+result = x * x;
+  else
+return 0;
+  return result;
+}
+
+// CHECK-NEXT: testSwitch
+int testSwitch(int x) { // CHECK-NEXT: File 0, [[@LINE]]:23 -> [[@LINE+22]]:2 = #0
+// CHECK-NEXT: Gap,File 0, [[@LINE+9]]:14 -> [[@LINE+17]]:15 = 0
+// CHECK-NEXT: File 0, [[@LINE+9]]:3 -> [[@LINE+11]]:10 = #2
+// CHECK-NEXT: Gap,File 0, [[@LINE+10]]:11 -> [[@LINE+11]]:3 = 0
+// CHECK-NEXT: File 0, [[@LINE+10]]:3 -> [[@LINE+12]]:10 = #3
+// CHECK-NEXT: Gap,File 0, [[@LINE+11]]:11 -> [[@LINE+12]]:3 = 0
+// CHECK-NEXT: File 0, [[@LINE+11]]:3 -> [[@LINE+12]]:15 = #4
+// CHECK-NEXT: Gap,File 0, [[@LINE+12]]:4 -> [[@LINE+14]]:3 = #1
+// CHECK-NEXT: File 0, [[@LINE+13]]:3 -> [[@LINE+13]]:16 = #1
+  int result;
+  switch (x) {
+  case 1:
+result = 1;
+break;
+  case 2:
+result = 2;
+break;
+  default:
+result = 0;
+  }
+
+  return result;
+}
+
+// CHECK-NEXT: testWhile
+int testWhile() { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+13]]:2 = #0
+  // CHECK-NEXT: File 0, [[@LINE+6]]:10 -> [[@LINE+6]]:16 = #1
+  // CHECK-NEXT: Gap,File 0, [[@LINE+5]]:17 -> [[@LINE+5]]:18 = #2
+  // CHECK-NEXT: File 0, [[@LINE+4]]:18 -> [[@LINE+7]]:4 = #2
+  // CHECK-NEXT: File 0, [[@LINE+8]]:3 -> [[@LINE+8]]:13 = #3
+  int i = 0;
+  int sum = 0;
+  while (i < 10) {
+sum += i;
+i++;
+  }
+
+  return sum;
+}
+
+// CHECK-NEXT: testContinue
+int testContinue() { // CHECK-NEXT: File 0, [[@LINE]]:20 -> [[@LINE+21]]:2 = #0
+ // CHECK-NEXT: File 0, [[@LINE+12]]:10 -> [[@LINE+12]]:16 = #1
+ 

[PATCH] D126586: [InstrProf] Single byte counters in coverage

2023-08-18 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem updated this revision to Diff 551686.
gulfem added a comment.

Ensure the correct traversal order for loops in CodeGenPGO
to fix the profile test failures (Profile/cxx-hash-v2.cpp
and Profile/cxx-rangefor.cpp)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126586

Files:
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/CodeGen/CodeGenPGO.h
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/single-byte-counters.cpp

Index: clang/test/CoverageMapping/single-byte-counters.cpp
===
--- /dev/null
+++ clang/test/CoverageMapping/single-byte-counters.cpp
@@ -0,0 +1,169 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -mllvm -enable-single-byte-coverage=true -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name single-byte-counters.cpp %s | FileCheck %s
+
+// CHECK: testIf
+int testIf(int x) { // CHECK-NEXT: File 0, [[@LINE]]:19 -> [[@LINE+10]]:2 = #0
+// CHECK-NEXT: File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:13 = #0
+// CHECK-NEXT: Gap,File 0, [[@LINE+4]]:14 -> [[@LINE+5]]:5 = #1
+// CHECK-NEXT: File 0, [[@LINE+4]]:5 -> [[@LINE+4]]:16 = #1
+// CHECK-NEXT: File 0, [[@LINE+5]]:3 -> [[@LINE+5]]:16 = #2
+  int result = 0;
+  if (x == 0)
+result = -1;
+
+  return result;
+}
+
+// CHECK-NEXT: testIfElse
+int testIfElse(int x) { // CHECK-NEXT: File 0, [[@LINE]]:23 -> [[@LINE+13]]:2 = #0
+// CHECK-NEXT: File 0, [[@LINE+7]]:7 -> [[@LINE+7]]:12 = #0
+// CHECK-NEXT: Gap,File 0, [[@LINE+6]]:13 -> [[@LINE+7]]:5 = #1
+// CHECK-NEXT: File 0, [[@LINE+6]]:5 -> [[@LINE+6]]:15 = #1
+// CHECK-NEXT: Gap,File 0, [[@LINE+5]]:16 -> [[@LINE+7]]:5 = #2
+// CHECK-NEXT: File 0, [[@LINE+6]]:5 -> [[@LINE+6]]:19 = #2
+// CHECK-NEXT: File 0, [[@LINE+6]]:3 -> [[@LINE+6]]:16 = #3
+  int result = 0;
+  if (x < 0)
+result = 0;
+  else
+result = x * x;
+  return result;
+}
+
+// CHECK-NEXT: testIfElseReturn
+int testIfElseReturn(int x) { // CHECK-NEXT: File 0, [[@LINE]]:29 -> [[@LINE+14]]:2 = #0
+  // CHECK-NEXT: File 0, [[@LINE+8]]:7 -> [[@LINE+8]]:12 = #0
+  // CHECK-NEXT: Gap,File 0, [[@LINE+7]]:13 -> [[@LINE+8]]:5 = #1
+  // CHECK-NEXT: File 0, [[@LINE+7]]:5 -> [[@LINE+7]]:19 = #1
+  // CHECK-NEXT: Gap,File 0, [[@LINE+6]]:20 -> [[@LINE+8]]:5 = #2
+  // CHECK-NEXT: File 0, [[@LINE+7]]:5 -> [[@LINE+7]]:13 = #2
+  // CHECK-NEXT: Gap,File 0, [[@LINE+6]]:14 -> [[@LINE+7]]:3 = #3
+  // CHECK-NEXT: File 0, [[@LINE+6]]:3 -> [[@LINE+6]]:16 = #3
+  int result = 0;
+  if (x > 0)
+result = x * x;
+  else
+return 0;
+  return result;
+}
+
+// CHECK-NEXT: testSwitch
+int testSwitch(int x) { // CHECK-NEXT: File 0, [[@LINE]]:23 -> [[@LINE+22]]:2 = #0
+// CHECK-NEXT: Gap,File 0, [[@LINE+9]]:14 -> [[@LINE+17]]:15 = 0
+// CHECK-NEXT: File 0, [[@LINE+9]]:3 -> [[@LINE+11]]:10 = #2
+// CHECK-NEXT: Gap,File 0, [[@LINE+10]]:11 -> [[@LINE+11]]:3 = 0
+// CHECK-NEXT: File 0, [[@LINE+10]]:3 -> [[@LINE+12]]:10 = #3
+// CHECK-NEXT: Gap,File 0, [[@LINE+11]]:11 -> [[@LINE+12]]:3 = 0
+// CHECK-NEXT: File 0, [[@LINE+11]]:3 -> [[@LINE+12]]:15 = #4
+// CHECK-NEXT: Gap,File 0, [[@LINE+12]]:4 -> [[@LINE+14]]:3 = #1
+// CHECK-NEXT: File 0, [[@LINE+13]]:3 -> [[@LINE+13]]:16 = #1
+  int result;
+  switch (x) {
+  case 1:
+result = 1;
+break;
+  case 2:
+result = 2;
+break;
+  default:
+result = 0;
+  }
+
+  return result;
+}
+
+// CHECK-NEXT: testWhile
+int testWhile() { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+13]]:2 = #0
+  // CHECK-NEXT: File 0, [[@LINE+6]]:10 -> [[@LINE+6]]:16 = #1
+  // CHECK-NEXT: Gap,File 0, [[@LINE+5]]:17 -> [[@LINE+5]]:18 = #2
+  // CHECK-NEXT: File 0, [[@LINE+4]]:18 -> [[@LINE+7]]:4 = #2
+  // CHECK-NEXT: File 0, [[@LINE+8]]:3 -> [[@LINE+8]]:13 = #3
+  int i = 0;
+  int sum = 0;
+  while (i < 10) {
+sum += i;
+i++;
+  }
+
+  return sum;
+}
+
+// CHECK-NEXT: testContinue
+int testContinue() { // CHECK-NEXT: File 0, [[@LINE]]:20 -> [[@LINE+21]]:2 = #0
+   

[PATCH] D156762: [-Wunsafe-buffer-usage][NFC] Refactor `getFixIts`---where fix-its are generated

2023-08-18 Thread Ziqing Luo 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 rGacc8a33b257f: [-Wunsafe-buffer-usage][NFC] Refactor 
`getFixIts`---where fix-its are generated (authored by ziqingluo-90).

Changed prior to commit:
  https://reviews.llvm.org/D156762?vs=547405=551684#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156762

Files:
  clang/lib/Analysis/UnsafeBufferUsage.cpp

Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -2212,16 +2212,30 @@
   });
 }
 
-static bool impossibleToFixForVar(const FixableGadgetSets ,
-  const Strategy ,
-  const VarDecl * Var) {
-  for (const auto  : FixablesForAllVars.byVar.find(Var)->second) {
-std::optional Fixits = F->getFixits(S);
-if (!Fixits) {
-  return true;
+// Erases variables in `FixItsForVariable`, if such a variable has an unfixable
+// group mate.  A variable `v` is unfixable iff `FixItsForVariable` does not
+// contain `v`.
+static void eraseVarsForUnfixableGroupMates(
+std::map ,
+const VariableGroupsManager ) {
+  // Variables will be removed from `FixItsForVariable`:
+  SmallVector ToErase;
+
+  for (auto [VD, Ignore] : FixItsForVariable) {
+VarGrpRef Grp = VarGrpMgr.getGroupOfVar(VD);
+if (llvm::any_of(Grp,
+ [](const VarDecl *GrpMember) -> bool {
+   return FixItsForVariable.find(GrpMember) ==
+  FixItsForVariable.end();
+ })) {
+  // At least one group member cannot be fixed, so we have to erase the
+  // whole group:
+  for (const VarDecl *Member : Grp)
+ToErase.push_back(Member);
 }
   }
-  return false;
+  for (auto *VarToErase : ToErase)
+FixItsForVariable.erase(VarToErase);
 }
 
 static std::map
@@ -2230,7 +2244,14 @@
   /* The function decl under analysis */ const Decl *D,
   const DeclUseTracker , UnsafeBufferUsageHandler ,
   const VariableGroupsManager ) {
+  // `FixItsForVariable` will map each variable to a set of fix-its directly
+  // associated to the variable itself.  Fix-its of distinct variables in
+  // `FixItsForVariable` are disjoint.
   std::map FixItsForVariable;
+
+  // Populate `FixItsForVariable` with fix-its directly associated with each
+  // variable.  Fix-its directly associated to a variable 'v' are the ones
+  // produced by the `FixableGadget`s whose claimed variable is 'v'.
   for (const auto &[VD, Fixables] : FixablesForAllVars.byVar) {
 FixItsForVariable[VD] =
 fixVariable(VD, S.lookup(VD), D, Tracker, Ctx, Handler);
@@ -2240,64 +2261,36 @@
   FixItsForVariable.erase(VD);
   continue;
 }
-bool ImpossibleToFix = false;
-llvm::SmallVector FixItsForVD;
 for (const auto  : Fixables) {
   std::optional Fixits = F->getFixits(S);
-  if (!Fixits) {
-#ifndef NDEBUG
-Handler.addDebugNoteForVar(
-VD, F->getBaseStmt()->getBeginLoc(),
-("gadget '" + F->getDebugName() + "' refused to produce a fix")
-.str());
-#endif
-ImpossibleToFix = true;
-break;
-  } else {
-const FixItList CorrectFixes = Fixits.value();
-FixItsForVD.insert(FixItsForVD.end(), CorrectFixes.begin(),
-   CorrectFixes.end());
-  }
-}
 
-if (ImpossibleToFix) {
-  FixItsForVariable.erase(VD);
-  continue;
-}
-
-
-   {
-  const auto VarGroupForVD = VarGrpMgr.getGroupOfVar(VD);
-  for (const VarDecl * V : VarGroupForVD) {
-if (V == VD) {
-  continue;
-}
-if (impossibleToFixForVar(FixablesForAllVars, S, V)) {
-  ImpossibleToFix = true;
-  break;
-}
-  }
-
-  if (ImpossibleToFix) {
-FixItsForVariable.erase(VD);
-for (const VarDecl * V : VarGroupForVD) {
-  FixItsForVariable.erase(V);
-}
+  if (Fixits) {
+FixItsForVariable[VD].insert(FixItsForVariable[VD].end(),
+ Fixits->begin(), Fixits->end());
 continue;
   }
-}
-FixItsForVariable[VD].insert(FixItsForVariable[VD].end(),
- FixItsForVD.begin(), FixItsForVD.end());
-
-// Fix-it shall not overlap with macros or/and templates:
-if (overlapWithMacro(FixItsForVariable[VD]) ||
-clang::internal::anyConflict(FixItsForVariable[VD],
- Ctx.getSourceManager())) {
+#ifndef NDEBUG
+  Handler.addDebugNoteForVar(
+  VD, F->getBaseStmt()->getBeginLoc(),
+  ("gadget '" + F->getDebugName() + "' refused to produce a fix")
+  

[clang] acc8a33 - [-Wunsafe-buffer-usage][NFC] Refactor `getFixIts`---where fix-its are generated

2023-08-18 Thread via cfe-commits

Author: ziqingluo-90
Date: 2023-08-18T17:44:22-07:00
New Revision: acc8a33b257f8176fae1bae929ff9da7ed2cbad5

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

LOG: [-Wunsafe-buffer-usage][NFC] Refactor `getFixIts`---where fix-its are 
generated

Refactor the getFixIts function for better readability.

Reviewed by: NoQ (Artem Dergachev), t-rasmud (Rashmi Mudduluru)

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

Added: 


Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 4638f7422320b9..21d3f6f2faaa68 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -2212,16 +2212,30 @@ static bool overlapWithMacro(const FixItList ) {
   });
 }
 
-static bool impossibleToFixForVar(const FixableGadgetSets ,
-  const Strategy ,
-  const VarDecl * Var) {
-  for (const auto  : FixablesForAllVars.byVar.find(Var)->second) {
-std::optional Fixits = F->getFixits(S);
-if (!Fixits) {
-  return true;
+// Erases variables in `FixItsForVariable`, if such a variable has an unfixable
+// group mate.  A variable `v` is unfixable iff `FixItsForVariable` does not
+// contain `v`.
+static void eraseVarsForUnfixableGroupMates(
+std::map ,
+const VariableGroupsManager ) {
+  // Variables will be removed from `FixItsForVariable`:
+  SmallVector ToErase;
+
+  for (auto [VD, Ignore] : FixItsForVariable) {
+VarGrpRef Grp = VarGrpMgr.getGroupOfVar(VD);
+if (llvm::any_of(Grp,
+ [](const VarDecl *GrpMember) -> bool {
+   return FixItsForVariable.find(GrpMember) ==
+  FixItsForVariable.end();
+ })) {
+  // At least one group member cannot be fixed, so we have to erase the
+  // whole group:
+  for (const VarDecl *Member : Grp)
+ToErase.push_back(Member);
 }
   }
-  return false;
+  for (auto *VarToErase : ToErase)
+FixItsForVariable.erase(VarToErase);
 }
 
 static std::map
@@ -2230,7 +2244,14 @@ getFixIts(FixableGadgetSets , const 
Strategy ,
   /* The function decl under analysis */ const Decl *D,
   const DeclUseTracker , UnsafeBufferUsageHandler ,
   const VariableGroupsManager ) {
+  // `FixItsForVariable` will map each variable to a set of fix-its directly
+  // associated to the variable itself.  Fix-its of distinct variables in
+  // `FixItsForVariable` are disjoint.
   std::map FixItsForVariable;
+
+  // Populate `FixItsForVariable` with fix-its directly associated with each
+  // variable.  Fix-its directly associated to a variable 'v' are the ones
+  // produced by the `FixableGadget`s whose claimed variable is 'v'.
   for (const auto &[VD, Fixables] : FixablesForAllVars.byVar) {
 FixItsForVariable[VD] =
 fixVariable(VD, S.lookup(VD), D, Tracker, Ctx, Handler);
@@ -2240,64 +2261,36 @@ getFixIts(FixableGadgetSets , const 
Strategy ,
   FixItsForVariable.erase(VD);
   continue;
 }
-bool ImpossibleToFix = false;
-llvm::SmallVector FixItsForVD;
 for (const auto  : Fixables) {
   std::optional Fixits = F->getFixits(S);
-  if (!Fixits) {
-#ifndef NDEBUG
-Handler.addDebugNoteForVar(
-VD, F->getBaseStmt()->getBeginLoc(),
-("gadget '" + F->getDebugName() + "' refused to produce a fix")
-.str());
-#endif
-ImpossibleToFix = true;
-break;
-  } else {
-const FixItList CorrectFixes = Fixits.value();
-FixItsForVD.insert(FixItsForVD.end(), CorrectFixes.begin(),
-   CorrectFixes.end());
-  }
-}
 
-if (ImpossibleToFix) {
-  FixItsForVariable.erase(VD);
-  continue;
-}
-
-
-   {
-  const auto VarGroupForVD = VarGrpMgr.getGroupOfVar(VD);
-  for (const VarDecl * V : VarGroupForVD) {
-if (V == VD) {
-  continue;
-}
-if (impossibleToFixForVar(FixablesForAllVars, S, V)) {
-  ImpossibleToFix = true;
-  break;
-}
-  }
-
-  if (ImpossibleToFix) {
-FixItsForVariable.erase(VD);
-for (const VarDecl * V : VarGroupForVD) {
-  FixItsForVariable.erase(V);
-}
+  if (Fixits) {
+FixItsForVariable[VD].insert(FixItsForVariable[VD].end(),
+ Fixits->begin(), Fixits->end());
 continue;
   }
-}
-FixItsForVariable[VD].insert(FixItsForVariable[VD].end(),
- FixItsForVD.begin(), FixItsForVD.end());
-
-// Fix-it shall not overlap with macros or/and templates:
-if 

[PATCH] D157579: [clang][ExtractAPI] Add support for C++ global function templates

2023-08-18 Thread Erick Velez 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 rG80b787e80329: [clang][ExtractAPI] Add support for C++ global 
function templates (authored by evelez7).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157579

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/global_func_template.cpp
  clang/test/ExtractAPI/global_func_template_spec.cpp

Index: clang/test/ExtractAPI/global_func_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/global_func_template_spec.cpp
@@ -0,0 +1,299 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template void Foo(T Bar);
+
+template<> void Foo(int Bar);
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ");"
+}
+  ],
+  "functionSignature": {
+"parameters": [
+  {
+"declarationFragments": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:t0.0",
+"spelling": "T"
+  },
+  {
+"kind": "text",
+"spelling": " "
+  },
+  {
+"kind": "internalParam",
+"spelling": "Bar"
+  }
+],
+"name": "Bar"
+  }
+],
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:v",
+"spelling": "void"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@FT@>1#TFoo#t0.0#v#"
+  },
+  "kind": {
+"displayName": "Function Template",
+"identifier": "c++.func"
+  },
+  "location": {
+"position": {
+  "character": 27,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+   

[clang] 80b787e - [clang][ExtractAPI] Add support for C++ global function templates

2023-08-18 Thread Erick Velez via cfe-commits

Author: Erick Velez
Date: 2023-08-18T17:42:05-07:00
New Revision: 80b787e803292119f30da2e1e95acff5beea61db

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

LOG: [clang][ExtractAPI] Add support for C++ global function templates

Add records, serialization for global function templates and their 
specializations

Depends on D157350

Reviewed By: dang

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

Added: 
clang/test/ExtractAPI/global_func_template.cpp
clang/test/ExtractAPI/global_func_template_spec.cpp

Modified: 
clang/include/clang/ExtractAPI/API.h
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/lib/ExtractAPI/API.cpp
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index 7846ad14127fe4..7fc6447e93b961 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -158,6 +158,8 @@ struct APIRecord {
   enum RecordKind {
 RK_Unknown,
 RK_GlobalFunction,
+RK_GlobalFunctionTemplate,
+RK_GlobalFunctionTemplateSpecialization,
 RK_GlobalVariable,
 RK_GlobalVariableTemplate,
 RK_GlobalVariableTemplateSpecialization,
@@ -281,6 +283,16 @@ struct GlobalFunctionRecord : APIRecord {
   IsFromSystemHeader),
 Signature(Signature) {}
 
+  GlobalFunctionRecord(RecordKind Kind, StringRef USR, StringRef Name,
+   PresumedLoc Loc, AvailabilitySet Availabilities,
+   LinkageInfo Linkage, const DocComment ,
+   DeclarationFragments Declaration,
+   DeclarationFragments SubHeading,
+   FunctionSignature Signature, bool IsFromSystemHeader)
+  : APIRecord(Kind, USR, Name, Loc, std::move(Availabilities), Linkage,
+  Comment, Declaration, SubHeading, IsFromSystemHeader),
+Signature(Signature) {}
+
   static bool classof(const APIRecord *Record) {
 return Record->getKind() == RK_GlobalFunction;
   }
@@ -289,6 +301,44 @@ struct GlobalFunctionRecord : APIRecord {
   virtual void anchor();
 };
 
+struct GlobalFunctionTemplateRecord : GlobalFunctionRecord {
+  Template Templ;
+
+  GlobalFunctionTemplateRecord(StringRef USR, StringRef Name, PresumedLoc Loc,
+   AvailabilitySet Availabilities,
+   LinkageInfo Linkage, const DocComment ,
+   DeclarationFragments Declaration,
+   DeclarationFragments SubHeading,
+   FunctionSignature Signature, Template Template,
+   bool IsFromSystemHeader)
+  : GlobalFunctionRecord(RK_GlobalFunctionTemplate, USR, Name, Loc,
+ std::move(Availabilities), Linkage, Comment,
+ Declaration, SubHeading, Signature,
+ IsFromSystemHeader),
+Templ(Template) {}
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() == RK_GlobalFunctionTemplate;
+  }
+};
+
+struct GlobalFunctionTemplateSpecializationRecord : GlobalFunctionRecord {
+  GlobalFunctionTemplateSpecializationRecord(
+  StringRef USR, StringRef Name, PresumedLoc Loc,
+  AvailabilitySet Availabilities, LinkageInfo Linkage,
+  const DocComment , DeclarationFragments Declaration,
+  DeclarationFragments SubHeading, FunctionSignature Signature,
+  bool IsFromSystemHeader)
+  : GlobalFunctionRecord(RK_GlobalFunctionTemplateSpecialization, USR, 
Name,
+ Loc, std::move(Availabilities), Linkage, Comment,
+ Declaration, SubHeading, Signature,
+ IsFromSystemHeader) {}
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() == RK_GlobalFunctionTemplateSpecialization;
+  }
+};
+
 /// This holds information associated with global functions.
 struct GlobalVariableRecord : APIRecord {
   GlobalVariableRecord(StringRef USR, StringRef Name, PresumedLoc Loc,
@@ -1025,6 +1075,15 @@ template <>
 struct has_template
 : public std::true_type {};
 
+template <>
+struct has_template : public std::true_type {};
+template <>
+struct has_function_signature
+: public std::true_type {};
+template <>
+struct has_function_signature
+: public std::true_type {};
+
 /// APISet holds the set of API records collected from given 

[PATCH] D158231: [clang][test] Fix clang machine-function-split tests

2023-08-18 Thread Han Shen via Phabricator via cfe-commits
shenhan updated this revision to Diff 551680.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158231

Files:
  clang/test/CodeGen/fsplit-machine-functions.c
  clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
  clang/test/Driver/fsplit-machine-functions.c
  llvm/test/CodeGen/Generic/machine-function-splitter.ll

Index: llvm/test/CodeGen/Generic/machine-function-splitter.ll
===
--- llvm/test/CodeGen/Generic/machine-function-splitter.ll
+++ llvm/test/CodeGen/Generic/machine-function-splitter.ll
@@ -16,10 +16,10 @@
 
 ;; Check that MFS is on for X86 targets.
 ; MFS_ON: Machine Function Splitter Transformation
-; MFS_ON_NO: warning: -fsplit-machine-functions is not valid for
+; MFS_ON-NOT: warning:
 ;; Check that MFS is not on for non-X86 targets.
 ; MFS_OFF: warning: -fsplit-machine-functions is not valid for
-; MFS_OFF_NO: Machine Function Splitter Transformation
+; MFS_OFF-NOT: Machine Function Splitter Transformation
 
 define void @foo1(i1 zeroext %0) nounwind !prof !14 !section_prefix !15 {
 ;; Check that cold block is moved to .text.split.
Index: clang/test/Driver/fsplit-machine-functions.c
===
--- clang/test/Driver/fsplit-machine-functions.c
+++ clang/test/Driver/fsplit-machine-functions.c
@@ -1,10 +1,5 @@
-// REQUIRES: arm-registered-target
+// RUN: %clang -### --target=x86_64 -fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK_OPT %s
+// RUN: %clang -### --target=x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK_NOOPT %s
 
-// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
-// RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
-// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
-// RUN: %clang -c -target arm-unknown-linux-gnueabi -fsplit-machine-functions %s -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
-
-// CHECK-OPT:   "-fsplit-machine-functions"
-// CHECK-NOOPT-NOT: "-fsplit-machine-functions"
-// CHECK-TRIPLE:warning: -fsplit-machine-functions is not valid for arm
+// CHECK_OPT:"-fsplit-machine-functions"
+// CHECK_NOOPT-NOT:  "-fsplit-machine-functions"
Index: clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
===
--- clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
+++ clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
@@ -1,68 +1,28 @@
-// REQUIRES: system-linux
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
-// REQUIRES: shell
 
 // Check that -fsplit-machine-functions is passed to both x86 and cuda
 // compilation and does not cause driver error.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
 // RUN: 2>&1 | FileCheck %s --check-prefix=MFS1
 // MFS1: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
 // MFS1: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
 
-// Check that -fsplit-machine-functions is passed to cuda and it
-// causes a warning.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
-// RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS2
-// MFS2: warning: -fsplit-machine-functions is not valid for nvptx
-
 // Check that -Xarch_host -fsplit-machine-functions is passed only to
 // native compilation.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
 // RUN: -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS3
-// MFS3: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
-// MFS3-NOT: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
-
-// Check that -Xarch_host -fsplit-machine-functions does not cause any warning.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
-// RUN  --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
-// RUN  -fsplit-machine-functions -S %s || { echo \
-// RUN  "warning: -fsplit-machine-functions is not valid for" ; } \
-// RUN 

[PATCH] D158293: [NFC][CLANG] Fix potential dereferencing of null return values

2023-08-18 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2009-2010
(Line.MightBeFunctionDecl || Line.InPPDirective) &&
-   Current.NestingLevel == 0 &&
+   Current.NestingLevel == 0 && Current.Previous &&
!Current.Previous->isOneOf(tok::kw_operator, tok::identifier)) {
   // not auto operator->() -> xxx;

tahonermann wrote:
> owenpan wrote:
> > `Current.Previous` can't be null here because `AutoFound` is `true`.
> Could you please elaborate on why you believe it is safe to move the check of 
> `Current.Previous` inside the body of the `if` statement? Doing so will short 
> circuit the remaining `else if` cases such that `Current.setType()` will not 
> be called at all. It isn't obvious to me that those cases should not be 
> considered if the previous token was not one of `kw_operator` or 
> `identifier`. This looks like it has potential to change behavior.
> 
> The change that was originally proposed is clearly safe.
> Could you please elaborate on why you believe it is safe to move the check of 
> `Current.Previous` inside the body of the `if` statement? Doing so will short 
> circuit the remaining `else if` cases such that `Current.setType()` will not 
> be called at all. It isn't obvious to me that those cases should not be 
> considered if the previous token was not one of `kw_operator` or 
> `identifier`. This looks like it has potential to change behavior.

Ahh, you are right.

> The change that was originally proposed is clearly safe.

My point that `Previous` can't be null still stands. So we should either make 
no changes here or add an assertion just before the `if` statement at line 1991 
above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158293

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D156821#4600550 , @MaskRay wrote:

>> Currenly both Clang and GCC support the following set of flags that control
>
> code gen of signed overflow:
>
>> [...]
>> Howerver, clang ignores these flags for __builtin_abs(int) and its 
>> higher-width
>
> versions, so passing minimum integer value always causes poison.
>
> This paragraph reads as if GCC emits a trap for `__builtin_abs` in -ftrapv 
> mode, but it doesn't. That said, its `-fsanitize=signed-integer-overflow` 
> does handle `__builtin_abs`.

On X86 at least, gcc does call `__negvsi2` for __builtin_abs under -ftrapv. 
https://godbolt.org/z/8dhn9bsv5


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

https://reviews.llvm.org/D156821

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


[PATCH] D158244: [clang-tidy]`pro-bounds-array-to-pointer-decay` ignore predefined expression

2023-08-18 Thread Congcong Cai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9be33de4f397: 
[clang-tidy]`pro-bounds-array-to-pointer-decay` ignore predefined expression 
(authored by HerrCai0907).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158244

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
@@ -43,6 +43,9 @@
 const char *g2() {
 return ("clang"); // OK, ParenExpr hides the literal-pointer decay
 }
+const char *g3() {
+return __func__; // OK, don't diagnose PredefinedExpr
+}
 
 void f2(void *const *);
 void bug25362() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -186,6 +186,10 @@
   ` check to
   ignore delegate constructors.
 
+- Improved :doc `cppcoreguidelines-pro-bounds-array-to-pointer-decay
+  ` 
check 
+  to ignore predefined expression (e.g., ``__func__``, ...).
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   ` check to ignore
   dependent delegate constructors.
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ParentMapContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
 
@@ -56,6 +57,7 @@
   TK_AsIs,
   implicitCastExpr(
   unless(hasParent(arraySubscriptExpr())),
+  unless(hasSourceExpression(predefinedExpr())),
   unless(hasParentIgnoringImpCasts(explicitCastExpr())),
   unless(isInsideOfRangeBeginEndStmt()),
   unless(hasSourceExpression(ignoringParens(stringLiteral(,


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
@@ -43,6 +43,9 @@
 const char *g2() {
 return ("clang"); // OK, ParenExpr hides the literal-pointer decay
 }
+const char *g3() {
+return __func__; // OK, don't diagnose PredefinedExpr
+}
 
 void f2(void *const *);
 void bug25362() {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -186,6 +186,10 @@
   ` check to
   ignore delegate constructors.
 
+- Improved :doc `cppcoreguidelines-pro-bounds-array-to-pointer-decay
+  ` check 
+  to ignore predefined expression (e.g., ``__func__``, ...).
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   ` check to ignore
   dependent delegate constructors.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ParentMapContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
 
@@ -56,6 +57,7 @@
   TK_AsIs,
   implicitCastExpr(
   unless(hasParent(arraySubscriptExpr())),
+  unless(hasSourceExpression(predefinedExpr())),
   unless(hasParentIgnoringImpCasts(explicitCastExpr())),
   unless(isInsideOfRangeBeginEndStmt()),
   unless(hasSourceExpression(ignoringParens(stringLiteral(,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 9be33de - [clang-tidy]`pro-bounds-array-to-pointer-decay` ignore predefined expression

2023-08-18 Thread Congcong Cai via cfe-commits

Author: Congcong Cai
Date: 2023-08-19T08:13:00+08:00
New Revision: 9be33de4f39713c2deb7cc262b4dd4e50dc8349d

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

LOG: [clang-tidy]`pro-bounds-array-to-pointer-decay` ignore predefined 
expression

cast PredefinedExpr such as `__func__` to const char* should be accpetted.

Reviewed By: PiotrZSL

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

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
index c210cb67e4f6b1..6f67ab955baa34 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ParentMapContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
 
@@ -56,6 +57,7 @@ void 
ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) {
   TK_AsIs,
   implicitCastExpr(
   unless(hasParent(arraySubscriptExpr())),
+  unless(hasSourceExpression(predefinedExpr())),
   unless(hasParentIgnoringImpCasts(explicitCastExpr())),
   unless(isInsideOfRangeBeginEndStmt()),
   unless(hasSourceExpression(ignoringParens(stringLiteral(,

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a80473f09464fe..5cf09bd26fab82 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -186,6 +186,10 @@ Changes in existing checks
   ` check to
   ignore delegate constructors.
 
+- Improved :doc `cppcoreguidelines-pro-bounds-array-to-pointer-decay
+  ` 
check 
+  to ignore predefined expression (e.g., ``__func__``, ...).
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   ` check to ignore
   dependent delegate constructors.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
index d41f54b4e77f2a..0bd058caf74ffe 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-array-to-pointer-decay.cpp
@@ -43,6 +43,9 @@ const char *g() {
 const char *g2() {
 return ("clang"); // OK, ParenExpr hides the literal-pointer decay
 }
+const char *g3() {
+return __func__; // OK, don't diagnose PredefinedExpr
+}
 
 void f2(void *const *);
 void bug25362() {



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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> Currenly both Clang and GCC support the following set of flags that control

code gen of signed overflow:

> [...]
> Howerver, clang ignores these flags for __builtin_abs(int) and its 
> higher-width

versions, so passing minimum integer value always causes poison.

This paragraph reads as if GCC emits a trap for `__builtin_abs` in -ftrapv 
mode, but it doesn't. That said, its `-fsanitize=signed-integer-overflow` does 
handle `__builtin_abs`.


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

https://reviews.llvm.org/D156821

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


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-18 Thread Ian Anderson via Phabricator via cfe-commits
iana added a comment.

In D157757#4600357 , @ldionne wrote:

> This is going to be really naive, but can someone explain why we need these 
> `__need_X` macros? Why doesn't `` simply always declare what it 
> should declare? Also, does anybody understand the expected relationship 
> between the C Standard Library headers and these Clang builtin headers? Who 
> defines what?
>
> Everyone I've spoken to so far about this (and myself) was extremely 
> confused. At some point I thought these macros were only needed for 
> compatibility with old glibcs but that wouldn't even be needed anymore, but 
> I'm not certain.

The `__need_` macros are to support some strict mostly POSIX behaviors like 
 is supposed to provide `size_t` but none of the other things in 
. Apple has headers like  and 
 that are expected to provide those types and nothing 
else. Right now they're redeclaring the types, and if you're using clang 
modules with the right flags, that's an error. So I need to switch those to 
doing something like this.

  #define __need_rsize_t
  #include 

The relationship between clang's stddef.h and the C Standard Library stddef.h 
is that there is no relationship. clang's header doesn't #include_next, and it 
is in the search path before the OS's cstdlib.




Comment at: clang/lib/Headers/stddef.h:118-122
+#ifdef __cplusplus
+namespace std {
+typedef decltype(nullptr) nullptr_t;
+}
+using ::std::nullptr_t;

ldionne wrote:
> iana wrote:
> > aaron.ballman wrote:
> > > Related:
> > > 
> > > https://github.com/llvm/llvm-project/issues/37564
> > > https://cplusplus.github.io/LWG/issue3484
> > > 
> > > CC @ldionne
> > I don't _think_ this change actually changes the way nullptr_t gets defined 
> > in C++, does it?
> I think we absolutely don't want to touch `std::nullptr_t` from this header. 
> It's libc++'s responsibility to define that, and in fact we define it in 
> `std::__1`, so this is even an ABI break (or I guess it would be a compiler 
> error, not sure).
I'm really not touching it though. All I did is move it from `__need_NULL` to 
`__need_nullptr_t`.

The old behavior is that `std::nullptr_t` would only be touched if (no 
`__need_` macros were set or if `__need_NULL` was set), and (_MSC_EXTENSIONS 
and _NATIVE_NULLPTR_SUPPORTED are defined).

The new behavior is that `std::nullptr_t` will only be touched if ((no 
`__need_` macros are set) and (_MSC_EXTENSIONS and _NATIVE_NULLPTR_SUPPORTED 
are defined)) or (the new `__need_nullptr_t` macro is set)

So the only change is that C++ code that previously set `__need_NULL` will no 
longer get `std::nullptr_t`. @efriedma felt like that was a fine change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157757

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


[PATCH] D158008: [AArch64] Add patterns for FMADD, FMSUB

2023-08-18 Thread Vladislav Dzhidzhoev via Phabricator via cfe-commits
dzhidzhoev added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64InstrFormats.td:5418
+  (EXTRACT_SUBREG V128:$Rn, dsub), FPR64:$Rm, FPR64:$Ra)>;
 }
 

Is it possible to use extractelt here? Since vector_extract is marked as 
deprecated in `TargetSelectionDAG.td`


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

https://reviews.llvm.org/D158008

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


[PATCH] D157762: [WIP] Implement [[msvc::no_unique_address]]

2023-08-18 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 551662.
akhuang added a comment.

address small fixes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157762

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/Decl.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Layout/ms-no-unique-address.cpp

Index: clang/test/Layout/ms-no-unique-address.cpp
===
--- /dev/null
+++ clang/test/Layout/ms-no-unique-address.cpp
@@ -0,0 +1,310 @@
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -triple x86_64-pc-win32 -fdump-record-layouts %s | FileCheck %s
+
+namespace Empty {
+  struct A {};
+  struct A2 {};
+  struct A3 { [[msvc::no_unique_address]] A a; };
+  struct alignas(8) A4 {};
+
+  struct B {
+[[msvc::no_unique_address]] A a;
+char b;
+  };
+  static_assert(sizeof(B) == 1);
+
+  // CHECK:*** Dumping AST Record Layout
+  // CHECK:  0 | struct Empty::B
+  // CHECK-NEXT: 0 |   struct Empty::A a (empty)
+  // CHECK-NEXT: 0 |   char b
+  // CHECK-NEXT:   | [sizeof=1, align=1,
+  // CHECK-NEXT:   |  nvsize=1, nvalign=1]
+
+  struct C {
+[[msvc::no_unique_address]] A a;
+[[msvc::no_unique_address]] A2 a2;
+char c;
+  };
+  static_assert(sizeof(C) == 1);
+
+  // CHECK:*** Dumping AST Record Layout
+  // CHECK:  0 | struct Empty::C
+  // CHECK-NEXT: 0 |   struct Empty::A a (empty)
+  // CHECK-NEXT: 0 |   struct Empty::A2 a2 (empty)
+  // CHECK-NEXT: 0 |   char c
+  // CHECK-NEXT:   | [sizeof=1, align=1,
+  // CHECK-NEXT:   |  nvsize=1, nvalign=1]
+
+  struct D {
+[[msvc::no_unique_address]] A3 a;
+int i;
+  };
+  static_assert(sizeof(D) == 8);
+
+  // CHECK:*** Dumping AST Record Layout
+  // CHECK:  0 | struct Empty::D
+  // CHECK-NEXT: 0 |   struct Empty::A3 a (empty)
+  // CHECK-NEXT: 0 | struct Empty::A a (empty)
+  // CHECK-NEXT: 4 |   int i 
+  // CHECK-NEXT:   | [sizeof=8, align=4,
+  // CHECK-NEXT:   |  nvsize=8, nvalign=4]
+
+  struct E {
+[[msvc::no_unique_address]] A a1;
+[[msvc::no_unique_address]] A a2;
+char e;
+  };
+  static_assert(sizeof(E) == 2);
+
+  // CHECK:*** Dumping AST Record Layout
+  // CHECK:  0 | struct Empty::E
+  // CHECK-NEXT: 0 |   struct Empty::A a1 (empty)
+  // CHECK-NEXT: 1 |   struct Empty::A a2 (empty)
+  // CHECK-NEXT: 0 |   char e
+  // CHECK-NEXT:   | [sizeof=2, align=1,
+  // CHECK-NEXT:   |  nvsize=2, nvalign=1]
+
+  struct F {
+~F();
+[[msvc::no_unique_address]] A a1;
+[[msvc::no_unique_address]] A a2;
+char f;
+  };
+  static_assert(sizeof(F) == 2);
+
+  // CHECK:*** Dumping AST Record Layout
+  // CHECK:  0 | struct Empty::F
+  // CHECK-NEXT: 0 |   struct Empty::A a1 (empty)
+  // CHECK-NEXT: 1 |   struct Empty::A a2 (empty)
+  // CHECK-NEXT: 0 |   char f
+  // CHECK-NEXT:   | [sizeof=2, align=1,
+  // CHECK-NEXT:   |  nvsize=2, nvalign=1]
+
+  struct G { [[msvc::no_unique_address]] A a; ~G(); };
+  static_assert(sizeof(G) == 1);
+
+  // CHECK:*** Dumping AST Record Layout
+  // CHECK:  0 | struct Empty::G
+  // CHECK-NEXT: 0 |   struct Empty::A a (empty)
+  // CHECK-NEXT:   | [sizeof=1, align=1,
+  // CHECK-NEXT:   |  nvsize=1, nvalign=1]
+
+  struct H {
+[[msvc::no_unique_address]] A a;
+[[msvc::no_unique_address]] A b;
+~H();
+  };
+  static_assert(sizeof(H) == 2);
+
+  // CHECK:*** Dumping AST Record Layout
+  // CHECK:  0 | struct Empty::H
+  // CHECK-NEXT: 0 |   struct Empty::A a (empty)
+  // CHECK-NEXT: 1 |   struct Empty::A b (empty)
+  // CHECK-NEXT:   | [sizeof=2, align=1,
+  // CHECK-NEXT:   |  nvsize=2, nvalign=1]
+
+  struct I {
+[[msvc::no_unique_address]] A4 a;
+[[msvc::no_unique_address]] A4 b;
+  };
+  static_assert(sizeof(I) == 16);
+
+  // CHECK:*** Dumping AST Record Layout
+  // CHECK:  0 | struct Empty::I
+  // CHECK-NEXT: 0 |   struct Empty::A4 a (empty)
+  // CHECK-NEXT: 8 |   struct Empty::A4 b (empty)
+  // CHECK-NEXT:   | [sizeof=16, align=8,
+  // CHECK-NEXT:   |  nvsize=16, nvalign=8]
+
+  // FIXME: MSVC puts both fields at offset 0.
+  struct J {
+[[msvc::no_unique_address]] A4 a;
+A4 b;
+  };
+  static_assert(sizeof(J) == 16);
+
+  // CHECK:*** Dumping AST Record Layout
+  // CHECK:  0 | struct Empty::J
+  // CHECK-NEXT: 0 |   struct Empty::A4 a (empty)
+  // CHECK-NEXT: 8 |   struct Empty::A4 b (empty)
+  // CHECK-NEXT:   | [sizeof=16, align=8,
+  // CHECK-NEXT:   |  nvsize=16, nvalign=8]
+
+  // FIXME: MSVC puts b at offset 1 instead of 8, and the struct size is 8.
+  struct K {
+[[msvc::no_unique_address]] A4 a;
+[[msvc::no_unique_address]] char c;
+

[PATCH] D157762: [WIP] Implement [[msvc::no_unique_address]]

2023-08-18 Thread Amy Huang via Phabricator via cfe-commits
akhuang marked 2 inline comments as done.
akhuang added a comment.

I'm still trying to figure out the MSVC layouts. I used the EmptySubobjects 
class for a lot of the logic, which is not always the same as what MSVC does. 
(some examples of differences in https://godbolt.org/z/6cP554ddb)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157762

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


[PATCH] D158008: [AArch64] Add patterns for FMADD, FMSUB

2023-08-18 Thread Vladislav Dzhidzhoev via Phabricator via cfe-commits
dzhidzhoev added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64InstrFormats.td:5393
+  (EXTRACT_SUBREG V128:$Rn, hsub), FPR16:$Rm, FPR16:$Ra)>;
+  }
+

BTW, these lines add some patterns for fnmadd. Could you add some tests for 
them? Or are they already covered by existing ones?


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

https://reviews.llvm.org/D158008

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:1787
+if (!VCI->isMinSignedValue()) {
+  return EmitAbs(CGF, ArgValue, true);
+}

MaskRay wrote:
> nit: we delete braces in this cascading case
> 
> https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements
Thanks. I think the coding standard omits the outer braces as well.


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

https://reviews.llvm.org/D156821

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.



Comment at: compiler-rt/test/ubsan/TestCases/Misc/abs.cpp:11
+int main() {
+  // ABORT: abs.cpp:[[@LINE+3]]:17: runtime error: negation of -{{[0-9]+}} 
cannot be represented in type 'int'; cast to an unsigned type to negate this 
value to itself
+  // RECOVER: abs.cpp:[[@LINE+2]]:17: runtime error: negation of -{{[0-9]+}} 
cannot be represented in type 'int'; cast to an unsigned type to negate this 
value to itself

FYI: `[[@LINE+3]]` is deprecated lit syntax 
https://llvm.org/docs/CommandGuide/FileCheck.html#filecheck-pseudo-numeric-variables.
 New code should use `[[#@LINE+3]]`

`{{[0-9]+}}` can be simplified as `[[#]]`


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

https://reviews.llvm.org/D156821

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


[PATCH] D158257: [RISCV] Add feature checks for vector crypto C intrinsics

2023-08-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158257

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


[PATCH] D158255: [RISCV][NFC] Update compile options for some vector crypto C intrinsics

2023-08-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper requested changes to this revision.
craig.topper added inline comments.
This revision now requires changes to proceed.



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vcpopv.c:4
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -target-feature +zvl512b 
\
+// RUN:   -target-feature +experimental-zvbb \
+// RUN:   -target-feature +experimental-zvbc \

We should use the minimum number of command line options for what is being 
tested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158255

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


[PATCH] D158298: [OpenMP] Always pass the optimization level to the linker wrapper

2023-08-18 Thread Joseph Huber 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 rG4ab4e40fa294: [OpenMP] Always pass the optimization level to 
the linker wrapper (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158298

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/amdgpu-openmp-toolchain.c


Index: clang/test/Driver/amdgpu-openmp-toolchain.c
===
--- clang/test/Driver/amdgpu-openmp-toolchain.c
+++ clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -70,3 +70,7 @@
 // RUN: not %clang -### -target x86_64-pc-linux-gnu -fopenmp 
--offload-arch=gfx90a,gfx90a:xnack+ \
 // RUN:   -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID-ERROR
 // CHECK-TARGET-ID-ERROR: error: invalid offload arch combinations: 'gfx90a' 
and 'gfx90a:xnack+'
+
+// RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a 
\
+// RUN:   -O3 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-OPT
+// CHECK-OPT: clang-linker-wrapper{{.*}}"--opt-level=O3"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -8619,24 +8619,22 @@
 }
   }
 
-  if (D.isUsingLTO(/* IsOffload */ true)) {
-// Pass in the optimization level to use for LTO.
-if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
-  StringRef OOpt;
-  if (A->getOption().matches(options::OPT_O4) ||
-  A->getOption().matches(options::OPT_Ofast))
-OOpt = "3";
-  else if (A->getOption().matches(options::OPT_O)) {
-OOpt = A->getValue();
-if (OOpt == "g")
-  OOpt = "1";
-else if (OOpt == "s" || OOpt == "z")
-  OOpt = "2";
-  } else if (A->getOption().matches(options::OPT_O0))
-OOpt = "0";
-  if (!OOpt.empty())
-CmdArgs.push_back(Args.MakeArgString(Twine("--opt-level=O") + OOpt));
-}
+  // Pass in the optimization level to use for LTO.
+  if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
+StringRef OOpt;
+if (A->getOption().matches(options::OPT_O4) ||
+A->getOption().matches(options::OPT_Ofast))
+  OOpt = "3";
+else if (A->getOption().matches(options::OPT_O)) {
+  OOpt = A->getValue();
+  if (OOpt == "g")
+OOpt = "1";
+  else if (OOpt == "s" || OOpt == "z")
+OOpt = "2";
+} else if (A->getOption().matches(options::OPT_O0))
+  OOpt = "0";
+if (!OOpt.empty())
+  CmdArgs.push_back(Args.MakeArgString(Twine("--opt-level=O") + OOpt));
   }
 
   CmdArgs.push_back(


Index: clang/test/Driver/amdgpu-openmp-toolchain.c
===
--- clang/test/Driver/amdgpu-openmp-toolchain.c
+++ clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -70,3 +70,7 @@
 // RUN: not %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a,gfx90a:xnack+ \
 // RUN:   -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID-ERROR
 // CHECK-TARGET-ID-ERROR: error: invalid offload arch combinations: 'gfx90a' and 'gfx90a:xnack+'
+
+// RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a \
+// RUN:   -O3 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-OPT
+// CHECK-OPT: clang-linker-wrapper{{.*}}"--opt-level=O3"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -8619,24 +8619,22 @@
 }
   }
 
-  if (D.isUsingLTO(/* IsOffload */ true)) {
-// Pass in the optimization level to use for LTO.
-if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
-  StringRef OOpt;
-  if (A->getOption().matches(options::OPT_O4) ||
-  A->getOption().matches(options::OPT_Ofast))
-OOpt = "3";
-  else if (A->getOption().matches(options::OPT_O)) {
-OOpt = A->getValue();
-if (OOpt == "g")
-  OOpt = "1";
-else if (OOpt == "s" || OOpt == "z")
-  OOpt = "2";
-  } else if (A->getOption().matches(options::OPT_O0))
-OOpt = "0";
-  if (!OOpt.empty())
-CmdArgs.push_back(Args.MakeArgString(Twine("--opt-level=O") + OOpt));
-}
+  // Pass in the optimization level to use for LTO.
+  if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
+StringRef OOpt;
+if (A->getOption().matches(options::OPT_O4) ||
+A->getOption().matches(options::OPT_Ofast))
+  OOpt = "3";
+else if (A->getOption().matches(options::OPT_O)) {
+  OOpt = A->getValue();
+  if (OOpt == "g")
+OOpt = "1";
+  else if (OOpt == "s" || OOpt == "z")
+OOpt = "2";
+} else if 

[clang] 4ab4e40 - [OpenMP] Always pass the optimization level to the linker wrapper

2023-08-18 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-08-18T17:10:13-05:00
New Revision: 4ab4e40fa2944bfd2ed44c63027e7a838043e0fd

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

LOG: [OpenMP] Always pass the optimization level to the linker wrapper

The linker wrapper runs LTO internally, so it needs to know the
optimization level the user requested, if any. Previously this was only
done in `-foffload-lto` mode as we were assuming that this would enble
LTO. However, AMDGPU always performs LTO, and it's possible to run clang
on object files to link without passing this flag. So we should just
respect it always.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/amdgpu-openmp-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index ed42eba0945ee5..8ac68df3b6db73 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8619,24 +8619,22 @@ void LinkerWrapper::ConstructJob(Compilation , const 
JobAction ,
 }
   }
 
-  if (D.isUsingLTO(/* IsOffload */ true)) {
-// Pass in the optimization level to use for LTO.
-if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
-  StringRef OOpt;
-  if (A->getOption().matches(options::OPT_O4) ||
-  A->getOption().matches(options::OPT_Ofast))
-OOpt = "3";
-  else if (A->getOption().matches(options::OPT_O)) {
-OOpt = A->getValue();
-if (OOpt == "g")
-  OOpt = "1";
-else if (OOpt == "s" || OOpt == "z")
-  OOpt = "2";
-  } else if (A->getOption().matches(options::OPT_O0))
-OOpt = "0";
-  if (!OOpt.empty())
-CmdArgs.push_back(Args.MakeArgString(Twine("--opt-level=O") + OOpt));
-}
+  // Pass in the optimization level to use for LTO.
+  if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
+StringRef OOpt;
+if (A->getOption().matches(options::OPT_O4) ||
+A->getOption().matches(options::OPT_Ofast))
+  OOpt = "3";
+else if (A->getOption().matches(options::OPT_O)) {
+  OOpt = A->getValue();
+  if (OOpt == "g")
+OOpt = "1";
+  else if (OOpt == "s" || OOpt == "z")
+OOpt = "2";
+} else if (A->getOption().matches(options::OPT_O0))
+  OOpt = "0";
+if (!OOpt.empty())
+  CmdArgs.push_back(Args.MakeArgString(Twine("--opt-level=O") + OOpt));
   }
 
   CmdArgs.push_back(

diff  --git a/clang/test/Driver/amdgpu-openmp-toolchain.c 
b/clang/test/Driver/amdgpu-openmp-toolchain.c
index acb175b8663607..06b6ed324e74ec 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -70,3 +70,7 @@
 // RUN: not %clang -### -target x86_64-pc-linux-gnu -fopenmp 
--offload-arch=gfx90a,gfx90a:xnack+ \
 // RUN:   -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID-ERROR
 // CHECK-TARGET-ID-ERROR: error: invalid offload arch combinations: 'gfx90a' 
and 'gfx90a:xnack+'
+
+// RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a 
\
+// RUN:   -O3 -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-OPT
+// CHECK-OPT: clang-linker-wrapper{{.*}}"--opt-level=O3"



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


[PATCH] D157757: [Headers] Replace __need_STDDEF_H_misc with specific __need_ macros

2023-08-18 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

This is going to be really naive, but can someone explain why we need these 
`__need_X` macros? Why doesn't `` simply always declare what it 
should declare? Also, does anybody understand the expected relationship between 
the C Standard Library headers and these Clang builtin headers? Who defines 
what?

Everyone I've spoken to so far about this (and myself) was extremely confused. 
At some point I thought these macros were only needed for compatibility with 
old glibcs but that wouldn't even be needed anymore, but I'm not certain.




Comment at: clang/lib/Headers/stddef.h:118-122
+#ifdef __cplusplus
+namespace std {
+typedef decltype(nullptr) nullptr_t;
+}
+using ::std::nullptr_t;

iana wrote:
> aaron.ballman wrote:
> > Related:
> > 
> > https://github.com/llvm/llvm-project/issues/37564
> > https://cplusplus.github.io/LWG/issue3484
> > 
> > CC @ldionne
> I don't _think_ this change actually changes the way nullptr_t gets defined 
> in C++, does it?
I think we absolutely don't want to touch `std::nullptr_t` from this header. 
It's libc++'s responsibility to define that, and in fact we define it in 
`std::__1`, so this is even an ABI break (or I guess it would be a compiler 
error, not sure).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157757

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-18 Thread Artem Labazov via Phabricator via cfe-commits
artem added inline comments.



Comment at: clang/test/ubsan/TestCases/Misc/abs.cpp:1
+// REQUIRES: arch=x86_64
+//

MaskRay wrote:
> Did you mean compiler-rt/ instead of clang/?
> 
> `// REQUIRES: arch=x86_64` is legacy style.
> 
> New style uses `// REQUIRES: target={{x86_64.*}}`
> 
> Actually, this test should be generic and we should remove REQUIRES.
I think that Aaron has moved the file when committed to the main branch. 
Anyway, moved.


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

https://reviews.llvm.org/D156821

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-18 Thread Artem Labazov via Phabricator via cfe-commits
artem updated this revision to Diff 551656.
artem marked 2 inline comments as done.
artem added a comment.

Fixed the comments. I do not have commit rights


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

https://reviews.llvm.org/D156821

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/abs-overflow.c
  compiler-rt/test/ubsan/TestCases/Misc/abs.cpp

Index: compiler-rt/test/ubsan/TestCases/Misc/abs.cpp
===
--- /dev/null
+++ compiler-rt/test/ubsan/TestCases/Misc/abs.cpp
@@ -0,0 +1,28 @@
+// RUN: %clangxx -fsanitize=signed-integer-overflow -w %s -O3 -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER
+//
+// RUN: %clangxx -fsanitize=signed-integer-overflow -fno-sanitize-recover=signed-integer-overflow -w %s -O3 -o %t.abort
+// RUN: not %run %t.abort 2>&1 | FileCheck %s --check-prefix=ABORT
+
+#include 
+#include 
+
+int main() {
+  // ABORT: abs.cpp:[[@LINE+3]]:17: runtime error: negation of -{{[0-9]+}} cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself
+  // RECOVER: abs.cpp:[[@LINE+2]]:17: runtime error: negation of -{{[0-9]+}} cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself
+  // RECOVER: abs.cpp:[[@LINE+2]]:7: runtime error: negation of -{{[0-9]+}} cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself
+  __builtin_abs(INT_MIN);
+  abs(INT_MIN);
+
+  // RECOVER: abs.cpp:[[@LINE+2]]:18: runtime error: negation of -{{[0-9]+}} cannot be represented in type 'long'; cast to an unsigned type to negate this value to itself
+  // RECOVER: abs.cpp:[[@LINE+2]]:8: runtime error: negation of -{{[0-9]+}} cannot be represented in type 'long'; cast to an unsigned type to negate this value to itself
+  __builtin_labs(LONG_MIN);
+  labs(LONG_MIN);
+
+  // RECOVER: abs.cpp:[[@LINE+2]]:19: runtime error: negation of -{{[0-9]+}} cannot be represented in type 'long long'; cast to an unsigned type to negate this value to itself
+  // RECOVER: abs.cpp:[[@LINE+2]]:9: runtime error: negation of -{{[0-9]+}} cannot be represented in type 'long long'; cast to an unsigned type to negate this value to itself
+  __builtin_llabs(LLONG_MIN);
+  llabs(LLONG_MIN);
+
+  return 0;
+}
Index: clang/test/CodeGen/abs-overflow.c
===
--- /dev/null
+++ clang/test/CodeGen/abs-overflow.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - -fwrapv -fsanitize=signed-integer-overflow | FileCheck %s --check-prefix=WRAPV
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - -ftrapv | FileCheck %s --check-prefixes=BOTH-TRAP,TRAPV
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - -fsanitize=signed-integer-overflow | FileCheck %s --check-prefixes=BOTH-TRAP,CATCH_UB
+// COM: TODO: Support -ftrapv-handler.
+
+extern int abs(int x);
+
+int absi(int x) {
+// WRAPV:   [[NEG:%.*]] = sub i32 0, [[X:%.*]]
+// WRAPV:   [[CMP:%.*]] = icmp slt i32 [[X]], 0
+// WRAPV:   [[SEL:%.*]] = select i1 [[CMP]], i32 [[NEG]], i32 [[X]]
+//
+// BOTH-TRAP:   [[NEG:%.*]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 0, i32 [[X:%.*]])
+// BOTH-TRAP:   [[NEGV:%.*]] = extractvalue { i32, i1 } [[NEG]], 0
+// BOTH-TRAP:   [[OFL:%.*]] = extractvalue { i32, i1 } [[NEG]], 1
+// BOTH-TRAP:   [[NOFL:%.*]] = xor i1 [[OFL]], true
+// BOTH-TRAP:   br i1 [[NOFL]], label %[[CONT:.*]], label %[[TRAP:[a-zA-Z_.]*]]
+// BOTH-TRAP:   [[TRAP]]:
+// TRAPV-NEXT:llvm.ubsantrap
+// CATCH_UB:  @__ubsan_handle_negate_overflow
+// BOTH-TRAP-NEXT:unreachable
+// BOTH-TRAP:   [[CONT]]:
+// BOTH-TRAP-NEXT:[[ABSCOND:%.*]] = icmp slt i32 [[X]], 0
+// BOTH-TRAP-NEXT:select i1 [[ABSCOND]], i32 [[NEGV]], i32 [[X]]
+  return abs(x);
+}
+
+int babsi(int x) {
+// WRAPV:   [[NEG:%.*]] = sub i32 0, [[X:%.*]]
+// WRAPV:   [[CMP:%.*]] = icmp slt i32 [[X]], 0
+// WRAPV:   [[SEL:%.*]] = select i1 [[CMP]], i32 [[NEG]], i32 [[X]]
+//
+// BOTH-TRAP:   [[NEG:%.*]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 0, i32 [[X:%.*]])
+// BOTH-TRAP:   [[NEGV:%.*]] = extractvalue { i32, i1 } [[NEG]], 0
+// BOTH-TRAP:   [[OFL:%.*]] = extractvalue { i32, i1 } [[NEG]], 1
+// BOTH-TRAP:   [[NOFL:%.*]] = xor i1 [[OFL]], true
+// BOTH-TRAP:   br i1 [[NOFL]], label %[[CONT:.*]], label %[[TRAP:[a-zA-Z_.]*]]
+// BOTH-TRAP:   [[TRAP]]:
+// TRAPV-NEXT:llvm.ubsantrap
+// CATCH_UB:  @__ubsan_handle_negate_overflow
+// BOTH-TRAP-NEXT:unreachable
+// BOTH-TRAP:   [[CONT]]:
+// BOTH-TRAP-NEXT:[[ABSCOND:%.*]] = icmp slt i32 [[X]], 0
+// BOTH-TRAP-NEXT:select i1 [[ABSCOND]], i32 [[NEGV]], i32 [[X]]
+  return __builtin_abs(x);
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- 

[PATCH] D158318: [Sema] tolerate more promotion matches in format string checking

2023-08-18 Thread Félix Cloutier via Phabricator via cfe-commits
fcloutier created this revision.
fcloutier added a reviewer: aaron.ballman.
Herald added a project: All.
fcloutier requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It's been reported that when using __attribute__((format)) on non-variadic 
functions, certain values that normally get promoted when passed as variadic 
arguments now unconditionally emit a diagnostic:

  c
  void foo(const char *fmt, float f) __attribute__((format(printf, 1, 2)));
  void bar(void) {
foo("%g", 123.f);
//   ^ format specifies type 'double' but the argument has type 'float'
  }

This is normally not an issue because float values get promoted to doubles when 
passed as variadic arguments, but needless to say, variadic argument promotion 
does not apply to non-variadic arguments.

While this can be fixed by adjusting the prototype of `foo`, this is sometimes 
undesirable in C (for instance, if `foo` is ABI). In C++, using variadic 
templates, this might instead require call-site fixing, which is tedious and 
arguably needless work:

  c++
  template
  void foo(const char *fmt, Args &&...args) __attribute__((format(printf, 1, 
2)));
  void bar(void) {
foo("%g", 123.f);
//   ^ format specifies type 'double' but the argument has type 'float'
  }

To address this issue, we teach FormatString about a few promotions that have 
always been around but that have never been exercised in the direction that 
FormatString checks for:

- `char`, `unsigned char` -> `int`, `unsigned`
- `half`, `float16`, `float` -> `double`

This addresses issue https://github.com/llvm/llvm-project/issues/59824.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158318

Files:
  clang/lib/AST/FormatString.cpp
  clang/test/Sema/attr-format.c
  clang/test/SemaCXX/attr-format.cpp


Index: clang/test/SemaCXX/attr-format.cpp
===
--- clang/test/SemaCXX/attr-format.cpp
+++ clang/test/SemaCXX/attr-format.cpp
@@ -78,6 +78,9 @@
   format("%s %s %u %d %i %p\n", "hello", s, 10u, x, y, do_format);
   format("bad format %s"); // expected-warning{{more '%' conversions than data 
arguments}}
 
+  format("%c %c %hhd %hd %d\n", (char)'a', 'a', 'a', (short)123, (int)123);
+  format("%f %f %f\n", (__fp16)123.f, 123.f, 123.);
+
   struct foo f;
   format_invalid_nonpod("hello %i", f); // expected-warning{{format specifies 
type 'int' but the argument has type 'struct foo'}}
 
Index: clang/test/Sema/attr-format.c
===
--- clang/test/Sema/attr-format.c
+++ clang/test/Sema/attr-format.c
@@ -94,13 +94,9 @@
   d3("%s", 123); // expected-warning{{format specifies type 'char *' but the 
argument has type 'int'}}
 }
 
-__attribute__((format(printf, 1, 2))) void forward_fixed(const char *fmt, int 
i) { // expected-warning{{GCC requires a function with the 'format' attribute 
to be variadic}}
-  forward_fixed(fmt, i);
-  a(fmt, i);
-}
-
-__attribute__((format(printf, 1, 2))) void forward_fixed_2(const char *fmt, 
int i, int j) { // expected-warning{{GCC requires a function with the 'format' 
attribute to be variadic}}
-  forward_fixed_2(fmt, i, j);
-  a(fmt, i);
+__attribute__((format(printf, 1, 2)))
+void forward_fixed(const char *fmt, char i, short j, int k, float l, double m) 
{ // expected-warning{{GCC requires a function with the 'format' attribute to 
be variadic}}
+  forward_fixed(fmt, i, j, k, l, m);
+  a(fmt, i, j, k, l, m);
 }
 
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -465,6 +465,24 @@
   T == C.WideCharTy)
 return MatchPromotion;
   break;
+case BuiltinType::Char_U:
+  if (T == C.UnsignedIntTy)
+return MatchPromotion;
+  if (T == C.UnsignedShortTy)
+return NoMatchPromotionTypeConfusion;
+  break;
+case BuiltinType::Char_S:
+  if (T == C.IntTy)
+return MatchPromotion;
+  if (T == C.ShortTy)
+return NoMatchPromotionTypeConfusion;
+  break;
+case BuiltinType::Half:
+case BuiltinType::Float16:
+case BuiltinType::Float:
+  if (T == C.DoubleTy)
+return MatchPromotion;
+  break;
 case BuiltinType::Short:
 case BuiltinType::UShort:
   if (T == C.SignedCharTy || T == C.UnsignedCharTy)


Index: clang/test/SemaCXX/attr-format.cpp
===
--- clang/test/SemaCXX/attr-format.cpp
+++ clang/test/SemaCXX/attr-format.cpp
@@ -78,6 +78,9 @@
   format("%s %s %u %d %i %p\n", "hello", s, 10u, x, y, do_format);
   format("bad format %s"); // expected-warning{{more '%' 

[clang] 3364d76 - [clang-format][doc] Don't use the ".0" suffix on version numbers

2023-08-18 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-08-18T14:57:43-07:00
New Revision: 3364d7620ef78c6e9f04c63e62ac6b0801090ea5

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

LOG: [clang-format][doc] Don't use the ".0" suffix on version numbers

Fixes #64818.

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6f02a436b0ac81..651fa4436dfe78 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3832,7 +3832,7 @@ the configuration (without a prefix: ``Auto``).
 
 .. _Macros:
 
-**Macros** (``List of Strings``) :versionbadge:`clang-format 17.0` :ref:`¶ 
`
+**Macros** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ 
`
   A list of macros of the form ``=`` .
 
   Code will be parsed with macros expanded, in order to determine how to

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 8bcf6e6f58f162..192cc68e51fad7 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2963,7 +2963,7 @@ struct FormatStyle {
   ///A(a, b); // will not be expanded.
   /// \endcode
   ///
-  /// \version 17.0
+  /// \version 17
   std::vector Macros;
 
   /// The maximum number of consecutive empty lines to keep.



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


[PATCH] D153156: [Clang] CWG1473: do not err on the lack of space after operator""

2023-08-18 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht added a comment.

In D153156#4600270 , @rupprecht wrote:

> of which there's an example in LLVM itself: 
> https://github.com/llvm/llvm-project/blob/6a0e536ccfef1f7bd64ee4153b4efc0aeecf28d4/clang/test/SemaCXX/cxx11-compat.cpp#L38

Sorry, I don't want to mislead: I just mean there's a handy example in clang's 
unit tests. I don't see any instances of this in LLVM non-test code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153156

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


[PATCH] D153156: [Clang] CWG1473: do not err on the lack of space after operator""

2023-08-18 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht added a comment.

The other common breakage I'm seeing is code that hasn't yet migrated from the 
"PRI" format macros, of which there's an example in LLVM itself: 
https://github.com/llvm/llvm-project/blob/6a0e536ccfef1f7bd64ee4153b4efc0aeecf28d4/clang/test/SemaCXX/cxx11-compat.cpp#L38

e.g.: https://godbolt.org/z/v3boc9E6T

> IMHO, people should stop using -Wno-reserved-user-defined-literal and 
> exploiting the addition of a whitespace to mingle pre-c++11 and post-c++11 
> code.

I mostly agree with this, at least the spirit of it, but do we usually remove 
the `-Wno` ability to suppress a common error because we don't like it? (Or 
justify it post-facto if we accidentally did that?) If removing this is 
important for some other aspect of clang development, it would be nice to have 
notice ahead of time that this option will go away. I guess +1 to what James 
said.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153156

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


[PATCH] D158238: Implement __builtin_fmaximum/fminimum*

2023-08-18 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 551646.
tra added a comment.

Fixed test RUN lines


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158238

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins.c
  clang/test/CodeGen/math-builtins.c
  clang/test/Sema/constant-builtins-fmaximum.cpp
  clang/test/Sema/constant-builtins-fminimum.cpp
  clang/test/Sema/overloaded-math-builtins.c

Index: clang/test/Sema/overloaded-math-builtins.c
===
--- clang/test/Sema/overloaded-math-builtins.c
+++ clang/test/Sema/overloaded-math-builtins.c
@@ -19,3 +19,21 @@
   int *r6 = __builtin_fminf(f, v);
   // expected-error@-1 {{passing 'float4' (vector of 4 'float' values) to parameter of incompatible type 'float'}}
 }
+
+float test_fminimumf(float f, int i, int *ptr, float4 v) {
+  float r1 = __builtin_fminimumf(f, ptr);
+  // expected-error@-1 {{passing 'int *' to parameter of incompatible type 'float'}}
+  float r2 = __builtin_fminimumf(ptr, f);
+  // expected-error@-1 {{passing 'int *' to parameter of incompatible type 'float'}}
+  float r3 = __builtin_fminimumf(v, f);
+  // expected-error@-1 {{passing 'float4' (vector of 4 'float' values) to parameter of incompatible type 'float'}}
+  float r4 = __builtin_fminimumf(f, v);
+  // expected-error@-1 {{passing 'float4' (vector of 4 'float' values) to parameter of incompatible type 'float'}}
+
+
+  int *r5 = __builtin_fminimumf(f, f);
+  // expected-error@-1 {{initializing 'int *' with an expression of incompatible type 'float'}}
+
+  int *r6 = __builtin_fminimumf(f, v);
+  // expected-error@-1 {{passing 'float4' (vector of 4 'float' values) to parameter of incompatible type 'float'}}
+}
Index: clang/test/Sema/constant-builtins-fminimum.cpp
===
--- /dev/null
+++ clang/test/Sema/constant-builtins-fminimum.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
+// expected-no-diagnostics
+
+constexpr double NaN = __builtin_nan("");
+constexpr double Inf = __builtin_inf();
+constexpr double NegInf = -__builtin_inf();
+
+#define FMIN_TEST_SIMPLE(T, FUNC)  \
+  static_assert(T(1.2345) == FUNC(T(1.2345), T(6.7890)));  \
+  static_assert(T(1.2345) == FUNC(T(6.7890), T(1.2345)));
+
+#define FMIN_TEST_NAN(T, FUNC) \
+  static_assert(__builtin_isnan(FUNC(NaN, Inf)));  \
+  static_assert(__builtin_isnan(FUNC(NegInf, NaN)));   \
+  static_assert(__builtin_isnan(FUNC(NaN, 0.0)));  \
+  static_assert(__builtin_isnan(FUNC(-0.0, NaN))); \
+  static_assert(__builtin_isnan(FUNC(NaN, T(-1.2345;   \
+  static_assert(__builtin_isnan(FUNC(T(1.2345), NaN)));\
+  static_assert(__builtin_isnan(FUNC(NaN, NaN)));
+
+#define FMIN_TEST_INF(T, FUNC) \
+  static_assert(NegInf == FUNC(NegInf, Inf));  \
+  static_assert(0.0 == FUNC(Inf, 0.0));\
+  static_assert(-0.0 == FUNC(-0.0, Inf));  \
+  static_assert(T(1.2345) == FUNC(Inf, T(1.2345)));\
+  static_assert(T(-1.2345) == FUNC(T(-1.2345), Inf));
+
+#define FMIN_TEST_NEG_INF(T, FUNC) \
+  static_assert(NegInf == FUNC(Inf, NegInf));  \
+  static_assert(NegInf == FUNC(NegInf, 0.0));  \
+  static_assert(NegInf == FUNC(-0.0, NegInf)); \
+  static_assert(NegInf == FUNC(NegInf, T(-1.2345)));   \
+  static_assert(NegInf == FUNC(T(1.2345), NegInf));
+
+#define FMIN_TEST_BOTH_ZERO(T, FUNC)   \
+  static_assert(__builtin_copysign(1.0, FUNC(0.0, 0.0)) == 1.0);   \
+  static_assert(__builtin_copysign(1.0, FUNC(-0.0, 0.0)) == -1.0); \
+  static_assert(__builtin_copysign(1.0, FUNC(0.0, -0.0)) == -1.0); \
+  static_assert(__builtin_copysign(1.0, FUNC(-0.0, -0.0)) == -1.0);
+
+#define LIST_FMIN_TESTS(T, FUNC)   \
+  FMIN_TEST_SIMPLE(T, FUNC)\
+  FMIN_TEST_NAN(T, FUNC)   \
+  FMIN_TEST_INF(T, FUNC)   \
+  FMIN_TEST_NEG_INF(T, FUNC)

[PATCH] D158293: [NFC][CLANG] Fix potential dereferencing of null return values

2023-08-18 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2009-2010
(Line.MightBeFunctionDecl || Line.InPPDirective) &&
-   Current.NestingLevel == 0 &&
+   Current.NestingLevel == 0 && Current.Previous &&
!Current.Previous->isOneOf(tok::kw_operator, tok::identifier)) {
   // not auto operator->() -> xxx;

owenpan wrote:
> `Current.Previous` can't be null here because `AutoFound` is `true`.
Could you please elaborate on why you believe it is safe to move the check of 
`Current.Previous` inside the body of the `if` statement? Doing so will short 
circuit the remaining `else if` cases such that `Current.setType()` will not be 
called at all. It isn't obvious to me that those cases should not be considered 
if the previous token was not one of `kw_operator` or `identifier`. This looks 
like it has potential to change behavior.

The change that was originally proposed is clearly safe.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158293

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


[PATCH] D157579: [clang][ExtractAPI] Add support for C++ global function templates

2023-08-18 Thread Erick Velez via Phabricator via cfe-commits
evelez7 updated this revision to Diff 551642.
evelez7 added a comment.

Formatting changes, keep GlobalFunction has templates together and revert 
extraneous formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157579

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/global_func_template.cpp
  clang/test/ExtractAPI/global_func_template_spec.cpp

Index: clang/test/ExtractAPI/global_func_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/global_func_template_spec.cpp
@@ -0,0 +1,299 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template void Foo(T Bar);
+
+template<> void Foo(int Bar);
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:v",
+  "spelling": "void"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": "("
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "internalParam",
+  "spelling": "Bar"
+},
+{
+  "kind": "text",
+  "spelling": ");"
+}
+  ],
+  "functionSignature": {
+"parameters": [
+  {
+"declarationFragments": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:t0.0",
+"spelling": "T"
+  },
+  {
+"kind": "text",
+"spelling": " "
+  },
+  {
+"kind": "internalParam",
+"spelling": "Bar"
+  }
+],
+"name": "Bar"
+  }
+],
+"returns": [
+  {
+"kind": "typeIdentifier",
+"preciseIdentifier": "c:v",
+"spelling": "void"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@FT@>1#TFoo#t0.0#v#"
+  },
+  "kind": {
+"displayName": "Function Template",
+"identifier": "c++.func"
+  },
+  "location": {
+"position": {
+  "character": 27,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  

[PATCH] D158008: [AArch64] Add patterns for FMADD, FMSUB

2023-08-18 Thread Vladislav Dzhidzhoev via Phabricator via cfe-commits
dzhidzhoev added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64InstrFormats.td:5381-5393
+  let Predicates = [HasFullFP16] in {
+  def : Pat<(f16 (node (f16 FPR16:$Rn),
+   (f16 (vector_extract (v8f16 V128:$Rm), (i64 0))),
+   (f16 FPR16:$Ra))),
+(!cast(NAME # Hrrr)
+  FPR16:$Rn, (EXTRACT_SUBREG V128:$Rm, hsub), FPR16:$Ra)>;
+

The result type of (EXTRACT_SUBREG ...) here seems to be deduced to i16, which 
causes an assertion after applying this rule.
Explicit specification of the result type fixes crashes of tests:

```
FPR16:$Rn, (f16 (EXTRACT_SUBREG V128:$Rm, hsub)), FPR16:$Ra)>;
```

```
(f16 (EXTRACT_SUBREG V128:$Rn, hsub)), FPR16:$Rm, FPR16:$Ra)>
```


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

https://reviews.llvm.org/D158008

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-18 Thread Thurston Dang via Phabricator via cfe-commits
thurston added a comment.

In D156821#4600086 , @MaskRay wrote:

>   Failed Tests (4):
> LLVM :: CodeGen/RISCV/rvv/fixed-vectors-int.ll
> LLVM :: CodeGen/SystemZ/ctpop-01.ll
> LLVM :: MC/ARM/basic-thumb2-instructions.s
> LLVM :: tools/llvm-readobj/ELF/relocations.test
>
> AFAICT these failures have been fixed and the change can reland after the 
> clang/ test is fixed.

+1. Thanks @MaskRay for fixing the `MC/ARM/basic-thumb2-instructions.s` and 
`tools/llvm-readobj/ELF/relocations.test` cases!

(For completeness, for anyone else following this discussion: the 
`CodeGen/SystemZ/ctpop-01.ll` failure is unrelated to this patch; it was 
reverted in https://reviews.llvm.org/rG29b200906155da393b83232dd31d746ba2ad66a5)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156821

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


[PATCH] D158231: [clang][test] Fix clang machine-function-split tests

2023-08-18 Thread Han Shen via Phabricator via cfe-commits
shenhan updated this revision to Diff 551634.
shenhan marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158231

Files:
  clang/test/CodeGen/fsplit-machine-functions.c
  clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
  clang/test/Driver/fsplit-machine-functions.c
  llvm/test/CodeGen/Generic/machine-function-splitter.ll

Index: llvm/test/CodeGen/Generic/machine-function-splitter.ll
===
--- llvm/test/CodeGen/Generic/machine-function-splitter.ll
+++ llvm/test/CodeGen/Generic/machine-function-splitter.ll
@@ -16,10 +16,10 @@
 
 ;; Check that MFS is on for X86 targets.
 ; MFS_ON: Machine Function Splitter Transformation
-; MFS_ON_NO: warning: -fsplit-machine-functions is not valid for
+; MFS_ON-NOT: warning:
 ;; Check that MFS is not on for non-X86 targets.
 ; MFS_OFF: warning: -fsplit-machine-functions is not valid for
-; MFS_OFF_NO: Machine Function Splitter Transformation
+; MFS_OFF-NOT: Machine Function Splitter Transformation
 
 define void @foo1(i1 zeroext %0) nounwind !prof !14 !section_prefix !15 {
 ;; Check that cold block is moved to .text.split.
Index: clang/test/Driver/fsplit-machine-functions.c
===
--- clang/test/Driver/fsplit-machine-functions.c
+++ clang/test/Driver/fsplit-machine-functions.c
@@ -1,10 +1,5 @@
-// REQUIRES: arm-registered-target
+// RUN: %clang -### --target=x86_64 -fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK_OPT %s
+// RUN: %clang -### --target=x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK_NOOPT %s
 
-// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
-// RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
-// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
-// RUN: %clang -c -target arm-unknown-linux-gnueabi -fsplit-machine-functions %s -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
-
-// CHECK-OPT:   "-fsplit-machine-functions"
-// CHECK-NOOPT-NOT: "-fsplit-machine-functions"
-// CHECK-TRIPLE:warning: -fsplit-machine-functions is not valid for arm
+// CHECK_OPT:"-fsplit-machine-functions"
+// CHECK_NOOPT-NOT:  "-fsplit-machine-functions"
Index: clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
===
--- clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
+++ clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
@@ -1,68 +1,28 @@
-// REQUIRES: system-linux
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
-// REQUIRES: shell
 
 // Check that -fsplit-machine-functions is passed to both x86 and cuda
 // compilation and does not cause driver error.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
 // RUN: 2>&1 | FileCheck %s --check-prefix=MFS1
 // MFS1: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
 // MFS1: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
 
-// Check that -fsplit-machine-functions is passed to cuda and it
-// causes a warning.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
-// RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS2
-// MFS2: warning: -fsplit-machine-functions is not valid for nvptx
-
 // Check that -Xarch_host -fsplit-machine-functions is passed only to
 // native compilation.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
 // RUN: -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS3
-// MFS3: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
-// MFS3-NOT: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
-
-// Check that -Xarch_host -fsplit-machine-functions does not cause any warning.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
-// RUN  --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
-// RUN  -fsplit-machine-functions -S %s || { echo \
-// RUN  "warning: 

[PATCH] D157350: [clang][ExtractAPI] Add support for C++ variable templates

2023-08-18 Thread Erick Velez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8d8c8981cac0: [clang][ExtractAPI] Add support for C++ 
variable templates (authored by evelez7).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157350

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/global_var_template.cpp
  clang/test/ExtractAPI/global_var_template_partial_spec.cpp
  clang/test/ExtractAPI/global_var_template_spec.cpp

Index: clang/test/ExtractAPI/global_var_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/global_var_template_spec.cpp
@@ -0,0 +1,207 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template T Foo = T(3.14);
+
+template<> int Foo;
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:t0.0",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@Foo"
+  },
+  "kind": {
+"displayName": "Global Variable Template",
+"identifier": "c++.var"
+  },
+  "location": {
+"position": {
+  "character": 24,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<> "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": ">;"
+}
+  ],
+  "identifier": {
+

[clang] 8d8c898 - [clang][ExtractAPI] Add support for C++ variable templates

2023-08-18 Thread Erick Velez via cfe-commits

Author: Erick Velez
Date: 2023-08-18T13:57:02-07:00
New Revision: 8d8c8981cac0e548f0fca1268d6e501431564f66

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

LOG: [clang][ExtractAPI] Add support for C++ variable templates

Serialize global C++ variable templates and specializations.

Depends on D157076

Reviewed By: dang

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

Added: 
clang/test/ExtractAPI/global_var_template.cpp
clang/test/ExtractAPI/global_var_template_partial_spec.cpp
clang/test/ExtractAPI/global_var_template_spec.cpp

Modified: 
clang/include/clang/ExtractAPI/API.h
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/lib/ExtractAPI/API.cpp
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index 83ff982be559b9..7846ad14127fe4 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -99,6 +99,24 @@ class Template {
 }
   }
 
+  Template(const VarTemplatePartialSpecializationDecl *Decl) {
+for (auto *const Parameter : *Decl->getTemplateParameters()) {
+  const auto *Param = dyn_cast(Parameter);
+  if (!Param) // some params are null
+continue;
+  std::string Type;
+  if (Param->hasTypeConstraint())
+Type = Param->getTypeConstraint()->getNamedConcept()->getName().str();
+  else if (Param->wasDeclaredWithTypename())
+Type = "typename";
+  else
+Type = "class";
+
+  addTemplateParameter(Type, Param->getName().str(), Param->getIndex(),
+   Param->getDepth(), Param->isParameterPack());
+}
+  }
+
   const llvm::SmallVector () const {
 return Parameters;
   }
@@ -141,6 +159,9 @@ struct APIRecord {
 RK_Unknown,
 RK_GlobalFunction,
 RK_GlobalVariable,
+RK_GlobalVariableTemplate,
+RK_GlobalVariableTemplateSpecialization,
+RK_GlobalVariableTemplatePartialSpecialization,
 RK_EnumConstant,
 RK_Enum,
 RK_StructField,
@@ -279,6 +300,14 @@ struct GlobalVariableRecord : APIRecord {
   Linkage, Comment, Declaration, SubHeading,
   IsFromSystemHeader) {}
 
+  GlobalVariableRecord(RecordKind Kind, StringRef USR, StringRef Name,
+   PresumedLoc Loc, AvailabilitySet Availabilities,
+   LinkageInfo Linkage, const DocComment ,
+   DeclarationFragments Declaration,
+   DeclarationFragments SubHeading, bool 
IsFromSystemHeader)
+  : APIRecord(Kind, USR, Name, Loc, std::move(Availabilities), Linkage,
+  Comment, Declaration, SubHeading, IsFromSystemHeader) {}
+
   static bool classof(const APIRecord *Record) {
 return Record->getKind() == RK_GlobalVariable;
   }
@@ -287,6 +316,61 @@ struct GlobalVariableRecord : APIRecord {
   virtual void anchor();
 };
 
+struct GlobalVariableTemplateRecord : GlobalVariableRecord {
+  Template Templ;
+
+  GlobalVariableTemplateRecord(StringRef USR, StringRef Name, PresumedLoc Loc,
+   AvailabilitySet Availabilities,
+   LinkageInfo Linkage, const DocComment ,
+   DeclarationFragments Declaration,
+   DeclarationFragments SubHeading,
+   class Template Template, bool 
IsFromSystemHeader)
+  : GlobalVariableRecord(RK_GlobalVariableTemplate, USR, Name, Loc,
+ std::move(Availabilities), Linkage, Comment,
+ Declaration, SubHeading, IsFromSystemHeader),
+Templ(Template) {}
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() == RK_GlobalVariableTemplate;
+  }
+};
+
+struct GlobalVariableTemplateSpecializationRecord : GlobalVariableRecord {
+  GlobalVariableTemplateSpecializationRecord(
+  StringRef USR, StringRef Name, PresumedLoc Loc,
+  AvailabilitySet Availabilities, LinkageInfo Linkage,
+  const DocComment , DeclarationFragments Declaration,
+  DeclarationFragments SubHeading, bool IsFromSystemHeader)
+  : GlobalVariableRecord(RK_GlobalVariableTemplateSpecialization, USR, 
Name,
+ Loc, std::move(Availabilities), Linkage, Comment,
+ Declaration, SubHeading, IsFromSystemHeader) {}
+
+  static bool classof(const APIRecord *Record) {
+return Record->getKind() 

[PATCH] D158231: [clang][test] Fix clang machine-function-split tests

2023-08-18 Thread Han Shen via Phabricator via cfe-commits
shenhan added inline comments.



Comment at: clang/test/CodeGen/fsplit-machine-functions.c:1
+// REQUIRES: system-linux
+// REQUIRES: x86-registered-target

MaskRay wrote:
> Any reason `system-linux` is needed?
Deleted. Also deleted "REQUIRES: system-linux" from 
"fsplit-machine-functions-with-cuda-nvptx.c".



Comment at: clang/test/CodeGen/fsplit-machine-functions.c:2
+// REQUIRES: system-linux
+// REQUIRES: x86-registered-target
+// REQUIRES: arm-registered-target

MaskRay wrote:
> We usually place x86 tests under CodeGen/X86 and arm tests under CodeGen/ARM
I can moved the X86 cases to clang/test/CodeGen/X86, but there is no 
clang/test/CodeGen/Arm or similar, shall I create "clang/test/CodeGen/Arm" 
instead? 



Comment at: clang/test/Driver/fsplit-machine-functions.c:1
-// REQUIRES: arm-registered-target
+// REQUIRES: x86-registered-target
 

MaskRay wrote:
> If you only use `-###`, `// REQUIRES: x86-registered-target` is unneeded.
Ah, yes. Deleted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158231

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


[PATCH] D158231: [clang][test] Fix clang machine-function-split tests

2023-08-18 Thread Han Shen via Phabricator via cfe-commits
shenhan updated this revision to Diff 551632.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158231

Files:
  clang/test/CodeGen/fsplit-machine-functions.c
  clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
  clang/test/Driver/fsplit-machine-functions.c
  llvm/test/CodeGen/Generic/machine-function-splitter.ll

Index: llvm/test/CodeGen/Generic/machine-function-splitter.ll
===
--- llvm/test/CodeGen/Generic/machine-function-splitter.ll
+++ llvm/test/CodeGen/Generic/machine-function-splitter.ll
@@ -16,10 +16,11 @@
 
 ;; Check that MFS is on for X86 targets.
 ; MFS_ON: Machine Function Splitter Transformation
-; MFS_ON_NO: warning: -fsplit-machine-functions is not valid for
+; MFS_ON-NOT: warning: -fsplit-machine-functions is not valid for
+; MFS_ON-NOT: warning:
 ;; Check that MFS is not on for non-X86 targets.
 ; MFS_OFF: warning: -fsplit-machine-functions is not valid for
-; MFS_OFF_NO: Machine Function Splitter Transformation
+; MFS_OFF-NOT: Machine Function Splitter Transformation
 
 define void @foo1(i1 zeroext %0) nounwind !prof !14 !section_prefix !15 {
 ;; Check that cold block is moved to .text.split.
Index: clang/test/Driver/fsplit-machine-functions.c
===
--- clang/test/Driver/fsplit-machine-functions.c
+++ clang/test/Driver/fsplit-machine-functions.c
@@ -1,10 +1,5 @@
-// REQUIRES: arm-registered-target
+// RUN: %clang -### --target=x86_64 -fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK_OPT %s
+// RUN: %clang -### --target=x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK_NOOPT %s
 
-// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
-// RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
-// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
-// RUN: %clang -c -target arm-unknown-linux-gnueabi -fsplit-machine-functions %s -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
-
-// CHECK-OPT:   "-fsplit-machine-functions"
-// CHECK-NOOPT-NOT: "-fsplit-machine-functions"
-// CHECK-TRIPLE:warning: -fsplit-machine-functions is not valid for arm
+// CHECK_OPT:"-fsplit-machine-functions"
+// CHECK_NOOPT-NOT:  "-fsplit-machine-functions"
Index: clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
===
--- clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
+++ clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
@@ -1,68 +1,28 @@
-// REQUIRES: system-linux
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
-// REQUIRES: shell
 
 // Check that -fsplit-machine-functions is passed to both x86 and cuda
 // compilation and does not cause driver error.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
 // RUN: 2>&1 | FileCheck %s --check-prefix=MFS1
 // MFS1: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
 // MFS1: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
 
-// Check that -fsplit-machine-functions is passed to cuda and it
-// causes a warning.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
-// RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS2
-// MFS2: warning: -fsplit-machine-functions is not valid for nvptx
-
 // Check that -Xarch_host -fsplit-machine-functions is passed only to
 // native compilation.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
 // RUN: -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS3
-// MFS3: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
-// MFS3-NOT: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
-
-// Check that -Xarch_host -fsplit-machine-functions does not cause any warning.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
-// RUN  --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
-// RUN  -fsplit-machine-functions -S %s || { echo \
-// RUN  

[PATCH] D158231: [clang][test] Fix clang machine-function-split tests

2023-08-18 Thread Han Shen via Phabricator via cfe-commits
shenhan updated this revision to Diff 551630.
shenhan marked 3 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158231

Files:
  clang/test/CodeGen/fsplit-machine-functions.c
  clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
  clang/test/Driver/fsplit-machine-functions.c
  llvm/test/CodeGen/Generic/machine-function-splitter.ll

Index: llvm/test/CodeGen/Generic/machine-function-splitter.ll
===
--- llvm/test/CodeGen/Generic/machine-function-splitter.ll
+++ llvm/test/CodeGen/Generic/machine-function-splitter.ll
@@ -16,10 +16,11 @@
 
 ;; Check that MFS is on for X86 targets.
 ; MFS_ON: Machine Function Splitter Transformation
-; MFS_ON_NO: warning: -fsplit-machine-functions is not valid for
+; MFS_ON-NOT: warning: -fsplit-machine-functions is not valid for
+; MFS_ON-NOT: warning:
 ;; Check that MFS is not on for non-X86 targets.
 ; MFS_OFF: warning: -fsplit-machine-functions is not valid for
-; MFS_OFF_NO: Machine Function Splitter Transformation
+; MFS_OFF-NOT: Machine Function Splitter Transformation
 
 define void @foo1(i1 zeroext %0) nounwind !prof !14 !section_prefix !15 {
 ;; Check that cold block is moved to .text.split.
Index: clang/test/Driver/fsplit-machine-functions.c
===
--- clang/test/Driver/fsplit-machine-functions.c
+++ clang/test/Driver/fsplit-machine-functions.c
@@ -1,10 +1,5 @@
-// REQUIRES: arm-registered-target
+// RUN: %clang -### --target=x86_64 -fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK_OPT %s
+// RUN: %clang -### --target=x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK_NOOPT %s
 
-// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
-// RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
-// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
-// RUN: %clang -c -target arm-unknown-linux-gnueabi -fsplit-machine-functions %s -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
-
-// CHECK-OPT:   "-fsplit-machine-functions"
-// CHECK-NOOPT-NOT: "-fsplit-machine-functions"
-// CHECK-TRIPLE:warning: -fsplit-machine-functions is not valid for arm
+// CHECK_OPT:"-fsplit-machine-functions"
+// CHECK_NOOPT-NOT:  "-fsplit-machine-functions"
Index: clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
===
--- clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
+++ clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c
@@ -1,68 +1,29 @@
 // REQUIRES: system-linux
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
-// REQUIRES: shell
 
 // Check that -fsplit-machine-functions is passed to both x86 and cuda
 // compilation and does not cause driver error.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
 // RUN: 2>&1 | FileCheck %s --check-prefix=MFS1
 // MFS1: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
 // MFS1: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
 
-// Check that -fsplit-machine-functions is passed to cuda and it
-// causes a warning.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
-// RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS2
-// MFS2: warning: -fsplit-machine-functions is not valid for nvptx
-
 // Check that -Xarch_host -fsplit-machine-functions is passed only to
 // native compilation.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
 // RUN: --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
 // RUN: -fsplit-machine-functions -S %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=MFS3
-// MFS3: "-target-cpu" "x86-64"{{.*}}"-fsplit-machine-functions"
-// MFS3-NOT: "-target-cpu" "sm_70"{{.*}}"-fsplit-machine-functions"
-
-// Check that -Xarch_host -fsplit-machine-functions does not cause any warning.
-// RUN:   cd "$(dirname "%t")" ; \
-// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
-// RUN  --cuda-gpu-arch=sm_70 -x cuda -Xarch_host \
-// RUN  

[PATCH] D158246: [amdgpu] WIP variadics

2023-08-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/CodeGen/DesugarVariadics.cpp:145
+for (Function  : llvm::make_early_inc_range(M))
+  if (Apply || canTransformFunctionInIsolation(F))
+Changed |= runOnFunction(F);

I think you need to guard against calls to variadic intrinsics


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158246

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D156821#4599471 , @thurston wrote:

> This patch might have broke the buildbots, starting with when it was first 
> built in https://lab.llvm.org/buildbot/#/builders/85/builds/18390
>
>   
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/libcxx_build_ubsan/include/c++/v1/stdlib.h:114:25:
>  runtime error: negation of -9223372036854775808 cannot be represented in 
> type 'long'; cast to an unsigned type to negate this value to itself
>   #0 0x5586b6dfb9aa in abs 
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/libcxx_build_ubsan/include/c++/v1/stdlib.h:114:10
>   #1 0x5586b6dfb9aa in (anonymous 
> namespace)::GNUELFDumper true>>::printRelRelaReloc((anonymous 
> namespace)::Relocation true>> const&, (anonymous 
> namespace)::RelSymbol true>> const&) 
> /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/tools/llvm-readobj/ELFDumper.cpp:3778:21
>
> (which is good insofar as it finds a real bug, but nonetheless is turning the 
> buildbots red)
>
> In the latest buildbots, the error persists (along with an unrelated 
> failure): https://lab.llvm.org/buildbot/#/builders/85/builds/18413
>
> The compiler code is a tad too nuanced for me to fix with confidence (e.g., 
> my first instinct would be to widen the type to int128 but I don't know if 
> that will break compatibility).



  Failed Tests (4):
LLVM :: CodeGen/RISCV/rvv/fixed-vectors-int.ll
LLVM :: CodeGen/SystemZ/ctpop-01.ll
LLVM :: MC/ARM/basic-thumb2-instructions.s
LLVM :: tools/llvm-readobj/ELF/relocations.test

AFAICT these failures have been fixed and the change can reland after the 
clang/ test is fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156821

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay reopened this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:1787
+if (!VCI->isMinSignedValue()) {
+  return EmitAbs(CGF, ArgValue, true);
+}

nit: we delete braces in this cascading case

https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements



Comment at: clang/test/ubsan/TestCases/Misc/abs.cpp:1
+// REQUIRES: arch=x86_64
+//

Did you mean compiler-rt/ instead of clang/?

`// REQUIRES: arch=x86_64` is legacy style.

New style uses `// REQUIRES: target={{x86_64.*}}`

Actually, this test should be generic and we should remove REQUIRES.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156821

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


[PATCH] D157076: [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-18 Thread Erick Velez 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 rG7ba37f4e46a5: [clang][ExtractAPI] Add support for C++ class 
templates and concepts (authored by evelez7).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157076

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/class_template.cpp
  clang/test/ExtractAPI/class_template_param_inheritance.cpp
  clang/test/ExtractAPI/class_template_partial_spec.cpp
  clang/test/ExtractAPI/class_template_spec.cpp
  clang/test/ExtractAPI/concept.cpp

Index: clang/test/ExtractAPI/concept.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/concept.cpp
@@ -0,0 +1,133 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -std=c++20 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template concept Foo = true;
+
+/// expected-no-diagnostics
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "template"
+},
+{
+  "kind": "text",
+  "spelling": "<"
+},
+{
+  "kind": "keyword",
+  "spelling": "typename"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "genericParameter",
+  "spelling": "T"
+},
+{
+  "kind": "text",
+  "spelling": "> "
+},
+{
+  "kind": "keyword",
+  "spelling": "concept"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c++",
+"precise": "c:@CT@Foo"
+  },
+  "kind": {
+"displayName": "Concept",
+"identifier": "c++.concept"
+  },
+  "location": {
+"position": {
+  "character": 30,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ],
+  "swiftGenerics": {
+"parameters": [
+  {
+"depth": 0,
+"index": 0,
+"name": "T"
+  }
+]
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/class_template_spec.cpp
===
--- /dev/null
+++ clang/test/ExtractAPI/class_template_spec.cpp
@@ -0,0 +1,206 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   -x c++-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+//--- input.h
+template class Foo 

[clang] 7ba37f4 - [clang][ExtractAPI] Add support for C++ class templates and concepts

2023-08-18 Thread Erick Velez via cfe-commits

Author: Erick Velez
Date: 2023-08-18T13:40:22-07:00
New Revision: 7ba37f4e46a5bbb1dc42f1ea1722296ea32034d5

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

LOG: [clang][ExtractAPI] Add support for C++ class templates and concepts

Add has_template template, DeclarationFragmentBuilder functions, and tests for 
class templates, specializations/partial specs, and concepts.

Depends on D157007

Reviewed By: dang

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

Added: 
clang/test/ExtractAPI/class_template.cpp
clang/test/ExtractAPI/class_template_param_inheritance.cpp
clang/test/ExtractAPI/class_template_partial_spec.cpp
clang/test/ExtractAPI/class_template_spec.cpp
clang/test/ExtractAPI/concept.cpp

Modified: 
clang/include/clang/ExtractAPI/API.h
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/lib/ExtractAPI/API.cpp
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/API.h 
b/clang/include/clang/ExtractAPI/API.h
index a965f49c8e91b2..83ff982be559b9 100644
--- a/clang/include/clang/ExtractAPI/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -36,6 +36,86 @@
 namespace clang {
 namespace extractapi {
 
+class Template {
+  struct TemplateParameter {
+// "class", "typename", or concept name
+std::string Type;
+std::string Name;
+unsigned int Index;
+unsigned int Depth;
+bool IsParameterPack;
+
+TemplateParameter(std::string Type, std::string Name, unsigned int Index,
+  unsigned int Depth, bool IsParameterPack)
+: Type(Type), Name(Name), Index(Index), Depth(Depth),
+  IsParameterPack(IsParameterPack) {}
+  };
+
+  struct TemplateConstraint {
+// type name of the constraint, if it has one
+std::string Type;
+std::string Kind;
+std::string LHS, RHS;
+  };
+  llvm::SmallVector Parameters;
+  llvm::SmallVector Constraints;
+
+public:
+  Template() = default;
+
+  Template(const TemplateDecl *Decl) {
+for (auto *const Parameter : *Decl->getTemplateParameters()) {
+  const auto *Param = dyn_cast(Parameter);
+  if (!Param) // some params are null
+continue;
+  std::string Type;
+  if (Param->hasTypeConstraint())
+Type = Param->getTypeConstraint()->getNamedConcept()->getName().str();
+  else if (Param->wasDeclaredWithTypename())
+Type = "typename";
+  else
+Type = "class";
+
+  addTemplateParameter(Type, Param->getName().str(), Param->getIndex(),
+   Param->getDepth(), Param->isParameterPack());
+}
+  }
+
+  Template(const ClassTemplatePartialSpecializationDecl *Decl) {
+for (auto *const Parameter : *Decl->getTemplateParameters()) {
+  const auto *Param = dyn_cast(Parameter);
+  if (!Param) // some params are null
+continue;
+  std::string Type;
+  if (Param->hasTypeConstraint())
+Type = Param->getTypeConstraint()->getNamedConcept()->getName().str();
+  else if (Param->wasDeclaredWithTypename())
+Type = "typename";
+  else
+Type = "class";
+
+  addTemplateParameter(Type, Param->getName().str(), Param->getIndex(),
+   Param->getDepth(), Param->isParameterPack());
+}
+  }
+
+  const llvm::SmallVector () const {
+return Parameters;
+  }
+
+  const llvm::SmallVector () const {
+return Constraints;
+  }
+
+  void addTemplateParameter(std::string Type, std::string Name,
+unsigned int Index, unsigned int Depth,
+bool IsParameterPack) {
+Parameters.emplace_back(Type, Name, Index, Depth, IsParameterPack);
+  }
+
+  bool empty() const { return Parameters.empty() && Constraints.empty(); }
+};
+
 /// DocComment is a vector of RawComment::CommentLine.
 ///
 /// Each line represents one line of striped documentation comment,
@@ -69,6 +149,10 @@ struct APIRecord {
 RK_StaticField,
 RK_CXXField,
 RK_CXXClass,
+RK_ClassTemplate,
+RK_ClassTemplateSpecialization,
+RK_ClassTemplatePartialSpecialization,
+RK_Concept,
 RK_CXXStaticMethod,
 RK_CXXInstanceMethod,
 RK_CXXConstructorMethod,
@@ -644,6 +728,75 @@ struct CXXClassRecord : APIRecord {
   virtual void anchor();
 };
 
+struct ClassTemplateRecord : CXXClassRecord {
+  Template Templ;
+
+  ClassTemplateRecord(StringRef USR, StringRef Name, PresumedLoc Loc,
+  AvailabilitySet Availabilities, const DocComment 
,
+   

[PATCH] D158246: [amdgpu] WIP variadics

2023-08-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/CodeGen/DesugarVariadics.cpp:296
+// Note - same attribute handling as DeadArgumentElimination
+NF->copyAttributesFrom();
+NF->setComdat(F.getComdat());

This might be missing copying the linkage


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158246

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


[PATCH] D158246: [amdgpu] WIP variadics

2023-08-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/CodeGen/DesugarVariadics.cpp:74-77
+Value *Mask = ConstantInt::get(IntPtrTy, ~(DataAlignMinusOne));
+Value *vaListAligned = Builder.CreateIntToPtr(
+Builder.CreateAnd(Builder.CreatePtrToInt(Incr, IntPtrTy), Mask),
+Incr->getType());

Can you use ptrmask?



Comment at: llvm/lib/CodeGen/DesugarVariadics.cpp:142
+  bool runOnModule(Module ) override {
+bool Apply = ApplicableToAllDefault | ApplyToAllOverride;
+bool Changed = false;

This would be better as a pass parameter. Don't see much point to specifying 
individual functions by name


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158246

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


[PATCH] D158246: [amdgpu] WIP variadics

2023-08-18 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

Name candidates

- expand
- lower
- desugar
- transform

Lowering probably makes the most sense for the abi level apply to all 
functions, I like desugar to cover rewriting a subset of the graph




Comment at: libc/config/gpu/entrypoints.txt:84-85
 # stdio.h entrypoints
+libc.src.stdio.snprintf
+libc.src.stdio.vsnprintf
 libc.src.stdio.puts

arsenm wrote:
> Split of the libc stuff into a separate patch, the lowering pass should be a 
> standalone change
There's quite a lot of wip in this patch. Your feedback is welcome, but you 
could also wait for a cleaned up version with your name on the reviewer list if 
you prefer. The libc plumbing is keeping track of which parts are currently 
passing for collaboration with jhuber6



Comment at: llvm/test/CodeGen/AMDGPU/unsupported-calls.ll:57-58
 
 ; GCN: in function test_tail_call_bitcast_extern_variadic{{.*}}: unsupported 
required tail call to function extern_variadic
-; R600: in function test_tail_call_bitcast_extern_variadic{{.*}}: unsupported 
call to function extern_variadic
 define i32 @test_tail_call_bitcast_extern_variadic(<4 x float> %arg0, <4 x 
float> %arg1, i32 %arg2) {

arsenm wrote:
> Deleted the wrong error?
this is curious - the test is passing as written, maybe a quirk of running it 
with not llc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158246

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


[PATCH] D158246: [amdgpu] WIP variadics

2023-08-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/CodeGen/DesugarVariadics.cpp:297
+NF->copyAttributesFrom();
+NF->setComdat(F.getComdat());
+F.getParent()->getFunctionList().insert(F.getIterator(), NF);

Test the comdat? Weird that copyAttributesFrom seems to not cover it



Comment at: llvm/lib/CodeGen/DesugarVariadics.cpp:339
+// This fails to update call instructions, unfortunately
+// It may therefore also fail to update globals
+F.replaceAllUsesWith(NF);

Add a test with a def and decl in a global initializer, and with a constantexpr 
cast in the initializer. I think this should also handle blockaddress


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158246

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


[PATCH] D158246: [amdgpu] WIP variadics

2023-08-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/CodeGen/DesugarVariadics.cpp:208-209
+
+StructType *VarargsTy = StructType::create(
+Ctx, LocalVarTypes, (Twine(NF->getName()) + ".vararg").str());
+

Should we go for a packed struct forced to align 4? There's no upside to stack 
values with > 4 align


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158246

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


[PATCH] D158246: [amdgpu] WIP variadics

2023-08-18 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield removed subscribers: kristof.beyls, wangpc, jdoerfert.
JonChesterfield added inline comments.



Comment at: llvm/lib/CodeGen/ExpandVAIntrinsics.cpp:215-217
+auto alloced = Builder.Insert(
+new AllocaInst(VarargsTy, DL.getAllocaAddrSpace(), nullptr,
+   std::max(MaxFieldAlign, assumedStructAlignment(DL))),

arsenm wrote:
> What's wrong with just Builder.CreateAlloca?
I want to mark the callee parameter with alignment metadata so the pointer 
alignment can constant fold (todo, said folding isn't currently working very 
well).

The struct contains whatever the caller was passing which we don't know much 
about. If we call CreateAlloca, it gets whatever alignment suffices for those 
fields.

If those two don't line up nicely, you get bad times. I'm using the stack 
alignment from the target string as a heuristic for a reasonable alignment to 
use for things on the stack. For amdgpu that's 4, which means passing a double 
gets an dynamic realignment which doesn't optimise out, but otherwise it seems 
reasonable.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158246

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


[PATCH] D158246: [amdgpu] WIP variadics

2023-08-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/CodeGen/DesugarVariadics.cpp:22
+// 5/ Delete the remaining parts of the original functions
+//
+//===--===//

Can you expand on the ABI requirements of this in the comment? If we make this 
be the way the ABI works for AMDGPU, we don't need any conditions. Should there 
be some control for the targets with established ABIs to apply this to internal 
functions?



Comment at: llvm/lib/CodeGen/DesugarVariadics.cpp:38
+
+#include 
+

Don't need cstdio



Comment at: llvm/lib/CodeGen/DesugarVariadics.cpp:102-103
+Value *src = Inst->getSrc();
+Value *ld = Builder.CreateLoad(src->getType(), src, "vacopy");
+Builder.CreateStore(ld, dst);
+Inst->eraseFromParent();

Can you use nontrivial types with this? Might be better to just start with 
memcpy



Comment at: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp:621
 }
+if (PassName == "desugar-variadics") {
+  PM.addPass(DesugarVariadicsPass());

desugar is a weird name for a lowering pass



Comment at: llvm/test/CodeGen/AMDGPU/llc-pipeline.ll:188
 ; GCN-O1-NEXT:Cycle Info Analysis
+; GCN-O1-NEXT:Desugar Variadics
 ; GCN-O1-NEXT:FunctionPass Manager

This is rather late, I'd think we'd be better off with an earlier run (e.g. as 
part of the initial module passes, along with sanitizers)



Comment at: llvm/test/CodeGen/AMDGPU/unsupported-calls.ll:57-58
 
 ; GCN: in function test_tail_call_bitcast_extern_variadic{{.*}}: unsupported 
required tail call to function extern_variadic
-; R600: in function test_tail_call_bitcast_extern_variadic{{.*}}: unsupported 
call to function extern_variadic
 define i32 @test_tail_call_bitcast_extern_variadic(<4 x float> %arg0, <4 x 
float> %arg1, i32 %arg2) {

Deleted the wrong error?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158246

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


[PATCH] D158104: [clang-format][NFC] Simplify getFirstNonComment() in the annotator

2023-08-18 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG07181e289e3c: [clang-format][NFC] Simplify 
getFirstNonComment() in the annotator (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158104

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/TokenAnnotator.h


Index: clang/lib/Format/TokenAnnotator.h
===
--- clang/lib/Format/TokenAnnotator.h
+++ clang/lib/Format/TokenAnnotator.h
@@ -151,6 +151,11 @@
startsWith(tok::kw_export, tok::kw_namespace);
   }
 
+  FormatToken *getFirstNonComment() const {
+assert(First);
+return First->is(tok::comment) ? First->getNextNonComment() : First;
+  }
+
   FormatToken *First;
   FormatToken *Last;
 
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4763,16 +4763,6 @@
  !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral);
 }
 
-// Returns the first token on the line that is not a comment.
-static const FormatToken *getFirstNonComment(const AnnotatedLine ) {
-  const FormatToken *Next = Line.First;
-  if (!Next)
-return Next;
-  if (Next->is(tok::comment))
-Next = Next->getNextNonComment();
-  return Next;
-}
-
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) const {
   const FormatToken  = *Right.Previous;
@@ -5044,7 +5034,7 @@
 return Right.HasUnescapedNewline;
 
   if (isAllmanBrace(Left) || isAllmanBrace(Right)) {
-auto FirstNonComment = getFirstNonComment(Line);
+auto *FirstNonComment = Line.getFirstNonComment();
 bool AccessSpecifier =
 FirstNonComment &&
 FirstNonComment->isOneOf(Keywords.kw_internal, tok::kw_public,


Index: clang/lib/Format/TokenAnnotator.h
===
--- clang/lib/Format/TokenAnnotator.h
+++ clang/lib/Format/TokenAnnotator.h
@@ -151,6 +151,11 @@
startsWith(tok::kw_export, tok::kw_namespace);
   }
 
+  FormatToken *getFirstNonComment() const {
+assert(First);
+return First->is(tok::comment) ? First->getNextNonComment() : First;
+  }
+
   FormatToken *First;
   FormatToken *Last;
 
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4763,16 +4763,6 @@
  !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral);
 }
 
-// Returns the first token on the line that is not a comment.
-static const FormatToken *getFirstNonComment(const AnnotatedLine ) {
-  const FormatToken *Next = Line.First;
-  if (!Next)
-return Next;
-  if (Next->is(tok::comment))
-Next = Next->getNextNonComment();
-  return Next;
-}
-
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) const {
   const FormatToken  = *Right.Previous;
@@ -5044,7 +5034,7 @@
 return Right.HasUnescapedNewline;
 
   if (isAllmanBrace(Left) || isAllmanBrace(Right)) {
-auto FirstNonComment = getFirstNonComment(Line);
+auto *FirstNonComment = Line.getFirstNonComment();
 bool AccessSpecifier =
 FirstNonComment &&
 FirstNonComment->isOneOf(Keywords.kw_internal, tok::kw_public,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 07181e2 - [clang-format][NFC] Simplify getFirstNonComment() in the annotator

2023-08-18 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-08-18T13:23:47-07:00
New Revision: 07181e289e3c6296ed5e982dca0764b91acbb8e6

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

LOG: [clang-format][NFC] Simplify getFirstNonComment() in the annotator

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/TokenAnnotator.h

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 73840332e22c2b..6972008a27fb1b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4763,16 +4763,6 @@ static bool isAllmanLambdaBrace(const FormatToken ) {
  !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral);
 }
 
-// Returns the first token on the line that is not a comment.
-static const FormatToken *getFirstNonComment(const AnnotatedLine ) {
-  const FormatToken *Next = Line.First;
-  if (!Next)
-return Next;
-  if (Next->is(tok::comment))
-Next = Next->getNextNonComment();
-  return Next;
-}
-
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) const {
   const FormatToken  = *Right.Previous;
@@ -5044,7 +5034,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
,
 return Right.HasUnescapedNewline;
 
   if (isAllmanBrace(Left) || isAllmanBrace(Right)) {
-auto FirstNonComment = getFirstNonComment(Line);
+auto *FirstNonComment = Line.getFirstNonComment();
 bool AccessSpecifier =
 FirstNonComment &&
 FirstNonComment->isOneOf(Keywords.kw_internal, tok::kw_public,

diff  --git a/clang/lib/Format/TokenAnnotator.h 
b/clang/lib/Format/TokenAnnotator.h
index f3e5b397aa78b3..58e2cf79f488fa 100644
--- a/clang/lib/Format/TokenAnnotator.h
+++ b/clang/lib/Format/TokenAnnotator.h
@@ -151,6 +151,11 @@ class AnnotatedLine {
startsWith(tok::kw_export, tok::kw_namespace);
   }
 
+  FormatToken *getFirstNonComment() const {
+assert(First);
+return First->is(tok::comment) ? First->getNextNonComment() : First;
+  }
+
   FormatToken *First;
   FormatToken *Last;
 



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


[clang] 472a510 - Re-land "[-Wunsafe-buffer-usage][NFC] Slightly refactor and optimize the code"

2023-08-18 Thread via cfe-commits

Author: ziqingluo-90
Date: 2023-08-18T13:22:01-07:00
New Revision: 472a510bbc0325eb8e5920845e7c8d1a6a28a387

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

LOG: Re-land "[-Wunsafe-buffer-usage][NFC] Slightly refactor and optimize the 
code"

This reverts commit ac9a76d7487b9af1ace626eb90064194cb12c53d.

Previously an abstract class has no pure virtual function.  It causes build 
error on some bots.

Added: 


Modified: 
clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
index 13f28076c6f4d7..c865b2e8bdb379 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
@@ -20,7 +20,19 @@
 
 namespace clang {
 
-using DefMapTy = llvm::DenseMap>;
+using VarGrpTy = std::vector;
+using VarGrpRef = ArrayRef;
+
+class VariableGroupsManager {
+public:
+  VariableGroupsManager() = default;
+  virtual ~VariableGroupsManager() = default;
+  /// Returns the set of variables (including `Var`) that need to be fixed
+  /// together in one step.
+  ///
+  /// `Var` must be a variable that needs fix (so it must be in a group).
+  virtual VarGrpRef getGroupOfVar(const VarDecl *Var) const =0;
+};
 
 /// The interface that lets the caller handle unsafe buffer usage analysis
 /// results by overriding this class's handle... methods.
@@ -53,7 +65,7 @@ class UnsafeBufferUsageHandler {
   /// all variables that must be fixed together (i.e their types must be 
changed to the
   /// same target type to prevent type mismatches) into a single fixit.
   virtual void handleUnsafeVariableGroup(const VarDecl *Variable,
- const DefMapTy ,
+ const VariableGroupsManager 
,
  FixItList &) = 0;
 
 #ifndef NDEBUG

diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 8152eb53da71c2..4638f7422320b9 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1176,7 +1176,11 @@ groupWarningGadgetsByVar(const WarningGadgetList 
) {
 }
 
 struct FixableGadgetSets {
-  std::map> byVar;
+  std::map,
+   // To keep keys sorted by their locations in the map so that the
+   // order is deterministic:
+   CompareNode>
+  byVar;
 };
 
 static FixableGadgetSets
@@ -1382,7 +1386,7 @@ static std::optional getRangeText(SourceRange 
SR,
  const SourceManager ,
  const LangOptions ) {
   bool Invalid = false;
-  CharSourceRange CSR = CharSourceRange::getCharRange(SR.getBegin(), 
SR.getEnd());
+  CharSourceRange CSR = CharSourceRange::getCharRange(SR);
   StringRef Text = Lexer::getSourceText(CSR, SM, LangOpts, );
 
   if (!Invalid)
@@ -2225,7 +2229,7 @@ getFixIts(FixableGadgetSets , const 
Strategy ,
  ASTContext ,
   /* The function decl under analysis */ const Decl *D,
   const DeclUseTracker , UnsafeBufferUsageHandler ,
-  const DefMapTy ) {
+  const VariableGroupsManager ) {
   std::map FixItsForVariable;
   for (const auto &[VD, Fixables] : FixablesForAllVars.byVar) {
 FixItsForVariable[VD] =
@@ -2261,9 +2265,10 @@ getFixIts(FixableGadgetSets , const 
Strategy ,
   continue;
 }
 
-const auto VarGroupForVD = VarGrpMap.find(VD);
-if (VarGroupForVD != VarGrpMap.end()) {
-  for (const VarDecl * V : VarGroupForVD->second) {
+
+   {
+  const auto VarGroupForVD = VarGrpMgr.getGroupOfVar(VD);
+  for (const VarDecl * V : VarGroupForVD) {
 if (V == VD) {
   continue;
 }
@@ -2275,7 +2280,7 @@ getFixIts(FixableGadgetSets , const 
Strategy ,
 
   if (ImpossibleToFix) {
 FixItsForVariable.erase(VD);
-for (const VarDecl * V : VarGroupForVD->second) {
+for (const VarDecl * V : VarGroupForVD) {
   FixItsForVariable.erase(V);
 }
 continue;
@@ -2293,30 +2298,24 @@ getFixIts(FixableGadgetSets , const 
Strategy ,
 }
   }
 
-  for (auto VD : FixItsForVariable) {
-const auto VarGroupForVD = VarGrpMap.find(VD.first);
-const Strategy::Kind ReplacementTypeForVD = S.lookup(VD.first);
-if (VarGroupForVD != VarGrpMap.end()) {
-  for (const VarDecl * Var : VarGroupForVD->second) {
-if (Var == VD.first) {
-  continue;
-}
+  // The map that maps each variable `v` to fix-its for the whole group where
+  // `v` is in:
+  std::map 

[PATCH] D158293: [NFC][CLANG] Fix potential dereferencing of null return values

2023-08-18 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2009-2010
(Line.MightBeFunctionDecl || Line.InPPDirective) &&
-   Current.NestingLevel == 0 &&
+   Current.NestingLevel == 0 && Current.Previous &&
!Current.Previous->isOneOf(tok::kw_operator, tok::identifier)) {
   // not auto operator->() -> xxx;

`Current.Previous` can't be null here because `AutoFound` is `true`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158293

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


[PATCH] D158246: [amdgpu] WIP variadics

2023-08-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: libc/config/gpu/entrypoints.txt:84-85
 # stdio.h entrypoints
+libc.src.stdio.snprintf
+libc.src.stdio.vsnprintf
 libc.src.stdio.puts

Split of the libc stuff into a separate patch, the lowering pass should be a 
standalone change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158246

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


[PATCH] D158309: [flang][driver] Mark -Wl as visible in Flang

2023-08-18 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
awarzynski added a reviewer: kiranchandramohan.
Herald added a reviewer: sscalpone.
Herald added projects: Flang, All.
awarzynski requested review of this revision.
Herald added subscribers: cfe-commits, jdoerfert.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158309

Files:
  clang/include/clang/Driver/Options.td
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/misc-flags.f90


Index: flang/test/Driver/misc-flags.f90
===
--- flang/test/Driver/misc-flags.f90
+++ flang/test/Driver/misc-flags.f90
@@ -1,6 +1,9 @@
 ! Make sure that `-l` is "visible" to Flang's driver
 ! RUN: %flang -lpgmath -### %s
 
+! Make sure that `-Wl` is "visible" to Flang's driver
+! RUN: %flang -Wl,abs -### %s
+
 program hello
   write(*,*), "Hello world!"
 end program hello
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -120,6 +120,7 @@
 ! HELP-NEXT: -U   Undefine macro 
 ! HELP-NEXT: --version   Print version information
 ! HELP-NEXT: -v  Show commands to run and use verbose 
output
+! HELP-NEXT: -Wl, Pass the comma separated arguments in  to the 
linker
 ! HELP-NEXT: -W Enable the specified warning
 ! HELP-NEXT: -XflangPass  to the flang compiler
 ! HELP-NEXT: -xTreat subsequent input files as having 
type 
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -132,6 +132,7 @@
 ! CHECK-NEXT: -U   Undefine macro 
 ! CHECK-NEXT: --version   Print version information
 ! CHECK-NEXT: -v  Show commands to run and use verbose 
output
+! CHECK-NEXT: -Wl, Pass the comma separated arguments in  to the 
linker
 ! CHECK-NEXT: -W Enable the specified warning
 ! CHECK-NEXT: -XflangPass  to the flang compiler
 ! CHECK-NEXT: -xTreat subsequent input files as having 
type 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -912,7 +912,8 @@
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
-def Wl_COMMA : CommaJoined<["-"], "Wl,">, Flags<[LinkerInput, RenderAsInput]>,
+def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
+  Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
   MetaVarName<"">, Group;
 // FIXME: This is broken; these should not be Joined arguments.


Index: flang/test/Driver/misc-flags.f90
===
--- flang/test/Driver/misc-flags.f90
+++ flang/test/Driver/misc-flags.f90
@@ -1,6 +1,9 @@
 ! Make sure that `-l` is "visible" to Flang's driver
 ! RUN: %flang -lpgmath -### %s
 
+! Make sure that `-Wl` is "visible" to Flang's driver
+! RUN: %flang -Wl,abs -### %s
+
 program hello
   write(*,*), "Hello world!"
 end program hello
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -120,6 +120,7 @@
 ! HELP-NEXT: -U   Undefine macro 
 ! HELP-NEXT: --version   Print version information
 ! HELP-NEXT: -v  Show commands to run and use verbose output
+! HELP-NEXT: -Wl, Pass the comma separated arguments in  to the linker
 ! HELP-NEXT: -W Enable the specified warning
 ! HELP-NEXT: -XflangPass  to the flang compiler
 ! HELP-NEXT: -xTreat subsequent input files as having type 
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -132,6 +132,7 @@
 ! CHECK-NEXT: -U   Undefine macro 
 ! CHECK-NEXT: --version   Print version information
 ! CHECK-NEXT: -v  Show commands to run and use verbose output
+! CHECK-NEXT: -Wl, Pass the comma separated arguments in  to the linker
 ! CHECK-NEXT: -W Enable the specified warning
 ! CHECK-NEXT: -XflangPass  to the flang compiler
 ! CHECK-NEXT: -xTreat subsequent input files as having type 
Index: clang/include/clang/Driver/Options.td
===
--- 

[PATCH] D157157: [clang] Add clang support for Machine Function Splitting on AArch64

2023-08-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:5852
options::OPT_fno_split_machine_functions)) {
-// This codegen pass is only available on x86-elf targets.
-if (Triple.isX86() && Triple.isOSBinFormatELF()) {
+// This codegen pass is only available on x86 and Arm ELF targets.
+if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF()) {

AArch64.

Arm can mean AArch32 (often written as "ARM").



Comment at: clang/test/Driver/fsplit-machine-functions.c:4
 // RUN: %clang -### -target x86_64 -fprofile-use=default.profdata 
-fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck 
-check-prefix=CHECK-NOOPT %s
+// RUN: %clang -### -target aarch64-unknown-linux 
-fprofile-use=default.profdata -fsplit-machine-functions %s -c 2>&1 | FileCheck 
-check-prefix=CHECK-AARCH64 %s
 // RUN: not %clang -c -target arm-unknown-linux -fsplit-machine-functions %s 
2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s

mingmingl wrote:
> nit: would `-target aarch64` be sufficient here? if yes it's more general.
Use `--target=` for new tests. `--target=aarch64` is sufficient and preferred 
for generic ELF features.



Comment at: clang/test/Driver/fsplit-machine-functions.c:9
 // CHECK-NOOPT-NOT: "-fsplit-machine-functions"
+// CHECK-AARCH64:   "-fsplit-machine-functions"
 // CHECK-TRIPLE:error: unsupported option '-fsplit-machine-functions' for 
target

Just reuse CHECK-OPT


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157157

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


[PATCH] D139730: [OpenMP][DeviceRTL][AMDGPU] Support code object version 5

2023-08-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/test/CodeGenCUDA/amdgpu-code-object-version-linking.cu:40-43
+__device__ void bar(int *out)
+{
+  *out = __builtin_amdgcn_workgroup_size_x();
+}

test all the builtins?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139730

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


[PATCH] D157157: [clang] Add clang support for Machine Function Splitting on AArch64

2023-08-18 Thread Mingming Liu via Phabricator via cfe-commits
mingmingl accepted this revision.
mingmingl added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/Driver/fsplit-machine-functions.c:4
 // RUN: %clang -### -target x86_64 -fprofile-use=default.profdata 
-fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck 
-check-prefix=CHECK-NOOPT %s
+// RUN: %clang -### -target aarch64-unknown-linux 
-fprofile-use=default.profdata -fsplit-machine-functions %s -c 2>&1 | FileCheck 
-check-prefix=CHECK-AARCH64 %s
 // RUN: not %clang -c -target arm-unknown-linux -fsplit-machine-functions %s 
2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s

nit: would `-target aarch64` be sufficient here? if yes it's more general.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157157

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


[PATCH] D139730: [OpenMP][DeviceRTL][AMDGPU] Support code object version 5

2023-08-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:17057
+  Constant *Offset, *OffsetOld;
+  Value *DP, *DP1;
+

Spell out to DispatchPtr?



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:1206-1208
+  getTargetCodeGenInfo().emitTargetGlobals(*this);
+
   getTargetCodeGenInfo().emitTargetMetadata(*this, MangledDeclNames);

These could be one combined hook? this isn't really different from metadata



Comment at: clang/lib/CodeGen/Targets/AMDGPU.cpp:369-386
+if (CGM.getModule().getNamedGlobal(Name))
+  return;
+
+auto *Type =
+llvm::IntegerType::getIntNTy(CGM.getModule().getContext(), Size);
+auto *GV = new llvm::GlobalVariable(
+CGM.getModule(), Type, true, Linkage,

You moved GetOrCreateLLVMGlobal but don't use it? 

The lamdba is unnecessary for a single local use



Comment at: clang/lib/Driver/ToolChain.cpp:1369
 if (A->getOption().matches(options::OPT_m_Group)) {
-  if (SameTripleAsHost)
+  // pass code objection version to device toolchain
+  // to correctly set meta-data in intermediate files

Capitalize



Comment at: clang/lib/Driver/ToolChain.cpp:1372
+  if (SameTripleAsHost ||
+  A->getOption().matches(options::OPT_mcode_object_version_EQ))
 DAL->append(A);

Don't understand why this is necessary


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139730

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


[clang] fc06cce - Revert "Respect integer overflow handling in abs builtin"

2023-08-18 Thread Thurston Dang via cfe-commits

Author: Thurston Dang
Date: 2023-08-18T19:59:34Z
New Revision: fc06cce30d2b7d49778b9a27420ca239e0c49856

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

LOG: Revert "Respect integer overflow handling in abs builtin"

This reverts commit 1783185790de29b24d3850d33d9a9d586e6bbd39,
which broke the buildbots, starting with when it was first built in 
https://lab.llvm.org/buildbot/#/builders/85/builds/18390

(N.B. I think the patch is uncovering real bugs; the revert
is simply to keep the tree green and the buildbots useful, because I'm not 
confident how to
fix-forward all the found bugs.)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 
clang/test/CodeGen/abs-overflow.c
clang/test/ubsan/TestCases/Misc/abs.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e34fc2e10b2df0..054c06ffa0f5c9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -154,10 +154,6 @@ Bug Fixes in This Version
 - Fix a hang on valid C code passing a function type as an argument to
   ``typeof`` to form a function declaration.
   (`#64713 _`)
-- Clang now respects ``-fwrapv`` and ``-ftrapv`` for ``__builtin_abs`` and
-  ``abs`` builtins.
-  (`#45129 `_,
-  `#45794 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
@@ -293,9 +289,6 @@ Static Analyzer
 
 Sanitizers
 --
-- ``-fsanitize=signed-integer-overflow`` now instruments ``__builtin_abs`` and
-  ``abs`` builtins.
-
 
 Python Binding Changes
 --

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 4ded5a10d529ae..5a183d3553279e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1768,49 +1768,6 @@ Value *CodeGenFunction::EmitCheckedArgForBuiltin(const 
Expr *E,
   return ArgValue;
 }
 
-static Value *EmitAbs(CodeGenFunction , Value *ArgValue, bool HasNSW) {
-  // X < 0 ? -X : X
-  // TODO: Use phi-node (for better SimplifyCFGPass)
-  Value *NegOp = CGF.Builder.CreateNeg(ArgValue, "neg", false, HasNSW);
-  Constant *Zero = llvm::Constant::getNullValue(ArgValue->getType());
-  Value *CmpResult = CGF.Builder.CreateICmpSLT(ArgValue, Zero, "abscond");
-  return CGF.Builder.CreateSelect(CmpResult, NegOp, ArgValue, "abs");
-}
-
-static Value *EmitOverflowCheckedAbs(CodeGenFunction , const CallExpr *E,
- bool SanitizeOverflow) {
-  Value *ArgValue = CGF.EmitScalarExpr(E->getArg(0));
-
-  // Try to eliminate overflow check.
-  if (const auto *VCI = dyn_cast(ArgValue)) {
-if (!VCI->isMinSignedValue()) {
-  return EmitAbs(CGF, ArgValue, true);
-}
-  }
-
-  CodeGenFunction::SanitizerScope SanScope();
-
-  Constant *Zero = Constant::getNullValue(ArgValue->getType());
-  Value *ResultAndOverflow = CGF.Builder.CreateBinaryIntrinsic(
-  Intrinsic::ssub_with_overflow, Zero, ArgValue);
-  Value *Result = CGF.Builder.CreateExtractValue(ResultAndOverflow, 0);
-  Value *NotOverflow = CGF.Builder.CreateNot(
-  CGF.Builder.CreateExtractValue(ResultAndOverflow, 1));
-
-  // TODO: support -ftrapv-handler.
-  if (SanitizeOverflow) {
-CGF.EmitCheck({{NotOverflow, SanitizerKind::SignedIntegerOverflow}},
-  SanitizerHandler::NegateOverflow,
-  {CGF.EmitCheckSourceLocation(E->getArg(0)->getExprLoc()),
-   CGF.EmitCheckTypeDescriptor(E->getType())},
-  {ArgValue});
-  } else
-CGF.EmitTrapCheck(NotOverflow, SanitizerHandler::SubOverflow);
-
-  Value *CmpResult = CGF.Builder.CreateICmpSLT(ArgValue, Zero, "abscond");
-  return CGF.Builder.CreateSelect(CmpResult, Result, ArgValue, "abs");
-}
-
 /// Get the argument type for arguments to os_log_helper.
 static CanQualType getOSLogArgType(ASTContext , int Size) {
   QualType UnsignedTy = C.getIntTypeForBitwidth(Size * 8, /*Signed=*/false);
@@ -2669,29 +2626,16 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.CreateCall(CGM.getIntrinsic(Intrinsic::vacopy), {DstPtr, SrcPtr});
 return RValue::get(nullptr);
   }
-  case Builtin::BIabs:
-  case Builtin::BIlabs:
-  case Builtin::BIllabs:
   case Builtin::BI__builtin_abs:
   case Builtin::BI__builtin_labs:
   case Builtin::BI__builtin_llabs: {
-bool SanitizeOverflow = SanOpts.has(SanitizerKind::SignedIntegerOverflow);
-
-Value *Result;
-switch (getLangOpts().getSignedOverflowBehavior()) {
-case LangOptions::SOB_Defined:
-  Result = EmitAbs(*this, EmitScalarExpr(E->getArg(0)), false);
-  break;
-case 

[PATCH] D158218: [CMake] Deprecate DEFAULT_SYSROOT and GCC_INSTALL_PREFIX

2023-08-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a subscriber: sbc100.
MaskRay added inline comments.



Comment at: clang/CMakeLists.txt:179-183
+if(DEFAULT_SYSROOT)
+  message(WARNING "DEFAULT_SYSROOT is deprecated and will be removed. Use "
+"configuration files 
(https://clang.llvm.org/docs/UsersManual.html#configuration-files)"
+"to specify the default --sysroot=")
+endif()

MaskRay wrote:
> bcain wrote:
> > MaskRay wrote:
> > > bcain wrote:
> > > > At one time I believe that the clang configuration files could not 
> > > > specify paths relative to the clang executable.  AFAICT 
> > > > `DEFAULT_SYSROOT` does support this.
> > > > 
> > > > But if I'm mistaken about that can we add an example to the docs at 
> > > > https://clang.llvm.org/docs/UsersManual.html#configuration-files 
> > > > illustrating how to use a relative sysroot?
> > > Clang configuration files just complement user-specified command line 
> > > options. As one can do `--sysroot=./sysroot`, one can add 
> > > `--sysroot=./sysroot` to a configuration file, too.
> > > 
> > > If you think having a sysroot example is useful, I can add
> > > 
> > > ```
> > > # Relative --sysroot
> > > --sysroot=./sysroot
> > > ```
> > > before
> > > clang/docs/UsersManual.rst:1018 `-c --target=x86_64-unknown-linux-gnu`
> > IIUC: when clang takes a `--sysroot=./sysroot` argument, it will interpret 
> > that path as a prefix to the files it wants to access.  So the system will 
> > treat it as relative to the environment's `cwd`, correct?
> > 
> > But when `DEFAULT_SYSROOT` is set to a relative path, that relative path is 
> > considered to be relative to `clang`.  Therefore a convenient feature that 
> > we take advantage of is setting it to something like 
> > `../target/hexagon-unknown-linux-musl` in order to have anyone who invokes 
> > `hexagon-unknown-linux-clang` from any path be able to find the includes 
> > and libraries distributed with the toolchain without having to specify the 
> > sysroot.
> > 
> > Maybe there's a better way to achieve this without the need for a relative 
> > `DEFAULT_SYSROOT` but it's been very useful and the config files do not 
> > seem suited to replace it.
> `--sysroot=` is used as a prefix to certain files, primarily libc and GCC 
> installations.
> 
> `-DDEFAULT_SYSROOT=...` just changes `clang/lib/Driver/Driver.cpp:203` 
> `SysRoot(DEFAULT_SYSROOT)`.
> There is no magic related to the `clang` executable path. CMake doesn't do 
> any magic, either.
Ah, sorry. There is magic: D76653 (@sbc100).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158218

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


[PATCH] D158246: [amdgpu] WIP variadics

2023-08-18 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield updated this revision to Diff 551616.
JonChesterfield added a comment.

- Rename ExpandVAIntrinsics to DesugarVariadics


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158246

Files:
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  libc/config/gpu/entrypoints.txt
  libc/test/src/__support/CMakeLists.txt
  libc/test/src/stdio/CMakeLists.txt
  llvm/include/llvm/CodeGen/DesugarVariadics.h
  llvm/include/llvm/CodeGen/MachinePassRegistry.def
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/InitializePasses.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CodeGen.cpp
  llvm/lib/CodeGen/DesugarVariadics.cpp
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
  llvm/test/CodeGen/AMDGPU/unsupported-calls.ll
  llvm/test/CodeGen/Generic/expand-variadic-intrinsics.ll
  llvm/tools/opt/opt.cpp
  llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn
@@ -72,6 +72,7 @@
 "ExpandMemCmp.cpp",
 "ExpandPostRAPseudos.cpp",
 "ExpandReductions.cpp",
+"DesugarVariadics.cpp",
 "ExpandVectorPredication.cpp",
 "FEntryInserter.cpp",
 "FaultMaps.cpp",
Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -365,6 +365,7 @@
   "global-merge",
   "pre-isel-intrinsic-lowering",
   "expand-reductions",
+  "desugar-variadics",
   "indirectbr-expand",
   "generic-to-nvvm",
   "expandmemcmp",
@@ -456,6 +457,7 @@
   initializeWriteBitcodePassPass(Registry);
   initializeReplaceWithVeclibLegacyPass(Registry);
   initializeJMCInstrumenterPass(Registry);
+  initializeDesugarVariadicsPass(Registry);
 
   SmallVector PluginList;
   PassPlugins.setCallback([&](const std::string ) {
Index: llvm/test/CodeGen/Generic/expand-variadic-intrinsics.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Generic/expand-variadic-intrinsics.ll
@@ -0,0 +1,85 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -desugar-variadics -desugar-variadics-all=true -S < %s | FileCheck %s
+
+target datalayout = "e-m:e-S8"
+
+; CHECK: %variadic_to_call_middle.vararg = type { i32, [4 x i8], double, i32 }
+
+define dso_local void @variadic_to_call_middle(double %d, ...) {
+; CHECK-LABEL: @variadic_to_call_middle(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[VA:%.*]] = alloca ptr, align 8
+; CHECK-NEXT:call void @llvm.lifetime.start.p0(i64 8, ptr nonnull [[VA]])
+; CHECK-NEXT:store ptr [[VARARGS:%.*]], ptr [[VA]], align 8
+; CHECK-NEXT:[[ARGLIST_CURRENT:%.*]] = load ptr, ptr [[VA]], align 8
+; CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds i8, ptr [[ARGLIST_CURRENT]], i32 3
+; CHECK-NEXT:[[TMP1:%.*]] = ptrtoint ptr [[TMP0]] to i64
+; CHECK-NEXT:[[TMP2:%.*]] = and i64 [[TMP1]], -4
+; CHECK-NEXT:[[TMP3:%.*]] = inttoptr i64 [[TMP2]] to ptr
+; CHECK-NEXT:[[TMP4:%.*]] = load i32, ptr [[TMP3]], align 4
+; CHECK-NEXT:[[ARGLIST_NEXT:%.*]] = getelementptr inbounds i32, ptr [[TMP3]], i64 1
+; CHECK-NEXT:store ptr [[ARGLIST_NEXT]], ptr [[VA]], align 8
+; CHECK-NEXT:[[ARGLIST_CURRENT1:%.*]] = load ptr, ptr [[VA]], align 8
+; CHECK-NEXT:[[TMP5:%.*]] = getelementptr inbounds i8, ptr [[ARGLIST_CURRENT1]], i32 7
+; CHECK-NEXT:[[TMP6:%.*]] = ptrtoint ptr [[TMP5]] to i64
+; CHECK-NEXT:[[TMP7:%.*]] = and i64 [[TMP6]], -8
+; CHECK-NEXT:[[TMP8:%.*]] = inttoptr i64 [[TMP7]] to ptr
+; CHECK-NEXT:[[TMP9:%.*]] = load double, ptr [[TMP8]], align 8
+; CHECK-NEXT:[[ARGLIST_NEXT2:%.*]] = getelementptr inbounds double, ptr [[TMP8]], i64 1
+; CHECK-NEXT:store ptr [[ARGLIST_NEXT2]], ptr [[VA]], align 8
+; CHECK-NEXT:[[ARGLIST_CURRENT3:%.*]] = load ptr, ptr [[VA]], align 8
+; CHECK-NEXT:[[TMP10:%.*]] = getelementptr inbounds i8, ptr [[ARGLIST_CURRENT3]], i32 3
+; CHECK-NEXT:[[TMP11:%.*]] = ptrtoint ptr [[TMP10]] to i64
+; CHECK-NEXT:[[TMP12:%.*]] = and i64 [[TMP11]], -4
+; CHECK-NEXT:[[TMP13:%.*]] = inttoptr i64 [[TMP12]] to ptr
+; CHECK-NEXT:[[TMP14:%.*]] = load i32, ptr [[TMP13]], align 4
+; CHECK-NEXT:[[ARGLIST_NEXT4:%.*]] = getelementptr inbounds i32, ptr [[TMP13]], i64 1
+; CHECK-NEXT:store ptr [[ARGLIST_NEXT4]], ptr [[VA]], align 8
+; CHECK-NEXT:call void @_Z3erri(i32 [[TMP4]])
+; CHECK-NEXT:call void @_Z3errd(double [[TMP9]])
+; CHECK-NEXT:call void @_Z3erri(i32 [[TMP14]])
+; CHECK-NEXT:call void @llvm.lifetime.end.p0(i64 8, ptr nonnull [[VA]])
+; CHECK-NEXT:ret void
+;
+entry:
+  %va = alloca ptr, align 8
+  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %va)
+  

[PATCH] D158218: [CMake] Deprecate DEFAULT_SYSROOT and GCC_INSTALL_PREFIX

2023-08-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/CMakeLists.txt:179-183
+if(DEFAULT_SYSROOT)
+  message(WARNING "DEFAULT_SYSROOT is deprecated and will be removed. Use "
+"configuration files 
(https://clang.llvm.org/docs/UsersManual.html#configuration-files)"
+"to specify the default --sysroot=")
+endif()

bcain wrote:
> MaskRay wrote:
> > bcain wrote:
> > > At one time I believe that the clang configuration files could not 
> > > specify paths relative to the clang executable.  AFAICT `DEFAULT_SYSROOT` 
> > > does support this.
> > > 
> > > But if I'm mistaken about that can we add an example to the docs at 
> > > https://clang.llvm.org/docs/UsersManual.html#configuration-files 
> > > illustrating how to use a relative sysroot?
> > Clang configuration files just complement user-specified command line 
> > options. As one can do `--sysroot=./sysroot`, one can add 
> > `--sysroot=./sysroot` to a configuration file, too.
> > 
> > If you think having a sysroot example is useful, I can add
> > 
> > ```
> > # Relative --sysroot
> > --sysroot=./sysroot
> > ```
> > before
> > clang/docs/UsersManual.rst:1018 `-c --target=x86_64-unknown-linux-gnu`
> IIUC: when clang takes a `--sysroot=./sysroot` argument, it will interpret 
> that path as a prefix to the files it wants to access.  So the system will 
> treat it as relative to the environment's `cwd`, correct?
> 
> But when `DEFAULT_SYSROOT` is set to a relative path, that relative path is 
> considered to be relative to `clang`.  Therefore a convenient feature that we 
> take advantage of is setting it to something like 
> `../target/hexagon-unknown-linux-musl` in order to have anyone who invokes 
> `hexagon-unknown-linux-clang` from any path be able to find the includes and 
> libraries distributed with the toolchain without having to specify the 
> sysroot.
> 
> Maybe there's a better way to achieve this without the need for a relative 
> `DEFAULT_SYSROOT` but it's been very useful and the config files do not seem 
> suited to replace it.
`--sysroot=` is used as a prefix to certain files, primarily libc and GCC 
installations.

`-DDEFAULT_SYSROOT=...` just changes `clang/lib/Driver/Driver.cpp:203` 
`SysRoot(DEFAULT_SYSROOT)`.
There is no magic related to the `clang` executable path. CMake doesn't do any 
magic, either.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158218

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


[PATCH] D158307: [flang][driver] Disable Clang options in Flang

2023-08-18 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
Herald added a reviewer: sscalpone.
Herald added a project: All.
awarzynski requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Restore the desired setting that was reverted in

  https://reviews.llvm.org/D158289.

This is to be merged once Fortran tests in llvm-test-suite are updated
accordingly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158307

Files:
  clang/lib/Driver/Driver.cpp


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -6495,7 +6495,7 @@
   if (IsDXCMode())
 return llvm::opt::Visibility(options::DXCOption);
   if (IsFlangMode())  {
-return llvm::opt::Visibility(options::ClangOption | options::FlangOption);
+return llvm::opt::Visibility(options::FlangOption);
   }
   return llvm::opt::Visibility(options::ClangOption);
 }


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -6495,7 +6495,7 @@
   if (IsDXCMode())
 return llvm::opt::Visibility(options::DXCOption);
   if (IsFlangMode())  {
-return llvm::opt::Visibility(options::ClangOption | options::FlangOption);
+return llvm::opt::Visibility(options::FlangOption);
   }
   return llvm::opt::Visibility(options::ClangOption);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158231: [clang][test] Fix clang machine-function-split tests

2023-08-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/CodeGen/fsplit-machine-functions.c:1
+// REQUIRES: system-linux
+// REQUIRES: x86-registered-target

Any reason `system-linux` is needed?



Comment at: clang/test/CodeGen/fsplit-machine-functions.c:2
+// REQUIRES: system-linux
+// REQUIRES: x86-registered-target
+// REQUIRES: arm-registered-target

We usually place x86 tests under CodeGen/X86 and arm tests under CodeGen/ARM



Comment at: clang/test/Driver/fsplit-machine-functions.c:1
-// REQUIRES: arm-registered-target
+// REQUIRES: x86-registered-target
 

If you only use `-###`, `// REQUIRES: x86-registered-target` is unneeded.



Comment at: clang/test/Driver/fsplit-machine-functions.c:3
 
-// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata 
-fsplit-machine-functions %s -c -o %t.o 2>&1 | FileCheck 
-check-prefix=CHECK-OPT %s
-// RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c -o %t.o 
2>&1 | FileCheck -check-prefix=CHECK-OPT %s
-// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata 
-fsplit-machine-functions -fno-split-machine-functions %s -c -o %t.o 2>&1 | 
FileCheck -check-prefix=CHECK-NOOPT %s
-// RUN: %clang -c -target arm-unknown-linux-gnueabi -fsplit-machine-functions 
%s -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
+// RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c 2>&1 | 
FileCheck -check-prefix=CHECK_OPT %s
+// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata 
-fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck 
-check-prefix=CHECK_NOOPT %s

Use `--target=` for new tests.



Comment at: llvm/test/CodeGen/Generic/machine-function-splitter.ll:19
 ; MFS_ON: Machine Function Splitter Transformation
-; MFS_ON_NO: warning: -fsplit-machine-functions is not valid for
+; MFS_ON-NOT: warning: -fsplit-machine-functions is not valid for
+; MFS_ON-NOT: warning:

Delete `; MFS_ON-NOT: warning: -fsplit-machine-functions is not valid for`. 
It's unneeded given `; MFS_ON-NOT: warning:`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158231

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


[PATCH] D158218: [CMake] Deprecate DEFAULT_SYSROOT and GCC_INSTALL_PREFIX

2023-08-18 Thread Brian Cain via Phabricator via cfe-commits
bcain added inline comments.



Comment at: clang/CMakeLists.txt:179-183
+if(DEFAULT_SYSROOT)
+  message(WARNING "DEFAULT_SYSROOT is deprecated and will be removed. Use "
+"configuration files 
(https://clang.llvm.org/docs/UsersManual.html#configuration-files)"
+"to specify the default --sysroot=")
+endif()

MaskRay wrote:
> bcain wrote:
> > At one time I believe that the clang configuration files could not specify 
> > paths relative to the clang executable.  AFAICT `DEFAULT_SYSROOT` does 
> > support this.
> > 
> > But if I'm mistaken about that can we add an example to the docs at 
> > https://clang.llvm.org/docs/UsersManual.html#configuration-files 
> > illustrating how to use a relative sysroot?
> Clang configuration files just complement user-specified command line 
> options. As one can do `--sysroot=./sysroot`, one can add 
> `--sysroot=./sysroot` to a configuration file, too.
> 
> If you think having a sysroot example is useful, I can add
> 
> ```
> # Relative --sysroot
> --sysroot=./sysroot
> ```
> before
> clang/docs/UsersManual.rst:1018 `-c --target=x86_64-unknown-linux-gnu`
IIUC: when clang takes a `--sysroot=./sysroot` argument, it will interpret that 
path as a prefix to the files it wants to access.  So the system will treat it 
as relative to the environment's `cwd`, correct?

But when `DEFAULT_SYSROOT` is set to a relative path, that relative path is 
considered to be relative to `clang`.  Therefore a convenient feature that we 
take advantage of is setting it to something like 
`../target/hexagon-unknown-linux-musl` in order to have anyone who invokes 
`hexagon-unknown-linux-clang` from any path be able to find the includes and 
libraries distributed with the toolchain without having to specify the sysroot.

Maybe there's a better way to achieve this without the need for a relative 
`DEFAULT_SYSROOT` but it's been very useful and the config files do not seem 
suited to replace it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158218

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


[PATCH] D157331: [clang] Implement C23

2023-08-18 Thread Zijun Zhao via Phabricator via cfe-commits
ZijunZhao added a comment.

Reformat clang/lib/Lex/PPDirectives.cpp. I use git-clang-format due to previous 
pre-check failure but lots of modifications in clang/lib/Lex/ directory. Should 
I keep running git-clang-format if the pre-check fails again?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157331

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


[PATCH] D157762: [WIP] Implement [[msvc::no_unique_address]]

2023-08-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/AST/Decl.cpp:4523-4524
 bool FieldDecl::isPotentiallyOverlapping() const {
-  return hasAttr() && getType()->getAsCXXRecordDecl();
+  return (hasAttr() ||
+  hasAttr()) &&
+ getType()->getAsCXXRecordDecl();

akhuang wrote:
> aaron.ballman wrote:
> > akhuang wrote:
> > > aaron.ballman wrote:
> > > > dblaikie wrote:
> > > > > Having to check both of these in several places seems problematic - 
> > > > > can we wrap that up somewhere? (or, maybe ideally, is there a way for 
> > > > > `msvc::no_unique_address` to map to the actual NoUniqueAddressAttr as 
> > > > > a different spelling of the same thing?)
> > > > This was why I was hoping we could merge the two in Attr.td, but I'm 
> > > > not certain that will be easy.
> > > What does merging the two in Attr.td mean? Could we just put the two 
> > > spellings in one attribute, or would that make it impossible for clang-cl 
> > > to ignore the [[no_unique_address]] spelling
> > We can have multiple syntactic spellings for the same semantic attribute 
> > (e.g., `__attribute__((foo))` and `__attribute__((bar))` can both map to a 
> > single `FooBarAttr` AST node), and we have "accessors" on the AST node that 
> > let you tell which spelling was used: 
> > https://github.com/llvm/llvm-project/blob/90ecadde62f30275c35fdf7928e3477a41691d21/clang/include/clang/Basic/Attr.td#L4095
> > 
> > The suggestion Erich and I are thinking of is:
> > 
> > 1) Add the additional spelling to `NoUniqueAddress`.
> > 2) Add accessors to differentiate the spellings.
> > 3) Remove the `TargetSpecificAttr` from `NoUniqueAddress`, manually 
> > implement those checks in an attribute handler in SemaDeclAttr.cpp.
> > 
> > Then, anywhere you care about the attribute in general, you can look for 
> > `isa`, and anywhere you care about which spelling, you can 
> > use `cast(A)->isMSVC()` (or whatever you name the 
> > accessors).
> Thanks! This patch should implement this, and so far, I don't think there are 
> any places outside of SemaDeclAttr where we have to differentiate the two.
(awesome - glad to see this was so tidy to do/that the generic attribute 
handling stuff mostly covers it)



Comment at: clang/lib/AST/Decl.cpp:4510
+  if (Ctx.getTargetInfo().getCXXABI().isMicrosoft() &&
+  llvm::any_of(CXXRD->fields(), [&](const FieldDecl *Field) {
+return Field->getType()->getAs();





Comment at: clang/lib/AST/RecordLayoutBuilder.cpp:3096-3098
+  if (!IsOverlappingEmptyField) {
+DataSize = std::max(DataSize, FieldOffset + Info.Size);
+  }




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157762

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


[PATCH] D157331: [clang] Implement C23

2023-08-18 Thread Zijun Zhao via Phabricator via cfe-commits
ZijunZhao updated this revision to Diff 551607.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157331

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/stdckdint.h
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/test/C/C2x/n2359.c
  clang/test/C/C2x/n2683.c
  clang/test/C/C2x/n2683_2.c
  clang/test/Headers/stdckdint.c
  clang/test/Modules/Inputs/System/usr/include/module.map
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -887,6 +887,11 @@
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2672.pdf;>N2672
   Yes
 
+
+  Towards Integer Safety
+  https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2683.pdf;>N2683
+  Clang 18
+
 
   Adding Fundamental Type for N-bit Integers
 
Index: clang/test/Modules/Inputs/System/usr/include/module.map
===
--- clang/test/Modules/Inputs/System/usr/include/module.map
+++ clang/test/Modules/Inputs/System/usr/include/module.map
@@ -14,6 +14,11 @@
 header "stdbool.h"
   }
 
+  // In both directories (compiler support version wins, does not forward)
+  module stdckdint {
+header "stdckdint.h"
+  }
+
   // In both directories (compiler support version wins, forwards)
   module stdint {
 header "stdint.h"
Index: clang/test/Headers/stdckdint.c
===
--- /dev/null
+++ clang/test/Headers/stdckdint.c
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -emit-llvm -verify -fgnuc-version=4.2.1 -std=c23 %s -o - | FileCheck %s
+// expected-no-diagnostics
+#include 
+
+// CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add() #0 {
+// CHECK:  entry:
+// CHECK:%result = alloca i32, align 4
+// CHECK:%0 = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 -1073741826, i32 -1073741826)
+// CHECK:%1 = extractvalue { i32, i1 } %0, 1
+// CHECK:%2 = extractvalue { i32, i1 } %0, 0
+// CHECK:store i32 %2, ptr %result, align 4
+// CHECK:ret i1 %1
+// CHECK:}
+// CHECK:; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+// CHECK:declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) #1
+bool test_ckd_add() {
+  int result;
+  return ckd_add(, -1073741826, -1073741826);
+}
+
+// CHECK-LABEL: define dso_local zeroext i1 @test_ckd_sub() #0 {
+// CHECK:  entry:
+// CHECK:%result = alloca i32, align 4
+// CHECK:%0 = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 -1073741826, i32 1073741826)
+// CHECK:%1 = extractvalue { i32, i1 } %0, 1
+// CHECK:%2 = extractvalue { i32, i1 } %0, 0
+// CHECK:store i32 %2, ptr %result, align 4
+// CHECK:ret i1 %1
+// CHECK:}
+// CHECK:declare { i32, i1 } @llvm.ssub.with.overflow.i32(i32, i32) #1
+bool test_ckd_sub() {
+  int result;
+  return ckd_sub(, -1073741826, 1073741826);
+}
+
+// CHECK-LABEL: define dso_local zeroext i1 @test_ckd_mul() #0 {
+// CHECK:  entry:
+// CHECK:%result = alloca i32, align 4
+// CHECK:%0 = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 -1073741826, i32 2)
+// CHECK:%1 = extractvalue { i32, i1 } %0, 1
+// CHECK:%2 = extractvalue { i32, i1 } %0, 0
+// CHECK:store i32 %2, ptr %result, align 4
+// CHECK:ret i1 %1
+// CHECK:}
+// CHECK:declare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32) #1
+bool test_ckd_mul() {
+  int result;
+  return ckd_mul(, -1073741826, 2);
+}
Index: clang/test/C/C2x/n2683_2.c
===
--- /dev/null
+++ clang/test/C/C2x/n2683_2.c
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -emit-llvm -o - -std=c23 %s | FileCheck %s
+// expected-no-diagnostics
+
+#include 
+#include 
+// CHECK-LABEL: define dso_local void @test_add_overflow_to64() #0 {
+// CHECK:  entry:
+// CHECK:%result64 = alloca i64, align 8
+// CHECK:%flag_add = alloca i8, align 1
+// CHECK:store i64 0, ptr %result64, align 8
+// CHECK:%0 = call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 2147483647, i64 1)
+// CHECK:%1 = extractvalue { i64, i1 } %0, 1 
+// CHECK:%2 = extractvalue { i64, i1 } %0, 0
+// CHECK:store i64 %2, ptr %result64, align 8
+// CHECK:%frombool = zext i1 %1 to i8
+// CHECK:store i8 %frombool, ptr %flag_add, align 1
+// CHECK:ret void
+// CHECK:  }
+void test_add_overflow_to64() {
+int64_t result64 = 0;
+bool flag_add = ckd_add(, INT32_MAX, 1);
+}
+
+// CHECK-LABEL: define dso_local void @test_sub_overflow() #0 {
+// CHECK:  entry:
+// CHECK:%result32 = alloca i32, align 4
+// CHECK:%flag_sub = alloca i8, align 1
+// CHECK:store i32 0, ptr %result32, align 4
+// CHECK:%0 = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 2147483647, i32 

[PATCH] D158218: [CMake] Deprecate DEFAULT_SYSROOT and GCC_INSTALL_PREFIX

2023-08-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/CMakeLists.txt:179-183
+if(DEFAULT_SYSROOT)
+  message(WARNING "DEFAULT_SYSROOT is deprecated and will be removed. Use "
+"configuration files 
(https://clang.llvm.org/docs/UsersManual.html#configuration-files)"
+"to specify the default --sysroot=")
+endif()

bcain wrote:
> At one time I believe that the clang configuration files could not specify 
> paths relative to the clang executable.  AFAICT `DEFAULT_SYSROOT` does 
> support this.
> 
> But if I'm mistaken about that can we add an example to the docs at 
> https://clang.llvm.org/docs/UsersManual.html#configuration-files illustrating 
> how to use a relative sysroot?
Clang configuration files just complement user-specified command line options. 
As one can do `--sysroot=./sysroot`, one can add `--sysroot=./sysroot` to a 
configuration file, too.

If you think having a sysroot example is useful, I can add

```
# Relative --sysroot
--sysroot=./sysroot
```
before
clang/docs/UsersManual.rst:1018 `-c --target=x86_64-unknown-linux-gnu`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158218

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


[PATCH] D157762: [WIP] Implement [[msvc::no_unique_address]]

2023-08-18 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:1409
+
+  On Windows targets, ``[[no_unique_address]]`` is ignored; use
+  ``[[msvc::no_unique_address]]`` instead.

On MSVC targets, `[[no_unique_address]]` is ignored - it's not ignored for 
mingw targets.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157762

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


[PATCH] D153156: [Clang] CWG1473: do not err on the lack of space after operator""

2023-08-18 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao added a comment.

I’ll see what I can do regarding reviving the string concat behavior. It feels 
like that a more refined treatment than before can be achieved. Maybe adds an 
imaginary preceding whitespace only when we can find a macro with the same name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153156

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


[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

I just put up a patch for RISC-V failure related to this 
https://reviews.llvm.org/D158304 change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156821

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


[PATCH] D158296: [NFC][Clang] Add assertion to check the value of NumSubExprs/ResultIndex does not overflow

2023-08-18 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Hopefully my clarification on https://reviews.llvm.org/D154784#inline-1531176 
makes it clear that assertions aren't necessarily the right tool here - as this 
path is reachable with actual code & I don't think we should allow that code to 
reach UB in the compiler in a non-assertionsn build. If we think this is a 
sufficient size to support, then we should error clearly even in a 
non-assertions build.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158296

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


[PATCH] D153924: [OpenMP] Allow exceptions in target regions when offloading to GPUs

2023-08-18 Thread Anton Rydahl via Phabricator via cfe-commits
AntonRydahl updated this revision to Diff 551600.
AntonRydahl added a comment.

CI tests failed on the built-bot, but that was not related to this patch. I 
patched the file that made the built-bot fail and rebased this differential 
after the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153924

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/CodeGen/CGException.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/OpenMP/amdgpu_exceptions.cpp
  clang/test/OpenMP/amdgpu_throw.cpp
  clang/test/OpenMP/amdgpu_throw_trap.cpp
  clang/test/OpenMP/amdgpu_try_catch.cpp
  clang/test/OpenMP/nvptx_exceptions.cpp
  clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
  clang/test/OpenMP/nvptx_throw.cpp
  clang/test/OpenMP/nvptx_throw_trap.cpp
  clang/test/OpenMP/nvptx_try_catch.cpp
  clang/test/OpenMP/x86_target_exceptions.cpp
  clang/test/OpenMP/x86_target_throw.cpp
  clang/test/OpenMP/x86_target_try_catch.cpp

Index: clang/test/OpenMP/x86_target_try_catch.cpp
===
--- /dev/null
+++ clang/test/OpenMP/x86_target_try_catch.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fopenmp -triple x86_64-pc-linux-gnu -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify -Wopenmp-target-exception -o - &> /dev/null
+#pragma omp declare target
+int foo(void) {
+	int error = -1;
+	try {
+		error = 1;
+	}
+	catch (int e){ 
+		error = e;
+	}
+	return error;
+}
+#pragma omp end declare target
+// expected-no-diagnostics
Index: clang/test/OpenMP/x86_target_throw.cpp
===
--- /dev/null
+++ clang/test/OpenMP/x86_target_throw.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fopenmp -triple x86_64-pc-linux-gnu -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify -Wopenmp-target-exception -o - &> /dev/null
+#pragma omp declare target
+void foo(void) {
+	throw 404;
+}
+#pragma omp end declare target
+// expected-no-diagnostics
Index: clang/test/OpenMP/x86_target_exceptions.cpp
===
--- /dev/null
+++ clang/test/OpenMP/x86_target_exceptions.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fopenmp -triple x86_64-pc-linux-gnu -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify -Wopenmp-target-exception -o - &> /dev/null
+#pragma omp declare target
+int foo(void) {
+	int error = -1;
+	try {
+		throw 404;
+	}
+	catch (int e){ 
+		error = e;
+	}
+	return error;
+}
+#pragma omp end declare target
+// expected-no-diagnostics
Index: clang/test/OpenMP/nvptx_try_catch.cpp
===
--- /dev/null
+++ clang/test/OpenMP/nvptx_try_catch.cpp
@@ -0,0 +1,45 @@
+/**
+ * The first four lines test that a warning is produced when enabling 
+ * -Wopenmp-target-exception no matter what combination of -fexceptions and 
+ * -fcxx-exceptions are set, as we want OpenMP to always allow exceptions in the
+ * target region but emit a warning instead.
+*/
+
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -o - &> /dev/null
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -o - &> /dev/null
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fexceptions %s -emit-llvm -S -verify=with -Wopenmp-target-exception -o - &> /dev/null
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device %s -emit-llvm -S -verify=with -Wopenmp-target-exception -o - &> /dev/null
+
+/**
+ * The following four lines test that no warning is emitted when providing 
+ * -Wno-openmp-target-exception no matter the combination of -fexceptions and 
+ * -fcxx-exceptions.
+*/
+
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions -fexceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -o - &> /dev/null
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fcxx-exceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -o - &> /dev/null
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device -fexceptions %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -o - &> /dev/null
+// RUN: %clang_cc1 -fopenmp -triple nvptx64 -fopenmp-is-target-device %s -emit-llvm -S -verify=without -Wno-openmp-target-exception -o - &> /dev/null
+
+/**
+ * Finally we should test that we only ignore exceptions in the OpenMP 
+ * offloading tool-chain
+*/
+
+// RUN: %clang_cc1 -triple nvptx64 %s -emit-llvm -S -verify=noexceptions -o -
+
+// noexceptions-error@36 {{cannot use 'try' with 

  1   2   3   >