[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-09 Thread Vikash Gupta via cfe-commits

https://github.com/vg0204 updated 
https://github.com/llvm/llvm-project/pull/95750

>From cbe656fa6db50319e74c0fab166538518506974e Mon Sep 17 00:00:00 2001
From: vg0204 
Date: Mon, 17 Jun 2024 11:20:02 +0530
Subject: [PATCH 1/5] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2
 and below

The __builtin_alloca was returning a flat pointer with no address
space when compiled using openCL1.2 or below but worked fine with
openCL2.0 and above. This accounts to the fact that later uses the
concept of generic address space which supports cast to other address
space(i.e to private address space which is used for stack allocation)
.

So, in  case of openCL1.2 and below __built_alloca is supposed to
return pointer to private address space to eliminate the need of
casting as not supported here. Thus,it requires redefintion of the
builtin function with appropraite return pointer to appropriate
address space.
---
 clang/lib/Sema/SemaExpr.cpp | 23 +-
 clang/test/CodeGenOpenCL/builtins-alloca.cl | 86 +
 clang/test/CodeGenOpenCL/memcpy.cl  |  0
 3 files changed, 106 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenOpenCL/builtins-alloca.cl
 mode change 100644 => 100755 clang/test/CodeGenOpenCL/memcpy.cl

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4db8b4130c3c7..bb63020dadb83 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6231,7 +6231,10 @@ bool Sema::CheckArgsForPlaceholders(MultiExprArg args) {
 ///  it does not contain any pointer arguments without
 ///  an address space qualifer.  Otherwise the rewritten
 ///  FunctionDecl is returned.
-/// TODO: Handle pointer return types.
+///
+/// Pointer return type with no explicit address space is assigned the
+/// default address space where pointer points to based on the language
+/// option used to compile it.
 static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext 
,
 FunctionDecl *FDecl,
 MultiExprArg ArgExprs) {
@@ -6275,13 +6278,27 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema 
*Sema, ASTContext ,
 OverloadParams.push_back(Context.getPointerType(PointeeType));
   }
 
+  QualType ReturnTy = FT->getReturnType();
+  QualType OverloadReturnTy = ReturnTy;
+  if (ReturnTy->isPointerType() &&
+  !ReturnTy->getPointeeType().hasAddressSpace()) {
+if (Sema->getLangOpts().OpenCL) {
+  NeedsNewDecl = true;
+
+  QualType ReturnPtTy = ReturnTy->getPointeeType();
+  LangAS defClAS = Context.getDefaultOpenCLPointeeAddrSpace();
+  ReturnPtTy = Context.getAddrSpaceQualType(ReturnPtTy, defClAS);
+  OverloadReturnTy = Context.getPointerType(ReturnPtTy);
+}
+  }
+
   if (!NeedsNewDecl)
 return nullptr;
 
   FunctionProtoType::ExtProtoInfo EPI;
   EPI.Variadic = FT->isVariadic();
-  QualType OverloadTy = Context.getFunctionType(FT->getReturnType(),
-OverloadParams, EPI);
+  QualType OverloadTy =
+  Context.getFunctionType(OverloadReturnTy, OverloadParams, EPI);
   DeclContext *Parent = FDecl->getParent();
   FunctionDecl *OverloadDecl = FunctionDecl::Create(
   Context, Parent, FDecl->getLocation(), FDecl->getLocation(),
diff --git a/clang/test/CodeGenOpenCL/builtins-alloca.cl 
b/clang/test/CodeGenOpenCL/builtins-alloca.cl
new file mode 100644
index 0..74a86955f2e4f
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-alloca.cl
@@ -0,0 +1,86 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL1.2 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL12 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL2.0 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL20 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL30 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 
-cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - | FileCheck 
--check-prefix=OPENCL30-EXT %s
+
+// OPENCL12-LABEL: define dso_local ptr addrspace(5) @test1(
+// OPENCL12-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL12-NEXT:  [[ENTRY:.*:]]
+// OPENCL12-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL12-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL12-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:[[TMP1:%.*]] = load ptr addrspace(5), ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:ret ptr addrspace(5) [[TMP1]]
+//
+// OPENCL20-LABEL: define dso_local ptr @test1(
+// OPENCL20-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL20-NEXT:  [[ENTRY:.*:]]
+// OPENCL20-NEXT:

[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-09 Thread Vikash Gupta via cfe-commits

https://github.com/vg0204 updated 
https://github.com/llvm/llvm-project/pull/95750

>From cbe656fa6db50319e74c0fab166538518506974e Mon Sep 17 00:00:00 2001
From: vg0204 
Date: Mon, 17 Jun 2024 11:20:02 +0530
Subject: [PATCH 1/5] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2
 and below

The __builtin_alloca was returning a flat pointer with no address
space when compiled using openCL1.2 or below but worked fine with
openCL2.0 and above. This accounts to the fact that later uses the
concept of generic address space which supports cast to other address
space(i.e to private address space which is used for stack allocation)
.

So, in  case of openCL1.2 and below __built_alloca is supposed to
return pointer to private address space to eliminate the need of
casting as not supported here. Thus,it requires redefintion of the
builtin function with appropraite return pointer to appropriate
address space.
---
 clang/lib/Sema/SemaExpr.cpp | 23 +-
 clang/test/CodeGenOpenCL/builtins-alloca.cl | 86 +
 clang/test/CodeGenOpenCL/memcpy.cl  |  0
 3 files changed, 106 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenOpenCL/builtins-alloca.cl
 mode change 100644 => 100755 clang/test/CodeGenOpenCL/memcpy.cl

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4db8b4130c3c7..bb63020dadb83 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6231,7 +6231,10 @@ bool Sema::CheckArgsForPlaceholders(MultiExprArg args) {
 ///  it does not contain any pointer arguments without
 ///  an address space qualifer.  Otherwise the rewritten
 ///  FunctionDecl is returned.
-/// TODO: Handle pointer return types.
+///
+/// Pointer return type with no explicit address space is assigned the
+/// default address space where pointer points to based on the language
+/// option used to compile it.
 static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext 
,
 FunctionDecl *FDecl,
 MultiExprArg ArgExprs) {
@@ -6275,13 +6278,27 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema 
*Sema, ASTContext ,
 OverloadParams.push_back(Context.getPointerType(PointeeType));
   }
 
+  QualType ReturnTy = FT->getReturnType();
+  QualType OverloadReturnTy = ReturnTy;
+  if (ReturnTy->isPointerType() &&
+  !ReturnTy->getPointeeType().hasAddressSpace()) {
+if (Sema->getLangOpts().OpenCL) {
+  NeedsNewDecl = true;
+
+  QualType ReturnPtTy = ReturnTy->getPointeeType();
+  LangAS defClAS = Context.getDefaultOpenCLPointeeAddrSpace();
+  ReturnPtTy = Context.getAddrSpaceQualType(ReturnPtTy, defClAS);
+  OverloadReturnTy = Context.getPointerType(ReturnPtTy);
+}
+  }
+
   if (!NeedsNewDecl)
 return nullptr;
 
   FunctionProtoType::ExtProtoInfo EPI;
   EPI.Variadic = FT->isVariadic();
-  QualType OverloadTy = Context.getFunctionType(FT->getReturnType(),
-OverloadParams, EPI);
+  QualType OverloadTy =
+  Context.getFunctionType(OverloadReturnTy, OverloadParams, EPI);
   DeclContext *Parent = FDecl->getParent();
   FunctionDecl *OverloadDecl = FunctionDecl::Create(
   Context, Parent, FDecl->getLocation(), FDecl->getLocation(),
diff --git a/clang/test/CodeGenOpenCL/builtins-alloca.cl 
b/clang/test/CodeGenOpenCL/builtins-alloca.cl
new file mode 100644
index 0..74a86955f2e4f
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-alloca.cl
@@ -0,0 +1,86 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL1.2 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL12 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL2.0 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL20 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL30 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 
-cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - | FileCheck 
--check-prefix=OPENCL30-EXT %s
+
+// OPENCL12-LABEL: define dso_local ptr addrspace(5) @test1(
+// OPENCL12-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL12-NEXT:  [[ENTRY:.*:]]
+// OPENCL12-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL12-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL12-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:[[TMP1:%.*]] = load ptr addrspace(5), ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:ret ptr addrspace(5) [[TMP1]]
+//
+// OPENCL20-LABEL: define dso_local ptr @test1(
+// OPENCL20-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL20-NEXT:  [[ENTRY:.*:]]
+// OPENCL20-NEXT:

[clang] [clang] inherit GD to let the codegen add kcfi type for ifunc (PR #96400)

2024-07-09 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> Oh, hmm, I see.
> 
> Maybe the right strategy here is to delay attaching the resolver to the ifunc 
> until the end of the translation unit, when we know the definition is already 
> emitted. That way, it should already have the right attributes. (We already 
> do some delayed checking on aliases/ifuncs anyway, in checkAliasedGlobal().)

@efriedma-quic I've tried your suggestion: move `setResolver` to 
`checkAliasedGlobal`. However, I've run into some difficulty. When 
`EmitGlobal(foo)` is called, how to mark `resolver` as eagerly emitted? 
(Otherwise, `resolver` would not be emitted at all.)

```c
int foo(int) __attribute__ ((ifunc("resolver")));
static void *resolver(void) { return 0; }   // MustBeEmitted(Global) return 
false
```

https://github.com/llvm/llvm-project/pull/96400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 015526b - [RISCV] Fix spelling instuctions->instructions.

2024-07-09 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2024-07-09T22:35:46-07:00
New Revision: 015526bf3fc6843ad28f9e0809598453228c4bc2

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

LOG: [RISCV] Fix spelling instuctions->instructions.

Taken from #98259 and with the necessary test updates added.

Added: 


Modified: 
clang/test/Driver/print-supported-extensions-riscv.c
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/test/MC/RISCV/rv32zcmt-valid.s

Removed: 




diff  --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 49bdb21ac59d6..d3df5b9208e74 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -51,8 +51,8 @@
 // CHECK-NEXT: zce  1.0   'Zce' (Compressed extensions 
for microcontrollers)
 // CHECK-NEXT: zcf  1.0   'Zcf' (Compressed 
Single-Precision Floating-Point Instructions)
 // CHECK-NEXT: zcmop1.0   'Zcmop' (Compressed 
May-Be-Operations)
-// CHECK-NEXT: zcmp 1.0   'Zcmp' (sequenced 
instuctions for code-size reduction)
-// CHECK-NEXT: zcmt 1.0   'Zcmt' (table jump 
instuctions for code-size reduction)
+// CHECK-NEXT: zcmp 1.0   'Zcmp' (sequenced 
instructions for code-size reduction)
+// CHECK-NEXT: zcmt 1.0   'Zcmt' (table jump 
instructions for code-size reduction)
 // CHECK-NEXT: zba  1.0   'Zba' (Address Generation 
Instructions)
 // CHECK-NEXT: zbb  1.0   'Zbb' (Basic 
Bit-Manipulation)
 // CHECK-NEXT: zbc  1.0   'Zbc' (Carry-Less 
Multiplication)

diff  --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index e2a8fb485850f..72d01f1258013 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -406,19 +406,19 @@ def FeatureStdExtZcf
 
 def FeatureStdExtZcmp
 : RISCVExtension<"zcmp", 1, 0,
- "'Zcmp' (sequenced instuctions for code-size reduction)",
+ "'Zcmp' (sequenced instructions for code-size reduction)",
  [FeatureStdExtZca]>;
 def HasStdExtZcmp : Predicate<"Subtarget->hasStdExtZcmp() && 
!Subtarget->hasStdExtC()">,
 AssemblerPredicate<(all_of FeatureStdExtZcmp),
-"'Zcmp' (sequenced instuctions for code-size 
reduction)">;
+"'Zcmp' (sequenced instructions for code-size 
reduction)">;
 
 def FeatureStdExtZcmt
 : RISCVExtension<"zcmt", 1, 0,
- "'Zcmt' (table jump instuctions for code-size reduction)",
+ "'Zcmt' (table jump instructions for code-size 
reduction)",
  [FeatureStdExtZca, FeatureStdExtZicsr]>;
 def HasStdExtZcmt : Predicate<"Subtarget->hasStdExtZcmt()">,
AssemblerPredicate<(all_of FeatureStdExtZcmt),
-   "'Zcmt' (table jump instuctions for code-size 
reduction)">;
+   "'Zcmt' (table jump instructions for code-size 
reduction)">;
 
 def FeatureStdExtZce
 : RISCVExtension<"zce", 1, 0,

diff  --git a/llvm/test/MC/RISCV/rv32zcmt-valid.s 
b/llvm/test/MC/RISCV/rv32zcmt-valid.s
index bc58e189d0ffa..a3829fed829f0 100644
--- a/llvm/test/MC/RISCV/rv32zcmt-valid.s
+++ b/llvm/test/MC/RISCV/rv32zcmt-valid.s
@@ -24,10 +24,10 @@
 
 # CHECK-ASM-AND-OBJ: cm.jt 1
 # CHECK-ASM: encoding: [0x06,0xa0]
-# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump 
instuctions for code-size reduction){{$}}
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump 
instructions for code-size reduction){{$}}
 cm.jt 1
 
 # CHECK-ASM-AND-OBJ: cm.jalt 32
 # CHECK-ASM: encoding: [0x82,0xa0]
-# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump 
instuctions for code-size reduction){{$}}
+# CHECK-NO-EXT: error: instruction requires the following: 'Zcmt' (table jump 
instructions for code-size reduction){{$}}
 cm.jalt 32



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


[clang] [llvm] Clang: don't unnecessarily convert inline-asm operands to x86mmx in IR. (PR #98273)

2024-07-09 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff bf528849819733482cff205f3bdf1fe9ce2b92a4 
546963316017935bfbbc05d7095d645344fbd5f5 -- clang/lib/CodeGen/Targets/X86.cpp 
clang/test/CodeGen/X86/mmx-inline-asm.c clang/test/CodeGen/asm-inout.c 
llvm/lib/Target/X86/X86ISelLowering.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 7fb9a4c070..5d33a8f5f3 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -24,9 +24,9 @@ bool IsX86_MMXType(llvm::Type *IRType) {
 IRType->getScalarSizeInBits() != 64;
 }
 
