[clang] ed1d90c - [clang][NFC] simplify the unset check in `ParseLabeledStatement` (#117430)

2024-11-23 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-11-24T10:59:41+08:00
New Revision: ed1d90ca11b1834e667e17255ba2ecf6fe305e8c

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

LOG: [clang][NFC] simplify the unset check in `ParseLabeledStatement` (#117430)

`!isInvalid && !isUsable -> !isInvalid && !(!isInvalid && !isUnset) ->
isUnset`
It is more simple to understand.

Added: 


Modified: 
clang/lib/Parse/ParseStmt.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index f6d787a0c88319..cd4504630f8719 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -799,7 +799,7 @@ StmtResult Parser::ParseLabeledStatement(ParsedAttributes 
&Attrs,
   }
 
   // If we've not parsed a statement yet, parse one now.
-  if (!SubStmt.isInvalid() && !SubStmt.isUsable())
+  if (SubStmt.isUnset())
 SubStmt = ParseStatement(nullptr, StmtCtx);
 
   // Broken substmt shouldn't prevent the label from being added to the AST.



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


[clang] [clang][NFC] simplify the unset check in `ParseLabeledStatement` (PR #117430)

2024-11-23 Thread Congcong Cai via cfe-commits

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


[clang] 68a48ec - [clang][analysis][NFC]place the comment to correct position (#117467)

2024-11-23 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-11-24T14:45:59+08:00
New Revision: 68a48ec90fb6609b964addcc99a55d16eee884a0

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

LOG: [clang][analysis][NFC]place the comment to correct position (#117467)

Added: 


Modified: 
clang/lib/Analysis/ExprMutationAnalyzer.cpp

Removed: 




diff  --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 5a95ef36d05024..a94b22e051d0e1 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -231,11 +231,11 @@ ExprMutationAnalyzer::Analyzer::findPointeeMutation(const 
Decl *Dec) {
 const Stmt *ExprMutationAnalyzer::Analyzer::findMutationMemoized(
 const Expr *Exp, llvm::ArrayRef Finders,
 Memoized::ResultMap &MemoizedResults) {
+  // Assume Exp is not mutated before analyzing Exp.
   auto [Memoized, Inserted] = MemoizedResults.try_emplace(Exp);
   if (!Inserted)
 return Memoized->second;
 
-  // Assume Exp is not mutated before analyzing Exp.
   if (isUnevaluated(Exp))
 return nullptr;
 



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


[clang] [clang][analysis][NFC]place the comment to correct position (PR #117467)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Congcong Cai (HerrCai0907)


Changes



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


1 Files Affected:

- (modified) clang/lib/Analysis/ExprMutationAnalyzer.cpp (+1-1) 


``diff
diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 5a95ef36d05024..a94b22e051d0e1 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -231,11 +231,11 @@ ExprMutationAnalyzer::Analyzer::findPointeeMutation(const 
Decl *Dec) {
 const Stmt *ExprMutationAnalyzer::Analyzer::findMutationMemoized(
 const Expr *Exp, llvm::ArrayRef Finders,
 Memoized::ResultMap &MemoizedResults) {
+  // Assume Exp is not mutated before analyzing Exp.
   auto [Memoized, Inserted] = MemoizedResults.try_emplace(Exp);
   if (!Inserted)
 return Memoized->second;
 
-  // Assume Exp is not mutated before analyzing Exp.
   if (isUnevaluated(Exp))
 return nullptr;
 

``




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


[clang] [clang][analysis][NFC]place the comment to correct position (PR #117467)

2024-11-23 Thread Congcong Cai via cfe-commits

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


[clang] [llvm] [SanitizerCoverage] Add gated tracing callbacks support to trace-cmp (PR #113227)

2024-11-23 Thread Vitaly Buka via cfe-commits

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


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


[clang] [clang][analysis][NFC]place the comment to correct position (PR #117467)

2024-11-23 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/117467

None

>From adfb09e1b3fa69ce0f9a8350fe74c0781d1f7b78 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 24 Nov 2024 14:45:15 +0800
Subject: [PATCH] [clang][analysis][NFC]place the comment to correct position

---
 clang/lib/Analysis/ExprMutationAnalyzer.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 5a95ef36d05024..a94b22e051d0e1 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -231,11 +231,11 @@ ExprMutationAnalyzer::Analyzer::findPointeeMutation(const 
Decl *Dec) {
 const Stmt *ExprMutationAnalyzer::Analyzer::findMutationMemoized(
 const Expr *Exp, llvm::ArrayRef Finders,
 Memoized::ResultMap &MemoizedResults) {
+  // Assume Exp is not mutated before analyzing Exp.
   auto [Memoized, Inserted] = MemoizedResults.try_emplace(Exp);
   if (!Inserted)
 return Memoized->second;
 
-  // Assume Exp is not mutated before analyzing Exp.
   if (isUnevaluated(Exp))
 return nullptr;
 

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


[clang] [AST] Migrate away from PointerUnion::{is, get} (NFC) (PR #117469)

2024-11-23 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/117469

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.


>From 74d11c6fbf8969ea2134c7db3f24fed403f99a22 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sat, 23 Nov 2024 22:50:26 -0800
Subject: [PATCH] [AST] Migrate away from PointerUnion::{is,get} (NFC)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
---
 clang/lib/AST/ASTConcept.cpp|  6 ++---
 clang/lib/AST/ASTContext.cpp|  6 ++---
 clang/lib/AST/ByteCode/Compiler.cpp |  2 +-
 clang/lib/AST/ByteCode/Program.cpp  |  2 +-
 clang/lib/AST/Decl.cpp  | 34 ++---
 clang/lib/AST/DeclCXX.cpp   |  6 ++---
 clang/lib/AST/DeclFriend.cpp|  3 +--
 clang/lib/AST/DeclTemplate.cpp  |  8 +++
 clang/lib/AST/ExprCXX.cpp   | 10 -
 clang/lib/AST/ExprConcepts.cpp  |  3 +--
 clang/lib/AST/ParentMapContext.cpp  | 22 +--
 clang/lib/AST/TemplateName.cpp  |  8 +++
 12 files changed, 54 insertions(+), 56 deletions(-)

diff --git a/clang/lib/AST/ASTConcept.cpp b/clang/lib/AST/ASTConcept.cpp
index bdc713ca3e791e..f7ee0fb3ee92da 100644
--- a/clang/lib/AST/ASTConcept.cpp
+++ b/clang/lib/AST/ASTConcept.cpp
@@ -22,11 +22,11 @@ static void
 CreateUnsatisfiedConstraintRecord(const ASTContext &C,
   const UnsatisfiedConstraintRecord &Detail,
   UnsatisfiedConstraintRecord *TrailingObject) 
{
-  if (Detail.is())
-new (TrailingObject) UnsatisfiedConstraintRecord(Detail.get());
+  if (auto *E = dyn_cast(Detail))
+new (TrailingObject) UnsatisfiedConstraintRecord(E);
   else {
 auto &SubstitutionDiagnostic =
-*Detail.get *>();
+*cast *>(Detail);
 StringRef Message = C.backupStr(SubstitutionDiagnostic.second);
 auto *NewSubstDiag = new (C) std::pair(
 SubstitutionDiagnostic.first, Message);
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 23df7878a3bf29..3e6f0d628ca926 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -374,10 +374,10 @@ static const Decl &adjustDeclToTemplate(const Decl &D) {
   llvm::PointerUnion
   PU = CTSD->getSpecializedTemplateOrPartial();
-  return PU.is()
- ? *static_cast(PU.get())
+  return isa(PU)
+ ? *static_cast(cast(PU))
  : *static_cast(
-   PU.get());
+   cast(PU));
 }
 
 // Class is instantiated from a member definition of a class template?
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 7cf2519d6a71fb..3d8215ffc8c228 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4033,7 +4033,7 @@ unsigned Compiler::allocateLocalPrimitive(DeclTy 
&&Src, PrimType Ty,
   //   (int){12} in C. Consider using Expr::isTemporaryObject() instead
   //   or isa().
   Descriptor *D = P.createDescriptor(Src, Ty, Descriptor::InlineDescMD, 
IsConst,
- Src.is());
+ isa(Src));
   Scope::Local Local = this->createLocal(D);
   if (auto *VD = dyn_cast_if_present(Src.dyn_cast()))
 Locals.insert({VD, Local});
diff --git a/clang/lib/AST/ByteCode/Program.cpp 
b/clang/lib/AST/ByteCode/Program.cpp
index 590ee19de6d2f0..c98a3506b0a90b 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -158,7 +158,7 @@ unsigned Program::getOrCreateDummy(const DeclTy &D) {
   if (const auto *E = D.dyn_cast()) {
 QT = E->getType();
   } else {
-const ValueDecl *VD = cast(D.get());
+const ValueDecl *VD = cast(cast(D));
 IsWeak = VD->isWeak();
 QT = VD->getType();
 if (const auto *RT = QT->getAs())
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index bfeb4827f79587..741e908cf9bc56 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1991,7 +1991,7 @@ void 
DeclaratorDecl::setQualifierInfo(NestedNameSpecifierLoc QualifierLoc) {
 // Make sure the extended decl info is allocated.
 if (!hasExtInfo()) {
   // Save (non-extended) type source info pointer.
-  auto *savedTInfo = DeclInfo.

[clang] [AST] Migrate away from PointerUnion::{is, get} (NFC) (PR #117469)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.


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


12 Files Affected:

- (modified) clang/lib/AST/ASTConcept.cpp (+3-3) 
- (modified) clang/lib/AST/ASTContext.cpp (+3-3) 
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+1-1) 
- (modified) clang/lib/AST/ByteCode/Program.cpp (+1-1) 
- (modified) clang/lib/AST/Decl.cpp (+17-17) 
- (modified) clang/lib/AST/DeclCXX.cpp (+3-3) 
- (modified) clang/lib/AST/DeclFriend.cpp (+1-2) 
- (modified) clang/lib/AST/DeclTemplate.cpp (+4-4) 
- (modified) clang/lib/AST/ExprCXX.cpp (+5-5) 
- (modified) clang/lib/AST/ExprConcepts.cpp (+1-2) 
- (modified) clang/lib/AST/ParentMapContext.cpp (+11-11) 
- (modified) clang/lib/AST/TemplateName.cpp (+4-4) 


``diff
diff --git a/clang/lib/AST/ASTConcept.cpp b/clang/lib/AST/ASTConcept.cpp
index bdc713ca3e791e..f7ee0fb3ee92da 100644
--- a/clang/lib/AST/ASTConcept.cpp
+++ b/clang/lib/AST/ASTConcept.cpp
@@ -22,11 +22,11 @@ static void
 CreateUnsatisfiedConstraintRecord(const ASTContext &C,
   const UnsatisfiedConstraintRecord &Detail,
   UnsatisfiedConstraintRecord *TrailingObject) 
{
-  if (Detail.is())
-new (TrailingObject) UnsatisfiedConstraintRecord(Detail.get());
+  if (auto *E = dyn_cast(Detail))
+new (TrailingObject) UnsatisfiedConstraintRecord(E);
   else {
 auto &SubstitutionDiagnostic =
-*Detail.get *>();
+*cast *>(Detail);
 StringRef Message = C.backupStr(SubstitutionDiagnostic.second);
 auto *NewSubstDiag = new (C) std::pair(
 SubstitutionDiagnostic.first, Message);
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 23df7878a3bf29..3e6f0d628ca926 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -374,10 +374,10 @@ static const Decl &adjustDeclToTemplate(const Decl &D) {
   llvm::PointerUnion
   PU = CTSD->getSpecializedTemplateOrPartial();
-  return PU.is()
- ? *static_cast(PU.get())
+  return isa(PU)
+ ? *static_cast(cast(PU))
  : *static_cast(
-   PU.get());
+   cast(PU));
 }
 
 // Class is instantiated from a member definition of a class template?
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 7cf2519d6a71fb..3d8215ffc8c228 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4033,7 +4033,7 @@ unsigned Compiler::allocateLocalPrimitive(DeclTy 
&&Src, PrimType Ty,
   //   (int){12} in C. Consider using Expr::isTemporaryObject() instead
   //   or isa().
   Descriptor *D = P.createDescriptor(Src, Ty, Descriptor::InlineDescMD, 
IsConst,
- Src.is());
+ isa(Src));
   Scope::Local Local = this->createLocal(D);
   if (auto *VD = dyn_cast_if_present(Src.dyn_cast()))
 Locals.insert({VD, Local});
diff --git a/clang/lib/AST/ByteCode/Program.cpp 
b/clang/lib/AST/ByteCode/Program.cpp
index 590ee19de6d2f0..c98a3506b0a90b 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -158,7 +158,7 @@ unsigned Program::getOrCreateDummy(const DeclTy &D) {
   if (const auto *E = D.dyn_cast()) {
 QT = E->getType();
   } else {
-const ValueDecl *VD = cast(D.get());
+const ValueDecl *VD = cast(cast(D));
 IsWeak = VD->isWeak();
 QT = VD->getType();
 if (const auto *RT = QT->getAs())
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index bfeb4827f79587..741e908cf9bc56 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1991,7 +1991,7 @@ void 
DeclaratorDecl::setQualifierInfo(NestedNameSpecifierLoc QualifierLoc) {
 // Make sure the extended decl info is allocated.
 if (!hasExtInfo()) {
   // Save (non-extended) type source info pointer.
-  auto *savedTInfo = DeclInfo.get();
+  auto *savedTInfo = cast(DeclInfo);
   // Allocate external info struct.
   DeclInfo = new (getASTContext()) ExtInfo;
   // Restore savedTInfo into (extended) decl info.
@@ -2010,7 +2010,7 @@ void DeclaratorDecl::setTrailingRequiresClause(Expr 
*TrailingRequiresClause) {
   // Make sure the extended decl info is allocated.
   if (!hasExtInfo()) {
 // Save (non-extended) type source info pointer.
-auto *savedTInfo = DeclInfo.get();
+auto *savedTInfo = cast(DeclInfo);
 // Allocate external

[clang] 14b9ca3 - [Sema] Fix a warning

2024-11-23 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-11-23T10:29:11-08:00
New Revision: 14b9ca3f38494bbd03709188b6e73c06ab84cd15

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

LOG: [Sema] Fix a warning

This patch fixes:

  clang/lib/Sema/SemaHLSL.cpp:2225:32: error: absolute value function
  'abs' given an argument of type 'int64_t' (aka 'long') but has
  parameter of type 'int' which may cause truncation of value
  [-Werror,-Wabsolute-value]

Added: 


Modified: 
clang/lib/Sema/SemaHLSL.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 289d9dc0f11306..8bdacd6ded1654 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -,7 +,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 Expr *OffsetExpr = TheCall->getArg(1);
 std::optional Offset =
 OffsetExpr->getIntegerConstantExpr(SemaRef.getASTContext());
-if (!Offset.has_value() || abs(Offset->getExtValue()) != 1) {
+if (!Offset.has_value() || std::abs(Offset->getExtValue()) != 1) {
   SemaRef.Diag(TheCall->getArg(1)->getBeginLoc(),
diag::err_hlsl_expect_arg_const_int_one_or_neg_one)
   << 1;



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


[clang] [llvm] Revert "[HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers (#114148)" (PR #117448)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-directx

Author: Helena Kotas (hekota)


Changes

This reverts commit 94bde8cdc39ff7e9c59ee0cd5edda882955242aa.

---

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


14 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+1-6) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-6) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (-9) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (-1) 
- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+93-321) 
- (modified) clang/lib/Sema/SemaExpr.cpp (-3) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (-54) 
- (modified) clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl (-26) 
- (removed) clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-lib.hlsl 
(-25) 
- (removed) clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-ps.hlsl 
(-28) 
- (removed) clang/test/SemaHLSL/BuiltIns/buffer_update_counter-errors.hlsl 
(-48) 
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+1-1) 
- (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (-5) 
- (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index eaff744924805e..83c90b3d6e681b 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4882,6 +4882,7 @@ def HLSLSaturate : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+
 def HLSLSelect : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_select"];
   let Attributes = [NoThrow, Const];
@@ -4906,12 +4907,6 @@ def HLSLRadians : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
-def HLSLBufferUpdateCounter : LangBuiltin<"HLSL_LANG"> {
-  let Spellings = ["__builtin_hlsl_buffer_update_counter"];
-  let Attributes = [NoThrow];
-  let Prototype = "uint32_t(...)";
-}
-
 def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_splitdouble"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f21b125252b063..eb05a6a77978af 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7287,8 +7287,6 @@ def err_typecheck_illegal_increment_decrement : Error<
   "cannot %select{decrement|increment}1 value of type %0">;
 def err_typecheck_expect_int : Error<
   "used type %0 where integer is required">;
-def err_typecheck_expect_hlsl_resource : Error<
-  "used type %0 where __hlsl_resource_t is required">;
 def err_typecheck_arithmetic_incomplete_or_sizeless_type : Error<
   "arithmetic on a pointer to %select{an incomplete|sizeless}0 type %1">;
 def err_typecheck_pointer_arith_function_type : Error<
@@ -12530,10 +12528,6 @@ def warn_attr_min_eq_max:  Warning<
 
 def err_hlsl_attribute_number_arguments_insufficient_shader_model: Error<
   "attribute %0 with %1 arguments requires shader model %2 or greater">;
-def err_hlsl_expect_arg_const_int_one_or_neg_one: Error<
-  "argument %0 must be constant integer 1 or -1">;
-def err_invalid_hlsl_resource_type: Error<
-  "invalid __hlsl_resource_t type attributes">;
 
 // Layout randomization diagnostics.
 def err_non_designated_init_used : Error<
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index cde03a92b02853..8f754953d28998 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19409,15 +19409,6 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef{Op0},
 nullptr, "hlsl.radians");
   }
-  case Builtin::BI__builtin_hlsl_buffer_update_counter: {
-Value *ResHandle = EmitScalarExpr(E->getArg(0));
-Value *Offset = EmitScalarExpr(E->getArg(1));
-Value *OffsetI8 = Builder.CreateIntCast(Offset, Int8Ty, true);
-return Builder.CreateIntrinsic(
-/*ReturnType=*/Offset->getType(),
-CGM.getHLSLRuntime().getBufferUpdateCounterIntrinsic(),
-ArrayRef{ResHandle, OffsetI8}, nullptr);
-  }
   case Builtin::BI__builtin_hlsl_elementwise_splitdouble: {
 
 assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 854214d6bc0677..a8e0ed42b79a35 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -102,7 +102,6 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(UClamp, uclamp)
 
   GENERATE_HLSL_INTRINSIC_FUNCTION(CreateHandleFromBinding, handle_fromBinding)
-  GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, bufferUpdateCounter)
 
   
//===--===//
   // End of reserved area for HLSL intrinsic getters.
diff --git a/clang/li

[clang] [Clang] Fix -Wunused-private-field false negative with defaulted comparison operators (PR #116871)

2024-11-23 Thread Mészáros Gergely via cfe-commits

Maetveis wrote:

Thanks! I added @AaronBallman, as a reviewer just to make sure I didn't miss 
anything, as I don't consider myself an expert when it comes to frontend. 
@AaronBallman I think you can merge if everything looks okay, I'm pretty sure 
@whiteio does not have commit rights.

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


[clang] [llvm] Revert "[HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers (#114148)" (PR #117448)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Helena Kotas (hekota)


Changes

This reverts commit 94bde8cdc39ff7e9c59ee0cd5edda882955242aa.

---

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


14 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+1-6) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-6) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (-9) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (-1) 
- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+93-321) 
- (modified) clang/lib/Sema/SemaExpr.cpp (-3) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (-54) 
- (modified) clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl (-26) 
- (removed) clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-lib.hlsl 
(-25) 
- (removed) clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-ps.hlsl 
(-28) 
- (removed) clang/test/SemaHLSL/BuiltIns/buffer_update_counter-errors.hlsl 
(-48) 
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+1-1) 
- (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (-5) 
- (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index eaff744924805e..83c90b3d6e681b 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4882,6 +4882,7 @@ def HLSLSaturate : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+
 def HLSLSelect : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_select"];
   let Attributes = [NoThrow, Const];
@@ -4906,12 +4907,6 @@ def HLSLRadians : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
-def HLSLBufferUpdateCounter : LangBuiltin<"HLSL_LANG"> {
-  let Spellings = ["__builtin_hlsl_buffer_update_counter"];
-  let Attributes = [NoThrow];
-  let Prototype = "uint32_t(...)";
-}
-
 def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_splitdouble"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f21b125252b063..eb05a6a77978af 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7287,8 +7287,6 @@ def err_typecheck_illegal_increment_decrement : Error<
   "cannot %select{decrement|increment}1 value of type %0">;
 def err_typecheck_expect_int : Error<
   "used type %0 where integer is required">;
-def err_typecheck_expect_hlsl_resource : Error<
-  "used type %0 where __hlsl_resource_t is required">;
 def err_typecheck_arithmetic_incomplete_or_sizeless_type : Error<
   "arithmetic on a pointer to %select{an incomplete|sizeless}0 type %1">;
 def err_typecheck_pointer_arith_function_type : Error<
@@ -12530,10 +12528,6 @@ def warn_attr_min_eq_max:  Warning<
 
 def err_hlsl_attribute_number_arguments_insufficient_shader_model: Error<
   "attribute %0 with %1 arguments requires shader model %2 or greater">;
-def err_hlsl_expect_arg_const_int_one_or_neg_one: Error<
-  "argument %0 must be constant integer 1 or -1">;
-def err_invalid_hlsl_resource_type: Error<
-  "invalid __hlsl_resource_t type attributes">;
 
 // Layout randomization diagnostics.
 def err_non_designated_init_used : Error<
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index cde03a92b02853..8f754953d28998 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19409,15 +19409,6 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef{Op0},
 nullptr, "hlsl.radians");
   }
-  case Builtin::BI__builtin_hlsl_buffer_update_counter: {
-Value *ResHandle = EmitScalarExpr(E->getArg(0));
-Value *Offset = EmitScalarExpr(E->getArg(1));
-Value *OffsetI8 = Builder.CreateIntCast(Offset, Int8Ty, true);
-return Builder.CreateIntrinsic(
-/*ReturnType=*/Offset->getType(),
-CGM.getHLSLRuntime().getBufferUpdateCounterIntrinsic(),
-ArrayRef{ResHandle, OffsetI8}, nullptr);
-  }
   case Builtin::BI__builtin_hlsl_elementwise_splitdouble: {
 
 assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 854214d6bc0677..a8e0ed42b79a35 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -102,7 +102,6 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(UClamp, uclamp)
 
   GENERATE_HLSL_INTRINSIC_FUNCTION(CreateHandleFromBinding, handle_fromBinding)
-  GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, bufferUpdateCounter)
 
   
//===--===//
   // End of reserved area for HLSL intrinsic getters.
diff --git a/clang/lib/Sema/H

[clang] [llvm] Revert "[HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers (#114148)" (PR #117448)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Helena Kotas (hekota)


Changes

This reverts commit 94bde8cdc39ff7e9c59ee0cd5edda882955242aa.

---

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


14 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+1-6) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-6) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (-9) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (-1) 
- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+93-321) 
- (modified) clang/lib/Sema/SemaExpr.cpp (-3) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (-54) 
- (modified) clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl (-26) 
- (removed) clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-lib.hlsl 
(-25) 
- (removed) clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-ps.hlsl 
(-28) 
- (removed) clang/test/SemaHLSL/BuiltIns/buffer_update_counter-errors.hlsl 
(-48) 
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+1-1) 
- (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (-5) 
- (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index eaff744924805e..83c90b3d6e681b 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4882,6 +4882,7 @@ def HLSLSaturate : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+
 def HLSLSelect : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_select"];
   let Attributes = [NoThrow, Const];
@@ -4906,12 +4907,6 @@ def HLSLRadians : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
-def HLSLBufferUpdateCounter : LangBuiltin<"HLSL_LANG"> {
-  let Spellings = ["__builtin_hlsl_buffer_update_counter"];
-  let Attributes = [NoThrow];
-  let Prototype = "uint32_t(...)";
-}
-
 def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_splitdouble"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f21b125252b063..eb05a6a77978af 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7287,8 +7287,6 @@ def err_typecheck_illegal_increment_decrement : Error<
   "cannot %select{decrement|increment}1 value of type %0">;
 def err_typecheck_expect_int : Error<
   "used type %0 where integer is required">;
-def err_typecheck_expect_hlsl_resource : Error<
-  "used type %0 where __hlsl_resource_t is required">;
 def err_typecheck_arithmetic_incomplete_or_sizeless_type : Error<
   "arithmetic on a pointer to %select{an incomplete|sizeless}0 type %1">;
 def err_typecheck_pointer_arith_function_type : Error<
@@ -12530,10 +12528,6 @@ def warn_attr_min_eq_max:  Warning<
 
 def err_hlsl_attribute_number_arguments_insufficient_shader_model: Error<
   "attribute %0 with %1 arguments requires shader model %2 or greater">;
-def err_hlsl_expect_arg_const_int_one_or_neg_one: Error<
-  "argument %0 must be constant integer 1 or -1">;
-def err_invalid_hlsl_resource_type: Error<
-  "invalid __hlsl_resource_t type attributes">;
 
 // Layout randomization diagnostics.
 def err_non_designated_init_used : Error<
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index cde03a92b02853..8f754953d28998 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19409,15 +19409,6 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef{Op0},
 nullptr, "hlsl.radians");
   }
-  case Builtin::BI__builtin_hlsl_buffer_update_counter: {
-Value *ResHandle = EmitScalarExpr(E->getArg(0));
-Value *Offset = EmitScalarExpr(E->getArg(1));
-Value *OffsetI8 = Builder.CreateIntCast(Offset, Int8Ty, true);
-return Builder.CreateIntrinsic(
-/*ReturnType=*/Offset->getType(),
-CGM.getHLSLRuntime().getBufferUpdateCounterIntrinsic(),
-ArrayRef{ResHandle, OffsetI8}, nullptr);
-  }
   case Builtin::BI__builtin_hlsl_elementwise_splitdouble: {
 
 assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 854214d6bc0677..a8e0ed42b79a35 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -102,7 +102,6 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(UClamp, uclamp)
 
   GENERATE_HLSL_INTRINSIC_FUNCTION(CreateHandleFromBinding, handle_fromBinding)
-  GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, bufferUpdateCounter)
 
   
//===--===//
   // End of reserved area for HLSL intrinsic getters.
diff --git a/clang/lib/

[clang] [llvm] Revert "[HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers (#114148)" (PR #117448)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Helena Kotas (hekota)


Changes

This reverts commit 94bde8cdc39ff7e9c59ee0cd5edda882955242aa.

---

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


14 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+1-6) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-6) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (-9) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (-1) 
- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+93-321) 
- (modified) clang/lib/Sema/SemaExpr.cpp (-3) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (-54) 
- (modified) clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl (-26) 
- (removed) clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-lib.hlsl 
(-25) 
- (removed) clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-ps.hlsl 
(-28) 
- (removed) clang/test/SemaHLSL/BuiltIns/buffer_update_counter-errors.hlsl 
(-48) 
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+1-1) 
- (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (-5) 
- (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index eaff744924805e..83c90b3d6e681b 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4882,6 +4882,7 @@ def HLSLSaturate : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+
 def HLSLSelect : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_select"];
   let Attributes = [NoThrow, Const];
@@ -4906,12 +4907,6 @@ def HLSLRadians : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
-def HLSLBufferUpdateCounter : LangBuiltin<"HLSL_LANG"> {
-  let Spellings = ["__builtin_hlsl_buffer_update_counter"];
-  let Attributes = [NoThrow];
-  let Prototype = "uint32_t(...)";
-}
-
 def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_splitdouble"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f21b125252b063..eb05a6a77978af 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7287,8 +7287,6 @@ def err_typecheck_illegal_increment_decrement : Error<
   "cannot %select{decrement|increment}1 value of type %0">;
 def err_typecheck_expect_int : Error<
   "used type %0 where integer is required">;
-def err_typecheck_expect_hlsl_resource : Error<
-  "used type %0 where __hlsl_resource_t is required">;
 def err_typecheck_arithmetic_incomplete_or_sizeless_type : Error<
   "arithmetic on a pointer to %select{an incomplete|sizeless}0 type %1">;
 def err_typecheck_pointer_arith_function_type : Error<
@@ -12530,10 +12528,6 @@ def warn_attr_min_eq_max:  Warning<
 
 def err_hlsl_attribute_number_arguments_insufficient_shader_model: Error<
   "attribute %0 with %1 arguments requires shader model %2 or greater">;
-def err_hlsl_expect_arg_const_int_one_or_neg_one: Error<
-  "argument %0 must be constant integer 1 or -1">;
-def err_invalid_hlsl_resource_type: Error<
-  "invalid __hlsl_resource_t type attributes">;
 
 // Layout randomization diagnostics.
 def err_non_designated_init_used : Error<
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index cde03a92b02853..8f754953d28998 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19409,15 +19409,6 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef{Op0},
 nullptr, "hlsl.radians");
   }
-  case Builtin::BI__builtin_hlsl_buffer_update_counter: {
-Value *ResHandle = EmitScalarExpr(E->getArg(0));
-Value *Offset = EmitScalarExpr(E->getArg(1));
-Value *OffsetI8 = Builder.CreateIntCast(Offset, Int8Ty, true);
-return Builder.CreateIntrinsic(
-/*ReturnType=*/Offset->getType(),
-CGM.getHLSLRuntime().getBufferUpdateCounterIntrinsic(),
-ArrayRef{ResHandle, OffsetI8}, nullptr);
-  }
   case Builtin::BI__builtin_hlsl_elementwise_splitdouble: {
 
 assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 854214d6bc0677..a8e0ed42b79a35 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -102,7 +102,6 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(UClamp, uclamp)
 
   GENERATE_HLSL_INTRINSIC_FUNCTION(CreateHandleFromBinding, handle_fromBinding)
-  GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, bufferUpdateCounter)
 
   
//===--===//
   // End of reserved area for HLSL intrinsic getters.
diff --git a/clang/lib/Sema/HLS

[clang] [llvm] Revert "[HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers (#114148)" (PR #117448)

2024-11-23 Thread Helena Kotas via cfe-commits

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/117448

This reverts commit 94bde8cdc39ff7e9c59ee0cd5edda882955242aa.

>From 4edec79a02e7d32fe16e257f6151669a2f009d85 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Sat, 23 Nov 2024 11:43:29 -0800
Subject: [PATCH] Revert "[HLSL] Add `Increment`/`DecrementCounter` methods to
 structured buffers (#114148)"

This reverts commit 94bde8cdc39ff7e9c59ee0cd5edda882955242aa.
---
 clang/include/clang/Basic/Builtins.td |   7 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   6 -
 clang/lib/CodeGen/CGBuiltin.cpp   |   9 -
 clang/lib/CodeGen/CGHLSLRuntime.h |   1 -
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 414 --
 clang/lib/Sema/SemaExpr.cpp   |   3 -
 clang/lib/Sema/SemaHLSL.cpp   |  54 ---
 .../test/AST/HLSL/RWStructuredBuffer-AST.hlsl |  26 --
 .../StructuredBuffers-methods-lib.hlsl|  25 --
 .../StructuredBuffers-methods-ps.hlsl |  28 --
 .../buffer_update_counter-errors.hlsl |  48 --
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   2 +-
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |   5 -
 llvm/lib/Target/DirectX/DXILOpLowering.cpp|   2 +-
 14 files changed, 96 insertions(+), 534 deletions(-)
 delete mode 100644 
clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-lib.hlsl
 delete mode 100644 
clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-ps.hlsl
 delete mode 100644 
clang/test/SemaHLSL/BuiltIns/buffer_update_counter-errors.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index eaff744924805e..83c90b3d6e681b 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4882,6 +4882,7 @@ def HLSLSaturate : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+
 def HLSLSelect : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_select"];
   let Attributes = [NoThrow, Const];
@@ -4906,12 +4907,6 @@ def HLSLRadians : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
-def HLSLBufferUpdateCounter : LangBuiltin<"HLSL_LANG"> {
-  let Spellings = ["__builtin_hlsl_buffer_update_counter"];
-  let Attributes = [NoThrow];
-  let Prototype = "uint32_t(...)";
-}
-
 def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_splitdouble"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f21b125252b063..eb05a6a77978af 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7287,8 +7287,6 @@ def err_typecheck_illegal_increment_decrement : Error<
   "cannot %select{decrement|increment}1 value of type %0">;
 def err_typecheck_expect_int : Error<
   "used type %0 where integer is required">;
-def err_typecheck_expect_hlsl_resource : Error<
-  "used type %0 where __hlsl_resource_t is required">;
 def err_typecheck_arithmetic_incomplete_or_sizeless_type : Error<
   "arithmetic on a pointer to %select{an incomplete|sizeless}0 type %1">;
 def err_typecheck_pointer_arith_function_type : Error<
@@ -12530,10 +12528,6 @@ def warn_attr_min_eq_max:  Warning<
 
 def err_hlsl_attribute_number_arguments_insufficient_shader_model: Error<
   "attribute %0 with %1 arguments requires shader model %2 or greater">;
-def err_hlsl_expect_arg_const_int_one_or_neg_one: Error<
-  "argument %0 must be constant integer 1 or -1">;
-def err_invalid_hlsl_resource_type: Error<
-  "invalid __hlsl_resource_t type attributes">;
 
 // Layout randomization diagnostics.
 def err_non_designated_init_used : Error<
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index cde03a92b02853..8f754953d28998 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19409,15 +19409,6 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef{Op0},
 nullptr, "hlsl.radians");
   }
-  case Builtin::BI__builtin_hlsl_buffer_update_counter: {
-Value *ResHandle = EmitScalarExpr(E->getArg(0));
-Value *Offset = EmitScalarExpr(E->getArg(1));
-Value *OffsetI8 = Builder.CreateIntCast(Offset, Int8Ty, true);
-return Builder.CreateIntrinsic(
-/*ReturnType=*/Offset->getType(),
-CGM.getHLSLRuntime().getBufferUpdateCounterIntrinsic(),
-ArrayRef{ResHandle, OffsetI8}, nullptr);
-  }
   case Builtin::BI__builtin_hlsl_elementwise_splitdouble: {
 
 assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 854214d6bc0677..a8e0ed42b79a35 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -102,7 +102,6 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(UC

[clang] dc4c8de - Revert "[HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers (#114148)" (#117448)

2024-11-23 Thread via cfe-commits

Author: Helena Kotas
Date: 2024-11-23T12:02:07-08:00
New Revision: dc4c8de179ff2237378bd42a2b650fad2f7b1940

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

LOG: Revert "[HLSL] Add `Increment`/`DecrementCounter` methods to structured 
buffers (#114148)" (#117448)

This reverts commit 94bde8cdc39ff7e9c59ee0cd5edda882955242aa.

Added: 


Modified: 
clang/include/clang/Basic/Builtins.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGHLSLRuntime.h
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaHLSL.cpp
clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl
llvm/include/llvm/IR/IntrinsicsDirectX.td
llvm/include/llvm/IR/IntrinsicsSPIRV.td
llvm/lib/Target/DirectX/DXILOpLowering.cpp

Removed: 
clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-lib.hlsl
clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-ps.hlsl
clang/test/SemaHLSL/BuiltIns/buffer_update_counter-errors.hlsl



diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index eaff744924805e..83c90b3d6e681b 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4882,6 +4882,7 @@ def HLSLSaturate : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+
 def HLSLSelect : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_select"];
   let Attributes = [NoThrow, Const];
@@ -4906,12 +4907,6 @@ def HLSLRadians : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
-def HLSLBufferUpdateCounter : LangBuiltin<"HLSL_LANG"> {
-  let Spellings = ["__builtin_hlsl_buffer_update_counter"];
-  let Attributes = [NoThrow];
-  let Prototype = "uint32_t(...)";
-}
-
 def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_splitdouble"];
   let Attributes = [NoThrow, Const];

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f21b125252b063..eb05a6a77978af 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7287,8 +7287,6 @@ def err_typecheck_illegal_increment_decrement : Error<
   "cannot %select{decrement|increment}1 value of type %0">;
 def err_typecheck_expect_int : Error<
   "used type %0 where integer is required">;
-def err_typecheck_expect_hlsl_resource : Error<
-  "used type %0 where __hlsl_resource_t is required">;
 def err_typecheck_arithmetic_incomplete_or_sizeless_type : Error<
   "arithmetic on a pointer to %select{an incomplete|sizeless}0 type %1">;
 def err_typecheck_pointer_arith_function_type : Error<
@@ -12530,10 +12528,6 @@ def warn_attr_min_eq_max:  Warning<
 
 def err_hlsl_attribute_number_arguments_insufficient_shader_model: Error<
   "attribute %0 with %1 arguments requires shader model %2 or greater">;
-def err_hlsl_expect_arg_const_int_one_or_neg_one: Error<
-  "argument %0 must be constant integer 1 or -1">;
-def err_invalid_hlsl_resource_type: Error<
-  "invalid __hlsl_resource_t type attributes">;
 
 // Layout randomization diagnostics.
 def err_non_designated_init_used : Error<

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index cde03a92b02853..8f754953d28998 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19409,15 +19409,6 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef{Op0},
 nullptr, "hlsl.radians");
   }
-  case Builtin::BI__builtin_hlsl_buffer_update_counter: {
-Value *ResHandle = EmitScalarExpr(E->getArg(0));
-Value *Offset = EmitScalarExpr(E->getArg(1));
-Value *OffsetI8 = Builder.CreateIntCast(Offset, Int8Ty, true);
-return Builder.CreateIntrinsic(
-/*ReturnType=*/Offset->getType(),
-CGM.getHLSLRuntime().getBufferUpdateCounterIntrinsic(),
-ArrayRef{ResHandle, OffsetI8}, nullptr);
-  }
   case Builtin::BI__builtin_hlsl_elementwise_splitdouble: {
 
 assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 854214d6bc0677..a8e0ed42b79a35 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -102,7 +102,6 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(UClamp, uclamp)
 
   GENERATE_HLSL_INTRINSIC_FUNCTION(CreateHandleFromBinding, handle_fromBinding)
-  GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, bufferUpdateCounter)
 
   
//===--===//
   // End of reserved area for 

[clang] [llvm] Revert "[HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers (#114148)" (PR #117448)

2024-11-23 Thread Helena Kotas via cfe-commits

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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-11-23 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From 2b526821d4e70f3ea83f95d25f804d9fbcf82612 Mon Sep 17 00:00:00 2001
From: cqwrteur <100043421+trcrsi...@users.noreply.github.com>
Date: Sat, 1 Jun 2024 02:55:50 -0400
Subject: [PATCH] [libunwind][libcxx][libcxxabi] Fix Exception Handling build
 for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change

Merge remote-tracking branch 'parent/main' into wasmlibunwindfix

remove unwanted changes in unwind-wasm.c

Make Unwind-wasm.c compile correctly without workaround in
CMakeLists.txt

using __wasm__ macro to guard against all wasm eh build

fix UnwindLevel.c's formatting issue

ISO C requires a translation unit to contain at least one declaration 
[-Werror,-Wempty-translation-unit]

compiler-rt does not define CMP_RESULT correct on wasm64
Fixed

Merge code
---
 compiler-rt/lib/builtins/fp_compare_impl.inc |   2 +-
 libcxx/include/__exception/exception_ptr.h   |  21 +-
 libcxxabi/include/cxxabi.h   | 134 ++--
 libcxxabi/src/cxa_exception.cpp  | 710 ---
 libcxxabi/src/cxa_exception.h|   7 +-
 libunwind/include/libunwind.h|   2 +
 libunwind/src/Unwind-wasm.c  |  13 +-
 libunwind/src/UnwindRegistersRestore.S   |   3 +-
 libunwind/src/UnwindRegistersSave.S  |   3 +
 libunwind/src/assembly.h |   2 +
 libunwind/src/cet_unwind.h   |   3 +
 libunwind/src/config.h   |  15 +-
 libunwind/src/libunwind.cpp  |   2 +
 libunwind/src/libunwind_ext.h|   2 +
 14 files changed, 403 insertions(+), 516 deletions(-)

diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe4..83bdea46a45da4 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -12,7 +12,7 @@
 // functions. We need to ensure that the return value is sign-extended in the
 // same way as GCC expects (since otherwise GCC-generated __builtin_isinf
 // returns true for finite 128-bit floating-point numbers).
-#ifdef __aarch64__
+#if defined(__aarch64__) || defined(__wasm__)
 // AArch64 GCC overrides libgcc_cmp_return to use int instead of long.
 typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 9e5351f534a1c1..84a78d378cc19f 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -29,22 +29,21 @@
 
 namespace __cxxabiv1 {
 
+#if defined(__wasm__)
+typedef void* (*__libcpp_exception_destructor_func)(void*);
+#elif defined(_WIN32)
+typedef void(__thiscall* __libcpp_exception_destructor_func)(void*);
+#else
+typedef void (*__libcpp_exception_destructor_func)(void*);
+#endif
+
 extern "C" {
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
 _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
 
 struct __cxa_exception;
-_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
-void*,
-std::type_info*,
-#if defined(_WIN32)
-void(__thiscall*)(void*)) throw();
-#elif defined(__wasm__)
-// In Wasm, a destructor returns its argument
-void* (*)(void*)) throw();
-#else
-void (*)(void*)) throw();
-#endif
+_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception*
+__cxa_init_primary_exception(void*, std::type_info*, 
__libcpp_exception_destructor_func) throw();
 }
 
 } // namespace __cxxabiv1
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index 9ea93680f62e06..cf0cc40ff42b9e 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -20,49 +20,41 @@
 #include <__cxxabi_config.h>
 
 #define _LIBCPPABI_VERSION 15000
-#define _LIBCXXABI_NORETURN  __attribute__((noreturn))
+#define _LIBCXXABI_NORETURN __attribute__((noreturn))
 #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
 
 #ifdef __cplusplus
 
 namespace std {
-#if defined(_WIN32)
+#  if defined(_WIN32)
 class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
-#else
+#  else
 class type_info; // forward declaration
-#endif
-}
-
+#  endif
+} // namespace std
 
 // runtime routines use C calling conventions, but are in __cxxabiv1 namespace
 namespace __cxxabiv1 {
 
 struct __cxa_exception;
+#  if defined(__wasm__)
+typedef 

[clang] [clang] Absoultify paths in dependency file output (PR #117458)

2024-11-23 Thread via cfe-commits

https://github.com/xtexChooser created 
https://github.com/llvm/llvm-project/pull/117458

This fixes #117438.

If paths in dependency file are not absoulte, make (or ninja) will canonicalize 
them.
While their canonicalization does not involves symbolic links expansion (for IO 
performance concerns), leaving a non-absolute path in dependency file may lead 
to unexpected canonicalization.
For example, '/a/../b', where '/a' is a symlink to '/c/d', it should be '/c/b' 
but make (and ninja) canonicalizes it as '/b', and fails for file not found.

>From f4b80b9cc44e5505180dff470440b7044e838507 Mon Sep 17 00:00:00 2001
From: xtex 
Date: Sun, 24 Nov 2024 07:06:35 +0800
Subject: [PATCH] [clang] Absoultify paths in dependency file output

This fixes #117438.

If paths in dependency file are not absoulte, make (or ninja) will
canonicalize them.
While their canonicalization does not involves symbolic links
expansion (for IO performance concerns), leaving a
non-absolute path in dependency file may lead to unexpected
canonicalization.
For example, '/a/../b', where '/a' is a symlink to '/c/d', it should be
'/c/b' but make (and ninja) canonicalizes it as '/b', and fails for file
not found.

Signed-off-by: Bingwu Zhang 
---
 clang/include/clang/Frontend/Utils.h  |  1 +
 clang/lib/Frontend/DependencyFile.cpp | 16 
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 604e42067a3f1e..8ed17179c9824b 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -120,6 +120,7 @@ class DependencyFileGenerator : public DependencyCollector {
 private:
   void outputDependencyFile(DiagnosticsEngine &Diags);
 
+  llvm::IntrusiveRefCntPtr FS;
   std::string OutputFile;
   std::vector Targets;
   bool IncludeSystemHeaders;
diff --git a/clang/lib/Frontend/DependencyFile.cpp 
b/clang/lib/Frontend/DependencyFile.cpp
index 528eae2c5283ea..ce7183b47e67c2 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -10,11 +10,11 @@
 //
 
//===--===//
 
-#include "clang/Frontend/Utils.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/Utils.h"
 #include "clang/Lex/DirectoryLookup.h"
 #include "clang/Lex/ModuleMap.h"
 #include "clang/Lex/PPCallbacks.h"
@@ -23,6 +23,7 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 
@@ -236,6 +237,7 @@ void 
DependencyFileGenerator::attachToPreprocessor(Preprocessor &PP) {
 PP.SetSuppressIncludeNotFoundError(true);
 
   DependencyCollector::attachToPreprocessor(PP);
+  FS = PP.getFileManager().getVirtualFileSystemPtr();
 }
 
 bool DependencyFileGenerator::sawDependency(StringRef Filename, bool 
FromModule,
@@ -312,11 +314,17 @@ void 
DependencyFileGenerator::finishedMainFile(DiagnosticsEngine &Diags) {
 /// https://msdn.microsoft.com/en-us/library/dd9y37ha.aspx for NMake info,
 /// 
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
 /// for Windows file-naming info.
-static void PrintFilename(raw_ostream &OS, StringRef Filename,
+static void PrintFilename(raw_ostream &OS, llvm::vfs::FileSystem *FS,
+  StringRef Filename,
   DependencyOutputFormat OutputFormat) {
   // Convert filename to platform native path
   llvm::SmallString<256> NativePath;
   llvm::sys::path::native(Filename.str(), NativePath);
+  // Make path absolute. Make and Ninja canonicalize paths without checking for
+  // symbolic links in the path, for performance concerns.
+  // If there is something like `/bin/../lib64` -> `/usr/lib64`
+  // (where `/bin` links to `/usr/bin`), Make will see them as `/lib64`.
+  FS->makeAbsolute(NativePath);
 
   if (OutputFormat == DependencyOutputFormat::NMake) {
 // Add quotes if needed. These are the characters listed as "special" to
@@ -400,7 +408,7 @@ void 
DependencyFileGenerator::outputDependencyFile(llvm::raw_ostream &OS) {
   Columns = 2;
 }
 OS << ' ';
-PrintFilename(OS, File, OutputFormat);
+PrintFilename(OS, FS.get(), File, OutputFormat);
 Columns += N + 1;
   }
   OS << '\n';
@@ -411,7 +419,7 @@ void 
DependencyFileGenerator::outputDependencyFile(llvm::raw_ostream &OS) {
 for (auto I = Files.begin(), E = Files.end(); I != E; ++I) {
   if (Index++ == InputFileIndex)
 continue;
-  PrintFilename(OS, *I, OutputFormat);
+  PrintFilename(OS, FS.get(), *I, OutputFormat);
   OS << ":\n";
 }
   }

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.o

[clang] [clang][NFC] simplify the unset check in `ParseLabeledStatement` (PR #117430)

2024-11-23 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building 
`clang` at step 10 "Add check check-offload".

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


Here is the relevant piece of the build log for the reference

```
Step 10 (Add check check-offload) failure: 1200 seconds without output running 
[b'ninja', b'-j 32', b'check-offload'], attempting to kill
...
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug47654.cpp 
(947 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49779.cpp 
(948 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug50022.cpp 
(949 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/test_libc.cpp 
(950 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/wtime.c (951 
of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: offloading/bug49021.cpp (952 
of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: 
offloading/std_complex_arithmetic.cpp (953 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: 
offloading/complex_reduction.cpp (954 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49021.cpp 
(955 of 960)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: 
offloading/std_complex_arithmetic.cpp (956 of 960)
command timed out: 1200 seconds without output running [b'ninja', b'-j 32', 
b'check-offload'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1237.279616

```



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


[clang] Revert "[AIX] Fix AIX BuildBot failure as AIX linker doesn't support version script." (PR #117444)

2024-11-23 Thread Daniel Chen via cfe-commits

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

LGTM. 
Thanks for reverting it.

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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-11-23 Thread Alexander Richardson via cfe-commits

arichardson wrote:

Could you address the raised issues instead of constantly updating the branch? 
This wastes CI resources and spams everyone subscribed to this PR. Please feel 
free to reopen it once you have addressed the issues.

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


[clang] [clang] Absoultify paths in dependency file output (PR #117458)

2024-11-23 Thread via cfe-commits

https://github.com/xtexChooser updated 
https://github.com/llvm/llvm-project/pull/117458

>From 3a9de0b6c2b3f8283080cd1f051fca5577116e59 Mon Sep 17 00:00:00 2001
From: xtex 
Date: Sun, 24 Nov 2024 07:06:35 +0800
Subject: [PATCH] [clang] Absoultify paths in dependency file output

This fixes #117438.

If paths in dependency file are not absoulte, make (or ninja) will
canonicalize them.
While their canonicalization does not involves symbolic links
expansion (for IO performance concerns), leaving a
non-absolute path in dependency file may lead to unexpected
canonicalization.
For example, '/a/../b', where '/a' is a symlink to '/c/d', it should be
'/c/b' but make (and ninja) canonicalizes it as '/b', and fails for file
not found.

Signed-off-by: Bingwu Zhang 
---
 clang/include/clang/Frontend/Utils.h  |  1 +
 clang/lib/Frontend/DependencyFile.cpp | 17 +
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 604e42067a3f1e..8ed17179c9824b 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -120,6 +120,7 @@ class DependencyFileGenerator : public DependencyCollector {
 private:
   void outputDependencyFile(DiagnosticsEngine &Diags);
 
+  llvm::IntrusiveRefCntPtr FS;
   std::string OutputFile;
   std::vector Targets;
   bool IncludeSystemHeaders;
diff --git a/clang/lib/Frontend/DependencyFile.cpp 
b/clang/lib/Frontend/DependencyFile.cpp
index 528eae2c5283ea..e7861b167e72d2 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -10,11 +10,11 @@
 //
 
//===--===//
 
-#include "clang/Frontend/Utils.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/Utils.h"
 #include "clang/Lex/DirectoryLookup.h"
 #include "clang/Lex/ModuleMap.h"
 #include "clang/Lex/PPCallbacks.h"
@@ -23,6 +23,7 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 
@@ -236,6 +237,7 @@ void 
DependencyFileGenerator::attachToPreprocessor(Preprocessor &PP) {
 PP.SetSuppressIncludeNotFoundError(true);
 
   DependencyCollector::attachToPreprocessor(PP);
+  FS = PP.getFileManager().getVirtualFileSystemPtr();
 }
 
 bool DependencyFileGenerator::sawDependency(StringRef Filename, bool 
FromModule,
@@ -312,11 +314,18 @@ void 
DependencyFileGenerator::finishedMainFile(DiagnosticsEngine &Diags) {
 /// https://msdn.microsoft.com/en-us/library/dd9y37ha.aspx for NMake info,
 /// 
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
 /// for Windows file-naming info.
-static void PrintFilename(raw_ostream &OS, StringRef Filename,
+static void PrintFilename(raw_ostream &OS, llvm::vfs::FileSystem *FS,
+  StringRef Filename,
   DependencyOutputFormat OutputFormat) {
   // Convert filename to platform native path
   llvm::SmallString<256> NativePath;
   llvm::sys::path::native(Filename.str(), NativePath);
+  // Make path absolute. Make and Ninja canonicalize paths without checking for
+  // symbolic links in the path, for performance concerns.
+  // If there is something like `/bin/../lib64` -> `/usr/lib64`
+  // (where `/bin` links to `/usr/bin`), Make will see them as `/lib64`.
+  if (FS != nullptr && llvm::sys::path::is_absolute(NativePath))
+FS->makeAbsolute(NativePath);
 
   if (OutputFormat == DependencyOutputFormat::NMake) {
 // Add quotes if needed. These are the characters listed as "special" to
@@ -400,7 +409,7 @@ void 
DependencyFileGenerator::outputDependencyFile(llvm::raw_ostream &OS) {
   Columns = 2;
 }
 OS << ' ';
-PrintFilename(OS, File, OutputFormat);
+PrintFilename(OS, FS.get(), File, OutputFormat);
 Columns += N + 1;
   }
   OS << '\n';
@@ -411,7 +420,7 @@ void 
DependencyFileGenerator::outputDependencyFile(llvm::raw_ostream &OS) {
 for (auto I = Files.begin(), E = Files.end(); I != E; ++I) {
   if (Index++ == InputFileIndex)
 continue;
-  PrintFilename(OS, *I, OutputFormat);
+  PrintFilename(OS, FS.get(), *I, OutputFormat);
   OS << ":\n";
 }
   }

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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-11-23 Thread Alexander Richardson via cfe-commits

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


[clang] [clang] Absoultify paths in dependency file output (PR #117458)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: xtex (xtexChooser)


Changes

This fixes #117438.

If paths in dependency file are not absoulte, make (or ninja) will canonicalize 
them.
While their canonicalization does not involves symbolic links expansion (for IO 
performance concerns), leaving a non-absolute path in dependency file may lead 
to unexpected canonicalization.
For example, '/a/../b', where '/a' is a symlink to '/c/d', it should be '/c/b' 
but make (and ninja) canonicalizes it as '/b', and fails for file not found.

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


2 Files Affected:

- (modified) clang/include/clang/Frontend/Utils.h (+1) 
- (modified) clang/lib/Frontend/DependencyFile.cpp (+12-4) 


``diff
diff --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 604e42067a3f1e..8ed17179c9824b 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -120,6 +120,7 @@ class DependencyFileGenerator : public DependencyCollector {
 private:
   void outputDependencyFile(DiagnosticsEngine &Diags);
 
+  llvm::IntrusiveRefCntPtr FS;
   std::string OutputFile;
   std::vector Targets;
   bool IncludeSystemHeaders;
diff --git a/clang/lib/Frontend/DependencyFile.cpp 
b/clang/lib/Frontend/DependencyFile.cpp
index 528eae2c5283ea..ce7183b47e67c2 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -10,11 +10,11 @@
 //
 
//===--===//
 
-#include "clang/Frontend/Utils.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/Utils.h"
 #include "clang/Lex/DirectoryLookup.h"
 #include "clang/Lex/ModuleMap.h"
 #include "clang/Lex/PPCallbacks.h"
@@ -23,6 +23,7 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 
@@ -236,6 +237,7 @@ void 
DependencyFileGenerator::attachToPreprocessor(Preprocessor &PP) {
 PP.SetSuppressIncludeNotFoundError(true);
 
   DependencyCollector::attachToPreprocessor(PP);
+  FS = PP.getFileManager().getVirtualFileSystemPtr();
 }
 
 bool DependencyFileGenerator::sawDependency(StringRef Filename, bool 
FromModule,
@@ -312,11 +314,17 @@ void 
DependencyFileGenerator::finishedMainFile(DiagnosticsEngine &Diags) {
 /// https://msdn.microsoft.com/en-us/library/dd9y37ha.aspx for NMake info,
 /// 
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
 /// for Windows file-naming info.
-static void PrintFilename(raw_ostream &OS, StringRef Filename,
+static void PrintFilename(raw_ostream &OS, llvm::vfs::FileSystem *FS,
+  StringRef Filename,
   DependencyOutputFormat OutputFormat) {
   // Convert filename to platform native path
   llvm::SmallString<256> NativePath;
   llvm::sys::path::native(Filename.str(), NativePath);
+  // Make path absolute. Make and Ninja canonicalize paths without checking for
+  // symbolic links in the path, for performance concerns.
+  // If there is something like `/bin/../lib64` -> `/usr/lib64`
+  // (where `/bin` links to `/usr/bin`), Make will see them as `/lib64`.
+  FS->makeAbsolute(NativePath);
 
   if (OutputFormat == DependencyOutputFormat::NMake) {
 // Add quotes if needed. These are the characters listed as "special" to
@@ -400,7 +408,7 @@ void 
DependencyFileGenerator::outputDependencyFile(llvm::raw_ostream &OS) {
   Columns = 2;
 }
 OS << ' ';
-PrintFilename(OS, File, OutputFormat);
+PrintFilename(OS, FS.get(), File, OutputFormat);
 Columns += N + 1;
   }
   OS << '\n';
@@ -411,7 +419,7 @@ void 
DependencyFileGenerator::outputDependencyFile(llvm::raw_ostream &OS) {
 for (auto I = Files.begin(), E = Files.end(); I != E; ++I) {
   if (Index++ == InputFileIndex)
 continue;
-  PrintFilename(OS, *I, OutputFormat);
+  PrintFilename(OS, FS.get(), *I, OutputFormat);
   OS << ":\n";
 }
   }

``




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


[clang] [clang] Absoultify paths in dependency file output (PR #117458)

2024-11-23 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [clang] Absoultify paths in dependency file output (PR #117458)

2024-11-23 Thread via cfe-commits

https://github.com/xtexChooser updated 
https://github.com/llvm/llvm-project/pull/117458

>From eb468c6e56ca906925d5ebd1a13cc510d86754d5 Mon Sep 17 00:00:00 2001
From: xtex 
Date: Sun, 24 Nov 2024 07:06:35 +0800
Subject: [PATCH] [clang] Absoultify paths in dependency file output

This fixes #117438.

If paths in dependency file are not absoulte, make (or ninja) will
canonicalize them.
While their canonicalization does not involves symbolic links
expansion (for IO performance concerns), leaving a
non-absolute path in dependency file may lead to unexpected
canonicalization.
For example, '/a/../b', where '/a' is a symlink to '/c/d', it should be
'/c/b' but make (and ninja) canonicalizes it as '/b', and fails for file
not found.

Signed-off-by: Bingwu Zhang 
---
 clang/include/clang/Frontend/Utils.h  |  1 +
 clang/lib/Frontend/DependencyFile.cpp | 17 +
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 604e42067a3f1e..8ed17179c9824b 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -120,6 +120,7 @@ class DependencyFileGenerator : public DependencyCollector {
 private:
   void outputDependencyFile(DiagnosticsEngine &Diags);
 
+  llvm::IntrusiveRefCntPtr FS;
   std::string OutputFile;
   std::vector Targets;
   bool IncludeSystemHeaders;
diff --git a/clang/lib/Frontend/DependencyFile.cpp 
b/clang/lib/Frontend/DependencyFile.cpp
index 528eae2c5283ea..b1b8b9d09baed4 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -10,11 +10,11 @@
 //
 
//===--===//
 
-#include "clang/Frontend/Utils.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/Utils.h"
 #include "clang/Lex/DirectoryLookup.h"
 #include "clang/Lex/ModuleMap.h"
 #include "clang/Lex/PPCallbacks.h"
@@ -23,6 +23,7 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 
@@ -236,6 +237,7 @@ void 
DependencyFileGenerator::attachToPreprocessor(Preprocessor &PP) {
 PP.SetSuppressIncludeNotFoundError(true);
 
   DependencyCollector::attachToPreprocessor(PP);
+  FS = PP.getFileManager().getVirtualFileSystemPtr();
 }
 
 bool DependencyFileGenerator::sawDependency(StringRef Filename, bool 
FromModule,
@@ -312,11 +314,18 @@ void 
DependencyFileGenerator::finishedMainFile(DiagnosticsEngine &Diags) {
 /// https://msdn.microsoft.com/en-us/library/dd9y37ha.aspx for NMake info,
 /// 
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
 /// for Windows file-naming info.
-static void PrintFilename(raw_ostream &OS, StringRef Filename,
+static void PrintFilename(raw_ostream &OS, llvm::vfs::FileSystem *FS,
+  StringRef Filename,
   DependencyOutputFormat OutputFormat) {
   // Convert filename to platform native path
   llvm::SmallString<256> NativePath;
   llvm::sys::path::native(Filename.str(), NativePath);
+  // Make path absolute. Make and Ninja canonicalize paths without checking for
+  // symbolic links in the path, for performance concerns.
+  // If there is something like `/bin/../lib64` -> `/usr/lib64`
+  // (where `/bin` links to `/usr/bin`), Make will see them as `/lib64`.
+  if (FS != nullptr)
+FS->makeAbsolute(NativePath);
 
   if (OutputFormat == DependencyOutputFormat::NMake) {
 // Add quotes if needed. These are the characters listed as "special" to
@@ -400,7 +409,7 @@ void 
DependencyFileGenerator::outputDependencyFile(llvm::raw_ostream &OS) {
   Columns = 2;
 }
 OS << ' ';
-PrintFilename(OS, File, OutputFormat);
+PrintFilename(OS, FS.get(), File, OutputFormat);
 Columns += N + 1;
   }
   OS << '\n';
@@ -411,7 +420,7 @@ void 
DependencyFileGenerator::outputDependencyFile(llvm::raw_ostream &OS) {
 for (auto I = Files.begin(), E = Files.end(); I != E; ++I) {
   if (Index++ == InputFileIndex)
 continue;
-  PrintFilename(OS, *I, OutputFormat);
+  PrintFilename(OS, FS.get(), *I, OutputFormat);
   OS << ":\n";
 }
   }

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


[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-23 Thread Scott Constable via cfe-commits

scottconstable wrote:

> > > > @phoebewang and @lvwr I also noticed that there is this code in LLVM:
> > > > https://github.com/llvm/llvm-project/blob/9ba6672b9f0e82a1f6d4100dc832c84447ea545c/llvm/lib/Transforms/Utils/ModuleUtils.cpp#L202-L214
> > > > 
> > > > . As far as I can tell, this code is not triggered when I build the 
> > > > Linux kernel with `-fsanitize=kcfi`.
> > > > When is this code triggered? And do you think it is necessary to 
> > > > additionally implement the arity-enhancement to this code?
> > > 
> > > 
> > > I'm not familar with KCFI. I find it's added by @samitolvanen in 
> > > [e1c36bd](https://github.com/llvm/llvm-project/commit/e1c36bde0551977d4b2efae032af6dfc4b2b3936).
> > >  I think you should triger it with attached test case.
> > 
> > 
> > It looks to me like this code might be triggered in some LTO 
> > configurations, and/or when linking code compiled from multiple source 
> > languages with the expectation that the KCFI type IDs will be compatible. 
> > Is my understanding correct?
> 
> Looks like the latter, see 
> [71c7313](https://github.com/llvm/llvm-project/commit/71c7313f42d2b6063fea09854cf4fc46fd0627e1)

Actually, I think this code was introduced to address a compatibility issue 
with KASAN, which apparently must generate KCFI-enabled code without clang. I 
found this explanation at 
https://github.com/llvm/llvm-project/commit/3b14862f0a968dc079530acbce4f2ca4aa7c1492
 and https://github.com/ClangBuiltLinux/linux/issues/1742.

Regardless, it looks like `llvm::setKCFIType` is intended to always produce the 
same KCFI type ID as `CodeGenModule::CreateKCFITypeId` for equivalent function 
types. For this PR, this implies that `llvm::setKCFIType` and 
`CodeGenModule::CreateKCFITypeId` must always infer the same arity for the same 
function type.

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


[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-23 Thread Scott Constable via cfe-commits


@@ -208,10 +209,34 @@ void llvm::setKCFIType(Module &M, Function &F, StringRef 
MangledType) {
   std::string Type = MangledType.str();
   if (M.getModuleFlag("cfi-normalize-integers"))
 Type += ".normalized";
+
+  uint32_t OutHash = static_cast(llvm::xxHash64(Type));
+  auto T = Triple(Twine(M.getTargetTriple()));
+  if (T.isX86() && T.isArch64Bit() && T.isOSLinux()) {
+// Estimate the function's arity (i.e., the number of arguments) at the ABI
+// level by counting the number of parameters that are likely to be passed
+// as registers, such as pointers and 64-bit (or smaller) integers. The
+// Linux x86-64 ABI allows up to 6 parameters to be passed in GPRs.
+// Additional parameters or parameters larger than 64 bits may be passed on
+// the stack, in which case the arity is denoted as 7.
+size_t NumParams = F.arg_size();
+bool MayHaveStackArgs = NumParams > 6;
+
+for (unsigned int i = 0; !MayHaveStackArgs && i < NumParams; ++i) {
+  const llvm::Type *PT = F.getArg(i)->getType();
+  if (!(PT->isPointerTy() || PT->getIntegerBitWidth() <= 64))

scottconstable wrote:

It appears that clang does not reserve stack for large arguments and instead 
this is done later by the LLVM X86 backend. For example:
```C
struct S {
int *p1;
int *p2;
int array[8];
};

int foo(struct S s, struct S *sp) {
return *s.p1 + *s.p2 + *sp->p1 + *sp->p2;
}
```
Then when I compile to LLVM IR I see:
```
define dso_local i32 @foo(ptr noundef byval(%struct.S) align 8 %s, ptr noundef 
%sp) #0 {
```
Which suggests an arity of 2. But the X86 backend transforms `foo` to pass `s` 
on the stack, and then `sp` becomes the sole argument and is passed in `rdi`. 
Hence, by the chart in the PR description, this should be treated as an arity-7 
function:

| Arity Indicator | Description |
| --- | --- |
| 0 | 0 parameters |
| 1 | 1 parameter in RDI |
| 2 | 2 parameters in RDI and RSI |
| 3 | 3 parameters in RDI, RSI, and RDX |
| 4 | 4 parameters in RDI, RSI, RDX, and RCX |
| 5 | 5 parameters in RDI, RSI, RDX, RCX, and R8 |
| 6 | 6 parameters in RDI, RSI, RDX, RCX, R8, and R9 |
| 7 | At least one parameter may be passed on the stack |

This predicate:
```
  // typeof(*PT) = llvm::Type
  if (!(PT->isPointerTy() || PT->getIntegerBitWidth() <= 64))
MayHaveStackArgs = true;
```
should prevent `s` from being counted as a register argument and correctly set 
the arity field to 7.

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


[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-23 Thread Scott Constable via cfe-commits

https://github.com/scottconstable updated 
https://github.com/llvm/llvm-project/pull/117121

>From b787d6d7a9c0904c5e47e32556103b8a5220a7d1 Mon Sep 17 00:00:00 2001
From: Scott D Constable 
Date: Tue, 19 Nov 2024 15:51:05 -0800
Subject: [PATCH] Enhance KCFI type IDs with a 3-bit arity indicator.

---
 clang/lib/CodeGen/CodeGenModule.cpp   | 31 +--
 clang/test/CodeGen/kcfi-normalize.c   | 18 +++
 clang/test/CodeGen/kcfi.c | 22 +++--
 llvm/lib/Transforms/Utils/ModuleUtils.cpp | 31 +--
 .../GCOVProfiling/kcfi-normalize.ll   |  7 +++--
 llvm/test/Transforms/GCOVProfiling/kcfi.ll|  7 +++--
 6 files changed, 95 insertions(+), 21 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index b854eeb62a80ce..f9c01edf4f0953 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2183,7 +2183,8 @@ llvm::ConstantInt 
*CodeGenModule::CreateCrossDsoCfiTypeId(llvm::Metadata *MD) {
 }
 
 llvm::ConstantInt *CodeGenModule::CreateKCFITypeId(QualType T) {
-  if (auto *FnType = T->getAs())
+  auto *FnType = T->getAs();
+  if (FnType)
 T = getContext().getFunctionType(
 FnType->getReturnType(), FnType->getParamTypes(),
 FnType->getExtProtoInfo().withExceptionSpec(EST_None));
@@ -2196,8 +2197,32 @@ llvm::ConstantInt 
*CodeGenModule::CreateKCFITypeId(QualType T) {
   if (getCodeGenOpts().SanitizeCfiICallNormalizeIntegers)
 Out << ".normalized";
 
-  return llvm::ConstantInt::get(Int32Ty,
-
static_cast(llvm::xxHash64(OutName)));
+  uint32_t OutHash = static_cast(llvm::xxHash64(OutName));
+  const auto &Triple = getTarget().getTriple();
+  if (FnType && Triple.isX86() && Triple.isArch64Bit() && Triple.isOSLinux()) {
+// Estimate the function's arity (i.e., the number of arguments) at the ABI
+// level by counting the number of parameters that are likely to be passed
+// as registers, such as pointers and 64-bit (or smaller) integers. The
+// Linux x86-64 ABI allows up to 6 parameters to be passed in GPRs.
+// Additional parameters or parameters larger than 64 bits may be passed on
+// the stack, in which case the arity is denoted as 7.
+bool MayHaveStackArgs = FnType->getNumParams() > 6;
+
+for (unsigned int i = 0; !MayHaveStackArgs && i < FnType->getNumParams();
+ ++i) {
+  const Type *PT = FnType->getParamType(i).getTypePtr();
+  if (!(PT->isPointerType() || (PT->isIntegralOrEnumerationType() &&
+getContext().getTypeSize(PT) <= 64)))
+MayHaveStackArgs = true;
+}
+
+// The 3-bit arity is concatenated with the lower 29 bits of the KCFI hash
+// to form an enhanced KCFI type ID. This can prevent, for example, a
+// 3-arity function's ID from ever colliding with a 2-arity function's ID.
+OutHash = (OutHash << 3) | (MayHaveStackArgs ? 7 : FnType->getNumParams());
+  }
+
+  return llvm::ConstantInt::get(Int32Ty, OutHash);
 }
 
 void CodeGenModule::SetLLVMFunctionAttributes(GlobalDecl GD,
diff --git a/clang/test/CodeGen/kcfi-normalize.c 
b/clang/test/CodeGen/kcfi-normalize.c
index b9150e88f6ab5f..8b7445fc85e490 100644
--- a/clang/test/CodeGen/kcfi-normalize.c
+++ b/clang/test/CodeGen/kcfi-normalize.c
@@ -10,25 +10,31 @@
 void foo(void (*fn)(int), int arg) {
 // CHECK-LABEL: define{{.*}}foo
 // CHECK-SAME: {{.*}}!kcfi_type ![[TYPE1:[0-9]+]]
-// CHECK: call void %0(i32 noundef %1){{.*}}[ "kcfi"(i32 1162514891) ]
+// KCFI ID = 0x2A548E59
+// CHECK: call void %0(i32 noundef %1){{.*}}[ "kcfi"(i32 710184537) ]
 fn(arg);
 }
 
 void bar(void (*fn)(int, int), int arg1, int arg2) {
 // CHECK-LABEL: define{{.*}}bar
 // CHECK-SAME: {{.*}}!kcfi_type ![[TYPE2:[0-9]+]]
-// CHECK: call void %0(i32 noundef %1, i32 noundef %2){{.*}}[ "kcfi"(i32 
448046469) ]
+// KCFI ID = 0xD5A52C2A
+// CHECK: call void %0(i32 noundef %1, i32 noundef %2){{.*}}[ "kcfi"(i32 
-710595542) ]
 fn(arg1, arg2);
 }
 
 void baz(void (*fn)(int, int, int), int arg1, int arg2, int arg3) {
 // CHECK-LABEL: define{{.*}}baz
 // CHECK-SAME: {{.*}}!kcfi_type ![[TYPE3:[0-9]+]]
-// CHECK: call void %0(i32 noundef %1, i32 noundef %2, i32 noundef 
%3){{.*}}[ "kcfi"(i32 -2049681433) ]
+// KCFI ID = 0x2EA2BF3B
+// CHECK: call void %0(i32 noundef %1, i32 noundef %2, i32 noundef 
%3){{.*}}[ "kcfi"(i32 782417723) ]
 fn(arg1, arg2, arg3);
 }
 
 // CHECK: ![[#]] = !{i32 4, !"cfi-normalize-integers", i32 1}
-// CHECK: ![[TYPE1]] = !{i32 -1143117868}
-// CHECK: ![[TYPE2]] = !{i32 -460921415}
-// CHECK: ![[TYPE3]] = !{i32 -333839615}
+// KCFI ID = DEEB3EA2
+// CHECK: ![[TYPE1]] = !{i32 -555008350}
+// KCFI ID = 24372DCB
+// CHECK: ![[TYPE2]] = !{i32 607595979}
+// KCFI ID = 0x60D0180C
+// CHECK: ![[TYPE3]] = !{i32 1624250380}
diff --git a/clang/test/CodeGen/kcfi.c b/clang/test/CodeGen

[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-23 Thread Scott Constable via cfe-commits


@@ -208,10 +209,34 @@ void llvm::setKCFIType(Module &M, Function &F, StringRef 
MangledType) {
   std::string Type = MangledType.str();
   if (M.getModuleFlag("cfi-normalize-integers"))
 Type += ".normalized";
+
+  uint32_t OutHash = static_cast(llvm::xxHash64(Type));
+  auto T = Triple(Twine(M.getTargetTriple()));

scottconstable wrote:

Thank you for the suggestion! This does look tidier than what I had written. I 
updated the PR.

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


[clang] [llvm] [InstCombine] Fold `X > C2 ? X + C1 : C2 + C1` to `max(X, C2) + C1` (PR #116888)

2024-11-23 Thread via cfe-commits

https://github.com/veera-sivarajan updated 
https://github.com/llvm/llvm-project/pull/116888

>From 4fe3c73cdfd89eb08b9491774e08fa5d3d48d26b Mon Sep 17 00:00:00 2001
From: Veera 
Date: Thu, 21 Nov 2024 20:55:55 +
Subject: [PATCH 1/2] Add Test

---
 .../InstCombine/canonicalize-const-to-bop.ll  | 400 ++
 1 file changed, 400 insertions(+)
 create mode 100644 
llvm/test/Transforms/InstCombine/canonicalize-const-to-bop.ll

diff --git a/llvm/test/Transforms/InstCombine/canonicalize-const-to-bop.ll 
b/llvm/test/Transforms/InstCombine/canonicalize-const-to-bop.ll
new file mode 100644
index 00..1c78e6ab7fc861
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/canonicalize-const-to-bop.ll
@@ -0,0 +1,400 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define i8 @add_and_sgt(i8 %x) {
+; CHECK-LABEL: define i8 @add_and_sgt(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:[[ADD:%.*]] = add nsw i8 [[X]], 16
+; CHECK-NEXT:[[CMP:%.*]] = icmp sgt i8 [[X]], 8
+; CHECK-NEXT:[[S:%.*]] = select i1 [[CMP]], i8 [[ADD]], i8 24
+; CHECK-NEXT:ret i8 [[S]]
+;
+  %add = add nsw i8 %x, 16
+  %cmp = icmp sgt i8 %x, 8
+  %s = select i1 %cmp, i8 %add, i8 24
+  ret i8 %s
+}
+
+define i8 @add_sgt_nuw(i8 %x) {
+; CHECK-LABEL: define i8 @add_sgt_nuw(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:[[ADD:%.*]] = add nuw i8 [[X]], 16
+; CHECK-NEXT:[[CMP:%.*]] = icmp sgt i8 [[X]], 8
+; CHECK-NEXT:[[S:%.*]] = select i1 [[CMP]], i8 [[ADD]], i8 24
+; CHECK-NEXT:ret i8 [[S]]
+;
+  %add = add nuw i8 %x, 16
+  %cmp = icmp sgt i8 %x, 8
+  %s = select i1 %cmp, i8 %add, i8 24
+  ret i8 %s
+}
+
+define i8 @sub_and_ugt(i8 %x) {
+; CHECK-LABEL: define i8 @sub_and_ugt(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:[[SUB:%.*]] = add nsw i8 [[X]], -50
+; CHECK-NEXT:[[CMP:%.*]] = icmp ugt i8 [[X]], 100
+; CHECK-NEXT:[[S:%.*]] = select i1 [[CMP]], i8 50, i8 [[SUB]]
+; CHECK-NEXT:ret i8 [[S]]
+;
+  %sub = sub nsw i8 %x, 50
+  %cmp = icmp ugt i8 %x, 100
+  %s = select i1 %cmp, i8 50, i8 %sub
+  ret i8 %s
+}
+
+define i8 @sub_ugt_nuw_nsw(i8 %x) {
+; CHECK-LABEL: define i8 @sub_ugt_nuw_nsw(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:[[SUB:%.*]] = add nsw i8 [[X]], -50
+; CHECK-NEXT:[[CMP:%.*]] = icmp ugt i8 [[X]], 100
+; CHECK-NEXT:[[S:%.*]] = select i1 [[CMP]], i8 50, i8 [[SUB]]
+; CHECK-NEXT:ret i8 [[S]]
+;
+  %sub = sub nuw nsw i8 %x, 50
+  %cmp = icmp ugt i8 %x, 100
+  %s = select i1 %cmp, i8 50, i8 %sub
+  ret i8 %s
+}
+
+define i8 @mul_and_ult(i8 %x) {
+; CHECK-LABEL: define i8 @mul_and_ult(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:[[ADD:%.*]] = mul nsw i8 [[X]], 10
+; CHECK-NEXT:[[CMP:%.*]] = icmp ugt i8 [[X]], 10
+; CHECK-NEXT:[[S:%.*]] = select i1 [[CMP]], i8 100, i8 [[ADD]]
+; CHECK-NEXT:ret i8 [[S]]
+;
+  %add = mul nsw i8 %x, 10
+  %cmp = icmp ult i8 10, %x
+  %s = select i1 %cmp, i8 100, i8 %add
+  ret i8 %s
+}
+
+define i8 @mul_ult_noflags(i8 %x) {
+; CHECK-LABEL: define i8 @mul_ult_noflags(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:[[ADD:%.*]] = mul i8 [[X]], 10
+; CHECK-NEXT:[[CMP:%.*]] = icmp ugt i8 [[X]], 10
+; CHECK-NEXT:[[S:%.*]] = select i1 [[CMP]], i8 100, i8 [[ADD]]
+; CHECK-NEXT:ret i8 [[S]]
+;
+  %add = mul i8 %x, 10
+  %cmp = icmp ult i8 10, %x
+  %s = select i1 %cmp, i8 100, i8 %add
+  ret i8 %s
+}
+
+define i8 @udiv_and_slt(i8 %x) {
+; CHECK-LABEL: define i8 @udiv_and_slt(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:[[SUB:%.*]] = udiv i8 [[X]], 10
+; CHECK-NEXT:[[CMP:%.*]] = icmp slt i8 [[X]], 100
+; CHECK-NEXT:[[S:%.*]] = select i1 [[CMP]], i8 10, i8 [[SUB]]
+; CHECK-NEXT:ret i8 [[S]]
+;
+  %sub = udiv i8 %x, 10
+  %cmp = icmp slt i8 %x, 100
+  %s = select i1 %cmp, i8 10, i8 %sub
+  ret i8 %s
+}
+
+define i8 @udiv_slt_exact(i8 %x) {
+; CHECK-LABEL: define i8 @udiv_slt_exact(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:[[SUB:%.*]] = udiv exact i8 [[X]], 10
+; CHECK-NEXT:[[CMP:%.*]] = icmp slt i8 [[X]], 100
+; CHECK-NEXT:[[S:%.*]] = select i1 [[CMP]], i8 10, i8 [[SUB]]
+; CHECK-NEXT:ret i8 [[S]]
+;
+  %sub = udiv exact i8 %x, 10
+  %cmp = icmp slt i8 %x, 100
+  %s = select i1 %cmp, i8 10, i8 %sub
+  ret i8 %s
+}
+
+define i8 @canonicalize_icmp_operands(i8 %x) {
+; CHECK-LABEL: define i8 @canonicalize_icmp_operands(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:[[ADD:%.*]] = add nsw i8 [[X]], 8
+; CHECK-NEXT:[[CMP:%.*]] = icmp sgt i8 [[X]], 119
+; CHECK-NEXT:[[S:%.*]] = select i1 [[CMP]], i8 127, i8 [[ADD]]
+; CHECK-NEXT:ret i8 [[S]]
+;
+  %add = add nsw i8 %x, 8
+  %cmp = icmp sle i8 120, %x
+  %s = select i1 %cmp, i8 127, i8 %add
+  ret i8 %s
+}
+
+declare void @use(i1)
+declare void @use_byte(i8)
+
+define i8 @multi_use_cond_and_sel(i8 %x) {
+; CHECK-LABEL: define i8 @multi_use_cond_and_sel(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:[[ADD:%.*

[clang] [llvm] [InstCombine] Fold `X > C2 ? X + C1 : C2 + C1` to `max(X, C2) + C1` (PR #116888)

2024-11-23 Thread via cfe-commits

veera-sivarajan wrote:

> The more idiomatic way to handle this is to have something like if 
> (match(FalseVal, m_Constant())) { std::swap(TrueVal, FalseVal); Pred = 
> ICmpInst::getInversePredicate(Pred); } and then you no longer have to deal 
> with which operand the constant is in.

Thank you for the detailed feedback.

This simplifies the pattern match but I still have to conditionally assign 
`NewTrue` and `NewFalse` because `matchDecomposedSelectPattern()` takes an 
`ICmpInst` and not a `ICmpInst:Predicate`.


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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-23 Thread via cfe-commits

vabridgers wrote:

Ping! Any more comments on this change? Thanks

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


[clang] [Clang] prevent errors for deduction guides using deduced type aliases (PR #117450)

2024-11-23 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/117450

Fixes #54909

>From 5212f12874a859a9f7b6c662402aa2171006d011 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 24 Nov 2024 00:19:06 +0200
Subject: [PATCH] [Clang] prevent errors for deduction guides using deduced
 type aliases

---
 clang/docs/ReleaseNotes.rst  |  2 ++
 clang/lib/Sema/SemaDeclCXX.cpp   |  6 +-
 clang/test/CXX/temp/temp.deduct.guide/p3.cpp | 12 +++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bd06fadfdc984..2437def6322764 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -583,6 +583,8 @@ Improvements to Clang's diagnostics
 - For an rvalue reference bound to a temporary struct with an integer member, 
Clang will detect constant integer overflow
   in the initializer for the integer member (#GH46755).
 
+- Clang now prevents errors for deduction guides with deduced type aliases 
(#GH54909).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 26041e53de5061..9d0eb098841a3a 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11451,7 +11451,11 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator 
&D, QualType &R,
 bool MightInstantiateToSpecialization = false;
 if (auto RetTST =
 TSI->getTypeLoc().getAsAdjusted()) {
-  TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName();
+  const TemplateSpecializationType *TST = RetTST.getTypePtr();
+  while (TST->isTypeAlias())
+TST = TST->getAliasedType()->getAs();
+
+  TemplateName SpecifiedName = TST->getTemplateName();
   bool TemplateMatches = Context.hasSameTemplateName(
   SpecifiedName, GuidedTemplate, /*IgnoreDeduced=*/true);
 
diff --git a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp 
b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp
index c5404847beb066..36e0f75ccf9098 100644
--- a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp
+++ b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp
@@ -33,7 +33,7 @@ template typename TT> struct E { // 
expected-note 2{{template
 };
 
 A(int) -> int; // expected-error {{deduced type 'int' of deduction guide is 
not a specialization of template 'A'}}
-template  A(T)->B; // expected-error {{deduced type 
'B' (aka 'A') of deduction guide is not written as a specialization of 
template 'A'}}
+template  A(T)->B;
 template A(T*) -> const A; // expected-error {{deduced type 
'const A' of deduction guide is not a specialization of template 'A'}}
 
 // A deduction-guide shall be declared in the same scope as the corresponding
@@ -71,3 +71,13 @@ namespace WrongScope {
 Local(int) -> Local; // expected-error {{expected}}
   }
 }
+
+namespace GH54909 {
+template  struct A {};
+A(void) -> A;
+
+template  using B = A;
+template  using C = B;
+template  using D = C;
+template  A(T) -> D;
+}

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


[clang] [Clang] prevent errors for deduction guides using deduced type aliases (PR #117450)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #54909

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+5-1) 
- (modified) clang/test/CXX/temp/temp.deduct.guide/p3.cpp (+11-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bd06fadfdc984..2437def6322764 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -583,6 +583,8 @@ Improvements to Clang's diagnostics
 - For an rvalue reference bound to a temporary struct with an integer member, 
Clang will detect constant integer overflow
   in the initializer for the integer member (#GH46755).
 
+- Clang now prevents errors for deduction guides with deduced type aliases 
(#GH54909).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 26041e53de5061..9d0eb098841a3a 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11451,7 +11451,11 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator 
&D, QualType &R,
 bool MightInstantiateToSpecialization = false;
 if (auto RetTST =
 TSI->getTypeLoc().getAsAdjusted()) {
-  TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName();
+  const TemplateSpecializationType *TST = RetTST.getTypePtr();
+  while (TST->isTypeAlias())
+TST = TST->getAliasedType()->getAs();
+
+  TemplateName SpecifiedName = TST->getTemplateName();
   bool TemplateMatches = Context.hasSameTemplateName(
   SpecifiedName, GuidedTemplate, /*IgnoreDeduced=*/true);
 
diff --git a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp 
b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp
index c5404847beb066..36e0f75ccf9098 100644
--- a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp
+++ b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp
@@ -33,7 +33,7 @@ template typename TT> struct E { // 
expected-note 2{{template
 };
 
 A(int) -> int; // expected-error {{deduced type 'int' of deduction guide is 
not a specialization of template 'A'}}
-template  A(T)->B; // expected-error {{deduced type 
'B' (aka 'A') of deduction guide is not written as a specialization of 
template 'A'}}
+template  A(T)->B;
 template A(T*) -> const A; // expected-error {{deduced type 
'const A' of deduction guide is not a specialization of template 'A'}}
 
 // A deduction-guide shall be declared in the same scope as the corresponding
@@ -71,3 +71,13 @@ namespace WrongScope {
 Local(int) -> Local; // expected-error {{expected}}
   }
 }
+
+namespace GH54909 {
+template  struct A {};
+A(void) -> A;
+
+template  using B = A;
+template  using C = B;
+template  using D = C;
+template  A(T) -> D;
+}

``




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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-11-23 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From 2b526821d4e70f3ea83f95d25f804d9fbcf82612 Mon Sep 17 00:00:00 2001
From: cqwrteur <100043421+trcrsi...@users.noreply.github.com>
Date: Sat, 1 Jun 2024 02:55:50 -0400
Subject: [PATCH] [libunwind][libcxx][libcxxabi] Fix Exception Handling build
 for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change

Merge remote-tracking branch 'parent/main' into wasmlibunwindfix

remove unwanted changes in unwind-wasm.c

Make Unwind-wasm.c compile correctly without workaround in
CMakeLists.txt

using __wasm__ macro to guard against all wasm eh build

fix UnwindLevel.c's formatting issue

ISO C requires a translation unit to contain at least one declaration 
[-Werror,-Wempty-translation-unit]

compiler-rt does not define CMP_RESULT correct on wasm64
Fixed

Merge code
---
 compiler-rt/lib/builtins/fp_compare_impl.inc |   2 +-
 libcxx/include/__exception/exception_ptr.h   |  21 +-
 libcxxabi/include/cxxabi.h   | 134 ++--
 libcxxabi/src/cxa_exception.cpp  | 710 ---
 libcxxabi/src/cxa_exception.h|   7 +-
 libunwind/include/libunwind.h|   2 +
 libunwind/src/Unwind-wasm.c  |  13 +-
 libunwind/src/UnwindRegistersRestore.S   |   3 +-
 libunwind/src/UnwindRegistersSave.S  |   3 +
 libunwind/src/assembly.h |   2 +
 libunwind/src/cet_unwind.h   |   3 +
 libunwind/src/config.h   |  15 +-
 libunwind/src/libunwind.cpp  |   2 +
 libunwind/src/libunwind_ext.h|   2 +
 14 files changed, 403 insertions(+), 516 deletions(-)

diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe4..83bdea46a45da4 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -12,7 +12,7 @@
 // functions. We need to ensure that the return value is sign-extended in the
 // same way as GCC expects (since otherwise GCC-generated __builtin_isinf
 // returns true for finite 128-bit floating-point numbers).
-#ifdef __aarch64__
+#if defined(__aarch64__) || defined(__wasm__)
 // AArch64 GCC overrides libgcc_cmp_return to use int instead of long.
 typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 9e5351f534a1c1..84a78d378cc19f 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -29,22 +29,21 @@
 
 namespace __cxxabiv1 {
 
+#if defined(__wasm__)
+typedef void* (*__libcpp_exception_destructor_func)(void*);
+#elif defined(_WIN32)
+typedef void(__thiscall* __libcpp_exception_destructor_func)(void*);
+#else
+typedef void (*__libcpp_exception_destructor_func)(void*);
+#endif
+
 extern "C" {
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
 _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
 
 struct __cxa_exception;
-_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
-void*,
-std::type_info*,
-#if defined(_WIN32)
-void(__thiscall*)(void*)) throw();
-#elif defined(__wasm__)
-// In Wasm, a destructor returns its argument
-void* (*)(void*)) throw();
-#else
-void (*)(void*)) throw();
-#endif
+_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception*
+__cxa_init_primary_exception(void*, std::type_info*, 
__libcpp_exception_destructor_func) throw();
 }
 
 } // namespace __cxxabiv1
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index 9ea93680f62e06..cf0cc40ff42b9e 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -20,49 +20,41 @@
 #include <__cxxabi_config.h>
 
 #define _LIBCPPABI_VERSION 15000
-#define _LIBCXXABI_NORETURN  __attribute__((noreturn))
+#define _LIBCXXABI_NORETURN __attribute__((noreturn))
 #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
 
 #ifdef __cplusplus
 
 namespace std {
-#if defined(_WIN32)
+#  if defined(_WIN32)
 class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
-#else
+#  else
 class type_info; // forward declaration
-#endif
-}
-
+#  endif
+} // namespace std
 
 // runtime routines use C calling conventions, but are in __cxxabiv1 namespace
 namespace __cxxabiv1 {
 
 struct __cxa_exception;
+#  if defined(__wasm__)
+typedef 

[libunwind] [libunwind] Fix compilation for the x32 ABI. (PR #116608)

2024-11-23 Thread Alex Rønne Petersen via cfe-commits

https://github.com/alexrp updated 
https://github.com/llvm/llvm-project/pull/116608

From dfcfbd6b9fbcd92326192677ba8e73d195719300 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= 
Date: Mon, 18 Nov 2024 13:12:30 +0100
Subject: [PATCH] [libunwind] Fix compilation for the x32 ABI.

This would previously fail the static assertions in UnwindCursor.hpp due to
UnwindCursor's size not matching unw_cursor_t's size. As is done for MIPS N32,
this just declares the appropriate size in __libunwind_config.h.
---
 libunwind/include/__libunwind_config.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 028b9e3baa8065..bb7fe4c83a3c17 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -53,6 +53,9 @@
 #else
 #  define _LIBUNWIND_CURSOR_SIZE 66
 #endif
+#  elif defined(__ILP32__)
+#define _LIBUNWIND_CONTEXT_SIZE 21
+#define _LIBUNWIND_CURSOR_SIZE 28
 #  else
 #define _LIBUNWIND_CONTEXT_SIZE 21
 #define _LIBUNWIND_CURSOR_SIZE 33

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


[clang] [llvm] [LoongArch] Support LA V1.1 feature ld-seq-sa that don't generate dbar 0x700. (PR #116762)

2024-11-23 Thread Yingwei Zheng via cfe-commits


@@ -2011,8 +2011,9 @@ const StringMap sys::getHostCPUFeatures() {
 const StringMap sys::getHostCPUFeatures() {
   unsigned long hwcap = getauxval(AT_HWCAP);
   bool HasFPU = hwcap & (1UL << 3); // HWCAP_LOONGARCH_FPU
-  uint32_t cpucfg2 = 0x2;
+  const uint32_t cpucfg2 = 0x2, cpucfg3 = 0x3;

dtcxzyw wrote:

I encountered a compilation error with gcc 13.2:
```
[1/371] Building CXX object 
lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o
FAILED: lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o 
ccache /usr/bin/g++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/dtcxzyw/llvm-build/lib/TargetParser 
-I/home/dtcxzyw/llvm-project/llvm/lib/TargetParser 
-I/home/dtcxzyw/llvm-build/include -I/home/dtcxzyw/llvm-project/llvm/include 
-fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time 
-fno-lifetime-dse -w -fdiagnostics-color -ffunction-sections -fdata-sections 
-O3 -DNDEBUG -std=c++17 -fPIC  -fno-exceptions -funwind-tables -fno-rtti 
-UNDEBUG -MD -MT lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o 
-MF lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o.d -o 
lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Host.cpp.o -c 
/home/dtcxzyw/llvm-project/llvm/lib/TargetParser/Host.cpp
/home/dtcxzyw/llvm-project/llvm/lib/TargetParser/Host.cpp: In function ‘const 
llvm::StringMap llvm::sys::getHostCPUFeatures()’:
/home/dtcxzyw/llvm-project/llvm/lib/TargetParser/Host.cpp:2015:3: error: 
read-only variable ‘cpucfg2’ used as ‘asm’ output
 2015 |   __asm__("cpucfg %[cpucfg2], %[cpucfg2]\n\t" : [cpucfg2] 
"+r"(cpucfg2));
  |   ^~~
/home/dtcxzyw/llvm-project/llvm/lib/TargetParser/Host.cpp:2016:3: error: 
read-only variable ‘cpucfg3’ used as ‘asm’ output
 2016 |   __asm__("cpucfg %[cpucfg3], %[cpucfg3]\n\t" : [cpucfg3] 
"+r"(cpucfg3));
  |   ^~~
ninja: build stopped: subcommand failed.
```

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


[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-23 Thread Phoebe Wang via cfe-commits


@@ -208,10 +209,34 @@ void llvm::setKCFIType(Module &M, Function &F, StringRef 
MangledType) {
   std::string Type = MangledType.str();
   if (M.getModuleFlag("cfi-normalize-integers"))
 Type += ".normalized";
+
+  uint32_t OutHash = static_cast(llvm::xxHash64(Type));
+  auto T = Triple(Twine(M.getTargetTriple()));
+  if (T.isX86() && T.isArch64Bit() && T.isOSLinux()) {
+// Estimate the function's arity (i.e., the number of arguments) at the ABI
+// level by counting the number of parameters that are likely to be passed
+// as registers, such as pointers and 64-bit (or smaller) integers. The
+// Linux x86-64 ABI allows up to 6 parameters to be passed in GPRs.
+// Additional parameters or parameters larger than 64 bits may be passed on
+// the stack, in which case the arity is denoted as 7.
+size_t NumParams = F.arg_size();
+bool MayHaveStackArgs = NumParams > 6;
+
+for (unsigned int i = 0; !MayHaveStackArgs && i < NumParams; ++i) {
+  const llvm::Type *PT = F.getArg(i)->getType();
+  if (!(PT->isPointerTy() || PT->getIntegerBitWidth() <= 64))

phoebewang wrote:

Right, `byval` is an exception. You can use `hasPassPointeeByValueCopyAttr()` 
to check it.

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


[clang] Add an off-by-default warning to complain about MSVC bitfield padding (PR #117428)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oliver Hunt (ojhunt)


Changes

This just adds a warning for bitfields placed next to other bitfields where the 
underlying type has different storage. Under the MS struct bitfield packing ABI 
such bitfields are not packed.

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


4 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+1) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+6) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+25-2) 
- (added) clang/test/SemaCXX/ms_struct-bitfield-padding.cpp (+180) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index df9bf94b5d0398..57bdda4b8f8b47 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -631,6 +631,7 @@ def Packed : DiagGroup<"packed", [PackedNonPod]>;
 def PaddedBitField : DiagGroup<"padded-bitfield">;
 def Padded : DiagGroup<"padded", [PaddedBitField]>;
 def UnalignedAccess : DiagGroup<"unaligned-access">;
+def MSBitfieldCompatibility : DiagGroup<"ms-bitfield-packing-compatibility">;
 
 def PessimizingMove : DiagGroup<"pessimizing-move">;
 def ReturnStdMove : DiagGroup<"return-std-move">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eb05a6a77978af..aa13e3438d3739 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6418,6 +6418,12 @@ def warn_signed_bitfield_enum_conversion : Warning<
   InGroup, DefaultIgnore;
 def note_change_bitfield_sign : Note<
   "consider making the bitfield type %select{unsigned|signed}0">;
+def warn_ms_bitfield_mismatched_storage_packing : Warning<
+  "bit-field %0 of type %1 has a different storage size (%2 vs %3 bytes) than 
the "
+  "preceding bit-field and may not be packed under MSVC ABI">,
+  InGroup, DefaultIgnore;
+def note_ms_bitfield_mismatched_storage_size_previous : Note<
+  "preceding bit-field %0 declared here with type %1">;
 
 def warn_missing_braces : Warning<
   "suggest braces around initialization of subobject">,
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 74b0e5ad23bd48..18aeca3b34f659 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19001,9 +19001,9 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, 
Decl *EnclosingDecl,
 
   // Verify that all the fields are okay.
   SmallVector RecFields;
-
+  std::optional PreviousField;
   for (ArrayRef::iterator i = Fields.begin(), end = Fields.end();
-   i != end; ++i) {
+   i != end; PreviousField = cast(*i), ++i) {
 FieldDecl *FD = cast(*i);
 
 // Get the type for the field.
@@ -19213,6 +19213,29 @@ void Sema::ActOnFields(Scope *S, SourceLocation 
RecLoc, Decl *EnclosingDecl,
 
 if (Record && FD->getType().isVolatileQualified())
   Record->setHasVolatileMember(true);
+auto IsNonDependentBitField = [](const FieldDecl *FD) {
+  if (!FD->isBitField())
+return false;
+  if (FD->getType()->isDependentType())
+return false;
+  return true;
+};
+
+if (Record && PreviousField && IsNonDependentBitField(FD) &&
+IsNonDependentBitField(*PreviousField)) {
+  unsigned FDStorageSize =
+  Context.getTypeSizeInChars(FD->getType()).getQuantity();
+  unsigned PreviousFieldStorageSize =
+  
Context.getTypeSizeInChars((*PreviousField)->getType()).getQuantity();
+  if (FDStorageSize != PreviousFieldStorageSize) {
+Diag(FD->getLocation(),
+ diag::warn_ms_bitfield_mismatched_storage_packing)
+<< FD << FD->getType() << FDStorageSize << 
PreviousFieldStorageSize;
+Diag((*PreviousField)->getLocation(),
+ diag::note_ms_bitfield_mismatched_storage_size_previous)
+<< *PreviousField << (*PreviousField)->getType();
+  }
+}
 // Keep track of the number of named members.
 if (FD->getIdentifier())
   ++NumNamedMembers;
diff --git a/clang/test/SemaCXX/ms_struct-bitfield-padding.cpp 
b/clang/test/SemaCXX/ms_struct-bitfield-padding.cpp
new file mode 100644
index 00..001086de5bbd10
--- /dev/null
+++ b/clang/test/SemaCXX/ms_struct-bitfield-padding.cpp
@@ -0,0 +1,180 @@
+
+// RUN: %clang_cc1 -fsyntax-only -Wms-bitfield-packing-compatibility -verify 
-triple armv8 -std=c++23 %s
+// RUN: %clang_cc1 -fsyntax-only -DMS_BITFIELDS -mms-bitfields 
-verify=msbitfields -triple armv8-apple-macos10.15 -std=c++23 %s
+
+// msbitfields-no-diagnostics
+
+enum Enum1 { Enum1_A, Enum1_B };
+enum Enum2 { Enum2_A, Enum2_B };
+
+enum class EnumU32_1 : unsigned { A, B };
+enum class EnumU32_2 : unsigned { A, B };
+enum class EnumU64 : unsigned long long { A, B };
+enum class EnumI32 : int { A, B };
+enum class EnumU8 : unsigned char { A, B };
+enum class EnumI8 : char { A, B }

[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-11-23 Thread Oliver Hunt via cfe-commits

ojhunt wrote:

This has been tentatively approved C++26 - CWG didn't have time to look at it 
this week but EWG and SG23 have approved it. I did spend some time discussing 
semantics with a couple of folk in EWG and CWG and the feedback was fairly 
strongly on the side of "the operator delete used for cleanup when a 
constructor throws must have the same typed awaredness" (e.g. the existing 
exact placement new parameters match requirement). But this implementation 
currently allows fallback to a non-type aware delete, so I'm changing that and 
adding test cases to ensure correctness according to those semantics.

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


[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

2024-11-23 Thread Nikolas Klauser via cfe-commits

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


[clang] aa2d084 - [clang-format][NFC] Reformat testcases added in 0ff8b7916050

2024-11-23 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-11-23T06:31:14-08:00
New Revision: aa2d084f9a68f041a42e4df84e11d769a7be34a6

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

LOG: [clang-format][NFC] Reformat testcases added in 0ff8b7916050

Added: 


Modified: 
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index e1ae1770e8ebe8..9db3187ac44e70 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2600,16 +2600,20 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) 
{
   EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown);
 
   // Module headers.
-  Tokens = Annotate("module x();\nendmodule");
+  Tokens = Annotate("module x();\n"
+"endmodule");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_VerilogMultiLineListLParen);
-  Tokens = Annotate("function automatic `x x();\nendmodule");
+  Tokens = Annotate("function automatic `x x();\n"
+"endmodule");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_VerilogMultiLineListLParen);
-  Tokens = Annotate("function automatic x``x x();\nendmodule");
+  Tokens = Annotate("function automatic x``x x();\n"
+"endmodule");
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_VerilogMultiLineListLParen);
-  Tokens = Annotate("function automatic x::x x();\nendmodule");
+  Tokens = Annotate("function automatic x::x x();\n"
+"endmodule");
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_VerilogMultiLineListLParen);
 }



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


[clang] Add an off-by-default warning to complain about MSVC bitfield padding (PR #117428)

2024-11-23 Thread Oliver Hunt via cfe-commits

ojhunt wrote:

Oh, my goal for this warning is to have us turn it on in the llvm+clang builds, 
so we can then move away from endless use of unsigned bitfields and just use 
enums as nature intended :D (cc @AaronBallman )

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


[clang] [clang-format] Stop crashing on slightly off Verilog module headers (PR #116000)

2024-11-23 Thread Owen Pan via cfe-commits


@@ -2598,6 +2598,20 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
   Tokens = Annotate("x = '{\"\"};");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown);
+
+  // Module headers.
+  Tokens = Annotate("module x();\nendmodule");

owenca wrote:

This (and other testcases below) should be broken up into two lines:
```c++
  Tokens = Annotate("module x();\n"
"endmodule");
```

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


[clang] [clang-format] Stop crashing on slightly off Verilog module headers (PR #116000)

2024-11-23 Thread Owen Pan via cfe-commits


@@ -2598,6 +2598,20 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
   Tokens = Annotate("x = '{\"\"};");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown);
+
+  // Module headers.
+  Tokens = Annotate("module x();\nendmodule");

owenca wrote:

Fixed in aa2d084f9a68f041a42e4df84e11d769a7be34a6.

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


[clang] [Clang] Fix -Wunused-private-field false negative with defaulted comparison operators (PR #116871)

2024-11-23 Thread Chris White via cfe-commits

https://github.com/whiteio updated 
https://github.com/llvm/llvm-project/pull/116871

>From ad14635ab12eb81a841db885962c95911722e4f2 Mon Sep 17 00:00:00 2001
From: Chris White 
Date: Tue, 19 Nov 2024 20:06:28 +
Subject: [PATCH 1/3] [Clang] Fix -Wunused-private-field false negative with
 defaulted comparison operators

Fix -Wunused-private-field suppressing warnings when defaulted comparison
operators are declared as friend functions. The warning should only be
suppressed for comparison operators that are class members.

Fixes #116270
---
 clang/lib/Sema/SemaDeclCXX.cpp   |  2 +-
 clang/test/SemaCXX/warn-unused-private-field.cpp | 11 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 26041e53de5061..e115eb0a3d7e10 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7535,7 +7535,7 @@ void Sema::CheckExplicitlyDefaultedFunction(Scope *S, 
FunctionDecl *FD) {
 return;
   }
 
-  if (DefKind.isComparison())
+  if (DefKind.isComparison() && isa(FD->getDeclContext()))
 UnusedPrivateFields.clear();
 
   if (DefKind.isSpecialMember()
diff --git a/clang/test/SemaCXX/warn-unused-private-field.cpp 
b/clang/test/SemaCXX/warn-unused-private-field.cpp
index 1128eacc309d9f..bdd66807dca35f 100644
--- a/clang/test/SemaCXX/warn-unused-private-field.cpp
+++ b/clang/test/SemaCXX/warn-unused-private-field.cpp
@@ -20,6 +20,17 @@ class SpaceShipDefaultCompare {
   int operator<=>(const SpaceShipDefaultCompare &) const = default;
 };
 
+class UnusedConstPrivateField {
+ public:
+  UnusedConstPrivateField() : unused_(0) {}
+ private:
+  const int unused_; // expected-warning{{private field 'unused_' is not used}}
+};
+
+class FriendEqDefaultCompare {
+  friend auto operator==(FriendEqDefaultCompare, FriendEqDefaultCompare) -> 
bool = default;
+};
+
 #endif
 
 class NotFullyDefined {

>From 935aa2edb4596f944d1477638b3654a94aad711e Mon Sep 17 00:00:00 2001
From: Chris White 
Date: Wed, 20 Nov 2024 18:34:52 +
Subject: [PATCH 2/3] Address review comments

---
 clang/lib/Sema/SemaDeclCXX.cpp   | 11 +--
 clang/test/SemaCXX/warn-unused-private-field.cpp | 13 -
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e115eb0a3d7e10..ccc2d5304058a3 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7535,8 +7535,15 @@ void Sema::CheckExplicitlyDefaultedFunction(Scope *S, 
FunctionDecl *FD) {
 return;
   }
 
-  if (DefKind.isComparison() && isa(FD->getDeclContext()))
-UnusedPrivateFields.clear();
+  if (DefKind.isComparison()) {
+auto PT = FD->getParamDecl(0)->getType();
+if (const CXXRecordDecl *RD =
+PT.getNonReferenceType()->getAsCXXRecordDecl()) {
+  for (FieldDecl *Field : RD->fields()) {
+UnusedPrivateFields.remove(Field);
+  }
+}
+  }
 
   if (DefKind.isSpecialMember()
   ? CheckExplicitlyDefaultedSpecialMember(cast(FD),
diff --git a/clang/test/SemaCXX/warn-unused-private-field.cpp 
b/clang/test/SemaCXX/warn-unused-private-field.cpp
index bdd66807dca35f..717b1864272140 100644
--- a/clang/test/SemaCXX/warn-unused-private-field.cpp
+++ b/clang/test/SemaCXX/warn-unused-private-field.cpp
@@ -20,17 +20,20 @@ class SpaceShipDefaultCompare {
   int operator<=>(const SpaceShipDefaultCompare &) const = default;
 };
 
-class UnusedConstPrivateField {
- public:
-  UnusedConstPrivateField() : unused_(0) {}
- private:
-  const int unused_; // expected-warning{{private field 'unused_' is not used}}
+class HasUnusedField {
+  int unused_; // expected-warning{{private field 'unused_' is not used}}
 };
 
 class FriendEqDefaultCompare {
+  int used;
   friend auto operator==(FriendEqDefaultCompare, FriendEqDefaultCompare) -> 
bool = default;
 };
 
+class UnrelatedFriendEqDefaultCompare {
+  friend auto operator==(UnrelatedFriendEqDefaultCompare, 
UnrelatedFriendEqDefaultCompare) -> bool = default;
+  int operator<=>(const UnrelatedFriendEqDefaultCompare &) const = default;
+};
+
 #endif
 
 class NotFullyDefined {

>From 63a93bad10008eeff2f461b94686a6ddf06f0674 Mon Sep 17 00:00:00 2001
From: Chris White 
Date: Sat, 23 Nov 2024 14:55:47 +
Subject: [PATCH 3/3] Update release notes

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bd06fadfdc984..188681f99ee5c5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -583,6 +583,20 @@ Improvements to Clang's diagnostics
 - For an rvalue reference bound to a temporary struct with an integer member, 
Clang will detect constant integer overflow
   in the initializer for the integer member (#GH46755).
 
+- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings 
when an unrelated class 
+  defined

[clang] [clang][AArch64] Avoid a crash when a non-reserved register is used (PR #117419)

2024-11-23 Thread Daniel Kiss via cfe-commits


@@ -232,13 +232,23 @@ bool AArch64TargetInfo::validateTarget(DiagnosticsEngine 
&Diags) const {
 
 bool AArch64TargetInfo::validateGlobalRegisterVariable(
 StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const {
-  if ((RegName == "sp") || RegName.starts_with("x")) {
-HasSizeMismatch = RegSize != 64;
-return true;
-  } else if (RegName.starts_with("w")) {
+  if (RegName.starts_with("w")) {
 HasSizeMismatch = RegSize != 32;
 return true;
   }
+  if (RegName == "sp") {
+HasSizeMismatch = RegSize != 64;
+return true;
+  }
+  if (RegName.starts_with("x")) {
+HasSizeMismatch = RegSize != 64;
+// Check if the register is reserved. See also
+// AArch64TargetLowering::getRegisterByName().
+return RegName == "x0" ||

DanielKristofKiss wrote:

maybe add a test case for x0 too?

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


[clang] [Clang] Fix -Wunused-private-field false negative with defaulted comparison operators (PR #116871)

2024-11-23 Thread Chris White via cfe-commits

whiteio wrote:

Thanks for that @Maetveis! I've updated the release notes.

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


[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #117437)

2024-11-23 Thread via cfe-commits

https://github.com/yronglin created 
https://github.com/llvm/llvm-project/pull/117437

Clang now support the following:

- Extending lifetime of object bound to reference members of aggregates, that 
are created from default member initializer.
- Rebuild all sub-expressions in CXXDefaultArgExpr and CXXDefaultInitExpr as 
needed.

But CFG and ExprEngine need to be updated to address this change.

This PR reapply https://github.com/llvm/llvm-project/pull/91879.

- Introduce a new flag `HasRebuiltInit` flag in `CXXDefaultInitExpr` and 
`CXXDefaultArgExpr`.
- Fixes https://github.com/llvm/llvm-project/issues/93725.

>From 75b4765da0b4ebb008781b393181c5b080be2578 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Fri, 22 Nov 2024 21:06:58 +0800
Subject: [PATCH] [Analyzer][CFG] Correctly handle rebuilt default arg and
 default init expression

Signed-off-by: yronglin 
---
 clang/include/clang/AST/ExprCXX.h | 30 +++---
 clang/include/clang/AST/Stmt.h| 13 -
 clang/lib/AST/ASTImporter.cpp |  7 ++-
 clang/lib/AST/ExprCXX.cpp | 43 +++---
 clang/lib/AST/ParentMap.cpp   | 17 ++
 clang/lib/Analysis/CFG.cpp| 50 ++---
 clang/lib/Analysis/ReachableCode.cpp  | 31 +-
 clang/lib/Sema/SemaExpr.cpp   |  9 ++-
 clang/lib/Sema/TreeTransform.h|  7 ++-
 clang/lib/Serialization/ASTReaderStmt.cpp |  8 ++-
 clang/lib/Serialization/ASTWriterStmt.cpp |  2 +
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  | 56 +++
 .../Analysis/lifetime-extended-regions.cpp|  7 +--
 clang/test/SemaCXX/warn-unreachable.cpp   | 39 +
 14 files changed, 229 insertions(+), 90 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 696a574833dad2..99680537a3f777 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1277,7 +1277,8 @@ class CXXDefaultArgExpr final
   DeclContext *UsedContext;
 
   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
-Expr *RewrittenExpr, DeclContext *UsedContext)
+DeclContext *UsedContext, Expr *RewrittenExpr,
+bool HasRebuiltInit)
   : Expr(SC,
  Param->hasUnparsedDefaultArg()
  ? Param->getType().getNonReferenceType()
@@ -1287,25 +1288,27 @@ class CXXDefaultArgExpr final
 Param(Param), UsedContext(UsedContext) {
 CXXDefaultArgExprBits.Loc = Loc;
 CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr;
+CXXDefaultArgExprBits.HasRebuiltInit = HasRebuiltInit;
 if (RewrittenExpr)
   *getTrailingObjects() = RewrittenExpr;
 setDependence(computeDependence(this));
   }
 
-  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit)
+  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit, bool 
HasRebuiltInit)
   : Expr(CXXDefaultArgExprClass, Empty) {
 CXXDefaultArgExprBits.HasRewrittenInit = HasRewrittenInit;
+CXXDefaultArgExprBits.HasRebuiltInit = HasRebuiltInit;
   }
 
 public:
   static CXXDefaultArgExpr *CreateEmpty(const ASTContext &C,
-bool HasRewrittenInit);
+bool HasRewrittenInit, bool 
HasRebuiltInit);
 
   // \p Param is the parameter whose default argument is used by this
   // expression.
   static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
-   ParmVarDecl *Param, Expr *RewrittenExpr,
-   DeclContext *UsedContext);
+   ParmVarDecl *Param, DeclContext 
*UsedContext,
+   Expr *RewrittenExpr, bool HasRebuiltInit);
   // Retrieve the parameter that the argument was created from.
   const ParmVarDecl *getParam() const { return Param; }
   ParmVarDecl *getParam() { return Param; }
@@ -1314,6 +1317,10 @@ class CXXDefaultArgExpr final
 return CXXDefaultArgExprBits.HasRewrittenInit;
   }
 
+  bool hasRebuiltInit() const {
+return CXXDefaultArgExprBits.HasRebuiltInit;
+  }
+
   // Retrieve the argument to the function call.
   Expr *getExpr();
   const Expr *getExpr() const {
@@ -1385,26 +1392,31 @@ class CXXDefaultInitExpr final
 
   CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc,
  FieldDecl *Field, QualType Ty, DeclContext *UsedContext,
- Expr *RewrittenInitExpr);
+ Expr *RewrittenInitExpr, bool HasRebuiltInit);
 
-  CXXDefaultInitExpr(EmptyShell Empty, bool HasRewrittenInit)
+  CXXDefaultInitExpr(EmptyShell Empty, bool HasRewrittenInit, bool 
HasRebuiltInit)
   : Expr(CXXDefaultInitExprClass, Empty) {
 CXXDefaultInitExprBits.HasRewrittenInit = HasRewrittenInit;
+CXXDefaultInitExprBits.HasRebuiltInit = HasRebuiltInit;
   }
 
 public:
   stat

[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #117437)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: None (yronglin)


Changes

Clang now support the following:

- Extending lifetime of object bound to reference members of aggregates, that 
are created from default member initializer.
- Rebuild all sub-expressions in CXXDefaultArgExpr and CXXDefaultInitExpr as 
needed.

But CFG and ExprEngine need to be updated to address this change.

This PR reapply https://github.com/llvm/llvm-project/pull/91879.

- Introduce a new flag `HasRebuiltInit` flag in `CXXDefaultInitExpr` and 
`CXXDefaultArgExpr`.
- Fixes https://github.com/llvm/llvm-project/issues/93725.

---

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


14 Files Affected:

- (modified) clang/include/clang/AST/ExprCXX.h (+21-9) 
- (modified) clang/include/clang/AST/Stmt.h (+11-2) 
- (modified) clang/lib/AST/ASTImporter.cpp (+4-3) 
- (modified) clang/lib/AST/ExprCXX.cpp (+24-19) 
- (modified) clang/lib/AST/ParentMap.cpp (+17) 
- (modified) clang/lib/Analysis/CFG.cpp (+41-9) 
- (modified) clang/lib/Analysis/ReachableCode.cpp (+16-15) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+7-2) 
- (modified) clang/lib/Sema/TreeTransform.h (+4-3) 
- (modified) clang/lib/Serialization/ASTReaderStmt.cpp (+6-2) 
- (modified) clang/lib/Serialization/ASTWriterStmt.cpp (+2) 
- (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+34-22) 
- (modified) clang/test/Analysis/lifetime-extended-regions.cpp (+3-4) 
- (modified) clang/test/SemaCXX/warn-unreachable.cpp (+39) 


``diff
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 696a574833dad2..99680537a3f777 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1277,7 +1277,8 @@ class CXXDefaultArgExpr final
   DeclContext *UsedContext;
 
   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
-Expr *RewrittenExpr, DeclContext *UsedContext)
+DeclContext *UsedContext, Expr *RewrittenExpr,
+bool HasRebuiltInit)
   : Expr(SC,
  Param->hasUnparsedDefaultArg()
  ? Param->getType().getNonReferenceType()
@@ -1287,25 +1288,27 @@ class CXXDefaultArgExpr final
 Param(Param), UsedContext(UsedContext) {
 CXXDefaultArgExprBits.Loc = Loc;
 CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr;
+CXXDefaultArgExprBits.HasRebuiltInit = HasRebuiltInit;
 if (RewrittenExpr)
   *getTrailingObjects() = RewrittenExpr;
 setDependence(computeDependence(this));
   }
 
-  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit)
+  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit, bool 
HasRebuiltInit)
   : Expr(CXXDefaultArgExprClass, Empty) {
 CXXDefaultArgExprBits.HasRewrittenInit = HasRewrittenInit;
+CXXDefaultArgExprBits.HasRebuiltInit = HasRebuiltInit;
   }
 
 public:
   static CXXDefaultArgExpr *CreateEmpty(const ASTContext &C,
-bool HasRewrittenInit);
+bool HasRewrittenInit, bool 
HasRebuiltInit);
 
   // \p Param is the parameter whose default argument is used by this
   // expression.
   static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
-   ParmVarDecl *Param, Expr *RewrittenExpr,
-   DeclContext *UsedContext);
+   ParmVarDecl *Param, DeclContext 
*UsedContext,
+   Expr *RewrittenExpr, bool HasRebuiltInit);
   // Retrieve the parameter that the argument was created from.
   const ParmVarDecl *getParam() const { return Param; }
   ParmVarDecl *getParam() { return Param; }
@@ -1314,6 +1317,10 @@ class CXXDefaultArgExpr final
 return CXXDefaultArgExprBits.HasRewrittenInit;
   }
 
+  bool hasRebuiltInit() const {
+return CXXDefaultArgExprBits.HasRebuiltInit;
+  }
+
   // Retrieve the argument to the function call.
   Expr *getExpr();
   const Expr *getExpr() const {
@@ -1385,26 +1392,31 @@ class CXXDefaultInitExpr final
 
   CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc,
  FieldDecl *Field, QualType Ty, DeclContext *UsedContext,
- Expr *RewrittenInitExpr);
+ Expr *RewrittenInitExpr, bool HasRebuiltInit);
 
-  CXXDefaultInitExpr(EmptyShell Empty, bool HasRewrittenInit)
+  CXXDefaultInitExpr(EmptyShell Empty, bool HasRewrittenInit, bool 
HasRebuiltInit)
   : Expr(CXXDefaultInitExprClass, Empty) {
 CXXDefaultInitExprBits.HasRewrittenInit = HasRewrittenInit;
+CXXDefaultInitExprBits.HasRebuiltInit = HasRebuiltInit;
   }
 
 public:
   static CXXDefaultInitExpr *CreateEmpty(const ASTContext &C,
- bool HasRewrittenInit);
+ bool HasRewrittenInit, bool 
HasRebuiltIni

[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #117437)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (yronglin)


Changes

Clang now support the following:

- Extending lifetime of object bound to reference members of aggregates, that 
are created from default member initializer.
- Rebuild all sub-expressions in CXXDefaultArgExpr and CXXDefaultInitExpr as 
needed.

But CFG and ExprEngine need to be updated to address this change.

This PR reapply https://github.com/llvm/llvm-project/pull/91879.

- Introduce a new flag `HasRebuiltInit` flag in `CXXDefaultInitExpr` and 
`CXXDefaultArgExpr`.
- Fixes https://github.com/llvm/llvm-project/issues/93725.

---

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


14 Files Affected:

- (modified) clang/include/clang/AST/ExprCXX.h (+21-9) 
- (modified) clang/include/clang/AST/Stmt.h (+11-2) 
- (modified) clang/lib/AST/ASTImporter.cpp (+4-3) 
- (modified) clang/lib/AST/ExprCXX.cpp (+24-19) 
- (modified) clang/lib/AST/ParentMap.cpp (+17) 
- (modified) clang/lib/Analysis/CFG.cpp (+41-9) 
- (modified) clang/lib/Analysis/ReachableCode.cpp (+16-15) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+7-2) 
- (modified) clang/lib/Sema/TreeTransform.h (+4-3) 
- (modified) clang/lib/Serialization/ASTReaderStmt.cpp (+6-2) 
- (modified) clang/lib/Serialization/ASTWriterStmt.cpp (+2) 
- (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+34-22) 
- (modified) clang/test/Analysis/lifetime-extended-regions.cpp (+3-4) 
- (modified) clang/test/SemaCXX/warn-unreachable.cpp (+39) 


``diff
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 696a574833dad2..99680537a3f777 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1277,7 +1277,8 @@ class CXXDefaultArgExpr final
   DeclContext *UsedContext;
 
   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
-Expr *RewrittenExpr, DeclContext *UsedContext)
+DeclContext *UsedContext, Expr *RewrittenExpr,
+bool HasRebuiltInit)
   : Expr(SC,
  Param->hasUnparsedDefaultArg()
  ? Param->getType().getNonReferenceType()
@@ -1287,25 +1288,27 @@ class CXXDefaultArgExpr final
 Param(Param), UsedContext(UsedContext) {
 CXXDefaultArgExprBits.Loc = Loc;
 CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr;
+CXXDefaultArgExprBits.HasRebuiltInit = HasRebuiltInit;
 if (RewrittenExpr)
   *getTrailingObjects() = RewrittenExpr;
 setDependence(computeDependence(this));
   }
 
-  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit)
+  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit, bool 
HasRebuiltInit)
   : Expr(CXXDefaultArgExprClass, Empty) {
 CXXDefaultArgExprBits.HasRewrittenInit = HasRewrittenInit;
+CXXDefaultArgExprBits.HasRebuiltInit = HasRebuiltInit;
   }
 
 public:
   static CXXDefaultArgExpr *CreateEmpty(const ASTContext &C,
-bool HasRewrittenInit);
+bool HasRewrittenInit, bool 
HasRebuiltInit);
 
   // \p Param is the parameter whose default argument is used by this
   // expression.
   static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
-   ParmVarDecl *Param, Expr *RewrittenExpr,
-   DeclContext *UsedContext);
+   ParmVarDecl *Param, DeclContext 
*UsedContext,
+   Expr *RewrittenExpr, bool HasRebuiltInit);
   // Retrieve the parameter that the argument was created from.
   const ParmVarDecl *getParam() const { return Param; }
   ParmVarDecl *getParam() { return Param; }
@@ -1314,6 +1317,10 @@ class CXXDefaultArgExpr final
 return CXXDefaultArgExprBits.HasRewrittenInit;
   }
 
+  bool hasRebuiltInit() const {
+return CXXDefaultArgExprBits.HasRebuiltInit;
+  }
+
   // Retrieve the argument to the function call.
   Expr *getExpr();
   const Expr *getExpr() const {
@@ -1385,26 +1392,31 @@ class CXXDefaultInitExpr final
 
   CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc,
  FieldDecl *Field, QualType Ty, DeclContext *UsedContext,
- Expr *RewrittenInitExpr);
+ Expr *RewrittenInitExpr, bool HasRebuiltInit);
 
-  CXXDefaultInitExpr(EmptyShell Empty, bool HasRewrittenInit)
+  CXXDefaultInitExpr(EmptyShell Empty, bool HasRewrittenInit, bool 
HasRebuiltInit)
   : Expr(CXXDefaultInitExprClass, Empty) {
 CXXDefaultInitExprBits.HasRewrittenInit = HasRewrittenInit;
+CXXDefaultInitExprBits.HasRebuiltInit = HasRebuiltInit;
   }
 
 public:
   static CXXDefaultInitExpr *CreateEmpty(const ASTContext &C,
- bool HasRewrittenInit);
+ bool HasRewrittenInit, bool 
HasRebuiltInit);
   /

[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #117437)

2024-11-23 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff aa2d084f9a68f041a42e4df84e11d769a7be34a6 
75b4765da0b4ebb008781b393181c5b080be2578 --extensions h,cpp -- 
clang/include/clang/AST/ExprCXX.h clang/include/clang/AST/Stmt.h 
clang/lib/AST/ASTImporter.cpp clang/lib/AST/ExprCXX.cpp 
clang/lib/AST/ParentMap.cpp clang/lib/Analysis/CFG.cpp 
clang/lib/Analysis/ReachableCode.cpp clang/lib/Sema/SemaExpr.cpp 
clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTReaderStmt.cpp 
clang/lib/Serialization/ASTWriterStmt.cpp 
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
clang/test/Analysis/lifetime-extended-regions.cpp 
clang/test/SemaCXX/warn-unreachable.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 99680537a3..b44a1604d0 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1294,15 +1294,16 @@ class CXXDefaultArgExpr final
 setDependence(computeDependence(this));
   }
 
-  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit, bool 
HasRebuiltInit)
+  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit,
+bool HasRebuiltInit)
   : Expr(CXXDefaultArgExprClass, Empty) {
 CXXDefaultArgExprBits.HasRewrittenInit = HasRewrittenInit;
 CXXDefaultArgExprBits.HasRebuiltInit = HasRebuiltInit;
   }
 
 public:
-  static CXXDefaultArgExpr *CreateEmpty(const ASTContext &C,
-bool HasRewrittenInit, bool 
HasRebuiltInit);
+  static CXXDefaultArgExpr *
+  CreateEmpty(const ASTContext &C, bool HasRewrittenInit, bool HasRebuiltInit);
 
   // \p Param is the parameter whose default argument is used by this
   // expression.
@@ -1317,9 +1318,7 @@ public:
 return CXXDefaultArgExprBits.HasRewrittenInit;
   }
 
-  bool hasRebuiltInit() const {
-return CXXDefaultArgExprBits.HasRebuiltInit;
-  }
+  bool hasRebuiltInit() const { return CXXDefaultArgExprBits.HasRebuiltInit; }
 
   // Retrieve the argument to the function call.
   Expr *getExpr();
@@ -1394,28 +1393,28 @@ class CXXDefaultInitExpr final
  FieldDecl *Field, QualType Ty, DeclContext *UsedContext,
  Expr *RewrittenInitExpr, bool HasRebuiltInit);
 
-  CXXDefaultInitExpr(EmptyShell Empty, bool HasRewrittenInit, bool 
HasRebuiltInit)
+  CXXDefaultInitExpr(EmptyShell Empty, bool HasRewrittenInit,
+ bool HasRebuiltInit)
   : Expr(CXXDefaultInitExprClass, Empty) {
 CXXDefaultInitExprBits.HasRewrittenInit = HasRewrittenInit;
 CXXDefaultInitExprBits.HasRebuiltInit = HasRebuiltInit;
   }
 
 public:
-  static CXXDefaultInitExpr *CreateEmpty(const ASTContext &C,
- bool HasRewrittenInit, bool 
HasRebuiltInit);
+  static CXXDefaultInitExpr *
+  CreateEmpty(const ASTContext &C, bool HasRewrittenInit, bool HasRebuiltInit);
   /// \p Field is the non-static data member whose default initializer is used
   /// by this expression.
   static CXXDefaultInitExpr *Create(const ASTContext &Ctx, SourceLocation Loc,
 FieldDecl *Field, DeclContext *UsedContext,
-Expr *RewrittenInitExpr, bool 
HasRebuiltInit);
+Expr *RewrittenInitExpr,
+bool HasRebuiltInit);
 
   bool hasRewrittenInit() const {
 return CXXDefaultInitExprBits.HasRewrittenInit;
   }
 
-  bool hasRebuiltInit() const {
-return CXXDefaultInitExprBits.HasRebuiltInit;
-  }
+  bool hasRebuiltInit() const { return CXXDefaultInitExprBits.HasRebuiltInit; }
 
   /// Get the field whose initializer will be used.
   FieldDecl *getField() { return Field; }
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 1b2dbcbaa0..85945d8003 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -860,7 +860,8 @@ protected:
 LLVM_PREFERRED_TYPE(bool)
 unsigned HasRewrittenInit : 1;
 
-/// Whether this CXXDefaultInitExpr fully rebuild its argument and stores 
a copy.
+/// Whether this CXXDefaultInitExpr fully rebuild its argument and stores a
+/// copy.
 LLVM_PREFERRED_TYPE(bool)
 unsigned HasRebuiltInit : 1;
 
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 6b6507d4b5..fb4951da5a 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -1046,7 +1046,8 @@ Expr *CXXDefaultArgExpr::getAdjustedRewrittenExpr() {
 CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &Ctx,
SourceLocation Loc, FieldDecl *Field,
QualType Ty, DeclContext *UsedContext,
-   Expr *RewrittenInitE

[clang] 3a31427 - [Clang] Add C++26 approved in the Poland WG21 meeting

2024-11-23 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2024-11-23T10:05:48+01:00
New Revision: 3a31427224d4fa49d7ef737b21f6027dc4928ecf

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

LOG: [Clang] Add C++26 approved in the Poland WG21 meeting

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index d59cec1b5b..da01cf6ceab59b 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -225,6 +225,32 @@ C++2c implementation status
   https://wg21.link/P0963R3";>P0963R3
   No
  
+ 
+ 
+  constexpr structured bindings
+  https://wg21.link/P2686R5";>P2686R5
+  No
+ 
+ 
+  Allowing exception throwing in constant-evaluation
+  https://wg21.link/P3068R6";>P3068R6
+  No
+ 
+ 
+  Remove Deprecated Array Comparisons from C++26
+  https://wg21.link/P2865R6";>P2865R6
+  No
+ 
+ 
+  Structured Bindings can introduce a Pack
+  https://wg21.link/P1061R10";>P1061R10
+  No
+ 
+ 
+  The Oxford variadic comma
+  https://wg21.link/P3176R1";>P3176R1
+  No
+ 
 
 
 



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


[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-11-23 Thread Chris Copeland via cfe-commits


@@ -16,7 +16,7 @@
 
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-flto=thin -c -o %t.call_thin.bc -DCALL_LIB
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-flto=thin -c -o %t.define_thin.bc -DDEFINE_LIB
-// RUN: llvm-lto2 run -o %t.lto_thin -save-temps %t.call_thin.bc 
%t.define_thin.bc \
+// RUN: llvm-lto2 run --mcpu=cortex-m33 --float-abi=hard -o %t.lto_thin 
-save-temps %t.call_thin.bc %t.define_thin.bc \

chrisnc wrote:

To test this theory, I had the error output the function name just like the 
nearby check for thumb does, and this is what I get when running this test 
unmodified:

`The hard-float ABI is enabled for function 'llvm.lifetime.start.p0', but the 
target lacks floating-point registers.`

This means that this function was being generated during LTO itself with an 
invalid target+ABI combination. Depending on what this functions parameters 
are, that could lead to incorrect behavior, so in general, it may not be safe 
to LTO without enough features enabled to support the ABI that the compiled 
inputs use, and it is good for LLVM to complain about this rather than 
potentially emit erroneous code.

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


[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-11-23 Thread Chris Copeland via cfe-commits

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


[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-11-23 Thread Chris Copeland via cfe-commits

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


[clang] [clang][NFC] simplify the unset check in `ParseLabeledStatement` (PR #117430)

2024-11-23 Thread via cfe-commits

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


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


[clang] [AIX] Fix AIX BuildBot failure as AIX linker doesn't support version script. (PR #117342)

2024-11-23 Thread Xing Xue via cfe-commits


@@ -48,11 +48,13 @@ add_clang_library(clang-cpp
   ${_OBJECTS}
   LINK_LIBS
   ${_DEPS})
+# AIX linker does not support version script
+if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+  configure_file(simple_version_script.map.in simple_version_script.map)
 
-configure_file(simple_version_script.map.in simple_version_script.map)
-
-if (CMAKE_SYSTEM_NAME STREQUAL "Linux")

xingxue-ibm wrote:

You are right, @aaronpuchert! With commit 
https://github.com/llvm/llvm-project/commit/eaa0a21d21962280dc2c03a09152510f6162a576
 the AIX build problem is fixed already so the change in 
https://github.com/llvm/llvm-project/pull/117342 does not make sense any more. 
I created PR [Revert "[AIX] Fix AIX BuildBot failure as AIX linker doesn't 
support version script."](https://github.com/llvm/llvm-project/pull/117444).

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


[clang] Revert "[AIX] Fix AIX BuildBot failure as AIX linker doesn't support version script." (PR #117444)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Xing Xue (xingxue-ibm)


Changes

Commit 
https://github.com/llvm/llvm-project/commit/eaa0a21d21962280dc2c03a09152510f6162a576
 has fixed the build problem already so the change in llvm/llvm-project#117342 does not make sense any more. I am reverting it. 

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


1 Files Affected:

- (modified) clang/tools/clang-shlib/CMakeLists.txt (+4-6) 


``diff
diff --git a/clang/tools/clang-shlib/CMakeLists.txt 
b/clang/tools/clang-shlib/CMakeLists.txt
index 2d97347ea7f828..31484ec49c7739 100644
--- a/clang/tools/clang-shlib/CMakeLists.txt
+++ b/clang/tools/clang-shlib/CMakeLists.txt
@@ -48,13 +48,11 @@ add_clang_library(clang-cpp
   ${_OBJECTS}
   LINK_LIBS
   ${_DEPS})
-# AIX linker does not support version script
-if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
-  configure_file(simple_version_script.map.in simple_version_script.map)
 
-  if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
-target_link_options(clang-cpp PRIVATE 
LINKER:--version-script,${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map)
-  endif()
+configure_file(simple_version_script.map.in simple_version_script.map)
+
+if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+  target_link_options(clang-cpp PRIVATE 
LINKER:--version-script,${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map)
 endif()
 
 # Optimize function calls for default visibility definitions to avoid PLT and

``




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


[clang] Revert "[AIX] Fix AIX BuildBot failure as AIX linker doesn't support version script." (PR #117444)

2024-11-23 Thread Xing Xue via cfe-commits

https://github.com/xingxue-ibm created 
https://github.com/llvm/llvm-project/pull/117444

Commit 
https://github.com/llvm/llvm-project/commit/eaa0a21d21962280dc2c03a09152510f6162a576
 has fixed the build problem already so the change in llvm/llvm-project#117342 
does not make sense any more. I am reverting it. 

>From d0e6539d49cdeeb617b75dcceacf6287a0a8178e Mon Sep 17 00:00:00 2001
From: Xing Xue 
Date: Sat, 23 Nov 2024 12:09:28 -0500
Subject: [PATCH] =?UTF-8?q?Revert=20"[AIX]=20Fix=20AIX=20BuildBot=20failur?=
 =?UTF-8?q?e=20as=20AIX=20linker=20doesn't=20support=20version=20=E2=80=A6?=
 =?UTF-8?q?"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit b71038a69ee95f5dd740f99a1cb7aefde0859562.
---
 clang/tools/clang-shlib/CMakeLists.txt | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/clang/tools/clang-shlib/CMakeLists.txt 
b/clang/tools/clang-shlib/CMakeLists.txt
index 2d97347ea7f828..31484ec49c7739 100644
--- a/clang/tools/clang-shlib/CMakeLists.txt
+++ b/clang/tools/clang-shlib/CMakeLists.txt
@@ -48,13 +48,11 @@ add_clang_library(clang-cpp
   ${_OBJECTS}
   LINK_LIBS
   ${_DEPS})
-# AIX linker does not support version script
-if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
-  configure_file(simple_version_script.map.in simple_version_script.map)
 
-  if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
-target_link_options(clang-cpp PRIVATE 
LINKER:--version-script,${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map)
-  endif()
+configure_file(simple_version_script.map.in simple_version_script.map)
+
+if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+  target_link_options(clang-cpp PRIVATE 
LINKER:--version-script,${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map)
 endif()
 
 # Optimize function calls for default visibility definitions to avoid PLT and

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


[clang] [HLSL] Add ByteAddressBuffer definition to HLSLExternalSemaSource #113477 (PR #116699)

2024-11-23 Thread via cfe-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/116699

>From 7210fcc7de181be6cad451ce1e885498c90c55fe Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Sat, 9 Nov 2024 01:34:16 +
Subject: [PATCH 01/13] adding definition

---
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 10 +
 .../test/AST/HLSL/ByteAddressBuffer-AST.hlsl  | 41 +++
 2 files changed, 51 insertions(+)
 create mode 100644 clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl

diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 822202fd81dc89..100d5be5516767 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -710,6 +710,16 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
 .addArraySubscriptOperators()
 .completeDefinition();
   });
+
+  Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ByteAddressBuffer")
+ .Record;
+  onCompletion(Decl, [this](CXXRecordDecl *Decl) {
+setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, 
ResourceKind::RawBuffer,
+/*IsROV=*/true,
+/*RawBuffer=*/true)
+.addArraySubscriptOperators()
+.completeDefinition();
+  });
 }
 
 void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record,
diff --git a/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl 
b/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl
new file mode 100644
index 00..013974369d033a
--- /dev/null
+++ b/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump 
-DEMPTY %s | FileCheck -check-prefix=EMPTY %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump %s 
| FileCheck %s
+
+
+// EMPTY: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit  class ByteAddressBuffer
+// EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+
+// There should be no more occurrences of ByteAddressBuffer
+// EMPTY-NOT: {{[^[:alnum:]]}}ByteAddressBuffer
+
+#ifndef EMPTY
+
+ByteAddressBuffer Buffer;
+
+#endif
+
+// CHECK: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit referenced  class ByteAddressBuffer 
definition
+
+
+// CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit h '__hlsl_resource_t
+// CHECK-SAME{LITERAL}: [[hlsl::resource_class(UAV)]]
+// CHECK-SAME{LITERAL}: [[hlsl::raw_buffer]]
+// CHECK-SAME{LITERAL}: [[hlsl::contained_type(char8_t)]]
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
RawBuffer
+
+// CHECK: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  
operator[] 'char8_t &const (unsigned int) const'
+// CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <>  
Idx 'unsigned int'
+// CHECK-NEXT: CompoundStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: ReturnStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: MemberExpr 0x{{[0-9A-Fa-f]+}} <> 'char8_t' lvalue 
.e 0x{{[0-9A-Fa-f]+}}
+// CHECK-NEXT: CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 'const 
hlsl::ByteAddressBuffer' lvalue implicit this
+// CHECK-NEXT: AlwaysInlineAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
always_inline
+
+// CHECK-NEXT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  operator[] 'char8_t &(unsigned int)'
+// CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <>  
Idx 'unsigned int'
+// CHECK-NEXT: CompoundStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: ReturnStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: MemberExpr 0x{{[0-9A-Fa-f]+}} <> 'char8_t' lvalue 
.e 0x{{[0-9A-Fa-f]+}}
+// CHECK-NEXT: CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 
'hlsl::ByteAddressBuffer' lvalue implicit this
+// CHECK-NEXT: AlwaysInlineAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
always_inline

>From b1f6a9468e01619d38ae3c5283381c566c130108 Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Mon, 18 Nov 2024 21:11:47 +
Subject: [PATCH 02/13] adding tests

---
 clang/test/AST/HLSL/ByteAddressBuffer-AST.ll| 13 +
 .../CodeGenHLSL/builtins/ByteAddressBuffer.hlsl |  8 
 2 files changed, 21 insertions(+)
 create mode 100644 clang/test/AST/HLSL/ByteAddressBuffer-AST.ll
 create mode 100644 clang/test/CodeGenHLSL/builtins/ByteAddressBuffer.hlsl

diff --git a/clang/test/AST/HLSL/ByteAddressBuffer-AST.ll 
b/clang/test/AST/HLSL/ByteAddressBuffer-AST.ll
new file mode 100644
index 00..7df06100d69fe5
--- /dev/null
+++ b/clang/test/AST/HLSL/ByteAddressBuffer-AST.ll
@@ -0,0 +1,13 @@
+; ModuleID = 
'/workspace/llvm-project/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl'
+source_filename = 
"/workspace/llvm-project/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl"
+target datalayout = 
"e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
+target triple = "dxilv1.0-pc-shadermodel6.0-library"
+
+!llvm.module.flags = !{!0, !1}
+!dx.valver = !{!2}
+!llvm.ident = !{!3}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 4, !"dx.disable_optimizations", i32 1}
+!2 = !{i32 1, i32 8}
+!3 = !{!"clang v

[clang] [HLSL] Add ByteAddressBuffer definition to HLSLExternalSemaSource #113477 (PR #116699)

2024-11-23 Thread via cfe-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/116699

>From 7210fcc7de181be6cad451ce1e885498c90c55fe Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Sat, 9 Nov 2024 01:34:16 +
Subject: [PATCH 01/13] adding definition

---
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 10 +
 .../test/AST/HLSL/ByteAddressBuffer-AST.hlsl  | 41 +++
 2 files changed, 51 insertions(+)
 create mode 100644 clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl

diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 822202fd81dc89..100d5be5516767 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -710,6 +710,16 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
 .addArraySubscriptOperators()
 .completeDefinition();
   });
+
+  Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ByteAddressBuffer")
+ .Record;
+  onCompletion(Decl, [this](CXXRecordDecl *Decl) {
+setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, 
ResourceKind::RawBuffer,
+/*IsROV=*/true,
+/*RawBuffer=*/true)
+.addArraySubscriptOperators()
+.completeDefinition();
+  });
 }
 
 void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record,
diff --git a/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl 
b/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl
new file mode 100644
index 00..013974369d033a
--- /dev/null
+++ b/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump 
-DEMPTY %s | FileCheck -check-prefix=EMPTY %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump %s 
| FileCheck %s
+
+
+// EMPTY: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit  class ByteAddressBuffer
+// EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+
+// There should be no more occurrences of ByteAddressBuffer
+// EMPTY-NOT: {{[^[:alnum:]]}}ByteAddressBuffer
+
+#ifndef EMPTY
+
+ByteAddressBuffer Buffer;
+
+#endif
+
+// CHECK: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit referenced  class ByteAddressBuffer 
definition
+
+
+// CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit h '__hlsl_resource_t
+// CHECK-SAME{LITERAL}: [[hlsl::resource_class(UAV)]]
+// CHECK-SAME{LITERAL}: [[hlsl::raw_buffer]]
+// CHECK-SAME{LITERAL}: [[hlsl::contained_type(char8_t)]]
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
RawBuffer
+
+// CHECK: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  
operator[] 'char8_t &const (unsigned int) const'
+// CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <>  
Idx 'unsigned int'
+// CHECK-NEXT: CompoundStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: ReturnStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: MemberExpr 0x{{[0-9A-Fa-f]+}} <> 'char8_t' lvalue 
.e 0x{{[0-9A-Fa-f]+}}
+// CHECK-NEXT: CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 'const 
hlsl::ByteAddressBuffer' lvalue implicit this
+// CHECK-NEXT: AlwaysInlineAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
always_inline
+
+// CHECK-NEXT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  operator[] 'char8_t &(unsigned int)'
+// CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <>  
Idx 'unsigned int'
+// CHECK-NEXT: CompoundStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: ReturnStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: MemberExpr 0x{{[0-9A-Fa-f]+}} <> 'char8_t' lvalue 
.e 0x{{[0-9A-Fa-f]+}}
+// CHECK-NEXT: CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 
'hlsl::ByteAddressBuffer' lvalue implicit this
+// CHECK-NEXT: AlwaysInlineAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
always_inline

>From b1f6a9468e01619d38ae3c5283381c566c130108 Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Mon, 18 Nov 2024 21:11:47 +
Subject: [PATCH 02/13] adding tests

---
 clang/test/AST/HLSL/ByteAddressBuffer-AST.ll| 13 +
 .../CodeGenHLSL/builtins/ByteAddressBuffer.hlsl |  8 
 2 files changed, 21 insertions(+)
 create mode 100644 clang/test/AST/HLSL/ByteAddressBuffer-AST.ll
 create mode 100644 clang/test/CodeGenHLSL/builtins/ByteAddressBuffer.hlsl

diff --git a/clang/test/AST/HLSL/ByteAddressBuffer-AST.ll 
b/clang/test/AST/HLSL/ByteAddressBuffer-AST.ll
new file mode 100644
index 00..7df06100d69fe5
--- /dev/null
+++ b/clang/test/AST/HLSL/ByteAddressBuffer-AST.ll
@@ -0,0 +1,13 @@
+; ModuleID = 
'/workspace/llvm-project/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl'
+source_filename = 
"/workspace/llvm-project/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl"
+target datalayout = 
"e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
+target triple = "dxilv1.0-pc-shadermodel6.0-library"
+
+!llvm.module.flags = !{!0, !1}
+!dx.valver = !{!2}
+!llvm.ident = !{!3}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 4, !"dx.disable_optimizations", i32 1}
+!2 = !{i32 1, i32 8}
+!3 = !{!"clang v

[clang] 94bde8c - [HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers (#114148)

2024-11-23 Thread via cfe-commits

Author: Helena Kotas
Date: 2024-11-23T09:33:38-08:00
New Revision: 94bde8cdc39ff7e9c59ee0cd5edda882955242aa

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

LOG: [HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers 
(#114148)

Introduces `__builtin_hlsl_buffer_update_counter` clang buildin that is
used to implement the `IncrementCounter` and `DecrementCounter` methods
on `RWStructuredBuffer` and `RasterizerOrderedStructuredBuffer` (see
Note).

The builtin is translated to LLVM intrisic `llvm.dx.bufferUpdateCounter`
or `llvm.spv.bufferUpdateCounter`.

Introduces `BuiltinTypeMethodBuilder` helper in `HLSLExternalSemaSource`
that enables adding methods to builtin types using builder pattern like
this:
```
   BuiltinTypeMethodBuilder(Sema, RecordBuilder, "MethodName", ReturnType)
   .addParam("param_name", Type, InOutModifier)
   .callBuiltin("buildin_name", { BuiltinParams })
   .finalizeMethod();
```

Fixes #113513

Added: 
clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-lib.hlsl
clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-ps.hlsl
clang/test/SemaHLSL/BuiltIns/buffer_update_counter-errors.hlsl

Modified: 
clang/include/clang/Basic/Builtins.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGHLSLRuntime.h
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaHLSL.cpp
clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl
llvm/include/llvm/IR/IntrinsicsDirectX.td
llvm/include/llvm/IR/IntrinsicsSPIRV.td
llvm/lib/Target/DirectX/DXILOpLowering.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 83c90b3d6e681b..eaff744924805e 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4882,7 +4882,6 @@ def HLSLSaturate : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
-
 def HLSLSelect : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_select"];
   let Attributes = [NoThrow, Const];
@@ -4907,6 +4906,12 @@ def HLSLRadians : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLBufferUpdateCounter : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_buffer_update_counter"];
+  let Attributes = [NoThrow];
+  let Prototype = "uint32_t(...)";
+}
+
 def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_splitdouble"];
   let Attributes = [NoThrow, Const];

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eb05a6a77978af..f21b125252b063 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7287,6 +7287,8 @@ def err_typecheck_illegal_increment_decrement : Error<
   "cannot %select{decrement|increment}1 value of type %0">;
 def err_typecheck_expect_int : Error<
   "used type %0 where integer is required">;
+def err_typecheck_expect_hlsl_resource : Error<
+  "used type %0 where __hlsl_resource_t is required">;
 def err_typecheck_arithmetic_incomplete_or_sizeless_type : Error<
   "arithmetic on a pointer to %select{an incomplete|sizeless}0 type %1">;
 def err_typecheck_pointer_arith_function_type : Error<
@@ -12528,6 +12530,10 @@ def warn_attr_min_eq_max:  Warning<
 
 def err_hlsl_attribute_number_arguments_insufficient_shader_model: Error<
   "attribute %0 with %1 arguments requires shader model %2 or greater">;
+def err_hlsl_expect_arg_const_int_one_or_neg_one: Error<
+  "argument %0 must be constant integer 1 or -1">;
+def err_invalid_hlsl_resource_type: Error<
+  "invalid __hlsl_resource_t type attributes">;
 
 // Layout randomization diagnostics.
 def err_non_designated_init_used : Error<

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 8f754953d28998..cde03a92b02853 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19409,6 +19409,15 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef{Op0},
 nullptr, "hlsl.radians");
   }
+  case Builtin::BI__builtin_hlsl_buffer_update_counter: {
+Value *ResHandle = EmitScalarExpr(E->getArg(0));
+Value *Offset = EmitScalarExpr(E->getArg(1));
+Value *OffsetI8 = Builder.CreateIntCast(Offset, Int8Ty, true);
+return Builder.CreateIntrinsic(
+/*ReturnType=*/Offset->getType(),
+CGM.getHLSLRuntime().getBufferUpdateCounterIntrinsic(),
+ArrayRef{ResHandle, OffsetI8}, nullptr);
+  }
   case Builtin::BI__builtin_hlsl_elementwise_splitdouble: {
 
 assert((E->getAr

[clang] [llvm] [HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers (PR #114148)

2024-11-23 Thread Helena Kotas via cfe-commits

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


[clang] [C23] Fixed the value of BOOL_WIDTH (PR #117364)

2024-11-23 Thread Jens Gustedt via cfe-commits


@@ -1103,7 +1103,15 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far");
   Builder.defineMacro("__CHAR_BIT__", Twine(TI.getCharWidth()));
 
-  Builder.defineMacro("__BOOL_WIDTH__", Twine(TI.getBoolWidth()));
+  // The macro is specifying the number of bits in the value representation,
+  // not the number of bits in the object representation, which is what
+  // getBoolWidth() will return. For the bool/_Bool data type, there is only

gustedt wrote:

Yes, on modern architectures, `bool` and `_BitInt` should be the only integer 
types that have padding bits.

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


[clang] [llvm] Codegen changes for strict modifier with grainsize/num_tasks of taskloop construct (PR #117196)

2024-11-23 Thread CHANDRA GHALE via cfe-commits


@@ -7831,10 +7831,14 @@ void 
CodeGenFunction::EmitOMPTaskLoopBasedDirective(const OMPLoopDirective &S) {
 // grainsize clause
 Data.Schedule.setInt(/*IntVal=*/false);
 Data.Schedule.setPointer(EmitScalarExpr(Clause->getGrainsize()));
+Data.HasModifier =
+(Clause->getModifier() == OMPC_GRAINSIZE_strict) ? true : false;
   } else if (const auto *Clause = S.getSingleClause()) {
 // num_tasks clause
 Data.Schedule.setInt(/*IntVal=*/true);
 Data.Schedule.setPointer(EmitScalarExpr(Clause->getNumTasks()));
+Data.HasModifier =
+(Clause->getModifier() == OMPC_NUMTASKS_strict) ? true : false;

chandraghale wrote:

@shiltian  
We need to check which Clause is present (either GrainsizeClause or 
NumTasksClause) and handle the case where no clause is matched. Combining the 
conditions would require an extra variable to track the clause type. I suggest 
sticking with the current logic, as it is simple and clear. What do you think?

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


[clang] [clang][NFC] simplify the check for `ParseLabeledStatement` (PR #117430)

2024-11-23 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/117430

`!isInvalid && !isUsable -> !isInvalid && !(!isInvalid && !isUnset) -> isUnset`
It is more simple to understand.


>From 61d17293801b552b40e78bc1277cea1c83741e56 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 23 Nov 2024 19:51:50 +0800
Subject: [PATCH] [clang][NFC] simplify the check for `ParseLabeledStatement`

`!isInvalid && !isUsable -> !isInvalid && !(!isInvalid && !isUnset) -> isUnset`
It is more simple to understand.
---
 clang/lib/Parse/ParseStmt.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index f6d787a0c88319..cd4504630f8719 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -799,7 +799,7 @@ StmtResult Parser::ParseLabeledStatement(ParsedAttributes 
&Attrs,
   }
 
   // If we've not parsed a statement yet, parse one now.
-  if (!SubStmt.isInvalid() && !SubStmt.isUsable())
+  if (SubStmt.isUnset())
 SubStmt = ParseStatement(nullptr, StmtCtx);
 
   // Broken substmt shouldn't prevent the label from being added to the AST.

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


[clang] [clang][NFC] simplify the unset check in `ParseLabeledStatement` (PR #117430)

2024-11-23 Thread Congcong Cai via cfe-commits

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


[libcxx] [libcxxabi] [libunwind] [llvm] [libc++] Enable -Wmissing-prototypes (PR #116261)

2024-11-23 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/116261

>From e6f36baf39d1c3e2d90c3343c49771ccf1ca976c Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 14 Nov 2024 18:30:39 +0100
Subject: [PATCH] [libc++] Enable -Wmissing-prototypes

---
 libcxx/src/charconv.cpp| 5 -
 libcxx/src/filesystem/int128_builtins.cpp  | 2 ++
 libcxx/src/include/from_chars_floating_point.h | 4 ++--
 libcxx/src/legacy_pointer_safety.cpp   | 4 
 libcxxabi/src/cxa_personality.cpp  | 5 +
 libcxxabi/src/private_typeinfo.cpp | 6 ++
 libunwind/src/UnwindLevel1.c   | 1 -
 libunwind/src/libunwind_ext.h  | 1 +
 runtimes/cmake/Modules/WarningFlags.cmake  | 1 +
 9 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/libcxx/src/charconv.cpp b/libcxx/src/charconv.cpp
index 5e8cb7d97703b4..4621df05066997 100644
--- a/libcxx/src/charconv.cpp
+++ b/libcxx/src/charconv.cpp
@@ -18,9 +18,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace __itoa {
 
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-prototypes")
+// These functions exist for ABI compatibility, so we don't ever want a 
declaration.
 _LIBCPP_EXPORTED_FROM_ABI char* __u32toa(uint32_t value, char* buffer) 
noexcept { return __base_10_u32(buffer, value); }
-
 _LIBCPP_EXPORTED_FROM_ABI char* __u64toa(uint64_t value, char* buffer) 
noexcept { return __base_10_u64(buffer, value); }
+_LIBCPP_DIAGNOSTIC_POP
 
 } // namespace __itoa
 
diff --git a/libcxx/src/filesystem/int128_builtins.cpp 
b/libcxx/src/filesystem/int128_builtins.cpp
index da6f39e7d78b60..e811b3e6f912db 100644
--- a/libcxx/src/filesystem/int128_builtins.cpp
+++ b/libcxx/src/filesystem/int128_builtins.cpp
@@ -16,6 +16,8 @@
 #include <__config>
 #include 
 
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-prototypes") // See the FIXME above
+
 #if _LIBCPP_HAS_INT128
 
 extern "C" __attribute__((no_sanitize("undefined"))) _LIBCPP_EXPORTED_FROM_ABI 
__int128_t
diff --git a/libcxx/src/include/from_chars_floating_point.h 
b/libcxx/src/include/from_chars_floating_point.h
index 19eeeb28fb08d2..81d2180cc94805 100644
--- a/libcxx/src/include/from_chars_floating_point.h
+++ b/libcxx/src/include/from_chars_floating_point.h
@@ -193,7 +193,7 @@ struct __exponent_result {
 // __offset, 0, false. This allows using the results unconditionally, the
 // __present is important for the scientific notation, where the value is
 // mandatory.
-__exponent_result __parse_exponent(const char* __input, size_t __n, size_t 
__offset, char __marker) {
+static __exponent_result __parse_exponent(const char* __input, size_t __n, 
size_t __offset, char __marker) {
   if (__offset + 1 < __n &&  // an exponent always 
needs at least one digit.
   std::tolower(__input[__offset]) == __marker && //
   !std::isspace(__input[__offset + 1])   // leading whitespace is 
not allowed.
@@ -213,7 +213,7 @@ __exponent_result __parse_exponent(const char* __input, 
size_t __n, size_t __off
 }
 
 // Here we do this operation as int64 to avoid overflow.
-int32_t __merge_exponents(int64_t __fractional, int64_t __exponent, int 
__max_biased_exponent) {
+static int32_t __merge_exponents(int64_t __fractional, int64_t __exponent, int 
__max_biased_exponent) {
   int64_t __sum = __fractional + __exponent;
 
   if (__sum > __max_biased_exponent)
diff --git a/libcxx/src/legacy_pointer_safety.cpp 
b/libcxx/src/legacy_pointer_safety.cpp
index a9361ca879bb58..31abc978499006 100644
--- a/libcxx/src/legacy_pointer_safety.cpp
+++ b/libcxx/src/legacy_pointer_safety.cpp
@@ -15,9 +15,13 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-prototypes")
+// These functions exist for ABI compatibility, so we don't ever want a 
declaration.
 _LIBCPP_EXPORTED_FROM_ABI void declare_reachable(void*) {}
 _LIBCPP_EXPORTED_FROM_ABI void declare_no_pointers(char*, size_t) {}
 _LIBCPP_EXPORTED_FROM_ABI void undeclare_no_pointers(char*, size_t) {}
 _LIBCPP_EXPORTED_FROM_ABI void* __undeclare_reachable(void* p) { return p; }
+_LIBCPP_DIAGNOSTIC_POP
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/libcxxabi/src/cxa_personality.cpp 
b/libcxxabi/src/cxa_personality.cpp
index 5f6e75c5be19ce..1836fba5ab5dd5 100644
--- a/libcxxabi/src/cxa_personality.cpp
+++ b/libcxxabi/src/cxa_personality.cpp
@@ -22,6 +22,11 @@
 #include "private_typeinfo.h"
 #include "unwind.h"
 
+// The functions defined in this file are magic functions called only by the 
compiler.
+#ifdef __clang__
+#  pragma clang diagnostic ignored "-Wmissing-prototypes"
+#endif
+
 // TODO: This is a temporary workaround for libc++abi to recognize that it's 
being
 // built against LLVM's libunwind. LLVM's libunwind started reporting 
_LIBUNWIND_VERSION
 // in LLVM 15 -- we can remove this workaround after shipping LLVM 17. Once we 
remove
diff --git a/libcxxabi/src/private_typeinfo.cpp 
b/libcxxabi/src/pr

[clang] [clang][NFC] simplify the unset check in `ParseLabeledStatement` (PR #117430)

2024-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Congcong Cai (HerrCai0907)


Changes

`!isInvalid && !isUsable -> !isInvalid && !(!isInvalid 
&& !isUnset) -> isUnset`
It is more simple to understand.


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


1 Files Affected:

- (modified) clang/lib/Parse/ParseStmt.cpp (+1-1) 


``diff
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index f6d787a0c88319..cd4504630f8719 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -799,7 +799,7 @@ StmtResult Parser::ParseLabeledStatement(ParsedAttributes 
&Attrs,
   }
 
   // If we've not parsed a statement yet, parse one now.
-  if (!SubStmt.isInvalid() && !SubStmt.isUsable())
+  if (SubStmt.isUnset())
 SubStmt = ParseStatement(nullptr, StmtCtx);
 
   // Broken substmt shouldn't prevent the label from being added to the AST.

``




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


[clang-tools-extra] Rename CODE_OWNERS -> Maintainers (PR #114544)

2024-11-23 Thread via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (PR #116033)

2024-11-23 Thread Helmut Januschka via cfe-commits

https://github.com/hjanuschka updated 
https://github.com/llvm/llvm-project/pull/116033

>From 23b4bcdf52041aad1c5581e0f7dc01028770a154 Mon Sep 17 00:00:00 2001
From: Helmut Januschka 
Date: Wed, 13 Nov 2024 12:52:36 +0100
Subject: [PATCH 01/12] [clang-tidy] Enhance modernize-use-starts-ends-with
 with substr detection

Enhances the modernize-use-starts-ends-with check to detect substr-based
patterns that can be replaced with starts_with() (C++20). This improves code
readability and efficiency by avoiding temporary string creation.

New patterns detected:
  str.substr(0, n) == "foo"   -> str.starts_with("foo")
  "foo" == str.substr(0, n)   -> str.starts_with("foo")
  str.substr(0, n) != "foo"   -> !str.starts_with("foo")
  str.substr(0, strlen("foo")) == "foo" -> str.starts_with("foo")
  str.substr(0, prefix.size()) == "foo" -> str.starts_with("foo")

The enhancement:
- Integrates with existing starts_with patterns
- Handles substr with zero first argument
- Supports length via literals, strlen(), and size()/length()
- Validates string literal length matches
- Handles both == and != operators

Part of modernize-use-starts-ends-with check.
---
 .../modernize/UseStartsEndsWithCheck.cpp  | 114 ++---
 .../modernize/UseStartsEndsWithCheck.h|   1 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +-
 .../checks/modernize/use-starts-ends-with.rst |  34 ++--
 .../clang-tidy/checkers/Inputs/Headers/string |   2 +
 .../modernize/use-starts-ends-with.cpp| 159 --
 6 files changed, 216 insertions(+), 99 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
index 1231f954298adc..12ff31dfa03541 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp
@@ -30,6 +30,17 @@ struct NotLengthExprForStringNode {
IntegerLiteralSizeNode->getValue().getZExtValue();
   }
 
+  if (const auto *DeclRefNode = Node.get()) {
+if (const auto *VD = dyn_cast(DeclRefNode->getDecl())) {
+  if (VD->hasInit() && VD->getType().isConstQualified()) {
+if (const auto *Init = dyn_cast(VD->getInit())) {
+  return StringLiteralNode->getLength() !=
+ Init->getValue().getZExtValue();
+}
+  }
+}
+  }
+
   if (const auto *StrlenNode = Node.get()) {
 if (StrlenNode->getDirectCallee()->getName() != "strlen" ||
 StrlenNode->getNumArgs() != 1) {
@@ -171,10 +182,64 @@ void UseStartsEndsWithCheck::registerMatchers(MatchFinder 
*Finder) {
  hasRHS(lengthExprForStringNode("needle")
   .bind("expr"),
   this);
+
+  Finder->addMatcher(
+  cxxOperatorCallExpr(
+  hasAnyOperatorName("==", "!="),
+  anyOf(
+  hasOperands(
+  cxxMemberCallExpr(
+  argumentCountIs(2), hasArgument(0, ZeroLiteral),
+  hasArgument(1, lengthExprForStringNode("needle")),
+  callee(
+  cxxMethodDecl(hasName("substr"),
+ofClass(OnClassWithStartsWithFunction))
+  .bind("find_fun")))
+  .bind("find_expr"),
+  expr().bind("needle")),
+  hasOperands(expr().bind("needle"),
+  cxxMemberCallExpr(
+  argumentCountIs(2), hasArgument(0, ZeroLiteral),
+  hasArgument(1, 
lengthExprForStringNode("needle")),
+  callee(cxxMethodDecl(
+ hasName("substr"),
+ 
ofClass(OnClassWithStartsWithFunction))
+ .bind("find_fun")))
+  .bind("find_expr"
+  .bind("expr"),
+  this);
+}
+
+bool UseStartsEndsWithCheck::isNegativeComparison(const Expr* ComparisonExpr) {
+  // Handle direct != operator
+  if (const auto *BO = llvm::dyn_cast(ComparisonExpr)) {
+return BO->getOpcode() == BO_NE;
+  }
+  
+  // Handle operator!= call
+  if (const auto *Op = llvm::dyn_cast(ComparisonExpr)) {
+return Op->getOperator() == OO_ExclaimEqual;
+  }
+  
+  // Handle rewritten !(expr == expr)
+  if (const auto *UO = llvm::dyn_cast(ComparisonExpr)) {
+if (UO->getOpcode() == UO_LNot) {
+  if (const auto *InnerBO = 
+  llvm::dyn_cast(UO->getSubExpr()->IgnoreParens())) {
+return InnerBO->getOpcode() == BO_EQ;
+  }
+  if (const auto *InnerOp = 
+  
llvm::dyn_cast(UO->getSubExpr()->IgnoreParens())) {
+return InnerOp->getOperator() == OO_EqualEqual;
+  }
+}
+  }
+  
+  return false;
 }
 
 void UseStartsEndsWithCheck::check(cons

[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-23 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

> > > @phoebewang and @lvwr I also noticed that there is this code in LLVM:
> > > https://github.com/llvm/llvm-project/blob/9ba6672b9f0e82a1f6d4100dc832c84447ea545c/llvm/lib/Transforms/Utils/ModuleUtils.cpp#L202-L214
> > > 
> > > . As far as I can tell, this code is not triggered when I build the Linux 
> > > kernel with `-fsanitize=kcfi`.
> > > When is this code triggered? And do you think it is necessary to 
> > > additionally implement the arity-enhancement to this code?
> > 
> > 
> > I'm not familar with KCFI. I find it's added by @samitolvanen in 
> > [e1c36bd](https://github.com/llvm/llvm-project/commit/e1c36bde0551977d4b2efae032af6dfc4b2b3936).
> >  I think you should triger it with attached test case.
> 
> It looks to me like this code might be triggered in some LTO configurations, 
> and/or when linking code compiled from multiple source languages with the 
> expectation that the KCFI type IDs will be compatible. Is my understanding 
> correct?

Looks like the latter, see 
https://github.com/llvm/llvm-project/commit/71c7313f42d2b6063fea09854cf4fc46fd0627e1

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


[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-23 Thread Phoebe Wang via cfe-commits


@@ -208,10 +209,34 @@ void llvm::setKCFIType(Module &M, Function &F, StringRef 
MangledType) {
   std::string Type = MangledType.str();
   if (M.getModuleFlag("cfi-normalize-integers"))
 Type += ".normalized";
+
+  uint32_t OutHash = static_cast(llvm::xxHash64(Type));
+  auto T = Triple(Twine(M.getTargetTriple()));

phoebewang wrote:

Like this? 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Utils/EscapeEnumerator.cpp#L24

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


[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-23 Thread Phoebe Wang via cfe-commits


@@ -208,10 +209,34 @@ void llvm::setKCFIType(Module &M, Function &F, StringRef 
MangledType) {
   std::string Type = MangledType.str();
   if (M.getModuleFlag("cfi-normalize-integers"))
 Type += ".normalized";
+
+  uint32_t OutHash = static_cast(llvm::xxHash64(Type));
+  auto T = Triple(Twine(M.getTargetTriple()));
+  if (T.isX86() && T.isArch64Bit() && T.isOSLinux()) {
+// Estimate the function's arity (i.e., the number of arguments) at the ABI
+// level by counting the number of parameters that are likely to be passed
+// as registers, such as pointers and 64-bit (or smaller) integers. The
+// Linux x86-64 ABI allows up to 6 parameters to be passed in GPRs.
+// Additional parameters or parameters larger than 64 bits may be passed on
+// the stack, in which case the arity is denoted as 7.
+size_t NumParams = F.arg_size();
+bool MayHaveStackArgs = NumParams > 6;
+
+for (unsigned int i = 0; !MayHaveStackArgs && i < NumParams; ++i) {
+  const llvm::Type *PT = F.getArg(i)->getType();
+  if (!(PT->isPointerTy() || PT->getIntegerBitWidth() <= 64))

phoebewang wrote:

Front end like Clang has solved it already. I think we can simply checking the 
number.

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


[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-23 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

> > > Second, this scheme reduces the expected number of hash collisions within 
> > > each arity, compared against the expected number of collisions 
> > > (0.01383765) for the 32-bit hashing scheme that includes all arities. The 
> > > table below shows the expected number of collisions for each arity, given 
> > > the number of unique indirect callable function types within that arity 
> > > in the same Ubuntu 24.04 server kernel discussed above.
> > 
> > 
> > The collisions vary a lot with different number of function types. It looks 
> > to me more smooth if we use 2 bits to distinguish 4 cases: 1, 2, 3 and 0 or 
> > others.
> 
> I re-ran the numbers with a 30-bit hash and 2-bit arity, and you are correct 
> that the distribution of expected collisions is more smooth:
> 
> Arity Unique Indirect Callable Function Types Number of Expected Collisions
> 0 or >3   20890.00201654
> 1 24920.00287330
> 2 37750.00660789
> 3 25470.00300181
> However, a 2-bit arity would undermine what is arguably the more desirable 
> property:
> 
> > This scheme enhances security in two ways. First, it prevents a j-arity 
> > function pointer from being used to call a k-arity function, unless j=k. 
> > The current 32-bit kCFI hash does not prevent, for example, a 2-arity fptr 
> > from calling a 3-arity target if the kCFI hashes collide. If this were to 
> > happen, then potentially malicious stale/dead data in RDX at the call site 
> > could suddenly become live as the third parameter at the call target.
> 
> For example, if the 30-bit hash of a 0-arity function type collides with the 
> 30-bit hash of the type of a 4-arity function type, then the `RDI`, `RSI`, 
> `RDX`, and `RCX` registers that die when calling a function of the 0-arity 
> type will unexpectedly become live if a COP attack redirects the call to a 
> function of the 4-arity type.
> 
> Therefore, I believe that the 29-bit hash and 3-bit arity offers a more 
> favorable security posture.

Although the default calling convention uses 6 registers, others like RegCall 
uses more. Do you want to check calling convention as well?

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


[clang] Add an off-by-default warning to complain about MSVC bitfield padding (PR #117428)

2024-11-23 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt created 
https://github.com/llvm/llvm-project/pull/117428

This just adds a warning for bitfields placed next to other bitfields where the 
underlying type has different storage. Under the MS struct bitfield packing ABI 
such bitfields are not packed.

>From 3e25d7ef2e223942298078dace8979905956d05c Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Fri, 22 Nov 2024 17:53:24 +0100
Subject: [PATCH] Add an off-by-default warning to complain about MSVC bitfield
 padding

---
 clang/include/clang/Basic/DiagnosticGroups.td |   1 +
 .../clang/Basic/DiagnosticSemaKinds.td|   6 +
 clang/lib/Sema/SemaDecl.cpp   |  27 ++-
 .../SemaCXX/ms_struct-bitfield-padding.cpp| 180 ++
 4 files changed, 212 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/ms_struct-bitfield-padding.cpp

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index df9bf94b5d0398..57bdda4b8f8b47 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -631,6 +631,7 @@ def Packed : DiagGroup<"packed", [PackedNonPod]>;
 def PaddedBitField : DiagGroup<"padded-bitfield">;
 def Padded : DiagGroup<"padded", [PaddedBitField]>;
 def UnalignedAccess : DiagGroup<"unaligned-access">;
+def MSBitfieldCompatibility : DiagGroup<"ms-bitfield-packing-compatibility">;
 
 def PessimizingMove : DiagGroup<"pessimizing-move">;
 def ReturnStdMove : DiagGroup<"return-std-move">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eb05a6a77978af..aa13e3438d3739 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6418,6 +6418,12 @@ def warn_signed_bitfield_enum_conversion : Warning<
   InGroup, DefaultIgnore;
 def note_change_bitfield_sign : Note<
   "consider making the bitfield type %select{unsigned|signed}0">;
+def warn_ms_bitfield_mismatched_storage_packing : Warning<
+  "bit-field %0 of type %1 has a different storage size (%2 vs %3 bytes) than 
the "
+  "preceding bit-field and may not be packed under MSVC ABI">,
+  InGroup, DefaultIgnore;
+def note_ms_bitfield_mismatched_storage_size_previous : Note<
+  "preceding bit-field %0 declared here with type %1">;
 
 def warn_missing_braces : Warning<
   "suggest braces around initialization of subobject">,
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 74b0e5ad23bd48..18aeca3b34f659 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19001,9 +19001,9 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, 
Decl *EnclosingDecl,
 
   // Verify that all the fields are okay.
   SmallVector RecFields;
-
+  std::optional PreviousField;
   for (ArrayRef::iterator i = Fields.begin(), end = Fields.end();
-   i != end; ++i) {
+   i != end; PreviousField = cast(*i), ++i) {
 FieldDecl *FD = cast(*i);
 
 // Get the type for the field.
@@ -19213,6 +19213,29 @@ void Sema::ActOnFields(Scope *S, SourceLocation 
RecLoc, Decl *EnclosingDecl,
 
 if (Record && FD->getType().isVolatileQualified())
   Record->setHasVolatileMember(true);
+auto IsNonDependentBitField = [](const FieldDecl *FD) {
+  if (!FD->isBitField())
+return false;
+  if (FD->getType()->isDependentType())
+return false;
+  return true;
+};
+
+if (Record && PreviousField && IsNonDependentBitField(FD) &&
+IsNonDependentBitField(*PreviousField)) {
+  unsigned FDStorageSize =
+  Context.getTypeSizeInChars(FD->getType()).getQuantity();
+  unsigned PreviousFieldStorageSize =
+  
Context.getTypeSizeInChars((*PreviousField)->getType()).getQuantity();
+  if (FDStorageSize != PreviousFieldStorageSize) {
+Diag(FD->getLocation(),
+ diag::warn_ms_bitfield_mismatched_storage_packing)
+<< FD << FD->getType() << FDStorageSize << 
PreviousFieldStorageSize;
+Diag((*PreviousField)->getLocation(),
+ diag::note_ms_bitfield_mismatched_storage_size_previous)
+<< *PreviousField << (*PreviousField)->getType();
+  }
+}
 // Keep track of the number of named members.
 if (FD->getIdentifier())
   ++NumNamedMembers;
diff --git a/clang/test/SemaCXX/ms_struct-bitfield-padding.cpp 
b/clang/test/SemaCXX/ms_struct-bitfield-padding.cpp
new file mode 100644
index 00..001086de5bbd10
--- /dev/null
+++ b/clang/test/SemaCXX/ms_struct-bitfield-padding.cpp
@@ -0,0 +1,180 @@
+
+// RUN: %clang_cc1 -fsyntax-only -Wms-bitfield-packing-compatibility -verify 
-triple armv8 -std=c++23 %s
+// RUN: %clang_cc1 -fsyntax-only -DMS_BITFIELDS -mms-bitfields 
-verify=msbitfields -triple armv8-apple-macos10.15 -std=c++23 %s
+
+// msbitfields-no-diagnostics
+
+enum Enum1 { Enum1_A, Enum1_B };
+enum Enum2 { Enum2_A, Enum2_B };
+
+enum class EnumU32_1 : unsi