[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-24 Thread Rana Pratap Reddy via cfe-commits

https://github.com/ranapratap55 updated 
https://github.com/llvm/llvm-project/pull/69567

>From 536e4b5912f976b295bc2b507e4181c8a65f0d12 Mon Sep 17 00:00:00 2001
From: ranapratap55 
Date: Thu, 19 Oct 2023 12:52:13 +0530
Subject: [PATCH] [AMDGPU] Lower __builtin_read_exec_hi to use amdgcn_ballot

---
 clang/lib/CodeGen/CGBuiltin.cpp   | 20 +++-
 .../CodeGenOpenCL/builtins-amdgcn-wave32.cl   | 24 +++
 .../CodeGenOpenCL/builtins-amdgcn-wave64.cl   | 23 ++
 clang/test/CodeGenOpenCL/builtins-amdgcn.cl   |  4 +++-
 4 files changed, 64 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e1211bb8949b665..b5318ed41b10c53 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7997,13 +7997,20 @@ enum SpecialRegisterAccessKind {
 
 static Value *EmitAMDGCNBallotForExec(CodeGenFunction &CGF, const CallExpr *E,
   llvm::Type *RegisterType,
-  llvm::Type *ValueType) {
+  llvm::Type *ValueType, bool isExecHi) {
   CodeGen::CGBuilderTy &Builder = CGF.Builder;
   CodeGen::CodeGenModule &CGM = CGF.CGM;
 
-  llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
+  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
   llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+
+  if (isExecHi) {
+Value *C1 = llvm::ConstantInt::get(ValueType, 32);
+Value *Rt2 = Builder.CreateLShr(Call, C1);
+Rt2 = Builder.CreateTrunc(Rt2, CGF.Int32Ty);
+return Rt2;
+  }
+
   return Call;
 }
 
@@ -17857,10 +17864,11 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
   case AMDGPU::BI__builtin_amdgcn_read_exec:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, false);
   case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
-  case AMDGPU::BI__builtin_amdgcn_read_exec_hi: {
-return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty);
-  }
+return EmitAMDGCNBallotForExec(*this, E, Int32Ty, Int32Ty, false);
+  case AMDGPU::BI__builtin_amdgcn_read_exec_hi:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, true);
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
index a4d14cf1f6cf0bd..43553131f63c549 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
@@ -13,6 +13,8 @@ void test_ballot_wave32(global uint* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK: declare i32 @llvm.amdgcn.ballot.i32(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave32_target_attr(
 // CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 %{{.+}})
 __attribute__((target("wavefrontsize32")))
@@ -21,6 +23,28 @@ void test_ballot_wave32_target_attr(global uint* out, int a, 
int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK-LABEL: @test_read_exec(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+void test_read_exec(global uint* out) {
+  *out = __builtin_amdgcn_read_exec();
+}
+
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
+// CHECK-LABEL: @test_read_exec_lo(
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
+void test_read_exec_lo(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_lo();
+}
+
+// CHECK-LABEL: @test_read_exec_hi(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+// CHECK: lshr i64 [[A:%.*]], 32
+// CHECK: trunc i64 [[B:%.*]] to i32
+void test_read_exec_hi(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_hi();
+}
+
 #if __AMDGCN_WAVEFRONT_SIZE != 32
 #error Wrong wavesize detected
 #endif
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
index 563c9a2a240c1dc..53f34c6a44ae7dc 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
@@ -13,6 +13,8 @@ void test_ballot_wave64(global ulong* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave64_target_attr(
 // CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 %{{.+}})
 __attribute__((target("wavefrontsize64")))
@@ -21,6 +23,27 @@ void test_ballot_wave64_target_attr(global ulong* out, int 
a, int b)
   *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
+// CHECK-LABEL: @test_read_exec(
+// CHECK: call i64 @llvm.amdgcn.ba

[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-24 Thread Rana Pratap Reddy via cfe-commits


@@ -7997,14 +7997,26 @@ enum SpecialRegisterAccessKind {
 
 static Value *EmitAMDGCNBallotForExec(CodeGenFunction &CGF, const CallExpr *E,
   llvm::Type *RegisterType,
-  llvm::Type *ValueType) {
+  llvm::Type *ValueType, bool isExecHi) {
   CodeGen::CGBuilderTy &Builder = CGF.Builder;
   CodeGen::CodeGenModule &CGM = CGF.CGM;
 
   llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
-  llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
-  return Call;
+  llvm::Value *Call;
+  Function *F;
+
+  if (isExecHi) {
+F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
+Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+Value *C1 = llvm::ConstantInt::get(ValueType, 32);
+Value *Rt2 = Builder.CreateLShr(Call, C1);
+Rt2 = Builder.CreateTruncOrBitCast(Rt2, CGF.Int32Ty);

ranapratap55 wrote:

Updated in the latest patch.

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


[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-24 Thread Rana Pratap Reddy via cfe-commits


@@ -7997,14 +7997,26 @@ enum SpecialRegisterAccessKind {
 
 static Value *EmitAMDGCNBallotForExec(CodeGenFunction &CGF, const CallExpr *E,
   llvm::Type *RegisterType,
-  llvm::Type *ValueType) {
+  llvm::Type *ValueType, bool isExecHi) {
   CodeGen::CGBuilderTy &Builder = CGF.Builder;
   CodeGen::CodeGenModule &CGM = CGF.CGM;
 
   llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
-  llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
-  return Call;
+  llvm::Value *Call;
+  Function *F;
+
+  if (isExecHi) {
+F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
+Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+Value *C1 = llvm::ConstantInt::get(ValueType, 32);
+Value *Rt2 = Builder.CreateLShr(Call, C1);
+Rt2 = Builder.CreateTruncOrBitCast(Rt2, CGF.Int32Ty);
+return Rt2;
+  } else {
+F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
+Call = Builder.CreateCall(F, {Builder.getInt1(true)});

ranapratap55 wrote:

Updated.

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


[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-24 Thread Rana Pratap Reddy via cfe-commits


@@ -526,7 +526,9 @@ void test_read_exec_lo(global uint* out) {
 // CHECK: declare i32 @llvm.amdgcn.ballot.i32(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
 
 // CHECK-LABEL: @test_read_exec_hi(
-// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)

ranapratap55 wrote:

moved to respected wave32.cl and wave64.cl tests.

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


[clang] [JITLink][RISCV] Implement eh_frame handling (PR #68253)

2023-10-24 Thread Job Noorman via cfe-commits

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


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


[clang] b44763c - [clang][Interp] Fix scalar inits of void type (#69868)

2023-10-24 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-10-24T09:18:39+02:00
New Revision: b44763c5e690ddb61941ad56fb12f46e723b8071

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

LOG: [clang][Interp] Fix scalar inits of void type (#69868)

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d3e0d1112935a98..eb96f021258b114 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1597,8 +1597,12 @@ bool ByteCodeExprGen::VisitOffsetOfExpr(const 
OffsetOfExpr *E) {
 template 
 bool ByteCodeExprGen::VisitCXXScalarValueInitExpr(
 const CXXScalarValueInitExpr *E) {
-  return this->visitZeroInitializer(classifyPrim(E->getType()), E->getType(),
-E);
+  QualType Ty = E->getType();
+
+  if (Ty->isVoidType())
+return true;
+
+  return this->visitZeroInitializer(classifyPrim(Ty), Ty, E);
 }
 
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 6e8927518355dae..ba24955d14503be 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -56,6 +56,15 @@ namespace ScalarTypes {
   };
   static_assert(getScalar() == First, "");
   /// FIXME: Member pointers.
+
+#if __cplusplus >= 201402L
+  constexpr void Void(int n) {
+void(n + 1);
+void();
+  }
+  constexpr int void_test = (Void(0), 1);
+  static_assert(void_test == 1, "");
+#endif
 }
 
 namespace IntegralCasts {



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


[clang] [clang][Interp] Fix scalar inits of void type (PR #69868)

2023-10-24 Thread Timm Baeder via cfe-commits

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


[clang] c45466c - [clang][Interp] Only emit function_param_value_unknown in C++11 (#67990)

2023-10-24 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-10-24T09:28:30+02:00
New Revision: c45466cd9a51fe384d2b31e124b77d14c821eb70

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

LOG: [clang][Interp] Only emit function_param_value_unknown in C++11 (#67990)

This is also what the current interpreter does.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.cpp
clang/test/SemaCXX/offsetof.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index a4d6844ebe61722..8b0e7beb4a1acc1 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -555,8 +555,12 @@ bool CheckDeclRef(InterpState &S, CodePtr OpPC, const 
DeclRefExpr *DR) {
   const SourceInfo &E = S.Current->getSource(OpPC);
 
   if (isa(D)) {
-S.FFDiag(E, diag::note_constexpr_function_param_value_unknown) << D;
-S.Note(D->getLocation(), diag::note_declared_at) << D->getSourceRange();
+if (S.getLangOpts().CPlusPlus11) {
+  S.FFDiag(E, diag::note_constexpr_function_param_value_unknown) << D;
+  S.Note(D->getLocation(), diag::note_declared_at) << D->getSourceRange();
+} else {
+  S.FFDiag(E);
+}
   } else if (const auto *VD = dyn_cast(D)) {
 if (!VD->getType().isConstQualified()) {
   S.FFDiag(E,

diff  --git a/clang/test/SemaCXX/offsetof.cpp b/clang/test/SemaCXX/offsetof.cpp
index cb91f2bed0b9224..1722b91fafc8696 100644
--- a/clang/test/SemaCXX/offsetof.cpp
+++ b/clang/test/SemaCXX/offsetof.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify %s 
-Winvalid-offsetof -std=c++98
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only 
-verify=expected,new-interp %s -Winvalid-offsetof -std=c++98 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify %s 
-Winvalid-offsetof -std=c++98 -fexperimental-new-constant-interpreter
 
 struct NonPOD {
   virtual void f();
@@ -25,10 +25,9 @@ struct HasArray {
 };
 
 // Constant and non-constant offsetof expressions
-void test_ice(int i) { // new-interp-note {{declared here}}
+void test_ice(int i) {
   int array0[__builtin_offsetof(HasArray, array[5])];
-  int array1[__builtin_offsetof(HasArray, array[i])]; // expected-warning 
{{variable length arrays in C++ are a Clang extension}} \
- new-interp-note 
{{function parameter 'i' with unknown value cannot be used in a constant 
expression}}
+  int array1[__builtin_offsetof(HasArray, array[i])]; // expected-warning 
{{variable length arrays in C++ are a Clang extension}}
 }
 
 // Bitfields



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


[clang] [clang][Interp] Only emit function_param_value_unknown in C++11 (PR #67990)

2023-10-24 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-24 Thread Rana Pratap Reddy via cfe-commits

https://github.com/ranapratap55 updated 
https://github.com/llvm/llvm-project/pull/69567

>From c2ed656fa149a9cb60fb43eb34f4b20186166b34 Mon Sep 17 00:00:00 2001
From: ranapratap55 
Date: Thu, 19 Oct 2023 12:52:13 +0530
Subject: [PATCH] [AMDGPU] Lower __builtin_read_exec_hi to use amdgcn_ballot

---
 clang/lib/CodeGen/CGBuiltin.cpp   | 22 -
 .../CodeGenOpenCL/builtins-amdgcn-wave32.cl   | 24 +++
 .../CodeGenOpenCL/builtins-amdgcn-wave64.cl   | 23 ++
 clang/test/CodeGenOpenCL/builtins-amdgcn.cl   |  4 +++-
 4 files changed, 66 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e1211bb8949b665..02ed6b0c6e56673 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7995,15 +7995,24 @@ enum SpecialRegisterAccessKind {
   Write,
 };
 
+// Generated the IR for __builtin_read_exec_*.
+// Lowers the builtin to amdgcn_ballot intrinsic.
 static Value *EmitAMDGCNBallotForExec(CodeGenFunction &CGF, const CallExpr *E,
   llvm::Type *RegisterType,
-  llvm::Type *ValueType) {
+  llvm::Type *ValueType, bool isExecHi) {
   CodeGen::CGBuilderTy &Builder = CGF.Builder;
   CodeGen::CodeGenModule &CGM = CGF.CGM;
 
-  llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
+  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
   llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+
+  if (isExecHi) {
+Value *C1 = llvm::ConstantInt::get(ValueType, 32);
+Value *Rt2 = Builder.CreateLShr(Call, C1);
+Rt2 = Builder.CreateTrunc(Rt2, CGF.Int32Ty);
+return Rt2;
+  }
+
   return Call;
 }
 
@@ -17857,10 +17866,11 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
   case AMDGPU::BI__builtin_amdgcn_read_exec:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, false);
   case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
-  case AMDGPU::BI__builtin_amdgcn_read_exec_hi: {
-return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty);
-  }
+return EmitAMDGCNBallotForExec(*this, E, Int32Ty, Int32Ty, false);
+  case AMDGPU::BI__builtin_amdgcn_read_exec_hi:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, true);
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
index a4d14cf1f6cf0bd..43553131f63c549 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
@@ -13,6 +13,8 @@ void test_ballot_wave32(global uint* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK: declare i32 @llvm.amdgcn.ballot.i32(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave32_target_attr(
 // CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 %{{.+}})
 __attribute__((target("wavefrontsize32")))
@@ -21,6 +23,28 @@ void test_ballot_wave32_target_attr(global uint* out, int a, 
int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK-LABEL: @test_read_exec(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+void test_read_exec(global uint* out) {
+  *out = __builtin_amdgcn_read_exec();
+}
+
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
+// CHECK-LABEL: @test_read_exec_lo(
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
+void test_read_exec_lo(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_lo();
+}
+
+// CHECK-LABEL: @test_read_exec_hi(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+// CHECK: lshr i64 [[A:%.*]], 32
+// CHECK: trunc i64 [[B:%.*]] to i32
+void test_read_exec_hi(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_hi();
+}
+
 #if __AMDGCN_WAVEFRONT_SIZE != 32
 #error Wrong wavesize detected
 #endif
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
index 563c9a2a240c1dc..53f34c6a44ae7dc 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
@@ -13,6 +13,8 @@ void test_ballot_wave64(global ulong* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave64_target_attr(
 // CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 %{{.+}})
 __attribute__((target("wavefrontsize64")))
@@ -21,6 +23,27 @@ void test_ballot_wave64_target_attr(global ulong* out, int 
a, int b)
   *out

[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-24 Thread Owen Pan via cfe-commits

owenca wrote:

> I didn't expect you to not want to be credited, but I'll respect your opinion!

I meant you didn't need to add me to the authorship. 🙂 Anyway, I do appreciate 
it and think you should be the only author.

> GitHub adds co-ownership automatically if using the web ui to commit a 
> suggestion (which is what happened in that other PR you pinged me in), but in 
> this case I did add it manually :)

Ah, I didn't know that. Thanks for letting me know!

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


[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-24 Thread Endre Fülöp via cfe-commits

https://github.com/gamesh411 updated 
https://github.com/llvm/llvm-project/pull/67663

From 9aea93ddeb70245a07984188aa98577d54e8e560 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= 
Date: Fri, 8 Sep 2023 14:20:00 +0200
Subject: [PATCH 01/12] [analyzer][clangsa] Add new option to
 alpha.security.cert.InvalidPtrChecker

The invalidation of pointer pointers returned by subsequent calls to genenv is
suggested by the POSIX standard, but is too strict from a practical point of
view. A new checker option 'InvalidatingGetEnv' is introduced, and is set to a
more lax default value, which does not consider consecutive getenv calls
invalidating.
The handling of the main function's possible specification where an environment
pointer is also pecified as a third parameter is also considered now.

Differential Revision: https://reviews.llvm.org/D154603
---
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  9 ++
 .../Checkers/cert/InvalidPtrChecker.cpp   | 86 ++-
 clang/test/Analysis/analyzer-config.c |  1 +
 .../Analysis/cert/env34-c-cert-examples.c | 40 -
 clang/test/Analysis/cert/env34-c.c|  1 +
 clang/test/Analysis/invalid-ptr-checker.c | 50 +++
 6 files changed, 163 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/Analysis/invalid-ptr-checker.c

diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 65c1595eb6245dd..b4f65c934bf483b 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -997,6 +997,15 @@ let ParentPackage = ENV in {
 
   def InvalidPtrChecker : Checker<"InvalidPtr">,
   HelpText<"Finds usages of possibly invalidated pointers">,
+  CheckerOptions<[
+CmdLineOption,
+  ]>,
   Documentation;
 
 } // end "alpha.cert.env"
diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index aae1a17bc0ae53e..8849eb1148564b7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -38,6 +38,15 @@ class InvalidPtrChecker
 CheckerContext &C) const;
 
   // SEI CERT ENV31-C
+
+  // If set to true, consider getenv calls as invalidating operations on the
+  // environment variable buffer. This is implied in the standard, but in
+  // practice does not cause problems (in the commonly used environments).
+  bool InvalidatingGetEnv = false;
+
+  // GetEnv can be treated invalidating and non-invalidating as well.
+  const CallDescription GetEnvCall{{"getenv"}, 1};
+
   const CallDescriptionMap EnvpInvalidatingFunctions = {
   {{{"setenv"}, 3}, &InvalidPtrChecker::EnvpInvalidatingCall},
   {{{"unsetenv"}, 1}, &InvalidPtrChecker::EnvpInvalidatingCall},
@@ -51,7 +60,6 @@ class InvalidPtrChecker
 
   // SEI CERT ENV34-C
   const CallDescriptionMap PreviousCallInvalidatingFunctions = {
-  {{{"getenv"}, 1}, 
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   {{{"setlocale"}, 2},
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   {{{"strerror"}, 1},
@@ -62,6 +70,10 @@ class InvalidPtrChecker
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   };
 
+  // The private members of this checker corresponding to commandline options
+  // are set in this function.
+  friend void ento::registerInvalidPtrChecker(CheckerManager &);
+
 public:
   // Obtain the environment pointer from 'main()' (if present).
   void checkBeginFunction(CheckerContext &C) const;
@@ -84,7 +96,10 @@ class InvalidPtrChecker
 REGISTER_SET_WITH_PROGRAMSTATE(InvalidMemoryRegions, const MemRegion *)
 
 // Stores the region of the environment pointer of 'main' (if present).
-REGISTER_TRAIT_WITH_PROGRAMSTATE(EnvPtrRegion, const MemRegion *)
+REGISTER_TRAIT_WITH_PROGRAMSTATE(MainEnvPtrRegion, const MemRegion *)
+
+// Stores the regions of environments returned by getenv calls.
+REGISTER_SET_WITH_PROGRAMSTATE(GetenvEnvPtrRegions, const MemRegion *)
 
 // Stores key-value pairs, where key is function declaration and value is
 // pointer to memory region returned by previous call of this function
@@ -95,22 +110,35 @@ void InvalidPtrChecker::EnvpInvalidatingCall(const 
CallEvent &Call,
  CheckerContext &C) const {
   StringRef FunctionName = Call.getCalleeIdentifier()->getName();
   ProgramStateRef State = C.getState();
-  const MemRegion *SymbolicEnvPtrRegion = State->get();
-  if (!SymbolicEnvPtrRegion)
-return;
 
-  State = State->add(SymbolicEnvPtrRegion);
+  auto PlaceInvalidationNote = [&C, FunctionName,
+&State](const MemRegion *Region,
+StringRef Message, ExplodedNode *Pred) 
{
+State = State->add(Region);
+
+// Make c

[clang] 1072fcd - [flang][driver] support -dumpversion and -dumpmachine (#68896)

2023-10-24 Thread via cfe-commits

Author: Yuanfang Chen
Date: 2023-10-24T01:32:39-07:00
New Revision: 1072fcd222468d36b1d4633f1a091a3376831ae3

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

LOG: [flang][driver] support -dumpversion and -dumpmachine (#68896)

Match GCC driver. GCC has -cc1/-fc1 support too, but this patch does not
address that.

Added: 
flang/test/Driver/dumpmachine.f90
flang/test/Driver/immediate-options.f90

Modified: 
clang/include/clang/Driver/Options.td
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e63158fb0e5333a..99e0f823299a999 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1382,9 +1382,13 @@ def dsym_dir : JoinedOrSeparate<["-"], "dsym-dir">,
 def dumpdir : Separate<["-"], "dumpdir">, Visibility<[ClangOption, CC1Option]>,
   MetaVarName<"">,
   HelpText<"Use  as a prefix to form auxiliary and dump file names">;
-def dumpmachine : Flag<["-"], "dumpmachine">;
+def dumpmachine : Flag<["-"], "dumpmachine">,
+  Visibility<[ClangOption, FlangOption]>,
+  HelpText<"Display the compiler's target processor">;
+def dumpversion : Flag<["-"], "dumpversion">,
+  Visibility<[ClangOption, FlangOption]>,
+  HelpText<"Display the version of the compiler">;
 def dumpspecs : Flag<["-"], "dumpspecs">, Flags<[Unsupported]>;
-def dumpversion : Flag<["-"], "dumpversion">;
 def dylib__file : Separate<["-"], "dylib_file">;
 def dylinker__install__name : JoinedOrSeparate<["-"], "dylinker_install_name">;
 def dylinker : Flag<["-"], "dylinker">;

diff  --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 0edb84d25f4de37..6d399f1d179a022 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -21,6 +21,8 @@
 ! CHECK-NEXT: -ccc-print-phases   Dump list of actions to perform
 ! CHECK-NEXT: -cppEnable predefined and command line 
preprocessor macros
 ! CHECK-NEXT: -c  Only run preprocess, compile, and 
assemble steps
+! CHECK-NEXT: -dumpmachineDisplay the compiler's target processor
+! CHECK-NEXT: -dumpversionDisplay the version of the compiler
 ! CHECK-NEXT: -D =  Define  to  (or 1 if 
 omitted)
 ! CHECK-NEXT: -emit-llvm  Use the LLVM representation for 
assembler and object files
 ! CHECK-NEXT: -E  Only run the preprocessor

diff  --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index 53b05a5ac104a7b..31c9caa32ea8292 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -17,6 +17,8 @@
 ! HELP-NEXT: -###Print (but do not run) the commands to 
run for this compilation
 ! HELP-NEXT: -cppEnable predefined and command line 
preprocessor macros
 ! HELP-NEXT: -c  Only run preprocess, compile, and 
assemble steps
+! HELP-NEXT: -dumpmachineDisplay the compiler's target processor
+! HELP-NEXT: -dumpversionDisplay the version of the compiler
 ! HELP-NEXT: -D =  Define  to  (or 1 if 
 omitted)
 ! HELP-NEXT: -emit-llvm  Use the LLVM representation for assembler 
and object files
 ! HELP-NEXT: -E  Only run the preprocessor

diff  --git a/flang/test/Driver/dumpmachine.f90 
b/flang/test/Driver/dumpmachine.f90
new file mode 100644
index 000..b68705707eefa04
--- /dev/null
+++ b/flang/test/Driver/dumpmachine.f90
@@ -0,0 +1,8 @@
+! Test that -dumpmachine prints the target triple.
+
+! Note: Debian GCC may omit "unknown-".
+! RUN: %flang --target=x86_64-linux-gnu -dumpmachine | FileCheck %s 
--check-prefix=X86_64
+! X86_64: x86_64-unknown-linux-gnu
+
+! RUN: %flang --target=xxx-pc-freebsd -dumpmachine | FileCheck %s 
--check-prefix=FREEBSD
+! FREEBSD: xxx-pc-freebsd

diff  --git a/flang/test/Driver/immediate-options.f90 
b/flang/test/Driver/immediate-options.f90
new file mode 100644
index 000..81c1e7181ba7935
--- /dev/null
+++ b/flang/test/Driver/immediate-options.f90
@@ -0,0 +1,2 @@
+! RUN: %flang -dumpversion | FileCheck %s -check-prefix=DUMPVERSION
+! DUMPVERSION: {{[0-9]+\.[0-9.]+}}



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


[clang] [flang][driver] support -dumpversion and -dumpmachine (PR #68896)

2023-10-24 Thread Yuanfang Chen via cfe-commits

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


[clang] [clang-format] Don't break between string literal operands of << (PR #69871)

2023-10-24 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/69871

>From d12aee14e9d588c402e69e49aa9b33be7f940acb Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 22 Oct 2023 01:36:17 -0700
Subject: [PATCH] [clang-format] Don't break between string literal operands of
 <<

Fixes #44363.
---
 clang/lib/Format/TokenAnnotator.cpp   | 4 
 clang/unittests/Format/FormatTest.cpp | 4 
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 4a7378c24cda57b..e0ea8bcdb07a32b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5117,10 +5117,6 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
 return true;
   if (Left.IsUnterminatedLiteral)
 return true;
-  if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&
-  Right.Next->is(tok::string_literal)) {
-return true;
-  }
   if (Right.is(TT_RequiresClause)) {
 switch (Style.RequiresClausePosition) {
 case FormatStyle::RCPS_OwnLine:
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index d5711782a23ef5b..176fe87c979cd2d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26478,6 +26478,10 @@ TEST_F(FormatTest, PPBranchesInBracedInit) {
"};");
 }
 
+TEST_F(FormatTest, StreamOutputOperator) {
+  verifyFormat("std::cout << \"foo\" << \"bar\" << baz;");
+}
+
 } // namespace
 } // namespace test
 } // namespace format

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


[clang] aceb34c - [analyzer][NFC] Simplifications in ArrayBoundV2 (#67572)

2023-10-24 Thread via cfe-commits

Author: DonatNagyE
Date: 2023-10-24T10:44:13+02:00
New Revision: aceb34c7046d315d615feaa94a5941db13299a1b

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

LOG: [analyzer][NFC] Simplifications in ArrayBoundV2 (#67572)

I'm planning to improve diagnostics generation in `ArrayBoundCheckerV2`
but before that I'm refactoring the source code to clean up some
over-complicated code and an inaccurate comment.

Changes in this commit:
- Remove the `mutable std::unique_ptr` boilerplate, because
it's no longer needed.
- Remove the code duplication between the methods `reportOOB()` and
`reportTaintedOOB()`.
- Eliminate the class `RegionRawOffsetV2` because it's just a "reinvent
the wheel" version of `std::pair` and it was used only once, as a
temporary object that was immediately decomposed. (I suspect that
`RegionRawOffset` in MemRegion.cpp could also be eliminated.)
- Flatten the code of `computeOffset()` which had contained six nested
indentation levels before this commit.
- Ensure that `computeOffset()` returns `std::nullopt` instead of a
`{Region, }` pair in the case when it encounters a
`Location` that is not an `ElementRegion`. This ensures that the
`checkLocation` callback returns early when it handles a memory access
where it has "nothing to do" (no subscript operation or equivalent
pointer arithmetic). Note that this is still NFC because zero is a
valid index everywhere, so the old logic without this shortcut
eventually reached the same conclusion.
- Correct a wrong explanation comment in `getSimplifiedOffsets()`.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
index db4a2fcea9b2cdd..e80a06e38587520 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -32,15 +32,13 @@ using namespace taint;
 namespace {
 class ArrayBoundCheckerV2 :
 public Checker {
-  mutable std::unique_ptr BT;
-  mutable std::unique_ptr TaintBT;
+  BugType BT{this, "Out-of-bound access"};
+  BugType TaintBT{this, "Out-of-bound access", categories::TaintedData};
 
-  enum OOB_Kind { OOB_Precedes, OOB_Excedes };
+  enum OOB_Kind { OOB_Precedes, OOB_Exceeds, OOB_Taint };
 
-  void reportOOB(CheckerContext &C, ProgramStateRef errorState,
- OOB_Kind kind) const;
-  void reportTaintOOB(CheckerContext &C, ProgramStateRef errorState,
-  SVal TaintedSVal) const;
+  void reportOOB(CheckerContext &C, ProgramStateRef ErrorState, OOB_Kind Kind,
+ SVal TaintedSVal = UnknownVal()) const;
 
   static bool isFromCtypeMacro(const Stmt *S, ASTContext &AC);
 
@@ -48,26 +46,62 @@ class ArrayBoundCheckerV2 :
   void checkLocation(SVal l, bool isLoad, const Stmt *S,
  CheckerContext &C) const;
 };
+} // anonymous namespace
 
-// FIXME: Eventually replace RegionRawOffset with this class.
-class RegionRawOffsetV2 {
-private:
-  const SubRegion *baseRegion;
-  NonLoc byteOffset;
-
-public:
-  RegionRawOffsetV2(const SubRegion *base, NonLoc offset)
-  : baseRegion(base), byteOffset(offset) { assert(base); }
+/// For a given Location that can be represented as a symbolic expression
+/// Arr[Idx] (or perhaps Arr[Idx1][Idx2] etc.), return the parent memory block
+/// Arr and the distance of Location from the beginning of Arr (expressed in a
+/// NonLoc that specifies the number of CharUnits). Returns nullopt when these
+/// cannot be determined.
+std::optional>
+computeOffset(ProgramStateRef State, SValBuilder &SVB, SVal Location) {
+  QualType T = SVB.getArrayIndexType();
+  auto EvalBinOp = [&SVB, State, T](BinaryOperatorKind Op, NonLoc L, NonLoc R) 
{
+// We will use this utility to add and multiply values.
+return SVB.evalBinOpNN(State, Op, L, R, T).getAs();
+  };
 
-  NonLoc getByteOffset() const { return byteOffset; }
-  const SubRegion *getRegion() const { return baseRegion; }
+  const SubRegion *OwnerRegion = nullptr;
+  std::optional Offset = SVB.makeZeroArrayIndex();
+
+  const ElementRegion *CurRegion =
+  dyn_cast_or_null(Location.getAsRegion());
+
+  while (CurRegion) {
+const auto Index = CurRegion->getIndex().getAs();
+if (!Index)
+  return std::nullopt;
+
+QualType ElemType = CurRegion->getElementType();
+
+// FIXME: The following early return was presumably added to safeguard the
+// getTypeSizeInChars() call (which doesn't accept an incomplete type), but
+// it seems that `ElemType` cannot be incomplete at this point.
+if (ElemType->isIncompleteType())
+  return std::nullopt;
+
+// Calculate Delta = Index * sizeof(ElemType).
+No

[clang] [analyzer][NFC] Simplifications in ArrayBoundV2 (PR #67572)

2023-10-24 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


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


[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-24 Thread Endre Fülöp via cfe-commits

https://github.com/gamesh411 updated 
https://github.com/llvm/llvm-project/pull/67663

From 65a4bf21e38a925f643c6cca3d3cad4c2910071c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= 
Date: Fri, 8 Sep 2023 14:20:00 +0200
Subject: [PATCH 01/12] [analyzer][clangsa] Add new option to
 alpha.security.cert.InvalidPtrChecker

The invalidation of pointer pointers returned by subsequent calls to genenv is
suggested by the POSIX standard, but is too strict from a practical point of
view. A new checker option 'InvalidatingGetEnv' is introduced, and is set to a
more lax default value, which does not consider consecutive getenv calls
invalidating.
The handling of the main function's possible specification where an environment
pointer is also pecified as a third parameter is also considered now.

Differential Revision: https://reviews.llvm.org/D154603
---
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  9 ++
 .../Checkers/cert/InvalidPtrChecker.cpp   | 86 ++-
 clang/test/Analysis/analyzer-config.c |  1 +
 .../Analysis/cert/env34-c-cert-examples.c | 40 -
 clang/test/Analysis/cert/env34-c.c|  1 +
 clang/test/Analysis/invalid-ptr-checker.c | 50 +++
 6 files changed, 163 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/Analysis/invalid-ptr-checker.c

diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index be813bde8be41ea..b6e9f0fae1c7f48 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1002,6 +1002,15 @@ let ParentPackage = ENV in {
 
   def InvalidPtrChecker : Checker<"InvalidPtr">,
   HelpText<"Finds usages of possibly invalidated pointers">,
+  CheckerOptions<[
+CmdLineOption,
+  ]>,
   Documentation;
 
 } // end "alpha.cert.env"
diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index aae1a17bc0ae53e..8849eb1148564b7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -38,6 +38,15 @@ class InvalidPtrChecker
 CheckerContext &C) const;
 
   // SEI CERT ENV31-C
+
+  // If set to true, consider getenv calls as invalidating operations on the
+  // environment variable buffer. This is implied in the standard, but in
+  // practice does not cause problems (in the commonly used environments).
+  bool InvalidatingGetEnv = false;
+
+  // GetEnv can be treated invalidating and non-invalidating as well.
+  const CallDescription GetEnvCall{{"getenv"}, 1};
+
   const CallDescriptionMap EnvpInvalidatingFunctions = {
   {{{"setenv"}, 3}, &InvalidPtrChecker::EnvpInvalidatingCall},
   {{{"unsetenv"}, 1}, &InvalidPtrChecker::EnvpInvalidatingCall},
@@ -51,7 +60,6 @@ class InvalidPtrChecker
 
   // SEI CERT ENV34-C
   const CallDescriptionMap PreviousCallInvalidatingFunctions = {
-  {{{"getenv"}, 1}, 
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   {{{"setlocale"}, 2},
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   {{{"strerror"}, 1},
@@ -62,6 +70,10 @@ class InvalidPtrChecker
&InvalidPtrChecker::postPreviousReturnInvalidatingCall},
   };
 
+  // The private members of this checker corresponding to commandline options
+  // are set in this function.
+  friend void ento::registerInvalidPtrChecker(CheckerManager &);
+
 public:
   // Obtain the environment pointer from 'main()' (if present).
   void checkBeginFunction(CheckerContext &C) const;
@@ -84,7 +96,10 @@ class InvalidPtrChecker
 REGISTER_SET_WITH_PROGRAMSTATE(InvalidMemoryRegions, const MemRegion *)
 
 // Stores the region of the environment pointer of 'main' (if present).
-REGISTER_TRAIT_WITH_PROGRAMSTATE(EnvPtrRegion, const MemRegion *)
+REGISTER_TRAIT_WITH_PROGRAMSTATE(MainEnvPtrRegion, const MemRegion *)
+
+// Stores the regions of environments returned by getenv calls.
+REGISTER_SET_WITH_PROGRAMSTATE(GetenvEnvPtrRegions, const MemRegion *)
 
 // Stores key-value pairs, where key is function declaration and value is
 // pointer to memory region returned by previous call of this function
@@ -95,22 +110,35 @@ void InvalidPtrChecker::EnvpInvalidatingCall(const 
CallEvent &Call,
  CheckerContext &C) const {
   StringRef FunctionName = Call.getCalleeIdentifier()->getName();
   ProgramStateRef State = C.getState();
-  const MemRegion *SymbolicEnvPtrRegion = State->get();
-  if (!SymbolicEnvPtrRegion)
-return;
 
-  State = State->add(SymbolicEnvPtrRegion);
+  auto PlaceInvalidationNote = [&C, FunctionName,
+&State](const MemRegion *Region,
+StringRef Message, ExplodedNode *Pred) 
{
+State = State->add(Region);
+
+// Make

[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-24 Thread Endre Fülöp via cfe-commits

gamesh411 wrote:

I have rebased on the current main.

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


[clang] [clang] Implement constexpr bit_cast for vectors (PR #66894)

2023-10-24 Thread via cfe-commits

https://github.com/DaMatrix updated 
https://github.com/llvm/llvm-project/pull/66894

>From 38647e8b00194a59a31eed92b04b229fe24802b6 Mon Sep 17 00:00:00 2001
From: DaPorkchop_ 
Date: Sun, 13 Aug 2023 22:39:12 +0200
Subject: [PATCH 1/2] [clang] Implement constexpr bit_cast for vectors

---
 .../include/clang/Basic/DiagnosticASTKinds.td |   3 +
 clang/lib/AST/ExprConstant.cpp| 269 --
 clang/lib/CodeGen/CGExprConstant.cpp  |   3 +
 clang/test/CodeGen/const-init.c   |   9 +-
 .../constexpr-builtin-bit-cast-fp80.cpp   |  48 
 .../SemaCXX/constexpr-builtin-bit-cast.cpp|  44 +++
 6 files changed, 278 insertions(+), 98 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-builtin-bit-cast-fp80.cpp

diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index b70cf1071d865da..85acce12dac7173 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -326,6 +326,9 @@ def note_constexpr_bit_cast_invalid_type : Note<
   "%select{type|member}1 is not allowed in a constant expression">;
 def note_constexpr_bit_cast_invalid_subtype : Note<
   "invalid type %0 is a %select{member|base}1 of %2">;
+def note_constexpr_bit_cast_invalid_vector : Note<
+  "bit_cast involving type %0 is not allowed in a constant expression; "
+  "element size %1 * element count %2 is not a multiple of the byte size %3">;
 def note_constexpr_bit_cast_indet_dest : Note<
   "indeterminate value can only initialize an object of type 'unsigned char'"
   "%select{, 'char',|}1 or 'std::byte'; %0 is invalid">;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b47b8a1256477d..adf73f0ec39f8a9 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2732,53 +2732,6 @@ static bool truncateBitfieldValue(EvalInfo &Info, const 
Expr *E,
   return true;
 }
 
-static bool EvalAndBitcastToAPInt(EvalInfo &Info, const Expr *E,
-  llvm::APInt &Res) {
-  APValue SVal;
-  if (!Evaluate(SVal, Info, E))
-return false;
-  if (SVal.isInt()) {
-Res = SVal.getInt();
-return true;
-  }
-  if (SVal.isFloat()) {
-Res = SVal.getFloat().bitcastToAPInt();
-return true;
-  }
-  if (SVal.isVector()) {
-QualType VecTy = E->getType();
-unsigned VecSize = Info.Ctx.getTypeSize(VecTy);
-QualType EltTy = VecTy->castAs()->getElementType();
-unsigned EltSize = Info.Ctx.getTypeSize(EltTy);
-bool BigEndian = Info.Ctx.getTargetInfo().isBigEndian();
-Res = llvm::APInt::getZero(VecSize);
-for (unsigned i = 0; i < SVal.getVectorLength(); i++) {
-  APValue &Elt = SVal.getVectorElt(i);
-  llvm::APInt EltAsInt;
-  if (Elt.isInt()) {
-EltAsInt = Elt.getInt();
-  } else if (Elt.isFloat()) {
-EltAsInt = Elt.getFloat().bitcastToAPInt();
-  } else {
-// Don't try to handle vectors of anything other than int or float
-// (not sure if it's possible to hit this case).
-Info.FFDiag(E, diag::note_invalid_subexpr_in_const_expr);
-return false;
-  }
-  unsigned BaseEltSize = EltAsInt.getBitWidth();
-  if (BigEndian)
-Res |= EltAsInt.zextOrTrunc(VecSize).rotr(i*EltSize+BaseEltSize);
-  else
-Res |= EltAsInt.zextOrTrunc(VecSize).rotl(i*EltSize);
-}
-return true;
-  }
-  // Give up if the input isn't an int, float, or vector.  For example, we
-  // reject "(v4i16)(intptr_t)&a".
-  Info.FFDiag(E, diag::note_invalid_subexpr_in_const_expr);
-  return false;
-}
-
 /// Perform the given integer operation, which is known to need at most 
BitWidth
 /// bits, and check for overflow in the original type (if that type was not an
 /// unsigned type).
@@ -7011,10 +6964,11 @@ class APValueToBufferConverter {
   return visitArray(Val, Ty, Offset);
 case APValue::Struct:
   return visitRecord(Val, Ty, Offset);
+case APValue::Vector:
+  return visitVector(Val, Ty, Offset);
 
 case APValue::ComplexInt:
 case APValue::ComplexFloat:
-case APValue::Vector:
 case APValue::FixedPoint:
   // FIXME: We should support these.
 
@@ -7101,6 +7055,72 @@ class APValueToBufferConverter {
 return true;
   }
 
+  bool visitVector(const APValue &Val, QualType Ty, CharUnits Offset) {
+const VectorType *VTy = Ty->castAs();
+QualType EltTy = VTy->getElementType();
+unsigned NElts = VTy->getNumElements();
+unsigned EltSize =
+VTy->isExtVectorBoolType() ? 1 : Info.Ctx.getTypeSize(EltTy);
+
+if ((NElts * EltSize) % Info.Ctx.getCharWidth() != 0) {
+  // The vector's size in bits is not a multiple of the target's byte size,
+  // so its layout is unspecified. For now, we'll simply treat these cases
+  // as unsupported (this should only be possible with OpenCL bool vectors
+  // whose element count isn't a multiple of the byte size).
+  

[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-24 Thread Rana Pratap Reddy via cfe-commits

https://github.com/ranapratap55 updated 
https://github.com/llvm/llvm-project/pull/69567

>From 65c806a4c1703214fa7eaebecfdaa200b6d0d205 Mon Sep 17 00:00:00 2001
From: ranapratap55 
Date: Thu, 19 Oct 2023 12:52:13 +0530
Subject: [PATCH] [AMDGPU] Lower __builtin_read_exec_hi to use amdgcn_ballot

---
 clang/lib/CodeGen/CGBuiltin.cpp   | 22 -
 .../CodeGenOpenCL/builtins-amdgcn-wave32.cl   | 24 +++
 .../CodeGenOpenCL/builtins-amdgcn-wave64.cl   | 23 ++
 clang/test/CodeGenOpenCL/builtins-amdgcn.cl   |  4 +++-
 4 files changed, 66 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e1211bb8949b665..63d02660dfc6b56 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7995,15 +7995,24 @@ enum SpecialRegisterAccessKind {
   Write,
 };
 
+// Generates the IR for __builtin_read_exec_*.
+// Lowers the builtin to amdgcn_ballot intrinsic.
 static Value *EmitAMDGCNBallotForExec(CodeGenFunction &CGF, const CallExpr *E,
   llvm::Type *RegisterType,
-  llvm::Type *ValueType) {
+  llvm::Type *ValueType, bool isExecHi) {
   CodeGen::CGBuilderTy &Builder = CGF.Builder;
   CodeGen::CodeGenModule &CGM = CGF.CGM;
 
-  llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
+  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
   llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+
+  if (isExecHi) {
+Value *C1 = llvm::ConstantInt::get(ValueType, 32);
+Value *Rt2 = Builder.CreateLShr(Call, C1);
+Rt2 = Builder.CreateTrunc(Rt2, CGF.Int32Ty);
+return Rt2;
+  }
+
   return Call;
 }
 
@@ -17857,10 +17866,11 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
   case AMDGPU::BI__builtin_amdgcn_read_exec:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, false);
   case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
-  case AMDGPU::BI__builtin_amdgcn_read_exec_hi: {
-return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty);
-  }
+return EmitAMDGCNBallotForExec(*this, E, Int32Ty, Int32Ty, false);
+  case AMDGPU::BI__builtin_amdgcn_read_exec_hi:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, true);
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
index a4d14cf1f6cf0bd..43553131f63c549 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
@@ -13,6 +13,8 @@ void test_ballot_wave32(global uint* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK: declare i32 @llvm.amdgcn.ballot.i32(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave32_target_attr(
 // CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 %{{.+}})
 __attribute__((target("wavefrontsize32")))
@@ -21,6 +23,28 @@ void test_ballot_wave32_target_attr(global uint* out, int a, 
int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK-LABEL: @test_read_exec(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+void test_read_exec(global uint* out) {
+  *out = __builtin_amdgcn_read_exec();
+}
+
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
+// CHECK-LABEL: @test_read_exec_lo(
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
+void test_read_exec_lo(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_lo();
+}
+
+// CHECK-LABEL: @test_read_exec_hi(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+// CHECK: lshr i64 [[A:%.*]], 32
+// CHECK: trunc i64 [[B:%.*]] to i32
+void test_read_exec_hi(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_hi();
+}
+
 #if __AMDGCN_WAVEFRONT_SIZE != 32
 #error Wrong wavesize detected
 #endif
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
index 563c9a2a240c1dc..53f34c6a44ae7dc 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
@@ -13,6 +13,8 @@ void test_ballot_wave64(global ulong* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave64_target_attr(
 // CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 %{{.+}})
 __attribute__((target("wavefrontsize64")))
@@ -21,6 +23,27 @@ void test_ballot_wave64_target_attr(global ulong* out, int 
a, int b)
   *out

[clang] 7bc1031 - Revert "[clang-format] Fix align consecutive declarations over function pointers"

2023-10-24 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-10-24T02:15:44-07:00
New Revision: 7bc1031c474ebb2216a5432273dafe4d1490fbce

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

LOG: Revert "[clang-format] Fix align consecutive declarations over function 
pointers"

This reverts commit a84e0b4bdc872adbdaafbade8164b197784b.

Fixes #68079.

Added: 


Modified: 
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index dc81060671c1712..dbe6175fb9653ed 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -980,7 +980,7 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
   AlignTokens(
   Style,
   [](Change const &C) {
-if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
+if (C.Tok->is(TT_FunctionDeclarationName))
   return true;
 if (C.Tok->isNot(TT_StartOfName))
   return false;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index d5711782a23ef5b..02447dec840e367 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2033,8 +2033,6 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"const unsigned int *d;\n"
"Const unsigned int &e;\n"
"const unsigned int &f;\n"
-   "int*f1(int *a, int &b, int &&c);\n"
-   "double *(*f2)(int *a, double &&b);\n"
"const unsigned&&g;\n"
"Const unsigned  h;",
Style);
@@ -2080,8 +2078,6 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"const unsigned int* d;\n"
"Const unsigned int& e;\n"
"const unsigned int& f;\n"
-   "int*f1(int* a, int& b, int&& c);\n"
-   "double* (*f2)(int* a, double&& b);\n"
"const unsigned&&g;\n"
"Const unsigned  h;",
Style);
@@ -2107,8 +2103,6 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"const unsigned int *d;\n"
"Const unsigned int& e;\n"
"const unsigned int& f;\n"
-   "int*f1(int *a, int& b, int&& c);\n"
-   "double *(*f2)(int *a, double&& b);\n"
"const unsigned  g;\n"
"Const unsigned  h;",
Style);
@@ -2149,8 +2143,6 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"const unsigned int*  d;\n"
"Const unsigned int & e;\n"
"const unsigned int & f;\n"
-   "int* f1(int* a, int & b, int && c);\n"
-   "double*  (*f2)(int* a, double && b);\n"
"const unsigned &&g;\n"
"Const unsigned   h;",
Style);
@@ -2176,8 +2168,6 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"const unsigned int * d;\n"
"Const unsigned int  &e;\n"
"const unsigned int  &f;\n"
-   "int *f1(int * a, int &b, int &&c);\n"
-   "double * (*f2)(int * a, double &&b);\n"
"const unsigned &&g;\n"
"Const unsigned   h;",
Style);



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


[clang] [Clang] Mark declarators invalid in the presence of ill-formed explicit parameters. (PR #70018)

2023-10-24 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/70018

To avoid crashes later in sema.

Fixes #69962
Fixes #69838

>From 4810d5c8d9d9ec95300c3b684fe3ff88fdd05351 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Tue, 24 Oct 2023 11:20:30 +0200
Subject: [PATCH] [Clang] Mark declarators invalid in the presence of
 ill-formed explicit parameters.

To avoid crashes later in sema.

Fixes #69962
Fixes #69838
---
 clang/lib/Sema/SemaDeclCXX.cpp |  7 +++-
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 43 ++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 0193e476b3a781b..898758502e51bde 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11352,12 +11352,14 @@ void 
Sema::CheckExplicitObjectMemberFunction(Declarator &D,
 Diag(ExplicitObjectParam->getBeginLoc(),
  diag::err_explicit_object_parameter_nonmember)
 << D.getSourceRange() << /*static=*/0 << IsLambda;
+D.setInvalidType();
   }
 
   if (D.getDeclSpec().isVirtualSpecified()) {
 Diag(ExplicitObjectParam->getBeginLoc(),
  diag::err_explicit_object_parameter_nonmember)
 << D.getSourceRange() << /*virtual=*/1 << IsLambda;
+D.setInvalidType();
   }
 
   if (IsLambda && FTI.hasMutableQualifier()) {
@@ -11373,16 +11375,19 @@ void 
Sema::CheckExplicitObjectMemberFunction(Declarator &D,
 Diag(ExplicitObjectParam->getLocation(),
  diag::err_explicit_object_parameter_nonmember)
 << D.getSourceRange() << /*non-member=*/2 << IsLambda;
+D.setInvalidType();
 return;
   }
 
   // CWG2674: constructors and destructors cannot have explicit parameters.
   if (Name.getNameKind() == DeclarationName::CXXConstructorName ||
-  Name.getNameKind() == DeclarationName::CXXDestructorName)
+  Name.getNameKind() == DeclarationName::CXXDestructorName) {
 Diag(ExplicitObjectParam->getBeginLoc(),
  diag::err_explicit_object_parameter_constructor)
 << (Name.getNameKind() == DeclarationName::CXXDestructorName)
 << D.getSourceRange();
+D.setInvalidType();
+  }
 }
 
 namespace {
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index cb83270752443ad..535381e876da9c7 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -542,3 +542,46 @@ void foo(C c) {
 }
 
 }
+
+
+namespace GH69838 {
+struct S {
+  S(this auto &self) {} // expected-error {{an explicit object parameter 
cannot appear in a constructor}}
+  virtual void f(this S self) {} // expected-error {{an explicit object 
parameter cannot appear in a virtual function}}
+  void g(this auto &self) const {} // expected-error {{explicit object member 
function cannot have 'const' qualifier}}
+  void h(this S self = S{}) {} // expected-error {{the explicit object 
parameter cannot have a default argument}}
+  void i(int i, this S self = S{}) {} // expected-error {{an explicit object 
parameter can only appear as the first parameter of the function}}
+  ~S(this S &&self); // expected-error {{an explicit object parameter cannot 
appear in a destructor}} \
+ // expected-error {{destructor cannot have any 
parameters}}
+
+  static void j(this S s); // expected-error {{an explicit object parameter 
cannot appear in a static function}}
+};
+
+void nonmember(this S s); // expected-error {{an explicit object parameter 
cannot appear in a non-member function}}
+
+int test() {
+  S s;
+  s.f();
+  s.g();
+  s.h();
+  s.i(0);
+  s.j({});
+  nonmember(S{});
+}
+
+}
+
+namespace GH69962 {
+struct S {
+S(const S&);
+};
+
+struct Thing {
+template
+Thing(this Self&& self, Args&& ... args) { } // expected-error {{an 
explicit object parameter cannot appear in a constructor}}
+};
+
+class Server : public Thing {
+S name_;
+};
+}

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


[clang] [Clang] Mark declarators invalid in the presence of ill-formed explicit parameters. (PR #70018)

2023-10-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

To avoid crashes later in sema.

Fixes #69962
Fixes #69838

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+6-1) 
- (modified) clang/test/SemaCXX/cxx2b-deducing-this.cpp (+43) 


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 0193e476b3a781b..898758502e51bde 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11352,12 +11352,14 @@ void 
Sema::CheckExplicitObjectMemberFunction(Declarator &D,
 Diag(ExplicitObjectParam->getBeginLoc(),
  diag::err_explicit_object_parameter_nonmember)
 << D.getSourceRange() << /*static=*/0 << IsLambda;
+D.setInvalidType();
   }
 
   if (D.getDeclSpec().isVirtualSpecified()) {
 Diag(ExplicitObjectParam->getBeginLoc(),
  diag::err_explicit_object_parameter_nonmember)
 << D.getSourceRange() << /*virtual=*/1 << IsLambda;
+D.setInvalidType();
   }
 
   if (IsLambda && FTI.hasMutableQualifier()) {
@@ -11373,16 +11375,19 @@ void 
Sema::CheckExplicitObjectMemberFunction(Declarator &D,
 Diag(ExplicitObjectParam->getLocation(),
  diag::err_explicit_object_parameter_nonmember)
 << D.getSourceRange() << /*non-member=*/2 << IsLambda;
+D.setInvalidType();
 return;
   }
 
   // CWG2674: constructors and destructors cannot have explicit parameters.
   if (Name.getNameKind() == DeclarationName::CXXConstructorName ||
-  Name.getNameKind() == DeclarationName::CXXDestructorName)
+  Name.getNameKind() == DeclarationName::CXXDestructorName) {
 Diag(ExplicitObjectParam->getBeginLoc(),
  diag::err_explicit_object_parameter_constructor)
 << (Name.getNameKind() == DeclarationName::CXXDestructorName)
 << D.getSourceRange();
+D.setInvalidType();
+  }
 }
 
 namespace {
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index cb83270752443ad..535381e876da9c7 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -542,3 +542,46 @@ void foo(C c) {
 }
 
 }
+
+
+namespace GH69838 {
+struct S {
+  S(this auto &self) {} // expected-error {{an explicit object parameter 
cannot appear in a constructor}}
+  virtual void f(this S self) {} // expected-error {{an explicit object 
parameter cannot appear in a virtual function}}
+  void g(this auto &self) const {} // expected-error {{explicit object member 
function cannot have 'const' qualifier}}
+  void h(this S self = S{}) {} // expected-error {{the explicit object 
parameter cannot have a default argument}}
+  void i(int i, this S self = S{}) {} // expected-error {{an explicit object 
parameter can only appear as the first parameter of the function}}
+  ~S(this S &&self); // expected-error {{an explicit object parameter cannot 
appear in a destructor}} \
+ // expected-error {{destructor cannot have any 
parameters}}
+
+  static void j(this S s); // expected-error {{an explicit object parameter 
cannot appear in a static function}}
+};
+
+void nonmember(this S s); // expected-error {{an explicit object parameter 
cannot appear in a non-member function}}
+
+int test() {
+  S s;
+  s.f();
+  s.g();
+  s.h();
+  s.i(0);
+  s.j({});
+  nonmember(S{});
+}
+
+}
+
+namespace GH69962 {
+struct S {
+S(const S&);
+};
+
+struct Thing {
+template
+Thing(this Self&& self, Args&& ... args) { } // expected-error {{an 
explicit object parameter cannot appear in a constructor}}
+};
+
+class Server : public Thing {
+S name_;
+};
+}

``




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


[clang] [clang-format] Don't break between string literal operands of << (PR #69871)

2023-10-24 Thread Owen Pan via cfe-commits

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


[clang] d68826d - [clang-format] Don't break between string literal operands of << (#69871)

2023-10-24 Thread via cfe-commits

Author: Owen Pan
Date: 2023-10-24T02:42:39-07:00
New Revision: d68826dfbd987377ef6771d40c1d984f09ee3b9e

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

LOG: [clang-format] Don't break between string literal operands of << (#69871)

Fixes #44363.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 4a7378c24cda57b..e0ea8bcdb07a32b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5117,10 +5117,6 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
 return true;
   if (Left.IsUnterminatedLiteral)
 return true;
-  if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&
-  Right.Next->is(tok::string_literal)) {
-return true;
-  }
   if (Right.is(TT_RequiresClause)) {
 switch (Style.RequiresClausePosition) {
 case FormatStyle::RCPS_OwnLine:

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 02447dec840e367..8329daa7665949c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26468,6 +26468,10 @@ TEST_F(FormatTest, PPBranchesInBracedInit) {
"};");
 }
 
+TEST_F(FormatTest, StreamOutputOperator) {
+  verifyFormat("std::cout << \"foo\" << \"bar\" << baz;");
+}
+
 } // namespace
 } // namespace test
 } // namespace format



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


[clang] 684e4c0 - [clang][Interp] Don't explicitly call InterpState destructor()

2023-10-24 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-10-24T12:00:40+02:00
New Revision: 684e4c0085e8d454c04e9813f89033b1c51d24fa

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

LOG: [clang][Interp] Don't explicitly call InterpState destructor()

This broke the msan builders because the destructor will be called
twice. Should've guessed.

Added: 


Modified: 
clang/lib/AST/Interp/Context.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index 3ad63f40b0c72b7..cb96e56fb5e1ad8 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -158,17 +158,18 @@ const llvm::fltSemantics 
&Context::getFloatSemantics(QualType T) const {
 }
 
 bool Context::Run(State &Parent, const Function *Func, APValue &Result) {
-  InterpState State(Parent, *P, Stk, *this);
-  State.Current = new InterpFrame(State, Func, /*Caller=*/nullptr, {});
-  if (Interpret(State, Result)) {
-assert(Stk.empty());
-return true;
-  }
 
-  // We explicitly delete our state here, so the Stk.clear() call
-  // below doesn't violently free values the destructor would
-  // otherwise access.
-  State.~InterpState();
+  {
+InterpState State(Parent, *P, Stk, *this);
+State.Current = new InterpFrame(State, Func, /*Caller=*/nullptr, {});
+if (Interpret(State, Result)) {
+  assert(Stk.empty());
+  return true;
+}
+
+// State gets destroyed here, so the Stk.clear() below doesn't accidentally
+// remove values the State's destructor might accedd.
+  }
 
   Stk.clear();
   return false;



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


[clang] [clang]Transform uninstantiated ExceptionSpec in TemplateInstantiator (PR #68878)

2023-10-24 Thread Congcong Cai via cfe-commits


@@ -396,6 +396,10 @@ Bug Fixes in This Version
   cannot be used with ``Release`` mode builds. (`#68237 
`_).
 - Fix crash in evaluating ``constexpr`` value for invalid template function.
   Fixes (`#68542 `_)
+- Clang will correctly evaluate ``noexcept`` expression with template in 
template
+  method of template record. Fixes

HerrCai0907 wrote:

What do you think for this?
Clang will correctly evaluate ``noexcept`` expression for template functions of 
template classes.

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


[clang] [Clang] Mark declarators invalid in the presence of ill-formed explicit parameters. (PR #70018)

2023-10-24 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

Is there no release note because there is no release that supports explicit 
object parameters yet?

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


[clang] [clang] Catch missing format attributes (PR #70024)

2023-10-24 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovicsyrmia created 
https://github.com/llvm/llvm-project/pull/70024

Enable flag -Wmissing-format-attribute to catch missing attributes

From 9d0b6ae67776a9adf9ca3eee64b2e01de9f07af4 Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 13 Oct 2023 14:45:15 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/include/clang/Basic/DiagnosticGroups.td |  2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/include/clang/Sema/Sema.h   |  2 +
 clang/lib/Sema/SemaAttr.cpp   | 80 +++
 clang/lib/Sema/SemaChecking.cpp   |  4 +-
 clang/test/Sema/attr-format-missing.c | 13 +++
 6 files changed, 102 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 17fdcffa2d42740..b8b77df84beb2be 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -482,7 +482,7 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
+def MissingFormatAttribute: DiagGroup<"missing-format-attribute">;
 def : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6d6f474f6dcdab9..7125de143c1710e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -936,6 +936,9 @@ def err_opencl_invalid_param : Error<
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
 def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
+def warn_missing_format_attribute : Warning<
+  "Function %0 might be candidate for %1 format attribute.">,
+  InGroup, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 741c2503127af7a..7041a309e5df220 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10615,6 +10615,8 @@ class Sema final {
 ChangedStateAtExit
   };
 
+  void DiagnoseMissingFormatAttributes(NamedDecl *FDecl, SourceLocation Loc);
+
   void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind,
  SourceLocation IncludeLoc);
   void DiagnoseUnterminatedPragmaAlignPack();
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 42f582724564d06..0a61748f6e20176 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -435,6 +435,86 @@ bool Sema::ConstantFoldAttrArgs(const AttributeCommonInfo 
&CI,
   return true;
 }
 
+// Warn if parent function does not have builtin function format attribute.
+void Sema::DiagnoseMissingFormatAttributes(NamedDecl *FDecl,
+   SourceLocation Loc) {
+  if (!FDecl)
+return;
+
+  auto *FD = dyn_cast_or_null(FDecl);
+  if (!FD)
+return;
+
+  unsigned BuiltinID = FD->getBuiltinID(/*ConsiderWrappers=*/true);
+  
+  // Function is not builtin if it's builtin ID is 0.
+  if (!BuiltinID)
+return;
+
+  // Check if function is one with format attribute.
+  switch (BuiltinID) {
+  case Builtin::BIprintf:
+  case Builtin::BIfprintf:
+  case Builtin::BIsprintf:
+  case Builtin::BIscanf:
+  case Builtin::BIfscanf:
+  case Builtin::BIsscanf:
+  case Builtin::BIvprintf:
+  case Builtin::BIvfprintf:
+  case Builtin::BIvsprintf:
+break;
+  default: {
+// In C99 mode check functions below.
+if (!getLangOpts().C99)
+  return;
+switch (BuiltinID) {
+case Builtin::BIsnprintf:
+case Builtin::BIvsnprintf:
+case Builtin::BIvscanf:
+case Builtin::BIvfscanf:
+case Builtin::BIvsscanf:
+  break;
+default:
+  return;
+}
+  }
+  }
+
+  Scope *ParentScope = getCurScope() ? getCurScope()->getFnParent() : nullptr;
+  if (!ParentScope)
+return;
+
+  DeclContext *ParentScopeEntity = ParentScope->getEntity();
+  if (!ParentScopeEntity)
+return;
+  if (ParentScopeEntity->getDeclKind() != Decl::Kind::Function)
+return;
+
+  FunctionDecl *ParentFuncDecl = static_cast(ParentScopeEntity);
+  if (!ParentFuncDecl)
+return;
+  if (!ParentFuncDecl->isVariadic())
+return;
+
+  // Iterate through builtin function format attributes. Then check
+  // if parent function has these attributes. If parent function does
+  // not have builtin function format attribut, emi

[clang] b4fc141 - [clang][Interp] Fix ArrayInitLoop common expr life time

2023-10-24 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-10-24T12:20:02+02:00
New Revision: b4fc1418d9765bfb605387efc70ecf233d27b383

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

LOG: [clang][Interp] Fix ArrayInitLoop common expr life time

The local variable needs to survive for all the interations of the
ArrayInitLoopExpr. So, visit it explicitly before we iterate.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/cxx20.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index eb96f021258b114..1b33c69b93aa4b9 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -820,14 +820,24 @@ bool ByteCodeExprGen::VisitArrayInitLoopExpr(
   //   Investigate compiling this to a loop.
 
   const Expr *SubExpr = E->getSubExpr();
+  const Expr *CommonExpr = E->getCommonExpr();
   size_t Size = E->getArraySize().getZExtValue();
   std::optional ElemT = classify(SubExpr->getType());
 
+  // If the common expression is an opaque expression, we visit it
+  // here once so we have its value cached.
+  // FIXME: This might be necessary (or useful) for all expressions.
+  if (isa(CommonExpr)) {
+if (!this->discard(CommonExpr))
+  return false;
+  }
+
   // So, every iteration, we execute an assignment here
   // where the LHS is on the stack (the target array)
   // and the RHS is our SubExpr.
   for (size_t I = 0; I != Size; ++I) {
 ArrayIndexScope IndexScope(this, I);
+BlockScope BS(this);
 
 if (ElemT) {
   if (!this->visit(SubExpr))
@@ -856,7 +866,7 @@ bool ByteCodeExprGen::VisitOpaqueValueExpr(const 
OpaqueValueExpr *E) {
 
   PrimType SubExprT = classify(E->getSourceExpr()).value_or(PT_Ptr);
   if (auto It = OpaqueExprs.find(E); It != OpaqueExprs.end())
-return this->emitGetLocal(SubExprT, It->getSecond(), E);
+return this->emitGetLocal(SubExprT, It->second, E);
 
   if (!this->visit(E->getSourceExpr()))
 return false;
@@ -873,8 +883,10 @@ bool ByteCodeExprGen::VisitOpaqueValueExpr(const 
OpaqueValueExpr *E) {
 
   // Here the local variable is created but the value is removed from the 
stack,
   // so we put it back, because the caller might need it.
-  if (!this->emitGetLocal(SubExprT, *LocalIndex, E))
-return false;
+  if (!DiscardResult) {
+if (!this->emitGetLocal(SubExprT, *LocalIndex, E))
+  return false;
+  }
 
   // FIXME: Ideally the cached value should be cleaned up later.
   OpaqueExprs.insert({E, *LocalIndex});

diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 553bc6eb4d5244f..f0bb4e9e0d0711b 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -701,13 +701,12 @@ namespace ThreeWayCmp {
   static_assert(pa2 <=> pa1 == 1, "");
 }
 
-// FIXME: Interp should also be able to evaluate this snippet properly.
 namespace ConstexprArrayInitLoopExprDestructors
 {
   struct Highlander {
   int *p = 0;
   constexpr Highlander() {}
-  constexpr void set(int *p) { this->p = p; ++*p; if (*p != 1) throw 
"there can be only one"; } // expected-note {{not valid in a constant 
expression}}
+  constexpr void set(int *p) { this->p = p; ++*p; if (*p != 1) throw 
"there can be only one"; }
   constexpr ~Highlander() { --*p; }
   };
 
@@ -715,23 +714,18 @@ namespace ConstexprArrayInitLoopExprDestructors
   int *p;
   constexpr X(int *p) : p(p) {}
   constexpr X(const X &x, Highlander &&h = Highlander()) : p(x.p) {
-  h.set(p); // expected-note {{in call to '&Highlander()->set(&n)'}}
+  h.set(p);
   }
   };
 
   constexpr int f() {
   int n = 0;
   X x[3] = {&n, &n, &n};
-  auto [a, b, c] = x; // expected-note {{in call to 'X(x[0], 
Highlander())'}}
+  auto [a, b, c] = x;
   return n;
   }
 
-  static_assert(f() == 0); // expected-error {{not an integral constant 
expression}} \
-   // expected-note {{in call to 'f()'}}
-
-  int main() {
-  return f();
-  }
+  static_assert(f() == 0);
 }
 
 namespace NonPrimitiveOpaqueValue



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


[clang] [clang] Catch missing format attributes (PR #70024)

2023-10-24 Thread Budimir Aranđelović via cfe-commits

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


[clang] [clang][Interp] Fix `ArrayInitLoopExpr` handling (PR #67886)

2023-10-24 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Sorry, but I had to investigate this locally anyway because the opaque value 
test started to break with one of my patches from today. I came up with 
https://github.com/llvm/llvm-project/commit/b4fc1418d9765bfb605387efc70ecf233d27b383.
 Thanks for your work on this though.

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


[clang] [clang][Interp] Fix `ArrayInitLoopExpr` handling (PR #67886)

2023-10-24 Thread Timm Baeder via cfe-commits

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


[clang] [Clang] Mark declarators invalid in the presence of ill-formed explicit parameters. (PR #70018)

2023-10-24 Thread via cfe-commits

cor3ntin wrote:

> Is there no release note because there is no release that supports explicit 
> object parameters yet?

Exactly, yes!

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


[clang] [clang][Analyzer] Move checker 'alpha.unix.Errno' to 'unix.Errno'. (PR #69469)

2023-10-24 Thread via cfe-commits


@@ -934,6 +934,76 @@ Check calls to various UNIX/Posix functions: ``open, 
pthread_once, calloc, mallo
 .. literalinclude:: checkers/unix_api_example.c
 :language: c
 
+.. _unix-Errno:
+
+unix.Errno (C)
+""
+
+Check for improper use of ``errno``.
+This checker implements partially CERT rule
+`ERR30-C. Set errno to zero before calling a library function known to set 
errno,
+and check errno only after the function returns a value indicating failure
+`_.
+The checker can find the first read of ``errno`` after successful standard
+function calls.
+
+The C and POSIX standards often do not define if a standard library function
+may change value of ``errno`` if the call does not fail.
+Therefore, ``errno`` should only be used if it is known from the return value
+of a function that the call has failed.
+There are exceptions to this rule (for example ``strtol``) but the affected
+functions are not yet supported by the checker.
+The return values for the failure cases are documented in the standard Linux 
man
+pages of the functions and in the `POSIX standard 
`_.
+
+.. code-block:: c
+
+ int unsafe_errno_read(int sock, void *data, int data_size) {
+   if (send(sock, data, data_size, 0) != data_size) {
+ // 'send' can be successful even if not all data was sent
+ if (errno == 1) { // An undefined value may be read from 'errno'
+   return 0;
+ }
+   }
+   return 1;
+ }
+
+The checker :ref:`unix-StdCLibraryFunctions` must be turned on to get the
+warnings from this checker. The supported functions are the same as by

DonatNagyE wrote:

Thanks for the clarification. I think it'd be important to improve this 
situation (it's very user-hostile to hide an "if you want to use this, you must 
manually enable another checker" remark in the docs), but this is independent 
of the currently reviewed commit.

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


[PATCH] D153701: [Clang] Implement P2718R0 "Lifetime extension in range-based for loops"

2023-10-24 Thread Yurong via Phabricator via cfe-commits
yronglin marked an inline comment as done.
yronglin added a comment.

ping~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153701

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


[clang] [InstCombine] Convert or concat to fshl if opposite or concat exists (PR #68502)

2023-10-24 Thread Nikita Popov via cfe-commits

nikic wrote:

> See most recent comments about missing tests. That being said code looks 
> functionally correct to me. Still not 100% sure this is a desirable change. 
> Will defer to @nikic about that.

I'm also skeptical about accepting this optimization. Looking at the motivating 
case in https://github.com/llvm/llvm-project/pull/68502#discussion_r1351618002, 
this seems like a bad approach to the problem: It means that in order to fold 
the pattern to `bitreverse(%xy)`, we must just so happen to have the right 
`%xy` lying around in the IR, even though it doesn't have any relation to the 
main pattern (it's not used inside it, just injected via an extra use). It 
sounds to me like the better way to handle that case would be to support 
matching a variant of plain bitreverse in the form of `bitreverse(rot(%yx))`.

Replacing the `rot(%yx)` by `%xy` is then an extra optimization opportunity, 
but it's no longer a precondition to performing the transform.

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


[clang] c8b267e - [clang][Interp] Handle variadic functions (#67814)

2023-10-24 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-10-24T12:33:29+02:00
New Revision: c8b267e98f8f5c0bc4c3b3b34f9cb54dbdf76205

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

LOG: [clang][Interp] Handle variadic functions (#67814)

Similarly to the code we already had for builtin functions, we need to
check the call expression for the arguments passed.

Added: 


Modified: 
clang/lib/AST/Interp/Function.cpp
clang/lib/AST/Interp/Function.h
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Function.cpp 
b/clang/lib/AST/Interp/Function.cpp
index 0b7cfc4e28883f0..357aff7fe6229b9 100644
--- a/clang/lib/AST/Interp/Function.cpp
+++ b/clang/lib/AST/Interp/Function.cpp
@@ -24,7 +24,7 @@ Function::Function(Program &P, const FunctionDecl *F, 
unsigned ArgSize,
 : P(P), Loc(F->getBeginLoc()), F(F), ArgSize(ArgSize),
   ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),
   ParamOffsets(std::move(ParamOffsets)), HasThisPointer(HasThisPointer),
-  HasRVO(HasRVO) {}
+  HasRVO(HasRVO), Variadic(F->isVariadic()) {}
 
 Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
   auto It = Params.find(Offset);

diff  --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h
index b93477c56346a9d..be9b1733635f725 100644
--- a/clang/lib/AST/Interp/Function.h
+++ b/clang/lib/AST/Interp/Function.h
@@ -173,6 +173,8 @@ class Function final {
   /// Checks if the function is defined.
   bool isDefined() const { return Defined; }
 
+  bool isVariadic() const { return Variadic; }
+
   unsigned getBuiltinID() const { return F->getBuiltinID(); }
 
   bool isBuiltin() const { return F->getBuiltinID() != 0; }
@@ -251,6 +253,7 @@ class Function final {
   /// If we've already compiled the function's body.
   bool HasBody = false;
   bool Defined = false;
+  bool Variadic = false;
 
 public:
   /// Dumps the disassembled bytecode to \c llvm::errs().

diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 8b0e7beb4a1acc1..c87bb2fa6b02f16 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -121,18 +121,47 @@ static bool CheckGlobal(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr) {
 
 namespace clang {
 namespace interp {
+static void popArg(InterpState &S, const Expr *Arg) {
+  PrimType Ty = S.getContext().classify(Arg->getType()).value_or(PT_Ptr);
+  TYPE_SWITCH(Ty, S.Stk.discard());
+}
+
+void cleanupAfterFunctionCall(InterpState &S, CodePtr OpPC) {
+  assert(S.Current);
+  const Function *CurFunc = S.Current->getFunction();
+  assert(CurFunc);
+
+  // Certain builtin functions are declared as func-name(...), so the
+  // parameters are checked in Sema and only available through the CallExpr.
+  // The interp::Function we create for them has 0 parameters, so we need to
+  // remove them from the stack by checking the CallExpr.
+  // FIXME: This is potentially just a special case and could be handled more
+  // generally with the code just below?
+  if (CurFunc->needsRuntimeArgPop(S.getCtx())) {
+const auto *CE = cast(S.Current->getExpr(OpPC));
+for (int32_t I = CE->getNumArgs() - 1; I >= 0; --I) {
+  popArg(S, CE->getArg(I));
+}
+return;
+  }
 
-bool popBuiltinArgs(InterpState &S, CodePtr OpPC) {
-  assert(S.Current && 
S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()));
-  const Expr *E = S.Current->getExpr(OpPC);
-  assert(isa(E));
-  const CallExpr *CE = cast(E);
-  for (int32_t I = CE->getNumArgs() - 1; I >= 0; --I) {
-const Expr *A = CE->getArg(I);
-PrimType Ty = S.getContext().classify(A->getType()).value_or(PT_Ptr);
-TYPE_SWITCH(Ty, S.Stk.discard());
+  if (S.Current->Caller && CurFunc->isVariadic()) {
+// CallExpr we're look for is at the return PC of the current function, 
i.e.
+// in the caller.
+// This code path should be executed very rarely.
+const auto *CE =
+cast(S.Current->Caller->getExpr(S.Current->getRetPC()));
+unsigned FixedParams = CurFunc->getNumParams();
+int32_t ArgsToPop = CE->getNumArgs() - FixedParams;
+assert(ArgsToPop >= 0);
+for (int32_t I = ArgsToPop - 1; I >= 0; --I) {
+  const Expr *A = CE->getArg(FixedParams + I);
+  popArg(S, A);
+}
   }
-  return true;
+  // And in any case, remove the fixed parameters (the non-variadic ones)
+  // at the end.
+  S.Current->popArgs();
 }
 
 bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 7ef1e344224a3c3..2132e8b0a8cfa29 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -200,8 +200,7 @@ enum 

[clang] [clang][Interp] Handle variadic functions (PR #67814)

2023-10-24 Thread Timm Baeder via cfe-commits

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


[clang] [clang][Interp] Implement IntegralAP::truncate() (PR #69912)

2023-10-24 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/69912

>From 40a32854cab91eb98aeb4788cabd4aa14d305d68 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 23 Oct 2023 12:23:45 +0200
Subject: [PATCH] [clang][Interp] Implement IntegralAP::truncate()

---
 clang/lib/AST/Interp/IntegralAP.h |  5 ++---
 clang/test/AST/Interp/intap.cpp   | 16 
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 45e5b49546270aa..f8d47ca183f3a67 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -137,9 +137,8 @@ template  class IntegralAP final {
 return NameStr;
   }
 
-  IntegralAP truncate(unsigned bitWidth) const {
-assert(false);
-return V;
+  IntegralAP truncate(unsigned BitWidth) const {
+return IntegralAP(V.trunc(BitWidth));
   }
 
   IntegralAP toUnsigned() const {
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 27fae1b904351ce..c19e8c1367e9f4f 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -118,4 +118,20 @@ namespace AddSubOffset {
   static_assert(*P2 == 1,"");
 }
 
+namespace Bitfields {
+  struct S1 {
+unsigned _BitInt(128) a : 2;
+  };
+  constexpr S1 s1{100}; // ref-warning {{changes value from 100 to 0}} \
+// expected-warning {{changes value from 100 to 0}}
+  constexpr S1 s12{3};
+  static_assert(s12.a == 3, "");
+
+  struct S2 {
+unsigned __int128 a : 2;
+  };
+  constexpr S2 s2{100}; // ref-warning {{changes value from 100 to 0}} \
+// expected-warning {{changes value from 100 to 0}}
+}
+
 #endif

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


[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-10-24 Thread Simon Tatham via cfe-commits

https://github.com/statham-arm updated 
https://github.com/llvm/llvm-project/pull/69447

>From e4d860c2968e4bf2e0ca198bdfe00dad4e985d40 Mon Sep 17 00:00:00 2001
From: Simon Tatham 
Date: Thu, 14 Sep 2023 14:51:17 +0100
Subject: [PATCH] [Driver] Add ExclusiveGroup feature to multilib.yaml.

This allows a YAML-based multilib configuration to specify explicitly
that a subset of its library directories are alternatives to each
other, i.e. at most one of that subset should be selected.

So if you have multiple sysroots each including a full set of headers
and libraries, you can mark them as members of the same
ExclusiveGroup, and then you'll be sure that only one of them is
selected, even if two or more are compatible with the compile options.

This is particularly important in multilib setups including the libc++
headers, where selecting the include directories from two different
sysroots can cause an actual build failure. This occurs when including
, for example: libc++'s stdio.h is included first, and will
try to use `#include_next` to fetch the underlying libc's version. But
if there are two include directories from separate multilibs, then
both of their C++ include directories will end up on the include path
first, followed by both the C directories. So the `#include_next` from
the first libc++ stdio.h will include the second libc++ stdio.h, which
will do nothing because it has the same include guard macro, and the
libc header won't ever be included at all.

If more than one of the options in an ExclusiveGroup matches the given
flags, the last one wins.
---
 clang/include/clang/Driver/Multilib.h | 16 -
 clang/lib/Driver/Multilib.cpp | 49 ++---
 .../baremetal-multilib-exclusive-group.yaml   | 69 +++
 3 files changed, 122 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/Driver/baremetal-multilib-exclusive-group.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index 1416559414f894b..6a9533e6dd831f1 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -39,13 +39,22 @@ class Multilib {
   std::string IncludeSuffix;
   flags_list Flags;
 
+  // Optionally, a multilib can be assigned a string tag indicating that it's
+  // part of a group of mutually exclusive possibilities. If two or more
+  // multilibs have the same non-empty value of ExclusiveGroup, then only the
+  // last matching one of them will be selected.
+  //
+  // Setting this to the empty string is a special case, indicating that the
+  // directory is not mutually exclusive with anything else.
+  std::string ExclusiveGroup;
+
 public:
   /// GCCSuffix, OSSuffix & IncludeSuffix will be appended directly to the
   /// sysroot string so they must either be empty or begin with a '/' 
character.
   /// This is enforced with an assert in the constructor.
   Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
-   StringRef IncludeSuffix = {},
-   const flags_list &Flags = flags_list());
+   StringRef IncludeSuffix = {}, const flags_list &Flags = 
flags_list(),
+   StringRef ExclusiveGroup = {});
 
   /// Get the detected GCC installation path suffix for the multi-arch
   /// target variant. Always starts with a '/', unless empty
@@ -63,6 +72,9 @@ class Multilib {
   /// All elements begin with either '-' or '!'
   const flags_list &flags() const { return Flags; }
 
+  /// Get the exclusive group label.
+  const std::string &exclusiveGroup() const { return ExclusiveGroup; }
+
   LLVM_DUMP_METHOD void dump() const;
   /// print summary of the Multilib
   void print(raw_ostream &OS) const;
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 48a494d9fa38db5..085ccee7b25752e 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -29,9 +29,10 @@ using namespace driver;
 using namespace llvm::sys;
 
 Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,
-   StringRef IncludeSuffix, const flags_list &Flags)
+   StringRef IncludeSuffix, const flags_list &Flags,
+   StringRef ExclusiveGroup)
 : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix),
-  Flags(Flags) {
+  Flags(Flags), ExclusiveGroup(ExclusiveGroup) {
   assert(GCCSuffix.empty() ||
  (StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
   assert(OSSuffix.empty() ||
@@ -96,13 +97,39 @@ bool MultilibSet::select(const Multilib::flags_list &Flags,
  llvm::SmallVector &Selected) const {
   llvm::StringSet<> FlagSet(expandFlags(Flags));
   Selected.clear();
-  llvm::copy_if(Multilibs, std::back_inserter(Selected),
-[&FlagSet](const Multilib &M) {
-  for (const std::string &F : M.flags())
-if (!FlagSet.contains(F))
-  return false;
-  return true

[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)

2023-10-24 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/69597

>From e77e43ac2a402a74fbf5c28e7dfa24d0c0e77f12 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 18 Oct 2023 15:36:13 +0200
Subject: [PATCH] [clang][Interp] Implement inc/dec for IntegralAP

---
 clang/lib/AST/Interp/IntegralAP.h | 21 ++-
 clang/test/AST/Interp/intap.cpp   | 62 +++
 2 files changed, 66 insertions(+), 17 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 45e5b49546270aa..2e68c59ee80d436 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -116,7 +116,9 @@ template  class IntegralAP final {
 
   constexpr unsigned bitWidth() const { return V.getBitWidth(); }
 
-  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); }
+  APSInt toAPSInt(unsigned Bits = 0) const {
+return APSInt(V, Signed).extend(Bits);
+  }
   APValue toAPValue() const { return APValue(APSInt(V, Signed)); }
 
   bool isZero() const { return V.isZero(); }
@@ -167,17 +169,13 @@ template  class IntegralAP final {
   }
 
   static bool increment(IntegralAP A, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-*R = IntegralAP(A.V - 1);
-return false;
+IntegralAP One(1, A.bitWidth());
+return add(A, One, A.bitWidth() + 1, R);
   }
 
   static bool decrement(IntegralAP A, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-*R = IntegralAP(A.V - 1);
-return false;
+IntegralAP One(1, A.bitWidth());
+return sub(A, One, A.bitWidth() + 1, R);
   }
 
   static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
@@ -246,7 +244,10 @@ template  class IntegralAP final {
 
   static void shiftRight(const IntegralAP A, const IntegralAP B,
  unsigned OpBits, IntegralAP *R) {
-*R = IntegralAP(A.V.ashr(B.V.getZExtValue()));
+if constexpr (Signed)
+  *R = IntegralAP(A.V.ashr(B.V.getZExtValue()));
+else
+  *R = IntegralAP(A.V.lshr(B.V.getZExtValue()));
   }
 
 private:
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 27fae1b904351ce..9d947a092bb7440 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -29,9 +29,17 @@ static_assert(UBitIntZero1 == 0, "");
 
 
 #ifdef __SIZEOF_INT128__
+typedef __int128 int128_t;
+typedef unsigned __int128 uint128_t;
+static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
+static_assert(UINT128_MAX == -1, "");
+
+static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
+static_assert(INT128_MAX != 0, "");
+static const __int128_t INT128_MIN = -INT128_MAX - 1;
+
 namespace i128 {
-  typedef __int128 int128_t;
-  typedef unsigned __int128 uint128_t;
+
   constexpr int128_t I128_1 = 12;
   static_assert(I128_1 == 12, "");
   static_assert(I128_1 != 10, "");
@@ -40,12 +48,7 @@ namespace i128 {
// expected-note{{evaluates to}} \
// ref-note{{evaluates to}}
 
-  static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
-  static_assert(UINT128_MAX == -1, "");
 
-  static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
-  static_assert(INT128_MAX != 0, "");
-  static const __int128_t INT128_MIN = -INT128_MAX - 1;
   constexpr __int128 A = INT128_MAX + 1; // expected-error {{must be 
initialized by a constant expression}} \
  // expected-note {{outside the 
range}} \
  // ref-error {{must be initialized by 
a constant expression}} \
@@ -118,4 +121,49 @@ namespace AddSubOffset {
   static_assert(*P2 == 1,"");
 }
 
+namespace IncDec {
+#if 0
+  constexpr int128_t maxPlus1(bool Pre) {
+int128_t a = INT128_MAX;
+
+if (Pre)
+  ++a; // ref-note {{value 170141183460469231731687303715884105728 is 
outside the range}} \
+   // expected-note {{value 170141183460469231731687303715884105728 is 
outside the range}}
+else
+  a++;
+return a;
+  }
+  static_assert(maxPlus1(true) == 0, ""); // ref-error {{not an integral 
constant expression}} \
+  // ref-note in call to}} \
+  // expected-error {{not an integral 
constant expression}} \
+  // expected-note in call to}}
+  static_assert(maxPlus1(false) == 0, ""); // ref-error {{not an integral 
constant expression}} \
+   // ref-note in call to}} \
+   // expected-error {{not an integral 
constant expression}} \
+   // expected-note in call to}}
+
+  constexpr int128_t inc1(bool Pre) {
+int128_t A = 0;
+if (Pre)
+  ++A;
+else
+  A++;
+return A;
+  }
+  static_assert(inc1(t

[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)

2023-10-24 Thread Vassil Vassilev via cfe-commits


@@ -617,24 +617,27 @@ void ASTDeclReader::VisitDecl(Decl *D) {
Reader.getContext());
   }
   D->setLocation(ThisDeclLoc);
-  D->InvalidDecl = Record.readInt();
-  if (Record.readInt()) { // hasAttrs
+
+  uint64_t DeclBits = Record.readInt();
+  D->InvalidDecl = DeclBits & 0x1;
+  D->setImplicit(DeclBits & (1 << 2));
+  D->Used = (DeclBits >> 3) & 0x1;
+  IsDeclMarkedUsed |= D->Used;
+  D->setReferenced(DeclBits & (1 << 4));
+  D->setTopLevelDeclInObjCContainer(DeclBits & (1 << 5));
+  D->setAccess((AccessSpecifier)((DeclBits >> 6) & 0x3));
+  D->FromASTFile = true;
+  auto ModuleOwnership = (Decl::ModuleOwnershipKind)((DeclBits >> 8) & 0x7);

vgvassilev wrote:

Is there a way to improve the API avoiding these magic constants? I suspect 
this would be difficult to read and maintain.

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


[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-24 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks updated 
https://github.com/llvm/llvm-project/pull/68743

From 465003388953a52b70702d45cef7c4031581310d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= 
Date: Tue, 10 Oct 2023 22:50:43 +0200
Subject: [PATCH] [clang-format] Don't align comments over scopes

We now stop aligning trailing comments on all closing braces, for
classes etc. we even check for the semicolon between the comment and the
brace.

Fixes #67906.
---
 clang/lib/Format/WhitespaceManager.cpp|  53 +-
 clang/unittests/Format/FormatTestComments.cpp | 178 --
 2 files changed, 210 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index dbe6175fb9653ed..ff8b1e6e13a3f77 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1048,6 +1048,9 @@ void WhitespaceManager::alignChainedConditionals() {
 }
 
 void WhitespaceManager::alignTrailingComments() {
+  if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never)
+return;
+
   const int Size = Changes.size();
   int MinColumn = 0;
   int StartOfSequence = 0;
@@ -1118,16 +1121,48 @@ void WhitespaceManager::alignTrailingComments() {
   }
 }
 
-// We don't want to align namespace end comments.
-const bool DontAlignThisComment =
-I > 0 && C.NewlinesBefore == 0 &&
-Changes[I - 1].Tok->is(TT_NamespaceRBrace);
-if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never ||
-DontAlignThisComment) {
+// We don't want to align comments which end a scope, which are here
+// identified by most closing braces.
+auto DontAlignThisComment = [](const auto *Tok) {
+  if (Tok->is(tok::semi)) {
+Tok = Tok->getPreviousNonComment();
+if (!Tok)
+  return false;
+  }
+  if (Tok->is(tok::r_paren)) {
+// Back up past the parentheses and a `TT_DoWhile` that may precede.
+Tok = Tok->MatchingParen;
+if (!Tok)
+  return false;
+Tok = Tok->getPreviousNonComment();
+if (!Tok)
+  return false;
+if (Tok->is(TT_DoWhile)) {
+  const auto *Prev = Tok->getPreviousNonComment();
+  if (!Prev) {
+// A do-while-loop without braces.
+return true;
+  }
+  Tok = Prev;
+}
+  }
+
+  if (Tok->isNot(tok::r_brace))
+return false;
+
+  while (Tok->Previous && Tok->Previous->is(tok::r_brace))
+Tok = Tok->Previous;
+  return Tok->NewlinesBefore > 0;
+};
+
+if (I > 0 && C.NewlinesBefore == 0 &&
+DontAlignThisComment(Changes[I - 1].Tok)) {
   alignTrailingComments(StartOfSequence, I, MinColumn);
-  MinColumn = ChangeMinColumn;
-  MaxColumn = ChangeMinColumn;
-  StartOfSequence = I;
+  // Reset to initial values, but skip this change for the next alignment
+  // pass.
+  MinColumn = 0;
+  MaxColumn = INT_MAX;
+  StartOfSequence = I + 1;
 } else if (BreakBeforeNext || Newlines > NewLineThreshold ||
(ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn) ||
// Break the comment sequence if the previous line did not end
diff --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 1198329b7b5a8f0..5e5324f01d8670a 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -182,7 +182,7 @@ TEST_F(FormatTestComments, UnderstandsSingleLineComments) {
"int   a; // This is unrelated"));
   EXPECT_EQ("class C {\n"
 "  void f() { // This does something ..\n"
-"  }  // awesome..\n"
+"  } // awesome..\n"
 "\n"
 "  int a; // This is unrelated\n"
 "};",
@@ -3102,7 +3102,8 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) {
   StringRef Input = "namespace A {\n"
 "  TESTSUITE(B) {\n"
 "namespace C {\n"
-"  namespace D {} // namespace D\n"
+"  namespace D { //\n"
+"  } // namespace D\n"
 "  std::string Foo = Bar; // Comment\n"
 "  std::string BazString = Baz;   // C2\n"
 "}  // namespace C\n"
@@ -3114,7 +3115,8 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) {
   verifyFormat("namespace A {\n"
"  TESTSUITE(B) {\n"
"namespace C {\n"
-   "  namespace D {} // namespace D\n"
+   "  namespace D { //\n"
+   "  } // namespace D\n"
"  std::string Foo = Bar;   // Comment\n"
"  std::string BazString = Baz; // C2\n"
"} // namespace C\n"
@@ -3126,7 +3128,8 @@ TES

[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-24 Thread Björn Schäpers via cfe-commits


@@ -3191,20 +3198,150 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) 
{
   "}\n"
   "// Comment";
 
-#if 0
-  // FIXME: The following comment is aligned with the namespace comment.
   verifyFormat("namespace A {\n"
"  int Foo;\n"
"  int Bar;\n"
"} // namespace A\n"
-   " // Comment",
+   "// Comment",
Input, Style);
-#endif
 
   Style.FixNamespaceComments = false;
   verifyFormat(Input, Style);
 }
 
+TEST_F(FormatTestComments, DontAlignOverScope) {
+  verifyFormat("if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("while (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("for (;;) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("do {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} while (foo); // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("do\n"
+   "  int aLongVariable; // with comment\n"
+   "while (foo); // not aigned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("do\n"
+   "  int aLongVariable; // with comment\n"
+   "/**/ while (foo); // not aigned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("switch (foo) {\n"
+   "case 7: {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // case not aligned\n"
+   "} // switch also not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("switch (foo) {\n"
+   "default: {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // case not aligned\n"
+   "} // switch also not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("class C {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("struct S {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("union U {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("enum E {\n"
+   "  aLongVariable, // with comment\n"
+   "  f  // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("void foo() {\n"
+   "  {\n"
+   "int aLongVariable; // with comment\n"
+   "int f; // aligned\n"
+   "  } // not aligned\n"
+   "  int bar;// new align\n"
+   "  int foobar; // group\n"
+   "}");
+
+  verifyFormat("auto longLambda = [] { // comment\n"
+   "  int aLongVariable;   // with comment\n"
+   "  int f;   // ali

[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-24 Thread Björn Schäpers via cfe-commits


@@ -3191,20 +3198,167 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) 
{
   "}\n"
   "// Comment";
 
-#if 0
-  // FIXME: The following comment is aligned with the namespace comment.
   verifyFormat("namespace A {\n"
"  int Foo;\n"
"  int Bar;\n"
"} // namespace A\n"
-   " // Comment",
+   "// Comment",
Input, Style);
-#endif
 
   Style.FixNamespaceComments = false;
   verifyFormat(Input, Style);
 }
 
+TEST_F(FormatTestComments, DontAlignOverScope) {
+  verifyFormat("if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("while (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("for (;;) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("do {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} while (foo); // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("do\n"
+   "  int aLongVariable; // with comment\n"
+   "while (foo); // not aigned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("do\n"
+   "  int aLongVariable; // with comment\n"
+   "/**/ while (foo); // not aigned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("switch (foo) {\n"
+   "case 7: {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // case not aligned\n"
+   "} // switch also not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("switch (foo) {\n"
+   "default: {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // case not aligned\n"
+   "} // switch also not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("class C {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("struct S {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("union U {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("enum E {\n"
+   "  aLongVariable, // with comment\n"
+   "  f  // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("void foo() {\n"
+   "  {\n"
+   "int aLongVariable; // with comment\n"
+   "int f; // aligned\n"
+   "  } // not aligned\n"
+   "  int bar;// new align\n"
+   "  int foobar; // group\n"
+   "}");
+
+  verifyFormat("auto longLambda = [] { // comment\n"
+   "  int aLongVariable;   // with comment\n"
+   "  int f;   // ali

[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-24 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks updated 
https://github.com/llvm/llvm-project/pull/68743

From 3e76e5a0724af4d6f24175796856c919f30547a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= 
Date: Tue, 10 Oct 2023 22:50:43 +0200
Subject: [PATCH] [clang-format] Don't align comments over scopes

We now stop aligning trailing comments on all closing braces, for
classes etc. we even check for the semicolon between the comment and the
brace.

Fixes #67906.
---
 clang/docs/ClangFormatStyleOptions.rst|   4 +
 clang/include/clang/Format/Format.h   |   4 +
 clang/lib/Format/WhitespaceManager.cpp|  53 +-
 clang/unittests/Format/FormatTestComments.cpp | 178 --
 4 files changed, 218 insertions(+), 21 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index cfd57f5fa8153f4..5f369ea9759edad 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -980,6 +980,10 @@ the configuration (without a prefix: ``Auto``).
 **AlignTrailingComments** (``TrailingCommentsAlignmentStyle``) 
:versionbadge:`clang-format 3.7` :ref:`¶ `
   Control of trailing comments.
 
+  The alignment stops at closing braces after a line break, and only
+  followed by other closing braces, a (``do-``) ``while``, a lambda call, or
+  a semicolon.
+
 
   .. note::
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4c344135d25163c..d0145fa9272cdd6 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -539,6 +539,10 @@ struct FormatStyle {
 
   /// Control of trailing comments.
   ///
+  /// The alignment stops at closing braces after a line break, and only
+  /// followed by other closing braces, a (``do-``) ``while``, a lambda call, 
or
+  /// a semicolon.
+  ///
   /// \note
   ///  As of clang-format 16 this option is not a bool but can be set
   ///  to the options. Conventional bool options still can be parsed as before.
diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index dbe6175fb9653ed..ff8b1e6e13a3f77 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1048,6 +1048,9 @@ void WhitespaceManager::alignChainedConditionals() {
 }
 
 void WhitespaceManager::alignTrailingComments() {
+  if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never)
+return;
+
   const int Size = Changes.size();
   int MinColumn = 0;
   int StartOfSequence = 0;
@@ -1118,16 +1121,48 @@ void WhitespaceManager::alignTrailingComments() {
   }
 }
 
-// We don't want to align namespace end comments.
-const bool DontAlignThisComment =
-I > 0 && C.NewlinesBefore == 0 &&
-Changes[I - 1].Tok->is(TT_NamespaceRBrace);
-if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never ||
-DontAlignThisComment) {
+// We don't want to align comments which end a scope, which are here
+// identified by most closing braces.
+auto DontAlignThisComment = [](const auto *Tok) {
+  if (Tok->is(tok::semi)) {
+Tok = Tok->getPreviousNonComment();
+if (!Tok)
+  return false;
+  }
+  if (Tok->is(tok::r_paren)) {
+// Back up past the parentheses and a `TT_DoWhile` that may precede.
+Tok = Tok->MatchingParen;
+if (!Tok)
+  return false;
+Tok = Tok->getPreviousNonComment();
+if (!Tok)
+  return false;
+if (Tok->is(TT_DoWhile)) {
+  const auto *Prev = Tok->getPreviousNonComment();
+  if (!Prev) {
+// A do-while-loop without braces.
+return true;
+  }
+  Tok = Prev;
+}
+  }
+
+  if (Tok->isNot(tok::r_brace))
+return false;
+
+  while (Tok->Previous && Tok->Previous->is(tok::r_brace))
+Tok = Tok->Previous;
+  return Tok->NewlinesBefore > 0;
+};
+
+if (I > 0 && C.NewlinesBefore == 0 &&
+DontAlignThisComment(Changes[I - 1].Tok)) {
   alignTrailingComments(StartOfSequence, I, MinColumn);
-  MinColumn = ChangeMinColumn;
-  MaxColumn = ChangeMinColumn;
-  StartOfSequence = I;
+  // Reset to initial values, but skip this change for the next alignment
+  // pass.
+  MinColumn = 0;
+  MaxColumn = INT_MAX;
+  StartOfSequence = I + 1;
 } else if (BreakBeforeNext || Newlines > NewLineThreshold ||
(ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn) ||
// Break the comment sequence if the previous line did not end
diff --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 1198329b7b5a8f0..5e5324f01d8670a 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -182,7 +182,7 @@ TEST_F(FormatTestComments, UnderstandsSingle

[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-24 Thread Owen Pan via cfe-commits


@@ -3191,20 +3198,167 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) 
{
   "}\n"
   "// Comment";
 
-#if 0
-  // FIXME: The following comment is aligned with the namespace comment.
   verifyFormat("namespace A {\n"
"  int Foo;\n"
"  int Bar;\n"
"} // namespace A\n"
-   " // Comment",
+   "// Comment",
Input, Style);
-#endif
 
   Style.FixNamespaceComments = false;
   verifyFormat(Input, Style);
 }
 
+TEST_F(FormatTestComments, DontAlignOverScope) {
+  verifyFormat("if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("while (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("for (;;) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("do {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} while (foo); // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("do\n"
+   "  int aLongVariable; // with comment\n"
+   "while (foo); // not aigned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("do\n"
+   "  int aLongVariable; // with comment\n"
+   "/**/ while (foo); // not aigned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("switch (foo) {\n"
+   "case 7: {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // case not aligned\n"
+   "} // switch also not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("switch (foo) {\n"
+   "default: {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // case not aligned\n"
+   "} // switch also not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("class C {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("struct S {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("union U {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("enum E {\n"
+   "  aLongVariable, // with comment\n"
+   "  f  // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("void foo() {\n"
+   "  {\n"
+   "int aLongVariable; // with comment\n"
+   "int f; // aligned\n"
+   "  } // not aligned\n"
+   "  int bar;// new align\n"
+   "  int foobar; // group\n"
+   "}");
+
+  verifyFormat("auto longLambda = [] { // comment\n"
+   "  int aLongVariable;   // with comment\n"
+   "  int f;   // ali

[clang] [Sema] Fixed faulty shift count warning (PR #69521)

2023-10-24 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

Ping

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


[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-10-24 Thread Simon Tatham via cfe-commits

https://github.com/statham-arm updated 
https://github.com/llvm/llvm-project/pull/69447

>From 2a65ae75e8c8e62e7275a439849837919599e896 Mon Sep 17 00:00:00 2001
From: Simon Tatham 
Date: Thu, 14 Sep 2023 14:51:17 +0100
Subject: [PATCH] [Driver] Add ExclusiveGroup feature to multilib.yaml.

This allows a YAML-based multilib configuration to specify explicitly
that a subset of its library directories are alternatives to each
other, i.e. at most one of that subset should be selected.

So if you have multiple sysroots each including a full set of headers
and libraries, you can mark them as members of the same
ExclusiveGroup, and then you'll be sure that only one of them is
selected, even if two or more are compatible with the compile options.

This is particularly important in multilib setups including the libc++
headers, where selecting the include directories from two different
sysroots can cause an actual build failure. This occurs when including
, for example: libc++'s stdio.h is included first, and will
try to use `#include_next` to fetch the underlying libc's version. But
if there are two include directories from separate multilibs, then
both of their C++ include directories will end up on the include path
first, followed by both the C directories. So the `#include_next` from
the first libc++ stdio.h will include the second libc++ stdio.h, which
will do nothing because it has the same include guard macro, and the
libc header won't ever be included at all.

If more than one of the options in an ExclusiveGroup matches the given
flags, the last one wins.
---
 clang/include/clang/Driver/Multilib.h | 16 -
 clang/lib/Driver/Multilib.cpp | 49 ++---
 .../baremetal-multilib-exclusive-group.yaml   | 69 +++
 3 files changed, 122 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/Driver/baremetal-multilib-exclusive-group.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index 1416559414f894b..6a9533e6dd831f1 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -39,13 +39,22 @@ class Multilib {
   std::string IncludeSuffix;
   flags_list Flags;
 
+  // Optionally, a multilib can be assigned a string tag indicating that it's
+  // part of a group of mutually exclusive possibilities. If two or more
+  // multilibs have the same non-empty value of ExclusiveGroup, then only the
+  // last matching one of them will be selected.
+  //
+  // Setting this to the empty string is a special case, indicating that the
+  // directory is not mutually exclusive with anything else.
+  std::string ExclusiveGroup;
+
 public:
   /// GCCSuffix, OSSuffix & IncludeSuffix will be appended directly to the
   /// sysroot string so they must either be empty or begin with a '/' 
character.
   /// This is enforced with an assert in the constructor.
   Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
-   StringRef IncludeSuffix = {},
-   const flags_list &Flags = flags_list());
+   StringRef IncludeSuffix = {}, const flags_list &Flags = 
flags_list(),
+   StringRef ExclusiveGroup = {});
 
   /// Get the detected GCC installation path suffix for the multi-arch
   /// target variant. Always starts with a '/', unless empty
@@ -63,6 +72,9 @@ class Multilib {
   /// All elements begin with either '-' or '!'
   const flags_list &flags() const { return Flags; }
 
+  /// Get the exclusive group label.
+  const std::string &exclusiveGroup() const { return ExclusiveGroup; }
+
   LLVM_DUMP_METHOD void dump() const;
   /// print summary of the Multilib
   void print(raw_ostream &OS) const;
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 48a494d9fa38db5..085ccee7b25752e 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -29,9 +29,10 @@ using namespace driver;
 using namespace llvm::sys;
 
 Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,
-   StringRef IncludeSuffix, const flags_list &Flags)
+   StringRef IncludeSuffix, const flags_list &Flags,
+   StringRef ExclusiveGroup)
 : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix),
-  Flags(Flags) {
+  Flags(Flags), ExclusiveGroup(ExclusiveGroup) {
   assert(GCCSuffix.empty() ||
  (StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
   assert(OSSuffix.empty() ||
@@ -96,13 +97,39 @@ bool MultilibSet::select(const Multilib::flags_list &Flags,
  llvm::SmallVector &Selected) const {
   llvm::StringSet<> FlagSet(expandFlags(Flags));
   Selected.clear();
-  llvm::copy_if(Multilibs, std::back_inserter(Selected),
-[&FlagSet](const Multilib &M) {
-  for (const std::string &F : M.flags())
-if (!FlagSet.contains(F))
-  return false;
-  return true

[clang] 4674e30 - [Tooling/Inclusion] Refactor to use tables for compile time

2023-10-24 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2023-10-24T13:15:02+02:00
New Revision: 4674e303d2603f5d3c8faba2de676ed6ad0299a0

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

LOG: [Tooling/Inclusion] Refactor to use tables for compile time

The macro expansion takes 13s and generates an 1.5M obj file, table uses
2s and 680k .o file.

Sanitizers take multiple minutes to compile the old version, while
having negligible overhead on the new version.

No change in functionality.

Added: 


Modified: 
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index 664f3b76f661281..e409b8481e5fc9c 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -55,20 +55,26 @@ static const SymbolHeaderMapping *getMappingPerLang(Lang L) 
{
 }
 
 static int countSymbols(Lang Language) {
-  llvm::DenseSet Set;
-#define SYMBOL(Name, NS, Header) Set.insert(#NS #Name);
+  ArrayRef Symbols;
+#define SYMBOL(Name, NS, Header) #NS #Name,
   switch (Language) {
   case Lang::C:
+static constexpr const char *CSymbols[] = {
 #include "CSymbolMap.inc"
+};
+Symbols = CSymbols;
 break;
   case Lang::CXX:
+static constexpr const char *CXXSymbols[] = {
 #include "StdSpecialSymbolMap.inc"
 #include "StdSymbolMap.inc"
 #include "StdTsSymbolMap.inc"
+};
+Symbols = CXXSymbols;
 break;
   }
 #undef SYMBOL
-  return Set.size();
+  return llvm::DenseSet(Symbols.begin(), Symbols.end()).size();
 }
 
 static int initialize(Lang Language) {
@@ -127,15 +133,29 @@ static int initialize(Lang Language) {
 NSSymbolMap &NSSymbols = AddNS(QName.take_front(NSLen));
 NSSymbols.try_emplace(QName.drop_front(NSLen), SymIndex);
   };
-#define SYMBOL(Name, NS, Header) Add(#NS #Name, strlen(#NS), #Header);
+
+  struct Symbol {
+const char *QName;
+unsigned NSLen;
+const char *HeaderName;
+  };
+#define SYMBOL(Name, NS, Header) {#NS #Name, StringRef(#NS).size(), #Header},
   switch (Language) {
   case Lang::C:
+static constexpr Symbol CSymbols[] = {
 #include "CSymbolMap.inc"
+};
+for (const Symbol &S : CSymbols)
+  Add(S.QName, S.NSLen, S.HeaderName);
 break;
   case Lang::CXX:
+static constexpr Symbol CXXSymbols[] = {
 #include "StdSpecialSymbolMap.inc"
 #include "StdSymbolMap.inc"
 #include "StdTsSymbolMap.inc"
+};
+for (const Symbol &S : CXXSymbols)
+  Add(S.QName, S.NSLen, S.HeaderName);
 break;
   }
 #undef SYMBOL



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


[clang] 24f068b - [Tooling/Inclusion] Fix MSVC build

2023-10-24 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2023-10-24T13:32:21+02:00
New Revision: 24f068b0f77e5de1980b71f036f6b83c4d506904

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

LOG: [Tooling/Inclusion] Fix MSVC build

Added: 


Modified: 
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index e409b8481e5fc9c..03f61d33e1f26e7 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -58,13 +58,14 @@ static int countSymbols(Lang Language) {
   ArrayRef Symbols;
 #define SYMBOL(Name, NS, Header) #NS #Name,
   switch (Language) {
-  case Lang::C:
+  case Lang::C: {
 static constexpr const char *CSymbols[] = {
 #include "CSymbolMap.inc"
 };
 Symbols = CSymbols;
 break;
-  case Lang::CXX:
+  }
+  case Lang::CXX: {
 static constexpr const char *CXXSymbols[] = {
 #include "StdSpecialSymbolMap.inc"
 #include "StdSymbolMap.inc"
@@ -73,6 +74,7 @@ static int countSymbols(Lang Language) {
 Symbols = CXXSymbols;
 break;
   }
+  }
 #undef SYMBOL
   return llvm::DenseSet(Symbols.begin(), Symbols.end()).size();
 }
@@ -141,14 +143,15 @@ static int initialize(Lang Language) {
   };
 #define SYMBOL(Name, NS, Header) {#NS #Name, StringRef(#NS).size(), #Header},
   switch (Language) {
-  case Lang::C:
+  case Lang::C: {
 static constexpr Symbol CSymbols[] = {
 #include "CSymbolMap.inc"
 };
 for (const Symbol &S : CSymbols)
   Add(S.QName, S.NSLen, S.HeaderName);
 break;
-  case Lang::CXX:
+  }
+  case Lang::CXX: {
 static constexpr Symbol CXXSymbols[] = {
 #include "StdSpecialSymbolMap.inc"
 #include "StdSymbolMap.inc"
@@ -158,6 +161,7 @@ static int initialize(Lang Language) {
   Add(S.QName, S.NSLen, S.HeaderName);
 break;
   }
+  }
 #undef SYMBOL
 
   Mapping->HeaderNames = new llvm::StringRef[Mapping->HeaderIDs->size()];



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


[clang] [clang] Catch missing format attributes (PR #70024)

2023-10-24 Thread via cfe-commits

martinboehme wrote:

Removing myself as a reviewer -- I don't really consider myself to have 
expertise here.

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


[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)

2023-10-24 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/69597

>From 75fd2d498ec8d4e5928619493fedbbc994501378 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 18 Oct 2023 15:36:13 +0200
Subject: [PATCH] [clang][Interp] Implement inc/dec for IntegralAP

---
 clang/lib/AST/Interp/IntegralAP.h | 21 ++-
 clang/test/AST/Interp/intap.cpp   | 62 +++
 2 files changed, 66 insertions(+), 17 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 45e5b49546270aa..d0e601032a6b645 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -116,7 +116,9 @@ template  class IntegralAP final {
 
   constexpr unsigned bitWidth() const { return V.getBitWidth(); }
 
-  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); }
+  APSInt toAPSInt(unsigned Bits = 0) const {
+return APSInt(V, !Signed).extend((Bits > 0) ? Bits : bitWidth());
+  }
   APValue toAPValue() const { return APValue(APSInt(V, Signed)); }
 
   bool isZero() const { return V.isZero(); }
@@ -167,17 +169,13 @@ template  class IntegralAP final {
   }
 
   static bool increment(IntegralAP A, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-*R = IntegralAP(A.V - 1);
-return false;
+IntegralAP One(1, A.bitWidth());
+return add(A, One, A.bitWidth() + 1, R);
   }
 
   static bool decrement(IntegralAP A, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-*R = IntegralAP(A.V - 1);
-return false;
+IntegralAP One(1, A.bitWidth());
+return sub(A, One, A.bitWidth() + 1, R);
   }
 
   static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
@@ -246,7 +244,10 @@ template  class IntegralAP final {
 
   static void shiftRight(const IntegralAP A, const IntegralAP B,
  unsigned OpBits, IntegralAP *R) {
-*R = IntegralAP(A.V.ashr(B.V.getZExtValue()));
+if constexpr (Signed)
+  *R = IntegralAP(A.V.ashr(B.V.getZExtValue()));
+else
+  *R = IntegralAP(A.V.lshr(B.V.getZExtValue()));
   }
 
 private:
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 27fae1b904351ce..9d947a092bb7440 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -29,9 +29,17 @@ static_assert(UBitIntZero1 == 0, "");
 
 
 #ifdef __SIZEOF_INT128__
+typedef __int128 int128_t;
+typedef unsigned __int128 uint128_t;
+static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
+static_assert(UINT128_MAX == -1, "");
+
+static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
+static_assert(INT128_MAX != 0, "");
+static const __int128_t INT128_MIN = -INT128_MAX - 1;
+
 namespace i128 {
-  typedef __int128 int128_t;
-  typedef unsigned __int128 uint128_t;
+
   constexpr int128_t I128_1 = 12;
   static_assert(I128_1 == 12, "");
   static_assert(I128_1 != 10, "");
@@ -40,12 +48,7 @@ namespace i128 {
// expected-note{{evaluates to}} \
// ref-note{{evaluates to}}
 
-  static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
-  static_assert(UINT128_MAX == -1, "");
 
-  static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
-  static_assert(INT128_MAX != 0, "");
-  static const __int128_t INT128_MIN = -INT128_MAX - 1;
   constexpr __int128 A = INT128_MAX + 1; // expected-error {{must be 
initialized by a constant expression}} \
  // expected-note {{outside the 
range}} \
  // ref-error {{must be initialized by 
a constant expression}} \
@@ -118,4 +121,49 @@ namespace AddSubOffset {
   static_assert(*P2 == 1,"");
 }
 
+namespace IncDec {
+#if 0
+  constexpr int128_t maxPlus1(bool Pre) {
+int128_t a = INT128_MAX;
+
+if (Pre)
+  ++a; // ref-note {{value 170141183460469231731687303715884105728 is 
outside the range}} \
+   // expected-note {{value 170141183460469231731687303715884105728 is 
outside the range}}
+else
+  a++;
+return a;
+  }
+  static_assert(maxPlus1(true) == 0, ""); // ref-error {{not an integral 
constant expression}} \
+  // ref-note in call to}} \
+  // expected-error {{not an integral 
constant expression}} \
+  // expected-note in call to}}
+  static_assert(maxPlus1(false) == 0, ""); // ref-error {{not an integral 
constant expression}} \
+   // ref-note in call to}} \
+   // expected-error {{not an integral 
constant expression}} \
+   // expected-note in call to}}
+
+  constexpr int128_t inc1(bool Pre) {
+int128_t A = 0;
+if (Pre)
+  ++A;
+else
+  A++;
+return A;
+

[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)

2023-10-24 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/69597

>From 26868de7b84d53e9399cd7420ce5496c845d8ef4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 18 Oct 2023 15:36:13 +0200
Subject: [PATCH] [clang][Interp] Implement inc/dec for IntegralAP

---
 clang/lib/AST/Interp/IntegralAP.h | 23 ++--
 clang/test/AST/Interp/intap.cpp   | 62 +++
 2 files changed, 67 insertions(+), 18 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 45e5b49546270aa..503d9450e404372 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -116,8 +116,10 @@ template  class IntegralAP final {
 
   constexpr unsigned bitWidth() const { return V.getBitWidth(); }
 
-  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); }
-  APValue toAPValue() const { return APValue(APSInt(V, Signed)); }
+  APSInt toAPSInt(unsigned Bits = 0) const {
+return APSInt(V, !Signed).extend((Bits > 0) ? Bits : bitWidth());
+  }
+  APValue toAPValue() const { return APValue(toAPSInt()); }
 
   bool isZero() const { return V.isZero(); }
   bool isPositive() const { return V.isNonNegative(); }
@@ -167,17 +169,13 @@ template  class IntegralAP final {
   }
 
   static bool increment(IntegralAP A, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-*R = IntegralAP(A.V - 1);
-return false;
+IntegralAP One(1, A.bitWidth());
+return add(A, One, A.bitWidth() + 1, R);
   }
 
   static bool decrement(IntegralAP A, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
-*R = IntegralAP(A.V - 1);
-return false;
+IntegralAP One(1, A.bitWidth());
+return sub(A, One, A.bitWidth() + 1, R);
   }
 
   static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
@@ -246,7 +244,10 @@ template  class IntegralAP final {
 
   static void shiftRight(const IntegralAP A, const IntegralAP B,
  unsigned OpBits, IntegralAP *R) {
-*R = IntegralAP(A.V.ashr(B.V.getZExtValue()));
+if constexpr (Signed)
+  *R = IntegralAP(A.V.ashr(B.V.getZExtValue()));
+else
+  *R = IntegralAP(A.V.lshr(B.V.getZExtValue()));
   }
 
 private:
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 27fae1b904351ce..9d947a092bb7440 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -29,9 +29,17 @@ static_assert(UBitIntZero1 == 0, "");
 
 
 #ifdef __SIZEOF_INT128__
+typedef __int128 int128_t;
+typedef unsigned __int128 uint128_t;
+static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
+static_assert(UINT128_MAX == -1, "");
+
+static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
+static_assert(INT128_MAX != 0, "");
+static const __int128_t INT128_MIN = -INT128_MAX - 1;
+
 namespace i128 {
-  typedef __int128 int128_t;
-  typedef unsigned __int128 uint128_t;
+
   constexpr int128_t I128_1 = 12;
   static_assert(I128_1 == 12, "");
   static_assert(I128_1 != 10, "");
@@ -40,12 +48,7 @@ namespace i128 {
// expected-note{{evaluates to}} \
// ref-note{{evaluates to}}
 
-  static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
-  static_assert(UINT128_MAX == -1, "");
 
-  static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
-  static_assert(INT128_MAX != 0, "");
-  static const __int128_t INT128_MIN = -INT128_MAX - 1;
   constexpr __int128 A = INT128_MAX + 1; // expected-error {{must be 
initialized by a constant expression}} \
  // expected-note {{outside the 
range}} \
  // ref-error {{must be initialized by 
a constant expression}} \
@@ -118,4 +121,49 @@ namespace AddSubOffset {
   static_assert(*P2 == 1,"");
 }
 
+namespace IncDec {
+#if 0
+  constexpr int128_t maxPlus1(bool Pre) {
+int128_t a = INT128_MAX;
+
+if (Pre)
+  ++a; // ref-note {{value 170141183460469231731687303715884105728 is 
outside the range}} \
+   // expected-note {{value 170141183460469231731687303715884105728 is 
outside the range}}
+else
+  a++;
+return a;
+  }
+  static_assert(maxPlus1(true) == 0, ""); // ref-error {{not an integral 
constant expression}} \
+  // ref-note in call to}} \
+  // expected-error {{not an integral 
constant expression}} \
+  // expected-note in call to}}
+  static_assert(maxPlus1(false) == 0, ""); // ref-error {{not an integral 
constant expression}} \
+   // ref-note in call to}} \
+   // expected-error {{not an integral 
constant expression}} \
+   // expected-note in call to}}
+
+  c

[clang] [clang][Interp] Only diagnose null field access in constant contexts (PR #69223)

2023-10-24 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 



@@ -295,7 +295,7 @@ class Pointer {
   bool isUnion() const;
 
   /// Checks if the storage is extern.
-  bool isExtern() const { return Pointee->isExtern(); }
+  bool isExtern() const { return Pointee && Pointee->isExtern(); }

tbaederr wrote:

We could. Do you want me to add them?

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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-24 Thread via cfe-commits

joanahalili wrote:

Hello, 
This commit is causing clang crashes on our end. Here is a reproducer:

repro Cmd: `clang -O0  -std=gnu++20  -fsized-deallocation -Xclang 
-target-feature -Xclang +sse4.2  -c fileName.ii`

where fileName.ii is
```
template  bool c = __is_constructible(a, b...);
template  using d = int;
template  bool e;
template  struct f;
template  struct h {
  static void i() { c; }
};
struct j {
  template , int> = 0>
  void l(unsigned long, f (k::*)());
};
template  void j::l(unsigned long, f (k::*)()) {
  h::i;
}
struct m : j {
  struct n;
  void o() { l(8, &m::p); }
  f p();
};
struct m::n {
  int q : 1;
};

```

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


[clang] f7a46d7 - [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (#67663)

2023-10-24 Thread via cfe-commits

Author: Endre Fülöp
Date: 2023-10-24T13:59:54+02:00
New Revision: f7a46d700f6458a382304339c5b3589bf30ae45d

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

LOG: [analyzer][clangsa] Add new option to 
alpha.security.cert.InvalidPtrChecker (#67663)

Introduce 'InvalidatingGetEnv' checker option for 'getenv' calls.

- POSIX suggests consecutive 'getenv' calls may invalidate 
  pointer pointers. This is often too strict in real-world scenarios.
- New 'InvalidatingGetEnv' checker option provides a more 
  pragmatic default that doesn't treat consecutive 'getenv' 
  calls as invalidating.
- Now also handles main function specifications with an 
  environment pointer as the third parameter.

Original Phabricator review:
https://reviews.llvm.org/D154603

Added: 
clang/test/Analysis/invalid-ptr-checker.c

Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/cert/env34-c-cert-examples.c
clang/test/Analysis/cert/env34-c.c

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 597ffcc4a10a25b..43137f4b020f9f7 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2520,13 +2520,34 @@ pointer. These functions include: getenv, localeconv, 
asctime, setlocale, strerr
 char *p, *pp;
 
 p = getenv("VAR");
-pp = getenv("VAR2");
-// subsequent call to 'getenv' invalidated previous one
+setenv("SOMEVAR", "VALUE", /*overwrite = */1);
+// call to 'setenv' may invalidate p
 
 *p;
 // dereferencing invalid pointer
   }
 
+
+The ``InvalidatingGetEnv`` option is available for treating getenv calls as
+invalidating. When enabled, the checker issues a warning if getenv is called
+multiple times and their results are used without first creating a copy.
+This level of strictness might be considered overly pedantic for the commonly
+used getenv implementations.
+
+To enable this option, use:
+``-analyzer-config 
alpha.security.cert.env.InvalidPtr:InvalidatingGetEnv=true``.
+
+By default, this option is set to *false*.
+
+When this option is enabled, warnings will be generated for scenarios like the
+following:
+
+.. code-block:: c
+
+  char* p = getenv("VAR");
+  char* pp = getenv("VAR2"); // assumes this call can invalidate `env`
+  strlen(p); // warns about accessing invalid ptr
+
 alpha.security.taint
 
 

diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index be813bde8be41ea..b6e9f0fae1c7f48 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1002,6 +1002,15 @@ let ParentPackage = ENV in {
 
   def InvalidPtrChecker : Checker<"InvalidPtr">,
   HelpText<"Finds usages of possibly invalidated pointers">,
+  CheckerOptions<[
+CmdLineOption,
+  ]>,
   Documentation;
 
 } // end "alpha.cert.env"

diff  --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index aae1a17bc0ae53e..e5dd907c660d8ea 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -30,7 +30,10 @@ namespace {
 class InvalidPtrChecker
 : public Checker {
 private:
-  BugType BT{this, "Use of invalidated pointer", categories::MemoryError};
+  // For accurate emission of NoteTags, the BugType of this checker should have
+  // a unique address.
+  BugType InvalidPtrBugType{this, "Use of invalidated pointer",
+categories::MemoryError};
 
   void EnvpInvalidatingCall(const CallEvent &Call, CheckerContext &C) const;
 
@@ -38,6 +41,15 @@ class InvalidPtrChecker
 CheckerContext &C) const;
 
   // SEI CERT ENV31-C
+
+  // If set to true, consider getenv calls as invalidating operations on the
+  // environment variable buffer. This is implied in the standard, but in
+  // practice does not cause problems (in the commonly used environments).
+  bool InvalidatingGetEnv = false;
+
+  // GetEnv can be treated invalidating and non-invalidating as well.
+  const CallDescription GetEnvCall{{"getenv"}, 1};
+
   const CallDescriptionMap EnvpInvalidatingFunctions = {
   {{{"setenv"}, 3}, &InvalidPtrChecker::EnvpInvalidatingCall},
   {{{"unsetenv"}, 1}, &InvalidPtrChecker::EnvpInvalidatingCall},
@@ -51,7 +63,6 @@ class InvalidPtrChecker
 
   // SEI CERT ENV34-C
   const CallDescriptionMap PreviousCallInvalidatingFunctions = {
-  {{

[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-24 Thread Endre Fülöp via cfe-commits

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


[clang] 82f75ed - [Driver] Ignore non-clang pch files when -include a.h probes a.h.gch (#69204)

2023-10-24 Thread via cfe-commits

Author: Hans
Date: 2023-10-24T14:03:13+02:00
New Revision: 82f75ed5997c317350b539dc185f5dbe2ec197a3

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

LOG: [Driver] Ignore non-clang pch files when -include a.h probes a.h.gch 
(#69204)

Instead of deprecating the "gch probe" as in
f726da1193baf51e0a66453cc32dcffb8a9121d4, this makes clang ignore files
which are not clang pch files (See discussion on PR #67084).

This fixes the issues mentioned in the former patch, with GCC-generated
.gch files getting in the way when using clang, while maintaining the
probing behavior for builds which rely on that.

Added: 
clang/test/PCH/Inputs/gch-probe.h
clang/test/PCH/Inputs/gch-probe.h.gch
clang/test/PCH/gch-probe.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/PCH/pch-dir.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 65c1c07e3ded9f6..4c24216888525cd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -43,8 +43,8 @@ C/C++ Language Potentially Breaking Changes
 
 - The default extension name for PCH generation (``-c -xc-header`` and ``-c
   -xc++-header``) is now ``.pch`` instead of ``.gch``.
-- ``-include a.h`` probing ``a.h.gch`` is deprecated. Change the extension name
-  to ``.pch`` or use ``-include-pch a.h.gch``.
+- ``-include a.h`` probing ``a.h.gch`` will now ignore ``a.h.gch`` if it is not
+  a clang pch file or a directory containing any clang pch file.
 - Fixed a bug that caused ``__has_cpp_attribute`` and ``__has_c_attribute``
   return incorrect values for some C++-11-style attributes. Below is a complete
   list of behavior changes.

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 6110c6d6ea195b8..5dbc5b5edfb4aeb 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -441,11 +441,14 @@ def warn_drv_overriding_option : Warning<
 def warn_drv_treating_input_as_cxx : Warning<
   "treating '%0' input as '%1' when in C++ mode, this behavior is deprecated">,
   InGroup;
-def warn_drv_include_probe_gch : Warning<
-  "'%0' probing .gch is deprecated. Use '-include-pch %1' or switch to .pch 
instead">,
-  InGroup;
 def warn_drv_pch_not_first_include : Warning<
   "precompiled header '%0' was ignored because '%1' is not first '-include'">;
+def warn_drv_pch_ignoring_gch_file : Warning<
+  "precompiled header '%0' was ignored because it is not a clang PCH file">,
+  InGroup;
+def warn_drv_pch_ignoring_gch_dir : Warning<
+  "precompiled header directory '%0' was ignored because it contains no clang 
PCH files">,
+  InGroup;
 def warn_missing_sysroot : Warning<"no such sysroot directory: '%0'">,
   InGroup>;
 def warn_incompatible_sysroot : Warning<"using sysroot for '%0' but targeting 
'%1'">,

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index ee4383216bdccf7..318eb0d6f889065 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -210,7 +210,6 @@ def DeprecatedWritableStr : 
DiagGroup<"deprecated-writable-strings",
   [CXX11CompatDeprecatedWritableStr]>;
 def DeprecatedPragma : DiagGroup<"deprecated-pragma">;
 def DeprecatedType : DiagGroup<"deprecated-type">;
-def DeprecatedIncludeGch : DiagGroup<"deprecated-include-gch">;
 // FIXME: Why is DeprecatedImplementations not in this group?
 def Deprecated : DiagGroup<"deprecated", [DeprecatedAnonEnumEnumConversion,
   DeprecatedArrayCompare,
@@ -233,8 +232,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedType,
   DeprecatedVolatile,
   DeprecatedWritableStr,
-  
DeprecatedRedundantConstexprStaticDef,
-  DeprecatedIncludeGch
+  DeprecatedRedundantConstexprStaticDef
   ]>,
  DiagCategory<"Deprecations">;
 
@@ -444,6 +442,7 @@ def IncrementBool : DiagGroup<"increment-bool", 
[DeprecatedIncrementBool]>;
 def InfiniteRecursion : DiagGroup<"infinite-recursion">;
 def PureVirtualCallFromCtorDtor: 
DiagGroup<"call-to-pure-virtual-from-ctor-dtor">;
 def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">;
+def IgnoredGCH : DiagGroup<"ign

[clang] [Driver] Ignore non-clang pch files when -include a.h probes a.h.gch (PR #69204)

2023-10-24 Thread via cfe-commits

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


[clang] [AArch64] Implement reinterpret builtins for SVE vector tuples (PR #69598)

2023-10-24 Thread via cfe-commits


@@ -263,17 +267,11 @@ class SVEEmitter {
   // which is inconvenient to specify in the arm_sve.td file or
   // generate in CGBuiltin.cpp.
   struct ReinterpretTypeInfo {
+SVEType BaseType;
 const char *Suffix;
-const char *Type;
-const char *BuiltinType;
   };
-  SmallVector Reinterprets = {

CarolineConcatto wrote:

Why you cannot do as you did before and only create an array for each size _x2, 
_x3 and _x4?

I  believe you've changed  the class SVEType, so you could use SVEType 
ToV(To.BaseType, N); and SVEType FromV(From.BaseType, N);.  I am not sure we 
should do that. 

But I am not sure if the changes are worth.

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


[clang] Revert "[clang] Support fixed point types in C++ (#67750)" (PR #69963)

2023-10-24 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/69963

>From 340e3777509f70b5b300adcb181261e84247cf1a Mon Sep 17 00:00:00 2001
From: Ammarguellat 
Date: Mon, 23 Oct 2023 12:51:21 -0700
Subject: [PATCH 1/3] Revert "[clang] Support fixed point types in C++
 (#67750)"

This reverts commit a3a7d6318027bb86e6614c022e77e0bd81aef6dc.

When compiling with MSVC2022 in  C++32 mode this is giving an
error.
Compiling this simple test case:
t1.cpp:
with -std=c++23 will give the following error:

In file included from C:\Users\zahiraam\t1.cpp:1:
c:\Program files\Microsoft Visual
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3329:16:
error:
  compile with '-ffixed-point' to enable fixed point types
   3329 | _Vbase _Accum = 0;
 |^
c:\Program files\Microsoft Visual
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3329:23:
error:
  expected unqualified-id
   3329 | _Vbase _Accum = 0;
 |   ^
Please full error in
https://github.com/llvm/llvm-project/pull/67750#issuecomment-1775264907
---
 clang/include/clang/Basic/TokenKinds.def |  6 +-
 clang/include/clang/Driver/Options.td|  2 +-
 clang/lib/AST/ItaniumMangle.cpp  | 59 +---
 clang/lib/Parse/ParseExpr.cpp|  3 -
 clang/lib/Parse/ParseExprCXX.cpp |  9 ---
 clang/lib/Parse/ParseTentative.cpp   |  6 --
 clang/test/CodeGenCXX/fixed-point-mangle.cpp | 45 ---
 clang/test/Frontend/fixed_point_errors.cpp   | 24 
 8 files changed, 15 insertions(+), 139 deletions(-)
 delete mode 100644 clang/test/CodeGenCXX/fixed-point-mangle.cpp

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index bbae1200d376c0d..3ce317d318f9bb6 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -423,9 +423,9 @@ C23_KEYWORD(typeof  , KEYGNU)
 C23_KEYWORD(typeof_unqual   , 0)
 
 // ISO/IEC JTC1 SC22 WG14 N1169 Extension
-KEYWORD(_Accum  , KEYALL)
-KEYWORD(_Fract  , KEYALL)
-KEYWORD(_Sat, KEYALL)
+KEYWORD(_Accum  , KEYNOCXX)
+KEYWORD(_Fract  , KEYNOCXX)
+KEYWORD(_Sat, KEYNOCXX)
 
 // GNU Extensions (in impl-reserved namespace)
 KEYWORD(_Decimal32  , KEYALL)
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e63158fb0e5333a..ca883689b05c28a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2097,7 +2097,7 @@ defm fixed_point : BoolFOption<"fixed-point",
   LangOpts<"FixedPoint">, DefaultFalse,
   PosFlag,
   NegFlag,
-  BothFlags<[], [ClangOption], " fixed point types">>;
+  BothFlags<[], [ClangOption], " fixed point types">>, 
ShouldParseIf;
 defm cxx_static_destructors : BoolFOption<"c++-static-destructors",
   LangOpts<"RegisterStaticDestructors">, DefaultTrue,
   NegFlag# vendor extended type
-  //
-  //  
-  // ::= s # short
-  // ::= t # unsigned short
-  // ::= i # plain
-  // ::= j # unsigned
-  // ::= l # long
-  // ::= m # unsigned long
   std::string type_name;
   // Normalize integer types as vendor extended types:
   // ui
@@ -3205,77 +3195,30 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
 Out << "DF16_";
 break;
   case BuiltinType::ShortAccum:
-Out << "DAs";
-break;
   case BuiltinType::Accum:
-Out << "DAi";
-break;
   case BuiltinType::LongAccum:
-Out << "DAl";
-break;
   case BuiltinType::UShortAccum:
-Out << "DAt";
-break;
   case BuiltinType::UAccum:
-Out << "DAj";
-break;
   case BuiltinType::ULongAccum:
-Out << "DAm";
-break;
   case BuiltinType::ShortFract:
-Out << "DRs";
-break;
   case BuiltinType::Fract:
-Out << "DRi";
-break;
   case BuiltinType::LongFract:
-Out << "DRl";
-break;
   case BuiltinType::UShortFract:
-Out << "DRt";
-break;
   case BuiltinType::UFract:
-Out << "DRj";
-break;
   case BuiltinType::ULongFract:
-Out << "DRm";
-break;
   case BuiltinType::SatShortAccum:
-Out << "DSDAs";
-break;
   case BuiltinType::SatAccum:
-Out << "DSDAi";
-break;
   case BuiltinType::SatLongAccum:
-Out << "DSDAl";
-break;
   case BuiltinType::SatUShortAccum:
-Out << "DSDAt";
-break;
   case BuiltinType::SatUAccum:
-Out << "DSDAj";
-break;
   case BuiltinType::SatULongAccum:
-Out << "DSDAm";
-break;
   case BuiltinType::SatShortFract:
-Out << "DSDRs";
-break;
   case BuiltinType::SatFract:
-Out << "DSDRi";
-break;
   case BuiltinType::SatLongFract:
-Out << "DSDRl";
-break;
   case BuiltinType::SatUShortFra

[clang] Revert "[clang] Support fixed point types in C++ (#67750)" (PR #69963)

2023-10-24 Thread Zahira Ammarguellat via cfe-commits

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


[clang] Revert "[clang] Support fixed point types in C++ (#67750)" (PR #69963)

2023-10-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Zahira Ammarguellat (zahiraam)


Changes

This reverts commit a3a7d6318027bb86e6614c022e77e0bd81aef6dc.

When compiling with MSVC2022 in  C++32 mode this is giving an error.
Compiling this simple test case:
t1.cpp:
with -std=c++23 will give the following error:

In file included from C:\Users\zahiraam\t1.cpp:1:
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3329:16: 
error:
  compile with '-ffixed-point' to enable fixed point types
 3329 | _Vbase _Accum = 0;
  |^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3329:23: 
error:
  expected unqualified-id
 3329 | _Vbase _Accum = 0;
  |   ^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3334:13: 
error:
  compile with '-ffixed-point' to enable fixed point types
 3334 | _Accum |= _Tmp ? _Mask : _Vbase{0};
  | ^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3334:20: 
error:
  expected unqualified-id
 3334 | _Accum |= _Tmp ? _Mask : _Vbase{0};
  |^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3336:53: 
error:
  expected '(' for function-style cast or type construction
 3336 | this->_Emplace_back_unchecked(_Accum);
  |   ~~^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3337:17: 
error:
  compile with '-ffixed-point' to enable fixed point types
 3337 | _Accum = 0;
  | ^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3337:24: 
error:
  expected unqualified-id
 3337 | _Accum = 0;
  |^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3343:49: 
error:
  expected '(' for function-style cast or type construction
 3343 | this->_Emplace_back_unchecked(_Accum);
  |   ~~^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3352:16: 
error:
  compile with '-ffixed-point' to enable fixed point types
 3352 | _Vbase _Accum= 0;
  |^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3352:26: 
error:
  expected unqualified-id
 3352 | _Vbase _Accum= 0;
  |  ^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3357:13: 
error:
  compile with '-ffixed-point' to enable fixed point types
 3357 | _Accum |= _Tmp ? _Mask : _Vbase{0};
  | ^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3357:20: 
error:
  expected unqualified-id
 3357 | _Accum |= _Tmp ? _Mask : _Vbase{0};
  |^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3359:46: 
error:
  expected '(' for function-style cast or type construction
 3359 | this->_Myvec.push_back(_Accum);
  |~~^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3360:17: 
error:
  compile with '-ffixed-point' to enable fixed point types
 3360 | _Accum = 0;
  | ^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3360:24: 
error:
  expected unqualified-id
 3360 | _Accum = 0;
  |^
c:\Program files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3366:42: 
error:
  expected '(' for function-style cast or type construction
 3366 | this->_Myvec.push_back(_Accum);
  |~~^
16 errors generated.

See also comment here: 
https://github.com/llvm/llvm-project/pull/67750#issuecomment-1775264907

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


8 Files Affected:

- (modified) clang/include/clang/Basic/TokenKinds.def (+3-3) 
- (modified) clang/include/clang/Driver/Options.td (+1-1) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+3-59) 
- (modified) clang/lib/Parse/ParseExpr.cpp (-3) 
- (modified) clang/lib/Parse/ParseExprCXX.cpp (-9) 
- (modified) clang/lib/Parse/ParseTentative.cpp (-6) 
- (removed) clang/test/CodeGenCXX/fixed-point-mangle.cpp (-45) 
- (modified) clang/

[clang] [clang][NFC] Refactor `Selector` to use `PointerIntPair` inside (PR #69916)

2023-10-24 Thread Aaron Ballman via cfe-commits


@@ -809,43 +927,42 @@ class Selector {
   enum IdentifierInfoFlag {
 // Empty selector = 0. Note that these enumeration values must
 // correspond to the enumeration values of DeclarationName::StoredNameKind
-ZeroArg  = 0x01,
-OneArg   = 0x02,
+ZeroArg = 0x01,
+OneArg = 0x02,
 MultiArg = 0x07,
-ArgFlags = 0x07
   };
 
   /// A pointer to the MultiKeywordSelector or IdentifierInfo. We use the low
-  /// three bits of InfoPtr to store an IdentifierInfoFlag. Note that in any
+  /// three bits of InfoPtr to store an IdentifierInfoFlag, but the highest
+  /// of them is also a discriminator for pointer type. Note that in any
   /// case IdentifierInfo and MultiKeywordSelector are already aligned to
   /// 8 bytes even on 32 bits archs because of DeclarationName.
-  uintptr_t InfoPtr = 0;
+  llvm::PointerIntPair<
+  llvm::PointerUnion, 2>
+  InfoPtr;
 
   Selector(IdentifierInfo *II, unsigned nArgs) {
-InfoPtr = reinterpret_cast(II);
-assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned 
IdentifierInfo");
 assert(nArgs < 2 && "nArgs not equal to 0/1");
-InfoPtr |= nArgs+1;
+InfoPtr.setPointerAndInt(II, nArgs + 1);
   }
 
   Selector(MultiKeywordSelector *SI) {
-InfoPtr = reinterpret_cast(SI);
-assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned 
IdentifierInfo");
-InfoPtr |= MultiArg;
+InfoPtr.setPointerAndInt(SI, MultiArg & 0b11);

AaronBallman wrote:

It's a bit strange to me that `MultiArg` is 0x7 and not 0x3 to begin with; are 
we able to reorder `DeclarationName::StoredNameKind` such that 
`StoredDeclarationNameExtra` is value 3 and then we can shave a bit off from 
the value of `MultiArg` and not have to do this odd masking here?

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


[clang] [AMDGPU] Add an option to disable unsafe uses of atomic xor (PR #69229)

2023-10-24 Thread Pierre-Andre Saulais via cfe-commits

pasaulais wrote:

Thanks for the review. I agree that function-level attributes are not ideal for 
solving this issue and instruction-level metadata would work better with things 
like inlining. Is the incomplete patch you mentioned something I could take on 
and complete?

Regarding int vs floating-point, I'm afraid there is a need for toggling one 
independently of the other (or at least special-casing operations like XOR that 
are not supported by PCIe 3.0). As the link I posted in the description 
mentions (see this comment 
https://github.com/RadeonOpenCompute/ROCm/issues/2481#issuecomment-1725874765), 
there are configurations where using FP atomics like add would work whereas XOR 
doesn't, due to missing support in the PCIe 3.0 spec. I have reproduced this on 
a system with a RX 6700 XT GPU, where `global_atomic_add_f32` works as expected 
using fine-grained allocations, and `global_atomic_xor` doesn't.

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-10-24 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


cor3ntin wrote:

> Kind of - [this 
> run](http://llvm-compile-time-tracker.com/compare.php?from=6ade5183232dc1398205d7c9dbe21243b2560837&to=5ad516d39b6706af6fd55eded264aba4ba432ad2&stat=instructions:u)
>  only shows noticeable slowdown in one test. But we also only highlight the 
> main file right now - that means we don't get syntax highlighting in included 
> files and implementing that would probably make it a bit slower as well since 
> we'd have to map the save points to their FileID.

I think we should do it for includes to.
Did you play with `reserve`? I think it would be reasonable to preallocate 
maybe ~1k check points - which should just be 8kb per file, which would be 
reasonable

> Regardless of the approach we take in the end - what do you think about tests 
> for this? Should we have a flag similar to 
> `-fdiagnostics-print-source-range-info` for the code style ranges?

I have no opinion. @AaronBallman ?


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


[libclc] [AMDGPU][MachineScheduler] Alternative way to control excess RP. (PR #68004)

2023-10-24 Thread via cfe-commits


@@ -959,16 +970,6 @@ void GCNSchedStage::checkScheduling() {
   << DAG.MinOccupancy << ".\n");
   }
 
-  unsigned MaxVGPRs = ST.getMaxNumVGPRs(MF);
-  unsigned MaxSGPRs = ST.getMaxNumSGPRs(MF);
-  if (PressureAfter.getVGPRNum(false) > MaxVGPRs ||
-  PressureAfter.getAGPRNum() > MaxVGPRs ||
-  PressureAfter.getSGPRNum() > MaxSGPRs) {
-DAG.RescheduleRegions[RegionIdx] = true;

alex-t wrote:

Because the ST.getMaxNumVGPRs(MF) would return the same value as the 
S.VGPRExcessLimit.
The latter gets initialized in GCNSchedStrategy::initialize as `VGPRExcessLimit 
=
  Context->RegClassInfo->getNumAllocatableRegs(&AMDGPU::VGPR_32RegClass);`
and the RegClassInfo initialize the value in SIRegisterInfo::getReservedRegs as 
`unsigned MaxNumVGPRs = ST.getMaxNumVGPRs(MF);`
So, yes, they are wavesPerEU aware.

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


[clang-tools-extra] [AMDGPU][MachineScheduler] Alternative way to control excess RP. (PR #68004)

2023-10-24 Thread via cfe-commits


@@ -959,16 +970,6 @@ void GCNSchedStage::checkScheduling() {
   << DAG.MinOccupancy << ".\n");
   }
 
-  unsigned MaxVGPRs = ST.getMaxNumVGPRs(MF);
-  unsigned MaxSGPRs = ST.getMaxNumSGPRs(MF);
-  if (PressureAfter.getVGPRNum(false) > MaxVGPRs ||
-  PressureAfter.getAGPRNum() > MaxVGPRs ||
-  PressureAfter.getSGPRNum() > MaxSGPRs) {
-DAG.RescheduleRegions[RegionIdx] = true;

alex-t wrote:

Because the ST.getMaxNumVGPRs(MF) would return the same value as the 
S.VGPRExcessLimit.
The latter gets initialized in GCNSchedStrategy::initialize as `VGPRExcessLimit 
=
  Context->RegClassInfo->getNumAllocatableRegs(&AMDGPU::VGPR_32RegClass);`
and the RegClassInfo initialize the value in SIRegisterInfo::getReservedRegs as 
`unsigned MaxNumVGPRs = ST.getMaxNumVGPRs(MF);`
So, yes, they are wavesPerEU aware.

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


[clang-tools-extra] [clang] Correct end for the `CastOperation.OpRange` (PR #69480)

2023-10-24 Thread via cfe-commits
Botond =?utf-8?q?István_Horváth?=,
Botond =?utf-8?q?István_Horváth?Message-ID:
In-Reply-To: 



@@ -1,7 +1,13 @@
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 
2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info 
-Wcast-function-type-strict %s 2>&1 | FileCheck %s
 
 struct S {
   char a : 12 - 12;
 };
 // CHECK: misc-source-ranges.cpp:[[@LINE-2]]:8:{[[@LINE-2]]:12-[[@LINE-2]]:19}
 
+using fun = long(*)(int&);
+fun foo(){
+  long (*f_ptr)(const int&);

whisperity wrote:

```suggestion
  long (*f_ptr)(const int &);
```
Format.

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


[clang] [clang] Correct end for the `CastOperation.OpRange` (PR #69480)

2023-10-24 Thread via cfe-commits
Botond =?utf-8?q?István_Horváth?=,
Botond =?utf-8?q?István_Horváth?Message-ID:
In-Reply-To: 



@@ -326,6 +326,25 @@ Improvements to Clang's diagnostics
 - Clang now always diagnoses when using non-standard layout types in 
``offsetof`` .
   (`#64619: `_)
 
+- When describing a warning/error in a function-style type converson clang 
underscored only until
+  the end of the expression we convert from. Now clang underscores the until 
the closing bracket.

whisperity wrote:

```suggestion
- When describing a warning/error in a function-style type conversion Clang 
underlines only until
  the end of the expression we convert from. Now, Clang underlines until the 
closing parenthesis.
```

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


[clang-tools-extra] [clang] Correct end for the `CastOperation.OpRange` (PR #69480)

2023-10-24 Thread via cfe-commits
Botond =?utf-8?q?Istv=C3=A1n_Horv=C3=A1th?=,
Botond =?utf-8?q?Istv=C3=A1n_Horv=C3=A1th?=
Message-ID:
In-Reply-To: 


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


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


[clang] [clang] Correct end for the `CastOperation.OpRange` (PR #69480)

2023-10-24 Thread via cfe-commits
Botond =?utf-8?q?István_Horváth?=,
Botond =?utf-8?q?István_Horváth?Message-ID:
In-Reply-To: 



@@ -1,7 +1,13 @@
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 
2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info 
-Wcast-function-type-strict %s 2>&1 | FileCheck %s
 
 struct S {
   char a : 12 - 12;
 };
 // CHECK: misc-source-ranges.cpp:[[@LINE-2]]:8:{[[@LINE-2]]:12-[[@LINE-2]]:19}
 
+using fun = long(*)(int&);
+fun foo(){
+  long (*f_ptr)(const int&);

whisperity wrote:

```suggestion
  long (*f_ptr)(const int &);
```
Format.

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


[clang] [clang] Correct end for the `CastOperation.OpRange` (PR #69480)

2023-10-24 Thread via cfe-commits
Botond =?utf-8?q?István_Horváth?=,
Botond =?utf-8?q?István_Horváth?Message-ID:
In-Reply-To: 



@@ -1,7 +1,13 @@
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 
2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info 
-Wcast-function-type-strict %s 2>&1 | FileCheck %s
 
 struct S {
   char a : 12 - 12;
 };
 // CHECK: misc-source-ranges.cpp:[[@LINE-2]]:8:{[[@LINE-2]]:12-[[@LINE-2]]:19}
 
+using fun = long(*)(int&);

whisperity wrote:

```suggestion
using fun = long(*)(int &);
```
Format.

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


[clang] [clang] Correct end for the `CastOperation.OpRange` (PR #69480)

2023-10-24 Thread via cfe-commits
Botond =?utf-8?q?Istv=C3=A1n_Horv=C3=A1th?=,
Botond =?utf-8?q?Istv=C3=A1n_Horv=C3=A1th?=
Message-ID:
In-Reply-To: 


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


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


[clang-tools-extra] [clang] Correct end for the `CastOperation.OpRange` (PR #69480)

2023-10-24 Thread via cfe-commits
Botond =?utf-8?q?István_Horváth?=,
Botond =?utf-8?q?István_Horváth?Message-ID:
In-Reply-To: 



@@ -326,6 +326,25 @@ Improvements to Clang's diagnostics
 - Clang now always diagnoses when using non-standard layout types in 
``offsetof`` .
   (`#64619: `_)
 
+- When describing a warning/error in a function-style type converson clang 
underscored only until
+  the end of the expression we convert from. Now clang underscores the until 
the closing bracket.

whisperity wrote:

```suggestion
- When describing a warning/error in a function-style type conversion Clang 
underlines only until
  the end of the expression we convert from. Now, Clang underlines until the 
closing parenthesis.
```

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


[clang-tools-extra] [clang] Correct end for the `CastOperation.OpRange` (PR #69480)

2023-10-24 Thread via cfe-commits
Botond =?utf-8?q?István_Horváth?=,
Botond =?utf-8?q?István_Horváth?Message-ID:
In-Reply-To: 



@@ -1,7 +1,13 @@
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 
2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info 
-Wcast-function-type-strict %s 2>&1 | FileCheck %s
 
 struct S {
   char a : 12 - 12;
 };
 // CHECK: misc-source-ranges.cpp:[[@LINE-2]]:8:{[[@LINE-2]]:12-[[@LINE-2]]:19}
 
+using fun = long(*)(int&);

whisperity wrote:

```suggestion
using fun = long(*)(int &);
```
Format.

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


[libclc] [AMDGPU][MachineScheduler] Alternative way to control excess RP. (PR #68004)

2023-10-24 Thread via cfe-commits


@@ -894,10 +894,22 @@ void GCNSchedStage::setupNewBlock() {
 
 void GCNSchedStage::finalizeGCNRegion() {
   DAG.Regions[RegionIdx] = std::pair(DAG.RegionBegin, DAG.RegionEnd);
-  DAG.RescheduleRegions[RegionIdx] = false;

alex-t wrote:

Should not we mark for rescheduling the "excess RP" regions only?

`if ((NewVGPRRP >= S.VGPRExcessLimit - S.VGPRExcessMargin) ||
  (NewAGPRRP >= S.VGPRExcessLimit - S.VGPRExcessMargin) ||
  (NewSGPRRP >= S.SGPRExcessLimit - S.SGPRExcessMargin)) {
DAG.RegionsWithExcessRP[RegionIdx] = true;
DAG.RescheduleRegions[RegionIdx] = true;
  }`

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


[libclc] [AMDGPU][MachineScheduler] Alternative way to control excess RP. (PR #68004)

2023-10-24 Thread via cfe-commits


@@ -702,7 +702,7 @@ bool UnclusteredHighRPStage::initGCNSchedStage() {
   if (!GCNSchedStage::initGCNSchedStage())
 return false;
 
-  if (DAG.RegionsWithHighRP.none() && DAG.RegionsWithExcessRP.none())
+  if (DAG.RegionsWithExcessRP.none())

alex-t wrote:

This change was intended to be the preliminary for the balanced scheduling 
model.
Maybe it is better to join it with the large change or revert the line in 
question.
Nevertheless, I would like to see if this affects the performance.

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-10-24 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

@arsenm?

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


[libunwind] [AMDGPU][MachineScheduler] Alternative way to control excess RP. (PR #68004)

2023-10-24 Thread via cfe-commits


@@ -1117,16 +1118,23 @@ bool 
OccInitialScheduleStage::shouldRevertScheduling(unsigned WavesAfter) {
 bool UnclusteredHighRPStage::shouldRevertScheduling(unsigned WavesAfter) {
   // If RP is not reduced in the unclustered reschedule stage, revert to the
   // old schedule.
-  if ((WavesAfter <= PressureBefore.getOccupancy(ST) &&
-   mayCauseSpilling(WavesAfter)) ||
-  GCNSchedStage::shouldRevertScheduling(WavesAfter)) {
-LLVM_DEBUG(dbgs() << "Unclustered reschedule did not help.\n");
-return true;
-  }
+  if (DAG.RegionsWithExcessRP[RegionIdx]) {

alex-t wrote:

The higher RP is necessary for the occupancy drop so it will be reverted.

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


[libclc] [AMDGPU][MachineScheduler] Alternative way to control excess RP. (PR #68004)

2023-10-24 Thread via cfe-commits


@@ -1117,16 +1118,23 @@ bool 
OccInitialScheduleStage::shouldRevertScheduling(unsigned WavesAfter) {
 bool UnclusteredHighRPStage::shouldRevertScheduling(unsigned WavesAfter) {
   // If RP is not reduced in the unclustered reschedule stage, revert to the
   // old schedule.
-  if ((WavesAfter <= PressureBefore.getOccupancy(ST) &&
-   mayCauseSpilling(WavesAfter)) ||
-  GCNSchedStage::shouldRevertScheduling(WavesAfter)) {
-LLVM_DEBUG(dbgs() << "Unclustered reschedule did not help.\n");
-return true;
-  }
+  if (DAG.RegionsWithExcessRP[RegionIdx]) {

alex-t wrote:

The higher RP is necessary for the occupancy drop so it will be reverted.

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


[clang] [Clang][DebugInfo] Clang generates an extra spurious unnamed 'dbg.declare' (PR #69681)

2023-10-24 Thread Carlos Alberto Enciso via cfe-commits

https://github.com/CarlosAlbertoEnciso updated 
https://github.com/llvm/llvm-project/pull/69681

>From eef5d041e6b2fe02bba86113a41035324c6c81b8 Mon Sep 17 00:00:00 2001
From: Carlos Alberto Enciso 
Date: Fri, 20 Oct 2023 06:09:04 +0100
Subject: [PATCH 1/2] [Clang][DebugInfo] Clang generates an extra spurious
 unnamed 'dbg.declare'.

Do not emit call to llvm.dbg.declare when the variable declaration
is a DecompositionDecl as its instance class is always unnamed.

The emitted debug declare looks like:

  call void @llvm.dbg.declare(metadata ..., metadata !xx, metadata ...)
  !xx = !DILocalVariable(scope: !..., file: !..., line: ..., type: !...)
---
 clang/lib/CodeGen/CGDebugInfo.cpp |  6 +-
 ...debug-info-structured-binding-bitfield.cpp |  3 ---
 .../debug-info-structured-binding-field.cpp   | 20 +++
 .../debug-info-structured-binding.cpp |  2 --
 4 files changed, 25 insertions(+), 6 deletions(-)
 create mode 100644 
clang/test/CodeGenCXX/debug-info-structured-binding-field.cpp

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 181e500b9671759..0aaf678bf287c6e 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4881,11 +4881,15 @@ CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl 
*VD, llvm::Value *Storage,
const bool UsePointerValue) {
   assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
 
-  if (auto *DD = dyn_cast(VD))
+  if (auto *DD = dyn_cast(VD)) {
 for (auto *B : DD->bindings()) {
   EmitDeclare(B, Storage, std::nullopt, Builder,
   VD->getType()->isReferenceType());
 }
+// Don't emit an llvm.dbg.declare for the composite storage as it doesn't
+// correspond to a user variable.
+return nullptr;
+  }
 
   return EmitDeclare(VD, Storage, std::nullopt, Builder, UsePointerValue);
 }
diff --git a/clang/test/CodeGenCXX/debug-info-structured-binding-bitfield.cpp 
b/clang/test/CodeGenCXX/debug-info-structured-binding-bitfield.cpp
index b5ee96224565d3a..0234e41009f6225 100644
--- a/clang/test/CodeGenCXX/debug-info-structured-binding-bitfield.cpp
+++ b/clang/test/CodeGenCXX/debug-info-structured-binding-bitfield.cpp
@@ -189,7 +189,6 @@ struct S11 {
 // CHECK-LABEL: define dso_local void @_Z4fS11v
 // CHECK:alloca %struct.S11, align 4
 // CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S11, align 4
-// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]]
 // CHECK-NOT: call void @llvm.dbg.declare(metadata ptr [[TMP0]]
 //
 void fS11() {
@@ -206,7 +205,6 @@ struct S12 {
 // CHECK:alloca %struct.S12, align 4
 // CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S12, align 4
 // CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata 
[[S12_A:![0-9]+]], metadata !DIExpression())
-// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]]
 // CHECK-NOT: call void @llvm.dbg.declare(metadata ptr [[TMP0]]
 //
 void fS12() {
@@ -222,7 +220,6 @@ struct __attribute__((packed)) S13 {
 // CHECK-LABEL: define dso_local void @_Z4fS13v
 // CHECK:alloca %struct.S13, align 1
 // CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S13, align 1
-// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata 
{{.*}}, metadata !DIExpression())
 // CHECK-NOT: call void @llvm.dbg.declare(metadata ptr [[TMP0]]
 //
 void fS13() {
diff --git a/clang/test/CodeGenCXX/debug-info-structured-binding-field.cpp 
b/clang/test/CodeGenCXX/debug-info-structured-binding-field.cpp
new file mode 100644
index 000..928d22776d21093
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-structured-binding-field.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck 
%s
+
+struct Tuple {
+  int Fld_1;
+  int Fld_2;
+};
+__attribute__((optnone)) Tuple get() { return {10, 20}; }
+
+// CHECK-LABEL: define dso_local noundef i32 @main
+// CHECK:  %retval = alloca i32, align 4
+// CHECK-NEXT: [[T0:%.*]] = alloca %struct.Tuple, align 4
+// CHECK:  call void @llvm.dbg.declare(metadata ptr [[T0]], metadata 
{{.*}}, metadata !DIExpression())
+// CHECK:  call void @llvm.dbg.declare(metadata ptr [[T0]], metadata 
{{.*}}, metadata !DIExpression(DW_OP_plus_uconst, {{[0-9]+}}))
+// CHECK-NOT:  call void @llvm.dbg.declare(metadata ptr [[T0]], metadata 
{{.*}}, metadata !DIExpression())
+//
+int main() {
+  auto [Var_1, Var_2] = get();
+
+  return Var_1 + Var_2;
+}
diff --git a/clang/test/CodeGenCXX/debug-info-structured-binding.cpp 
b/clang/test/CodeGenCXX/debug-info-structured-binding.cpp
index 8d4ae0aaf32636b..163c152efa19d0b 100644
--- a/clang/test/CodeGenCXX/debug-info-structured-binding.cpp
+++ b/clang/test/CodeGenCXX/debug-info-structured-binding.cpp
@@ -2,10 +2,8 @@
 
 // CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata 
!{{[0-9]+}}, metadata !DIExpressio

[clang] [Clang][DebugInfo] Clang generates an extra spurious unnamed 'dbg.declare' (PR #69681)

2023-10-24 Thread Carlos Alberto Enciso via cfe-commits


@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck 
%s
+
+struct Tuple {
+  int Fld_1;
+  int Fld_2;
+};
+__attribute__((optnone)) Tuple get() { return {10, 20}; }
+
+// CHECK-LABEL: define dso_local noundef i32 @main
+// CHECK:  %retval = alloca i32, align 4
+// CHECK-NEXT: [[T0:%.*]] = alloca %struct.Tuple, align 4
+// CHECK:  call void @llvm.dbg.declare(metadata ptr [[T0]], metadata 
{{.*}}, metadata !DIExpression())
+// CHECK:  call void @llvm.dbg.declare(metadata ptr [[T0]], metadata 
{{.*}}, metadata !DIExpression(DW_OP_plus_uconst, {{[0-9]+}}))
+// CHECK-NOT:  call void @llvm.dbg.declare(metadata ptr [[T0]], metadata 
{{.*}}, metadata !DIExpression())

CarlosAlbertoEnciso wrote:

Removed the test case.
Added checks to check the variable names.

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


[clang] [Clang][DebugInfo] Clang generates an extra spurious unnamed 'dbg.declare' (PR #69681)

2023-10-24 Thread Carlos Alberto Enciso via cfe-commits


@@ -2,10 +2,8 @@
 

CarlosAlbertoEnciso wrote:

Added the `--implicit-check-not` option.

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


[clang] [Clang][DebugInfo] Clang generates an extra spurious unnamed 'dbg.declare' (PR #69681)

2023-10-24 Thread Carlos Alberto Enciso via cfe-commits

CarlosAlbertoEnciso wrote:

Uploaded new patch to address comments from @OCHyams 

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


[clang] [CXXNameMangler] Correct the mangling of SVE ACLE types within function names. (PR #69460)

2023-10-24 Thread Paul Walker via cfe-commits

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


[clang] [OpenMP] Introduce support for OMPX extensions and taskgraph frontend (PR #66919)

2023-10-24 Thread Jose Manuel Monsalve Diaz via cfe-commits

josemonsalve2 wrote:

@jdoerfert ping

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


[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-24 Thread Guray Ozen via cfe-commits

https://github.com/grypp commented:

Looks good overall to me. I left a few comments

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


[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-24 Thread Guray Ozen via cfe-commits

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


[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-24 Thread Guray Ozen via cfe-commits


@@ -0,0 +1,222 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32
+
+namespace {
+
+template 
+auto catchAll(F &&func) {
+  try {
+return func();
+  } catch (const std::exception &e) {
+fprintf(stdout, "An exception was thrown: %s\n", e.what());
+fflush(stdout);
+abort();
+  } catch (...) {
+fprintf(stdout, "An unknown exception was thrown\n");
+fflush(stdout);
+abort();
+  }
+}
+
+#define L0_SAFE_CALL(call) 
\
+  {
\
+ze_result_t status = (call);   
\
+if (status != ZE_RESULT_SUCCESS) { 
\
+  fprintf(stdout, "L0 error %d\n", status);
\
+  fflush(stdout);  
\
+  abort(); 
\
+}  
\
+  }
+
+} // namespace
+
+static sycl::device getDefaultDevice() {
+  static sycl::device syclDevice;
+  static bool isDeviceInitialised = false; 
+  if(!isDeviceInitialised) {
+  auto platformList = sycl::platform::get_platforms();
+  for (const auto &platform : platformList) {
+auto platformName = platform.get_info();
+bool isLevelZero = platformName.find("Level-Zero") != std::string::npos;
+if (!isLevelZero)
+  continue;
+
+syclDevice = platform.get_devices()[0];
+isDeviceInitialised = true;
+return syclDevice;
+  }
+throw std::runtime_error("getDefaultDevice failed");

grypp wrote:

In our other runtimes, we don't use 'throw' or 'std::runtime_error.' Instead, 
we use on 'fprintf.' (see 
[CUDA](https://github.com/llvm/llvm-project/blob/main/mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp#L44)
 and 
[ROCm](https://github.com/llvm/llvm-project/blob/main/mlir/lib/ExecutionEngine/RocmRuntimeWrappers.cpp#L30)).

>From what I understand, throwing exceptions are heavy and requires a C++ 
>runtime. Do you really want to use exceptions in this context?

Our approach keeps the error lightweight. In the event of an error, the runtime 
prints the error message, and the program proceeds to run. The compiler can 
implement fallback if needed (we don't do it right now). 

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


[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-24 Thread Guray Ozen via cfe-commits


@@ -0,0 +1,222 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32

grypp wrote:

This macro exist in other runtimes too. Maybe we need a common header for all 
of them. But let's keep this in our mind, we can do it later.

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


[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-24 Thread Guray Ozen via cfe-commits


@@ -0,0 +1,222 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.

grypp wrote:

Wrappers are in C++ but their linkage is C. Can we say something like below:
`Implements wrappers around the sycl runtime library with C linkage`

(I see the same wording in other runtimes too)

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


[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-24 Thread Guray Ozen via cfe-commits


@@ -0,0 +1,222 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32
+
+namespace {
+
+template 
+auto catchAll(F &&func) {
+  try {
+return func();
+  } catch (const std::exception &e) {
+fprintf(stdout, "An exception was thrown: %s\n", e.what());
+fflush(stdout);
+abort();
+  } catch (...) {
+fprintf(stdout, "An unknown exception was thrown\n");
+fflush(stdout);
+abort();
+  }
+}
+
+#define L0_SAFE_CALL(call) 
\
+  {
\
+ze_result_t status = (call);   
\
+if (status != ZE_RESULT_SUCCESS) { 
\
+  fprintf(stdout, "L0 error %d\n", status);
\
+  fflush(stdout);  
\
+  abort(); 
\
+}  
\
+  }
+
+} // namespace
+
+static sycl::device getDefaultDevice() {
+  static sycl::device syclDevice;
+  static bool isDeviceInitialised = false; 
+  if(!isDeviceInitialised) {
+  auto platformList = sycl::platform::get_platforms();
+  for (const auto &platform : platformList) {
+auto platformName = platform.get_info();
+bool isLevelZero = platformName.find("Level-Zero") != std::string::npos;
+if (!isLevelZero)
+  continue;
+
+syclDevice = platform.get_devices()[0];
+isDeviceInitialised = true;
+return syclDevice;
+  }
+throw std::runtime_error("getDefaultDevice failed");

grypp wrote:

In our other runtimes, we don't use 'throw' or 'std::runtime_error.' Instead, 
we use on 'fprintf.' (see 
[CUDA](https://github.com/llvm/llvm-project/blob/main/mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp#L44)
 and 
[ROCm](https://github.com/llvm/llvm-project/blob/main/mlir/lib/ExecutionEngine/RocmRuntimeWrappers.cpp#L30)).

>From what I understand, throwing exceptions are heavy and requires a C++ 
>runtime. Do you really want to use exceptions in this context?

Our approach keeps the error lightweight. In the event of an error, the runtime 
prints the error message, and the program proceeds to run. The compiler can 
implement fallback if needed (we don't do it right now). 

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


[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-24 Thread Guray Ozen via cfe-commits


@@ -0,0 +1,222 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.

grypp wrote:

Wrappers are in C++ but their linkage is C. Can we say something like below:
`Implements wrappers around the sycl runtime library with C linkage`

(I see the same wording in other runtimes too)

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


[clang] [clang]improve diagnosing redefined defaulted constructor with different exception specs (PR #69688)

2023-10-24 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/69688

>From 2629b346123f9838a4fc3d8b6fb6a98508773965 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Fri, 20 Oct 2023 15:45:42 +0800
Subject: [PATCH 1/2] [clang]improve diagnosing redefined defaulted constructor
 with different exception specs

It is misleading when diagnosing 'ExplicitlySpecialMethod' is missing exception 
specification 'noexcept' for
```c++
struct ExplicitlySpecialMethod {
  ExplicitlySpecialMethod() = default;
};
ExplicitlySpecialMethod::ExplicitlySpecialMethod() {}
```
Fixes: #69094
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaDecl.cpp   | 25 ++-
 ...agnoise-prioritiy-exception-redefining.cpp |  9 +++
 3 files changed, 25 insertions(+), 12 deletions(-)
 create mode 100644 
clang/test/SemaCXX/diagnoise-prioritiy-exception-redefining.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc8caf9221b9d29..ae995a12cf0fd7d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -325,6 +325,9 @@ Improvements to Clang's diagnostics
   |   ~^~~~
 - Clang now always diagnoses when using non-standard layout types in 
``offsetof`` .
   (`#64619: `_)
+- Clang now diagnoses redefined defaulted constructor when redefined
+  defaulted constructor with different exception specs.
+  (`#69094: `_)
 
 Bug Fixes in This Version
 -
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b363b0db79f164d..c4979b51e68f5e2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3922,18 +3922,6 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *&OldD, Scope *S,
   }
 
   if (getLangOpts().CPlusPlus) {
-// C++1z [over.load]p2
-//   Certain function declarations cannot be overloaded:
-// -- Function declarations that differ only in the return type,
-//the exception specification, or both cannot be overloaded.
-
-// Check the exception specifications match. This may recompute the type of
-// both Old and New if it resolved exception specifications, so grab the
-// types again after this. Because this updates the type, we do this before
-// any of the other checks below, which may update the "de facto" NewQType
-// but do not necessarily update the type of New.
-if (CheckEquivalentExceptionSpec(Old, New))
-  return true;
 OldQType = Context.getCanonicalType(Old->getType());
 NewQType = Context.getCanonicalType(New->getType());
 
@@ -4055,6 +4043,19 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *&OldD, Scope *S,
   }
 }
 
+// C++1z [over.load]p2
+//   Certain function declarations cannot be overloaded:
+// -- Function declarations that differ only in the return type,
+//the exception specification, or both cannot be overloaded.
+
+// Check the exception specifications match. This may recompute the type of
+// both Old and New if it resolved exception specifications, so grab the
+// types again after this. Because this updates the type, we do this before
+// any of the other checks below, which may update the "de facto" NewQType
+// but do not necessarily update the type of New.
+if (CheckEquivalentExceptionSpec(Old, New))
+  return true;
+
 // C++11 [dcl.attr.noreturn]p1:
 //   The first declaration of a function shall specify the noreturn
 //   attribute if any declaration of that function specifies the noreturn
diff --git a/clang/test/SemaCXX/diagnoise-prioritiy-exception-redefining.cpp 
b/clang/test/SemaCXX/diagnoise-prioritiy-exception-redefining.cpp
new file mode 100644
index 000..ad025bf041ce519
--- /dev/null
+++ b/clang/test/SemaCXX/diagnoise-prioritiy-exception-redefining.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions -std=c++11 %s
+
+struct ExplicitlySpecialMethod {
+  ExplicitlySpecialMethod() = default;
+};
+ExplicitlySpecialMethod::ExplicitlySpecialMethod() {} // 
expected-error{{definition of explicitly defaulted default constructor}}
+
+struct ImplicitlySpecialMethod {};
+ImplicitlySpecialMethod::ImplicitlySpecialMethod() {} // 
expected-error{{definition of implicitly declared default constructor}}

>From a58d6f45d5c4e09e655fd9d4d6111a9605b8a434 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 22 Oct 2023 00:14:02 +0800
Subject: [PATCH 2/2] fix typo

---
 ...redefining.cpp => diagnose-prioritiy-exception-redefining.cpp} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename clang/test/SemaCXX/{diagnoise-prioritiy-exception-redefining.cpp => 
diagnose-prioritiy-exception-redefining.cpp} (100%)

diff --git a/clang/test/SemaCXX/diagnoise-prioritiy-exception-redefining.cpp 
b/clang/test/

[clang] [clang]Transform uninstantiated ExceptionSpec in TemplateInstantiator (PR #68878)

2023-10-24 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/68878

>From b93096929aa98e17dfdb0240a9285d315fc95bfc Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 12 Oct 2023 19:31:08 +0800
Subject: [PATCH 1/3] [clang]Transform uninstantiated ExceptionSpec in
 TemplateInstantiator

Fixes #68543, #42496
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  9 -
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 19 +--
 .../dependent-noexcept-uninstantiated.cpp | 11 +++
 4 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/dependent-noexcept-uninstantiated.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..d3612db7957391d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -377,6 +377,8 @@ Bug Fixes in This Version
   cannot be used with ``Release`` mode builds. (`#68237 
`_).
 - Fix crash in evaluating ``constexpr`` value for invalid template function.
   Fixes (`#68542 `_)
+- Clang will correctly evaluate ``noexcept`` expression with template in 
template
+  method of template record.
 
 - Fixed an issue when a shift count larger than ``__INT64_MAX__``, in a right
   shift operation, could result in missing warnings about
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 62fbd903a04044b..2883e650b1ebd94 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3367,7 +3367,14 @@ Sema::TemplateDeductionResult 
Sema::SubstituteExplicitTemplateArguments(
 SmallVector ExceptionStorage;
 if (getLangOpts().CPlusPlus17 &&
 SubstExceptionSpec(Function->getLocation(), EPI.ExceptionSpec,
-   ExceptionStorage, MLTAL))
+   ExceptionStorage,
+   getTemplateInstantiationArgs(
+   FunctionTemplate, /*Final=*/true,
+   /*Innermost=*/SugaredExplicitArgumentList,
+   /*RelativeToPrimary=*/false,
+   /*Pattern=*/nullptr,
+   /*ForConstraintInstantiation=*/false,
+   /*SkipForSpecialization=*/true)))
   return TDK_SubstitutionFailure;
 
 *FunctionType = BuildFunctionType(ResultType, ParamTypes,
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 23de64080a070ca..f28768931cfabf4 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1325,6 +1325,11 @@ namespace {
 /// declaration.
 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation 
Loc);
 
+bool TransformExceptionSpec(SourceLocation Loc,
+FunctionProtoType::ExceptionSpecInfo &ESI,
+SmallVectorImpl &Exceptions,
+bool &Changed);
+
 /// Rebuild the exception declaration and register the declaration
 /// as an instantiated local.
 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
@@ -1607,6 +1612,18 @@ Decl 
*TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) {
   return Inst;
 }
 
+bool TemplateInstantiator::TransformExceptionSpec(
+SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
+SmallVectorImpl &Exceptions, bool &Changed) {
+  if (ESI.Type == EST_Uninstantiated) {
+ESI.NoexceptExpr = cast(ESI.SourceTemplate->getType())
+   ->getNoexceptExpr();
+ESI.Type = EST_DependentNoexcept;
+Changed = true;
+  }
+  return inherited::TransformExceptionSpec(Loc, ESI, Exceptions, Changed);
+}
+
 NamedDecl *
 TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D,
  SourceLocation Loc) {
@@ -2672,8 +2689,6 @@ bool Sema::SubstExceptionSpec(SourceLocation Loc,
   FunctionProtoType::ExceptionSpecInfo &ESI,
   SmallVectorImpl &ExceptionStorage,
   const MultiLevelTemplateArgumentList &Args) {
-  assert(ESI.Type != EST_Uninstantiated);
-
   bool Changed = false;
   TemplateInstantiator Instantiator(*this, Args, Loc, DeclarationName());
   return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
diff --git a/clang/test/SemaCXX/dependent-noexcept-uninstantiated.cpp 
b/clang/test/SemaCXX/dependent-noexcept-uninstantiated.cpp
new file mode 100644
index 000..ddb269890227539
--- /dev/null
+++ b/clang/test/SemaCXX/dependent-noexcept-uninstantiated.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 %s
+// expected

[clang] [clang]improve diagnosing redefined defaulted constructor with different exception specs (PR #69688)

2023-10-24 Thread Congcong Cai via cfe-commits


@@ -378,7 +381,6 @@ Improvements to Clang's diagnostics
   C++ semantics, e.g. which function template is more specialized. This
   can sometimes lead to worse ordering.
 
-

HerrCai0907 wrote:

```suggestion

```

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


  1   2   3   4   >