[clang] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2 and below (PR #95750)

2024-06-17 Thread Vikash Gupta via cfe-commits

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

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.

>From 04ff7bd289d0840b8aa2b0502e4ac050174c95ab Mon Sep 17 00:00:00 2001
From: vg0204 
Date: Mon, 17 Jun 2024 11:20:02 +0530
Subject: [PATCH] [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 99a8704298314..e12c2a9209706 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 
&Context,
 FunctionDecl *FDecl,
 MultiExprArg ArgExprs) {
@@ -6275,13 +6278,27 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema 
*Sema, ASTContext &Context,
 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

[clang] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2 and below (PR #95750)

2024-06-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vikash Gupta (vg0204)


Changes

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.

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


3 Files Affected:

- (modified) clang/lib/Sema/SemaExpr.cpp (+20-3) 
- (added) clang/test/CodeGenOpenCL/builtins-alloca.cl (+86) 
- (modified) clang/test/CodeGenOpenCL/memcpy.cl () 


``diff
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 99a8704298314..e12c2a9209706 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 
&Context,
 FunctionDecl *FDecl,
 MultiExprArg ArgExprs) {
@@ -6275,13 +6278,27 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema 
*Sema, ASTContext &Context,
 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:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) [[TMP0]] to 
ptr
+// OPENCL20-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], alig

[clang] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2 and below (PR #95750)

2024-06-17 Thread Matt Arsenault via cfe-commits


@@ -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:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) [[TMP0]] to 
ptr
+// OPENCL20-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], align 
8
+// OPENCL20-NEXT:[[TMP2:%.*]] = load ptr, ptr addrspace(5) [[ALLOC_PTR]], 
align 8
+// OPENCL20-NEXT:ret ptr [[TMP2]]
+//
+// OPENCL30-LABEL: define dso_local ptr addrspace(5) @test1(
+// OPENCL30-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL30-NEXT:  [[ENTRY:.*:]]
+// OPENCL30-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL30-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL30-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL30-NEXT:[[TMP1:%.*]] = load ptr addrspace(5), ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL30-NEXT:ret ptr addrspace(5) [[TMP1]]
+//
+// OPENCL30-EXT-LABEL: define dso_local ptr @test1(
+// OPENCL30-EXT-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL30-EXT-NEXT:  [[ENTRY:.*:]]
+// OPENCL30-EXT-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL30-EXT-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, 
addrspace(5)
+// OPENCL30-EXT-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) 
[[TMP0]] to ptr
+// OPENCL30-EXT-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], 
align 8
+// OPENCL30-EXT-NEXT:[[TMP2:%.*]] = load ptr, ptr addrspace(5) 
[[ALLOC_PTR]], align 8
+// OPENCL30-EXT-NEXT:ret ptr [[TMP2]]
+//
+float* test1() {
+float* alloc_ptr = (float*)__builtin_alloca(32 * sizeof(int));

arsenm wrote:

Should test with __private qualified pointer, we want to see that there is no 
cast 

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


[clang] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2 and below (PR #95750)

2024-06-17 Thread Matt Arsenault via cfe-commits


@@ -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:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) [[TMP0]] to 
ptr
+// OPENCL20-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], align 
8
+// OPENCL20-NEXT:[[TMP2:%.*]] = load ptr, ptr addrspace(5) [[ALLOC_PTR]], 
align 8
+// OPENCL20-NEXT:ret ptr [[TMP2]]
+//
+// OPENCL30-LABEL: define dso_local ptr addrspace(5) @test1(
+// OPENCL30-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL30-NEXT:  [[ENTRY:.*:]]
+// OPENCL30-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL30-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL30-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL30-NEXT:[[TMP1:%.*]] = load ptr addrspace(5), ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL30-NEXT:ret ptr addrspace(5) [[TMP1]]
+//
+// OPENCL30-EXT-LABEL: define dso_local ptr @test1(
+// OPENCL30-EXT-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL30-EXT-NEXT:  [[ENTRY:.*:]]
+// OPENCL30-EXT-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL30-EXT-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, 
addrspace(5)
+// OPENCL30-EXT-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) 
[[TMP0]] to ptr
+// OPENCL30-EXT-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], 
align 8
+// OPENCL30-EXT-NEXT:[[TMP2:%.*]] = load ptr, ptr addrspace(5) 
[[ALLOC_PTR]], align 8
+// OPENCL30-EXT-NEXT:ret ptr [[TMP2]]
+//
+float* test1() {
+float* alloc_ptr = (float*)__builtin_alloca(32 * sizeof(int));
+return alloc_ptr;
+}
+
+// OPENCL12-LABEL: define dso_local void @test2(
+// OPENCL12-SAME: ) #[[ATTR0]] {
+// OPENCL12-NEXT:  [[ENTRY:.*:]]
+// OPENCL12-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL12-NEXT:[[TMP0:%.*]] = alloca i8, i64 28, align 8, addrspace(5)
+// OPENCL12-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:ret void
+//
+// OPENCL20-LABEL: define dso_local void @test2(
+// OPENCL20-SAME: ) #[[ATTR0]] {
+// OPENCL20-NEXT:  [[ENTRY:.*:]]
+// OPENCL20-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP0:%.*]] = alloca i8, i64 28, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) [[TMP0]] to 
ptr
+// OPENCL20-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], align 
8
+// OPENCL20-NEXT:ret void
+//
+// OPENCL30-LABEL: define dso_local void @test2(
+// OPENCL30-SAME: ) #[[ATTR0]] {
+// OPENCL30-NEXT:  [[ENTRY:.*:]]
+// OPENCL30-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL30-NEXT:[[TMP0:%.*]] = alloca i8, i64 28, align 8, addrspace(5)
+// OPENCL30-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL30-NEXT:ret void
+//
+// OPENCL30-EXT-LABEL: define dso_local void @test2(
+// OPENCL30-EXT-SAME: ) #[[ATTR0]] {
+// OPENCL30-EXT-NEXT:  [[ENTRY:.*:]]
+// OPENCL30-EXT-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL30-EXT-NEXT:[[TMP0:%.*]] = alloca i8, i64 28, align 8, 
addrspace(5)
+// OPENCL30-EXT-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) 
[[TMP0]] to ptr
+// OPENCL30-EXT-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], 
align 8
+// OPENCL30-EXT-NEXT:ret void
+//
+void test2() {
+void *alloc_ptr = __builtin_alloca(28);

a

[clang] [clang][CodeGen] Add query for a target's flat address space (PR #95728)

2024-06-17 Thread Matt Arsenault via cfe-commits


@@ -1764,6 +1764,13 @@ class TargetInfo : public TransferrableTargetInfo,
 return 0;
   }
 
+  /// \returns Target specific flat ptr address space; a flat ptr is a ptr that
+  /// can be casted to / from all other target address spaces. If the target
+  /// exposes no such address space / does not care, we return 0.

arsenm wrote:

This further spreads the notion that 0 is a lack of address space, which it is 
not. You shouldn't need a new thing for this; it should be equivalent to 
querying the target address space map for the LangAS Generic thing 

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


[clang] [Clang][Sema] Skip checking anonymous enum in using enum declaration (PR #87144)

2024-06-17 Thread Balázs Kéri via cfe-commits

balazske wrote:

I did not get crash with this script and latest clang. Probably there is a 
difference in the used system headers (`iostream` and `string` is included)?

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


[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)

2024-06-17 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,17 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -fsyntax-only -verify -std=gnu++11 -triple amdgcn 
-Wno-unused-value %s
+

arsenm wrote:

We probably want another similar sema test for OpenCL/HIP/OpenMP 

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


[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)

2024-06-17 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,9 @@
+

arsenm wrote:

Extra blank line 

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


[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)

2024-06-17 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,84 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature
+ // REQUIRES: amdgpu-registered-target
+ // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu verde 
-emit-llvm -o - %s | FileCheck %s
+ // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu tonga 
-emit-llvm -o - %s | FileCheck %s
+ // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1100 
-emit-llvm -o - %s | FileCheck %s
+
+typedef struct AA_ty {
+  int x;
+  __amdgcn_buffer_rsrc_t r;
+} AA;
+
+AA getAA(void *p);
+__amdgcn_buffer_rsrc_t getBufferImpl(void *p);
+void consumeBuffer(__amdgcn_buffer_rsrc_t);
+
+// CHECK-LABEL: define {{[^@]+}}@getBuffer

arsenm wrote:

I guess that covers it, but we don't get to see the return attributes now 

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


[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)

2024-06-17 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,84 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature
+ // REQUIRES: amdgpu-registered-target
+ // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu verde 
-emit-llvm -o - %s | FileCheck %s
+ // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu tonga 
-emit-llvm -o - %s | FileCheck %s
+ // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1100 
-emit-llvm -o - %s | FileCheck %s

arsenm wrote:

Not much point in testing all the subtargets here

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


[clang] [llvm] Cleanup MC/DC intrinsics for #82448 (PR #95496)

2024-06-17 Thread via cfe-commits

zmodem wrote:

> Sweep `condbitmap.update`, since it is no longer used.

It's used by Rust: 
https://github.com/rust-lang/rust/blob/fd7eefc2753e867053a1c567a7b504ae308e3f85/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp#L1581

What's the migration path? Could you put something in the release notes for 
other users hitting this?

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


[clang] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2 and below (PR #95750)

2024-06-17 Thread Vikash Gupta via cfe-commits


@@ -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:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) [[TMP0]] to 
ptr
+// OPENCL20-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], align 
8
+// OPENCL20-NEXT:[[TMP2:%.*]] = load ptr, ptr addrspace(5) [[ALLOC_PTR]], 
align 8
+// OPENCL20-NEXT:ret ptr [[TMP2]]
+//
+// OPENCL30-LABEL: define dso_local ptr addrspace(5) @test1(
+// OPENCL30-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL30-NEXT:  [[ENTRY:.*:]]
+// OPENCL30-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL30-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL30-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL30-NEXT:[[TMP1:%.*]] = load ptr addrspace(5), ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL30-NEXT:ret ptr addrspace(5) [[TMP1]]
+//
+// OPENCL30-EXT-LABEL: define dso_local ptr @test1(
+// OPENCL30-EXT-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL30-EXT-NEXT:  [[ENTRY:.*:]]
+// OPENCL30-EXT-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL30-EXT-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, 
addrspace(5)
+// OPENCL30-EXT-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) 
[[TMP0]] to ptr
+// OPENCL30-EXT-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], 
align 8
+// OPENCL30-EXT-NEXT:[[TMP2:%.*]] = load ptr, ptr addrspace(5) 
[[ALLOC_PTR]], align 8
+// OPENCL30-EXT-NEXT:ret ptr [[TMP2]]
+//
+float* test1() {
+float* alloc_ptr = (float*)__builtin_alloca(32 * sizeof(int));

vg0204 wrote:

Currently, I made it as such for opencl1.2 & below, it will return private 
pointer so no cast would be seen if __private qualifier is used. But for 
openCL2.0 & above, it returns a pointer to generic address space, so test2 
becomes problematic as initializing '__private void *__private' with an 
expression of type '__generic void *' changes address space of pointer.

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


[clang] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2 and below (PR #95750)

2024-06-17 Thread Vikash Gupta via cfe-commits


@@ -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:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) [[TMP0]] to 
ptr
+// OPENCL20-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], align 
8
+// OPENCL20-NEXT:[[TMP2:%.*]] = load ptr, ptr addrspace(5) [[ALLOC_PTR]], 
align 8
+// OPENCL20-NEXT:ret ptr [[TMP2]]
+//
+// OPENCL30-LABEL: define dso_local ptr addrspace(5) @test1(
+// OPENCL30-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL30-NEXT:  [[ENTRY:.*:]]
+// OPENCL30-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL30-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL30-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL30-NEXT:[[TMP1:%.*]] = load ptr addrspace(5), ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL30-NEXT:ret ptr addrspace(5) [[TMP1]]
+//
+// OPENCL30-EXT-LABEL: define dso_local ptr @test1(
+// OPENCL30-EXT-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL30-EXT-NEXT:  [[ENTRY:.*:]]
+// OPENCL30-EXT-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL30-EXT-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, 
addrspace(5)
+// OPENCL30-EXT-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) 
[[TMP0]] to ptr
+// OPENCL30-EXT-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], 
align 8
+// OPENCL30-EXT-NEXT:[[TMP2:%.*]] = load ptr, ptr addrspace(5) 
[[ALLOC_PTR]], align 8
+// OPENCL30-EXT-NEXT:ret ptr [[TMP2]]
+//
+float* test1() {
+float* alloc_ptr = (float*)__builtin_alloca(32 * sizeof(int));

vg0204 wrote:

So, should it return __private pointer everytime?

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread Vlad Serebrennikov via cfe-commits


@@ -1145,8 +1145,10 @@ namespace cwg181 { // cwg181: yes
   namespace X {
 template  > struct A { };
 // expected-error@-1 +{{}}
+//  expected-note@-2 {{did you mean to use 'typename'?}}
 template  > void f(A) { }
 // expected-error@-1 +{{}}
+//  expected-note@-2 {{did you mean to use 'typename'?}}

Endilll wrote:

```suggestion
//   expected-note@-2 {{did you mean to use 'typename'?}}
```

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread Vlad Serebrennikov via cfe-commits


@@ -1145,8 +1145,10 @@ namespace cwg181 { // cwg181: yes
   namespace X {
 template  > struct A { };
 // expected-error@-1 +{{}}
+//  expected-note@-2 {{did you mean to use 'typename'?}}

Endilll wrote:

```suggestion
//   expected-note@-2 {{did you mean to use 'typename'?}}
```

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

Changes to DR tests look fine.

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2 and below (PR #95750)

2024-06-17 Thread Vikash Gupta via cfe-commits

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


[clang] [llvm] Cleanup MC/DC intrinsics for #82448 (PR #95496)

2024-06-17 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

@zmodem Thanks for the notification.
I supposed release notes may be updated just before the release. I was 
wondering how I could propagate changes.
I will fill recent changes to Release notes, later.

Re. condbitmap.update, it has become useless after #82448 . I think pruning it 
will be the possible way.

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


[clang] [Debug Info] Fix debug info ptr to ptr test (PR #95637)

2024-06-17 Thread Jeremy Morse via cfe-commits

jmorse wrote:

@huangjd Thanks for the fix -- FYI it's acceptable to commit patches like this 
without review (and leave a comment on the original PR) if you wanted to. Given 
that it's just the format of the test changing, not any of the meaning, it's an 
"obvious" fix.

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


[clang] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2 and below (PR #95750)

2024-06-17 Thread Matt Arsenault via cfe-commits


@@ -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:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL20-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) [[TMP0]] to 
ptr
+// OPENCL20-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], align 
8
+// OPENCL20-NEXT:[[TMP2:%.*]] = load ptr, ptr addrspace(5) [[ALLOC_PTR]], 
align 8
+// OPENCL20-NEXT:ret ptr [[TMP2]]
+//
+// OPENCL30-LABEL: define dso_local ptr addrspace(5) @test1(
+// OPENCL30-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL30-NEXT:  [[ENTRY:.*:]]
+// OPENCL30-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL30-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL30-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL30-NEXT:[[TMP1:%.*]] = load ptr addrspace(5), ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL30-NEXT:ret ptr addrspace(5) [[TMP1]]
+//
+// OPENCL30-EXT-LABEL: define dso_local ptr @test1(
+// OPENCL30-EXT-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL30-EXT-NEXT:  [[ENTRY:.*:]]
+// OPENCL30-EXT-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr, align 8, addrspace(5)
+// OPENCL30-EXT-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, 
addrspace(5)
+// OPENCL30-EXT-NEXT:[[TMP1:%.*]] = addrspacecast ptr addrspace(5) 
[[TMP0]] to ptr
+// OPENCL30-EXT-NEXT:store ptr [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], 
align 8
+// OPENCL30-EXT-NEXT:[[TMP2:%.*]] = load ptr, ptr addrspace(5) 
[[ALLOC_PTR]], align 8
+// OPENCL30-EXT-NEXT:ret ptr [[TMP2]]
+//
+float* test1() {
+float* alloc_ptr = (float*)__builtin_alloca(32 * sizeof(int));

arsenm wrote:

Yes, this is fundamentally a stack / private pointer 

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)

2024-06-17 Thread via cfe-commits


@@ -222,18 +222,13 @@ static bool DiagnoseNoDiscard(Sema &S, const 
WarnUnusedResultAttr *A,
   return S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
 }
 
-void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) {
-  const unsigned OrigDiagID = DiagID;
-  if (const LabelStmt *Label = dyn_cast_or_null(S))
-return DiagnoseUnusedExprResult(Label->getSubStmt(), DiagID);
-
-  const Expr *E = dyn_cast_or_null(S);
-  if (!E)
-return;
+namespace {
+void DiagnoseUnused(Sema &S, const Expr *E, std::optional DiagID) {
+  bool NoDiscardOnly = !DiagID.has_value();

Sirraide wrote:

A comment explaining the relationship between the `DiagID` parameter and 
`NoDiscardOnly` here would be nice so anyone looking at calls to this knows 
what’s going on w/o having to go through the entire function.

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)

2024-06-17 Thread via cfe-commits

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)

2024-06-17 Thread via cfe-commits


@@ -222,18 +222,13 @@ static bool DiagnoseNoDiscard(Sema &S, const 
WarnUnusedResultAttr *A,
   return S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
 }
 
-void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) {
-  const unsigned OrigDiagID = DiagID;
-  if (const LabelStmt *Label = dyn_cast_or_null(S))
-return DiagnoseUnusedExprResult(Label->getSubStmt(), DiagID);
-
-  const Expr *E = dyn_cast_or_null(S);
-  if (!E)
-return;
+namespace {

Sirraide wrote:

For functions, we typically mark them as `static` rather than using an 
anonymous namespace.

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)

2024-06-17 Thread via cfe-commits


@@ -171,21 +187,3 @@ void f() {
 #endif
 }
 } // namespace discarded_member_access
-
-
-// cxx11-warning@5 {{use of the 'nodiscard' attribute is a C++17 extension}}
-// cxx11-warning@9 {{use of the 'nodiscard' attribute is a C++17 extension}}
-// cxx11-warning@12 {{use of the 'nodiscard' attribute is a C++17 extension}}
-// cxx11-warning@13 {{use of the 'nodiscard' attribute is a C++17 extension}}
-// cxx11-warning@29 {{use of the 'nodiscard' attribute is a C++17 extension}}
-// cxx11-warning@65 {{use of the 'nodiscard' attribute is a C++20 extension}}
-// cxx11-warning@67 {{use of the 'nodiscard' attribute is a C++20 extension}}
-// cxx11-warning@71 {{use of the 'nodiscard' attribute is a C++20 extension}}
-// cxx11-warning@73 {{use of the 'nodiscard' attribute is a C++20 extension}}
-// cxx11-warning@74 {{use of the 'nodiscard' attribute is a C++20 extension}}
-// cxx11-warning@84 {{use of the 'nodiscard' attribute is a C++20 extension}}
-// cxx11-warning@86 {{use of the 'nodiscard' attribute is a C++17 extension}}
-// cxx11-warning@87 {{use of the 'nodiscard' attribute is a C++20 extension}}
-// cxx11-warning@91 {{use of the 'nodiscard' attribute is a C++17 extension}}
-// cxx11-warning@92 {{use of the 'nodiscard' attribute is a C++20 extension}}
-// cxx11-warning@95 {{use of the 'nodiscard' attribute is a C++20 extension}}

Sirraide wrote:

I will say, this was very confusing to me just now. Are there any actual 
changes left in this file at this point? This refactoring here is nice, but it 
should be part of a separate NFC patch if there are no other changes in this 
file...

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)

2024-06-17 Thread via cfe-commits

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

A few more minor things, but LGTM otherwise. 

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


[clang] [Clang] disallow non-lvalue values in constant expressions to prevent invalid pointer offset computation (PR #95479)

2024-06-17 Thread via cfe-commits

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


[clang] [Clang] disallow non-lvalue values in constant expressions to prevent invalid pointer offset computation (PR #95479)

2024-06-17 Thread via cfe-commits

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

There’s a typo in the release notes, but everything else lg.

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


[clang] [Clang] disallow non-lvalue values in constant expressions to prevent invalid pointer offset computation (PR #95479)

2024-06-17 Thread via cfe-commits


@@ -858,6 +858,8 @@ Bug Fixes to C++ Support
 - Fixed several bugs in capturing variables within unevaluated contexts. 
(#GH63845), (#GH67260), (#GH69307),
   (#GH88081), (#GH89496), (#GH90669) and (#GH91633).
 - Fixed handling of brace ellison when building deduction guides. (#GH64625), 
(#GH83368).
+- Fixed a failed assertion when attempting to convert an integer representing 
the difference
+  between the addresses of two labels (a GNU extension) to a pointer within a 
constant expression. (GH95366).

Sirraide wrote:

```suggestion
  between the addresses of two labels (a GNU extension) to a pointer within a 
constant expression. (#GH95366).
```

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


[clang] [clang] Emit bad shift warnings (PR #70307)

2024-06-17 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovicsyrmia updated 
https://github.com/llvm/llvm-project/pull/70307

From 0ed347381cdd9e639ab5026dcf244ca4d7fcb6e3 Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Thu, 26 Oct 2023 10:39:52 +0200
Subject: [PATCH] [clang] Emit bad shift warnings

---
 clang/lib/AST/ExprConstant.cpp |  7 +++
 clang/lib/Sema/SemaExpr.cpp| 17 +
 clang/test/C/drs/dr0xx.c   |  2 +-
 clang/test/Sema/shift-count-negative.c | 10 ++
 clang/test/Sema/shift-count-overflow.c |  7 +++
 clang/test/Sema/shift-negative-value.c | 10 ++
 clang/test/Sema/vla-2.c|  6 --
 clang/test/SemaCXX/shift.cpp   |  1 -
 8 files changed, 52 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/Sema/shift-count-negative.c
 create mode 100644 clang/test/Sema/shift-count-overflow.c
 create mode 100644 clang/test/Sema/shift-negative-value.c

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index af1f18aa8ef24..0926bcf258f58 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2856,6 +2856,9 @@ static bool handleIntIntBinOp(EvalInfo &Info, const 
BinaryOperator *E,
   else if (LHS.countl_zero() < SA)
 Info.CCEDiag(E, diag::note_constexpr_lshift_discards);
 }
+if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
+Info.getLangOpts().CPlusPlus)
+  return false;
 Result = LHS << SA;
 return true;
   }
@@ -2879,6 +2882,10 @@ static bool handleIntIntBinOp(EvalInfo &Info, const 
BinaryOperator *E,
 if (SA != RHS)
   Info.CCEDiag(E, diag::note_constexpr_large_shift)
 << RHS << E->getType() << LHS.getBitWidth();
+
+if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
+Info.getLangOpts().CPlusPlus)
+  return false;
 Result = LHS >> SA;
 return true;
   }
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 44f886bf54e3a..c77a0e511a3a8 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -11246,7 +11246,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   if (Right.isNegative()) {
 S.DiagRuntimeBehavior(Loc, RHS.get(),
   S.PDiag(diag::warn_shift_negative)
-<< RHS.get()->getSourceRange());
+  << RHS.get()->getSourceRange());
 return;
   }
 
@@ -11261,7 +11261,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   if (Right.uge(LeftSize)) {
 S.DiagRuntimeBehavior(Loc, RHS.get(),
   S.PDiag(diag::warn_shift_gt_typewidth)
-<< RHS.get()->getSourceRange());
+  << RHS.get()->getSourceRange());
 return;
   }
 
@@ -11294,7 +11294,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
&LHS, ExprResult &RHS,
   if (Left.isNegative()) {
 S.DiagRuntimeBehavior(Loc, LHS.get(),
   S.PDiag(diag::warn_shift_lhs_negative)
-<< LHS.get()->getSourceRange());
+  << LHS.get()->getSourceRange());
 return;
   }
 
@@ -17130,11 +17130,20 @@ Sema::VerifyIntegerConstantExpression(Expr *E, 
llvm::APSInt *Result,
   // Circumvent ICE checking in C++11 to avoid evaluating the expression twice
   // in the non-ICE case.
   if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) {
+SmallVector Notes;
 if (Result)
-  *Result = E->EvaluateKnownConstIntCheckOverflow(Context);
+  *Result = E->EvaluateKnownConstIntCheckOverflow(Context, &Notes);
 if (!isa(E))
   E = Result ? ConstantExpr::Create(Context, E, APValue(*Result))
  : ConstantExpr::Create(Context, E);
+
+if (Notes.size() && !Diagnoser.Suppress) {
+  Diagnoser.diagnoseNotICE(*this, DiagLoc) << E->getSourceRange();
+  for (const PartialDiagnosticAt &Note : Notes)
+Diag(Note.first, Note.second);
+  return ExprError();
+}
+
 return E;
   }
 
diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index 36de32a93da95..05045344efd91 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -430,7 +430,7 @@ void dr081(void) {
   /* Demonstrate that we don't crash when left shifting a signed value; that's
* implementation defined behavior.
*/
- _Static_assert(-1 << 1 == -2, "fail"); /* Didn't shift a zero into the "sign 
bit". */
+ _Static_assert(-1 << 1 == -2, "fail"); /* Undefined behavior since C99 */
  _Static_assert(1 << 3 == 1u << 3u, "fail"); /* Shift of a positive signed 
value does sensible things. */
 }
 
diff --git a/clang/test/Sema/shift-count-negative.c 
b/clang/test/Sema/shift-count-negative.c
new file mode 100644
index 0..34d51294b43d4
--- /dev/null
+++ b/clang/test/Sema/shift-count-negative.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc

[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)

2024-06-17 Thread via cfe-commits

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

LGTM

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


[clang] [Clang] Remove preprocessor guards and global feature checks for NEON (PR #95224)

2024-06-17 Thread via cfe-commits

https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/95224

>From d5caa1a22c90c7d3b1fd995c3ae980f02e4c14c9 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 12 Jun 2024 11:13:48 +
Subject: [PATCH 1/3] fix for mve

---
 clang/lib/Sema/SemaType.cpp| 18 --
 clang/test/Sema/arm-vector-types-support.c | 11 ++-
 clang/test/SemaCUDA/neon-attrs.cu  | 22 --
 clang/utils/TableGen/NeonEmitter.cpp   |  5 -
 4 files changed, 14 insertions(+), 42 deletions(-)
 delete mode 100644 clang/test/SemaCUDA/neon-attrs.cu

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 441fdcca0758f..9c0d043725dde 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8086,23 +8086,21 @@ static void HandleNeonVectorTypeAttr(QualType &CurType, 
const ParsedAttr &Attr,
 
   // Target must have NEON (or MVE, whose vectors are similar enough
   // not to need a separate attribute)
-  if (!(S.Context.getTargetInfo().hasFeature("neon") ||
-S.Context.getTargetInfo().hasFeature("mve") ||
-S.Context.getTargetInfo().hasFeature("sve") ||
-S.Context.getTargetInfo().hasFeature("sme") ||
+  if (!(S.Context.getTargetInfo().hasFeature("mve") ||
 IsTargetCUDAAndHostARM) &&
-  VecKind == VectorKind::Neon) {
+  VecKind == VectorKind::Neon && 
+  S.Context.getTargetInfo().getTriple().isArmMClass()) {
 S.Diag(Attr.getLoc(), diag::err_attribute_unsupported)
-<< Attr << "'neon', 'mve', 'sve' or 'sme'";
+<< Attr << "'mve'";
 Attr.setInvalid();
 return;
   }
-  if (!(S.Context.getTargetInfo().hasFeature("neon") ||
-S.Context.getTargetInfo().hasFeature("mve") ||
+  if (!(S.Context.getTargetInfo().hasFeature("mve") ||
 IsTargetCUDAAndHostARM) &&
-  VecKind == VectorKind::NeonPoly) {
+  VecKind == VectorKind::NeonPoly &&
+  S.Context.getTargetInfo().getTriple().isArmMClass()) {
 S.Diag(Attr.getLoc(), diag::err_attribute_unsupported)
-<< Attr << "'neon' or 'mve'";
+<< Attr << "'mve'";
 Attr.setInvalid();
 return;
   }
diff --git a/clang/test/Sema/arm-vector-types-support.c 
b/clang/test/Sema/arm-vector-types-support.c
index ed5f5ba175a94..e648d791a2687 100644
--- a/clang/test/Sema/arm-vector-types-support.c
+++ b/clang/test/Sema/arm-vector-types-support.c
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 %s -triple armv7 -fsyntax-only -verify
-// RUN: %clang_cc1 %s -triple aarch64 -fsyntax-only -verify
-// RUN: %clang_cc1 %s -triple aarch64 -target-feature -fp-armv8 -target-abi 
aapcs-soft -fsyntax-only -verify
+// RUN: %clang_cc1 %s -triple armv8.1m.main -fsyntax-only -verify
+// RUN: %clang_cc1 %s -triple aarch64 -fsyntax-only -verify=sve-type
+// RUN: %clang_cc1 %s -triple aarch64 -target-feature -fp-armv8 -target-abi 
aapcs-soft -fsyntax-only -verify=sve-type
 
-typedef __attribute__((neon_vector_type(2))) int int32x2_t; // 
expected-error{{'neon_vector_type' attribute is not supported on targets 
missing 'neon', 'mve', 'sve' or 'sme'; specify an appropriate -march= or 
-mcpu=}}
-typedef __attribute__((neon_polyvector_type(16))) short poly8x16_t; // 
expected-error{{'neon_polyvector_type' attribute is not supported on targets 
missing 'neon' or 'mve'; specify an appropriate -march= or -mcpu=}}
+typedef __attribute__((neon_vector_type(2))) int int32x2_t; // 
expected-error{{'neon_vector_type' attribute is not supported on targets 
missing 'mve'; specify an appropriate -march= or -mcpu=}}
+typedef __attribute__((neon_polyvector_type(16))) unsigned char poly8x16_t; // 
expected-error{{'neon_polyvector_type' attribute is not supported on targets 
missing 'mve'; specify an appropriate -march= or -mcpu=}}
 typedef __attribute__((arm_sve_vector_bits(256))) void nosveflag; // 
expected-error{{'arm_sve_vector_bits' attribute is not supported on targets 
missing 'sve'; specify an appropriate -march= or -mcpu=}}
+  // 
sve-type-error@-1{{'arm_sve_vector_bits' attribute is not supported on targets 
missing 'sve'; specify an appropriate -march= or -mcpu=}}
diff --git a/clang/test/SemaCUDA/neon-attrs.cu 
b/clang/test/SemaCUDA/neon-attrs.cu
deleted file mode 100644
index 129056741ac9a..0
--- a/clang/test/SemaCUDA/neon-attrs.cu
+++ /dev/null
@@ -1,22 +0,0 @@
-// CPU-side compilation on ARM with neon enabled (no errors expected).
-// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon -aux-triple 
nvptx64 -x cuda -fsyntax-only -verify=quiet %s
-
-// CPU-side compilation on ARM with neon disabled.
-// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature -neon -aux-triple 
nvptx64 -x cuda -fsyntax-only -verify %s
-
-// GPU-side compilation on ARM (no errors expected).
-// RUN: %clang_cc1 -triple nvptx64 -aux-triple arm64-linux-gnu 
-fcuda-is-device -x cuda -fsyntax-only -verify=quiet %s
-
-// Regular C++ compilation on ARM with

[clang] [Clang] Remove preprocessor guards and global feature checks for NEON (PR #95224)

2024-06-17 Thread via cfe-commits


@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 %s -triple armv7 -fsyntax-only -verify
-// RUN: %clang_cc1 %s -triple aarch64 -fsyntax-only -verify
-// RUN: %clang_cc1 %s -triple aarch64 -target-feature -fp-armv8 -target-abi 
aapcs-soft -fsyntax-only -verify
+// RUN: %clang_cc1 %s -triple armv8.1m.main -fsyntax-only -verify
+// RUN: %clang_cc1 %s -triple aarch64 -fsyntax-only -verify=sve-type
+// RUN: %clang_cc1 %s -triple aarch64 -target-feature -fp-armv8 -target-abi 
aapcs-soft -fsyntax-only -verify=sve-type
 
-typedef __attribute__((neon_vector_type(2))) int int32x2_t; // 
expected-error{{'neon_vector_type' attribute is not supported on targets 
missing 'neon', 'mve', 'sve' or 'sme'; specify an appropriate -march= or 
-mcpu=}}
-typedef __attribute__((neon_polyvector_type(16))) short poly8x16_t; // 
expected-error{{'neon_polyvector_type' attribute is not supported on targets 
missing 'neon' or 'mve'; specify an appropriate -march= or -mcpu=}}
+typedef __attribute__((neon_vector_type(2))) int int32x2_t; // 
expected-error{{'neon_vector_type' attribute is not supported on targets 
missing 'mve'; specify an appropriate -march= or -mcpu=}}

Lukacma wrote:

M-profile specific message added. The original error message was used elsewhere 
so couldn't be changed so I just created new one

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


[clang] [llvm] Cleanup MC/DC intrinsics for #82448 (PR #95496)

2024-06-17 Thread via cfe-commits

zmodem wrote:

> Re. condbitmap.update, it has become useless after #82448 . I think pruning 
> it will be the possible way.

Can you expand on this? I'm not familiar with these intrinsics at all. What are 
users who were using `condbitmap.update` supposed to call now?

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


[clang] [Clang] Remove preprocessor guards and global feature checks for NEON (PR #95224)

2024-06-17 Thread via cfe-commits

https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/95224

>From d5caa1a22c90c7d3b1fd995c3ae980f02e4c14c9 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 12 Jun 2024 11:13:48 +
Subject: [PATCH 1/4] fix for mve

---
 clang/lib/Sema/SemaType.cpp| 18 --
 clang/test/Sema/arm-vector-types-support.c | 11 ++-
 clang/test/SemaCUDA/neon-attrs.cu  | 22 --
 clang/utils/TableGen/NeonEmitter.cpp   |  5 -
 4 files changed, 14 insertions(+), 42 deletions(-)
 delete mode 100644 clang/test/SemaCUDA/neon-attrs.cu

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 441fdcca0758f..9c0d043725dde 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8086,23 +8086,21 @@ static void HandleNeonVectorTypeAttr(QualType &CurType, 
const ParsedAttr &Attr,
 
   // Target must have NEON (or MVE, whose vectors are similar enough
   // not to need a separate attribute)
-  if (!(S.Context.getTargetInfo().hasFeature("neon") ||
-S.Context.getTargetInfo().hasFeature("mve") ||
-S.Context.getTargetInfo().hasFeature("sve") ||
-S.Context.getTargetInfo().hasFeature("sme") ||
+  if (!(S.Context.getTargetInfo().hasFeature("mve") ||
 IsTargetCUDAAndHostARM) &&
-  VecKind == VectorKind::Neon) {
+  VecKind == VectorKind::Neon && 
+  S.Context.getTargetInfo().getTriple().isArmMClass()) {
 S.Diag(Attr.getLoc(), diag::err_attribute_unsupported)
-<< Attr << "'neon', 'mve', 'sve' or 'sme'";
+<< Attr << "'mve'";
 Attr.setInvalid();
 return;
   }
-  if (!(S.Context.getTargetInfo().hasFeature("neon") ||
-S.Context.getTargetInfo().hasFeature("mve") ||
+  if (!(S.Context.getTargetInfo().hasFeature("mve") ||
 IsTargetCUDAAndHostARM) &&
-  VecKind == VectorKind::NeonPoly) {
+  VecKind == VectorKind::NeonPoly &&
+  S.Context.getTargetInfo().getTriple().isArmMClass()) {
 S.Diag(Attr.getLoc(), diag::err_attribute_unsupported)
-<< Attr << "'neon' or 'mve'";
+<< Attr << "'mve'";
 Attr.setInvalid();
 return;
   }
diff --git a/clang/test/Sema/arm-vector-types-support.c 
b/clang/test/Sema/arm-vector-types-support.c
index ed5f5ba175a94..e648d791a2687 100644
--- a/clang/test/Sema/arm-vector-types-support.c
+++ b/clang/test/Sema/arm-vector-types-support.c
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 %s -triple armv7 -fsyntax-only -verify
-// RUN: %clang_cc1 %s -triple aarch64 -fsyntax-only -verify
-// RUN: %clang_cc1 %s -triple aarch64 -target-feature -fp-armv8 -target-abi 
aapcs-soft -fsyntax-only -verify
+// RUN: %clang_cc1 %s -triple armv8.1m.main -fsyntax-only -verify
+// RUN: %clang_cc1 %s -triple aarch64 -fsyntax-only -verify=sve-type
+// RUN: %clang_cc1 %s -triple aarch64 -target-feature -fp-armv8 -target-abi 
aapcs-soft -fsyntax-only -verify=sve-type
 
-typedef __attribute__((neon_vector_type(2))) int int32x2_t; // 
expected-error{{'neon_vector_type' attribute is not supported on targets 
missing 'neon', 'mve', 'sve' or 'sme'; specify an appropriate -march= or 
-mcpu=}}
-typedef __attribute__((neon_polyvector_type(16))) short poly8x16_t; // 
expected-error{{'neon_polyvector_type' attribute is not supported on targets 
missing 'neon' or 'mve'; specify an appropriate -march= or -mcpu=}}
+typedef __attribute__((neon_vector_type(2))) int int32x2_t; // 
expected-error{{'neon_vector_type' attribute is not supported on targets 
missing 'mve'; specify an appropriate -march= or -mcpu=}}
+typedef __attribute__((neon_polyvector_type(16))) unsigned char poly8x16_t; // 
expected-error{{'neon_polyvector_type' attribute is not supported on targets 
missing 'mve'; specify an appropriate -march= or -mcpu=}}
 typedef __attribute__((arm_sve_vector_bits(256))) void nosveflag; // 
expected-error{{'arm_sve_vector_bits' attribute is not supported on targets 
missing 'sve'; specify an appropriate -march= or -mcpu=}}
+  // 
sve-type-error@-1{{'arm_sve_vector_bits' attribute is not supported on targets 
missing 'sve'; specify an appropriate -march= or -mcpu=}}
diff --git a/clang/test/SemaCUDA/neon-attrs.cu 
b/clang/test/SemaCUDA/neon-attrs.cu
deleted file mode 100644
index 129056741ac9a..0
--- a/clang/test/SemaCUDA/neon-attrs.cu
+++ /dev/null
@@ -1,22 +0,0 @@
-// CPU-side compilation on ARM with neon enabled (no errors expected).
-// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon -aux-triple 
nvptx64 -x cuda -fsyntax-only -verify=quiet %s
-
-// CPU-side compilation on ARM with neon disabled.
-// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature -neon -aux-triple 
nvptx64 -x cuda -fsyntax-only -verify %s
-
-// GPU-side compilation on ARM (no errors expected).
-// RUN: %clang_cc1 -triple nvptx64 -aux-triple arm64-linux-gnu 
-fcuda-is-device -x cuda -fsyntax-only -verify=quiet %s
-
-// Regular C++ compilation on ARM with

[clang] [Clang] Introduce `CXXTypeidExpr::hasNullCheck` (PR #95718)

2024-06-17 Thread via cfe-commits

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

LGTM as well.

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


[clang] [Clang] Introduce `CXXTypeidExpr::hasNullCheck` (PR #95718)

2024-06-17 Thread via cfe-commits

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


[clang] [Clang] Introduce `CXXTypeidExpr::hasNullCheck` (PR #95718)

2024-06-17 Thread via cfe-commits


@@ -166,6 +166,55 @@ QualType CXXTypeidExpr::getTypeOperand(ASTContext 
&Context) const {
   Operand.get()->getType().getNonReferenceType(), Quals);
 }
 
+namespace {
+static bool isGLValueFromPointerDeref(const Expr *E) {

Sirraide wrote:

Pretty sure `namespace {` *and* `static` is redundant; we usually only use 
`static`.

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


[clang] [serialization] no transitive decl change (PR #92083)

2024-06-17 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

Oh, I didn't realize you were eager to land this in Clang 19, thanks for 
sharing that.
In that case, I think a specialiazed hash function for `GlobalDeclID` is indeed 
the way to go.

I was also worried a little there are other performance implications of this 
change that would block us, but we won't know until we run a full release 
testing cycle, which may take a week or more. Hopefully it will be okay, as my 
observations around the increase in PCM sizes align with the numbers from this 
patch and performance seems to be on par as well, if we change the hash 
function.
However, I still wanted to mention it so that we won't come out completely of 
the blue.

I'll try to help reviewing the two patches you posted, thanks!

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


[clang] [Serialization] Use specialized decl hash function for GlobalDeclID (PR #95730)

2024-06-17 Thread Ilya Biryukov via cfe-commits


@@ -230,7 +230,11 @@ template <> struct DenseMapInfo {
   }
 
   static unsigned getHashValue(const GlobalDeclID &Key) {
-return DenseMapInfo::getHashValue(Key.get());
+// Our default hash algorithm for 64 bits integer may not be very good.
+// In GlobalDeclID's case, it is pretty common that the lower 32 bits can
+// be same.
+return DenseMapInfo::getHashValue(Key.getModuleFileIndex()) ^

ilya-biryukov wrote:

+1 to using `hash_combine`, it should provide better results than xor.

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


[clang] [Clang] Introduce `CXXTypeidExpr::hasNullCheck` (PR #95718)

2024-06-17 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/95718

>From c3912611dd63f81ea7067a4b26ef5450f6f01f75 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 16 Jun 2024 22:35:38 +0100
Subject: [PATCH 1/3] [Clang] Introduce CXXTypeidExpr::hasNullCheck

---
 clang/docs/ReleaseNotes.rst  |  3 ++
 clang/include/clang/AST/ExprCXX.h|  4 ++
 clang/lib/AST/Expr.cpp   | 16 +--
 clang/lib/AST/ExprCXX.cpp| 49 ++
 clang/lib/CodeGen/CGCXXABI.h |  3 +-
 clang/lib/CodeGen/CGExprCXX.cpp  | 53 
 clang/lib/CodeGen/ItaniumCXXABI.cpp  |  7 ++--
 clang/lib/CodeGen/MicrosoftCXXABI.cpp|  8 ++--
 clang/lib/Sema/SemaExceptionSpec.cpp | 20 +++--
 clang/test/CXX/drs/cwg21xx.cpp   | 13 ++
 clang/test/SemaCXX/warn-unused-value.cpp | 10 +
 clang/www/cxx_dr_status.html |  2 +-
 12 files changed, 113 insertions(+), 75 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 69aea6c21ad39..6c92177d71298 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -268,6 +268,9 @@ Resolutions to C++ Defect Reports
 - Clang now requires a template argument list after a template keyword.
   (`CWG96: Syntactic disambiguation using the template keyword 
`_).
 
+- Clang no longer always reports ``!noexcept(typeid(expr))`` when the 
``typeid`` cannot throw a ``std::bad_typeid``.
+  (`CWG2191: Incorrect result for noexcept(typeid(v)) 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index d2e8d93656359..c2feac525c1ea 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -919,6 +919,10 @@ class CXXTypeidExpr : public Expr {
 reinterpret_cast(&const_cast(this)->Operand);
 return const_child_range(begin, begin + 1);
   }
+
+  /// Whether this is of a form like "typeid(*ptr)" that can throw a
+  /// std::bad_typeid if a pointer is a null pointer ([expr.typeid]p2)
+  bool hasNullCheck() const;
 };
 
 /// A member reference to an MSPropertyDecl.
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 7e555689b64c4..37ba5b69f446d 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3769,10 +3769,18 @@ bool Expr::HasSideEffects(const ASTContext &Ctx,
 break;
   }
 
-  case CXXTypeidExprClass:
-// typeid might throw if its subexpression is potentially-evaluated, so has
-// side-effects in that case whether or not its subexpression does.
-return cast(this)->isPotentiallyEvaluated();
+  case CXXTypeidExprClass: {
+const auto *TE = cast(this);
+if (!TE->isPotentiallyEvaluated())
+  return false;
+
+// If this type id expression can throw because of a null pointer, that is 
a
+// side-effect independent of if the operand has a side-effect
+if (IncludePossibleEffects && TE->hasNullCheck())
+  return true;
+
+break;
+  }
 
   case CXXConstructExprClass:
   case CXXTemporaryObjectExprClass: {
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 2abc0acbfde3b..7ecdb908e7d9f 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -166,6 +166,55 @@ QualType CXXTypeidExpr::getTypeOperand(ASTContext 
&Context) const {
   Operand.get()->getType().getNonReferenceType(), Quals);
 }
 
+namespace {
+static bool isGLValueFromPointerDeref(const Expr *E) {
+  E = E->IgnoreParens();
+
+  if (const auto *CE = dyn_cast(E)) {
+if (!CE->getSubExpr()->isGLValue())
+  return false;
+return isGLValueFromPointerDeref(CE->getSubExpr());
+  }
+
+  if (const auto *OVE = dyn_cast(E))
+return isGLValueFromPointerDeref(OVE->getSourceExpr());
+
+  if (const auto *BO = dyn_cast(E))
+if (BO->getOpcode() == BO_Comma)
+  return isGLValueFromPointerDeref(BO->getRHS());
+
+  if (const auto *ACO = dyn_cast(E))
+return isGLValueFromPointerDeref(ACO->getTrueExpr()) ||
+   isGLValueFromPointerDeref(ACO->getFalseExpr());
+
+  // C++11 [expr.sub]p1:
+  //   The expression E1[E2] is identical (by definition) to *((E1)+(E2))
+  if (isa(E))
+return true;
+
+  if (const auto *UO = dyn_cast(E))
+if (UO->getOpcode() == UO_Deref)
+  return true;
+
+  return false;
+}
+} // namespace
+
+bool CXXTypeidExpr::hasNullCheck() const {
+  if (!isPotentiallyEvaluated())
+return false;
+
+  // C++ [expr.typeid]p2:
+  //   If the glvalue expression is obtained by applying the unary * operator 
to
+  //   a pointer and the pointer is a null pointer value, the typeid expression
+  //   throws the std::bad_typeid exception.
+  //
+  // However, this paragraph's intent is not clear.  We choose a very generous
+  // interpretation which implores us to consider comma operators, conditional

[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits

https://github.com/Sirraide commented:

This does seem like a nice qoi improvement.

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits


@@ -787,6 +787,23 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
+  if (Token ahead = GetLookAheadToken(1);
+  ahead.isOneOf(tok::identifier, tok::ellipsis,
+tok::equal, tok::comma,
+tok::greater, tok::greatergreater, 
tok::greatergreatergreater)) {

Sirraide wrote:

I think it might be simpler to just check if the next token is *not* `<` and 
correct to `typename` in that case since a template-template parameter always 
has to start with `template <` anyway.

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo. Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account. See 
[LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 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 9f69e116a55dbd36e2f4fde38317de7262c88d7c 
44620330cd5238de549d3d77ddc447cd3bc51e60 -- clang/lib/Parse/ParseTemplate.cpp 
clang/test/CXX/drs/cwg1xx.cpp clang/test/Parser/cxx-template-decl.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index e5308d9eda..858a22f43a 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -787,18 +787,17 @@ NamedDecl 
*Parser::ParseTemplateTemplateParameter(unsigned Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
-  if (Token ahead = GetLookAheadToken(1);
-  ahead.isOneOf(tok::identifier, tok::ellipsis,
-tok::equal, tok::comma,
-tok::greater, tok::greatergreater, 
tok::greatergreatergreater)) {
-// Maybe they intended `typename` instead of `template` (given thats more 
common)
-// Error early, to add a fixit hint
+  if (Token ahead = GetLookAheadToken(1); ahead.isOneOf(
+  tok::identifier, tok::ellipsis, tok::equal, tok::comma, tok::greater,
+  tok::greatergreater, tok::greatergreatergreater)) {
+// Maybe they intended `typename` instead of `template` (given thats more
+// common) Error early, to add a fixit hint
 
 Diag(ahead.getLocation(), diag::err_expected_less_after) << "template";
-
+
 Diag(Tok.getLocation(), diag::note_meant_to_use_typename)
-  << 
FixItHint::CreateReplacement(CharSourceRange::getTokenRange(Tok.getLocation()),
-  "typename");
+<< FixItHint::CreateReplacement(
+   CharSourceRange::getTokenRange(Tok.getLocation()), "typename");
 
 Tok.setKind(tok::kw_typename);
 return ParseTypeParameter(Depth, Position);

``




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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-06-17 Thread Paul Heidekrüger via cfe-commits

https://github.com/PBHDK updated https://github.com/llvm/llvm-project/pull/95220

From 37292995de0c5aa87408586749795a97468d4725 Mon Sep 17 00:00:00 2001
From: Sebastian Wolf 
Date: Wed, 17 Apr 2024 16:16:35 +0200
Subject: [PATCH 01/15] Enforce SL.con.3: Add check to replace operator[] with
 at() on std containers

---
 .../AvoidBoundsErrorsCheck.cpp| 81 +++
 .../AvoidBoundsErrorsCheck.h  | 32 
 .../cppcoreguidelines/CMakeLists.txt  |  1 +
 .../CppCoreGuidelinesTidyModule.cpp   |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../cppcoreguidelines/avoid-bounds-errors.rst | 20 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../cppcoreguidelines/avoid-bounds-errors.cpp | 66 +++
 8 files changed, 209 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-bounds-errors.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-bounds-errors.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
new file mode 100644
index 0..524c21b5bdb81
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
@@ -0,0 +1,81 @@
+//===--- AvoidBoundsErrorsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "AvoidBoundsErrorsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+bool isApplicable(const QualType &Type) {
+  const auto TypeStr = Type.getAsString();
+  bool Result = false;
+  // Only check for containers in the std namespace
+  if (TypeStr.find("std::vector") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::array") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::deque") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::unordered_map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::flat_map") != std::string::npos) {
+Result = true;
+  }
+  // TODO Add std::span with C++26
+  return Result;
+}
+
+void AvoidBoundsErrorsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee(cxxMethodDecl(hasName("operator[]")).bind("f")))
+  .bind("x"),
+  this);
+}
+
+void AvoidBoundsErrorsCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Context = *Result.Context;
+  const SourceManager &Source = Context.getSourceManager();
+  const auto *MatchedExpr = Result.Nodes.getNodeAs("x");
+  const auto *MatchedFunction = Result.Nodes.getNodeAs("f");
+  const auto Type = MatchedFunction->getThisType();
+  if (!isApplicable(Type)) {
+return;
+  }
+
+  // Get original code.
+  const SourceLocation b(MatchedExpr->getBeginLoc());
+  const SourceLocation e(MatchedExpr->getEndLoc());
+  const std::string OriginalCode =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(b, e), Source,
+   getLangOpts())
+  .str();
+  const auto Range = SourceRange(b, e);
+
+  // Build replacement.
+  std::string NewCode = OriginalCode;
+  const auto BeginOpen = NewCode.find("[");
+  NewCode.replace(BeginOpen, 1, ".at(");
+  const auto BeginClose = NewCode.find("]");
+  NewCode.replace(BeginClose, 1, ")");
+
+  diag(MatchedExpr->getBeginLoc(), "Do not use operator[], use at() instead.")
+  << FixItHint::CreateReplacement(Range, NewCode);
+}
+
+} // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
new file mode 100644
index 0..f915729cd7bbe
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
@@ -0,0 +1,32 @@
+//===--- AvoidBoundsErrorsCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLV

[clang] [NFC] Refactor `[[nodiscard]]` test to not use macros and run under `-pedantic` (PR #95762)

2024-06-17 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok created 
https://github.com/llvm/llvm-project/pull/95762

None

>From fd52c588543a44a71652d7dbabc563777ebe4437 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Mon, 17 Jun 2024 11:15:16 +0100
Subject: [PATCH] [NFC] Refactor `[[nodiscard]]` test to not use macros and run
 under `-pedantic`

---
 .../dcl.attr/dcl.attr.nodiscard/p2.cpp| 62 ---
 1 file changed, 27 insertions(+), 35 deletions(-)

diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
index e2397c12e2e99..693ca29370cf3 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
@@ -1,16 +1,20 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify -Wc++20-extensions %s
-// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify -Wc++17-extensions %s
-// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -DEXT -Wc++17-extensions 
-Wc++20-extensions %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify=expected,cxx11,cxx11-17 
-pedantic %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 
-verify=expected,cxx11-17,since-cxx17 -pedantic %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify=expected,since-cxx17 
-pedantic %s
 
 struct [[nodiscard]] S {};
+// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
 S get_s();
 S& get_s_ref();
 
 enum [[nodiscard]] E {};
+// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
 E get_e();
 
 [[nodiscard]] int get_i();
+// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
 [[nodiscard]] volatile int &get_vi();
+// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
 
 void f() {
   get_s(); // expected-warning {{ignoring return value of function declared 
with 'nodiscard' attribute}}
@@ -27,6 +31,7 @@ void f() {
 }
 
 [[nodiscard]] volatile char &(*fp)(); // expected-warning {{'nodiscard' 
attribute only applies to functions, classes, or enumerations}}
+// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
 void g() {
   fp(); // expected-warning {{ignoring return value of function declared with 
'nodiscard' attribute}}
 
@@ -63,15 +68,20 @@ void f() {
 } // namespace PR31526
 
 struct [[nodiscard("reason")]] ReasonStruct {};
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 struct LaterReason;
 struct [[nodiscard("later reason")]] LaterReason {};
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 
 ReasonStruct get_reason();
 LaterReason get_later_reason();
 [[nodiscard("another reason")]] int another_reason();
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 
 [[nodiscard("conflicting reason")]] int conflicting_reason();
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 [[nodiscard("special reason")]] int conflicting_reason();
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 
 void cxx20_use() {
   get_reason(); // expected-warning {{ignoring return value of function 
declared with 'nodiscard' attribute: reason}}
@@ -82,17 +92,23 @@ void cxx20_use() {
 
 namespace p1771 {
 struct[[nodiscard("Don't throw me away!")]] ConvertTo{};
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 struct S {
   [[nodiscard]] S();
+  // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
   [[nodiscard("Don't let that S-Char go!")]] S(char);
+  // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
   S(int);
   [[gnu::warn_unused_result]] S(double);
   operator ConvertTo();
   [[nodiscard]] operator int();
+  // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
   [[nodiscard("Don't throw away as a double")]] operator double();
+  // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 };
 
 struct[[nodiscard("Don't throw me away either!")]] Y{};
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 
 void usage() {
   S();// expected-warning {{ignoring temporary created by a constructor 
declared with 'nodiscard' attribute}}
@@ -103,42 +119,18 @@ void usage() {
   S s;
   ConvertTo{}; // expected-warning {{ignoring return value of function 
declared with 'nodiscard' attribute: Don't throw me away!}}
 
-// AST is different in C++20 mode, pre-2017 a move ctor for ConvertTo is there
-// as well, hense the constructor warning.
-#if __cplusplus >= 201703L
-// expected-warning@+4 {{ignoring return value of function declared with 
'nodiscard' attribute: Don't throw me away!}}
-#else
-// expected-warning@+2 {{ignoring temporary created by a constructor declared 
with 'nodiscard' attribute: Don't throw me away!}}
-#endif
+  // AST is different in C++17 mode. Before, a move ctor for Conve

[clang] [NFC] Refactor `[[nodiscard]]` test to not use macros and run under `-pedantic` (PR #95762)

2024-06-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mital Ashok (MitalAshok)


Changes



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


1 Files Affected:

- (modified) clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp (+27-35) 


``diff
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
index e2397c12e2e99..693ca29370cf3 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp
@@ -1,16 +1,20 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify -Wc++20-extensions %s
-// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify -Wc++17-extensions %s
-// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -DEXT -Wc++17-extensions 
-Wc++20-extensions %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify=expected,cxx11,cxx11-17 
-pedantic %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 
-verify=expected,cxx11-17,since-cxx17 -pedantic %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify=expected,since-cxx17 
-pedantic %s
 
 struct [[nodiscard]] S {};
+// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
 S get_s();
 S& get_s_ref();
 
 enum [[nodiscard]] E {};
+// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
 E get_e();
 
 [[nodiscard]] int get_i();
+// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
 [[nodiscard]] volatile int &get_vi();
+// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
 
 void f() {
   get_s(); // expected-warning {{ignoring return value of function declared 
with 'nodiscard' attribute}}
@@ -27,6 +31,7 @@ void f() {
 }
 
 [[nodiscard]] volatile char &(*fp)(); // expected-warning {{'nodiscard' 
attribute only applies to functions, classes, or enumerations}}
+// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
 void g() {
   fp(); // expected-warning {{ignoring return value of function declared with 
'nodiscard' attribute}}
 
@@ -63,15 +68,20 @@ void f() {
 } // namespace PR31526
 
 struct [[nodiscard("reason")]] ReasonStruct {};
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 struct LaterReason;
 struct [[nodiscard("later reason")]] LaterReason {};
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 
 ReasonStruct get_reason();
 LaterReason get_later_reason();
 [[nodiscard("another reason")]] int another_reason();
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 
 [[nodiscard("conflicting reason")]] int conflicting_reason();
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 [[nodiscard("special reason")]] int conflicting_reason();
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 
 void cxx20_use() {
   get_reason(); // expected-warning {{ignoring return value of function 
declared with 'nodiscard' attribute: reason}}
@@ -82,17 +92,23 @@ void cxx20_use() {
 
 namespace p1771 {
 struct[[nodiscard("Don't throw me away!")]] ConvertTo{};
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 struct S {
   [[nodiscard]] S();
+  // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
   [[nodiscard("Don't let that S-Char go!")]] S(char);
+  // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
   S(int);
   [[gnu::warn_unused_result]] S(double);
   operator ConvertTo();
   [[nodiscard]] operator int();
+  // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
   [[nodiscard("Don't throw away as a double")]] operator double();
+  // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 };
 
 struct[[nodiscard("Don't throw me away either!")]] Y{};
+// cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 
extension}}
 
 void usage() {
   S();// expected-warning {{ignoring temporary created by a constructor 
declared with 'nodiscard' attribute}}
@@ -103,42 +119,18 @@ void usage() {
   S s;
   ConvertTo{}; // expected-warning {{ignoring return value of function 
declared with 'nodiscard' attribute: Don't throw me away!}}
 
-// AST is different in C++20 mode, pre-2017 a move ctor for ConvertTo is there
-// as well, hense the constructor warning.
-#if __cplusplus >= 201703L
-// expected-warning@+4 {{ignoring return value of function declared with 
'nodiscard' attribute: Don't throw me away!}}
-#else
-// expected-warning@+2 {{ignoring temporary created by a constructor declared 
with 'nodiscard' attribute: Don't throw me away!}}
-#endif
+  // AST is different in C++17 mode. Before, a move ctor for ConvertTo is there
+  // as well, hence the constructor warning.
+
+  // since-cxx17-warning@+2 {{ignoring return value of function declared with 
'nodiscard' attribute: Don't

[clang] [NFC] Refactor `[[nodiscard]]` test to not use macros and run under `-pedantic` (PR #95762)

2024-06-17 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

CC @AaronBallman @Sirraide

More tests will be added in 
https://github.com/llvm/llvm-project/pull/95112/files#diff-50c6ce984d17856a8b61d98f625dacec78bfbbe01d2e9fbab80b27c771e3db99R144
 but these changes are unrelated enough to warrant a separate patch

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


[clang] [NFC] Refactor `[[nodiscard]]` test to not use macros and run under `-pedantic` (PR #95762)

2024-06-17 Thread via cfe-commits

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

LGTM

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


[clang] [llvm] Cleanup MC/DC intrinsics for #82448 (PR #95496)

2024-06-17 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

@zmodem #82448 doesn't use intermediate condbitmap but integer index. I decided 
not to modify and use the intrinsic `condbitmapupdate`, since the signature 
will be quite different and this is too simple to be put into the intrinsic.
Also pre-#82448 impl of `condbitmapupdate` was so simple (`|= (V << ID)`) just 
to update the local variable. I wondered why it was implemented with the 
intrinsic.

In contrast, I modified `tvbitmapupdate` in #82448 without getting rid of it. I 
modified its signature and semantics. I thought `tvbitmapupdate` might be left 
as an intrinsic since it could be enhanced to atomic ops (and continuous bias 
mode).

I guess they would hit apparently buggy behavior if they were using obsolete 
`condbitmapupdate` and modified `tvbitmapupdate`.

Since I didn't update and won't update the semantics of `condupdate`, they 
should get rid of it, as far as they follow our trunk. I don't think I could 
provide "easy" migration path.

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


[clang] [Clang] Forward -rpath flag in the correct format in CPU offloading (PR #95763)

2024-06-17 Thread via cfe-commits

https://github.com/mikaoP created 
https://github.com/llvm/llvm-project/pull/95763

`clang-linker-wrapper` gets flags in linker format. In CPU offloading we need 
to format some of them as compiler flags, like it is already done with 
`--no-whole-archine`. This patch does the same with `-rpath`

>From eb1145aa4faea37806780823cc55daaba1340f36 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ra=C3=BAl=20Pe=C3=B1acoba=20Veigas?= 
Date: Mon, 17 Jun 2024 10:34:10 +
Subject: [PATCH] [Clang] Forward -rpath flag in the correct format in CPU
 offloading

---
 clang/test/Driver/Inputs/linker-wrapper/.keep   | 0
 clang/test/Driver/linker-wrapper.c  | 1 +
 clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp | 2 ++
 3 files changed, 3 insertions(+)
 create mode 100644 clang/test/Driver/Inputs/linker-wrapper/.keep

diff --git a/clang/test/Driver/Inputs/linker-wrapper/.keep 
b/clang/test/Driver/Inputs/linker-wrapper/.keep
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index 0d05f913aad63..9ed43343bf8d7 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -57,6 +57,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: llvm-ar rcs %t.a %t.o
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
 // RUN:   --linker-path=/usr/bin/ld.lld --whole-archive %t.a 
--no-whole-archive \
+// RUN:   -rpath %S/Inputs/linker-wrapper
 // RUN:   %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK
 
 // CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu 
-march=native -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared 
-Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 07a8d53c04b16..0023899513dd9 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -500,6 +500,8 @@ Expected clang(ArrayRef InputFiles, 
const ArgList &Args) {
 LinkerArgs.push_back(Args.MakeArgString("-Wl,--whole-archive"));
   else if (Arg->getOption().matches(OPT_no_whole_archive))
 LinkerArgs.push_back(Args.MakeArgString("-Wl,--no-whole-archive"));
+  else if (Arg->getOption().matches(OPT_rpath))
+LinkerArgs.push_back(Args.MakeArgString("-Wl,-rpath," + 
Twine(Arg->getValue(;
   else
 Arg->render(Args, LinkerArgs);
 }

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


[clang] [Clang] Forward -rpath flag in the correct format in CPU offloading (PR #95763)

2024-06-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: None (mikaoP)


Changes

`clang-linker-wrapper` gets flags in linker format. In CPU offloading we need 
to format some of them as compiler flags, like it is already done with 
`--no-whole-archine`. This patch does the same with `-rpath`

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


3 Files Affected:

- (added) clang/test/Driver/Inputs/linker-wrapper/.keep () 
- (modified) clang/test/Driver/linker-wrapper.c (+1) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+2) 


``diff
diff --git a/clang/test/Driver/Inputs/linker-wrapper/.keep 
b/clang/test/Driver/Inputs/linker-wrapper/.keep
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index 0d05f913aad63..9ed43343bf8d7 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -57,6 +57,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: llvm-ar rcs %t.a %t.o
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
 // RUN:   --linker-path=/usr/bin/ld.lld --whole-archive %t.a 
--no-whole-archive \
+// RUN:   -rpath %S/Inputs/linker-wrapper
 // RUN:   %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK
 
 // CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu 
-march=native -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared 
-Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 07a8d53c04b16..0023899513dd9 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -500,6 +500,8 @@ Expected clang(ArrayRef InputFiles, 
const ArgList &Args) {
 LinkerArgs.push_back(Args.MakeArgString("-Wl,--whole-archive"));
   else if (Arg->getOption().matches(OPT_no_whole_archive))
 LinkerArgs.push_back(Args.MakeArgString("-Wl,--no-whole-archive"));
+  else if (Arg->getOption().matches(OPT_rpath))
+LinkerArgs.push_back(Args.MakeArgString("-Wl,-rpath," + 
Twine(Arg->getValue(;
   else
 Arg->render(Args, LinkerArgs);
 }

``




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


[clang] [Clang] Forward -rpath flag in the correct format in CPU offloading (PR #95763)

2024-06-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (mikaoP)


Changes

`clang-linker-wrapper` gets flags in linker format. In CPU offloading we need 
to format some of them as compiler flags, like it is already done with 
`--no-whole-archine`. This patch does the same with `-rpath`

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


3 Files Affected:

- (added) clang/test/Driver/Inputs/linker-wrapper/.keep () 
- (modified) clang/test/Driver/linker-wrapper.c (+1) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+2) 


``diff
diff --git a/clang/test/Driver/Inputs/linker-wrapper/.keep 
b/clang/test/Driver/Inputs/linker-wrapper/.keep
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index 0d05f913aad63..9ed43343bf8d7 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -57,6 +57,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: llvm-ar rcs %t.a %t.o
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
 // RUN:   --linker-path=/usr/bin/ld.lld --whole-archive %t.a 
--no-whole-archive \
+// RUN:   -rpath %S/Inputs/linker-wrapper
 // RUN:   %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK
 
 // CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu 
-march=native -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared 
-Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 07a8d53c04b16..0023899513dd9 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -500,6 +500,8 @@ Expected clang(ArrayRef InputFiles, 
const ArgList &Args) {
 LinkerArgs.push_back(Args.MakeArgString("-Wl,--whole-archive"));
   else if (Arg->getOption().matches(OPT_no_whole_archive))
 LinkerArgs.push_back(Args.MakeArgString("-Wl,--no-whole-archive"));
+  else if (Arg->getOption().matches(OPT_rpath))
+LinkerArgs.push_back(Args.MakeArgString("-Wl,-rpath," + 
Twine(Arg->getValue(;
   else
 Arg->render(Args, LinkerArgs);
 }

``




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


[clang] [clang][CodeGen] Fix EmitInvariantStart for non-zero addrspace (PR #94346)

2024-06-17 Thread Bruno De Fraine via cfe-commits

brunodf-snps wrote:

@efriedma-quic Thanks for the review! Could you merge this request on our 
behalf? (No commit access)

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


[clang] [Clang] Forward -rpath flag in the correct format in CPU offloading (PR #95763)

2024-06-17 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 657ec7320d8a28171755ba0dd5afc570a5a16791 
eb1145aa4faea37806780823cc55daaba1340f36 -- clang/test/Driver/linker-wrapper.c 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 0023899513..6705a4635b 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -501,7 +501,8 @@ Expected clang(ArrayRef InputFiles, 
const ArgList &Args) {
   else if (Arg->getOption().matches(OPT_no_whole_archive))
 LinkerArgs.push_back(Args.MakeArgString("-Wl,--no-whole-archive"));
   else if (Arg->getOption().matches(OPT_rpath))
-LinkerArgs.push_back(Args.MakeArgString("-Wl,-rpath," + 
Twine(Arg->getValue(;
+LinkerArgs.push_back(
+Args.MakeArgString("-Wl,-rpath," + Twine(Arg->getValue(;
   else
 Arg->render(Args, LinkerArgs);
 }

``




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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-06-17 Thread Paul Heidekrüger via cfe-commits

https://github.com/PBHDK updated https://github.com/llvm/llvm-project/pull/95220

From 37292995de0c5aa87408586749795a97468d4725 Mon Sep 17 00:00:00 2001
From: Sebastian Wolf 
Date: Wed, 17 Apr 2024 16:16:35 +0200
Subject: [PATCH 01/16] Enforce SL.con.3: Add check to replace operator[] with
 at() on std containers

---
 .../AvoidBoundsErrorsCheck.cpp| 81 +++
 .../AvoidBoundsErrorsCheck.h  | 32 
 .../cppcoreguidelines/CMakeLists.txt  |  1 +
 .../CppCoreGuidelinesTidyModule.cpp   |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../cppcoreguidelines/avoid-bounds-errors.rst | 20 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../cppcoreguidelines/avoid-bounds-errors.cpp | 66 +++
 8 files changed, 209 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-bounds-errors.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-bounds-errors.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
new file mode 100644
index 0..524c21b5bdb81
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
@@ -0,0 +1,81 @@
+//===--- AvoidBoundsErrorsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "AvoidBoundsErrorsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+bool isApplicable(const QualType &Type) {
+  const auto TypeStr = Type.getAsString();
+  bool Result = false;
+  // Only check for containers in the std namespace
+  if (TypeStr.find("std::vector") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::array") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::deque") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::unordered_map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::flat_map") != std::string::npos) {
+Result = true;
+  }
+  // TODO Add std::span with C++26
+  return Result;
+}
+
+void AvoidBoundsErrorsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee(cxxMethodDecl(hasName("operator[]")).bind("f")))
+  .bind("x"),
+  this);
+}
+
+void AvoidBoundsErrorsCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Context = *Result.Context;
+  const SourceManager &Source = Context.getSourceManager();
+  const auto *MatchedExpr = Result.Nodes.getNodeAs("x");
+  const auto *MatchedFunction = Result.Nodes.getNodeAs("f");
+  const auto Type = MatchedFunction->getThisType();
+  if (!isApplicable(Type)) {
+return;
+  }
+
+  // Get original code.
+  const SourceLocation b(MatchedExpr->getBeginLoc());
+  const SourceLocation e(MatchedExpr->getEndLoc());
+  const std::string OriginalCode =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(b, e), Source,
+   getLangOpts())
+  .str();
+  const auto Range = SourceRange(b, e);
+
+  // Build replacement.
+  std::string NewCode = OriginalCode;
+  const auto BeginOpen = NewCode.find("[");
+  NewCode.replace(BeginOpen, 1, ".at(");
+  const auto BeginClose = NewCode.find("]");
+  NewCode.replace(BeginClose, 1, ")");
+
+  diag(MatchedExpr->getBeginLoc(), "Do not use operator[], use at() instead.")
+  << FixItHint::CreateReplacement(Range, NewCode);
+}
+
+} // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
new file mode 100644
index 0..f915729cd7bbe
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
@@ -0,0 +1,32 @@
+//===--- AvoidBoundsErrorsCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLV

[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-06-17 Thread Paul Heidekrüger via cfe-commits


@@ -0,0 +1,123 @@
+//===--- PreferAtOverSubscriptOperatorCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "PreferAtOverSubscriptOperatorCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+static constexpr std::array DefaultExclusions = {
+llvm::StringRef("std::map"), llvm::StringRef("std::unordered_map"),
+llvm::StringRef("std::flat_map")};
+
+PreferAtOverSubscriptOperatorCheck::PreferAtOverSubscriptOperatorCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {
+
+  ExcludedClasses = clang::tidy::utils::options::parseStringList(
+  Options.get("ExcludeClasses", ""));
+  ExcludedClasses.insert(ExcludedClasses.end(), DefaultExclusions.begin(),
+ DefaultExclusions.end());
+}
+
+void PreferAtOverSubscriptOperatorCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+
+  if (ExcludedClasses.size() == DefaultExclusions.size()) {
+Options.store(Opts, "ExcludeClasses", "");
+return;
+  }
+
+  // Sum up the sizes of the defaults ( + semicolons), so we can remove them
+  // from the saved options
+  size_t DefaultsStringLength =
+  std::transform_reduce(DefaultExclusions.begin(), DefaultExclusions.end(),
+DefaultExclusions.size(), std::plus<>(),
+[](llvm::StringRef Name) { return Name.size(); });
+
+  std::string Serialized =
+  clang::tidy::utils::options::serializeStringList(ExcludedClasses);
+
+  Options.store(Opts, "ExcludeClasses",
+Serialized.substr(0, Serialized.size() - 
DefaultsStringLength));
+}
+
+const CXXMethodDecl *findAlternative(const CXXRecordDecl *MatchedParent,
+ const CXXMethodDecl *MatchedOperator) {
+  for (const CXXMethodDecl *Method : MatchedParent->methods()) {
+const bool CorrectName = Method->getNameInfo().getAsString() == "at";
+if (!CorrectName)
+  continue;
+
+const bool SameReturnType =
+Method->getReturnType() == MatchedOperator->getReturnType();
+if (!SameReturnType)
+  continue;
+
+const bool SameNumberOfArguments =
+Method->getNumParams() == MatchedOperator->getNumParams();
+if (!SameNumberOfArguments)
+  continue;
+
+for (unsigned ArgInd = 0; ArgInd < Method->getNumParams(); ArgInd++) {
+  const bool SameArgType =
+  Method->parameters()[ArgInd]->getOriginalType() ==
+  MatchedOperator->parameters()[ArgInd]->getOriginalType();
+  if (!SameArgType)
+continue;
+}
+
+return Method;
+  }
+  return static_cast(nullptr);
+}
+
+void PreferAtOverSubscriptOperatorCheck::registerMatchers(MatchFinder *Finder) 
{
+  // Need a callExpr here to match CXXOperatorCallExpr ``(&a)->operator[](0)``
+  // and CXXMemberCallExpr ``a[0]``.
+  Finder->addMatcher(
+  callExpr(
+  callee(
+  cxxMethodDecl(hasOverloadedOperatorName("[]")).bind("operator")),
+  callee(cxxMethodDecl(hasParent(
+  cxxRecordDecl(hasMethod(hasName("at"))).bind("parent")
+  .bind("caller"),
+  this);
+}
+
+void PreferAtOverSubscriptOperatorCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MatchedExpr = Result.Nodes.getNodeAs("caller");
+  const auto *MatchedOperator =
+  Result.Nodes.getNodeAs("operator");
+  const auto *MatchedParent = Result.Nodes.getNodeAs("parent");
+
+  std::string ClassIdentifier = MatchedParent->getQualifiedNameAsString();
+
+  if (std::find(ExcludedClasses.begin(), ExcludedClasses.end(),
+ClassIdentifier) != ExcludedClasses.end())
+return;

PBHDK wrote:

Like so: 5098f65dc68e33ef854335e243b9570c4b0cf696?

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


[clang] [Clang] Forward -rpath flag in the correct format in CPU offloading (PR #95763)

2024-06-17 Thread via cfe-commits

https://github.com/mikaoP updated 
https://github.com/llvm/llvm-project/pull/95763

>From 9710628fb49e941bc43b1a4fb11a9d03470b8d04 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ra=C3=BAl=20Pe=C3=B1acoba=20Veigas?= 
Date: Mon, 17 Jun 2024 10:34:10 +
Subject: [PATCH] [Clang] Forward -rpath flag in the correct format in CPU
 offloading

---
 clang/test/Driver/Inputs/linker-wrapper/.keep   | 0
 clang/test/Driver/linker-wrapper.c  | 1 +
 clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp | 3 +++
 3 files changed, 4 insertions(+)
 create mode 100644 clang/test/Driver/Inputs/linker-wrapper/.keep

diff --git a/clang/test/Driver/Inputs/linker-wrapper/.keep 
b/clang/test/Driver/Inputs/linker-wrapper/.keep
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index 0d05f913aad63..9ed43343bf8d7 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -57,6 +57,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: llvm-ar rcs %t.a %t.o
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
 // RUN:   --linker-path=/usr/bin/ld.lld --whole-archive %t.a 
--no-whole-archive \
+// RUN:   -rpath %S/Inputs/linker-wrapper
 // RUN:   %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK
 
 // CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu 
-march=native -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared 
-Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 07a8d53c04b16..6705a4635b4cd 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -500,6 +500,9 @@ Expected clang(ArrayRef InputFiles, 
const ArgList &Args) {
 LinkerArgs.push_back(Args.MakeArgString("-Wl,--whole-archive"));
   else if (Arg->getOption().matches(OPT_no_whole_archive))
 LinkerArgs.push_back(Args.MakeArgString("-Wl,--no-whole-archive"));
+  else if (Arg->getOption().matches(OPT_rpath))
+LinkerArgs.push_back(
+Args.MakeArgString("-Wl,-rpath," + Twine(Arg->getValue(;
   else
 Arg->render(Args, LinkerArgs);
 }

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


[clang] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2 and below (PR #95750)

2024-06-17 Thread Vikash Gupta via cfe-commits

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

>From 04ff7bd289d0840b8aa2b0502e4ac050174c95ab Mon Sep 17 00:00:00 2001
From: vg0204 
Date: Mon, 17 Jun 2024 11:20:02 +0530
Subject: [PATCH 1/2] [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 99a8704298314..e12c2a9209706 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 
&Context,
 FunctionDecl *FDecl,
 MultiExprArg ArgExprs) {
@@ -6275,13 +6278,27 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema 
*Sema, ASTContext &Context,
 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] Forward -rpath flag to the correct format in CPU offloading (PR #95763)

2024-06-17 Thread via cfe-commits

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


[clang] [llvm] [BPF] Fix linking issues in static map initializers (PR #91310)

2024-06-17 Thread Nick Zavaritsky via cfe-commits

mejedi wrote:

ping

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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-06-17 Thread Julian Schmidt via cfe-commits
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,123 @@
+//===--- PreferAtOverSubscriptOperatorCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "PreferAtOverSubscriptOperatorCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+static constexpr std::array DefaultExclusions = {
+llvm::StringRef("std::map"), llvm::StringRef("std::unordered_map"),
+llvm::StringRef("std::flat_map")};
+
+PreferAtOverSubscriptOperatorCheck::PreferAtOverSubscriptOperatorCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {
+
+  ExcludedClasses = clang::tidy::utils::options::parseStringList(
+  Options.get("ExcludeClasses", ""));
+  ExcludedClasses.insert(ExcludedClasses.end(), DefaultExclusions.begin(),
+ DefaultExclusions.end());
+}
+
+void PreferAtOverSubscriptOperatorCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+
+  if (ExcludedClasses.size() == DefaultExclusions.size()) {
+Options.store(Opts, "ExcludeClasses", "");
+return;
+  }
+
+  // Sum up the sizes of the defaults ( + semicolons), so we can remove them
+  // from the saved options
+  size_t DefaultsStringLength =
+  std::transform_reduce(DefaultExclusions.begin(), DefaultExclusions.end(),
+DefaultExclusions.size(), std::plus<>(),
+[](llvm::StringRef Name) { return Name.size(); });
+
+  std::string Serialized =
+  clang::tidy::utils::options::serializeStringList(ExcludedClasses);
+
+  Options.store(Opts, "ExcludeClasses",
+Serialized.substr(0, Serialized.size() - 
DefaultsStringLength));
+}
+
+const CXXMethodDecl *findAlternative(const CXXRecordDecl *MatchedParent,
+ const CXXMethodDecl *MatchedOperator) {
+  for (const CXXMethodDecl *Method : MatchedParent->methods()) {
+const bool CorrectName = Method->getNameInfo().getAsString() == "at";
+if (!CorrectName)
+  continue;
+
+const bool SameReturnType =
+Method->getReturnType() == MatchedOperator->getReturnType();
+if (!SameReturnType)
+  continue;
+
+const bool SameNumberOfArguments =
+Method->getNumParams() == MatchedOperator->getNumParams();
+if (!SameNumberOfArguments)
+  continue;
+
+for (unsigned ArgInd = 0; ArgInd < Method->getNumParams(); ArgInd++) {
+  const bool SameArgType =
+  Method->parameters()[ArgInd]->getOriginalType() ==
+  MatchedOperator->parameters()[ArgInd]->getOriginalType();
+  if (!SameArgType)
+continue;
+}
+
+return Method;
+  }
+  return static_cast(nullptr);
+}
+
+void PreferAtOverSubscriptOperatorCheck::registerMatchers(MatchFinder *Finder) 
{
+  // Need a callExpr here to match CXXOperatorCallExpr ``(&a)->operator[](0)``
+  // and CXXMemberCallExpr ``a[0]``.
+  Finder->addMatcher(
+  callExpr(
+  callee(
+  cxxMethodDecl(hasOverloadedOperatorName("[]")).bind("operator")),
+  callee(cxxMethodDecl(hasParent(
+  cxxRecordDecl(hasMethod(hasName("at"))).bind("parent")
+  .bind("caller"),
+  this);
+}
+
+void PreferAtOverSubscriptOperatorCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MatchedExpr = Result.Nodes.getNodeAs("caller");
+  const auto *MatchedOperator =
+  Result.Nodes.getNodeAs("operator");
+  const auto *MatchedParent = Result.Nodes.getNodeAs("parent");
+
+  std::string ClassIdentifier = MatchedParent->getQualifiedNameAsString();
+
+  if (std::find(ExcludedClasses.begin(), ExcludedClasses.end(),
+ClassIdentifier) != ExcludedClasses.end())
+return;

5chmidti wrote:

Yes

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits


@@ -787,6 +787,23 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
+  if (Token ahead = GetLookAheadToken(1);
+  ahead.isOneOf(tok::identifier, tok::ellipsis,
+tok::equal, tok::comma,
+tok::greater, tok::greatergreater, 
tok::greatergreatergreater)) {

Veeloxfire wrote:

In hindsight yes I think thats a better solution. I believe this solution came 
about because I was just going to check for `identifier` but then realised 
there were more options for type templates and kept adding

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits

https://github.com/Veeloxfire updated 
https://github.com/llvm/llvm-project/pull/95726

>From 44620330cd5238de549d3d77ddc447cd3bc51e60 Mon Sep 17 00:00:00 2001
From: Veeloxfire <58116051+veeloxf...@users.noreply.github.com>
Date: Mon, 17 Jun 2024 01:20:32 +0100
Subject: [PATCH 1/3] [clang][Parser] "Better" error messages for invalid
 template template

For the somewhat easy mistake of `template ...` clang outputs a 
partially cryptic error
Change this to assume the programmer intended `typename` in cases where 
`template` is illegal, and emit diagnostics (and forward parsing) accordingly
This mirrors the behaviour of `typedef` handling
---
 clang/lib/Parse/ParseTemplate.cpp   | 17 +
 clang/test/CXX/drs/cwg1xx.cpp   |  2 ++
 clang/test/Parser/cxx-template-decl.cpp |  2 +-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index a5130f56600e5..e5308d9edac5f 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -787,6 +787,23 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
+  if (Token ahead = GetLookAheadToken(1);
+  ahead.isOneOf(tok::identifier, tok::ellipsis,
+tok::equal, tok::comma,
+tok::greater, tok::greatergreater, 
tok::greatergreatergreater)) {
+// Maybe they intended `typename` instead of `template` (given thats more 
common)
+// Error early, to add a fixit hint
+
+Diag(ahead.getLocation(), diag::err_expected_less_after) << "template";
+
+Diag(Tok.getLocation(), diag::note_meant_to_use_typename)
+  << 
FixItHint::CreateReplacement(CharSourceRange::getTokenRange(Tok.getLocation()),
+  "typename");
+
+Tok.setKind(tok::kw_typename);
+return ParseTypeParameter(Depth, Position);
+  }
+
   // Handle the template <...> part.
   SourceLocation TemplateLoc = ConsumeToken();
   SmallVector TemplateParams;
diff --git a/clang/test/CXX/drs/cwg1xx.cpp b/clang/test/CXX/drs/cwg1xx.cpp
index e71ea9278..72b3ff40152d5 100644
--- a/clang/test/CXX/drs/cwg1xx.cpp
+++ b/clang/test/CXX/drs/cwg1xx.cpp
@@ -1145,8 +1145,10 @@ namespace cwg181 { // cwg181: yes
   namespace X {
 template  > struct A { };
 // expected-error@-1 +{{}}
+//  expected-note@-2 {{did you mean to use 'typename'?}}
 template  > void f(A) { }
 // expected-error@-1 +{{}}
+//  expected-note@-2 {{did you mean to use 'typename'?}}
   }
 
   namespace Y {
diff --git a/clang/test/Parser/cxx-template-decl.cpp 
b/clang/test/Parser/cxx-template-decl.cpp
index 734438069b9ae..69b9ab012b478 100644
--- a/clang/test/Parser/cxx-template-decl.cpp
+++ b/clang/test/Parser/cxx-template-decl.cpp
@@ -22,7 +22,7 @@ template> struct x3; // expected-error 
{{expected ',' or '>' in t
  cpp14-error {{template template 
parameter requires 'class' after the parameter list}} \
  cpp17-error {{template template 
parameter requires 'class' or 'typename' after the parameter list}}
 template  struct Err1; // expected-error {{expected '<' after 
'template'}} \
-// expected-error{{extraneous}}
+// expected-note{{did you mean to use 'typename'?}}
 template  > struct Err2;   // cpp14-error {{template 
template parameter requires 'class' after the parameter list}}
 // cpp17-error@-1{{template template parameter requires 'class' or 'typename' 
after the parameter list}}
 template  Foo> struct Err3;// cpp14-error {{template 
template parameter requires 'class' after the parameter list}}

>From 35840e8fd58d3dfa0db424d55eedc1d666d10505 Mon Sep 17 00:00:00 2001
From: Veeloxfire <58116051+veeloxf...@users.noreply.github.com>
Date: Mon, 17 Jun 2024 12:18:48 +0100
Subject: [PATCH 2/3] [clang][Parser] Check for actual failure condition

`ahead.isNot(tok::less)` is the actual failure condition of the parse, so check 
for that instead of trying to match all the possible alternatives
---
 clang/lib/Parse/ParseTemplate.cpp | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index e5308d9edac5f..381c57536e755 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -787,10 +787,7 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
-  if (Token ahead = GetLookAheadToken(1);
-  ahead.isOneOf(tok::identifier, tok::ellipsis,
-tok::equal, tok::comma,
-tok::greater, tok::greatergreater, 
tok::greatergreatergreater)) {
+  if (Token ahead = GetLookAheadToke

[clang] [clang][Interp] Implement complex division (PR #94892)

2024-06-17 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Ping

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


[clang] [clang][Interp] Implement Complex-complex multiplication (PR #94891)

2024-06-17 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] 6d973b4 - [clang][CodeGen] Return RValue from `EmitVAArg` (#94635)

2024-06-17 Thread via cfe-commits

Author: Mariya Podchishchaeva
Date: 2024-06-17T13:29:20+02:00
New Revision: 6d973b4548e281d0b8e75e85833804bb45b6a0e8

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

LOG: [clang][CodeGen] Return RValue from `EmitVAArg` (#94635)

This should simplify handling of resulting value by the callers.

Added: 


Modified: 
clang/lib/CodeGen/ABIInfo.cpp
clang/lib/CodeGen/ABIInfo.h
clang/lib/CodeGen/ABIInfoImpl.cpp
clang/lib/CodeGen/ABIInfoImpl.h
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/CodeGen/CGExprComplex.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/Targets/AArch64.cpp
clang/lib/CodeGen/Targets/AMDGPU.cpp
clang/lib/CodeGen/Targets/ARC.cpp
clang/lib/CodeGen/Targets/ARM.cpp
clang/lib/CodeGen/Targets/CSKY.cpp
clang/lib/CodeGen/Targets/Hexagon.cpp
clang/lib/CodeGen/Targets/LoongArch.cpp
clang/lib/CodeGen/Targets/MSP430.cpp
clang/lib/CodeGen/Targets/Mips.cpp
clang/lib/CodeGen/Targets/NVPTX.cpp
clang/lib/CodeGen/Targets/PNaCl.cpp
clang/lib/CodeGen/Targets/PPC.cpp
clang/lib/CodeGen/Targets/RISCV.cpp
clang/lib/CodeGen/Targets/Sparc.cpp
clang/lib/CodeGen/Targets/SystemZ.cpp
clang/lib/CodeGen/Targets/WebAssembly.cpp
clang/lib/CodeGen/Targets/X86.cpp
clang/lib/CodeGen/Targets/XCore.cpp
clang/test/CodeGen/X86/x86_64-vaarg.c
clang/test/CodeGen/aarch64-varargs.c
clang/test/CodeGen/arm-abi-vector.c
clang/test/CodeGen/arm-vaarg.c
clang/test/CodeGen/mips-varargs.c
clang/test/CodeGenCXX/arm64-empty-struct.cpp
clang/test/CodeGenCXX/x86_32-vaarg.cpp
clang/test/CodeGenCXX/x86_64-vaarg.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/ABIInfo.cpp b/clang/lib/CodeGen/ABIInfo.cpp
index acaae9f8c3d84..edd7146dc1ac7 100644
--- a/clang/lib/CodeGen/ABIInfo.cpp
+++ b/clang/lib/CodeGen/ABIInfo.cpp
@@ -39,9 +39,9 @@ bool ABIInfo::isOHOSFamily() const {
   return getTarget().getTriple().isOHOSFamily();
 }
 
-Address ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
- QualType Ty) const {
-  return Address::invalid();
+RValue ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty, AggValueSlot Slot) const {
+  return RValue::getIgnored();
 }
 
 bool ABIInfo::isHomogeneousAggregateBaseType(QualType Ty) const {

diff  --git a/clang/lib/CodeGen/ABIInfo.h b/clang/lib/CodeGen/ABIInfo.h
index ff4ae44a42c33..b8a8de57e5b97 100644
--- a/clang/lib/CodeGen/ABIInfo.h
+++ b/clang/lib/CodeGen/ABIInfo.h
@@ -34,6 +34,8 @@ class CGCXXABI;
 class CGFunctionInfo;
 class CodeGenFunction;
 class CodeGenTypes;
+class RValue;
+class AggValueSlot;
 
 // FIXME: All of this stuff should be part of the target interface
 // somehow. It is currently here because it is not clear how to factor
@@ -75,18 +77,18 @@ class ABIInfo {
   // the ABI information any lower than CodeGen. Of course, for
   // VAArg handling it has to be at this level; there is no way to
   // abstract this out.
-  virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF,
- CodeGen::Address VAListAddr,
- QualType Ty) const = 0;
+  virtual RValue EmitVAArg(CodeGen::CodeGenFunction &CGF,
+   CodeGen::Address VAListAddr, QualType Ty,
+   AggValueSlot Slot) const = 0;
 
   bool isAndroid() const;
   bool isOHOSFamily() const;
 
   /// Emit the target dependent code to load a value of
   /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
-  virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
-   CodeGen::Address VAListAddr,
-   QualType Ty) const;
+  virtual RValue EmitMSVAArg(CodeGen::CodeGenFunction &CGF,
+ CodeGen::Address VAListAddr, QualType Ty,
+ AggValueSlot Slot) const;
 
   virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
 

diff  --git a/clang/lib/CodeGen/ABIInfoImpl.cpp 
b/clang/lib/CodeGen/ABIInfoImpl.cpp
index eb627a3c043bc..e9a26abb77837 100644
--- a/clang/lib/CodeGen/ABIInfoImpl.cpp
+++ b/clang/lib/CodeGen/ABIInfoImpl.cpp
@@ -71,9 +71,12 @@ void DefaultABIInfo::computeInfo(CGFunctionInfo &FI) const {
 I.info = classifyArgumentType(I.type);
 }
 
-Address DefaultABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
-  QualType Ty) const {
-  return EmitVAArgInstr(CGF, VAListAddr, Ty, classifyArgumentType(Ty));
+RValue DefaultABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
+  

[clang] [clang][CodeGen] Return RValue from `EmitVAArg` (PR #94635)

2024-06-17 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] c2d9f25 - [clang][CodeGen] Fix EmitInvariantStart for non-zero addrspace (#94346)

2024-06-17 Thread via cfe-commits

Author: Bruno De Fraine
Date: 2024-06-17T07:30:10-04:00
New Revision: c2d9f253e5a4074bb965e483cca2fe968b78693c

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

LOG: [clang][CodeGen] Fix EmitInvariantStart for non-zero addrspace (#94346)

The `llvm.invariant.start` intrinsic is already overloaded to work with
memory objects in any address space. We simply instantiate the intrinsic
with the appropriate pointer type.

Fixes #94345.

Co-authored-by: Vito Kortbeek 

Added: 


Modified: 
clang/lib/CodeGen/CGDeclCXX.cpp
clang/test/CodeGenCXX/init-invariant.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index a88bb2af59fee..e18b339b31d24 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -162,7 +162,8 @@ void CodeGenFunction::EmitInvariantStart(llvm::Constant 
*Addr, CharUnits Size) {
   // Grab the llvm.invariant.start intrinsic.
   llvm::Intrinsic::ID InvStartID = llvm::Intrinsic::invariant_start;
   // Overloaded address space type.
-  llvm::Type *ObjectPtr[1] = {Int8PtrTy};
+  assert(Addr->getType()->isPointerTy() && "Address must be a pointer");
+  llvm::Type *ObjectPtr[1] = {Addr->getType()};
   llvm::Function *InvariantStart = CGM.getIntrinsic(InvStartID, ObjectPtr);
 
   // Emit a call with the size in bytes of the object.

diff  --git a/clang/test/CodeGenCXX/init-invariant.cpp 
b/clang/test/CodeGenCXX/init-invariant.cpp
index fdd5753402ccb..974064b70a3c0 100644
--- a/clang/test/CodeGenCXX/init-invariant.cpp
+++ b/clang/test/CodeGenCXX/init-invariant.cpp
@@ -46,6 +46,8 @@ extern const C c = C();
 int f();
 // CHECK: @d ={{.*}} global i32 0
 extern const int d = f();
+// CHECK: @d2 ={{.*}} addrspace(10) global i32 0
+extern const int __attribute__((address_space(10))) d2 = f();
 
 void e() {
   static const A a = A();
@@ -67,6 +69,10 @@ void e() {
 // CHECK: store {{.*}}, ptr @d
 // CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @d)
 
+// CHECK: call noundef i32 @_Z1fv(
+// CHECK: store {{.*}}, ptr addrspace(10) @d2
+// CHECK: call {{.*}}@llvm.invariant.start.p10(i64 4, ptr addrspace(10) @d2)
+
 // CHECK-LABEL: define{{.*}} void @_Z1ev(
 // CHECK: call void @_ZN1AC1Ev(ptr noundef {{[^,]*}} @_ZZ1evE1a)
 // CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr {{.*}}@_ZZ1evE1a)



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


[clang] [clang][CodeGen] Fix EmitInvariantStart for non-zero addrspace (PR #94346)

2024-06-17 Thread Aaron Ballman via cfe-commits

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits

https://github.com/Veeloxfire updated 
https://github.com/llvm/llvm-project/pull/95726

>From 44620330cd5238de549d3d77ddc447cd3bc51e60 Mon Sep 17 00:00:00 2001
From: Veeloxfire <58116051+veeloxf...@users.noreply.github.com>
Date: Mon, 17 Jun 2024 01:20:32 +0100
Subject: [PATCH 1/4] [clang][Parser] "Better" error messages for invalid
 template template

For the somewhat easy mistake of `template ...` clang outputs a 
partially cryptic error
Change this to assume the programmer intended `typename` in cases where 
`template` is illegal, and emit diagnostics (and forward parsing) accordingly
This mirrors the behaviour of `typedef` handling
---
 clang/lib/Parse/ParseTemplate.cpp   | 17 +
 clang/test/CXX/drs/cwg1xx.cpp   |  2 ++
 clang/test/Parser/cxx-template-decl.cpp |  2 +-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index a5130f56600e5..e5308d9edac5f 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -787,6 +787,23 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
+  if (Token ahead = GetLookAheadToken(1);
+  ahead.isOneOf(tok::identifier, tok::ellipsis,
+tok::equal, tok::comma,
+tok::greater, tok::greatergreater, 
tok::greatergreatergreater)) {
+// Maybe they intended `typename` instead of `template` (given thats more 
common)
+// Error early, to add a fixit hint
+
+Diag(ahead.getLocation(), diag::err_expected_less_after) << "template";
+
+Diag(Tok.getLocation(), diag::note_meant_to_use_typename)
+  << 
FixItHint::CreateReplacement(CharSourceRange::getTokenRange(Tok.getLocation()),
+  "typename");
+
+Tok.setKind(tok::kw_typename);
+return ParseTypeParameter(Depth, Position);
+  }
+
   // Handle the template <...> part.
   SourceLocation TemplateLoc = ConsumeToken();
   SmallVector TemplateParams;
diff --git a/clang/test/CXX/drs/cwg1xx.cpp b/clang/test/CXX/drs/cwg1xx.cpp
index e71ea9278..72b3ff40152d5 100644
--- a/clang/test/CXX/drs/cwg1xx.cpp
+++ b/clang/test/CXX/drs/cwg1xx.cpp
@@ -1145,8 +1145,10 @@ namespace cwg181 { // cwg181: yes
   namespace X {
 template  > struct A { };
 // expected-error@-1 +{{}}
+//  expected-note@-2 {{did you mean to use 'typename'?}}
 template  > void f(A) { }
 // expected-error@-1 +{{}}
+//  expected-note@-2 {{did you mean to use 'typename'?}}
   }
 
   namespace Y {
diff --git a/clang/test/Parser/cxx-template-decl.cpp 
b/clang/test/Parser/cxx-template-decl.cpp
index 734438069b9ae..69b9ab012b478 100644
--- a/clang/test/Parser/cxx-template-decl.cpp
+++ b/clang/test/Parser/cxx-template-decl.cpp
@@ -22,7 +22,7 @@ template> struct x3; // expected-error 
{{expected ',' or '>' in t
  cpp14-error {{template template 
parameter requires 'class' after the parameter list}} \
  cpp17-error {{template template 
parameter requires 'class' or 'typename' after the parameter list}}
 template  struct Err1; // expected-error {{expected '<' after 
'template'}} \
-// expected-error{{extraneous}}
+// expected-note{{did you mean to use 'typename'?}}
 template  > struct Err2;   // cpp14-error {{template 
template parameter requires 'class' after the parameter list}}
 // cpp17-error@-1{{template template parameter requires 'class' or 'typename' 
after the parameter list}}
 template  Foo> struct Err3;// cpp14-error {{template 
template parameter requires 'class' after the parameter list}}

>From 35840e8fd58d3dfa0db424d55eedc1d666d10505 Mon Sep 17 00:00:00 2001
From: Veeloxfire <58116051+veeloxf...@users.noreply.github.com>
Date: Mon, 17 Jun 2024 12:18:48 +0100
Subject: [PATCH 2/4] [clang][Parser] Check for actual failure condition

`ahead.isNot(tok::less)` is the actual failure condition of the parse, so check 
for that instead of trying to match all the possible alternatives
---
 clang/lib/Parse/ParseTemplate.cpp | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index e5308d9edac5f..381c57536e755 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -787,10 +787,7 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
-  if (Token ahead = GetLookAheadToken(1);
-  ahead.isOneOf(tok::identifier, tok::ellipsis,
-tok::equal, tok::comma,
-tok::greater, tok::greatergreater, 
tok::greatergreatergreater)) {
+  if (Token ahead = GetLookAheadToke

[clang] [Clang] disallow non-lvalue values in constant expressions to prevent invalid pointer offset computation (PR #95479)

2024-06-17 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/95479

>From 125d9cdd617d6415ef24eb785fe22705149f2d01 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 14 Jun 2024 01:26:34 +0300
Subject: [PATCH 1/5] [Clang] disallow non-lvalue values in constant
 expressions to prevent invalid pointer offset computation

---
 clang/docs/ReleaseNotes.rst   | 1 +
 clang/lib/AST/ExprConstant.cpp| 3 +++
 clang/test/Sema/integral-to-ptr.c | 3 +++
 3 files changed, 7 insertions(+)
 create mode 100644 clang/test/Sema/integral-to-ptr.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8c2f737836a9d..77906360b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -847,6 +847,7 @@ Bug Fixes to C++ Support
 - Fixed several bugs in capturing variables within unevaluated contexts. 
(#GH63845), (#GH67260), (#GH69307),
   (#GH88081), (#GH89496), (#GH90669) and (#GH91633).
 - Fixed handling of brace ellison when building deduction guides. (#GH64625), 
(#GH83368).
+- Fix an assertion failure caused by non-lvalue usage in lvalue context. 
(GH95366).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 7178f081d9cf3..08bee806f172f 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
   Result.IsNullPtr = false;
   return true;
 } else {
+  if (!Value.isLValue())
+return false;
+
   // Cast is of an lvalue, no need to change value.
   Result.setFrom(Info.Ctx, Value);
   return true;
diff --git a/clang/test/Sema/integral-to-ptr.c 
b/clang/test/Sema/integral-to-ptr.c
new file mode 100644
index 0..99f83c3e52057
--- /dev/null
+++ b/clang/test/Sema/integral-to-ptr.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11
+
+int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered 
comparison between pointer and integer ('long' and 'int (*)(void)')}}

>From b73cf0659a115f29c7b224a8f89ab519dac01a13 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 14 Jun 2024 08:50:03 +0300
Subject: [PATCH 2/5] update test expectations

---
 clang/test/Sema/integral-to-ptr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/integral-to-ptr.c 
b/clang/test/Sema/integral-to-ptr.c
index 99f83c3e52057..b8ab4cb79820d 100644
--- a/clang/test/Sema/integral-to-ptr.c
+++ b/clang/test/Sema/integral-to-ptr.c
@@ -1,3 +1,3 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11
 
-int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered 
comparison between pointer and integer ('long' and 'int (*)(void)')}}
+int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered 
comparison between pointer and integer}}

>From 78fc56a0aab96984760a3874e06e51259b599bd5 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 14 Jun 2024 18:16:34 +0300
Subject: [PATCH 3/5] add detailed comment

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

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 08bee806f172f..712c3062eb9ac 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -9325,6 +9325,10 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
   Result.IsNullPtr = false;
   return true;
 } else {
+  // In rare instances, the value isn't an lvalue.
+  // For example, when the value is the difference between the addresses of
+  // two labels. We reject that as a constant expression because we can't
+  // compute a valid offset to convert into a pointer.
   if (!Value.isLValue())
 return false;
 

>From 7e3af56b7fbb43041f81c982cee712f516ecc6f1 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 14 Jun 2024 18:16:58 +0300
Subject: [PATCH 4/5] update changelog message

---
 clang/docs/ReleaseNotes.rst | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 77906360b..efd17d8f9a089 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -847,7 +847,8 @@ Bug Fixes to C++ Support
 - Fixed several bugs in capturing variables within unevaluated contexts. 
(#GH63845), (#GH67260), (#GH69307),
   (#GH88081), (#GH89496), (#GH90669) and (#GH91633).
 - Fixed handling of brace ellison when building deduction guides. (#GH64625), 
(#GH83368).
-- Fix an assertion failure caused by non-lvalue usage in lvalue context. 
(GH95366).
+- Fixed a failed assertion when attempting to convert an integer representing 
the difference
+  between the addresses of two labels (a GNU extension) to a pointer within a 
constant expression. (GH95366).
 
 Bug Fixes to AST Handling
 ^

>From 6408619fd0b0a3f06dcd096719

[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits

Veeloxfire wrote:

Sorry for the extra reformatting commit, I somehow missed the original 
formatting suggestions (I dont know how I didnt notice the 1 space indent 
originally)

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


[clang] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (PR #94542)

2024-06-17 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/94542

>From da4df73607a9edefc8db721818eff50e974a0637 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 6 Jun 2024 01:55:54 +0300
Subject: [PATCH] [Clang] skip alignment checks on incomplete types to avoid an
 assertion failure while parsing lambda used as default argument

---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Sema/SemaStmt.cpp| 2 +-
 clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++
 3 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 39a9013c75a41..819fe1811ddaf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -840,6 +840,8 @@ Bug Fixes to C++ Support
 - Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
 - Fixed several bugs in capturing variables within unevaluated contexts. 
(#GH63845), (#GH67260), (#GH69307),
   (#GH88081), (#GH89496), (#GH90669) and (#GH91633).
+- Fix an assertion failure caused by parsing a lambda used as a default 
argument for the value of a
+  forward-declared class. (#GH93512).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 57465d4a77ac2..56f69dd50f361 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const 
VarDecl *VD) {
 
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
-  if (!VD->hasDependentAlignment() &&
+  if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() &&
   Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType))
 Info.S = NamedReturnInfo::MoveEligible;
 
diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp 
b/clang/test/SemaCXX/lambda-as-default-parameter.cpp
new file mode 100644
index 0..1f07a7f5644b7
--- /dev/null
+++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+struct a; // expected-note {{forward declaration of 'a'}} \
+ expected-note {{forward declaration of 'a'}}
+void b(a c = [] { return c; }); // expected-error {{initialization of 
incomplete type 'a'}} \
+   expected-error {{variable has incomplete 
type 'a'}}

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits

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

LGTM after fixing two more minor things I only noticed just now.

Also, this needs a release note (in `clang/docs/ReleaseNotes.rst`, probably in 
the section ‘Improvements to Clang’s Diagnostics’ or whatever it was called).

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits


@@ -787,6 +787,20 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
+  if (Token ahead = GetLookAheadToken(1); ahead.isNot(tok::less)) {

Sirraide wrote:

One more thing, I somehow forgot to comment on this earlier, but we typically 
use PascalCase for variables, so this should be `Ahead` (though I’d probably 
call it `Next` or sth, but that’s not that important...).

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits


@@ -787,6 +787,20 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
+  if (Token ahead = GetLookAheadToken(1); ahead.isNot(tok::less)) {
+// Maybe they intended `typename` instead of `template` (given thats more
+// common) Error early, to add a fixit hint

Sirraide wrote:

```suggestion
// `template` may have been a typo for `typename`, given that the
// latter is more common.
```
nit: the comment could be cleaned up a bit, maybe like this

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits


@@ -787,6 +787,20 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
+  if (Token ahead = GetLookAheadToken(1); ahead.isNot(tok::less)) {

Veeloxfire wrote:

Oh yes sorry!

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits


@@ -787,6 +787,20 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
+  if (Token ahead = GetLookAheadToken(1); ahead.isNot(tok::less)) {
+// Maybe they intended `typename` instead of `template` (given thats more
+// common) Error early, to add a fixit hint

Veeloxfire wrote:

Ah yes that comment is more consistent with other wording I've seen, thanks for 
the suggestion

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


[clang] [clang][CodeGen] Add query for a target's flat address space (PR #95728)

2024-06-17 Thread Alex Voicu via cfe-commits


@@ -1764,6 +1764,13 @@ class TargetInfo : public TransferrableTargetInfo,
 return 0;
   }
 
+  /// \returns Target specific flat ptr address space; a flat ptr is a ptr that
+  /// can be casted to / from all other target address spaces. If the target
+  /// exposes no such address space / does not care, we return 0.

AlexVlx wrote:

There's no such thing as LangAS::Generic, there's LangAS::Default. Default 
doesn't have to map to something that's actually useful, and it actually does 
not. There's no actual mechanism to get a flat pointer. And I have no idea what 
notion spreading you are talking about - this merely maintains the status quo, 
wherein everybody grabs an AS 0 pointer and hopes for the best. So I have no 
idea what you are talking about, if I'm honest.

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


[clang] [lldb] [clang][lldb] Don't assert structure layout correctness for layouts provided by LLDB (PR #93809)

2024-06-17 Thread Michael Buch via cfe-commits

Michael137 wrote:

> > > The correct answer here is probably to fix the sizes in the RecordLayout 
> > > itself; in particular, the DataSize of the members.
> > 
> > 
> > That would be ideal, but also means we'd have to reflect the various C++ 
> > attributes that affect layout in DWARF. Avoiding adding such 
> > language-specific constructs to DWARF is what partly motivated this patch.
> 
> Given the offsets and sizes of the members of a struct, you can compute the 
> datasize as the offset plus the size of the last member. That isn't really 
> correct for POD structs, but the CGRecordLayout won't care: it can't tell the 
> difference between padding that's illegal to reuse, vs. padding that the 
> frontend chose not to reuse for some other reason.

Just got back to looking at this again. Haven't fully figured out yet why the 
AST and LLVM layouts in the LLDB case don't seem to be consistent. Though the 
asserts that iterate over `Members` and `FieldTypes` fail because those 
structures are filled out conditionally on `isZeroSize()` (which in the LLDB 
case won't work because we don't have that information in the AST, i.e., the 
`[[no_unique_address]]` attribute).

Interestingly, I only just found out about the `-foverride-record-layout=` 
flag, which seems like a neat way of testing externally provided layouts. I 
compiled the test attached to this patch but using the layout that LLDB 
computes. Then compared the `dump-record-layouts` output to the one that Clang 
generates without externally provided layouts.

```
$ ./bin/clang -cc1 
~/Git/llvm-project/clang/test/CodeGenCXX/override-layout-no_unique_address.cpp 
-w -std=c++14 -fdump-record-layouts-simple -DNUA= 
-foverride-record-layout=nua.lldb > nua.lldb.after
michaelbuch@Michaels-MacBook-Pro-6:~/Git/lldb-build-main-rel
$ diff nua.lldb.after nua.before 
52c52
<   Alignment:8
---
>   Alignment:64
```
Interestingly the only difference here is the alignment computed for `Foo`.

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits


@@ -787,6 +787,20 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
+  if (Token ahead = GetLookAheadToken(1); ahead.isNot(tok::less)) {

Veeloxfire wrote:

Actually this prompted me to check and I was just writing `NextToken()` 
manually (didnt realise `GetLookAheadToken` did a `-1`), so I think I'll switch 
it to `NextToken()` instead.
Then the renaming makes sense too with `Token Next = NextToken();`

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits


@@ -787,6 +787,20 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
+  if (Token ahead = GetLookAheadToken(1); ahead.isNot(tok::less)) {

Sirraide wrote:

Ah yes, you can tell I don’t review parser code too often because I probably 
should have noticed that haha.

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


[clang] [clang][CodeGen] Add query for a target's flat address space (PR #95728)

2024-06-17 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/95728

>From 2b500ad9ef2baf27da29146b5a4123dcb75e Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Mon, 17 Jun 2024 02:15:00 +0100
Subject: [PATCH 1/2] Add interface for exposing a target's flat address space,
 if it exists.

---
 clang/include/clang/Basic/TargetInfo.h | 7 +++
 clang/lib/Basic/Targets/AMDGPU.h   | 6 ++
 clang/lib/Basic/Targets/SPIR.h | 4 
 3 files changed, 17 insertions(+)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 8a6511b9ced83..8841ec5f910d9 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1764,6 +1764,13 @@ class TargetInfo : public TransferrableTargetInfo,
 return 0;
   }
 
+  /// \returns Target specific flat ptr address space; a flat ptr is a ptr that
+  /// can be casted to / from all other target address spaces. If the target
+  /// exposes no such address space / does not care, we return 0.
+  virtual unsigned getFlatPtrAddressSpace() const {
+return 0;
+  }
+
   /// \returns If a target requires an address within a target specific address
   /// space \p AddressSpace to be converted in order to be used, then return 
the
   /// corresponding target specific DWARF address space.
diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index 94d9ba93ed226..d06c7d58fe94c 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -379,6 +379,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
 return static_cast(llvm::AMDGPUAS::CONSTANT_ADDRESS);
   }
 
+  /// \returns Target specific flat ptr address space; a flat ptr is a ptr that
+  /// can be casted to / from all other target address spaces.
+  unsigned getFlatPtrAddressSpace() const override {
+return static_cast(llvm::AMDGPUAS::FLAT_ADDRESS);
+  }
+
   /// \returns If a target requires an address within a target specific address
   /// space \p AddressSpace to be converted in order to be used, then return 
the
   /// corresponding target specific DWARF address space.
diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
index 37cf9d7921bac..14d235bace960 100644
--- a/clang/lib/Basic/Targets/SPIR.h
+++ b/clang/lib/Basic/Targets/SPIR.h
@@ -182,6 +182,10 @@ class LLVM_LIBRARY_VISIBILITY BaseSPIRTargetInfo : public 
TargetInfo {
 return TargetInfo::VoidPtrBuiltinVaList;
   }
 
+  unsigned getFlatPtrAddressSpace() const override {
+return 4u; // 4 is generic i.e. flat for SPIR & SPIR-V.
+  }
+
   std::optional
   getDWARFAddressSpace(unsigned AddressSpace) const override {
 return AddressSpace;

>From 346877d118700a748bffa8b0aee8633d6991582c Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Mon, 17 Jun 2024 12:58:04 +0100
Subject: [PATCH 2/2] Fix formatting.

---
 clang/include/clang/Basic/TargetInfo.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 8841ec5f910d9..a3b60db122cae 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1767,9 +1767,7 @@ class TargetInfo : public TransferrableTargetInfo,
   /// \returns Target specific flat ptr address space; a flat ptr is a ptr that
   /// can be casted to / from all other target address spaces. If the target
   /// exposes no such address space / does not care, we return 0.
-  virtual unsigned getFlatPtrAddressSpace() const {
-return 0;
-  }
+  virtual unsigned getFlatPtrAddressSpace() const { return 0; }
 
   /// \returns If a target requires an address within a target specific address
   /// space \p AddressSpace to be converted in order to be used, then return 
the

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


[clang-tools-extra] [clangd] Add inlay hints for default function arguments and implicit lambda captures (PR #95712)

2024-06-17 Thread Tor Shepherd via cfe-commits

torshepherd wrote:

Aha, that's a great suggestion. I agree that beyond the trivial case of 2 
captured variables it gets a bit noisy. On-hover would be quite nice though!

To clarify, you mean hovering over the default capture '=' or '&' right?

I'm happy to remove the lambdas from this PR in favor of the hover approach. 
Thoughts on the default arguments?

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


[clang-tools-extra] [clangd] Add inlay hints for default function arguments and implicit lambda captures (PR #95712)

2024-06-17 Thread Tor Shepherd via cfe-commits


@@ -15,9 +15,12 @@
 #include "support/Context.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/raw_ostream.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 #include 
+#include 

torshepherd wrote:

I believe std::move - let me check if they're still used in the latest revision 
though

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits

https://github.com/Veeloxfire updated 
https://github.com/llvm/llvm-project/pull/95726

>From 44620330cd5238de549d3d77ddc447cd3bc51e60 Mon Sep 17 00:00:00 2001
From: Veeloxfire <58116051+veeloxf...@users.noreply.github.com>
Date: Mon, 17 Jun 2024 01:20:32 +0100
Subject: [PATCH 1/5] [clang][Parser] "Better" error messages for invalid
 template template

For the somewhat easy mistake of `template ...` clang outputs a 
partially cryptic error
Change this to assume the programmer intended `typename` in cases where 
`template` is illegal, and emit diagnostics (and forward parsing) accordingly
This mirrors the behaviour of `typedef` handling
---
 clang/lib/Parse/ParseTemplate.cpp   | 17 +
 clang/test/CXX/drs/cwg1xx.cpp   |  2 ++
 clang/test/Parser/cxx-template-decl.cpp |  2 +-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index a5130f56600e5..e5308d9edac5f 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -787,6 +787,23 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
+  if (Token ahead = GetLookAheadToken(1);
+  ahead.isOneOf(tok::identifier, tok::ellipsis,
+tok::equal, tok::comma,
+tok::greater, tok::greatergreater, 
tok::greatergreatergreater)) {
+// Maybe they intended `typename` instead of `template` (given thats more 
common)
+// Error early, to add a fixit hint
+
+Diag(ahead.getLocation(), diag::err_expected_less_after) << "template";
+
+Diag(Tok.getLocation(), diag::note_meant_to_use_typename)
+  << 
FixItHint::CreateReplacement(CharSourceRange::getTokenRange(Tok.getLocation()),
+  "typename");
+
+Tok.setKind(tok::kw_typename);
+return ParseTypeParameter(Depth, Position);
+  }
+
   // Handle the template <...> part.
   SourceLocation TemplateLoc = ConsumeToken();
   SmallVector TemplateParams;
diff --git a/clang/test/CXX/drs/cwg1xx.cpp b/clang/test/CXX/drs/cwg1xx.cpp
index e71ea9278..72b3ff40152d5 100644
--- a/clang/test/CXX/drs/cwg1xx.cpp
+++ b/clang/test/CXX/drs/cwg1xx.cpp
@@ -1145,8 +1145,10 @@ namespace cwg181 { // cwg181: yes
   namespace X {
 template  > struct A { };
 // expected-error@-1 +{{}}
+//  expected-note@-2 {{did you mean to use 'typename'?}}
 template  > void f(A) { }
 // expected-error@-1 +{{}}
+//  expected-note@-2 {{did you mean to use 'typename'?}}
   }
 
   namespace Y {
diff --git a/clang/test/Parser/cxx-template-decl.cpp 
b/clang/test/Parser/cxx-template-decl.cpp
index 734438069b9ae..69b9ab012b478 100644
--- a/clang/test/Parser/cxx-template-decl.cpp
+++ b/clang/test/Parser/cxx-template-decl.cpp
@@ -22,7 +22,7 @@ template> struct x3; // expected-error 
{{expected ',' or '>' in t
  cpp14-error {{template template 
parameter requires 'class' after the parameter list}} \
  cpp17-error {{template template 
parameter requires 'class' or 'typename' after the parameter list}}
 template  struct Err1; // expected-error {{expected '<' after 
'template'}} \
-// expected-error{{extraneous}}
+// expected-note{{did you mean to use 'typename'?}}
 template  > struct Err2;   // cpp14-error {{template 
template parameter requires 'class' after the parameter list}}
 // cpp17-error@-1{{template template parameter requires 'class' or 'typename' 
after the parameter list}}
 template  Foo> struct Err3;// cpp14-error {{template 
template parameter requires 'class' after the parameter list}}

>From 35840e8fd58d3dfa0db424d55eedc1d666d10505 Mon Sep 17 00:00:00 2001
From: Veeloxfire <58116051+veeloxf...@users.noreply.github.com>
Date: Mon, 17 Jun 2024 12:18:48 +0100
Subject: [PATCH 2/5] [clang][Parser] Check for actual failure condition

`ahead.isNot(tok::less)` is the actual failure condition of the parse, so check 
for that instead of trying to match all the possible alternatives
---
 clang/lib/Parse/ParseTemplate.cpp | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index e5308d9edac5f..381c57536e755 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -787,10 +787,7 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned 
Depth,
   unsigned Position) {
   assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
 
-  if (Token ahead = GetLookAheadToken(1);
-  ahead.isOneOf(tok::identifier, tok::ellipsis,
-tok::equal, tok::comma,
-tok::greater, tok::greatergreater, 
tok::greatergreatergreater)) {
+  if (Token ahead = GetLookAheadToke

[clang-tools-extra] [clangd] Add inlay hints for default function arguments and implicit lambda captures (PR #95712)

2024-06-17 Thread Tor Shepherd via cfe-commits


@@ -1458,13 +1463,66 @@ TEST(TypeHints, DefaultTemplateArgs) {
 struct A {};
 A foo();
 auto $var[[var]] = foo();
-A bar[1];
+A baz;
+A bar[1]{};

torshepherd wrote:

My fault, an artifact from a different set of inlay hints I decided not to 
include (show implicit default constructions with '{}')

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


[clang-tools-extra] [clangd] Add inlay hints for default function arguments and implicit lambda captures (PR #95712)

2024-06-17 Thread Tor Shepherd via cfe-commits


@@ -1568,7 +1626,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
   )cpp";
 
   llvm::StringRef VectorIntPtr = R"cpp(
-vector array;
+vector $init[[array]];

torshepherd wrote:

Another artifact, sorry

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


[clang-tools-extra] [clangd] Add inlay hints for default function arguments and implicit lambda captures (PR #95712)

2024-06-17 Thread Tor Shepherd via cfe-commits


@@ -504,10 +503,10 @@ struct FragmentCompiler {
   auto Fast = isFastTidyCheck(Str);
   if (!Fast.has_value()) {
 diag(Warning,
- llvm::formatv(
- "Latency of clang-tidy check '{0}' is not known. "
- "It will only run if ClangTidy.FastCheckFilter is Loose or 
None",
- Str)
+ llvm::formatv("Latency of clang-tidy check '{0}' is not known. "
+   "It will only run if ClangTidy.FastCheckFilter is "
+   "Loose or None",
+   Str)

torshepherd wrote:

Sorry, I think this was the formatter messing with it

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


[clang] [llvm] [AMDGPU][WIP] Extend permlane16, permlanex16 and permlane64 intrinsic lowering for generic types (PR #92725)

2024-06-17 Thread Vikram Hegde via cfe-commits


@@ -18479,6 +18479,28 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 CGM.getIntrinsic(Intrinsic::amdgcn_update_dpp, Args[0]->getType());
 return Builder.CreateCall(F, Args);
   }
+  case AMDGPU::BI__builtin_amdgcn_permlane16:
+  case AMDGPU::BI__builtin_amdgcn_permlanex16: {
+llvm::Value *Src0 = EmitScalarExpr(E->getArg(0));

vikramRH wrote:

added a new helper

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


[clang] [Serialization] Use specialized decl hash function for GlobalDeclID (PR #95730)

2024-06-17 Thread Ilya Biryukov via cfe-commits

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


[clang] [Serialization] Use specialized decl hash function for GlobalDeclID (PR #95730)

2024-06-17 Thread Ilya Biryukov via cfe-commits


@@ -230,7 +230,11 @@ template <> struct DenseMapInfo {
   }
 
   static unsigned getHashValue(const GlobalDeclID &Key) {
-return DenseMapInfo::getHashValue(Key.get());
+// Our default hash algorithm for 64 bits integer may not be very good.

ilya-biryukov wrote:

NIT: could you add a FIXME to remove this after we update the hash functions?

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


[clang] [llvm] [AMDGPU][WIP] Extend permlane16, permlanex16 and permlane64 intrinsic lowering for generic types (PR #92725)

2024-06-17 Thread Vikram Hegde via cfe-commits

vikramRH wrote:

Updated this PR to be in sync with #89217, However still plan is to land this 
land this only after changes in #89217 are accepted.

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


[clang-tools-extra] [clangd] Add inlay hints for default function arguments and implicit lambda captures (PR #95712)

2024-06-17 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

> To clarify, you mean hovering over the default capture '=' or '&' right?

Yep, that's what I thought.

> I'm happy to remove the lambdas from this PR in favor of the hover approach.

No worries, but let's wait for other reviewers' opinions before we move 
forward. :)

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


[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)

2024-06-17 Thread via cfe-commits

Veeloxfire wrote:

> Also, this needs a release note (in `clang/docs/ReleaseNotes.rst`, probably 
> in the section ‘Improvements to Clang’s Diagnostics’ or whatever it was 
> called).

So I dont end up making 100 commits rewording this:
How about "Clang now diagnoses template template paramter missing `<` as typo 
for `typename`"

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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-06-17 Thread Paul Heidekrüger via cfe-commits

https://github.com/PBHDK updated https://github.com/llvm/llvm-project/pull/95220

From 37292995de0c5aa87408586749795a97468d4725 Mon Sep 17 00:00:00 2001
From: Sebastian Wolf 
Date: Wed, 17 Apr 2024 16:16:35 +0200
Subject: [PATCH 01/17] Enforce SL.con.3: Add check to replace operator[] with
 at() on std containers

---
 .../AvoidBoundsErrorsCheck.cpp| 81 +++
 .../AvoidBoundsErrorsCheck.h  | 32 
 .../cppcoreguidelines/CMakeLists.txt  |  1 +
 .../CppCoreGuidelinesTidyModule.cpp   |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../cppcoreguidelines/avoid-bounds-errors.rst | 20 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../cppcoreguidelines/avoid-bounds-errors.cpp | 66 +++
 8 files changed, 209 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-bounds-errors.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-bounds-errors.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
new file mode 100644
index 0..524c21b5bdb81
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
@@ -0,0 +1,81 @@
+//===--- AvoidBoundsErrorsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "AvoidBoundsErrorsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+bool isApplicable(const QualType &Type) {
+  const auto TypeStr = Type.getAsString();
+  bool Result = false;
+  // Only check for containers in the std namespace
+  if (TypeStr.find("std::vector") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::array") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::deque") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::unordered_map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::flat_map") != std::string::npos) {
+Result = true;
+  }
+  // TODO Add std::span with C++26
+  return Result;
+}
+
+void AvoidBoundsErrorsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee(cxxMethodDecl(hasName("operator[]")).bind("f")))
+  .bind("x"),
+  this);
+}
+
+void AvoidBoundsErrorsCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Context = *Result.Context;
+  const SourceManager &Source = Context.getSourceManager();
+  const auto *MatchedExpr = Result.Nodes.getNodeAs("x");
+  const auto *MatchedFunction = Result.Nodes.getNodeAs("f");
+  const auto Type = MatchedFunction->getThisType();
+  if (!isApplicable(Type)) {
+return;
+  }
+
+  // Get original code.
+  const SourceLocation b(MatchedExpr->getBeginLoc());
+  const SourceLocation e(MatchedExpr->getEndLoc());
+  const std::string OriginalCode =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(b, e), Source,
+   getLangOpts())
+  .str();
+  const auto Range = SourceRange(b, e);
+
+  // Build replacement.
+  std::string NewCode = OriginalCode;
+  const auto BeginOpen = NewCode.find("[");
+  NewCode.replace(BeginOpen, 1, ".at(");
+  const auto BeginClose = NewCode.find("]");
+  NewCode.replace(BeginClose, 1, ")");
+
+  diag(MatchedExpr->getBeginLoc(), "Do not use operator[], use at() instead.")
+  << FixItHint::CreateReplacement(Range, NewCode);
+}
+
+} // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
new file mode 100644
index 0..f915729cd7bbe
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
@@ -0,0 +1,32 @@
+//===--- AvoidBoundsErrorsCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLV

  1   2   3   4   5   >