-static llvm::Type* X86AdjustInlineAsmType(CodeGen::CodeGenFunction ,
+static llvm::Type *X86AdjustInlineAsmType(CodeGen::CodeGenFunction ,
   StringRef Constraint,
-  llvm::Type* Ty) {
+  llvm::Type *Ty) {
   if (Constraint == "k") {
 llvm::Type *Int1Ty = llvm::Type::getInt1Ty(CGF.getLLVMContext());
 return llvm::FixedVectorType::get(Int1Ty, Ty->getScalarSizeInBits());

``




https://github.com/llvm/llvm-project/pull/98273
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Clang: don't unnecessarily convert inline-asm operands to x86mmx in IR. (PR #98273)

2024-07-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: James Y Knight (jyknight)


Changes

The SelectionDAG asm-lowering code can already handle conversion of other 
vector types to MMX if needed.


---
Full diff: https://github.com/llvm/llvm-project/pull/98273.diff


5 Files Affected:

- (modified) clang/lib/CodeGen/Targets/X86.cpp (-13) 
- (modified) clang/test/CodeGen/X86/mmx-inline-asm.c (+1-1) 
- (modified) clang/test/CodeGen/asm-inout.c (+3-3) 
- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+3-3) 
- (added) llvm/test/CodeGen/X86/mmx-inlineasm.ll (+20) 


``diff
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 3146caba1c615..7fb9a4c070873 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -27,19 +27,6 @@ bool IsX86_MMXType(llvm::Type *IRType) {
 static llvm::Type* X86AdjustInlineAsmType(CodeGen::CodeGenFunction ,
   StringRef Constraint,
   llvm::Type* Ty) {
-  bool IsMMXCons = llvm::StringSwitch(Constraint)
- .Cases("y", "", "^Ym", true)
- .Default(false);
-  if (IsMMXCons && Ty->isVectorTy()) {
-if (cast(Ty)->getPrimitiveSizeInBits().getFixedValue() !=
-64) {
-  // Invalid MMX constraint
-  return nullptr;
-}
-
-return llvm::Type::getX86_MMXTy(CGF.getLLVMContext());
-  }
-
   if (Constraint == "k") {
 llvm::Type *Int1Ty = llvm::Type::getInt1Ty(CGF.getLLVMContext());
 return llvm::FixedVectorType::get(Int1Ty, Ty->getScalarSizeInBits());
diff --git a/clang/test/CodeGen/X86/mmx-inline-asm.c 
b/clang/test/CodeGen/X86/mmx-inline-asm.c
index 19c24a3a91e14..a0702c7f780d1 100644
--- a/clang/test/CodeGen/X86/mmx-inline-asm.c
+++ b/clang/test/CodeGen/X86/mmx-inline-asm.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -emit-llvm -triple i386 -target-feature +mmx %s -o - | 
FileCheck %s
 #include 
 
-// CHECK: { x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx }
+// CHECK: { <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64>, 
<1 x i64> }
 
 void foo(long long fill) {
   __m64 vfill = _mm_cvtsi64_m64(fill);
diff --git a/clang/test/CodeGen/asm-inout.c b/clang/test/CodeGen/asm-inout.c
index 1383a421efbc2..6d40451b778d9 100644
--- a/clang/test/CodeGen/asm-inout.c
+++ b/clang/test/CodeGen/asm-inout.c
@@ -38,11 +38,11 @@ int test4(volatile int *addr) {
   return (int)oldval;
 }
 
-// This should have both inputs be of type x86_mmx.
+// This should have both inputs be of type <1 x i64>.
 // CHECK: @test5
 typedef long long __m64 __attribute__((__vector_size__(8)));
 __m64 test5(__m64 __A, __m64 __B) {
-  // CHECK: call x86_mmx asm "pmulhuw $1, $0\0A\09", 
"=y,y,0,~{dirflag},~{fpsr},~{flags}"(x86_mmx %{{.*}}, x86_mmx %{{.*}})
+  // CHECK: call <1 x i64> asm "pmulhuw $1, $0\0A\09", 
"=y,y,0,~{dirflag},~{fpsr},~{flags}"(<1 x i64> %{{.*}}, <1 x i64> %{{.*}})
   asm ("pmulhuw %1, %0\n\t" : "+y" (__A) : "y" (__B));
   return __A;
 }
@@ -51,7 +51,7 @@ __m64 test5(__m64 __A, __m64 __B) {
 int test6(void) {
   typedef unsigned char __attribute__((vector_size(8))) _m64u8;
   _m64u8 __attribute__((aligned(16))) Mu8_0, __attribute__((aligned(16))) 
Mu8_1;
-  // CHECK: call x86_mmx asm "nop", "=y,0,~{dirflag},~{fpsr},~{flags}"(x86_mmx 
%1)
+  // CHECK: call <8 x i8> asm "nop", "=y,0,~{dirflag},~{fpsr},~{flags}"(<8 x 
i8> %0)
   asm ("nop" : "=y"(Mu8_1 ) : "0"(Mu8_0 ));
   return 0;
 }
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 50cacc3038b0c..d2e7074c59077 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -58150,7 +58150,7 @@ X86TargetLowering::getSingleConstraintMatchWeight(
   Wt = CW_SpecificReg;
 break;
   case 'y':
-if (Ty->isX86_MMXTy() && Subtarget.hasMMX())
+if (Ty->getPrimitiveSizeInBits() == 64 && Subtarget.hasMMX())
   Wt = CW_SpecificReg;
 break;
   case 'Y':
@@ -58173,8 +58173,8 @@ X86TargetLowering::getSingleConstraintMatchWeight(
   return CW_Invalid;
 // Any MMX reg
 case 'm':
-  if (Ty->isX86_MMXTy() && Subtarget.hasMMX())
-return Wt;
+  if (Ty->getPrimitiveSizeInBits() == 64 && Subtarget.hasMMX())
+return CW_SpecificReg;
   return CW_Invalid;
 // Any SSE reg when ISA >= SSE2, same as 'x'
 case 'i':
diff --git a/llvm/test/CodeGen/X86/mmx-inlineasm.ll 
b/llvm/test/CodeGen/X86/mmx-inlineasm.ll
new file mode 100644
index 0..5a15600a4b312
--- /dev/null
+++ b/llvm/test/CodeGen/X86/mmx-inlineasm.ll
@@ -0,0 +1,20 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+mmx | FileCheck %s
+
+;; Verify that the mmx 'y' constraint works with arbitrary IR types.
+define <2 x i32> @test_mmx_asm(<2 x i32> %a) nounwind {
+; CHECK-LABEL: test_mmx_asm:
+; CHECK:   # 

[clang] [llvm] Clang: don't unnecessarily convert inline-asm operands to x86mmx in IR. (PR #98273)

2024-07-09 Thread James Y Knight via cfe-commits

https://github.com/jyknight created 
https://github.com/llvm/llvm-project/pull/98273

The SelectionDAG asm-lowering code can already handle conversion of other 
vector types to MMX if needed.


>From 546963316017935bfbbc05d7095d645344fbd5f5 Mon Sep 17 00:00:00 2001
From: James Y Knight 
Date: Wed, 10 Jul 2024 00:49:25 -0400
Subject: [PATCH] Clang: don't unnecessarily convert inline-asm operands to
 x86mmx in IR.

The SelectionDAG asm-lowering code can already handle conversion of other 
vector types to MMX if needed.
---
 clang/lib/CodeGen/Targets/X86.cpp   | 13 -
 clang/test/CodeGen/X86/mmx-inline-asm.c |  2 +-
 clang/test/CodeGen/asm-inout.c  |  6 +++---
 llvm/lib/Target/X86/X86ISelLowering.cpp |  6 +++---
 llvm/test/CodeGen/X86/mmx-inlineasm.ll  | 20 
 5 files changed, 27 insertions(+), 20 deletions(-)
 create mode 100644 llvm/test/CodeGen/X86/mmx-inlineasm.ll

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 3146caba1c615..7fb9a4c070873 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -27,19 +27,6 @@ bool IsX86_MMXType(llvm::Type *IRType) {
 static llvm::Type* X86AdjustInlineAsmType(CodeGen::CodeGenFunction ,
   StringRef Constraint,
   llvm::Type* Ty) {
-  bool IsMMXCons = llvm::StringSwitch(Constraint)
- .Cases("y", "", "^Ym", true)
- .Default(false);
-  if (IsMMXCons && Ty->isVectorTy()) {
-if (cast(Ty)->getPrimitiveSizeInBits().getFixedValue() !=
-64) {
-  // Invalid MMX constraint
-  return nullptr;
-}
-
-return llvm::Type::getX86_MMXTy(CGF.getLLVMContext());
-  }
-
   if (Constraint == "k") {
 llvm::Type *Int1Ty = llvm::Type::getInt1Ty(CGF.getLLVMContext());
 return llvm::FixedVectorType::get(Int1Ty, Ty->getScalarSizeInBits());
diff --git a/clang/test/CodeGen/X86/mmx-inline-asm.c 
b/clang/test/CodeGen/X86/mmx-inline-asm.c
index 19c24a3a91e14..a0702c7f780d1 100644
--- a/clang/test/CodeGen/X86/mmx-inline-asm.c
+++ b/clang/test/CodeGen/X86/mmx-inline-asm.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -emit-llvm -triple i386 -target-feature +mmx %s -o - | 
FileCheck %s
 #include 
 
-// CHECK: { x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx, x86_mmx }
+// CHECK: { <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64>, <1 x i64>, 
<1 x i64> }
 
 void foo(long long fill) {
   __m64 vfill = _mm_cvtsi64_m64(fill);
diff --git a/clang/test/CodeGen/asm-inout.c b/clang/test/CodeGen/asm-inout.c
index 1383a421efbc2..6d40451b778d9 100644
--- a/clang/test/CodeGen/asm-inout.c
+++ b/clang/test/CodeGen/asm-inout.c
@@ -38,11 +38,11 @@ int test4(volatile int *addr) {
   return (int)oldval;
 }
 
-// This should have both inputs be of type x86_mmx.
+// This should have both inputs be of type <1 x i64>.
 // CHECK: @test5
 typedef long long __m64 __attribute__((__vector_size__(8)));
 __m64 test5(__m64 __A, __m64 __B) {
-  // CHECK: call x86_mmx asm "pmulhuw $1, $0\0A\09", 
"=y,y,0,~{dirflag},~{fpsr},~{flags}"(x86_mmx %{{.*}}, x86_mmx %{{.*}})
+  // CHECK: call <1 x i64> asm "pmulhuw $1, $0\0A\09", 
"=y,y,0,~{dirflag},~{fpsr},~{flags}"(<1 x i64> %{{.*}}, <1 x i64> %{{.*}})
   asm ("pmulhuw %1, %0\n\t" : "+y" (__A) : "y" (__B));
   return __A;
 }
@@ -51,7 +51,7 @@ __m64 test5(__m64 __A, __m64 __B) {
 int test6(void) {
   typedef unsigned char __attribute__((vector_size(8))) _m64u8;
   _m64u8 __attribute__((aligned(16))) Mu8_0, __attribute__((aligned(16))) 
Mu8_1;
-  // CHECK: call x86_mmx asm "nop", "=y,0,~{dirflag},~{fpsr},~{flags}"(x86_mmx 
%1)
+  // CHECK: call <8 x i8> asm "nop", "=y,0,~{dirflag},~{fpsr},~{flags}"(<8 x 
i8> %0)
   asm ("nop" : "=y"(Mu8_1 ) : "0"(Mu8_0 ));
   return 0;
 }
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 50cacc3038b0c..d2e7074c59077 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -58150,7 +58150,7 @@ X86TargetLowering::getSingleConstraintMatchWeight(
   Wt = CW_SpecificReg;
 break;
   case 'y':
-if (Ty->isX86_MMXTy() && Subtarget.hasMMX())
+if (Ty->getPrimitiveSizeInBits() == 64 && Subtarget.hasMMX())
   Wt = CW_SpecificReg;
 break;
   case 'Y':
@@ -58173,8 +58173,8 @@ X86TargetLowering::getSingleConstraintMatchWeight(
   return CW_Invalid;
 // Any MMX reg
 case 'm':
-  if (Ty->isX86_MMXTy() && Subtarget.hasMMX())
-return Wt;
+  if (Ty->getPrimitiveSizeInBits() == 64 && Subtarget.hasMMX())
+return CW_SpecificReg;
   return CW_Invalid;
 // Any SSE reg when ISA >= SSE2, same as 'x'
 case 'i':
diff --git a/llvm/test/CodeGen/X86/mmx-inlineasm.ll 
b/llvm/test/CodeGen/X86/mmx-inlineasm.ll
new file mode 100644
index 0..5a15600a4b312
--- /dev/null
+++ b/llvm/test/CodeGen/X86/mmx-inlineasm.ll
@@ -0,0 +1,20 @@
+; NOTE: Assertions have 

[clang] [llvm] [RISCV] Add ability to list extensions enabled for a target (PR #98207)

2024-07-09 Thread Craig Topper via cfe-commits

https://github.com/topperc edited 
https://github.com/llvm/llvm-project/pull/98207
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Add ability to list extensions enabled for a target (PR #98207)

2024-07-09 Thread Craig Topper via cfe-commits


@@ -116,6 +115,44 @@ void llvm::riscvExtensionsHelp(StringMap 
DescMap) {
 "For example, clang -march=rv32i_v1p0\n";
 }
 
+void RISCVISAInfo::printEnabledExtensions(
+bool IsRV64, std::set ,
+StringMap ) {
+  outs() << "Extensions enabled for the given RISC-V target\n\n";
+  PrintExtension("Name", "Version", (DescMap.empty() ? "" : "Description"));
+
+  RISCVISAUtils::OrderedExtensionMap FullExtMap;
+  RISCVISAUtils::OrderedExtensionMap ExtMap;
+  for (const auto  : SupportedExtensions)
+if (EnabledFeatureNames.count(E.Name) != 0) {
+  FullExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+  ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+}
+  for (const auto  : ExtMap) {
+std::string Version =
+std::to_string(E.second.Major) + "." + std::to_string(E.second.Minor);
+PrintExtension(E.first, Version, DescMap[E.first]);
+  }

topperc wrote:

It's sorted but not in the same order as OrderedExtensionMap.

https://github.com/llvm/llvm-project/pull/98207
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Add ability to list extensions enabled for a target (PR #98207)

2024-07-09 Thread Yingwei Zheng via cfe-commits


@@ -116,6 +115,44 @@ void llvm::riscvExtensionsHelp(StringMap 
DescMap) {
 "For example, clang -march=rv32i_v1p0\n";
 }
 
+void RISCVISAInfo::printEnabledExtensions(
+bool IsRV64, std::set ,
+StringMap ) {
+  outs() << "Extensions enabled for the given RISC-V target\n\n";
+  PrintExtension("Name", "Version", (DescMap.empty() ? "" : "Description"));
+
+  RISCVISAUtils::OrderedExtensionMap FullExtMap;
+  RISCVISAUtils::OrderedExtensionMap ExtMap;
+  for (const auto  : SupportedExtensions)
+if (EnabledFeatureNames.count(E.Name) != 0) {
+  FullExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+  ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+}
+  for (const auto  : ExtMap) {
+std::string Version =
+std::to_string(E.second.Major) + "." + std::to_string(E.second.Minor);
+PrintExtension(E.first, Version, DescMap[E.first]);
+  }

dtcxzyw wrote:

```suggestion
  RISCVISAUtils::OrderedExtensionMap FullExtMap;
  for (const auto  : SupportedExtensions)
if (EnabledFeatureNames.count(E.Name) != 0) {
  FullExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
   std::string Version =
std::to_string(E.Version.Major) + "." + std::to_string(E.Version.Minor);
PrintExtension(E.Name, Version, DescMap[E.Name]);
}
```
`SupportedExtensions` is sorted.
 

https://github.com/llvm/llvm-project/pull/98207
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [Clang] Implement resolution for CWG1835 (PR #92957)

2024-07-09 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

Reverted, thank you.

https://github.com/llvm/llvm-project/pull/92957
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 869ac40 - [Clang][Sema] Substitute for the type aliases inside of a CTAD guide (#94740)

2024-07-09 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-07-10T12:51:27+08:00
New Revision: 869ac4064861b7e644ae52a72fb80efacfd86462

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

LOG: [Clang][Sema] Substitute for the type aliases inside of a CTAD guide 
(#94740)

Similar to the approach of handling nested class templates when building
a CTAD guide, we substitute the template parameters of a type alias
declaration with the instantiating template arguments in order to ensure
the guide eventually doesn't reference any outer template parameters.

For example,
```cpp
template  struct Outer {
  using Alias = S;
  template  struct Inner {
Inner(Alias);
  };
};
```
we used to retain the reference to T accidentally because the
TreeTransform does nothing on type alias Decls by default.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Template.h
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/nested-deduction-guides.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2a2bff082ea7f..cd3a4c2b1be1a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1000,6 +1000,7 @@ Bug Fixes to C++ Support
   evaluated to an integer. (#GH96670).
 - Fixed a bug where references to lambda capture inside a ``noexcept`` 
specifier were not correctly
   instantiated. (#GH95735).
+- Fixed a CTAD substitution bug involving type aliases that reference outer 
template parameters. (#GH94614).
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index ce44aca797b0f..0340c23fd170d 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -711,6 +711,7 @@ enum class TemplateSubstitutionKind : char {
 VarTemplateSpecializationDecl *PrevDecl = nullptr);
 
 Decl *InstantiateTypedefNameDecl(TypedefNameDecl *D, bool IsTypeAlias);
+Decl *InstantiateTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
 ClassTemplatePartialSpecializationDecl *
 InstantiateClassTemplatePartialSpecialization(
   ClassTemplateDecl *ClassTemplate,

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 07b3f793b3a29..726de9172e1cf 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2178,23 +2178,110 @@ namespace {
 class ExtractTypeForDeductionGuide
   : public TreeTransform {
   llvm::SmallVectorImpl 
+  ClassTemplateDecl *NestedPattern;
+  const MultiLevelTemplateArgumentList *OuterInstantiationArgs;
+  std::optional TypedefNameInstantiator;
 
 public:
   typedef TreeTransform Base;
   ExtractTypeForDeductionGuide(
   Sema ,
-  llvm::SmallVectorImpl )
-  : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs) {}
+  llvm::SmallVectorImpl ,
+  ClassTemplateDecl *NestedPattern,
+  const MultiLevelTemplateArgumentList *OuterInstantiationArgs)
+  : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs),
+NestedPattern(NestedPattern),
+OuterInstantiationArgs(OuterInstantiationArgs) {
+if (OuterInstantiationArgs)
+  TypedefNameInstantiator.emplace(
+  SemaRef, SemaRef.getASTContext().getTranslationUnitDecl(),
+  *OuterInstantiationArgs);
+  }
 
   TypeSourceInfo *transform(TypeSourceInfo *TSI) { return TransformType(TSI); }
 
+  /// Returns true if it's safe to substitute \p Typedef with
+  /// \p OuterInstantiationArgs.
+  bool mightReferToOuterTemplateParameters(TypedefNameDecl *Typedef) {
+if (!NestedPattern)
+  return false;
+
+static auto WalkUp = [](DeclContext *DC, DeclContext *TargetDC) {
+  if (DC->Equals(TargetDC))
+return true;
+  while (DC->isRecord()) {
+if (DC->Equals(TargetDC))
+  return true;
+DC = DC->getParent();
+  }
+  return false;
+};
+
+if (WalkUp(Typedef->getDeclContext(), NestedPattern->getTemplatedDecl()))
+  return true;
+if (WalkUp(NestedPattern->getTemplatedDecl(), Typedef->getDeclContext()))
+  return true;
+return false;
+  }
+
+  QualType
+  RebuildTemplateSpecializationType(TemplateName Template,
+SourceLocation TemplateNameLoc,
+TemplateArgumentListInfo ) {
+if (!OuterInstantiationArgs ||
+!isa_and_present(Template.getAsTemplateDecl()))
+  return Base::RebuildTemplateSpecializationType(Template, TemplateNameLoc,
+ TemplateArgs);
+
+auto *TATD = 

[clang] [Clang] Substitute for the type aliases inside of a CTAD guide (PR #94740)

2024-07-09 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 closed 
https://github.com/llvm/llvm-project/pull/94740
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Substitute for the type aliases inside of a CTAD guide (PR #94740)

2024-07-09 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Thanks for the review.

https://github.com/llvm/llvm-project/pull/94740
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Substitute for the type aliases inside of a CTAD guide (PR #94740)

2024-07-09 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/94740

>From 2f60e51f2017e4448047f64983b2f22cdb67e816 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 7 Jun 2024 18:08:10 +0800
Subject: [PATCH 1/6] [Clang] Substitute for the type aliases inside of a CTAD
 guide

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/SemaTemplate.cpp   | 96 +--
 .../SemaTemplate/nested-deduction-guides.cpp  | 70 ++
 3 files changed, 160 insertions(+), 7 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c700d23257bf..3f6d040b0ddf1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -823,6 +823,7 @@ Bug Fixes to C++ Support
   differering by their constraints when only one of these function was 
variadic.
 - Fix a crash when a variable is captured by a block nested inside a lambda. 
(Fixes #GH93625).
 - Fixed a type constraint substitution issue involving a generic lambda 
expression. (#GH93821)
+- Fixed a CTAD substitution bug involving type aliases that reference outer 
template parameters. (#GH94614).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 40a759ea330de..1e921dd26bd7d 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2220,23 +2220,101 @@ namespace {
 class ExtractTypeForDeductionGuide
   : public TreeTransform {
   llvm::SmallVectorImpl 
+  ClassTemplateDecl *NestedPattern;
+  const MultiLevelTemplateArgumentList *OuterInstantiationArgs;
 
 public:
   typedef TreeTransform Base;
   ExtractTypeForDeductionGuide(
   Sema ,
-  llvm::SmallVectorImpl )
-  : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs) {}
+  llvm::SmallVectorImpl ,
+  ClassTemplateDecl *NestedPattern,
+  const MultiLevelTemplateArgumentList *OuterInstantiationArgs)
+  : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs),
+NestedPattern(NestedPattern),
+OuterInstantiationArgs(OuterInstantiationArgs) {}
 
   TypeSourceInfo *transform(TypeSourceInfo *TSI) { return TransformType(TSI); }
 
+  bool mightReferToOuterTemplateParameters(TypedefNameDecl *Typedef) {
+if (!NestedPattern)
+  return false;
+
+static auto WalkUp = [](DeclContext *DC, DeclContext *TargetDC) {
+  if (DC == TargetDC)
+return true;
+  while (!DC->isTranslationUnit()) {
+if (DC->Equals(TargetDC))
+  return true;
+DC = DC->getParent();
+  }
+  return false;
+};
+
+if (WalkUp(Typedef->getDeclContext(), NestedPattern->getTemplatedDecl()))
+  return true;
+if (WalkUp(NestedPattern->getTemplatedDecl(), Typedef->getDeclContext()))
+  return true;
+return false;
+  }
+
+  QualType
+  RebuildTemplateSpecializationType(TemplateName Template,
+SourceLocation TemplateNameLoc,
+TemplateArgumentListInfo ) {
+if (!OuterInstantiationArgs ||
+!isa_and_present(Template.getAsTemplateDecl()))
+  return Base::RebuildTemplateSpecializationType(Template, TemplateNameLoc,
+ TemplateArgs);
+
+auto *TATD = cast(Template.getAsTemplateDecl());
+auto *Pattern = TATD;
+while (Pattern->getInstantiatedFromMemberTemplate())
+  Pattern = Pattern->getInstantiatedFromMemberTemplate();
+if (!mightReferToOuterTemplateParameters(Pattern->getTemplatedDecl()))
+  return Base::RebuildTemplateSpecializationType(Template, TemplateNameLoc,
+ TemplateArgs);
+
+Decl *NewD = SemaRef.SubstDecl(
+TATD, SemaRef.getASTContext().getTranslationUnitDecl(),
+*OuterInstantiationArgs);
+if (!NewD)
+  return QualType();
+
+auto *NewTATD = cast(NewD);
+MaterializedTypedefs.push_back(NewTATD->getTemplatedDecl());
+
+return Base::RebuildTemplateSpecializationType(
+TemplateName(NewTATD), TemplateNameLoc, TemplateArgs);
+  }
+
   QualType TransformTypedefType(TypeLocBuilder , TypedefTypeLoc TL) {
 ASTContext  = SemaRef.getASTContext();
 TypedefNameDecl *OrigDecl = TL.getTypedefNameDecl();
 TypedefNameDecl *Decl = OrigDecl;
 // Transform the underlying type of the typedef and clone the Decl only if
 // the typedef has a dependent context.
-if (OrigDecl->getDeclContext()->isDependentContext()) {
+bool InDependentContext = OrigDecl->getDeclContext()->isDependentContext();
+
+// A typedef/alias Decl within the NestedPattern may reference the outer
+// template parameters. They're substituted with corresponding 
instantiation
+// arguments here and in RebuildTemplateSpecializationType() above.
+// Otherwise, we would have a CTAD guide with "dangling" template
+// parameters.
+// For example,
+//   template 

[clang] [clang] fix sema init crash for not checking a ExprResult (PR #98102)

2024-07-09 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/98102

>From 588762c4c3a1e01f4cf2bd418a8545b79a6b5371 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Mon, 8 Jul 2024 18:16:17 -0700
Subject: [PATCH 1/2] [clang] fix sema init crash for not checking a ExprResult

---
 clang/lib/Sema/SemaInit.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 41753a1661ace..a27ed02fc73b8 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5576,6 +5576,10 @@ static void TryOrBuildParenListInitialization(
   ExprResult ER;
   ER = IS.Perform(S, SubEntity, SubKind,
   Arg ? MultiExprArg(Arg) : std::nullopt);
+
+  if (ER.isInvalid())
+return false;
+
   if (InitExpr)
 *InitExpr = ER.get();
   else

>From 3c5b72db756e603253d3aa424bea23c2e762056f Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 9 Jul 2024 19:52:34 -0700
Subject: [PATCH 2/2] Add a crash-on-valid unit test

---
 clang/test/SemaCXX/pr98102.cpp | 33 +
 1 file changed, 33 insertions(+)
 create mode 100644 clang/test/SemaCXX/pr98102.cpp

diff --git a/clang/test/SemaCXX/pr98102.cpp b/clang/test/SemaCXX/pr98102.cpp
new file mode 100644
index 0..9281279c1848c
--- /dev/null
+++ b/clang/test/SemaCXX/pr98102.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+template 
+struct BC {
+  static constexpr bool value = v;
+};
+
+template 
+struct Constructible : BC<__is_constructible(T, Arg)> {};
+
+template 
+using Requires = T::value;
+
+template 
+struct optional {
+  template > = true>
+  optional(U) {}
+};
+
+struct MO {};
+struct S : MO {};
+struct TB {
+  TB(optional) {}
+};
+
+class TD : TB, MO {
+  using TB::TB;
+};
+
+void foo() {
+  static_assert(Constructible::value);
+}

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


[clang] [clang] fix sema init crash for not checking a ExprResult (PR #98102)

2024-07-09 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/98102

>From 588762c4c3a1e01f4cf2bd418a8545b79a6b5371 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Mon, 8 Jul 2024 18:16:17 -0700
Subject: [PATCH 1/2] [clang] fix sema init crash for not checking a ExprResult

---
 clang/lib/Sema/SemaInit.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 41753a1661ace..a27ed02fc73b8 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5576,6 +5576,10 @@ static void TryOrBuildParenListInitialization(
   ExprResult ER;
   ER = IS.Perform(S, SubEntity, SubKind,
   Arg ? MultiExprArg(Arg) : std::nullopt);
+
+  if (ER.isInvalid())
+return false;
+
   if (InitExpr)
 *InitExpr = ER.get();
   else

>From f12bfc7bea827fd3962b0dee20601fa216639ceb Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 9 Jul 2024 19:52:34 -0700
Subject: [PATCH 2/2] Add a crash-on-valid unit test

---
 clang/test/SemaCXX/pr98102.cpp | 33 +
 1 file changed, 33 insertions(+)
 create mode 100644 clang/test/SemaCXX/pr98102.cpp

diff --git a/clang/test/SemaCXX/pr98102.cpp b/clang/test/SemaCXX/pr98102.cpp
new file mode 100644
index 0..1497ac85306fd
--- /dev/null
+++ b/clang/test/SemaCXX/pr98102.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+template 
+struct BC {
+  static constexpr bool value = v;
+};
+
+template 
+struct Constructible : BC<__is_constructible(_Tp, _Args)> {};
+
+template 
+using Requires = T::value;
+
+template 
+struct optional {
+  template > = true>
+  optional(U) {}
+};
+
+struct MO {};
+struct S : MO {};
+struct TB {
+  TB(optional) {}
+};
+
+class TD : public TB, MO {
+  using TB::TB;
+};
+
+void foo() {
+  static_assert(Constructible::value);
+}

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


[clang] [RFC] [clang][Toolchain] Treat "pc"/"unknown" vendor interchangeable (PR #97802)

2024-07-09 Thread Azat Khuzhin via cfe-commits

azat wrote:

>If you specify the wrong --target= (avoid -target , deprecated since Clang 
>3.4), clangDriver will not find the compiler-rt library.
>This works as intended.

But isn't this odd, that you depends on `LLVM_DEFAULT_TARGET_TRIPLE`?

https://github.com/llvm/llvm-project/pull/97802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [TBAA] Emit int TBAA metadata on FP math libcall expf (PR #96025)

2024-07-09 Thread via cfe-commits


@@ -0,0 +1,43 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// The test may fail as time out on windows
+// REQUIRES: system-linux
+
+// RUN:  %clang -S -O3 -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefixes=CHECK,NoNewStructPathTBAA
+// RUN:  %clang -S -O3 -Xclang -new-struct-path-tbaa -emit-llvm -o - -x c++ %s 
| FileCheck %s -check-prefixes=CHECK,NewStructPathTBAA
+

vfdff wrote:

Thanks, apply your idea. But the test is still fail with timeout on the windows 
target.

https://github.com/llvm/llvm-project/pull/96025
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 62a7562 - [docs] [C++20] [Modules] Add a workaround document for missing vtables

2024-07-09 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-07-10T11:23:14+08:00
New Revision: 62a7562b828ee9df6a41b6ce3dfda7c5511816a6

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

LOG: [docs] [C++20] [Modules] Add a workaround document for missing vtables

Due to https://github.com/llvm/llvm-project/pull/75912 is reverted and
https://github.com/llvm/llvm-project/issues/70585 is reopened. It looks
riskful to fix the issue correctly before 19. So we provide a workaround
here to help people in this trouble as much as possible.

Added: 


Modified: 
clang/docs/StandardCPlusPlusModules.rst

Removed: 




diff  --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 1c3c4d319c0e1..cf0528e75e7f2 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -1092,6 +1092,74 @@ A high-level overview of support for standards features, 
including modules, can
 be found on the `C++ Feature Status `_
 page.
 
+Missing VTables for classes attached to modules
+~~~
+
+Now the compiler may miss emitting the definition of vtables
+for classes attached to modules, if the definition of the class
+doesn't contain any key function in that module units
+(The key function is the first non-pure virtual function that is
+not inline at the point of class definition.)
+
+(Note: technically, the key function is not a thing for modules.
+We use the concept here for convinient.)
+
+For example,
+
+.. code-block:: c++
+
+  // layer1.cppm
+  export module foo:layer1;
+  struct Fruit {
+  virtual ~Fruit() = default;
+  virtual void eval() = 0;
+  };
+  struct Banana : public Fruit {
+  Banana() {}
+  void eval() override;
+  };
+
+  // layer2.cppm
+  export module foo:layer2;
+  import :layer1;
+  export void layer2_fun() {
+  Banana *b = new Banana();
+  b->eval();
+  }
+  void Banana::eval() {
+  }
+
+For the above example, we can't find the definition for the vtable of
+class ``Banana`` in any object files.
+
+The expected behavior is, for dynamic classes attached to named modules,
+the vtable should always be emitted to the module units the class attaches
+to.
+
+To workaround the problem, users can add the key function manually in the
+corresponding module units. e.g.,
+
+.. code-block:: c++
+
+  // layer1.cppm
+  export module foo:layer1;
+  struct Fruit {
+  virtual ~Fruit() = default;
+  virtual void eval() = 0;
+  };
+  struct Banana : public Fruit {
+  // Hack a key function to hint the compiler to emit the virtual table.
+  virtual void anchor();
+
+  Banana() {}
+  void eval() override;
+  };
+
+  void Banana::anchor() {}
+
+This is tracked by
+`#70585 `_.
+
 Including headers after import is not well-supported
 
 



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


[clang] [clang] fix sema init crash for not checking a ExprResult (PR #98102)

2024-07-09 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/98102

>From 588762c4c3a1e01f4cf2bd418a8545b79a6b5371 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Mon, 8 Jul 2024 18:16:17 -0700
Subject: [PATCH 1/2] [clang] fix sema init crash for not checking a ExprResult

---
 clang/lib/Sema/SemaInit.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 41753a1661ace..a27ed02fc73b8 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5576,6 +5576,10 @@ static void TryOrBuildParenListInitialization(
   ExprResult ER;
   ER = IS.Perform(S, SubEntity, SubKind,
   Arg ? MultiExprArg(Arg) : std::nullopt);
+
+  if (ER.isInvalid())
+return false;
+
   if (InitExpr)
 *InitExpr = ER.get();
   else

>From 1f9905b3d593e18caab81920f86a3588f1a97644 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 9 Jul 2024 19:52:34 -0700
Subject: [PATCH 2/2] Add a crash-on-valid unit test

---
 clang/test/SemaCXX/pr98102.cpp | 38 ++
 1 file changed, 38 insertions(+)
 create mode 100644 clang/test/SemaCXX/pr98102.cpp

diff --git a/clang/test/SemaCXX/pr98102.cpp b/clang/test/SemaCXX/pr98102.cpp
new file mode 100644
index 0..504bfc802d4cf
--- /dev/null
+++ b/clang/test/SemaCXX/pr98102.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+template 
+struct BC {
+  static constexpr bool value = v;
+};
+
+template 
+struct A : B {
+  static constexpr bool value = B::value;
+};
+
+template 
+using _Requires = A::value;
+
+template 
+struct __is_constructible_impl : BC<__is_constructible(_Tp, _Args)> {};
+
+template 
+struct optional {
+  template > = true>
+  optional(_Up) {}
+};
+
+struct MO {};
+struct S : MO {};
+struct TB {
+  TB(optional) {}
+};
+
+class TD : public TB, MO {
+  using TB::TB;
+};
+
+void foo() {
+  static_assert(__is_constructible_impl::value);
+}

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


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-07-09 Thread Chris Apple via cfe-commits

cjappl wrote:

> This also breaks building the compiler-rt for older android versions, because 
> pthread_spinlock_t is only defined when `__ANDROID_API__` >= 24.

Thanks for reporting this @glandium ! I am in the process of disabling this for 
android as we speak. Let me know if you see anything else fishy

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-07-09 Thread Mike Hommey via cfe-commits

glandium wrote:

This also breaks building the compiler-rt for older android versions, because 
pthread_spinlock_t is only defined when __ANDROID_API__ >= 24.

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AIX] Add -msave-reg-params to save arguments to stack (PR #97524)

2024-07-09 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises updated 
https://github.com/llvm/llvm-project/pull/97524

>From 654cf7753023302c367340872e889856f8738169 Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Wed, 3 Jul 2024 14:17:01 +0800
Subject: [PATCH 1/3] [AIX] Add -msave-reg-params to save arguments to stack

In PowerPC ABI, a few initial arguments are passed through registers,
but their places in parameter save area are reserved, arguments passed
by memory goes after the reserved location.

For debugging purpose, we may want to save copy of the pass-by-reg
arguments into correct places on stack. The new option achieves by
adding new function level attribute and make argument lowering part
aware of it.
---
 clang/include/clang/Basic/CodeGenOptions.def  |   3 +
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/CodeGen/CGCall.cpp  |   3 +
 clang/lib/Driver/ToolChains/AIX.cpp   |   3 +
 clang/test/CodeGen/PowerPC/save-reg-params.c  |  12 +
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp |  20 +-
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  29 +
 .../Target/PowerPC/PPCMachineFunctionInfo.h   |   6 +
 llvm/test/CodeGen/PowerPC/save-reg-params.ll  | 816 ++
 9 files changed, 888 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/save-reg-params.c
 create mode 100644 llvm/test/CodeGen/PowerPC/save-reg-params.ll

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index e3f6da4a84f69..fcf15aa9c400a 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -425,6 +425,9 @@ CODEGENOPT(ForceAAPCSBitfieldLoad, 1, 0)
 /// Assume that by-value parameters do not alias any other values.
 CODEGENOPT(PassByValueIsNoAlias, 1, 0)
 
+/// Whether to store register parameters to stack.
+CODEGENOPT(SaveRegParams, 1, 0)
+
 /// Whether to not follow the AAPCS that enforces volatile bit-field access 
width to be
 /// according to the field declaring type width.
 CODEGENOPT(AAPCSBitfieldWidth, 1, 1)
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1c2b8cfeef6ce..4135f0db60450 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5040,6 +5040,10 @@ def mspe : Flag<["-"], "mspe">, 
Group;
 def mno_spe : Flag<["-"], "mno-spe">, Group;
 def mefpu2 : Flag<["-"], "mefpu2">, Group;
 } // let Flags = [TargetSpecific]
+def msave_reg_params : Flag<["-"], "msave-reg-params">, Group,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Save arguments passed by registers to stack">,
+  MarshallingInfoFlag>;
 def mabi_EQ_quadword_atomics : Flag<["-"], "mabi=quadword-atomics">,
   Group, Visibility<[ClangOption, CC1Option]>,
   HelpText<"Enable quadword atomics ABI on AIX (AIX PPC64 only). Uses 
lqarx/stqcx. instructions.">,
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 2b301130ef7b7..8269755cdbf89 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1931,6 +1931,9 @@ static void getTrivialDefaultFunctionAttributes(
 if (CodeGenOpts.NullPointerIsValid)
   FuncAttrs.addAttribute(llvm::Attribute::NullPointerIsValid);
 
+if (CodeGenOpts.SaveRegParams)
+  FuncAttrs.addAttribute("save-reg-params");
+
 if (LangOpts.getDefaultExceptionMode() == LangOptions::FPE_Ignore)
   FuncAttrs.addAttribute("no-trapping-math", "true");
 
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index b04502a57a9f7..c2de7328c25c5 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -548,6 +548,9 @@ void AIX::addClangTargetOptions(
   options::OPT_mtocdata))
 addTocDataOptions(Args, CC1Args, getDriver());
 
+  if (Args.hasArg(options::OPT_msave_reg_params))
+CC1Args.push_back("-msave-reg-params");
+
   if (Args.hasFlag(options::OPT_fxl_pragma_pack,
options::OPT_fno_xl_pragma_pack, true))
 CC1Args.push_back("-fxl-pragma-pack");
diff --git a/clang/test/CodeGen/PowerPC/save-reg-params.c 
b/clang/test/CodeGen/PowerPC/save-reg-params.c
new file mode 100644
index 0..6599310afa41a
--- /dev/null
+++ b/clang/test/CodeGen/PowerPC/save-reg-params.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s 
-msave-reg-params | FileCheck -check-prefix=SAVE %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -o - %s 
-msave-reg-params | FileCheck -check-prefix=SAVE %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix -emit-llvm -o - %s 
-msave-reg-params | FileCheck -check-prefix=SAVE %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck -check-prefix=NOSAVE %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -emit-llvm -o - %s | FileCheck 
-check-prefix=NOSAVE %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix -emit-llvm -o - %s | 

[clang] [clang] fix sema init crash for not checking a ExprResult (PR #98102)

2024-07-09 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/98102

>From 588762c4c3a1e01f4cf2bd418a8545b79a6b5371 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Mon, 8 Jul 2024 18:16:17 -0700
Subject: [PATCH 1/2] [clang] fix sema init crash for not checking a ExprResult

---
 clang/lib/Sema/SemaInit.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 41753a1661ace..a27ed02fc73b8 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5576,6 +5576,10 @@ static void TryOrBuildParenListInitialization(
   ExprResult ER;
   ER = IS.Perform(S, SubEntity, SubKind,
   Arg ? MultiExprArg(Arg) : std::nullopt);
+
+  if (ER.isInvalid())
+return false;
+
   if (InitExpr)
 *InitExpr = ER.get();
   else

>From c97ad74e326fa2ec72845d45c9670b74d3efab71 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 9 Jul 2024 19:52:34 -0700
Subject: [PATCH 2/2] Add a crash-on-valid unit test

---
 clang/test/SemaCXX/pr98102.cpp | 38 ++
 1 file changed, 38 insertions(+)
 create mode 100644 clang/test/SemaCXX/pr98102.cpp

diff --git a/clang/test/SemaCXX/pr98102.cpp b/clang/test/SemaCXX/pr98102.cpp
new file mode 100644
index 0..a7c36e492729c
--- /dev/null
+++ b/clang/test/SemaCXX/pr98102.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+template 
+struct BC {
+  static constexpr bool value = v;
+};
+
+template  
+struct A : B {
+  static constexpr bool value = true;
+};
+
+template 
+using _Requires = A::value;
+
+template 
+struct __is_constructible_impl : BC<__is_constructible(_Tp, _Args)> {};
+
+template 
+struct optional {
+  template > = true>
+  optional(_Up) {}
+};
+
+struct MO {};
+struct S : MO {};
+struct TB {
+  TB(optional) {}
+};
+
+class TD : public TB, MO {
+  using TB::TB;
+};
+
+void foo() {
+  static_assert(__is_constructible_impl::value);
+}

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


[clang] [clang] fix sema init crash for not checking a ExprResult (PR #98102)

2024-07-09 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/98102

>From 01a5dd6e5bfc612678818035b88f85fda5c039d1 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Mon, 8 Jul 2024 18:16:17 -0700
Subject: [PATCH 1/2] [clang] fix sema init crash for not checking a ExprResult

---
 clang/lib/Sema/SemaInit.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 41753a1661ace..a27ed02fc73b8 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5576,6 +5576,10 @@ static void TryOrBuildParenListInitialization(
   ExprResult ER;
   ER = IS.Perform(S, SubEntity, SubKind,
   Arg ? MultiExprArg(Arg) : std::nullopt);
+
+  if (ER.isInvalid())
+return false;
+
   if (InitExpr)
 *InitExpr = ER.get();
   else

>From eeefe4cdbc87d127005ccb3fdd50ce7ec539f5cd Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 9 Jul 2024 19:52:34 -0700
Subject: [PATCH 2/2] Add a crash-on-valid unit test

---
 clang/test/SemaCXX/pr98102.cpp | 38 ++
 1 file changed, 38 insertions(+)
 create mode 100644 clang/test/SemaCXX/pr98102.cpp

diff --git a/clang/test/SemaCXX/pr98102.cpp b/clang/test/SemaCXX/pr98102.cpp
new file mode 100644
index 0..a7c36e492729c
--- /dev/null
+++ b/clang/test/SemaCXX/pr98102.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+template 
+struct BC {
+  static constexpr bool value = v;
+};
+
+template  
+struct A : B {
+  static constexpr bool value = true;
+};
+
+template 
+using _Requires = A::value;
+
+template 
+struct __is_constructible_impl : BC<__is_constructible(_Tp, _Args)> {};
+
+template 
+struct optional {
+  template > = true>
+  optional(_Up) {}
+};
+
+struct MO {};
+struct S : MO {};
+struct TB {
+  TB(optional) {}
+};
+
+class TD : public TB, MO {
+  using TB::TB;
+};
+
+void foo() {
+  static_assert(__is_constructible_impl::value);
+}

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


[clang] 91d40ef - Revert "[C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (#75912)"

2024-07-09 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-07-10T10:58:18+08:00
New Revision: 91d40ef6e369a73b0147d9153a95c3bc63e14102

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

LOG: Revert "[C++20] [Modules] [Itanium ABI] Generate the vtable in the module 
unit of dynamic classes (#75912)"

This reverts commit 18f3bcbb13ca83d33223b00761d8cddf463e9ffb, 
15bb02650e26875c48889053d6a9697444583721 and
99873b35da7ecb905143c8a6b8deca4d4416f1a9.

See the post commit message in
https://github.com/llvm/llvm-project/pull/75912 to see the reasons.

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ASTWriter.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/CodeGen/CGVTables.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/CodeGenCXX/modules-vtable.cppm

Removed: 
clang/test/CodeGenCXX/pr70585.cppm
clang/test/Modules/pr97313.cppm



diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 45dac82e54077..06ffc2ce09b89 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -670,16 +670,6 @@ class alignas(8) Decl {
   /// Whether this declaration comes from another module unit.
   bool isInAnotherModuleUnit() const;
 
-  /// Whether this declaration comes from the same module unit being compiled.
-  bool isInCurrentModuleUnit() const;
-
-  /// Whether the definition of the declaration should be emitted in external
-  /// sources.
-  bool shouldEmitInExternalSource() const;
-
-  /// Whether this declaration comes from a named module;
-  bool isInNamedModule() const;
-
   /// Whether this declaration comes from explicit global module.
   bool isFromExplicitGlobalModule() const;
 

diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 38502a23f805e..488994c05dc12 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -721,9 +721,6 @@ enum ASTRecordTypes {
 
   /// Record code for \#pragma clang unsafe_buffer_usage begin/end
   PP_UNSAFE_BUFFER_USAGE = 69,
-
-  /// Record code for vtables to emit.
-  VTABLES_TO_EMIT = 70,
 };
 
 /// Record types used within a source manager block.

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index f41c473c97cd9..76e51ac7ab979 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -790,11 +790,6 @@ class ASTReader
   /// the consumer eagerly.
   SmallVector EagerlyDeserializedDecls;
 
-  /// The IDs of all vtables to emit. The referenced declarations are passed
-  /// to the consumers's HandleVTable eagerly after passing
-  /// EagerlyDeserializedDecls.
-  SmallVector VTablesToEmit;
-
   /// The IDs of all tentative definitions stored in the chain.
   ///
   /// Sema keeps track of all tentative definitions in a TU because it has to
@@ -1505,7 +1500,6 @@ class ASTReader
   bool isConsumerInterestedIn(Decl *D);
   void PassInterestingDeclsToConsumer();
   void PassInterestingDeclToConsumer(Decl *D);
-  void PassVTableToConsumer(CXXRecordDecl *RD);
 
   void finishPendingActions();
   void diagnoseOdrViolations();

diff  --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index 71a7c28047e31..a0e475ec9f862 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -500,10 +500,6 @@ class ASTWriter : public ASTDeserializationListener,
   std::vector NonAffectingRanges;
   std::vector NonAffectingOffsetAdjustments;
 
-  /// A list of classes which need to emit the VTable in the corresponding
-  /// object file.
-  llvm::SmallVector PendingEmittingVTables;
-
   /// Computes input files that didn't affect compilation of the current 
module,
   /// and initializes data structures necessary for leaving those files out
   /// during \c SourceManager serialization.
@@ -861,8 +857,6 @@ class ASTWriter : public ASTDeserializationListener,
 return PredefinedDecls.count(D);
   }
 
-  void handleVTable(CXXRecordDecl *RD);
-
 private:
   // ASTDeserializationListener implementation
   void ReaderInitialized(ASTReader *Reader) override;
@@ -957,7 +951,6 @@ class PCHGenerator : public SemaConsumer {
 
   void 

[clang] [TBAA] Emit int TBAA metadata on FP math libcall expf (PR #96025)

2024-07-09 Thread via cfe-commits

https://github.com/vfdff updated https://github.com/llvm/llvm-project/pull/96025

>From ed6292fd0e9119322c39e5f37e2225c76e324101 Mon Sep 17 00:00:00 2001
From: zhongyunde 00443407 
Date: Tue, 18 Jun 2024 09:21:07 -0400
Subject: [PATCH 1/8] [TBAA] Emit int TBAA metadata on FP math libcalls

Base on the discussion 
https://discourse.llvm.org/t/fp-can-we-add-pure-attribute-for-math-library-functions-default/79459,
math libcalls set errno, so it should emit "int" TBAA metadata on FP libcalls
to solve the alias issue.

Fix https://github.com/llvm/llvm-project/issues/86635
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 33 ++-
 clang/test/CodeGen/math-libcalls-tbaa.cpp | 22 +++
 2 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/math-libcalls-tbaa.cpp

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 08a89bd123d03..dc4af109cdbdb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -707,7 +707,38 @@ static RValue emitLibraryCall(CodeGenFunction , const 
FunctionDecl *FD,
   const CallExpr *E, llvm::Constant *calleeValue) {
   CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   CGCallee callee = CGCallee::forDirect(calleeValue, GlobalDecl(FD));
-  return CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
+  RValue Call =
+  CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
+
+  // Check the supported intrinsic.
+  if (unsigned BuiltinID = FD->getBuiltinID()) {
+auto IntrinsicID = [&]() -> unsigned {
+  switch (BuiltinID) {
+  case Builtin::BIexpf:
+  case Builtin::BI__builtin_expf:
+  case Builtin::BI__builtin_expf128:
+return true;
+  }
+  // TODO: support more FP math libcalls
+  return false;
+}();
+
+if (IntrinsicID) {
+  llvm::MDBuilder MDHelper(CGF.getLLVMContext());
+  MDNode *RootMD;
+  if (CGF.getLangOpts().CPlusPlus)
+RootMD = MDHelper.createTBAARoot("Simple C++ TBAA");
+  else
+RootMD = MDHelper.createTBAARoot("Simple C/C++ TBAA");
+  // Emit "int" TBAA metadata on FP math libcalls.
+  MDNode *AliasType = MDHelper.createTBAANode("int", RootMD);
+  MDNode *MDInt = MDHelper.createTBAAStructTagNode(AliasType, AliasType, 
0);
+
+  Value *Val = Call.getScalarVal();
+  cast(Val)->setMetadata(LLVMContext::MD_tbaa, MDInt);
+}
+  }
+  return Call;
 }
 
 /// Emit a call to llvm.{sadd,uadd,ssub,usub,smul,umul}.with.overflow.*
diff --git a/clang/test/CodeGen/math-libcalls-tbaa.cpp 
b/clang/test/CodeGen/math-libcalls-tbaa.cpp
new file mode 100644
index 0..d5b0741a476cb
--- /dev/null
+++ b/clang/test/CodeGen/math-libcalls-tbaa.cpp
@@ -0,0 +1,22 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// RUN:  %clang -S -O3 -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefixes=CHECK
+
+#include 
+
+
+// Emit int TBAA metadata on FP math libcalls, which is useful for alias 
analysis
+
+// CHECK-LABEL: define dso_local noundef float @_Z3fooPffi
+// CHECK-SAME: (ptr nocapture noundef readonly [[NUM:%.*]], float noundef 
[[R2INV:%.*]], i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[NUM]], 
i64 40
+// CHECK-NEXT:[[TMP0:%.*]] = load float, ptr [[ARRAYIDX]], align 4, !tbaa 
[[TBAA6:![0-9]+]]
+// CHECK-NEXT:[[CALL_I:%.*]] = tail call noundef float @expf(float noundef 
[[TMP0]]) #[[ATTR2:[0-9]+]], !tbaa [[TBAA10:![0-9]+]]
+// CHECK-NEXT:[[MUL:%.*]] = fmul float [[TMP0]], [[CALL_I]]
+// CHECK-NEXT:ret float [[MUL]]
+//
+float foo (float num[], float r2inv, int n) {
+   const float expm2 =  std::exp(num[10]);  // Emit TBAA metadata on @expf
+   float tmp = expm2 * num[10];
+   return tmp;
+}

>From 9990877a2b9736c684c8cabeb03c6d98a3d078ce Mon Sep 17 00:00:00 2001
From: zhongyunde 00443407 
Date: Thu, 20 Jun 2024 02:29:11 -0400
Subject: [PATCH 2/8] Address comment, reuse CodeGenTBAA::getRoot

---
 clang/lib/CodeGen/CGBuiltin.cpp   |  6 +-
 clang/lib/CodeGen/CodeGenModule.h |  2 ++
 clang/lib/CodeGen/CodeGenTBAA.h   |  8 
 clang/test/CodeGen/math-libcalls-tbaa.cpp | 20 +++-
 4 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index dc4af109cdbdb..3f448e11bca1a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -725,11 +725,7 @@ static RValue emitLibraryCall(CodeGenFunction , const 
FunctionDecl *FD,
 
 if (IntrinsicID) {
   llvm::MDBuilder MDHelper(CGF.getLLVMContext());
-  MDNode *RootMD;
-  if (CGF.getLangOpts().CPlusPlus)
-RootMD = MDHelper.createTBAARoot("Simple C++ TBAA");
-  else
-RootMD = MDHelper.createTBAARoot("Simple 

[clang] [clang] fix sema init crash for not checking a ExprResult (PR #98102)

2024-07-09 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/98102

>From 01a5dd6e5bfc612678818035b88f85fda5c039d1 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Mon, 8 Jul 2024 18:16:17 -0700
Subject: [PATCH 1/2] [clang] fix sema init crash for not checking a ExprResult

---
 clang/lib/Sema/SemaInit.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 41753a1661ace..a27ed02fc73b8 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5576,6 +5576,10 @@ static void TryOrBuildParenListInitialization(
   ExprResult ER;
   ER = IS.Perform(S, SubEntity, SubKind,
   Arg ? MultiExprArg(Arg) : std::nullopt);
+
+  if (ER.isInvalid())
+return false;
+
   if (InitExpr)
 *InitExpr = ER.get();
   else

>From 619d5e7bfba3378420e95c3d9bfd6cc253cdc810 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 9 Jul 2024 19:52:34 -0700
Subject: [PATCH 2/2] Add a crash-on-valid unit test

---
 clang/test/SemaCXX/pr98102.cpp | 45 ++
 1 file changed, 45 insertions(+)
 create mode 100644 clang/test/SemaCXX/pr98102.cpp

diff --git a/clang/test/SemaCXX/pr98102.cpp b/clang/test/SemaCXX/pr98102.cpp
new file mode 100644
index 0..175a5ba80934f
--- /dev/null
+++ b/clang/test/SemaCXX/pr98102.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+template 
+struct BC {
+  static constexpr bool value = v;
+};
+
+template  struct __and_ : B {
+  static constexpr bool value = true;
+};
+
+template 
+using _Requires = __and_::value;
+
+template 
+struct __is_constructible_impl : BC<__is_constructible(_Tp, _Args)> {};
+
+template 
+struct optional {
+  template > = true>
+optional(_Up) {}
+};
+
+struct MO {};
+struct S : MO {};
+struct TB {
+  TB(optional) {}
+};
+
+class Try : public TB, MO {
+  using TB::TB;
+};
+
+template 
+struct MQB;
+
+template <>
+struct MQB {
+static_assert(__is_constructible_impl::value);
+};
+
+void foo() {
+  MQB m;
+}

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


[clang] [Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (PR #95474)

2024-07-09 Thread Shafik Yaghmour via cfe-commits


@@ -249,13 +249,15 @@ class APValue {
   struct NoLValuePath {};
   struct UninitArray {};
   struct UninitStruct {};
+  struct ConstexprUnknown {};
 
   template  friend class clang::serialization::BasicReaderBase;
   friend class ASTImporter;
   friend class ASTNodeImporter;
 
 private:
   ValueKind Kind;
+  bool AllowConstexprUnknown = false;

shafik wrote:

Initializing a bit-field inline is a C++20 extension and so I don't think I can 
use it.

I set `AllowConstexprUnknown` everyplace I thought it mattered in `APValue` but 
I obtain different results. It means I am missing someplace where `APValue` is 
being initialized. I can try again and see if I can hunt down the places I 
missed but it left me a bit spooked that it was not obvious. 

https://github.com/llvm/llvm-project/pull/95474
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)

2024-07-09 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

Given this patch has another unexpected behavior in windows 
(https://github.com/llvm/llvm-project/issues/97447), I'd like to revert this 
temporarily to wait for the response from Windows devs and your reproducer 
@mizvekov 

https://github.com/llvm/llvm-project/pull/75912
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (PR #95474)

2024-07-09 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik deleted 
https://github.com/llvm/llvm-project/pull/95474
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (PR #95474)

2024-07-09 Thread Shafik Yaghmour via cfe-commits


@@ -249,13 +249,15 @@ class APValue {
   struct NoLValuePath {};
   struct UninitArray {};
   struct UninitStruct {};
+  struct ConstexprUnknown {};
 
   template  friend class clang::serialization::BasicReaderBase;
   friend class ASTImporter;
   friend class ASTNodeImporter;
 
 private:
   ValueKind Kind;
+  bool AllowConstexprUnknown = false;

shafik wrote:

Initializing a bit-field inline is a C++20 extension and it got messy when I 
tried to do the init manually but I can look at it again now that this is a 
much simpler set of code.

https://github.com/llvm/llvm-project/pull/95474
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [TBAA] Emit int TBAA metadata on FP math libcall expf (PR #96025)

2024-07-09 Thread via cfe-commits

https://github.com/vfdff updated https://github.com/llvm/llvm-project/pull/96025

>From ed6292fd0e9119322c39e5f37e2225c76e324101 Mon Sep 17 00:00:00 2001
From: zhongyunde 00443407 
Date: Tue, 18 Jun 2024 09:21:07 -0400
Subject: [PATCH 1/8] [TBAA] Emit int TBAA metadata on FP math libcalls

Base on the discussion 
https://discourse.llvm.org/t/fp-can-we-add-pure-attribute-for-math-library-functions-default/79459,
math libcalls set errno, so it should emit "int" TBAA metadata on FP libcalls
to solve the alias issue.

Fix https://github.com/llvm/llvm-project/issues/86635
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 33 ++-
 clang/test/CodeGen/math-libcalls-tbaa.cpp | 22 +++
 2 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/math-libcalls-tbaa.cpp

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 08a89bd123d03..dc4af109cdbdb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -707,7 +707,38 @@ static RValue emitLibraryCall(CodeGenFunction , const 
FunctionDecl *FD,
   const CallExpr *E, llvm::Constant *calleeValue) {
   CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   CGCallee callee = CGCallee::forDirect(calleeValue, GlobalDecl(FD));
-  return CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
+  RValue Call =
+  CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
+
+  // Check the supported intrinsic.
+  if (unsigned BuiltinID = FD->getBuiltinID()) {
+auto IntrinsicID = [&]() -> unsigned {
+  switch (BuiltinID) {
+  case Builtin::BIexpf:
+  case Builtin::BI__builtin_expf:
+  case Builtin::BI__builtin_expf128:
+return true;
+  }
+  // TODO: support more FP math libcalls
+  return false;
+}();
+
+if (IntrinsicID) {
+  llvm::MDBuilder MDHelper(CGF.getLLVMContext());
+  MDNode *RootMD;
+  if (CGF.getLangOpts().CPlusPlus)
+RootMD = MDHelper.createTBAARoot("Simple C++ TBAA");
+  else
+RootMD = MDHelper.createTBAARoot("Simple C/C++ TBAA");
+  // Emit "int" TBAA metadata on FP math libcalls.
+  MDNode *AliasType = MDHelper.createTBAANode("int", RootMD);
+  MDNode *MDInt = MDHelper.createTBAAStructTagNode(AliasType, AliasType, 
0);
+
+  Value *Val = Call.getScalarVal();
+  cast(Val)->setMetadata(LLVMContext::MD_tbaa, MDInt);
+}
+  }
+  return Call;
 }
 
 /// Emit a call to llvm.{sadd,uadd,ssub,usub,smul,umul}.with.overflow.*
diff --git a/clang/test/CodeGen/math-libcalls-tbaa.cpp 
b/clang/test/CodeGen/math-libcalls-tbaa.cpp
new file mode 100644
index 0..d5b0741a476cb
--- /dev/null
+++ b/clang/test/CodeGen/math-libcalls-tbaa.cpp
@@ -0,0 +1,22 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// RUN:  %clang -S -O3 -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefixes=CHECK
+
+#include 
+
+
+// Emit int TBAA metadata on FP math libcalls, which is useful for alias 
analysis
+
+// CHECK-LABEL: define dso_local noundef float @_Z3fooPffi
+// CHECK-SAME: (ptr nocapture noundef readonly [[NUM:%.*]], float noundef 
[[R2INV:%.*]], i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[NUM]], 
i64 40
+// CHECK-NEXT:[[TMP0:%.*]] = load float, ptr [[ARRAYIDX]], align 4, !tbaa 
[[TBAA6:![0-9]+]]
+// CHECK-NEXT:[[CALL_I:%.*]] = tail call noundef float @expf(float noundef 
[[TMP0]]) #[[ATTR2:[0-9]+]], !tbaa [[TBAA10:![0-9]+]]
+// CHECK-NEXT:[[MUL:%.*]] = fmul float [[TMP0]], [[CALL_I]]
+// CHECK-NEXT:ret float [[MUL]]
+//
+float foo (float num[], float r2inv, int n) {
+   const float expm2 =  std::exp(num[10]);  // Emit TBAA metadata on @expf
+   float tmp = expm2 * num[10];
+   return tmp;
+}

>From 9990877a2b9736c684c8cabeb03c6d98a3d078ce Mon Sep 17 00:00:00 2001
From: zhongyunde 00443407 
Date: Thu, 20 Jun 2024 02:29:11 -0400
Subject: [PATCH 2/8] Address comment, reuse CodeGenTBAA::getRoot

---
 clang/lib/CodeGen/CGBuiltin.cpp   |  6 +-
 clang/lib/CodeGen/CodeGenModule.h |  2 ++
 clang/lib/CodeGen/CodeGenTBAA.h   |  8 
 clang/test/CodeGen/math-libcalls-tbaa.cpp | 20 +++-
 4 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index dc4af109cdbdb..3f448e11bca1a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -725,11 +725,7 @@ static RValue emitLibraryCall(CodeGenFunction , const 
FunctionDecl *FD,
 
 if (IntrinsicID) {
   llvm::MDBuilder MDHelper(CGF.getLLVMContext());
-  MDNode *RootMD;
-  if (CGF.getLangOpts().CPlusPlus)
-RootMD = MDHelper.createTBAARoot("Simple C++ TBAA");
-  else
-RootMD = MDHelper.createTBAARoot("Simple 

[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)

2024-07-09 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> FYI, the commit 
> [99873b3](https://github.com/llvm/llvm-project/commit/99873b35da7ecb905143c8a6b8deca4d4416f1a9),
>  which lists this PR as a motivator, causes breakage building a project, 
> which I am still looking for a reduced test case.
> 
> The commit is not NFC despite what is says, just by cursory inspection of the 
> change.
> 
> Please avoid adding NFC tag to such commits in the future and create a pull 
> request.

Oh, sorry, I took another look at the commit and it looks the change makes it 
not a NFC change is this line: 
https://github.com/llvm/llvm-project/commit/99873b35da7ecb905143c8a6b8deca4d4416f1a9#diff-6fe53759e8d797c328c73ada5f3324c6248a8634ef36131c7eb2b9d89192bb64R6514

This shouldn't be in that commit but in this commit. It is not intentional. I 
guess we can't observe that if we put that in this PR too. And that change 
looks not bad. So maybe it makes something already bad to show up. 

https://github.com/llvm/llvm-project/pull/75912
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Earlier type checking for builtin unary operators (PR #90500)

2024-07-09 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

You reapplied this here: 
https://github.com/llvm/llvm-project/commit/1595988ee6f9732e7ea79928af8a470ad5ef7dbe

but it has caused a regression: 
https://github.com/llvm/llvm-project/issues/97646



https://github.com/llvm/llvm-project/pull/90500
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-09 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

They look quite independent. 
Would be possible to split independent fixed into a separate patches?

https://github.com/llvm/llvm-project/pull/98001
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)

2024-07-09 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> At the end of the recent flurry of Illumos (and implicitly Solaris) safestack 
> patches, the tests were disabled in
> [b0260c5](https://github.com/llvm/llvm-project/commit/b0260c5b1052f8e3ff1ec77dc42a11f42da762cc)
>  without explanation.

@devnexen  Thank you for #97183, which seemed to addressed a real issue, but 
make sure to include descriptions in the future.

https://github.com/llvm/llvm-project/pull/98001
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix erroneous `-Wmissing-prototypes` for Win32 entry points (PR #98105)

2024-07-09 Thread Max Winkler via cfe-commits

https://github.com/MaxEW707 closed 
https://github.com/llvm/llvm-project/pull/98105
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b0b96fb - Fix erroneous `-Wmissing-prototypes` for Win32 entry points (#98105)

2024-07-09 Thread via cfe-commits

Author: Max Winkler
Date: 2024-07-09T18:38:32-07:00
New Revision: b0b96fbff47c74940a62073c579372f3c47df9c8

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

LOG: Fix erroneous `-Wmissing-prototypes` for Win32 entry points (#98105)

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/no-warn-missing-prototype.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fac4c8e69dc15..3b105d91958cc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -686,6 +686,9 @@ Improvements to Clang's diagnostics
 
 - Clang now shows implicit deduction guides when diagnosing overload 
resolution failure. #GH92393.
 
+- Clang no longer emits a "no previous prototype" warning for Win32 entry 
points under ``-Wmissing-prototypes``.
+  Fixes #GH94366.
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index aa44608035538..97e1f7e05e44e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15222,6 +15222,9 @@ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
   if (II->isStr("main") || II->isStr("efi_main"))
 return false;
 
+  if (FD->isMSVCRTEntryPoint())
+return false;
+
   // Don't warn about inline functions.
   if (FD->isInlined())
 return false;

diff  --git a/clang/test/Sema/no-warn-missing-prototype.c 
b/clang/test/Sema/no-warn-missing-prototype.c
index 6059b6aa0f146..17d69ac8913fa 100644
--- a/clang/test/Sema/no-warn-missing-prototype.c
+++ b/clang/test/Sema/no-warn-missing-prototype.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes -x c -ffreestanding 
-verify %s
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-prototypes -x c++ -ffreestanding 
-verify %s
+// RUN: %clang_cc1 -fms-compatibility -fsyntax-only -Wmissing-prototypes -x 
c++ -ffreestanding -triple=x86_64-pc-win32 -verify -DMS %s
 // expected-no-diagnostics
 int main() {
   return 0;
@@ -8,3 +9,21 @@ int main() {
 int efi_main() {
   return 0;
 }
+
+#ifdef MS
+int wmain(int, wchar_t *[], wchar_t *[]) {
+  return 0;
+}
+
+int wWinMain(void*, void*, wchar_t*, int) {
+  return 0;
+}
+
+int WinMain(void*, void*, char*, int) {
+  return 0;
+}
+
+bool DllMain(void*, unsigned, void*) {
+  return true;
+}
+#endif



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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-07-09 Thread Paul Kirth via cfe-commits

ilovepi wrote:

any progress here?

https://github.com/llvm/llvm-project/pull/93281
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] modify basic-project test (PR #97684)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -54,306 +54,249 @@
 // JSON-INDEX-NEXT: };
 // JSON-INDEX-NEXT: }
 
-// HTML-SHAPE: 
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT: class Shape
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: class Shape
-// HTML-SHAPE-NEXT: Defined at line 8 of file {{.*}}Shape.h
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT:  Provides a common interface for different 
types of shapes.
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT: Functions
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   ~Shape
-// HTML-SHAPE-NEXT:   public void ~Shape()
-// HTML-SHAPE-NEXT:   Defined at line 13 of file {{.*}}Shape.h
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT:   area
-// HTML-SHAPE-NEXT:   public double area()
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT:   perimeter
-// HTML-SHAPE-NEXT:   public double perimeter()
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   Functions
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   ~Shape
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   area
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   perimeter
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
-// HTML-SHAPE-NEXT:   
-// HTML-SHAPE-NEXT: 
+// HTML-SHAPE: class Shape
+// HTML-SHAPE: Defined at line 8 of file {{.*}}Shape.h
+// HTML-SHAPE: 
+// HTML-SHAPE:   

ilovepi wrote:

Do you need to match these? are they important? same w/ all the lines that only 
have tags...

https://github.com/llvm/llvm-project/pull/97684
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] modify basic-project test (PR #97684)

2024-07-09 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi edited 
https://github.com/llvm/llvm-project/pull/97684
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] modify basic-project test (PR #97684)

2024-07-09 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi commented:

This is headed in the right direction, but I'm not sure we want to match so 
many of the single line tags ... they don't seem particularly valuable from a 
testing standpoint. If you think we're missing tests for the HTML structure, 
then we should have some tests that focus on just that aspect that can be a bit 
simpler in nature than a full project.

Ultimately, I'd like to see a subset of tests that veryify that we do the 
documentation correctly, and a set of tests that exercise the format enough to 
be sure we're emiting well structured markdown/yaml/html.

https://github.com/llvm/llvm-project/pull/97684
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Driver] Fix Linux/sparc64 -m32 (PR #98124)

2024-07-09 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/98124
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add nested namespace test case (PR #97681)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,340 @@
+// RUN: clang-doc --format=html --output=%t/docs --executor=standalone %s
+// RUN: clang-doc --format=md --output=%t/docs --executor=standalone %s

ilovepi wrote:

Why no `mkdir`? I presume because clang-doc will make it, but the test 
shouldn't rely on that behavior. Plus we want to be sure each run is isolated, 
so starting w/ `rm -rf %t && mkdir %t` is a good practice if you need a 
directory. also, probably don't need `docs`...

https://github.com/llvm/llvm-project/pull/97681
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add nested namespace test case (PR #97681)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,340 @@
+// RUN: clang-doc --format=html --output=%t/docs --executor=standalone %s
+// RUN: clang-doc --format=md --output=%t/docs --executor=standalone %s
+// RUN: FileCheck %s -input-file=%t/docs/index_json.js -check-prefix=JSON-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/@nonymous_namespace/AnonClass.html 
-check-prefix=HTML-ANON-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/@nonymous_namespace/index.html 
-check-prefix=HTML-ANON-INDEX
+// RUN: FileCheck %s 
-input-file=%t/docs/AnotherNamespace/ClassInAnotherNamespace.html 
-check-prefix=HTML-ANOTHER-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/AnotherNamespace/index.html 
-check-prefix=HTML-ANOTHER-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/index.html 
-check-prefix=HTML-GLOBAL-INDEX
+// RUN: FileCheck %s 
-input-file=%t/docs/PrimaryNamespace/NestedNamespace/ClassInNestedNamespace.html
 -check-prefix=HTML-NESTED-CLASS
+// RUN: FileCheck %s 
-input-file=%t/docs/PrimaryNamespace/NestedNamespace/index.html 
-check-prefix=HTML-NESTED-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/PrimaryNamespace/index.html 
-check-prefix=HTML-PRIMARY-INDEX
+// RUN: FileCheck %s 
-input-file=%t/docs/PrimaryNamespace/ClassInPrimaryNamespace.html 
-check-prefix=HTML-PRIMARY-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/@nonymous_namespace/AnonClass.md 
-check-prefix=MD-ANON-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/@nonymous_namespace/index.md 
-check-prefix=MD-ANON-INDEX
+// RUN: FileCheck %s 
-input-file=%t/docs/AnotherNamespace/ClassInAnotherNamespace.md 
-check-prefix=MD-ANOTHER-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/AnotherNamespace/index.md 
-check-prefix=MD-ANOTHER-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/index.md 
-check-prefix=MD-GLOBAL-INDEX
+// RUN: FileCheck %s 
-input-file=%t/docs/PrimaryNamespace/NestedNamespace/ClassInNestedNamespace.md 
-check-prefix=MD-NESTED-CLASS
+// RUN: FileCheck %s 
-input-file=%t/docs/PrimaryNamespace/NestedNamespace/index.md 
-check-prefix=MD-NESTED-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/PrimaryNamespace/index.md 
-check-prefix=MD-PRIMARY-INDEX
+// RUN: FileCheck %s 
-input-file=%t/docs/PrimaryNamespace/ClassInPrimaryNamespace.md 
-check-prefix=MD-PRIMARY-CLASS
+// RUN: FileCheck %s -input-file=%t/docs/all_files.md 
-check-prefix=MD-ALL-FILES
+// RUN: FileCheck %s -input-file=%t/docs/index.md -check-prefix=MD-INDEX

ilovepi wrote:

nit: -input-file

https://github.com/llvm/llvm-project/pull/97681
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Damyan Pepper via cfe-commits


@@ -437,7 +444,419 @@ void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr 
) {
 D->addAttr(NewAttr);
 }
 
+struct RegisterBindingFlags {
+  bool Resource = false;
+  bool UDT = false;
+  bool Other = false;
+  bool Basic = false;
+
+  bool SRV = false;
+  bool UAV = false;
+  bool CBV = false;
+  bool Sampler = false;
+
+  bool ContainsNumeric = false;
+  bool DefaultGlobals = false;
+};
+
+bool isDeclaredWithinCOrTBuffer(const Decl *decl) {
+  if (!decl)
+return false;
+
+  // Traverse up the parent contexts
+  const DeclContext *context = decl->getDeclContext();
+  if (isa(context)) {
+return true;
+  }
+
+  return false;
+}
+
+const CXXRecordDecl *getRecordDeclFromVarDecl(VarDecl *VD) {
+  const Type *Ty = VD->getType()->getPointeeOrArrayElementType();
+  assert(Ty && "Resource class must have an element type.");
+
+  if (const auto *BTy = dyn_cast(Ty))
+return nullptr;
+
+  const CXXRecordDecl *TheRecordDecl = Ty->getAsCXXRecordDecl();
+  assert(TheRecordDecl &&
+ "Resource class should have a resource type declaration.");
+
+  if (auto TDecl = dyn_cast(TheRecordDecl))
+TheRecordDecl = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+  TheRecordDecl = TheRecordDecl->getCanonicalDecl();
+  return TheRecordDecl;
+}
+
+const HLSLResourceAttr *
+getHLSLResourceAttrFromEitherDecl(VarDecl *VD,
+  HLSLBufferDecl *CBufferOrTBuffer) {
+
+  if (VD) {
+const CXXRecordDecl *TheRecordDecl = getRecordDeclFromVarDecl(VD);
+if (!TheRecordDecl)
+  return nullptr;
+const auto *Attr = TheRecordDecl->getAttr();
+return Attr;
+  } else if (CBufferOrTBuffer) {
+const auto *Attr = CBufferOrTBuffer->getAttr();
+return Attr;
+  }
+  llvm_unreachable("one of the two conditions should be true.");
+  return nullptr;
+}
+
+void traverseType(QualType T, RegisterBindingFlags ) {
+  if (T->isIntegralOrEnumerationType() || T->isFloatingType()) {
+r.ContainsNumeric = true;
+return;
+  }
+  const RecordType *RT = T->getAs();
+  if (!RT)
+return;
+
+  RecordDecl *SubRD = RT->getDecl();
+  if (auto TDecl = dyn_cast(SubRD)) {
+auto TheRecordDecl = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+TheRecordDecl = TheRecordDecl->getCanonicalDecl();
+const auto *Attr = TheRecordDecl->getAttr();
+llvm::hlsl::ResourceClass DeclResourceClass = Attr->getResourceClass();
+switch (DeclResourceClass) {
+case llvm::hlsl::ResourceClass::SRV:
+  r.SRV = true;
+  break;
+case llvm::hlsl::ResourceClass::UAV:
+  r.UAV = true;
+  break;
+case llvm::hlsl::ResourceClass::CBuffer:
+  r.CBV = true;
+  break;
+case llvm::hlsl::ResourceClass::Sampler:
+  r.Sampler = true;
+  break;
+}
+  }
+
+  else if (SubRD->isCompleteDefinition()) {
+for (auto Field : SubRD->fields()) {
+  QualType T = Field->getType();
+  traverseType(T, r);
+}
+  }
+}
+
+void setResourceClassFlagsFromRecordDecl(RegisterBindingFlags ,
+ const RecordDecl *RD) {
+  if (!RD)
+return;
+
+  if (RD->isCompleteDefinition()) {
+for (auto Field : RD->fields()) {
+  QualType T = Field->getType();
+  traverseType(T, r);
+}
+  }
+}
+
+RegisterBindingFlags HLSLFillRegisterBindingFlags(Sema , Decl *D) {
+  RegisterBindingFlags r;
+  if (!isDeclaredWithinCOrTBuffer(D)) {
+// make sure the type is a basic / numeric type
+if (VarDecl *v = dyn_cast(D)) {
+  QualType t = v->getType();
+  // a numeric variable will inevitably end up in $Globals buffer
+  if (t->isIntegralType(S.getASTContext()) || t->isFloatingType())
+r.DefaultGlobals = true;
+}
+  }
+  // Cbuffers and Tbuffers are HLSLBufferDecl types
+  HLSLBufferDecl *CBufferOrTBuffer = dyn_cast(D);
+  // Samplers, UAVs, and SRVs are VarDecl types
+  VarDecl *VD = dyn_cast(D);
+
+  assert(((VD && !CBufferOrTBuffer) || (!VD && CBufferOrTBuffer)) &&
+ "either VD or CBufferOrTBuffer should be set");
+
+  if (CBufferOrTBuffer) {
+r.Resource = true;
+if (CBufferOrTBuffer->isCBuffer())
+  r.CBV = true;
+else
+  r.SRV = true;
+  } else if (VD) {
+const HLSLResourceAttr *res_attr =
+getHLSLResourceAttrFromEitherDecl(VD, CBufferOrTBuffer);
+if (res_attr) {
+  llvm::hlsl::ResourceClass DeclResourceClass =
+  res_attr->getResourceClass();
+  r.Resource = true;
+  switch (DeclResourceClass) {
+  case llvm::hlsl::ResourceClass::SRV: {
+r.SRV = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::UAV: {
+r.UAV = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::CBuffer: {
+r.CBV = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::Sampler: {
+r.Sampler = true;
+break;
+  }
+  }
+} else {
+  if (VD->getType()->isBuiltinType())
+r.Basic = true;
+  else if 

[clang-tools-extra] [clang-doc] add enum test (PR #97679)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,38 @@
+// RUN: clang-doc --format=html --doxygen --output=%t/docs 
--executor=standalone %s
+// RUN: clang-doc --format=md --doxygen --output=%t/docs --executor=standalone 
%s
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/index.html 
-check-prefix=HTML-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/index.md 
-check-prefix=MD-INDEX

ilovepi wrote:

Do these not work w/o `-input-file`?

https://github.com/llvm/llvm-project/pull/97679
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add enum test (PR #97679)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,38 @@
+// RUN: clang-doc --format=html --doxygen --output=%t/docs 
--executor=standalone %s
+// RUN: clang-doc --format=md --doxygen --output=%t/docs --executor=standalone 
%s
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/index.html 
-check-prefix=HTML-INDEX
+// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/index.md 
-check-prefix=MD-INDEX
+
+/**
+ * @brief For specifying RGB colors
+ */
+enum Color {
+  Red, // Red enums
+  Green, // Green enums
+  Blue // Blue enums

ilovepi wrote:

should these be doc comments?

https://github.com/llvm/llvm-project/pull/97679
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add enum test (PR #97679)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,38 @@
+// RUN: clang-doc --format=html --doxygen --output=%t/docs 
--executor=standalone %s
+// RUN: clang-doc --format=md --doxygen --output=%t/docs --executor=standalone 
%s

ilovepi wrote:

This can't work right, can it? you haven't made `%t`, you also don't need 
`docs`, right? It would be good if I didn't have to point these out in every 
patch... I've given this piece of feedback in almost all of your patches.

https://github.com/llvm/llvm-project/pull/97679
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Damyan Pepper via cfe-commits


@@ -437,7 +444,419 @@ void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr 
) {
 D->addAttr(NewAttr);
 }
 
+struct RegisterBindingFlags {
+  bool Resource = false;
+  bool UDT = false;
+  bool Other = false;
+  bool Basic = false;
+
+  bool SRV = false;
+  bool UAV = false;
+  bool CBV = false;
+  bool Sampler = false;
+
+  bool ContainsNumeric = false;
+  bool DefaultGlobals = false;
+};
+
+bool isDeclaredWithinCOrTBuffer(const Decl *decl) {
+  if (!decl)
+return false;
+
+  // Traverse up the parent contexts
+  const DeclContext *context = decl->getDeclContext();
+  if (isa(context)) {
+return true;
+  }
+
+  return false;
+}
+
+const CXXRecordDecl *getRecordDeclFromVarDecl(VarDecl *VD) {
+  const Type *Ty = VD->getType()->getPointeeOrArrayElementType();
+  assert(Ty && "Resource class must have an element type.");
+
+  if (const auto *BTy = dyn_cast(Ty))
+return nullptr;
+
+  const CXXRecordDecl *TheRecordDecl = Ty->getAsCXXRecordDecl();
+  assert(TheRecordDecl &&
+ "Resource class should have a resource type declaration.");
+
+  if (auto TDecl = dyn_cast(TheRecordDecl))
+TheRecordDecl = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+  TheRecordDecl = TheRecordDecl->getCanonicalDecl();
+  return TheRecordDecl;
+}
+
+const HLSLResourceAttr *
+getHLSLResourceAttrFromEitherDecl(VarDecl *VD,
+  HLSLBufferDecl *CBufferOrTBuffer) {
+
+  if (VD) {
+const CXXRecordDecl *TheRecordDecl = getRecordDeclFromVarDecl(VD);
+if (!TheRecordDecl)
+  return nullptr;
+const auto *Attr = TheRecordDecl->getAttr();
+return Attr;
+  } else if (CBufferOrTBuffer) {
+const auto *Attr = CBufferOrTBuffer->getAttr();
+return Attr;
+  }
+  llvm_unreachable("one of the two conditions should be true.");
+  return nullptr;
+}
+
+void traverseType(QualType T, RegisterBindingFlags ) {
+  if (T->isIntegralOrEnumerationType() || T->isFloatingType()) {
+r.ContainsNumeric = true;
+return;
+  }
+  const RecordType *RT = T->getAs();
+  if (!RT)
+return;
+
+  RecordDecl *SubRD = RT->getDecl();
+  if (auto TDecl = dyn_cast(SubRD)) {
+auto TheRecordDecl = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+TheRecordDecl = TheRecordDecl->getCanonicalDecl();
+const auto *Attr = TheRecordDecl->getAttr();
+llvm::hlsl::ResourceClass DeclResourceClass = Attr->getResourceClass();
+switch (DeclResourceClass) {
+case llvm::hlsl::ResourceClass::SRV:
+  r.SRV = true;
+  break;
+case llvm::hlsl::ResourceClass::UAV:
+  r.UAV = true;
+  break;
+case llvm::hlsl::ResourceClass::CBuffer:
+  r.CBV = true;
+  break;
+case llvm::hlsl::ResourceClass::Sampler:
+  r.Sampler = true;
+  break;
+}
+  }
+
+  else if (SubRD->isCompleteDefinition()) {
+for (auto Field : SubRD->fields()) {
+  QualType T = Field->getType();
+  traverseType(T, r);
+}
+  }
+}
+
+void setResourceClassFlagsFromRecordDecl(RegisterBindingFlags ,
+ const RecordDecl *RD) {
+  if (!RD)
+return;
+
+  if (RD->isCompleteDefinition()) {
+for (auto Field : RD->fields()) {
+  QualType T = Field->getType();
+  traverseType(T, r);
+}
+  }
+}
+
+RegisterBindingFlags HLSLFillRegisterBindingFlags(Sema , Decl *D) {
+  RegisterBindingFlags r;
+  if (!isDeclaredWithinCOrTBuffer(D)) {
+// make sure the type is a basic / numeric type
+if (VarDecl *v = dyn_cast(D)) {
+  QualType t = v->getType();
+  // a numeric variable will inevitably end up in $Globals buffer
+  if (t->isIntegralType(S.getASTContext()) || t->isFloatingType())
+r.DefaultGlobals = true;
+}
+  }
+  // Cbuffers and Tbuffers are HLSLBufferDecl types
+  HLSLBufferDecl *CBufferOrTBuffer = dyn_cast(D);
+  // Samplers, UAVs, and SRVs are VarDecl types
+  VarDecl *VD = dyn_cast(D);
+
+  assert(((VD && !CBufferOrTBuffer) || (!VD && CBufferOrTBuffer)) &&
+ "either VD or CBufferOrTBuffer should be set");
+
+  if (CBufferOrTBuffer) {
+r.Resource = true;
+if (CBufferOrTBuffer->isCBuffer())
+  r.CBV = true;
+else
+  r.SRV = true;
+  } else if (VD) {
+const HLSLResourceAttr *res_attr =
+getHLSLResourceAttrFromEitherDecl(VD, CBufferOrTBuffer);
+if (res_attr) {
+  llvm::hlsl::ResourceClass DeclResourceClass =
+  res_attr->getResourceClass();
+  r.Resource = true;
+  switch (DeclResourceClass) {
+  case llvm::hlsl::ResourceClass::SRV: {
+r.SRV = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::UAV: {
+r.UAV = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::CBuffer: {
+r.CBV = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::Sampler: {
+r.Sampler = true;
+break;
+  }
+  }
+} else {
+  if (VD->getType()->isBuiltinType())
+r.Basic = true;
+  else if 

[clang] [RFC] [clang][Toolchain] Treat "pc"/"unknown" vendor interchangeable (PR #97802)

2024-07-09 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> The problem is not only with Rust, it is any invocation with non-default 
> --target (--target != LLVM_DEFAULT_TARGET_TRIPLE), and I was fixing a C++ 
> issue not a Rust issue, but I guess it will be covered

If you specify the wrong `--target=` (avoid `-target `, deprecated since Clang 
3.4), clangDriver will not find the compiler-rt library.
This works as intended.

If you mix target triples for LTO you will get warnings:

```
% clang --target=x86_64-pc-linux-gnu -flto -c a.c && clang 
--target=x86_64-unkwown-linux-gnu -flto -c b.c && clang -flto -fuse-ld=lld a.o 
b.o
ld.lld: warning: Linking two modules of different target triples: 'b.o' is 
'x86_64-unkwown-linux-gnu' whereas 'ld-temp.o' is 'x86_64-pc-linux-gnu'
```

> @MaskRay you still think that it does not worth to make this two targets 
> (x86_64-**pc**-linux-gnu and x86_64-**unknown**-linux-gnu) interchangeable?

Try fixing the build system issue instead:) I hope that we don't make Clang 
less strict.


https://github.com/llvm/llvm-project/pull/97802
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add ftime profiling (PR #97644)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -670,6 +671,7 @@ llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, 
T I) {
 
 template <>
 llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, Reference *I) {
+  llvm::TimeTraceScope("clang-doc", "readRecord Reference");

ilovepi wrote:

Why `readRecord Reference`? If you want to describe the fact that you're in 
`readRecord`, just do that, otherwise, if its a logical thing, `Read Record`. 
If `reference` is important, its fine to leave, but its not clear to me why. 

https://github.com/llvm/llvm-project/pull/97644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add ftime profiling (PR #97644)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -362,6 +395,17 @@ Example usage for a project using a compile commands 
database:
   if (Err) {
 llvm::outs() << "warning: " << toString(std::move(Err)) << "\n";
   }
-
+  llvm::timeTraceProfilerEnd();
+
+  if (FTimeTrace) {
+std::error_code EC;
+llvm::raw_fd_ostream OS("clang-doc-tracing.json", EC,
+llvm::sys::fs::OF_Text);
+if (!EC) {
+  llvm::timeTraceProfilerWrite(OS);
+} else {
+  llvm::errs() << "Error opening file: " << EC.message() << "\n";

ilovepi wrote:

shouldn't we be returning an error value from main here?

https://github.com/llvm/llvm-project/pull/97644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add ftime profiling (PR #97644)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -99,6 +100,16 @@ URL of repository that hosts code.
 Used for links to definition locations.)"),
   llvm::cl::cat(ClangDocCategory));
 
+static llvm::cl::opt FTimeTrace("ftime-trace", llvm::cl::desc(R"(
+Turn on time profiler. Generates clang-doc-tracing.json)"),
+  llvm::cl::init(false),
+  llvm::cl::cat(ClangDocCategory));
+
+static llvm::cl::opt FTimeGranularity("ftime-gran", llvm::cl::desc(R"(

ilovepi wrote:

```suggestion
static llvm::cl::opt FTimeGranularity("ftime-granularity", 
llvm::cl::desc(R"(
```
I haven't seen this used elsewhere, is it common in other components? I think 
its more typical to pick/set the granularity for a tool as a constant. Even if 
we keep it, it should be a hidden option.

https://github.com/llvm/llvm-project/pull/97644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add ftime profiling (PR #97644)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -30,6 +35,7 @@ template  bool MapASTVisitor::mapDecl(const T *D) 
{
   if (D->getParentFunctionOrMethod())
 return true;
 
+  llvm::timeTraceProfilerBegin("emit info phase", "emit info");

ilovepi wrote:

nit: try to be consistent w/ the logging style and capitalization of your 
messages. It seems to be all over the place.

More concretely, though, what does `emit info` mean/imply here?

https://github.com/llvm/llvm-project/pull/97644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add ftime profiling (PR #97644)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -316,32 +342,39 @@ Example usage for a project using a compile commands 
database:
 std::move(ReadInfos->begin(), ReadInfos->end(),
   std::back_inserter(Infos));
   }
+  llvm::timeTraceProfilerEnd();
 
+  llvm::timeTraceProfilerBegin("merging bitcode phase", "merging");
   auto Reduced = doc::mergeInfos(Infos);
   if (!Reduced) {
 llvm::errs() << llvm::toString(Reduced.takeError());
 return;
   }
+  llvm::timeTraceProfilerEnd();
 
   // Add a reference to this Info in the Index
   {
 std::lock_guard Guard(IndexMutex);
 clang::doc::Generator::addInfoToIndex(CDCtx.Idx, Reduced.get().get());
   }
-

ilovepi wrote:

nit: unrelated change.

https://github.com/llvm/llvm-project/pull/97644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add ftime profiling (PR #97644)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -681,6 +683,7 @@ llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, 
Reference *I) {
 // Read a block of records into a single info.
 template 
 llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) {
+  llvm::TimeTraceScope("readBlock", "ClangDocBitcodeReader");

ilovepi wrote:

Actually, looking at these, I'm not sure I follow the organizational structure 
of these. How did you decide what's the `Name` and what's the `Detail`? is 
there some logic to this?

https://github.com/llvm/llvm-project/pull/97644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add ftime profiling (PR #97644)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -480,12 +480,15 @@ mergeInfos(std::vector> );
 struct ClangDocContext {
   ClangDocContext() = default;
   ClangDocContext(tooling::ExecutionContext *ECtx, StringRef ProjectName,
-  bool PublicOnly, StringRef OutDirectory, StringRef 
SourceRoot,
+  bool PublicOnly, bool FTimeTrace, int Granularity,

ilovepi wrote:

These new params should probably go at the end of the arguments list. Likely 
they should have a default value, too.

https://github.com/llvm/llvm-project/pull/97644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add ftime profiling (PR #97644)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -30,7 +30,7 @@ ClangDocContext
 getClangDocContext(std::vector UserStylesheets = {},
StringRef RepositoryUrl = "") {
   ClangDocContext CDCtx{
-  {}, "test-project", {}, {}, {}, RepositoryUrl, UserStylesheets};
+  {}, "test-project", {}, {}, {}, {}, {}, RepositoryUrl, UserStylesheets};

ilovepi wrote:

If the new parameters go at the end, and have default values, then you don't 
need to updated this.

https://github.com/llvm/llvm-project/pull/97644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add ftime profiling (PR #97644)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -13,12 +13,17 @@
 #include "clang/Index/USRGeneration.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/TimeProfiler.h"
 
 namespace clang {
 namespace doc {
 
 void MapASTVisitor::HandleTranslationUnit(ASTContext ) {
+  if (CDCtx.FTimeTrace)
+llvm::timeTraceProfilerInitialize(CDCtx.Granularity, "clang-doc");

ilovepi wrote:

Why here and not say in the lambda in clang-doc main, or in the constructor for 
the visitor?

https://github.com/llvm/llvm-project/pull/97644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add ftime profiling (PR #97644)

2024-07-09 Thread Paul Kirth via cfe-commits


@@ -362,6 +395,17 @@ Example usage for a project using a compile commands 
database:
   if (Err) {
 llvm::outs() << "warning: " << toString(std::move(Err)) << "\n";
   }
-
+  llvm::timeTraceProfilerEnd();
+
+  if (FTimeTrace) {
+std::error_code EC;
+llvm::raw_fd_ostream OS("clang-doc-tracing.json", EC,
+llvm::sys::fs::OF_Text);
+if (!EC) {
+  llvm::timeTraceProfilerWrite(OS);
+} else {

ilovepi wrote:

nit: no braces for single statement conditions.

https://github.com/llvm/llvm-project/pull/97644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add ftime profiling (PR #97644)

2024-07-09 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/97644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] add ftime profiling (PR #97644)

2024-07-09 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi edited 
https://github.com/llvm/llvm-project/pull/97644
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Damyan Pepper via cfe-commits


@@ -437,7 +444,419 @@ void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr 
) {
 D->addAttr(NewAttr);
 }
 
+struct RegisterBindingFlags {
+  bool Resource = false;
+  bool UDT = false;
+  bool Other = false;
+  bool Basic = false;
+
+  bool SRV = false;
+  bool UAV = false;
+  bool CBV = false;
+  bool Sampler = false;
+
+  bool ContainsNumeric = false;
+  bool DefaultGlobals = false;
+};
+
+bool isDeclaredWithinCOrTBuffer(const Decl *decl) {
+  if (!decl)
+return false;
+
+  // Traverse up the parent contexts
+  const DeclContext *context = decl->getDeclContext();
+  if (isa(context)) {
+return true;
+  }
+
+  return false;
+}
+
+const CXXRecordDecl *getRecordDeclFromVarDecl(VarDecl *VD) {
+  const Type *Ty = VD->getType()->getPointeeOrArrayElementType();
+  assert(Ty && "Resource class must have an element type.");
+
+  if (const auto *BTy = dyn_cast(Ty))
+return nullptr;
+
+  const CXXRecordDecl *TheRecordDecl = Ty->getAsCXXRecordDecl();
+  assert(TheRecordDecl &&
+ "Resource class should have a resource type declaration.");
+
+  if (auto TDecl = dyn_cast(TheRecordDecl))
+TheRecordDecl = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+  TheRecordDecl = TheRecordDecl->getCanonicalDecl();
+  return TheRecordDecl;
+}
+
+const HLSLResourceAttr *
+getHLSLResourceAttrFromEitherDecl(VarDecl *VD,
+  HLSLBufferDecl *CBufferOrTBuffer) {
+
+  if (VD) {
+const CXXRecordDecl *TheRecordDecl = getRecordDeclFromVarDecl(VD);
+if (!TheRecordDecl)
+  return nullptr;
+const auto *Attr = TheRecordDecl->getAttr();
+return Attr;
+  } else if (CBufferOrTBuffer) {
+const auto *Attr = CBufferOrTBuffer->getAttr();
+return Attr;
+  }
+  llvm_unreachable("one of the two conditions should be true.");
+  return nullptr;
+}
+
+void traverseType(QualType T, RegisterBindingFlags ) {
+  if (T->isIntegralOrEnumerationType() || T->isFloatingType()) {
+r.ContainsNumeric = true;
+return;
+  }
+  const RecordType *RT = T->getAs();
+  if (!RT)
+return;
+
+  RecordDecl *SubRD = RT->getDecl();
+  if (auto TDecl = dyn_cast(SubRD)) {
+auto TheRecordDecl = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+TheRecordDecl = TheRecordDecl->getCanonicalDecl();
+const auto *Attr = TheRecordDecl->getAttr();
+llvm::hlsl::ResourceClass DeclResourceClass = Attr->getResourceClass();
+switch (DeclResourceClass) {
+case llvm::hlsl::ResourceClass::SRV:
+  r.SRV = true;
+  break;
+case llvm::hlsl::ResourceClass::UAV:
+  r.UAV = true;
+  break;
+case llvm::hlsl::ResourceClass::CBuffer:
+  r.CBV = true;
+  break;
+case llvm::hlsl::ResourceClass::Sampler:
+  r.Sampler = true;
+  break;
+}
+  }
+
+  else if (SubRD->isCompleteDefinition()) {
+for (auto Field : SubRD->fields()) {
+  QualType T = Field->getType();
+  traverseType(T, r);
+}
+  }
+}
+
+void setResourceClassFlagsFromRecordDecl(RegisterBindingFlags ,
+ const RecordDecl *RD) {
+  if (!RD)
+return;
+
+  if (RD->isCompleteDefinition()) {
+for (auto Field : RD->fields()) {
+  QualType T = Field->getType();
+  traverseType(T, r);
+}
+  }
+}
+
+RegisterBindingFlags HLSLFillRegisterBindingFlags(Sema , Decl *D) {
+  RegisterBindingFlags r;
+  if (!isDeclaredWithinCOrTBuffer(D)) {
+// make sure the type is a basic / numeric type
+if (VarDecl *v = dyn_cast(D)) {
+  QualType t = v->getType();
+  // a numeric variable will inevitably end up in $Globals buffer
+  if (t->isIntegralType(S.getASTContext()) || t->isFloatingType())
+r.DefaultGlobals = true;
+}
+  }
+  // Cbuffers and Tbuffers are HLSLBufferDecl types
+  HLSLBufferDecl *CBufferOrTBuffer = dyn_cast(D);
+  // Samplers, UAVs, and SRVs are VarDecl types
+  VarDecl *VD = dyn_cast(D);
+
+  assert(((VD && !CBufferOrTBuffer) || (!VD && CBufferOrTBuffer)) &&
+ "either VD or CBufferOrTBuffer should be set");
+
+  if (CBufferOrTBuffer) {
+r.Resource = true;
+if (CBufferOrTBuffer->isCBuffer())
+  r.CBV = true;
+else
+  r.SRV = true;
+  } else if (VD) {
+const HLSLResourceAttr *res_attr =
+getHLSLResourceAttrFromEitherDecl(VD, CBufferOrTBuffer);
+if (res_attr) {
+  llvm::hlsl::ResourceClass DeclResourceClass =
+  res_attr->getResourceClass();
+  r.Resource = true;
+  switch (DeclResourceClass) {
+  case llvm::hlsl::ResourceClass::SRV: {
+r.SRV = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::UAV: {
+r.UAV = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::CBuffer: {
+r.CBV = true;
+break;
+  }
+  case llvm::hlsl::ResourceClass::Sampler: {
+r.Sampler = true;
+break;
+  }
+  }
+} else {
+  if (VD->getType()->isBuiltinType())
+r.Basic = true;
+  else if 

[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Damyan Pepper via cfe-commits


@@ -437,7 +444,419 @@ void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr 
) {
 D->addAttr(NewAttr);
 }
 
+struct RegisterBindingFlags {
+  bool Resource = false;
+  bool UDT = false;
+  bool Other = false;
+  bool Basic = false;
+
+  bool SRV = false;
+  bool UAV = false;
+  bool CBV = false;
+  bool Sampler = false;
+
+  bool ContainsNumeric = false;
+  bool DefaultGlobals = false;
+};
+
+bool isDeclaredWithinCOrTBuffer(const Decl *decl) {
+  if (!decl)
+return false;
+
+  // Traverse up the parent contexts
+  const DeclContext *context = decl->getDeclContext();
+  if (isa(context)) {
+return true;
+  }
+
+  return false;
+}
+
+const CXXRecordDecl *getRecordDeclFromVarDecl(VarDecl *VD) {
+  const Type *Ty = VD->getType()->getPointeeOrArrayElementType();
+  assert(Ty && "Resource class must have an element type.");
+
+  if (const auto *BTy = dyn_cast(Ty))
+return nullptr;
+
+  const CXXRecordDecl *TheRecordDecl = Ty->getAsCXXRecordDecl();
+  assert(TheRecordDecl &&
+ "Resource class should have a resource type declaration.");
+
+  if (auto TDecl = dyn_cast(TheRecordDecl))
+TheRecordDecl = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+  TheRecordDecl = TheRecordDecl->getCanonicalDecl();
+  return TheRecordDecl;
+}
+
+const HLSLResourceAttr *
+getHLSLResourceAttrFromEitherDecl(VarDecl *VD,
+  HLSLBufferDecl *CBufferOrTBuffer) {
+
+  if (VD) {
+const CXXRecordDecl *TheRecordDecl = getRecordDeclFromVarDecl(VD);
+if (!TheRecordDecl)
+  return nullptr;
+const auto *Attr = TheRecordDecl->getAttr();
+return Attr;
+  } else if (CBufferOrTBuffer) {
+const auto *Attr = CBufferOrTBuffer->getAttr();
+return Attr;
+  }
+  llvm_unreachable("one of the two conditions should be true.");
+  return nullptr;
+}
+
+void traverseType(QualType T, RegisterBindingFlags ) {
+  if (T->isIntegralOrEnumerationType() || T->isFloatingType()) {
+r.ContainsNumeric = true;
+return;
+  }
+  const RecordType *RT = T->getAs();
+  if (!RT)
+return;
+
+  RecordDecl *SubRD = RT->getDecl();
+  if (auto TDecl = dyn_cast(SubRD)) {
+auto TheRecordDecl = TDecl->getSpecializedTemplate()->getTemplatedDecl();
+TheRecordDecl = TheRecordDecl->getCanonicalDecl();
+const auto *Attr = TheRecordDecl->getAttr();
+llvm::hlsl::ResourceClass DeclResourceClass = Attr->getResourceClass();
+switch (DeclResourceClass) {
+case llvm::hlsl::ResourceClass::SRV:
+  r.SRV = true;
+  break;
+case llvm::hlsl::ResourceClass::UAV:
+  r.UAV = true;
+  break;
+case llvm::hlsl::ResourceClass::CBuffer:
+  r.CBV = true;
+  break;
+case llvm::hlsl::ResourceClass::Sampler:
+  r.Sampler = true;
+  break;
+}
+  }
+
+  else if (SubRD->isCompleteDefinition()) {
+for (auto Field : SubRD->fields()) {
+  QualType T = Field->getType();
+  traverseType(T, r);
+}
+  }
+}
+
+void setResourceClassFlagsFromRecordDecl(RegisterBindingFlags ,
+ const RecordDecl *RD) {
+  if (!RD)
+return;
+
+  if (RD->isCompleteDefinition()) {
+for (auto Field : RD->fields()) {
+  QualType T = Field->getType();
+  traverseType(T, r);
+}
+  }
+}
+
+RegisterBindingFlags HLSLFillRegisterBindingFlags(Sema , Decl *D) {
+  RegisterBindingFlags r;
+  if (!isDeclaredWithinCOrTBuffer(D)) {
+// make sure the type is a basic / numeric type
+if (VarDecl *v = dyn_cast(D)) {
+  QualType t = v->getType();
+  // a numeric variable will inevitably end up in $Globals buffer
+  if (t->isIntegralType(S.getASTContext()) || t->isFloatingType())
+r.DefaultGlobals = true;
+}
+  }
+  // Cbuffers and Tbuffers are HLSLBufferDecl types
+  HLSLBufferDecl *CBufferOrTBuffer = dyn_cast(D);
+  // Samplers, UAVs, and SRVs are VarDecl types
+  VarDecl *VD = dyn_cast(D);
+
+  assert(((VD && !CBufferOrTBuffer) || (!VD && CBufferOrTBuffer)) &&
+ "either VD or CBufferOrTBuffer should be set");
+
+  if (CBufferOrTBuffer) {
+r.Resource = true;
+if (CBufferOrTBuffer->isCBuffer())
+  r.CBV = true;
+else
+  r.SRV = true;
+  } else if (VD) {
+const HLSLResourceAttr *res_attr =
+getHLSLResourceAttrFromEitherDecl(VD, CBufferOrTBuffer);
+if (res_attr) {
+  llvm::hlsl::ResourceClass DeclResourceClass =
+  res_attr->getResourceClass();
+  r.Resource = true;
+  switch (DeclResourceClass) {
+  case llvm::hlsl::ResourceClass::SRV: {

damyanp wrote:

The braces around all the cases here aren't necessary.

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Damyan Pepper via cfe-commits


@@ -437,7 +453,409 @@ void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr 
) {
 D->addAttr(NewAttr);
 }
 
+struct RegisterBindingFlags {
+  bool Resource = false;
+  bool Udt = false;
+  bool Other = false;
+  bool Basic = false;
+
+  bool Srv = false;
+  bool Uav = false;
+  bool Cbv = false;
+  bool Sampler = false;
+
+  bool ContainsNumeric = false;
+  bool DefaultGlobals = false;
+};
+
+bool isDeclaredWithinCOrTBuffer(const Decl *decl) {

damyanp wrote:

There's quite a few places where local variables start with lowercase remaining.

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Damyan Pepper via cfe-commits


@@ -0,0 +1,103 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - 
-fsyntax-only %s -verify
+
+// TODO: Implement "Buffer"
+struct Eg1 {
+  float f;
+  // Buffer Buf;
+  RWBuffer RWBuf;
+  };
+Eg1 e1 : /* register(t0) :*/ register(u0); 
+// Valid: f is skipped, Buf is bound to t0, RWBuf is bound to u0
+
+
+struct Eg2 {
+  float f;
+  // Buffer Buf;
+  RWBuffer RWBuf;
+  RWBuffer RWBuf2;
+  };
+Eg2 e2 : /* register(t0) :*/ register(u0); 
+// Valid: f is skipped, Buf is bound to t0, RWBuf is bound to u0. 
+// RWBuf2 gets automatically assigned to u1 even though there is no explicit 
binding for u1.
+
+/*
+struct Eg3 {
+  float f;
+  // Buffer Buf;
+  }; 
+Eg3 e3 : register(t0) : register(u0);
+// Valid: Buf gets bound to t0. Buf will also be bound to u0.
+*/
+
+struct Eg4 {
+  struct Bar {
+RWBuffer a;
+};
+Bar b;
+};
+Eg4 e4 : register(u0);
+// Valid: Bar, the struct within Eg4, has a valid resource that can be bound 
to t0. 
+
+/* Light up this test when SamplerState is implemented
+struct Eg5 {
+  SamplerState s[3];
+};
+
+Eg5 e5 : register(s5);
+// Valid: the first sampler state object within Eg5's s is bound to slot 5
+*/
+
+struct Eg6 {
+  float f;
+}; 
+// expected-warning@+1{{variable of type 'Eg6' bound to register type 't' does 
not contain a matching 'srv' resource}}
+Eg6 e6 : register(t0);
+
+struct Eg7 {
+  struct Bar {
+float f;
+  };
+  Bar b;
+};
+// expected-warning@+1{{variable of type 'Eg7' bound to register type 't' does 
not contain a matching 'srv' resource}}
+Eg7 e7 : register(t0);
+
+struct Eg8 {
+  RWBuffer a;
+}; 
+// expected-warning@+1{{register 'c' used on type with no contents to allocate 
in a constant buffer}}
+Eg8 e8 : register(c0);
+
+
+struct Eg9{
+  // expected-error@+1{{'register' attribute only applies to cbuffer/tbuffer 
and external global variables}}
+  RWBuffer a : register(u9);
+};
+
+Eg9 e9;
+/* Light up this test when Texture2D is implemented
+template
+struct Eg10 {
+R b;
+};
+// expecting warning: {{variable of type 'Eg10' bound to register type 'u' 
does not contain a matching 'uav' resource}}
+Eg10 e10 : register(u0);
+
+// invalid because after template expansion, there are no valid resources 
inside Eg10 to bind as a UAV.
+*/
+
+struct Eg11{
+  RWBuffer a;
+  RWBuffer b;
+};
+
+// expected-error@+1{{conflicting register annotations: multiple register 
annotations detected for register type 'u'}}
+Eg11 e11 : register(u9) : register(u10);
+// expected-error@+1{{conflicting register annotations: multiple register 
annotations detected for register type 'u'}}
+Eg11 e11a : register(u9, space0) : register(u9, space1);

damyanp wrote:

This is different to DXC - DXC prohibits register space's entirely for globals 
like this.  Maybe we want to change the language there, but we should do that 
deliberately if so.

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Damyan Pepper via cfe-commits


@@ -20,12 +20,12 @@ tbuffer g_tbuffer1 {
 float f5 : register(c2);
 };
 
-tbuffer g_cbuffer2 {
+cbuffer g_cbuffer2 {
 // expected-error@+1{{register binding type 'float' not supported for variable 
of type 'b'}}

damyanp wrote:

hmmm...is this message actually correct? This seems more correct to me:

> register binding type 'b' not supported for variable of type 'float'



https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc] Add another test project to clang-doc (PR #97518)

2024-07-09 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi requested changes to this pull request.

I'm a bit confused by the "advanced project", as it largely seems to be minor 
extensions to the `basic project`. I would expect that an "advanced project" 
would use a complicated structure and be much larger.  IMO if you're only 
adding some more language features, then they should be added to the existing 
`basic_project` already in tree.

https://github.com/llvm/llvm-project/pull/97518
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Clang][Coroutines] Introducing the `[[clang::coro_inplace_task]]` attribute (PR #94693)

2024-07-09 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 updated 
https://github.com/llvm/llvm-project/pull/94693

>From b263674367fb82ac9d7c306a42c500c8968ca3f7 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 4 Jun 2024 23:22:00 -0700
Subject: [PATCH 1/2] [Clang] Introduce [[clang::coro_inplace_task]]

---
 clang/include/clang/AST/ExprCXX.h | 26 --
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td | 19 +
 clang/lib/CodeGen/CGBlocks.cpp|  5 +-
 clang/lib/CodeGen/CGCUDARuntime.cpp   |  5 +-
 clang/lib/CodeGen/CGCUDARuntime.h |  8 +-
 clang/lib/CodeGen/CGCXXABI.h  | 10 +--
 clang/lib/CodeGen/CGClass.cpp | 16 ++--
 clang/lib/CodeGen/CGCoroutine.cpp | 30 +--
 clang/lib/CodeGen/CGExpr.cpp  | 41 +
 clang/lib/CodeGen/CGExprCXX.cpp   | 60 +++--
 clang/lib/CodeGen/CodeGenFunction.h   | 64 --
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 16 ++--
 clang/lib/CodeGen/MicrosoftCXXABI.cpp | 18 ++--
 clang/lib/Sema/SemaCoroutine.cpp  | 58 -
 clang/lib/Serialization/ASTReaderStmt.cpp | 10 ++-
 clang/lib/Serialization/ASTWriterStmt.cpp |  3 +-
 clang/test/CodeGenCoroutines/Inputs/utility.h | 13 +++
 .../coro-structured-concurrency.cpp   | 84 +++
 ...a-attribute-supported-attributes-list.test |  1 +
 llvm/include/llvm/IR/Intrinsics.td|  3 +
 .../lib/Transforms/Coroutines/CoroCleanup.cpp |  9 +-
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  | 58 -
 llvm/lib/Transforms/Coroutines/Coroutines.cpp |  1 +
 .../coro-elide-structured-concurrency.ll  | 64 ++
 25 files changed, 496 insertions(+), 134 deletions(-)
 create mode 100644 clang/test/CodeGenCoroutines/Inputs/utility.h
 create mode 100644 clang/test/CodeGenCoroutines/coro-structured-concurrency.cpp
 create mode 100644 
llvm/test/Transforms/Coroutines/coro-elide-structured-concurrency.ll

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index c2feac525c1ea..0cf62aee41b66 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -5082,7 +5082,8 @@ class CoroutineSuspendExpr : public Expr {
   enum SubExpr { Operand, Common, Ready, Suspend, Resume, Count };
 
   Stmt *SubExprs[SubExpr::Count];
-  OpaqueValueExpr *OpaqueValue = nullptr;
+  OpaqueValueExpr *CommonExprOpaqueValue = nullptr;
+  OpaqueValueExpr *InplaceCallOpaqueValue = nullptr;
 
 public:
   // These types correspond to the three C++ 'await_suspend' return variants
@@ -5090,10 +5091,10 @@ class CoroutineSuspendExpr : public Expr {
 
   CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Operand,
Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume,
-   OpaqueValueExpr *OpaqueValue)
+   OpaqueValueExpr *CommonExprOpaqueValue)
   : Expr(SC, Resume->getType(), Resume->getValueKind(),
  Resume->getObjectKind()),
-KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) {
+KeywordLoc(KeywordLoc), CommonExprOpaqueValue(CommonExprOpaqueValue) {
 SubExprs[SubExpr::Operand] = Operand;
 SubExprs[SubExpr::Common] = Common;
 SubExprs[SubExpr::Ready] = Ready;
@@ -5128,7 +5129,16 @@ class CoroutineSuspendExpr : public Expr {
   }
 
   /// getOpaqueValue - Return the opaque value placeholder.
-  OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
+  OpaqueValueExpr *getCommonExprOpaqueValue() const {
+return CommonExprOpaqueValue;
+  }
+
+  OpaqueValueExpr *getInplaceCallOpaqueValue() const {
+return InplaceCallOpaqueValue;
+  }
+  void setInplaceCallOpaqueValue(OpaqueValueExpr *E) {
+InplaceCallOpaqueValue = E;
+  }
 
   Expr *getReadyExpr() const {
 return static_cast(SubExprs[SubExpr::Ready]);
@@ -5194,9 +5204,9 @@ class CoawaitExpr : public CoroutineSuspendExpr {
 public:
   CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Common,
   Expr *Ready, Expr *Suspend, Expr *Resume,
-  OpaqueValueExpr *OpaqueValue, bool IsImplicit = false)
+  OpaqueValueExpr *CommonExprOpaqueValue, bool IsImplicit = false)
   : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Common,
- Ready, Suspend, Resume, OpaqueValue) {
+ Ready, Suspend, Resume, CommonExprOpaqueValue) {
 CoawaitBits.IsImplicit = IsImplicit;
   }
 
@@ -5275,9 +5285,9 @@ class CoyieldExpr : public CoroutineSuspendExpr {
 public:
   CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Common,
   Expr *Ready, Expr *Suspend, Expr *Resume,
-  OpaqueValueExpr *OpaqueValue)
+  OpaqueValueExpr *CommonExprOpaqueValue)
   : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Common,
-  

[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Joshua Batista via cfe-commits


@@ -635,46 +626,52 @@ RegisterBindingFlags HLSLFillRegisterBindingFlags(Sema 
, Decl *D) {
   } else
 r.Other = true;
 }
-  } else {
-llvm_unreachable("unknown decl type");
   }
   return r;
 }
 
+int getRegisterTypeIndex(StringRef Slot) {
+  switch (Slot[0]) {
+  case 't':
+return 0;
+  case 'u':
+return 1;
+  case 'b':
+return 2;
+  case 's':
+return 3;
+  case 'c':
+return 4;
+  case 'i':
+return 5;
+  default:
+llvm_unreachable("invalid register type");
+  }
+}
+
 static void ValidateMultipleRegisterAnnotations(Sema , Decl *D,
 StringRef ) {
-  // make sure that there are no register annotations applied to the decl
-  // with the same register type but different numbers
-  std::unordered_map>
-  s; // store unique register type + numbers
-  std::set starting_set = {Slot[1]};
-  s.insert(std::make_pair(Slot[0], starting_set));
+  // make sure that there are no tworegister annotations
+  // applied to the decl with the same register type
+  bool registerTypesDetectedCount[6];
+  for (int i = 0; i < 6; i++)
+registerTypesDetectedCount[i] = false;
+  registerTypesDetectedCount[getRegisterTypeIndex(Slot)] = true;
+
   for (auto it = D->attr_begin(); it != D->attr_end(); ++it) {
 if (HLSLResourceBindingAttr *attr =
 dyn_cast(*it)) {
   std::string otherSlot(attr->getSlot().data());

bob80905 wrote:

I've substituted the value into the diagnostic emission line, so no variable 
needs to be created. 

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Joshua Batista via cfe-commits


@@ -437,7 +453,409 @@ void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr 
) {
 D->addAttr(NewAttr);
 }
 
+struct RegisterBindingFlags {
+  bool Resource = false;
+  bool Udt = false;
+  bool Other = false;
+  bool Basic = false;
+
+  bool Srv = false;
+  bool Uav = false;
+  bool Cbv = false;
+  bool Sampler = false;
+
+  bool ContainsNumeric = false;
+  bool DefaultGlobals = false;
+};
+
+bool isDeclaredWithinCOrTBuffer(const Decl *decl) {
+  if (!decl)
+return false;
+
+  // Traverse up the parent contexts
+  const DeclContext *context = decl->getDeclContext();
+  while (context) {

bob80905 wrote:

I don't think there is such a case, I've removed the while loop.

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Damyan Pepper via cfe-commits


@@ -0,0 +1,104 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - 
-fsyntax-only %s -verify
+
+// TODO: Implement "Buffer"
+struct Eg1 {
+  float f;
+  // Buffer Buf;
+  RWBuffer RWBuf;
+  };
+Eg1 e1 : /* register(t0) :*/ register(u0); 
+// Valid: f is skipped, Buf is bound to t0, RWBuf is bound to u0
+
+
+struct Eg2 {
+  float f;
+  // Buffer Buf;
+  RWBuffer RWBuf;
+  RWBuffer RWBuf2;
+  };
+Eg2 e2 : /* register(t0) :*/ register(u0); 
+// Valid: f is skipped, Buf is bound to t0, RWBuf is bound to u0. 
+// RWBuf2 gets automatically assigned to u1 even though there is no explicit 
binding for u1.
+
+/*
+struct Eg3 {
+  float f;
+  // Buffer Buf;
+  }; 
+Eg3 e3 : register(t0) : register(u0);
+// Valid: Buf gets bound to t0. Buf will also be bound to u0.
+*/
+
+struct Eg4 {
+  struct Bar {
+RWBuffer a;
+};
+Bar b;
+};
+Eg4 e4 : register(u0);
+// Valid: Bar, the struct within Eg4, has a valid resource that can be bound 
to t0. 
+
+/* Light up this test when SamplerState is implemented
+struct Eg5 {
+  SamplerState s[3];
+};
+
+Eg5 e5 : register(s5);
+// Valid: the first sampler state object within Eg5's s is bound to slot 5
+*/
+
+struct Eg6 {
+  float f;
+}; 
+// expected-warning@+1{{variable of type 'Eg6' bound to register type 't' does 
not contain a matching 'srv' resource}}
+Eg6 e6 : register(t0);
+
+struct Eg7 {
+  struct Bar {
+float f;
+  };
+  Bar b;
+};
+// expected-warning@+1{{variable of type 'Eg7' bound to register type 't' does 
not contain a matching 'srv' resource}}
+Eg7 e7 : register(t0);
+
+struct Eg8 {
+  RWBuffer a;
+}; 
+// expected-warning@+1{{register 'c' used on type with no contents to allocate 
in a constant buffer}}
+Eg8 e8 : register(c0);
+
+
+struct Eg9{
+  // expected-error@+1{{'register' attribute only applies to cbuffer/tbuffer 
and external global variables}}
+  RWBuffer a : register(u9);
+};
+
+Eg9 e9;
+
+
+/* Light up this test when Texture2D is implemented
+template
+struct Eg10 {
+R b;
+};
+// expecting warning: {{variable of type 'Eg10' bound to register type 'u' 
does not contain a matching 'uav' resource}}
+Eg10 e10 : register(u0);
+
+// invalid because after template expansion, there are no valid resources 
inside Eg10 to bind as a UAV.
+*/ 
+
+struct Eg11{
+  RWBuffer a;
+  RWBuffer b;
+};
+
+// expected-error@+1{{conflicting register annotations: multiple register 
numbers detected for register type 'u'}}
+Eg11 e11 : register(u9) : register(u10);

damyanp wrote:

Happy with change to make all any 2 annotations for the same register type be a 
conflict.

For the record though, DXC does call this an error. It just stops reporting 
errors after the first one: https://godbolt.org/z/Mavh7KcPT

The "conflict" I was referring to was that the two register attributes are 
setting different initial bindings for `u` resources.  One starts at `u9, 
space0` and the other at `u9, space1`.  As the documentation says, these are 
two different registers. You cannot ignore the space when you try and decide if 
two registers are the same.

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Damyan Pepper via cfe-commits


@@ -635,46 +626,52 @@ RegisterBindingFlags HLSLFillRegisterBindingFlags(Sema 
, Decl *D) {
   } else
 r.Other = true;
 }
-  } else {
-llvm_unreachable("unknown decl type");
   }
   return r;
 }
 
+int getRegisterTypeIndex(StringRef Slot) {
+  switch (Slot[0]) {
+  case 't':
+return 0;
+  case 'u':
+return 1;
+  case 'b':
+return 2;
+  case 's':
+return 3;
+  case 'c':
+return 4;
+  case 'i':
+return 5;
+  default:
+llvm_unreachable("invalid register type");
+  }
+}
+
 static void ValidateMultipleRegisterAnnotations(Sema , Decl *D,
 StringRef ) {
-  // make sure that there are no register annotations applied to the decl
-  // with the same register type but different numbers
-  std::unordered_map>
-  s; // store unique register type + numbers
-  std::set starting_set = {Slot[1]};
-  s.insert(std::make_pair(Slot[0], starting_set));
+  // make sure that there are no tworegister annotations
+  // applied to the decl with the same register type
+  bool registerTypesDetectedCount[6];
+  for (int i = 0; i < 6; i++)
+registerTypesDetectedCount[i] = false;

damyanp wrote:

```suggestion
  bool RegisterTypesDetected[6] = {false};
```

Can initialize in one line.  Also I think the "Count" part of the name might be 
from an earlier design.

Also, should start with a capital letter.

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Damyan Pepper via cfe-commits


@@ -635,46 +626,52 @@ RegisterBindingFlags HLSLFillRegisterBindingFlags(Sema 
, Decl *D) {
   } else
 r.Other = true;
 }
-  } else {
-llvm_unreachable("unknown decl type");
   }
   return r;
 }
 
+int getRegisterTypeIndex(StringRef Slot) {
+  switch (Slot[0]) {
+  case 't':
+return 0;
+  case 'u':
+return 1;
+  case 'b':
+return 2;
+  case 's':
+return 3;
+  case 'c':
+return 4;
+  case 'i':
+return 5;
+  default:
+llvm_unreachable("invalid register type");
+  }
+}
+
 static void ValidateMultipleRegisterAnnotations(Sema , Decl *D,
 StringRef ) {
-  // make sure that there are no register annotations applied to the decl
-  // with the same register type but different numbers
-  std::unordered_map>
-  s; // store unique register type + numbers
-  std::set starting_set = {Slot[1]};
-  s.insert(std::make_pair(Slot[0], starting_set));
+  // make sure that there are no tworegister annotations
+  // applied to the decl with the same register type
+  bool registerTypesDetectedCount[6];
+  for (int i = 0; i < 6; i++)
+registerTypesDetectedCount[i] = false;
+  registerTypesDetectedCount[getRegisterTypeIndex(Slot)] = true;
+
   for (auto it = D->attr_begin(); it != D->attr_end(); ++it) {
 if (HLSLResourceBindingAttr *attr =
 dyn_cast(*it)) {
   std::string otherSlot(attr->getSlot().data());

damyanp wrote:

Do we really need to construct a `std::string` here?

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Damyan Pepper via cfe-commits


@@ -635,46 +626,52 @@ RegisterBindingFlags HLSLFillRegisterBindingFlags(Sema 
, Decl *D) {
   } else
 r.Other = true;
 }
-  } else {
-llvm_unreachable("unknown decl type");
   }
   return r;
 }
 
+int getRegisterTypeIndex(StringRef Slot) {
+  switch (Slot[0]) {
+  case 't':

damyanp wrote:

Good news!  It looks like DXC is case insensitive for register types: 
https://godbolt.org/z/e9Y71o9ch

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix sema init crash for not checking a ExprResult (PR #98102)

2024-07-09 Thread Yuxuan Chen via cfe-commits

yuxuanchen1997 wrote:

@AaronBallman I have good news. I was able to manually write a well-formed C++ 
file that crashes. 
https://gist.github.com/yuxuanchen1997/576dce964666f0f8713fccacf5847138

And I am able to validate that the fix I proposed here does fix the problem. 

https://github.com/llvm/llvm-project/pull/98102
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [msan] Precommit MSan Arm NEON vst tests (PR #98247)

2024-07-09 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka requested changes to this pull request.

Discussed offline, it should be IR tests

https://github.com/llvm/llvm-project/pull/98247
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Add -mlr-for-calls-only to replace the now removed -ffixed-x30 flag. (PR #98073)

2024-07-09 Thread Amara Emerson via cfe-commits

https://github.com/aemerson updated 
https://github.com/llvm/llvm-project/pull/98073

>From d7a8f55b0790b15060f73f188ce97c83fe75f62d Mon Sep 17 00:00:00 2001
From: Amara Emerson 
Date: Mon, 8 Jul 2024 10:09:06 -0700
Subject: [PATCH 1/4] [AArch64] Add -mlr-for-calls-only to replace the now
 removed -ffixed-x30 flag.

This re-introduces the effective behaviour that was reverted in 
7ad481e76c9bee5b9895ebfa0fdb52f31cb7de77.

This time we're not using the same mechanism, exposing another reservation 
feature
that prevents only regalloc from using the register, but not for other required 
uses
like ABIs.

This also fixes a consequent issue with reserving LR, which is that frame 
lowering
was only adding live-in flags for non-reserved regs. This would cause issues 
later
since the outliner needs accurate flags to determine when LR needs to be 
preserved.

rdar://131313095
---
 clang/include/clang/Driver/Options.td |   3 +
 .../clang/Driver/aarch64-mlr-for-calls-only.c |   4 +
 clang/lib/Driver/ToolChains/Arch/AArch64.cpp  |   3 +
 llvm/lib/Target/AArch64/AArch64Features.td|   4 +
 .../Target/AArch64/AArch64FrameLowering.cpp   |   7 +-
 .../Target/AArch64/AArch64RegisterInfo.cpp|   3 +
 llvm/lib/Target/AArch64/AArch64Subtarget.h|   1 +
 .../CodeGen/AArch64/arm64-platform-reg.ll |   7 +-
 .../AArch64/lr-reserved-for-ra-live-in.mir| 110 ++
 9 files changed, 139 insertions(+), 3 deletions(-)
 create mode 100644 clang/include/clang/Driver/aarch64-mlr-for-calls-only.c
 create mode 100644 llvm/test/CodeGen/AArch64/lr-reserved-for-ra-live-in.mir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 58ca6f2bea9e4..714d5de76dd99 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4917,6 +4917,9 @@ foreach i = {1-31} in
   def ffixed_x#i : Flag<["-"], "ffixed-x"#i>, Group,
 HelpText<"Reserve the x"#i#" register (AArch64/RISC-V only)">;
 
+def mlr_for_calls_only : Flag<["-"], "mlr-for-calls-only">, 
Group,
+  HelpText<"Do not allocate the LR register for general purpose usage, only 
for calls. (AArch64 only)">;
+
 foreach i = {8-15,18} in
   def fcall_saved_x#i : Flag<["-"], "fcall-saved-x"#i>, 
Group,
 HelpText<"Make the x"#i#" register call-saved (AArch64 only)">;
diff --git a/clang/include/clang/Driver/aarch64-mlr-for-calls-only.c 
b/clang/include/clang/Driver/aarch64-mlr-for-calls-only.c
new file mode 100644
index 0..1fe3bdab4f3e4
--- /dev/null
+++ b/clang/include/clang/Driver/aarch64-mlr-for-calls-only.c
@@ -0,0 +1,4 @@
+
+// RUN: %clang --target=aarch64-none-gnu -mlr-for-calls-only -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK < %t %s
+// CHECK: "-target-feature" "+reserve-lr-for-ra"
diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index ec248b80251ea..5fbf38cdda12b 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -398,6 +398,9 @@ void aarch64::getAArch64TargetFeatures(const Driver ,
   if (Args.hasArg(options::OPT_ffixed_x28))
 Features.push_back("+reserve-x28");
 
+  if (Args.hasArg(options::OPT_mlr_for_calls_only))
+Features.push_back("+reserve-lr-for-ra");
+
   if (Args.hasArg(options::OPT_fcall_saved_x8))
 Features.push_back("+call-saved-x8");
 
diff --git a/llvm/lib/Target/AArch64/AArch64Features.td 
b/llvm/lib/Target/AArch64/AArch64Features.td
index 8754ea4974999..50ff25ff1ba0c 100644
--- a/llvm/lib/Target/AArch64/AArch64Features.td
+++ b/llvm/lib/Target/AArch64/AArch64Features.td
@@ -571,6 +571,10 @@ foreach i = {1-7,9-15,18,20-28} in
  "Reserve X"#i#", making it 
unavailable "
  "as a GPR">;
 
+def FeatureReserveLRForRA : SubtargetFeature<"reserve-lr-for-ra",
+ "ReserveLRForRA", "true",
+ "Reserve LR for call use only">;
+
 foreach i = {8-15,18} in
 def FeatureCallSavedX#i : SubtargetFeature<"call-saved-x"#i,
  "CustomCallSavedXRegs["#i#"]", "true", "Make X"#i#" callee saved.">;
diff --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
index 75e89e8222ae9..c760d29e9d138 100644
--- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
@@ -3267,10 +3267,13 @@ bool AArch64FrameLowering::spillCalleeSavedRegisters(
 InsertSEH(MIB, TII, MachineInstr::FrameSetup);
 } else { // The code when the pair of ZReg is not present
   MachineInstrBuilder MIB = BuildMI(MBB, MI, DL, TII.get(StrOpc));
-  if (!MRI.isReserved(Reg1))
+  const AArch64RegisterInfo *RegInfo =
+  static_cast(
+  MF.getSubtarget().getRegisterInfo());
+  if (!RegInfo->isStrictlyReservedReg(MF, Reg1))
 

[clang] [clang][doc] Improve error handling for `LibTooling` example code avoiding core dump (PR #98129)

2024-07-09 Thread nick huang via cfe-commits

nickhuang99 wrote:

> @nickhuang99 Could you land this for me?

Sure. Do I need to do anything?

https://github.com/llvm/llvm-project/pull/98129
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

2024-07-09 Thread Joshua Batista via cfe-commits


@@ -0,0 +1,104 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - 
-fsyntax-only %s -verify
+
+// TODO: Implement "Buffer"
+struct Eg1 {
+  float f;
+  // Buffer Buf;
+  RWBuffer RWBuf;
+  };
+Eg1 e1 : /* register(t0) :*/ register(u0); 
+// Valid: f is skipped, Buf is bound to t0, RWBuf is bound to u0
+
+
+struct Eg2 {
+  float f;
+  // Buffer Buf;
+  RWBuffer RWBuf;
+  RWBuffer RWBuf2;
+  };
+Eg2 e2 : /* register(t0) :*/ register(u0); 
+// Valid: f is skipped, Buf is bound to t0, RWBuf is bound to u0. 
+// RWBuf2 gets automatically assigned to u1 even though there is no explicit 
binding for u1.
+
+/*
+struct Eg3 {
+  float f;
+  // Buffer Buf;
+  }; 
+Eg3 e3 : register(t0) : register(u0);
+// Valid: Buf gets bound to t0. Buf will also be bound to u0.
+*/
+
+struct Eg4 {
+  struct Bar {
+RWBuffer a;
+};
+Bar b;
+};
+Eg4 e4 : register(u0);
+// Valid: Bar, the struct within Eg4, has a valid resource that can be bound 
to t0. 
+
+/* Light up this test when SamplerState is implemented
+struct Eg5 {
+  SamplerState s[3];
+};
+
+Eg5 e5 : register(s5);
+// Valid: the first sampler state object within Eg5's s is bound to slot 5
+*/
+
+struct Eg6 {
+  float f;
+}; 
+// expected-warning@+1{{variable of type 'Eg6' bound to register type 't' does 
not contain a matching 'srv' resource}}
+Eg6 e6 : register(t0);
+
+struct Eg7 {
+  struct Bar {
+float f;
+  };
+  Bar b;
+};
+// expected-warning@+1{{variable of type 'Eg7' bound to register type 't' does 
not contain a matching 'srv' resource}}
+Eg7 e7 : register(t0);
+
+struct Eg8 {
+  RWBuffer a;
+}; 
+// expected-warning@+1{{register 'c' used on type with no contents to allocate 
in a constant buffer}}
+Eg8 e8 : register(c0);
+
+
+struct Eg9{
+  // expected-error@+1{{'register' attribute only applies to cbuffer/tbuffer 
and external global variables}}
+  RWBuffer a : register(u9);
+};
+
+Eg9 e9;
+
+
+/* Light up this test when Texture2D is implemented
+template
+struct Eg10 {
+R b;
+};
+// expecting warning: {{variable of type 'Eg10' bound to register type 'u' 
does not contain a matching 'uav' resource}}
+Eg10 e10 : register(u0);
+
+// invalid because after template expansion, there are no valid resources 
inside Eg10 to bind as a UAV.
+*/ 
+
+struct Eg11{
+  RWBuffer a;
+  RWBuffer b;
+};
+
+// expected-error@+1{{conflicting register annotations: multiple register 
numbers detected for register type 'u'}}
+Eg11 e11 : register(u9) : register(u10);

bob80905 wrote:

After some online discussion, I've changed it so that any 2 annotations with 
the same register type on the same decl will conflict.

https://github.com/llvm/llvm-project/pull/97103
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [msan] Precommit MSan Arm NEON vst tests (PR #98247)

2024-07-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Thurston Dang (thurstond)


Changes

These tests show that MSan currently does not handle vst (or vld) correctly.

---

Patch is 1.22 MiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/98247.diff


2 Files Affected:

- (added) clang/test/CodeGen/aarch64-neon-intrinsics-msan-vst.c (+1250) 
- (added) clang/test/CodeGen/aarch64-neon-intrinsics-msan.c (+18071) 


``diff
diff --git a/clang/test/CodeGen/aarch64-neon-intrinsics-msan-vst.c 
b/clang/test/CodeGen/aarch64-neon-intrinsics-msan-vst.c
new file mode 100644
index 0..c0cfe093a1a18
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-neon-intrinsics-msan-vst.c
@@ -0,0 +1,1250 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
+// RUN: -S \
+// RUN:  -emit-llvm -o - %s -fsanitize=memory \
+// RUN: | FileCheck %s
+
+// REQUIRES: aarch64-registered-target || arm-registered-target
+
+#include 
+#include 
+
+// CHECK-LABEL: define dso_local noundef i32 @test_vst1(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:call void @llvm.donothing()
+// CHECK-NEXT:[[__P0_ADDR_I:%.*]] = alloca i16, align 2
+// CHECK-NEXT:[[TMP0:%.*]] = ptrtoint ptr [[__P0_ADDR_I]] to i64
+// CHECK-NEXT:[[TMP1:%.*]] = xor i64 [[TMP0]], 193514046488576
+// CHECK-NEXT:[[TMP2:%.*]] = inttoptr i64 [[TMP1]] to ptr
+// CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 2 [[TMP2]], i8 -1, 
i64 2, i1 false)
+// CHECK-NEXT:[[__RET_I:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:[[DOTCOMPOUNDLITERAL_I:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:[[TMP3:%.*]] = ptrtoint ptr [[DOTCOMPOUNDLITERAL_I]] to i64
+// CHECK-NEXT:[[TMP4:%.*]] = xor i64 [[TMP3]], 193514046488576
+// CHECK-NEXT:[[TMP5:%.*]] = inttoptr i64 [[TMP4]] to ptr
+// CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 16 [[TMP5]], i8 -1, 
i64 16, i1 false)
+// CHECK-NEXT:[[VEC1:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:[[DST1:%.*]] = alloca [8 x i16], align 2
+// CHECK-NEXT:[[__S1:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:[[SUM:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[I:%.*]] = alloca i32, align 4
+// CHECK-NEXT:call void @llvm.lifetime.start.p0(i64 16, ptr [[VEC1]]) 
#[[ATTR4:[0-9]+]]
+// CHECK-NEXT:[[TMP6:%.*]] = ptrtoint ptr [[VEC1]] to i64
+// CHECK-NEXT:[[TMP7:%.*]] = xor i64 [[TMP6]], 193514046488576
+// CHECK-NEXT:[[TMP8:%.*]] = inttoptr i64 [[TMP7]] to ptr
+// CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 16 [[TMP8]], i8 -1, 
i64 16, i1 false)
+// CHECK-NEXT:[[TMP9:%.*]] = ptrtoint ptr [[__P0_ADDR_I]] to i64
+// CHECK-NEXT:[[TMP10:%.*]] = xor i64 [[TMP9]], 193514046488576
+// CHECK-NEXT:[[TMP11:%.*]] = inttoptr i64 [[TMP10]] to ptr
+// CHECK-NEXT:store i16 0, ptr [[TMP11]], align 2
+// CHECK-NEXT:store i16 15, ptr [[__P0_ADDR_I]], align 2
+// CHECK-NEXT:call void @llvm.lifetime.start.p0(i64 16, ptr [[__RET_I]]) 
#[[ATTR4]]
+// CHECK-NEXT:[[TMP12:%.*]] = ptrtoint ptr [[__RET_I]] to i64
+// CHECK-NEXT:[[TMP13:%.*]] = xor i64 [[TMP12]], 193514046488576
+// CHECK-NEXT:[[TMP14:%.*]] = inttoptr i64 [[TMP13]] to ptr
+// CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 16 [[TMP14]], i8 -1, 
i64 16, i1 false)
+// CHECK-NEXT:[[TMP15:%.*]] = load i16, ptr [[__P0_ADDR_I]], align 2
+// CHECK-NEXT:[[TMP16:%.*]] = ptrtoint ptr [[__P0_ADDR_I]] to i64
+// CHECK-NEXT:[[TMP17:%.*]] = xor i64 [[TMP16]], 193514046488576
+// CHECK-NEXT:[[TMP18:%.*]] = inttoptr i64 [[TMP17]] to ptr
+// CHECK-NEXT:[[_MSLD:%.*]] = load i16, ptr [[TMP18]], align 2
+// CHECK-NEXT:[[_MSPROP:%.*]] = insertelement <8 x i16> , i16 [[_MSLD]], i32 0
+// CHECK-NEXT:[[VECINIT_I:%.*]] = insertelement <8 x i16> poison, i16 
[[TMP15]], i32 0
+// CHECK-NEXT:[[TMP19:%.*]] = load i16, ptr [[__P0_ADDR_I]], align 2
+// CHECK-NEXT:[[TMP20:%.*]] = ptrtoint ptr [[__P0_ADDR_I]] to i64
+// CHECK-NEXT:[[TMP21:%.*]] = xor i64 [[TMP20]], 193514046488576
+// CHECK-NEXT:[[TMP22:%.*]] = inttoptr i64 [[TMP21]] to ptr
+// CHECK-NEXT:[[_MSLD2:%.*]] = load i16, ptr [[TMP22]], align 2
+// CHECK-NEXT:[[_MSPROP3:%.*]] = insertelement <8 x i16> [[_MSPROP]], i16 
[[_MSLD2]], i32 1
+// CHECK-NEXT:[[VECINIT1_I:%.*]] = insertelement <8 x i16> [[VECINIT_I]], 
i16 [[TMP19]], i32 1
+// CHECK-NEXT:[[TMP23:%.*]] = load i16, ptr [[__P0_ADDR_I]], align 2
+// CHECK-NEXT:[[TMP24:%.*]] = ptrtoint ptr [[__P0_ADDR_I]] to i64
+// CHECK-NEXT:[[TMP25:%.*]] = xor i64 [[TMP24]], 193514046488576
+// CHECK-NEXT:[[TMP26:%.*]] = inttoptr i64 [[TMP25]] to ptr
+// CHECK-NEXT:[[_MSLD4:%.*]] = load i16, ptr [[TMP26]], align 2
+// CHECK-NEXT:[[_MSPROP5:%.*]] = insertelement <8 x i16> [[_MSPROP3]], i16 
[[_MSLD4]], i32 2
+// 

[clang] [libcxx] [Clang] Implement resolution for CWG1835 (PR #92957)

2024-07-09 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`ppc64le-lld-multistage-test` running on `ppc64le-lld-multistage-test` while 
building `clang,libcxx` at step 12 "build-stage2-unified-tree".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/168/builds/862

Here is the relevant piece of the build log for the reference:
```
Step 12 (build-stage2-unified-tree) failure: build (failure)
...
0.387 [5813/305/51] Generating ../../../../share/scan-view/startfile.py
0.417 [5813/304/52] Creating export file for BugpointPasses
0.418 [5813/303/53] Creating export file for Remarks
0.422 [5813/302/54] Building C object 
lib/Support/CMakeFiles/LLVMSupport.dir/regerror.c.o
0.501 [5813/301/55] Building C object utils/count/CMakeFiles/count.dir/count.c.o
1.233 [5813/300/56] Building CXX object 
lib/Support/CMakeFiles/LLVMSupport.dir/MathExtras.cpp.o
1.250 [5813/299/57] Building CXX object 
unittests/Support/DynamicLibrary/CMakeFiles/DynamicLibraryLib.dir/ExportedFuncs.cpp.o
1.277 [5812/299/58] Linking CXX static library lib/libDynamicLibraryLib.a
1.472 [5812/298/59] Building CXX object 
third-party/benchmark/src/CMakeFiles/benchmark.dir/check.cc.o
1.504 [5812/297/60] Building CXX object 
lib/Support/CMakeFiles/LLVMSupport.dir/SHA1.cpp.o
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/SHA1.cpp.o 
ccache 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/install/stage1/bin/clang++
 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage2/lib/Support
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/lib/Support
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage2/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Werror=global-constructors -O3 -DNDEBUG 
-std=c++17 -UNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -MD -MT 
lib/Support/CMakeFiles/LLVMSupport.dir/SHA1.cpp.o -MF 
lib/Support/CMakeFiles/LLVMSupport.dir/SHA1.cpp.o.d -o 
lib/Support/CMakeFiles/LLVMSupport.dir/SHA1.cpp.o -c 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/lib/Support/SHA1.cpp
In file included from 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/lib/Support/SHA1.cpp:18:
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:463:13:
 error: use 'template' keyword to treat 'MutableArrayRef' as a dependent 
template name [-Werror]
  463 |   this->MutableArrayRef::operator=(Other);
  | ^
  | template 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:464:13:
 error: use 'template' keyword to treat 'MutableArrayRef' as a dependent 
template name [-Werror]
  464 |   Other.MutableArrayRef::operator=(MutableArrayRef());
  | ^
  | template 
2 errors generated.
1.549 [5812/296/61] Building CXX object 
lib/Support/CMakeFiles/LLVMSupport.dir/FormattedStream.cpp.o
1.599 [5812/295/62] Building CXX object 
lib/DebugInfo/CodeView/CMakeFiles/LLVMDebugInfoCodeView.dir/Line.cpp.o
1.604 [5812/294/63] Building CXX object 
lib/Support/CMakeFiles/LLVMSupport.dir/Errno.cpp.o
1.692 [5812/293/64] Building C object 
lib/Support/BLAKE3/CMakeFiles/LLVMSupportBlake3.dir/blake3.c.o
1.710 [5812/292/65] Building CXX object 
third-party/benchmark/src/CMakeFiles/benchmark_main.dir/benchmark_main.cc.o
1.749 [5812/291/66] Building CXX object 
unittests/Support/DynamicLibrary/CMakeFiles/PipSqueak.dir/PipSqueak.cpp.o
1.782 [5812/290/67] Building CXX object 
lib/Support/CMakeFiles/LLVMSupport.dir/UnicodeNameToCodepointGenerated.cpp.o
1.805 [5812/289/68] Building CXX object 
lib/Demangle/CMakeFiles/LLVMDemangle.dir/Demangle.cpp.o
1.826 [5812/288/69] Building CXX object 
lib/Support/CMakeFiles/LLVMSupport.dir/BuryPointer.cpp.o
1.856 

[clang] [llvm] demangle function names in trace files (PR #87626)

2024-07-09 Thread via cfe-commits

Trass3r wrote:

@jamieschmeiser ping

https://github.com/llvm/llvm-project/pull/87626
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Add ability to list extensions enabled for a target (PR #98207)

2024-07-09 Thread Craig Topper via cfe-commits


@@ -116,6 +115,44 @@ void llvm::riscvExtensionsHelp(StringMap 
DescMap) {
 "For example, clang -march=rv32i_v1p0\n";
 }
 
+void RISCVISAInfo::printEnabledExtensions(
+bool IsRV64, std::set ,
+StringMap ) {
+  outs() << "Extensions enabled for the given RISC-V target\n\n";
+  PrintExtension("Name", "Version", (DescMap.empty() ? "" : "Description"));
+
+  RISCVISAUtils::OrderedExtensionMap FullExtMap;
+  RISCVISAUtils::OrderedExtensionMap ExtMap;
+  for (const auto  : SupportedExtensions)
+if (EnabledFeatureNames.count(E.Name) != 0) {
+  FullExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+  ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+}
+  for (const auto  : ExtMap) {
+std::string Version =
+std::to_string(E.second.Major) + "." + std::to_string(E.second.Minor);
+PrintExtension(E.first, Version, DescMap[E.first]);
+  }
+
+  outs() << "\nExperimental extensions\n";
+  ExtMap.clear();
+  for (const auto  : SupportedExperimentalExtensions) {
+StringRef Name(E.Name);
+if (EnabledFeatureNames.count("experimental-" + Name.str()) != 0) {
+  FullExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+  ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+}
+  }
+  for (const auto  : ExtMap) {
+std::string Version =
+std::to_string(E.second.Major) + "." + std::to_string(E.second.Minor);
+PrintExtension(E.first, Version, DescMap["experimental-" + E.first]);
+  }
+
+  unsigned XLen = IsRV64 ? 64 : 32;
+  outs() << "\nISA String: " << RISCVISAInfo(XLen, FullExtMap).toString();

topperc wrote:

I'm going to remove this RISCVISAInfo constructor in factor of a new static 
function in RISCVISAInfo. It's only used in lld before this patch and I don't 
like the division of responsibilities there.

https://github.com/llvm/llvm-project/pull/98207
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CGRecordLayout] Remove dependency on isZeroSize (PR #96422)

2024-07-09 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/96422

>From 07e603f7afc98e5af31962a5b1f44f4e4c079ebb Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 21 Jun 2024 12:15:07 +0100
Subject: [PATCH 01/12] [clang][CGRecordLayout] Remove dependency on isZeroSize

This is a follow-up from the conversation starting at
https://github.com/llvm/llvm-project/pull/93809#issuecomment-2173729801

The root problem that motivated the change are external AST
sources that compute `ASTRecordLayout`s themselves instead of
letting Clang compute them from the AST. One such examples is
LLDB using DWARF to get the definitive offsets and sizes of C++
structures. Such layouts should be considered correct (modulo
buggy DWARF), but various assertions and lowering logic around
the `CGRecordLayoutBuilder` relies on the AST having
`[[no_unique_address]]` attached to them. This is a layout-altering
attribute which is not encoded in DWARF. This causes us LLDB to trip
over the various LLVM<->Clang layout consistency checks. There has been
precedent for avoiding such layout-altering attributes to affect
lowering with externally-provided layouts (e.g., packed structs).

This patch proposes to replace the `isZeroSize` checks in
`CGRecordLayoutBuilder` (which roughly means "empty field
with [[no_unique_address]]") with checks for
`CodeGen::isEmptyField`/`CodeGen::isEmptyRecord`.
---
 clang/lib/CodeGen/ABIInfoImpl.cpp |  6 ++---
 clang/lib/CodeGen/ABIInfoImpl.h   |  6 ++---
 clang/lib/CodeGen/CGExpr.cpp  |  3 ++-
 clang/lib/CodeGen/CGRecordLayoutBuilder.cpp   | 14 ++--
 clang/test/CodeGen/X86/x86_64-vaarg.c |  3 ++-
 clang/test/CodeGen/debug-info-packed-struct.c |  2 +-
 clang/test/CodeGen/paren-list-agg-init.cpp| 15 +
 .../CodeGenCXX/2011-12-19-init-list-ctor.cpp  |  6 ++---
 clang/test/CodeGenCXX/auto-var-init.cpp   | 10 -
 .../test/CodeGenCXX/bitfield-access-empty.cpp | 16 +++---
 clang/test/CodeGenCXX/class-layout.cpp|  2 +-
 clang/test/CodeGenCXX/compound-literals.cpp   |  2 +-
 clang/test/CodeGenCXX/exceptions.cpp  |  7 +++---
 .../lambda-deterministic-captures.cpp |  4 +---
 clang/test/CodeGenCXX/ms_struct.cpp   |  4 +---
 clang/test/CodeGenCXX/partial-destruction.cpp | 11 --
 clang/test/CodeGenCXX/pr18962.cpp |  5 ++---
 clang/test/CodeGenCXX/references.cpp  |  4 +---
 clang/test/CodeGenCXX/temporaries.cpp | 12 +-
 clang/test/CodeGenObjCXX/lambda-to-block.mm   |  9 
 clang/test/OpenMP/irbuilder_for_iterator.cpp  | 10 -
 clang/test/OpenMP/irbuilder_for_rangefor.cpp  | 14 +---
 .../test/OpenMP/task_member_call_codegen.cpp  | 22 ---
 clang/test/Sema/ms_class_layout.cpp   | 14 ++--
 24 files changed, 85 insertions(+), 116 deletions(-)

diff --git a/clang/lib/CodeGen/ABIInfoImpl.cpp 
b/clang/lib/CodeGen/ABIInfoImpl.cpp
index e9a26abb77837..92fcc3bc2c5f4 100644
--- a/clang/lib/CodeGen/ABIInfoImpl.cpp
+++ b/clang/lib/CodeGen/ABIInfoImpl.cpp
@@ -248,7 +248,7 @@ Address CodeGen::emitMergePHI(CodeGenFunction , Address 
Addr1,
   return Address(PHI, Addr1.getElementType(), Align);
 }
 
-bool CodeGen::isEmptyField(ASTContext , const FieldDecl *FD,
+bool CodeGen::isEmptyField(const ASTContext , const FieldDecl *FD,
bool AllowArrays, bool AsIfNoUniqueAddr) {
   if (FD->isUnnamedBitField())
 return true;
@@ -289,8 +289,8 @@ bool CodeGen::isEmptyField(ASTContext , const 
FieldDecl *FD,
   return isEmptyRecord(Context, FT, AllowArrays, AsIfNoUniqueAddr);
 }
 
-bool CodeGen::isEmptyRecord(ASTContext , QualType T, bool AllowArrays,
-bool AsIfNoUniqueAddr) {
+bool CodeGen::isEmptyRecord(const ASTContext , QualType T,
+bool AllowArrays, bool AsIfNoUniqueAddr) {
   const RecordType *RT = T->getAs();
   if (!RT)
 return false;
diff --git a/clang/lib/CodeGen/ABIInfoImpl.h b/clang/lib/CodeGen/ABIInfoImpl.h
index 92986fb431646..e3f373e39c35a 100644
--- a/clang/lib/CodeGen/ABIInfoImpl.h
+++ b/clang/lib/CodeGen/ABIInfoImpl.h
@@ -126,15 +126,15 @@ Address emitMergePHI(CodeGenFunction , Address Addr1,
 /// is an unnamed bit-field or an (array of) empty record(s). If
 /// AsIfNoUniqueAddr is true, then C++ record fields are considered empty if
 /// the [[no_unique_address]] attribute would have made them empty.
-bool isEmptyField(ASTContext , const FieldDecl *FD, bool AllowArrays,
-  bool AsIfNoUniqueAddr = false);
+bool isEmptyField(const ASTContext , const FieldDecl *FD,
+  bool AllowArrays, bool AsIfNoUniqueAddr = false);
 
 /// isEmptyRecord - Return true iff a structure contains only empty
 /// fields. Note that a structure with a flexible array member is not
 /// considered empty. If AsIfNoUniqueAddr is true, then C++ record fields are
 /// considered empty if the 

[clang] [C23] Add *_NORM_MAX macros to (PR #96643)

2024-07-09 Thread Hubert Tong via cfe-commits


@@ -113,7 +113,11 @@ static T PickFP(const llvm::fltSemantics *Sem, T 
IEEEHalfVal, T IEEESingleVal,
 
 static void DefineFloatMacros(MacroBuilder , StringRef Prefix,
   const llvm::fltSemantics *Sem, StringRef Ext) {
-  const char *DenormMin, *Epsilon, *Max, *Min;
+  const char *DenormMin, *NormMax, *Epsilon, *Max, *Min;
+  NormMax = PickFP(Sem, "6.5504e+4", "3.40282347e+38",
+   "1.7976931348623157e+308", "1.18973149535723176502e+4932",
+   "1.79769313486231580793728971405301e+308",

hubert-reinterpretcast wrote:

Yes, the value is correct for an interpretation where the `LDBL_MANT_DIG` is 
106.

https://github.com/llvm/llvm-project/pull/96643
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [Clang] Implement resolution for CWG1835 (PR #92957)

2024-07-09 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian closed 
https://github.com/llvm/llvm-project/pull/92957
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CGRecordLayout] Remove dependency on isZeroSize (PR #96422)

2024-07-09 Thread Michael Buch via cfe-commits


@@ -1,7 +1,17 @@
-// RUN: %clang_cc1 -emit-llvm < %s | grep "zeroinitializer, i16 16877"
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
 // PR4390
 struct sysfs_dirent {
- union { struct sysfs_elem_dir {} s_dir; };
+ union { struct sysfs_elem_dir { int x; } s_dir; };
  unsigned short s_mode;
 };
 struct sysfs_dirent sysfs_root = { {}, 16877 };
+
+// CHECK: @sysfs_root = global %struct.sysfs_dirent { %union.anon 
zeroinitializer, i16 16877 }
+
+struct Foo {
+ union { struct empty {} x; };
+ unsigned short s_mode;

Michael137 wrote:

Yup, can confirm that as C++ we'd get:
```
%struct.sysfs_dirent = type { [2 x i8], i16 }   
 

 
@sysfs_root = global %struct.sysfs_dirent { [2 x i8] undef, i16 16877 }, align 
2 
```

https://github.com/llvm/llvm-project/pull/96422
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CGRecordLayout] Remove dependency on isZeroSize (PR #96422)

2024-07-09 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/96422

>From 07e603f7afc98e5af31962a5b1f44f4e4c079ebb Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 21 Jun 2024 12:15:07 +0100
Subject: [PATCH 01/11] [clang][CGRecordLayout] Remove dependency on isZeroSize

This is a follow-up from the conversation starting at
https://github.com/llvm/llvm-project/pull/93809#issuecomment-2173729801

The root problem that motivated the change are external AST
sources that compute `ASTRecordLayout`s themselves instead of
letting Clang compute them from the AST. One such examples is
LLDB using DWARF to get the definitive offsets and sizes of C++
structures. Such layouts should be considered correct (modulo
buggy DWARF), but various assertions and lowering logic around
the `CGRecordLayoutBuilder` relies on the AST having
`[[no_unique_address]]` attached to them. This is a layout-altering
attribute which is not encoded in DWARF. This causes us LLDB to trip
over the various LLVM<->Clang layout consistency checks. There has been
precedent for avoiding such layout-altering attributes to affect
lowering with externally-provided layouts (e.g., packed structs).

This patch proposes to replace the `isZeroSize` checks in
`CGRecordLayoutBuilder` (which roughly means "empty field
with [[no_unique_address]]") with checks for
`CodeGen::isEmptyField`/`CodeGen::isEmptyRecord`.
---
 clang/lib/CodeGen/ABIInfoImpl.cpp |  6 ++---
 clang/lib/CodeGen/ABIInfoImpl.h   |  6 ++---
 clang/lib/CodeGen/CGExpr.cpp  |  3 ++-
 clang/lib/CodeGen/CGRecordLayoutBuilder.cpp   | 14 ++--
 clang/test/CodeGen/X86/x86_64-vaarg.c |  3 ++-
 clang/test/CodeGen/debug-info-packed-struct.c |  2 +-
 clang/test/CodeGen/paren-list-agg-init.cpp| 15 +
 .../CodeGenCXX/2011-12-19-init-list-ctor.cpp  |  6 ++---
 clang/test/CodeGenCXX/auto-var-init.cpp   | 10 -
 .../test/CodeGenCXX/bitfield-access-empty.cpp | 16 +++---
 clang/test/CodeGenCXX/class-layout.cpp|  2 +-
 clang/test/CodeGenCXX/compound-literals.cpp   |  2 +-
 clang/test/CodeGenCXX/exceptions.cpp  |  7 +++---
 .../lambda-deterministic-captures.cpp |  4 +---
 clang/test/CodeGenCXX/ms_struct.cpp   |  4 +---
 clang/test/CodeGenCXX/partial-destruction.cpp | 11 --
 clang/test/CodeGenCXX/pr18962.cpp |  5 ++---
 clang/test/CodeGenCXX/references.cpp  |  4 +---
 clang/test/CodeGenCXX/temporaries.cpp | 12 +-
 clang/test/CodeGenObjCXX/lambda-to-block.mm   |  9 
 clang/test/OpenMP/irbuilder_for_iterator.cpp  | 10 -
 clang/test/OpenMP/irbuilder_for_rangefor.cpp  | 14 +---
 .../test/OpenMP/task_member_call_codegen.cpp  | 22 ---
 clang/test/Sema/ms_class_layout.cpp   | 14 ++--
 24 files changed, 85 insertions(+), 116 deletions(-)

diff --git a/clang/lib/CodeGen/ABIInfoImpl.cpp 
b/clang/lib/CodeGen/ABIInfoImpl.cpp
index e9a26abb77837..92fcc3bc2c5f4 100644
--- a/clang/lib/CodeGen/ABIInfoImpl.cpp
+++ b/clang/lib/CodeGen/ABIInfoImpl.cpp
@@ -248,7 +248,7 @@ Address CodeGen::emitMergePHI(CodeGenFunction , Address 
Addr1,
   return Address(PHI, Addr1.getElementType(), Align);
 }
 
-bool CodeGen::isEmptyField(ASTContext , const FieldDecl *FD,
+bool CodeGen::isEmptyField(const ASTContext , const FieldDecl *FD,
bool AllowArrays, bool AsIfNoUniqueAddr) {
   if (FD->isUnnamedBitField())
 return true;
@@ -289,8 +289,8 @@ bool CodeGen::isEmptyField(ASTContext , const 
FieldDecl *FD,
   return isEmptyRecord(Context, FT, AllowArrays, AsIfNoUniqueAddr);
 }
 
-bool CodeGen::isEmptyRecord(ASTContext , QualType T, bool AllowArrays,
-bool AsIfNoUniqueAddr) {
+bool CodeGen::isEmptyRecord(const ASTContext , QualType T,
+bool AllowArrays, bool AsIfNoUniqueAddr) {
   const RecordType *RT = T->getAs();
   if (!RT)
 return false;
diff --git a/clang/lib/CodeGen/ABIInfoImpl.h b/clang/lib/CodeGen/ABIInfoImpl.h
index 92986fb431646..e3f373e39c35a 100644
--- a/clang/lib/CodeGen/ABIInfoImpl.h
+++ b/clang/lib/CodeGen/ABIInfoImpl.h
@@ -126,15 +126,15 @@ Address emitMergePHI(CodeGenFunction , Address Addr1,
 /// is an unnamed bit-field or an (array of) empty record(s). If
 /// AsIfNoUniqueAddr is true, then C++ record fields are considered empty if
 /// the [[no_unique_address]] attribute would have made them empty.
-bool isEmptyField(ASTContext , const FieldDecl *FD, bool AllowArrays,
-  bool AsIfNoUniqueAddr = false);
+bool isEmptyField(const ASTContext , const FieldDecl *FD,
+  bool AllowArrays, bool AsIfNoUniqueAddr = false);
 
 /// isEmptyRecord - Return true iff a structure contains only empty
 /// fields. Note that a structure with a flexible array member is not
 /// considered empty. If AsIfNoUniqueAddr is true, then C++ record fields are
 /// considered empty if the 

[clang] [llvm] [PAC][Driver] Implement `-mbranch-protection=pauthabi` option (PR #97237)

2024-07-09 Thread Peter Smith via cfe-commits

smithp35 wrote:

Apologies for the length of the post, it could probably do with more revisions 
and research but I thought it better to send what I have and refine later after 
comments. Most of this is a summation of a discussion had in the PAuthABI call, 
followed by my attempts at analysing the options we discussed. My apologies if 
I've misrepresented or missed out anything in the call. Please feel free to 
correct me where I'm wrong or have missed something out. I'll be at a 
conference this week so I may be slow to respond.

 Known use cases and background.

We have three known use cases for PAuthABI, with two in active development:
* A platform either ELF or MachO based deploys PAuthABI in all or, most likely, 
a subset of programs.
* A bare-metal system that can statically compile everything the same way for 
the device. This not in active development.
* Enabling PAuthABI for testing in upstream LLVM.

On each of the platforms, there is expected to be more than onesigning schema, 
for example kernel vs user-space. With the possible exception of return address 
signing, each signing schema is its own ABI. While low-level options may exist 
to control the signing schema, we do not expect end users to use them as they 
risk breaking the platform ABI.

This infers that we need an option to choose between high-level signing 
schemas, that map to some combination of the low-level options. This mapping 
will need to be per-platform as Linux may choose differently to BSD.

The signing schema will also need to be used as the multilib key so that a 
compatible set of libraries can be linked for the signing schema.

On ELF the (platform, signing-schema) choice can be recorded in the ELF 
properties.

Users of the low-level command line options cannot be easily recorded in the 
ELF properties. There are various platform specific choices that could be made 
if the low-level options are used. For example:
* Record the high-level signing schema and trust the user has written the code 
such that it is compatible.
* Reject the low-level option.
* Ignore the low-level option.
* Record a custom signing schema.

I think that this has to be under control of the platform. My intuition is that 
we trust the user, perhaps with a warning, and
record the high-level signing schema.

On a bare-metal embedded system each toolchain can make up their own signing 
schema, however no toolchain is likely to provide pre-compiled libraries for 
every possible choice so we expect there to be a sensible default signing 
schema.

 Thoughts on `-mbranch-protection=pauthabi`

While pauthabi is a form of CFI like the other mbranch-protection
options there are a number of differences that cause problems:
* All existing `-mbranch-protection` options have a hint space implementation 
so are compatible with any architecture. PAuthABI requires an extension.
* All existing `-mbranch-protection` options are compatible, pauthabi conflicts 
with standard and pac-ret.
* All existing `-mbranch-protection` options are ABI neutral, pauthabi is not 
and any use of it on a standard linux platform would not work.
* Not got an easy way to extend with the signing schema.

### Alternatives discussed

 A single option using -mabi:

Use the existing `-mabi` option to indicate the signing schema (or absence of
signing schema) if pauthabi is not used. The `-mabi` option for AArch64 is
currently permits `aapcs` (default hard-float) `aapcs-soft` and `darwinpcs`.

`-mabi=pauth` // default signing schema for the platform (OS in triple).
`-mabi=pauth` // named signing schema, interpreted per platform.

The  expands to a number of low-level options. This is
determined per platform. With this information we can derive a
 for the ELF marking.

For example:
* `--target=aarch64-none-elf -mabi=pauth`
* `--target=aarch64-linux-gnu -mabi=pauthkernel`

There is an open question over what we should do with the theoretical 
combination of soft-floating point and pauth as these both use the 
`-mabi=` option. While each combination is its own ABI, the choice of 
float-abi is orthogonal to signing schema. I'm leaning towards suggesting a + 
or , separated list for `-mabi` with a default of aapcs (hard-float) so we 
don't end up doubling the number of options. So we would have 
`-mabi=pauth,aapcs-soft` rather than
`-mabi=aapcs-soft-pauth`. I don't think that would need to be 
implemented until there is an actual need for it.

 Two options using -mabi and -msigning-schema:

This is functionally equivalent to the single `-mabi=pauth` 
split into two options.

* `-mabi=pauth enables pauthabi`
* `-msigning-schema=`
if `-msigning-schema` is absent then the default signing schema for the 
platform is used.

This has the advantage of being easier to parse, but has a couple of drawbacks:
* Each `-msigning-schema` is a different ABI so it is logical to have a single 
`-mabi` option with disjoint choices.
* `-msigning-schema` without `-mabi=pauth` is meaningless.

 Use 

[clang] [clang][CGRecordLayout] Remove dependency on isZeroSize (PR #96422)

2024-07-09 Thread Michael Buch via cfe-commits

https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/96422
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CGRecordLayout] Remove dependency on isZeroSize (PR #96422)

2024-07-09 Thread Michael Buch via cfe-commits


@@ -185,6 +203,18 @@ CALL_AO(PackedMembers)
 // CHECK: call void @llvm.memcpy.p0.p0.i64({{.*}} align 1 {{.*}} align 1 
{{.*}}i64 16, i1 {{.*}})
 // CHECK: ret ptr
 
+// WithEmptyField copy-assignment:
+// CHECK-LABEL: define linkonce_odr nonnull align {{[0-9]+}} 
dereferenceable({{[0-9]+}}) ptr @_ZN14WithEmptyFieldaSERKS_
+// CHECK: call void @llvm.memcpy.p0.p0.i64({{.*}} align 4 {{.*}} align 4 
{{.*}}i64 4, i1 {{.*}})

Michael137 wrote:

Uhm yea that would be an ABI break, and I'm not sure how I got to this IR, 
apologies for the confusion. What actually happens is that we get:
```
%struct.WithEmptyField = type { i32, [4 x i8], i32 }
```
which seems fine. The `memcpy` does change from `5` to 4`

https://github.com/llvm/llvm-project/pull/96422
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add `__CLANG_GPU_DISABLE_MATH_WRAPPERS` macro for offloading math (PR #98234)

2024-07-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)


Changes

Summary:
Currently we replace all math calls with vendor specific ones. This
patch introduces a macro `__CLANG_GPU_DISABLE_MATH_WRAPPERS` that when
defined will disable this.

I went this route instead of a flag for two reasons. One, I think we
have too many flags as is, and we already have `-nogpuinc` to cover
disabling these wrappers entirely, so this would be a really specific
subset of that. Second, these math headers aren't easily decoupled by
simply not including a single header from the clang driver layer.
There's the cmath and the regular math forward declares it would disable
as well.

Note, this currently causes errors because the GPU `libm` doesn't have
`powi`, that's an NVIDIA extension I'll add to LLVM libm.


---
Full diff: https://github.com/llvm/llvm-project/pull/98234.diff


2 Files Affected:

- (modified) clang/lib/Headers/__clang_cuda_math.h (+5) 
- (modified) clang/lib/Headers/__clang_hip_math.h (+5) 


``diff
diff --git a/clang/lib/Headers/__clang_cuda_math.h 
b/clang/lib/Headers/__clang_cuda_math.h
index 0401916506866..44c6e9a4e48d1 100644
--- a/clang/lib/Headers/__clang_cuda_math.h
+++ b/clang/lib/Headers/__clang_cuda_math.h
@@ -12,6 +12,10 @@
 #error "This file is for CUDA compilation only."
 #endif
 
+// The __CLANG_GPU_DISABLE_MATH_WRAPPERS macro provides a way to let standard
+// libcalls reach the link step instead of being eagerly replaced.
+#ifndef __CLANG_GPU_DISABLE_MATH_WRAPPERS
+
 #ifndef __OPENMP_NVPTX__
 #if CUDA_VERSION < 9000
 #error This file is intended to be used with CUDA-9+ only.
@@ -345,4 +349,5 @@ __DEVICE__ float ynf(int __a, float __b) { return 
__nv_ynf(__a, __b); }
 #pragma pop_macro("__DEVICE_VOID__")
 #pragma pop_macro("__FAST_OR_SLOW")
 
+#endif // __CLANG_GPU_DISABLE_MATH_WRAPPERS
 #endif // __CLANG_CUDA_MATH_H__
diff --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index 11e1e7d032586..8468751d9de26 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -13,6 +13,10 @@
 #error "This file is for HIP and OpenMP AMDGCN device compilation only."
 #endif
 
+// The __CLANG_GPU_DISABLE_MATH_WRAPPERS macro provides a way to let standard
+// libcalls reach the link step instead of being eagerly replaced.
+#ifndef __CLANG_GPU_DISABLE_MATH_WRAPPERS
+
 #if !defined(__HIPCC_RTC__)
 #include 
 #include 
@@ -1321,4 +1325,5 @@ __host__ inline static int max(int __arg1, int __arg2) {
 #pragma pop_macro("__RETURN_TYPE")
 #pragma pop_macro("__FAST_OR_SLOW")
 
+#endif // __CLANG_GPU_DISABLE_MATH_WRAPPERS
 #endif // __CLANG_HIP_MATH_H__

``




https://github.com/llvm/llvm-project/pull/98234
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add `__CLANG_GPU_DISABLE_MATH_WRAPPERS` macro for offloading math (PR #98234)

2024-07-09 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/98234

Summary:
Currently we replace all math calls with vendor specific ones. This
patch introduces a macro `__CLANG_GPU_DISABLE_MATH_WRAPPERS` that when
defined will disable this.

I went this route instead of a flag for two reasons. One, I think we
have too many flags as is, and we already have `-nogpuinc` to cover
disabling these wrappers entirely, so this would be a really specific
subset of that. Second, these math headers aren't easily decoupled by
simply not including a single header from the clang driver layer.
There's the cmath and the regular math forward declares it would disable
as well.

Note, this currently causes errors because the GPU `libm` doesn't have
`powi`, that's an NVIDIA extension I'll add to LLVM libm.


>From e658e992b04d195e5f398549a40a2278304c7b80 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Tue, 9 Jul 2024 17:17:39 -0500
Subject: [PATCH] [Clang] Add `__CLANG_GPU_DISABLE_MATH_WRAPPERS` macro for
 offloading math

Summary:
Currently we replace all math calls with vendor specific ones. This
patch introduces a macro `__CLANG_GPU_DISABLE_MATH_WRAPPERS` that when
defined will disable this.

I went this route instead of a flag for two reasons. One, I think we
have too many flags as is, and we already have `-nogpuinc` to cover
disabling these wrappers entirely, so this would be a really specific
subset of that. Second, these math headers aren't easily decoupled by
simply not including a single header from the clang driver layer.
There's the cmath and the regular math forward declares it would disable
as well.

Note, this currently causes errors because the GPU `libm` doesn't have
`powi`, that's an NVIDIA extension I'll add to LLVM libm.
---
 clang/lib/Headers/__clang_cuda_math.h | 5 +
 clang/lib/Headers/__clang_hip_math.h  | 5 +
 2 files changed, 10 insertions(+)

diff --git a/clang/lib/Headers/__clang_cuda_math.h 
b/clang/lib/Headers/__clang_cuda_math.h
index 0401916506866..44c6e9a4e48d1 100644
--- a/clang/lib/Headers/__clang_cuda_math.h
+++ b/clang/lib/Headers/__clang_cuda_math.h
@@ -12,6 +12,10 @@
 #error "This file is for CUDA compilation only."
 #endif
 
+// The __CLANG_GPU_DISABLE_MATH_WRAPPERS macro provides a way to let standard
+// libcalls reach the link step instead of being eagerly replaced.
+#ifndef __CLANG_GPU_DISABLE_MATH_WRAPPERS
+
 #ifndef __OPENMP_NVPTX__
 #if CUDA_VERSION < 9000
 #error This file is intended to be used with CUDA-9+ only.
@@ -345,4 +349,5 @@ __DEVICE__ float ynf(int __a, float __b) { return 
__nv_ynf(__a, __b); }
 #pragma pop_macro("__DEVICE_VOID__")
 #pragma pop_macro("__FAST_OR_SLOW")
 
+#endif // __CLANG_GPU_DISABLE_MATH_WRAPPERS
 #endif // __CLANG_CUDA_MATH_H__
diff --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index 11e1e7d032586..8468751d9de26 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -13,6 +13,10 @@
 #error "This file is for HIP and OpenMP AMDGCN device compilation only."
 #endif
 
+// The __CLANG_GPU_DISABLE_MATH_WRAPPERS macro provides a way to let standard
+// libcalls reach the link step instead of being eagerly replaced.
+#ifndef __CLANG_GPU_DISABLE_MATH_WRAPPERS
+
 #if !defined(__HIPCC_RTC__)
 #include 
 #include 
@@ -1321,4 +1325,5 @@ __host__ inline static int max(int __arg1, int __arg2) {
 #pragma pop_macro("__RETURN_TYPE")
 #pragma pop_macro("__FAST_OR_SLOW")
 
+#endif // __CLANG_GPU_DISABLE_MATH_WRAPPERS
 #endif // __CLANG_HIP_MATH_H__

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


[clang] [llvm] [AMDGPU] Report error in clang if wave32 is requested where unsupported (PR #97633)

2024-07-09 Thread Stanislav Mekhanoshin via cfe-commits

rampitec wrote:

> /build/buildbot/premerge-monolithic-linux/llvm-project/flang/lib/Frontend/CompilerInstance.cpp:226:44:
>  error: too many arguments to function call, expected 3, have 4

Fixed.

https://github.com/llvm/llvm-project/pull/97633
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Report error in clang if wave32 is requested where unsupported (PR #97633)

2024-07-09 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `premerge-monolithic-linux` 
running on `premerge-linux-1` while building `clang,llvm` at step 6 
"build-unified-tree".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/153/builds/2433

Here is the relevant piece of the build log for the reference:
```
Step 6 (build-unified-tree) failure: build (failure)
...
16.660 [2956/11/227] Linking CXX executable bin/clang-doc
16.660 [2956/10/228] Linking CXX executable bin/arcmt-test
16.665 [2956/9/229] Linking CXX executable bin/clang-include-cleaner
16.704 [2956/8/230] Linking CXX executable bin/clang-installapi
16.709 [2956/7/231] Linking CXX executable bin/clang-refactor
17.083 [2956/6/232] Linking CXX executable bin/clangd-indexer
17.102 [2956/5/233] Linking CXX executable bin/clangd-fuzzer
17.112 [2956/4/234] Linking CXX executable bin/clang-import-test
17.145 [2956/3/235] Linking CXX executable bin/clangd
28.093 [2956/2/236] Building CXX object 
tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o
FAILED: 
tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o
 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/clang++ 
-DBUILD_EXAMPLES -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 
-DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/build/buildbot/premerge-monolithic-linux/build/tools/flang/lib/Frontend 
-I/build/buildbot/premerge-monolithic-linux/llvm-project/flang/lib/Frontend 
-I/build/buildbot/premerge-monolithic-linux/llvm-project/flang/include 
-I/build/buildbot/premerge-monolithic-linux/build/tools/flang/include 
-I/build/buildbot/premerge-monolithic-linux/build/include 
-I/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include -isystem 
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/../mlir/include 
-isystem /build/buildbot/premerge-monolithic-linux/build/tools/mlir/include 
-isystem /build/buildbot/premerge-monolithic-linux/build/tools/clang/include 
-isystem 
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/../clang/include 
-gmlt -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion 
-Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument 
-Wstring-conversion   -Wcovered-switch-default -Wno-nested-anon-types 
-O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD 
-MT 
tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o
 -MF 
tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o.d
 -o 
tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o
 -c 
/build/buildbot/premerge-monolithic-linux/llvm-project/flang/lib/Frontend/CompilerInstance.cpp
/build/buildbot/premerge-monolithic-linux/llvm-project/flang/lib/Frontend/CompilerInstance.cpp:226:44:
 error: too many arguments to function call, expected 3, have 4
   errorMsg)) {
   ^~~~
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include/llvm/TargetParser/TargetParser.h:187:1:
 note: 'insertWaveSizeFeature' declared here
insertWaveSizeFeature(StringRef GPU, const Triple ,
^
1 error generated.
29.203 [2956/1/237] Building CXX object 
lib/Target/AMDGPU/AsmParser/CMakeFiles/LLVMAMDGPUAsmParser.dir/AMDGPUAsmParser.cpp.o
ninja: build stopped: subcommand failed.

```

https://github.com/llvm/llvm-project/pull/97633
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C2y] Add documentation to conform to WG14 N3262; NFC (PR #98146)

2024-07-09 Thread John McCall via cfe-commits

rjmccall wrote:

> > _Every_ `va_list` stores pointers; otherwise, it wouldn't be able to 
> > support an arbitrary number of arguments. Copying just copies the pointers, 
> > and that's fine because the memory they point to is immutable and always 
> > outlives the `va_list`. You can imagine a `va_list` implementation that 
> > doesn't have these properties, but it's hard.
> 
> But do separate va_list objects within the same function always have the same 
> pointer _values_? I was thinking the "saved state" pointers might actually 
> point to different memory regions to support different restoration points, 
> but I could be way off base there.

The pointer values in a specific `va_list` can and often do change when you 
call `va_arg`, but I am not aware of any targets where they do not always point 
to the same regions.  Every `va_list` ABI I know has a pointer to the stack 
argument area, and those pointers *must* point there because the stack argument 
area cannot be either copied or relocated.  Some ABIs also require certain 
argument registers to be spilled to the stack in the prologue, and then a 
pointer to that spill area (or multiple areas, depending on target) is also 
written into the `va_list`.  In theory, a compiler could produce multiple 
copies of that spill area, or an ABI could require it to be allocate on the 
heap or copied by `va_copy`.  However, there's no good reason to do either of 
those things: the `va_list` can never validly escape the variadic function 
because of the limitation on the stack argument area, and so the spill area 
might as well also go in a unique location on the stack.

> > > I'm not super happy about "this is well-defined if you happen to be on a 
> > > target that makes it well-defined" because there's basically no 
> > > reasonable way for a user to find that information out themselves.
> > 
> > 
> > Well, if we're going to document that this is allowed, we should document 
> > what targets it's allowed on. I'm not arguing that we shouldn't document it.
> 
> I had the unpleasant experience of trying to figure out what targets it's 
> allowed on. We have five links to ABI resources regarding va_list in
> 
> https://github.com/llvm/llvm-project/blob/746f5726158d31aeeb1fd12b226dc869834a7ad2/clang/include/clang/Basic/TargetInfo.h#L319
> 
> ; four of the links are dead and one of the targets is unsupported as of 2022 
> (thus has no documentation whatsoever) but its va_list type continues to be 
> used outside of that target (
> https://github.com/llvm/llvm-project/blob/a1d73ace13a20ed122a66d3d59f0cbae58d0f669/clang/lib/Basic/Targets/Le64.h#L41
> 
> ).
> Given the ease of calling `va_copy`, the fact that C had implicit UB here for 
> ~40 years, and it's going to be a slog to try to nail down every single 
> target's behavior, I still think documenting it as explicit UB is reasonable. 
> If users or target owners want a different behavior, then they could give a 
> use case for why and we could re-assess at that point. All we're effectively 
> saying with that documentation is "if you do it, we don't promise it will 
> work" and we already effectively say that with our existing documentation 
> when we say `It is undefined behavior to call this function with a list that 
> has not been initialized by either __builtin_va_start or __builtin_va_copy.`
> 
> Alternatively, we could document that it's supported on all targets, test 
> whatever codegen Clang emits, assume all the targets support this, and then 
> document any unsupported targets discovered in the wild as explicitly 
> unsupported. I'm a bit less comfortable with that, but when both the codegen 
> code owners tell me they it's very unlikely this _won't_ work on any targets 
> we care about, I can certainly trust that expertise!

I have no objection to requiring `va_copy` and documenting primitive copies as 
undefined behavior.  It is the easiest thing to do, and we can clearly revisit 
it later if we want.

https://github.com/llvm/llvm-project/pull/98146
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   >