[clang] 06fc7d6 - [clang][bytecode] Don't error out on incomplete declarations (#129685)

2025-03-04 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-04T12:41:34+01:00
New Revision: 06fc7d68ff816090ea8654a5a0240aa8eb6f

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

LOG: [clang][bytecode] Don't error out on incomplete declarations (#129685)

Later operations on these are invalid, but the declaration is fine, if
extern.

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/Descriptor.cpp
clang/lib/AST/ByteCode/Descriptor.h
clang/lib/AST/ByteCode/Pointer.cpp
clang/lib/AST/ByteCode/Program.cpp
clang/test/AST/ByteCode/records.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 96f67ffca43b3..394e39e99a106 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2843,6 +2843,8 @@ bool Compiler::VisitLambdaExpr(const LambdaExpr 
*E) {
 
   assert(Initializing);
   const Record *R = P.getOrCreateRecord(E->getLambdaClass());
+  if (!R)
+return false;
 
   auto *CaptureInitIt = E->capture_init_begin();
   // Initialize all fields (which represent lambda captures) of the
@@ -4087,9 +4089,8 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
 } else if (D->isRecord()) {
   if (!this->visitZeroRecordInitializer(D->ElemRecord, E))
 return false;
-} else {
-  assert(false);
-}
+} else
+  return false;
 
 if (!this->emitFinishInitPop(E))
   return false;

diff  --git a/clang/lib/AST/ByteCode/Descriptor.cpp 
b/clang/lib/AST/ByteCode/Descriptor.cpp
index bcd9f6f3d078a..0f862583a37b1 100644
--- a/clang/lib/AST/ByteCode/Descriptor.cpp
+++ b/clang/lib/AST/ByteCode/Descriptor.cpp
@@ -404,10 +404,10 @@ Descriptor::Descriptor(const DeclTy &D, const Record *R, 
MetadataSize MD,
 }
 
 /// Dummy.
-Descriptor::Descriptor(const DeclTy &D)
-: Source(D), ElemSize(1), Size(1), MDSize(0), AllocSize(MDSize),
-  ElemRecord(nullptr), IsConst(true), IsMutable(false), IsTemporary(false),
-  IsDummy(true) {
+Descriptor::Descriptor(const DeclTy &D, MetadataSize MD)
+: Source(D), ElemSize(1), Size(1), MDSize(MD.value_or(0)),
+  AllocSize(MDSize), ElemRecord(nullptr), IsConst(true), IsMutable(false),
+  IsTemporary(false), IsDummy(true) {
   assert(Source && "Missing source");
 }
 

diff  --git a/clang/lib/AST/ByteCode/Descriptor.h 
b/clang/lib/AST/ByteCode/Descriptor.h
index 8ce99731ee0ae..dfb008e4c8b8a 100644
--- a/clang/lib/AST/ByteCode/Descriptor.h
+++ b/clang/lib/AST/ByteCode/Descriptor.h
@@ -200,7 +200,7 @@ struct Descriptor final {
  bool IsTemporary, bool IsMutable);
 
   /// Allocates a dummy descriptor.
-  Descriptor(const DeclTy &D);
+  Descriptor(const DeclTy &D, MetadataSize MD = std::nullopt);
 
   /// Make this descriptor a dummy descriptor.
   void makeDummy() { IsDummy = true; }
@@ -263,7 +263,7 @@ struct Descriptor final {
   bool isUnknownSizeArray() const { return Size == UnknownSizeMark; }
 
   /// Checks if the descriptor is of a primitive.
-  bool isPrimitive() const { return !IsArray && !ElemRecord; }
+  bool isPrimitive() const { return !IsArray && !ElemRecord && !IsDummy; }
 
   /// Checks if the descriptor is of an array.
   bool isArray() const { return IsArray; }

diff  --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index e5876409edcf7..324097a95dda3 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -248,7 +248,12 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const 
{
 Index = Ptr.getIndex();
 
   QualType ElemType = Desc->getElemQualType();
-  Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
+  if (const auto *RD = ElemType->getAsRecordDecl();
+  RD && !RD->getDefinition()) {
+// Ignore this for the offset.
+  } else {
+Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
+  }
   if (Ptr.getArray().getType()->isArrayType())
 Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
   Ptr = Ptr.getArray();

diff  --git a/clang/lib/AST/ByteCode/Program.cpp 
b/clang/lib/AST/ByteCode/Program.cpp
index cc2cfc9b03b41..c33d7fd7a2dc5 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -393,6 +393,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, 
const Type *Ty,
 if (const auto *Record = getOrCreateRecord(RT->getDecl()))
   return allocateDescriptor(D, Record, MDSize, IsConst, IsTemporary,
 IsMutable);
+return allocateDescriptor(D, MDSize);
   }
 
   // Arrays.

diff  --git a/clang/test/AST/ByteCode/records.cpp 
b/clang/test/AST/ByteCode/records.cpp
index cb3d6111fd2bf..42b6d82d7190b 100644
--- a/clang/test/

[clang] 43ec9e1 - [Clang] Mark that P2280R4 was approved as a dr in the status page

2025-03-04 Thread via cfe-commits

Author: cor3ntin
Date: 2025-03-04T12:56:42+01:00
New Revision: 43ec9e18938930546e63db41ecda26d3de30e4ea

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

LOG: [Clang] Mark that P2280R4 was approved as a dr in the status page

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 2e2fecc418504..8570592101cc5 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -475,7 +475,7 @@ C++23 implementation status
 
 
   Using unknown pointers and references in constant expressions
-  https://wg21.link/P2280R4";>P2280R4
+  https://wg21.link/P2280R4";>P2280R4 (DR)
   Clang 20
 
 



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


[clang] 53d433e - [clang][bytecode] Only emit literal_comparison for string literals (#129691)

2025-03-04 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-04T14:07:53+01:00
New Revision: 53d433e702736f9edfee57ec2c1628c729336866

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

LOG: [clang][bytecode] Only emit literal_comparison for string literals 
(#129691)

This is what the current interpreter does as well.

Added: 


Modified: 
clang/lib/AST/ByteCode/Interp.h
clang/test/AST/ByteCode/builtin-functions.cpp
clang/test/AST/ByteCode/functions.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index db35208a02941..2cf7ae2dd6f96 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1065,7 +1065,8 @@ inline bool CmpHelperEQ(InterpState &S, CodePtr 
OpPC, CompareFn Fn) {
   for (const auto &P : {LHS, RHS}) {
 if (P.isZero())
   continue;
-if (BothNonNull && P.pointsToLiteral()) {
+if (BothNonNull && P.pointsToLiteral() &&
+isa(P.getDeclDesc()->asExpr())) {
   const SourceInfo &Loc = S.Current->getSource(OpPC);
   S.FFDiag(Loc, diag::note_constexpr_literal_comparison);
   return false;

diff  --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index d51b039d40043..0c26d40ec5cd5 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1008,9 +1008,9 @@ namespace shufflevector {
 
 namespace FunctionStart {
   void a(void) {}
-  static_assert(__builtin_function_start(a) == a, ""); // both-error {{not an 
integral constant expression}} \
+  static_assert(__builtin_function_start(a) == a, ""); // ref-error {{not an 
integral constant expression}} \
// ref-note 
{{comparison against opaque constant address '&__builtin_function_start(a)'}} \
-   // expected-note 
{{comparison of addresses of potentially overlapping literals has unspecified 
value}}
+   // expected-error 
{{static assertion failed}}
 }
 
 namespace BuiltinInImplicitCtor {

diff  --git a/clang/test/AST/ByteCode/functions.cpp 
b/clang/test/AST/ByteCode/functions.cpp
index 66693a1fd7e32..a7c8836eac6b8 100644
--- a/clang/test/AST/ByteCode/functions.cpp
+++ b/clang/test/AST/ByteCode/functions.cpp
@@ -484,6 +484,18 @@ namespace AddressOf {
   void testAddressof(int x) {
 static_assert(&x == __builtin_addressof(x), "");
   }
+
+  struct TS {
+constexpr bool f(TS s) const {
+  /// The addressof call has a CXXConstructExpr as a parameter.
+  return this != __builtin_addressof(s);
+}
+  };
+  constexpr bool exprAddressOf() {
+TS s;
+return s.f(s);
+  }
+  static_assert(exprAddressOf(), "");
 }
 
 namespace std {



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


[clang] 9ad5156 - A more precise matching for the driver test (#129611)

2025-03-04 Thread via cfe-commits

Author: Chris B
Date: 2025-03-04T09:09:44-06:00
New Revision: 9ad515603d97615045470fc4bdc72e1865d2986d

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

LOG: A more precise matching for the driver test (#129611)

Maybe this fixes issues detected after #128894

Added: 


Modified: 
clang/test/Driver/hip-gz-options.hip

Removed: 




diff  --git a/clang/test/Driver/hip-gz-options.hip 
b/clang/test/Driver/hip-gz-options.hip
index bdef24e052ffb..36de8e8404020 100644
--- a/clang/test/Driver/hip-gz-options.hip
+++ b/clang/test/Driver/hip-gz-options.hip
@@ -8,7 +8,7 @@
 // RUN:   -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
 // RUN:   -ggdb -gz=zlib 2>&1 | FileCheck %s
 
-// CHECK-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
-// CHECK-DAG: {{".*lld.*" .* "--compress-debug-sections=zlib"}}
-// CHECK-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
+// CHECK-DAG: {{".*clang(-[0-9]+)?(.exe)?" .* 
"--compress-debug-sections=zlib"}}
+// CHECK-DAG: {{".*lld(.exe)?" .* "--compress-debug-sections=zlib"}}
+// CHECK-DAG: {{".*clang(-[0-9]+)?(.exe)?" .* 
"--compress-debug-sections=zlib"}}
 // CHECK: "--compress-debug-sections=zlib"



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


[clang] 4c4fd6b - [clang] Fix missing diagnostic of declaration use when accessing TypeDecls through typename access (#129681)

2025-03-04 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2025-03-04T12:15:09-03:00
New Revision: 4c4fd6b03149348cf11af245ad2603d24144a9d5

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

LOG: [clang] Fix missing diagnostic of declaration use when accessing TypeDecls 
through typename access (#129681)

We were missing a call to DiagnoseUseOfDecl when performing typename
access.

This refactors the code so that TypeDecl lookups funnel through a helper
which performs all the necessary checks, removing some related
duplication on the way.

Fixes #58547

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 97b8e32f03b57..48d3eed04c823 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -35,6 +35,9 @@ Potentially Breaking Changes
 
 
 - The Objective-C ARC migrator (ARCMigrate) has been removed.
+- Fix missing diagnostics for uses of declarations when performing typename 
access,
+  such as when performing member access on a '[[deprecated]]' type alias.
+  (#GH58547)
 
 C/C++ Language Potentially Breaking Changes
 ---

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5b5cee5810488..2da5f5e311fc7 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3168,6 +3168,13 @@ class Sema final : public SemaBase {
 
   DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr);
 
+  enum class DiagCtorKind { None, Implicit, Typename };
+  /// Returns the TypeDeclType for the given type declaration,
+  /// as ASTContext::getTypeDeclType would, but
+  /// performs the required semantic checks for name lookup of said entity.
+  QualType getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,
+   TypeDecl *TD, SourceLocation NameLoc);
+
   /// If the identifier refers to a type name within this scope,
   /// return the declaration of that type.
   ///

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fe313c62ff846..36de02d91e151 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -137,6 +137,26 @@ class TypeNameValidatorCCC final : public 
CorrectionCandidateCallback {
 
 } // end anonymous namespace
 
+QualType Sema::getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,
+   TypeDecl *TD, SourceLocation NameLoc) {
+  auto *LookupRD = dyn_cast_or_null(LookupCtx);
+  auto *FoundRD = dyn_cast(TD);
+  if (DCK != DiagCtorKind::None && LookupRD && FoundRD &&
+  FoundRD->isInjectedClassName() &&
+  declaresSameEntity(LookupRD, cast(FoundRD->getParent( {
+Diag(NameLoc,
+ DCK == DiagCtorKind::Typename
+ ? diag::ext_out_of_line_qualified_id_type_names_constructor
+ : diag::err_out_of_line_qualified_id_type_names_constructor)
+<< TD->getIdentifier() << /*Type=*/1
+<< 0 /*if any keyword was present, it was 'typename'*/;
+  }
+
+  DiagnoseUseOfDecl(TD, NameLoc);
+  MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
+  return Context.getTypeDeclType(TD);
+}
+
 namespace {
 enum class UnqualifiedTypeNameLookupResult {
   NotFound,
@@ -293,10 +313,11 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, 
SourceLocation NameLoc,
  bool IsClassTemplateDeductionContext,
  ImplicitTypenameContext AllowImplicitTypename,
  IdentifierInfo **CorrectedII) {
+  bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
   // FIXME: Consider allowing this outside C++1z mode as an extension.
   bool AllowDeducedTemplate = IsClassTemplateDeductionContext &&
-  getLangOpts().CPlusPlus17 && !IsCtorOrDtorName &&
-  !isClassName && !HasTrailingDot;
+  getLangOpts().CPlusPlus17 && IsImplicitTypename 
&&
+  !HasTrailingDot;
 
   // Determine where we will perform name lookup.
   DeclContext *LookupCtx = nullptr;
@@ -320,11 +341,9 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, 
SourceLocation NameLoc,
 // refer to a member of an unknown specialization.
 // In C++2a, in several contexts a 'typename' is not required. Also
 // allow this as an extension.
-if (AllowImplicitTypename == ImplicitTypenameContext::No &&
-!isClassName && !IsCtorO

[clang] 1d8eb43 - [clang][bytecode] Diagnose member calls on inactive union fields (#129709)

2025-03-04 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-04T16:14:47+01:00
New Revision: 1d8eb436ca694a9e215066e0b2dbd18b2d3943ea

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

LOG: [clang][bytecode] Diagnose member calls on inactive union fields (#129709)

Unless the function is a constructor, which is allowed to do this since
it will activate the member.

Added: 


Modified: 
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/unions.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index bf9fdb6a690db..9f641541ad4b6 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1341,6 +1341,9 @@ bool Call(InterpState &S, CodePtr OpPC, const Function 
*Func,
 } else {
   if (!CheckInvoke(S, OpPC, ThisPtr))
 return cleanup();
+  if (!Func->isConstructor() &&
+  !CheckActive(S, OpPC, ThisPtr, AK_MemberCall))
+return false;
 }
 
 if (Func->isConstructor() && !checkConstructor(S, OpPC, Func, ThisPtr))

diff  --git a/clang/test/AST/ByteCode/unions.cpp 
b/clang/test/AST/ByteCode/unions.cpp
index 2064cae11e970..72b9b18609720 100644
--- a/clang/test/AST/ByteCode/unions.cpp
+++ b/clang/test/AST/ByteCode/unions.cpp
@@ -504,4 +504,22 @@ namespace AnonymousUnion {
   static_assert(return_init_all().a.p == 7); // both-error {{}} \
  // both-note {{read of member 'p' 
of union with no active member}}
 }
+
+namespace MemberCalls {
+  struct S {
+constexpr bool foo() const { return true; }
+  };
+
+  constexpr bool foo() { // both-error {{never produces a constant expression}}
+union {
+  int a;
+  S s;
+} u;
+
+u.a = 10;
+return u.s.foo(); // both-note 2{{member call on member 's' of union with 
active member 'a'}}
+  }
+  static_assert(foo()); // both-error {{not an integral constant expression}} \
+// both-note {{in call to}}
+}
 #endif



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


[clang] f838a5e - [clang][bytecode] Fix diagnostic difference with opaque call cmps (#129702)

2025-03-04 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-04T15:04:57+01:00
New Revision: f838a5e96cb15f3cd70b2f26db0b520004350c7e

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

LOG: [clang][bytecode] Fix diagnostic difference with opaque call cmps (#129702)

Try to dig out the call expression and diagnose this as an opaque call.

Added: 


Modified: 
clang/lib/AST/ByteCode/Interp.h
clang/test/AST/ByteCode/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 2cf7ae2dd6f96..d8f90e45b0ced 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1006,6 +1006,14 @@ inline bool CmpHelper(InterpState &S, CodePtr 
OpPC, CompareFn Fn) {
   }
 }
 
+static inline bool IsOpaqueConstantCall(const CallExpr *E) {
+  unsigned Builtin = E->getBuiltinCallee();
+  return (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
+  Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
+  Builtin == Builtin::BI__builtin_ptrauth_sign_constant ||
+  Builtin == Builtin::BI__builtin_function_start);
+}
+
 template <>
 inline bool CmpHelperEQ(InterpState &S, CodePtr OpPC, CompareFn Fn) {
   using BoolT = PrimConv::T;
@@ -1065,11 +1073,19 @@ inline bool CmpHelperEQ(InterpState &S, 
CodePtr OpPC, CompareFn Fn) {
   for (const auto &P : {LHS, RHS}) {
 if (P.isZero())
   continue;
-if (BothNonNull && P.pointsToLiteral() &&
-isa(P.getDeclDesc()->asExpr())) {
-  const SourceInfo &Loc = S.Current->getSource(OpPC);
-  S.FFDiag(Loc, diag::note_constexpr_literal_comparison);
-  return false;
+if (BothNonNull && P.pointsToLiteral()) {
+  const Expr *E = P.getDeclDesc()->asExpr();
+  if (isa(E)) {
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+S.FFDiag(Loc, diag::note_constexpr_literal_comparison);
+return false;
+  } else if (const auto *CE = dyn_cast(E);
+ CE && IsOpaqueConstantCall(CE)) {
+const SourceInfo &Loc = S.Current->getSource(OpPC);
+S.FFDiag(Loc, diag::note_constexpr_opaque_call_comparison)
+<< P.toDiagnosticString(S.getASTContext());
+return false;
+  }
 }
   }
 

diff  --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 0c26d40ec5cd5..75380f99901a2 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1008,9 +1008,8 @@ namespace shufflevector {
 
 namespace FunctionStart {
   void a(void) {}
-  static_assert(__builtin_function_start(a) == a, ""); // ref-error {{not an 
integral constant expression}} \
-   // ref-note 
{{comparison against opaque constant address '&__builtin_function_start(a)'}} \
-   // expected-error 
{{static assertion failed}}
+  static_assert(__builtin_function_start(a) == a, ""); // both-error {{not an 
integral constant expression}} \
+   // both-note 
{{comparison against opaque constant address '&__builtin_function_start(a)'}}
 }
 
 namespace BuiltinInImplicitCtor {



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


[libclc] e5d5503 - [libclc] Move hypot to CLC library; optimize (#129551)

2025-03-04 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-03-04T14:16:16Z
New Revision: e5d5503e4efa48b61194b1e70e469aba91297bec

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

LOG: [libclc] Move hypot to CLC library; optimize (#129551)

This was already nominally in the CLC library; this commit just formally
moves it over. It simultaneously optimizes it for vector types by
avoiding scalarization.

Added: 
libclc/clc/include/clc/math/clc_hypot.h
libclc/clc/lib/generic/math/clc_hypot.cl
libclc/clc/lib/generic/math/clc_hypot.inc

Modified: 
libclc/clc/lib/generic/SOURCES
libclc/clspv/lib/SOURCES
libclc/generic/lib/SOURCES
libclc/generic/lib/math/hypot.cl
libclc/spirv/lib/SOURCES

Removed: 
libclc/generic/include/math/clc_hypot.h
libclc/generic/lib/math/clc_hypot.cl



diff  --git a/libclc/clc/include/clc/math/clc_hypot.h 
b/libclc/clc/include/clc/math/clc_hypot.h
new file mode 100644
index 0..c09e89bb2f071
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_hypot.h
@@ -0,0 +1,12 @@
+#ifndef __CLC_MATH_CLC_HYPOT_H__
+#define __CLC_MATH_CLC_HYPOT_H__
+
+#define __CLC_BODY 
+#define __CLC_FUNCTION __clc_hypot
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_HYPOT_H__

diff  --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES
index 206c7c18ce1a1..f7688d0442253 100644
--- a/libclc/clc/lib/generic/SOURCES
+++ b/libclc/clc/lib/generic/SOURCES
@@ -23,6 +23,7 @@ math/clc_fabs.cl
 math/clc_fma.cl
 math/clc_floor.cl
 math/clc_frexp.cl
+math/clc_hypot.cl
 math/clc_ldexp.cl
 math/clc_log.cl
 math/clc_log10.cl

diff  --git a/libclc/clc/lib/generic/math/clc_hypot.cl 
b/libclc/clc/lib/generic/math/clc_hypot.cl
new file mode 100644
index 0..3bbe5a984efe5
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_hypot.cl
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define __CLC_BODY 
+#include 
+#undef __CLC_BODY

diff  --git a/libclc/clc/lib/generic/math/clc_hypot.inc 
b/libclc/clc/lib/generic/math/clc_hypot.inc
new file mode 100644
index 0..72a989646ff38
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc_hypot.inc
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+// Returns sqrt(x*x + y*y) with no overflow or underflow unless the result
+// warrants it
+
+#if __CLC_FPSIZE == 32
+_CLC_DEF _CLC_OVERLOAD __CLC_GENTYPE __clc_hypot(__CLC_GENTYPE x,
+

[clang] 9c542bc - [analyzer] performTrivialCopy triggers checkLocation before binding (#129016)

2025-03-04 Thread via cfe-commits

Author: T-Gruber
Date: 2025-03-04T17:00:55+01:00
New Revision: 9c542bcf0a1b243dd39c2ecffdd7331c15ae0fb1

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

LOG: [analyzer] performTrivialCopy triggers checkLocation before binding 
(#129016)

The triggered callbacks for the default copy constructed instance and
the instance used for initialization now behave in the same way. The LHS
already calls checkBind. To keep this consistent, checkLocation is now
triggered accordingly for the RHS.
Further details on the previous discussion:
https://discourse.llvm.org/t/checklocation-for-implicitcastexpr-of-kind-ck-noop/84729

-

Authored-by: tobias.gruber 

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
index f7020da2e6da2..ff4fa58857fc6 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -69,6 +69,7 @@ void ExprEngine::performTrivialCopy(NodeBuilder &Bldr, 
ExplodedNode *Pred,
 
   assert(ThisRD);
   SVal V = Call.getArgSVal(0);
+  const Expr *VExpr = Call.getArgExpr(0);
 
   // If the value being copied is not unknown, load from its location to get
   // an aggregate rvalue.
@@ -76,7 +77,12 @@ void ExprEngine::performTrivialCopy(NodeBuilder &Bldr, 
ExplodedNode *Pred,
 V = Pred->getState()->getSVal(*L);
   else
 assert(V.isUnknownOrUndef());
-  evalBind(Dst, CallExpr, Pred, ThisVal, V, true);
+
+  ExplodedNodeSet Tmp;
+  evalLocation(Tmp, CallExpr, VExpr, Pred, Pred->getState(), V,
+   /*isLoad=*/true);
+  for (ExplodedNode *N : Tmp)
+evalBind(Dst, CallExpr, N, ThisVal, V, true);
 
   PostStmt PS(CallExpr, LCtx);
   for (ExplodedNode *N : Dst) {
@@ -1199,4 +1205,4 @@ void ExprEngine::VisitLambdaExpr(const LambdaExpr *LE, 
ExplodedNode *Pred,
 
   // FIXME: Move all post/pre visits to ::Visit().
   getCheckerManager().runCheckersForPostStmt(Dst, Tmp, LE, *this);
-}
+}
\ No newline at end of file

diff  --git a/clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp 
b/clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp
index a8579f9d0f90c..b6eeb9ce37386 100644
--- a/clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp
+++ b/clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp
@@ -12,6 +12,8 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
+#include "llvm/Support/Casting.h"
 #include "gtest/gtest.h"
 
 using namespace clang;
@@ -44,6 +46,33 @@ CREATE_EXPR_ENGINE_CHECKER(ExprEngineVisitPreChecker, 
PreStmt, GCCAsmStmt,
 CREATE_EXPR_ENGINE_CHECKER(ExprEngineVisitPostChecker, PostStmt, GCCAsmStmt,
"GCCAsmStmtBug")
 
+class MemAccessChecker : public Checker {
+public:
+  void checkLocation(const SVal &Loc, bool IsLoad, const Stmt *S,
+ CheckerContext &C) const {
+emitErrorReport(C, Bug,
+"checkLocation: Loc = " + dumpToString(Loc) +
+", Stmt = " + S->getStmtClassName());
+  }
+
+  void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext &C) const {
+emitErrorReport(C, Bug,
+"checkBind: Loc = " + dumpToString(Loc) +
+", Val = " + dumpToString(Val) +
+", Stmt = " + S->getStmtClassName());
+  }
+
+private:
+  const BugType Bug{this, "MemAccess"};
+
+  std::string dumpToString(SVal V) const {
+std::string StrBuf;
+llvm::raw_string_ostream StrStream{StrBuf};
+V.dumpToStream(StrStream);
+return StrBuf;
+  }
+};
+
 void addExprEngineVisitPreChecker(AnalysisASTConsumer &AnalysisConsumer,
   AnalyzerOptions &AnOpts) {
   AnOpts.CheckersAndPackages = {{"ExprEngineVisitPreChecker", true}};
@@ -62,6 +91,15 @@ void addExprEngineVisitPostChecker(AnalysisASTConsumer 
&AnalysisConsumer,
   });
 }
 
+void addMemAccessChecker(AnalysisASTConsumer &AnalysisConsumer,
+ AnalyzerOptions &AnOpts) {
+  AnOpts.CheckersAndPackages = {{"MemAccessChecker", true}};
+  AnalysisConsumer.AddCheckerRegistrationFn([](CheckerRegistry &Registry) {
+Registry.addChecker("MemAccessChecker", "Desc",
+  "DocsURI");
+  });
+}
+
 TEST(ExprEngineVisitTest, checkPreStmtGCCAsmStmt) {
   std::string Diags;
   EXPECT_TRUE(runCheckerOnCode(R"(
@@ -84,4 +122,32 @@ TEST(ExprEngineVisitTest, checkPostStmtGCCAsmStmt) {
   EXPECT_EQ(Diags, "ExprEngineVisitPostChecker: c

[clang] aeca2aa - [clang][bytecode] Fix CallPtr return type check (#129722)

2025-03-04 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-04T17:14:13+01:00
New Revision: aeca2aa19374d7f70f6f84a99510535b854ec15a

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

LOG: [clang][bytecode] Fix CallPtr return type check (#129722)

CallExpr::getType() isn't enough here in some cases, we need to use
CallExpr::getCallReturnType().

Added: 


Modified: 
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/memberpointers.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 9f641541ad4b6..a2090f3e85e08 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1515,7 +1515,7 @@ bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t 
ArgSize,
   // This happens when the call expression has been cast to
   // something else, but we don't support that.
   if (S.Ctx.classify(F->getDecl()->getReturnType()) !=
-  S.Ctx.classify(CE->getType()))
+  S.Ctx.classify(CE->getCallReturnType(S.getASTContext(
 return false;
 
   // Check argument nullability state.

diff  --git a/clang/test/AST/ByteCode/memberpointers.cpp 
b/clang/test/AST/ByteCode/memberpointers.cpp
index ea4a725d3fd0d..db4a86ae03aff 100644
--- a/clang/test/AST/ByteCode/memberpointers.cpp
+++ b/clang/test/AST/ByteCode/memberpointers.cpp
@@ -226,3 +226,26 @@ namespace IndirectFields {
   constexpr I i{12};
   static_assert(ReadField(i) == 12, "");
 }
+
+namespace CallExprTypeMismatch {
+  /// The call expression's getType() returns just S, not S&.
+  struct S {
+constexpr S(int i_) : i(i_) {}
+constexpr const S& identity() const { return *this; }
+int i;
+  };
+
+  template
+  constexpr void Call(T t, U u) {
+((&u)->*t)();
+  }
+
+  constexpr bool test() {
+const S s{12};
+
+Call(&S::identity, s);
+
+return true;
+  }
+  static_assert(test(), "");
+}



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


[clang] cd3acd1 - [AMDGPU] Remove unused s_barrier_{init, join, leave} instructions (#129548)

2025-03-04 Thread via cfe-commits

Author: Mariusz Sikora
Date: 2025-03-04T17:52:43+01:00
New Revision: cd3acd1bff02d0100cbe74307f29c00a3874bc41

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

LOG: [AMDGPU] Remove unused s_barrier_{init,join,leave} instructions (#129548)

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-param-err.cl
clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12.cl
llvm/include/llvm/IR/IntrinsicsAMDGPU.td
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h
llvm/lib/Target/AMDGPU/AMDGPUMemoryUtils.cpp
llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
llvm/lib/Target/AMDGPU/SIInstrInfo.h
llvm/lib/Target/AMDGPU/SOPInstructions.td
llvm/test/CodeGen/AMDGPU/insert-skips-gfx12.mir
llvm/test/CodeGen/AMDGPU/s-barrier-lowering.ll
llvm/test/MC/AMDGPU/gfx12_asm_sop1.s
llvm/test/MC/AMDGPU/gfx12_asm_sopp.s
llvm/test/MC/Disassembler/AMDGPU/gfx12_dasm_sop1.txt
llvm/test/MC/Disassembler/AMDGPU/gfx12_dasm_sopp.txt

Removed: 
llvm/test/CodeGen/AMDGPU/s-barrier.ll



diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 6d00862dde5ed..44ef404aee72f 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -487,9 +487,6 @@ TARGET_BUILTIN(__builtin_amdgcn_s_barrier_signal, "vIi", 
"n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_barrier_signal_var, "vv*i", "n", 
"gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_barrier_wait, "vIs", "n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_barrier_signal_isfirst, "bIi", "n", 
"gfx12-insts")
-TARGET_BUILTIN(__builtin_amdgcn_s_barrier_init, "vv*i", "n", "gfx12-insts")
-TARGET_BUILTIN(__builtin_amdgcn_s_barrier_join, "vv*", "n", "gfx12-insts")
-TARGET_BUILTIN(__builtin_amdgcn_s_barrier_leave, "vIs", "n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_get_barrier_state, "Uii", "n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_get_named_barrier_state, "Uiv*", "n", 
"gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_prefetch_data, "vvC*Ui", "nc", "gfx12-insts")

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-param-err.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-param-err.cl
index 1a5043328895a..5d86a9b369429 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-param-err.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-param-err.cl
@@ -23,13 +23,6 @@ kernel void 
builtins_amdgcn_s_barrier_signal_isfirst_err(global int* in, global
   *out = *in;
 }
 
-kernel void builtins_amdgcn_s_barrier_leave_err(global int* in, global int* 
out, int barrier) {
-
-  __builtin_amdgcn_s_barrier_signal(-1);
-  __builtin_amdgcn_s_barrier_leave(barrier); // expected-error 
{{'__builtin_amdgcn_s_barrier_leave' must be a constant integer}}
-  *out = *in;
-}
-
 void test_s_buffer_prefetch_data(__amdgpu_buffer_rsrc_t rsrc, unsigned int off)
 {
   __builtin_amdgcn_s_buffer_prefetch_data(rsrc, off, 31); // expected-error 
{{'__builtin_amdgcn_s_buffer_prefetch_data' must be a constant integer}}

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12.cl
index 234ad4fd8cde6..2dba7fb719376 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12.cl
@@ -139,50 +139,6 @@ void test_s_barrier_signal_isfirst(int* a, int* b, int *c)
   __builtin_amdgcn_s_barrier_wait(1);
 }
 
-// CHECK-LABEL: @test_s_barrier_init(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[BAR_ADDR:%.*]] = alloca ptr, align 8, addrspace(5)
-// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4, addrspace(5)
-// CHECK-NEXT:[[BAR_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BAR_ADDR]] to ptr
-// CHECK-NEXT:[[A_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[A_ADDR]] to ptr
-// CHECK-NEXT:store ptr [[BAR:%.*]], ptr [[BAR_ADDR_ASCAST]], align 8
-// CHECK-NEXT:store i32 [[A:%.*]], ptr [[A_ADDR_ASCAST]], align 4
-// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[BAR_ADDR_ASCAST]], align 8
-// CHECK-NEXT:[[TMP1:%.*]] = addrspacecast ptr [[TMP0]] to ptr addrspace(3)
-// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[A_ADDR_ASCAST]], align 4
-// CHECK-NEXT:call void @llvm.amdgcn.s.barrier.init(ptr addrspace(3) 
[[TMP1]], i32 [[TMP2]])
-// CHECK-NEXT:ret void
-//
-void test_s_barrier_init(void *bar, int a)
-{
-  __builtin_amdgcn_s_barrier_init(bar, a);
-}
-
-// CHECK-LABEL: @test_s_barrier_join(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[BAR_ADDR:%.*]] = alloca ptr, ali

[clang] fa072bd - [CIR] Add lowering for Func, Return, Alloca, Load, and Store (#129571)

2025-03-04 Thread via cfe-commits

Author: Andy Kaylor
Date: 2025-03-04T14:50:34-08:00
New Revision: fa072bd29a109be424e6f4521823529750a55efe

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

LOG: [CIR] Add lowering for Func, Return, Alloca, Load, and Store (#129571)

Add support for lowering recently upstreamed CIR ops to LLVM IR.

Added: 
clang/test/CIR/Lowering/basic.cpp
clang/test/CIR/Lowering/func-simple.cpp

Modified: 
clang/include/clang/CIR/MissingFeatures.h
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h
clang/test/CIR/Lowering/global-var-simple.cpp

Removed: 




diff  --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 9b416ef61055e..6fbaa27bc7073 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -27,9 +27,6 @@ struct MissingFeatures {
   // Address space related
   static bool addressSpace() { return false; }
 
-  // This isn't needed until we add support for bools.
-  static bool convertTypeForMemory() { return false; }
-
   // CIRGenFunction implementation details
   static bool cgfSymbolTable() { return false; }
 
@@ -40,10 +37,14 @@ struct MissingFeatures {
   static bool opGlobalAlignment() { return false; }
   static bool opGlobalLinkage() { return false; }
 
-  // Load attributes
+  // Load/store attributes
   static bool opLoadThreadLocal() { return false; }
   static bool opLoadEmitScalarRangeCheck() { return false; }
   static bool opLoadBooleanRepresentation() { return false; }
+  static bool opLoadStoreTbaa() { return false; }
+  static bool opLoadStoreMemOrder() { return false; }
+  static bool opLoadStoreVolatile() { return false; }
+  static bool opLoadStoreAlignment() { return false; }
 
   // AllocaOp handling
   static bool opAllocaVarDeclContext() { return false; }
@@ -55,11 +56,23 @@ struct MissingFeatures {
   static bool opAllocaOpenMPThreadPrivate() { return false; }
   static bool opAllocaEscapeByReference() { return false; }
   static bool opAllocaReference() { return false; }
+  static bool opAllocaAnnotations() { return false; }
+  static bool opAllocaDynAllocSize() { return false; }
+
+  // FuncOp handling
+  static bool opFuncOpenCLKernelMetadata() { return false; }
+  static bool opFuncCallingConv() { return false; }
+  static bool opFuncExtraAttrs() { return false; }
+  static bool opFuncDsolocal() { return false; }
+  static bool opFuncLinkage() { return false; }
+  static bool opFuncVisibility() { return false; }
 
   // Misc
   static bool scalarConversionOpts() { return false; }
   static bool tryEmitAsConstant() { return false; }
   static bool constructABIArgDirectExtend() { return false; }
+  static bool opGlobalViewAttr() { return false; }
+  static bool lowerModeOptLevel() { return false; }
 };
 
 } // namespace cir

diff  --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 6f7cae8fa7fa3..f614c5d1db0c0 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -29,6 +29,7 @@
 #include "clang/CIR/Passes.h"
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/IR/Module.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/TimeProfiler.h"
 
 using namespace cir;
@@ -37,6 +38,77 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+/// Given a type convertor and a data layout, convert the given type to a type
+/// that is suitable for memory operations. For example, this can be used to
+/// lower cir.bool accesses to i8.
+static mlir::Type convertTypeForMemory(const mlir::TypeConverter &converter,
+   mlir::DataLayout const &dataLayout,
+   mlir::Type type) {
+  // TODO(cir): Handle other types similarly to clang's codegen
+  // convertTypeForMemory
+  if (isa(type)) {
+return mlir::IntegerType::get(type.getContext(),
+  dataLayout.getTypeSizeInBits(type));
+  }
+
+  return converter.convertType(type);
+}
+
+static mlir::Value createIntCast(mlir::OpBuilder &bld, mlir::Value src,
+ mlir::IntegerType dstTy,
+ bool isSigned = false) {
+  mlir::Type srcTy = src.getType();
+  assert(mlir::isa(srcTy));
+
+  unsigned srcWidth = mlir::cast(srcTy).getWidth();
+  unsigned dstWidth = mlir::cast(dstTy).getWidth();
+  mlir::Location loc = src.getLoc();
+
+  if (dstWidth > srcWidth && isSigned)
+return bld.create(loc, dstTy, src);
+  else if (dstWidth > srcWidth)
+return bld.create(loc, dstTy, src);
+  else if (dstWidth < srcWidth)
+return bld.create(loc, dstTy, src);
+  else
+  

[clang] 17bfc00 - [BPF] Add load-acquire and store-release instructions under -mcpu=v4 (#108636)

2025-03-04 Thread via cfe-commits

Author: Peilin Ye
Date: 2025-03-04T09:19:39-08:00
New Revision: 17bfc00f7c4a424d7b5dc6da575865833701fd1a

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

LOG: [BPF] Add load-acquire and store-release instructions under -mcpu=v4 
(#108636)

As discussed in [1], introduce BPF instructions with load-acquire and
store-release semantics under -mcpu=v4.  Define 2 new flags:

  BPF_LOAD_ACQ0x100
  BPF_STORE_REL   0x110

A "load-acquire" is a BPF_STX | BPF_ATOMIC instruction with the 'imm'
field set to BPF_LOAD_ACQ (0x100).

Similarly, a "store-release" is a BPF_STX | BPF_ATOMIC instruction with
the 'imm' field set to BPF_STORE_REL (0x110).

Unlike existing atomic read-modify-write operations that only support
BPF_W (32-bit) and BPF_DW (64-bit) size modifiers, load-acquires and
store-releases also support BPF_B (8-bit) and BPF_H (16-bit).  An 8- or
16-bit load-acquire zero-extends the value before writing it to a 32-bit
register, just like ARM64 instruction LDAPRH and friends.

As an example (assuming little-endian):

  long foo(long *ptr) {
  return __atomic_load_n(ptr, __ATOMIC_ACQUIRE);
  }

foo() can be compiled to:

  db 10 00 00 00 01 00 00  r0 = load_acquire((u64 *)(r1 + 0x0))
  95 00 00 00 00 00 00 00  exit

  opcode (0xdb): BPF_ATOMIC | BPF_DW | BPF_STX
  imm (0x0100): BPF_LOAD_ACQ

Similarly:

  void bar(short *ptr, short val) {
  __atomic_store_n(ptr, val, __ATOMIC_RELEASE);
  }

bar() can be compiled to:

  cb 21 00 00 10 01 00 00  store_release((u16 *)(r1 + 0x0), w2)
  95 00 00 00 00 00 00 00  exit

  opcode (0xcb): BPF_ATOMIC | BPF_H | BPF_STX
  imm (0x0110): BPF_STORE_REL

Inline assembly is also supported.

Add a pre-defined macro, __BPF_FEATURE_LOAD_ACQ_STORE_REL, to let
developers detect this new feature.  It can also be disabled using a new
llc option, -disable-load-acq-store-rel.

Using __ATOMIC_RELAXED for __atomic_store{,_n}() will generate a "plain"
store (BPF_MEM | BPF_STX) instruction:

  void foo(short *ptr, short val) {
  __atomic_store_n(ptr, val, __ATOMIC_RELAXED);
  }

  6b 21 00 00 00 00 00 00  *(u16 *)(r1 + 0x0) = w2
  95 00 00 00 00 00 00 00  exit

Similarly, using __ATOMIC_RELAXED for __atomic_load{,_n}() will generate
a zero-extending, "plain" load (BPF_MEM | BPF_LDX) instruction:

  int foo(char *ptr) {
  return __atomic_load_n(ptr, __ATOMIC_RELAXED);
  }

  71 11 00 00 00 00 00 00  w1 = *(u8 *)(r1 + 0x0)
  bc 10 08 00 00 00 00 00  w0 = (s8)w1
  95 00 00 00 00 00 00 00  exit

Currently __ATOMIC_CONSUME is an alias for __ATOMIC_ACQUIRE.  Using
__ATOMIC_SEQ_CST ("sequentially consistent") is not supported yet and
will cause an error:

  $ clang --target=bpf -mcpu=v4 -c bar.c > /dev/null
bar.c:1:5: error: sequentially consistent (seq_cst) atomic load/store is
not supported
1 | int foo(int *ptr) { return __atomic_load_n(ptr, __ATOMIC_SEQ_CST); }
  | ^
  ...

Finally, rename those isST*() and isLD*() helper functions in
BPFMISimplifyPatchable.cpp based on what the instructions actually do,
rather than their instruction class.

[1]
https://lore.kernel.org/all/20240729183246.4110549-1-yepei...@google.com/

Added: 
llvm/test/CodeGen/BPF/atomic-load-store.ll

Modified: 
clang/lib/Basic/Targets/BPF.cpp
clang/test/Preprocessor/bpf-predefined-macros.c
llvm/lib/Target/BPF/AsmParser/BPFAsmParser.cpp
llvm/lib/Target/BPF/BPFISelLowering.cpp
llvm/lib/Target/BPF/BPFISelLowering.h
llvm/lib/Target/BPF/BPFInstrFormats.td
llvm/lib/Target/BPF/BPFInstrInfo.td
llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
llvm/lib/Target/BPF/BPFSubtarget.cpp
llvm/lib/Target/BPF/BPFSubtarget.h
llvm/test/CodeGen/BPF/assembler-disassembler-v4.s

Removed: 




diff  --git a/clang/lib/Basic/Targets/BPF.cpp b/clang/lib/Basic/Targets/BPF.cpp
index a463de0884020..4b85a3645b17d 100644
--- a/clang/lib/Basic/Targets/BPF.cpp
+++ b/clang/lib/Basic/Targets/BPF.cpp
@@ -75,6 +75,7 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
 Builder.defineMacro("__BPF_FEATURE_SDIV_SMOD");
 Builder.defineMacro("__BPF_FEATURE_GOTOL");
 Builder.defineMacro("__BPF_FEATURE_ST");
+Builder.defineMacro("__BPF_FEATURE_LOAD_ACQ_STORE_REL");
   }
 }
 

diff  --git a/clang/test/Preprocessor/bpf-predefined-macros.c 
b/clang/test/Preprocessor/bpf-predefined-macros.c
index 8c2143f767c40..cd8a2ec031925 100644
--- a/clang/test/Preprocessor/bpf-predefined-macros.c
+++ b/clang/test/Preprocessor/bpf-predefined-macros.c
@@ -67,6 +67,9 @@ int t;
 #ifdef __BPF_FEATURE_MAY_GOTO
 int u;
 #endif
+#ifdef __BPF_FEATURE_LOAD_ACQ_STORE_REL
+int v;
+#endif
 
 // CHECK: int b;
 // CHECK: int c;
@@ -106,6 +109,8 @@ int u;
 // CPU_V3: int u;
 // CPU_V4: int u;
 
+// CPU_V4: int v;
+
 // CPU_GENERIC: int g;
 
 // CPU_PROBE: int f;

diff  --git a

[clang] 9e1eaff - [clang] Fix `gnu::init_priority` attribute handling for reserved values (#121577)

2025-03-04 Thread via cfe-commits

Author: Iris
Date: 2025-03-04T12:07:40-05:00
New Revision: 9e1eaff95b3284ccec71fec70eb9e286c34974c4

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

LOG: [clang] Fix `gnu::init_priority` attribute handling for reserved values 
(#121577)

- Added a new diagnostic group `InitPriorityReserved`
- Allow values within the range 0-100 of `init_priority` to be used
outside system library, but with a warning
- Updated relavant tests

Fixes #121108

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/SemaCXX/init-priority-attr.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 48d3eed04c823..37ea963bf337d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -147,6 +147,9 @@ related warnings within the method body.
   ``__attribute__((model("large")))`` on non-TLS globals in x86-64 
compilations.
   This forces the global to be considered small or large in regards to the
   x86-64 code model, regardless of the code model specified for the 
compilation.
+- Clang now emits a warning ``-Wreserved-init-priority`` instead of a hard 
error 
+  when ``__attribute__((init_priority(n)))`` is used with values of n in the 
+  reserved range [0, 100]. The warning will be treated as an error by default.
 
 - There is a new ``format_matches`` attribute to complement the existing
   ``format`` attribute. ``format_matches`` allows the compiler to verify that

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d89648a8a2e83..0b121c04cd3c0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3343,6 +3343,9 @@ def err_attribute_argument_out_of_range : Error<
 def err_init_priority_object_attr : Error<
   "can only use 'init_priority' attribute on file-scope definitions "
   "of objects of class type">;
+def warn_init_priority_reserved : Warning<
+  "requested 'init_priority' %0 is reserved for internal use">,
+  InGroup>, DefaultError;
 def err_attribute_argument_out_of_bounds : Error<
   "%0 attribute parameter %1 is out of bounds">;
 def err_attribute_only_once_per_parameter : Error<

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 5785cf5eec3c5..1405ee5341dcf 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3720,16 +3720,18 @@ static void handleInitPriorityAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 return;
   }
 
-  // Only perform the priority check if the attribute is outside of a system
-  // header. Values <= 100 are reserved for the implementation, and libc++
-  // benefits from being able to specify values in that range.
-  if ((prioritynum < 101 || prioritynum > 65535) &&
-  !S.getSourceManager().isInSystemHeader(AL.getLoc())) {
+  if (prioritynum > 65535) {
 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_range)
-<< E->getSourceRange() << AL << 101 << 65535;
+<< E->getSourceRange() << AL << 0 << 65535;
 AL.setInvalid();
 return;
   }
+
+  // Values <= 100 are reserved for the implementation, and libc++
+  // benefits from being able to specify values in that range.
+  if (prioritynum < 101)
+S.Diag(AL.getLoc(), diag::warn_init_priority_reserved)
+<< E->getSourceRange() << prioritynum;
   D->addAttr(::new (S.Context) InitPriorityAttr(S.Context, AL, prioritynum));
 }
 

diff  --git a/clang/test/SemaCXX/init-priority-attr.cpp 
b/clang/test/SemaCXX/init-priority-attr.cpp
index 8c0a17682bb02..8151bf7aecb95 100644
--- a/clang/test/SemaCXX/init-priority-attr.cpp
+++ b/clang/test/SemaCXX/init-priority-attr.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple=x86_64-unknown-unknown -fsyntax-only -verify %s
 // RUN: %clang_cc1 -triple=x86_64-unknown-unknown -fsyntax-only -DSYSTEM 
-verify %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -fsyntax-only -DNOERROR 
-Wno-error=init-priority-reserved -verify %s
 // RUN: %clang_cc1 -triple=s390x-none-zos -fsyntax-only -verify=unknown %s
 // RUN: %clang_cc1 -triple=s390x-none-zos -fsyntax-only -DSYSTEM 
-verify=unknown-system %s
 
@@ -24,24 +25,32 @@ extern Two goo;
 extern Two coo[];
 extern Two koo[];
 
+// unknown-system-no-diagnostics
+
 Two foo __attribute__((init_priority(101))) ( 5, 6 );
- // unknown-system-no-diagnostics
- // unknown-warning@-2 {{unknown attribute 'init_priority' ignored}}
+// unknown-warning@-1 {{unknown attribute 'init_priority' ignored}}
+
+Two loo __attribute__((init_priority(65535))) ( 5, 6 );
+// unknown-warning@-1 {{unknown attribute 'init_priority' ignored}}
 
 Two goo __attribute__((init_pr

[clang] [clang][dataflow] Fix unsupported types always being equal (PR #129502)

2025-03-04 Thread via cfe-commits

Discookie wrote:

Ah I see, thanks for letting me know! I'll test a bit more, and add more tests 
as well if I find something.

One of the things I could see an issue with, is that technically the nullptr 
literal doesn't have a pointee type, since it's a nullptr_t.
Downstream code should be able to handle a <<>> QualType without any 
further code, but that could be a starting point.

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


[clang] [Clang] Don't give up on an unsuccessful function instantiation (PR #126723)

2025-03-04 Thread Younan Zhang via cfe-commits

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


[clang] 024362f - [clang-format] Insert a space after kw_new by default (#129634)

2025-03-04 Thread via cfe-commits

Author: Owen Pan
Date: 2025-03-04T21:14:07-08:00
New Revision: 024362f413dbfcf8188003762c9cc299f274d76e

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

LOG: [clang-format] Insert a space after kw_new by default (#129634)

This effectively reverts dbc4d281bd6954362ccfc0747893ceaae842671b.

Fix #54703

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 3a49650d95ba4..08539de405c67 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4845,16 +4845,11 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
 return Style.SpaceBeforeParensOptions.AfterControlStatements ||
spaceRequiredBeforeParens(Right);
   }
-  if (Left.isOneOf(tok::kw_new, tok::kw_delete)) {
-return ((!Line.MightBeFunctionDecl || !BeforeLeft) &&
-Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
-   spaceRequiredBeforeParens(Right);
-  }
-
-  if (Left.is(tok::r_square) && Left.MatchingParen &&
-  Left.MatchingParen->Previous &&
-  Left.MatchingParen->Previous->is(tok::kw_delete)) {
-return (Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
+  if (Left.isOneOf(tok::kw_new, tok::kw_delete) ||
+  (Left.is(tok::r_square) && Left.MatchingParen &&
+   Left.MatchingParen->Previous &&
+   Left.MatchingParen->Previous->is(tok::kw_delete))) {
+return Style.SpaceBeforeParens != FormatStyle::SBPO_Never ||
spaceRequiredBeforeParens(Right);
   }
 }

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index f3948142da0c9..ae2eaf70de1c2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12100,6 +12100,7 @@ TEST_F(FormatTest, PointerAlignmentFallback) {
 }
 
 TEST_F(FormatTest, UnderstandsNewAndDelete) {
+  verifyFormat("A(void *p) : a(new (p) int) {}");
   verifyFormat("void f() {\n"
"  A *a = new A;\n"
"  A *a = new (placement) A;\n"
@@ -12122,7 +12123,8 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) {
   verifyFormat("void new(link p);\n"
"void delete(link p);",
"void new (link p);\n"
-   "void delete (link p);");
+   "void delete (link p);",
+   getLLVMStyle(FormatStyle::LK_C));
 
   verifyFormat("{\n"
"  p->new();\n"



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


[clang] [clang-format] Insert a space after kw_new by default (PR #129634)

2025-03-04 Thread Owen Pan via cfe-commits

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


[clang-tools-extra] [clangd] Add `HeaderInsertion` yaml config option (PR #128503)

2025-03-04 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

(Recording myself as reviewer. I have a backlog of several patches in my review 
queue, will get to this as time permits.)

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


[clang] [Clang][CodeGen] Bail out on constexpr unknown values in ConstantEmitter (PR #127525)

2025-03-04 Thread Yingwei Zheng via cfe-commits

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


[clang] [Clang][CodeGen] Bail out on constexpr unknown values in ConstantEmitter (PR #127525)

2025-03-04 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

Closed in favor of https://github.com/llvm/llvm-project/pull/128409

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


[clang] [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (PR #128409)

2025-03-04 Thread Yingwei Zheng via cfe-commits

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


[clang] clang: Regenerate test checks (PR #129834)

2025-03-04 Thread Matt Arsenault via cfe-commits

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


[clang] clang: Regenerate test checks (PR #129834)

2025-03-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matt Arsenault (arsenm)


Changes

The previous checks missed the new metadata at the end of the line.
Regenerate to avoid future spurious diffs.

---

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


1 Files Affected:

- (modified) clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp (+40-40) 


``diff
diff --git a/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp 
b/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
index 4f3b5a4ce7760..5920ceda4a811 100644
--- a/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
+++ b/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
@@ -13,12 +13,12 @@
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[TMP1]], align 4
-// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i32 
[[TMP2]] syncscope("workgroup") seq_cst, align 4
+// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i32 
[[TMP2]] syncscope("workgroup") seq_cst, align 4, 
!amdgpu.no.fine.grained.memory [[META4:![0-9]+]]
 // CHECK-NEXT:store i32 [[TMP3]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP5:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP6:%.*]] = load i32, ptr [[TMP5]], align 4
-// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i32 
[[TMP6]] syncscope("workgroup") seq_cst, align 4
+// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i32 
[[TMP6]] syncscope("workgroup") seq_cst, align 4, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i32 [[TMP7]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:ret void
 //
@@ -39,12 +39,12 @@ __attribute__((device)) void 
test_non_volatile_parameter32(__UINT32_TYPE__ *ptr)
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP2:%.*]] = load i64, ptr [[TMP1]], align 8
-// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i64 
[[TMP2]] syncscope("workgroup") seq_cst, align 8
+// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i64 
[[TMP2]] syncscope("workgroup") seq_cst, align 8, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i64 [[TMP3]], ptr [[RES_ASCAST]], align 8
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP5:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP6:%.*]] = load i64, ptr [[TMP5]], align 8
-// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i64 
[[TMP6]] syncscope("workgroup") seq_cst, align 8
+// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i64 
[[TMP6]] syncscope("workgroup") seq_cst, align 8, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i64 [[TMP7]], ptr [[RES_ASCAST]], align 8
 // CHECK-NEXT:ret void
 //
@@ -65,12 +65,12 @@ __attribute__((device)) void 
test_non_volatile_parameter64(__UINT64_TYPE__ *ptr)
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP2:%.*]] = load volatile i32, ptr [[TMP1]], align 4
-// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw volatile uinc_wrap ptr [[TMP0]], 
i32 [[TMP2]] syncscope("workgroup") seq_cst, align 4
+// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw volatile uinc_wrap ptr [[TMP0]], 
i32 [[TMP2]] syncscope("workgroup") seq_cst, align 4, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i32 [[TMP3]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP5:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP6:%.*]] = load volatile i32, ptr [[TMP5]], align 4
-// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw volatile udec_wrap ptr [[TMP4]], 
i32 [[TMP6]] syncscope("workgroup") seq_cst, align 4
+// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw volatile udec_wrap ptr [[TMP4]], 
i32 [[TMP6]] syncscope("workgroup") seq_cst, align 4, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i32 [[TMP7]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:ret void
 //
@@ -91,12 +91,12 @@ __attribute__((device)) void 
test_volatile_parameter32(volatile __UINT32_TYPE__
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP2:%.*]] = load volatile i64, ptr [[TMP1]], align 8
-// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw volatile uinc_wrap ptr [[TMP0]], 
i64 [[TMP2]] syncscope("wor

[clang] [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (PR #128409)

2025-03-04 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja milestoned 
https://github.com/llvm/llvm-project/pull/128409
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Diagnose potential size confusion with VLA params (PR #129772)

2025-03-04 Thread Martin Uecker via cfe-commits


@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 %s -std=c23 -verify=expected,c -fsyntax-only
+// RUN: %clang_cc1 %s -std=c23 -verify=good -fsyntax-only -Wno-vla
+// RUN: %clang_cc1 -x c++ %s -verify -fsyntax-only
+// RUN: %clang_cc1 -DCARET -fsyntax-only -std=c23 
-fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines=1 %s 2>&1 | 
FileCheck %s -strict-whitespace
+
+// good-no-diagnostics
+
+int n, m;  // #decl
+int size(int);
+
+void foo(int vla[n], int n); // expected-warning {{variable length array size 
expression refers to declaration from an outer scope}} \
+expected-note {{does not refer to this 
declaration}} \
+expected-note@#decl {{refers to this 
declaration instead}}
+
+void bar(int (*vla)[n], int n); // expected-warning {{variable length array 
size expression refers to declaration from an outer scope}} \
+   expected-note {{does not refer to this 
declaration}} \
+   expected-note@#decl {{refers to this 
declaration instead}}
+
+void baz(int n, int vla[n]); // no diagnostic expected
+
+void quux(int vla[n + 12], int n); // expected-warning {{variable length array 
size expression refers to declaration from an outer scope}} \
+  expected-note {{does not refer to this 
declaration}} \
+  expected-note@#decl {{refers to this 
declaration instead}}
+
+void quibble(int vla[size(n)], int n);  // expected-warning {{variable length 
array size expression refers to declaration from an outer scope}} \
+   expected-note {{does not refer to 
this declaration}} \
+   expected-note@#decl {{refers to 
this declaration instead}}
+
+void quobble(int vla[n + m], int n, int m);  // expected-warning 2 {{variable 
length array size expression refers to declaration from an outer scope}} \
+expected-note 2 {{does not 
refer to this declaration}} \
+expected-note@#decl 2 {{refers 
to this declaration instead}}
+
+// For const int, we still treat the function as having a variably-modified
+// type, but only in C.

uecker wrote:

Note that there is proposal in flight for C that might change this.


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


[clang] [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (PR #128409)

2025-03-04 Thread A. Jiang via cfe-commits

frederick-vs-ja wrote:

/cherry-pick 27757fb87429c89a65bb5e1f619ad700928db0fd

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


[clang] clang: Regenerate test checks (PR #129834)

2025-03-04 Thread Matt Arsenault via cfe-commits

arsenm wrote:

* **#129834** https://app.graphite.dev/github/pr/llvm/llvm-project/129834?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/129834?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


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


[clang] 107fe0e - [clang][bytecode] Fix a crash in CheckConstantExpression (#129752)

2025-03-04 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-05T08:21:51+01:00
New Revision: 107fe0ec6cb36dca6bfafbfdf2996ce38d84e5bd

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

LOG: [clang][bytecode] Fix a crash in CheckConstantExpression (#129752)

The APValue we generated for a pointer with a LValueReferenceType base
had an incorrect lvalue path attached.

The attached test case is extracted from libc++'s regex.cpp.

Added: 


Modified: 
clang/lib/AST/ByteCode/Pointer.cpp
clang/test/AST/ByteCode/references.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index 324097a95dda3..8abdc54b64677 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -210,7 +210,8 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
   };
 
   bool UsePath = true;
-  if (getType()->isLValueReferenceType())
+  if (const ValueDecl *VD = getDeclDesc()->asValueDecl();
+  VD && VD->getType()->isLValueReferenceType())
 UsePath = false;
 
   // Build the path into the object.

diff  --git a/clang/test/AST/ByteCode/references.cpp 
b/clang/test/AST/ByteCode/references.cpp
index 7610655958230..36609b7df3f59 100644
--- a/clang/test/AST/ByteCode/references.cpp
+++ b/clang/test/AST/ByteCode/references.cpp
@@ -140,3 +140,41 @@ namespace Temporaries {
   static_assert(j.a.n == 1, "");  // both-error {{not an integral constant 
expression}} \
   // both-note {{read of temporary is not 
allowed in a constant expression outside the expression that created the 
temporary}}
 }
+
+namespace Params {
+  typedef __SIZE_TYPE__ size_t;
+
+  template 
+  constexpr _Tp* end(_Tp (&__array)[_Np]) noexcept {
+return __array + _Np;
+  }
+
+
+  struct classnames {
+const char* elem_;
+int a;
+  };
+
+  constexpr classnames ClassNames[] = {
+{"a", 0},
+{"b", 1},
+{"b", 1},
+{"b", 1},
+{"b", 1},
+{"b", 1},
+{"b", 1},
+{"b", 1},
+  };
+
+  constexpr bool foo() {
+/// This will instantiate end() with ClassNames.
+/// In Sema, we will constant-evaluate the return statement, which is
+/// something like __array + 8. The APValue we return for this
+/// may NOT have a LValuePath set, since it's for a parameter
+/// of LValueReferenceType.
+end(ClassNames);
+return true;
+  }
+
+  static_assert(foo());
+}



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


[clang] [clang][bytecode] Fix a crash in CheckConstantExpression (PR #129752)

2025-03-04 Thread Timm Baeder via cfe-commits

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-04 Thread Maurice Heumann via cfe-commits


@@ -5450,10 +5450,20 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl 
*Constructor, bool AnyErrors,
NumInitializers * sizeof(CXXCtorInitializer*));
 Constructor->setCtorInitializers(baseOrMemberInitializers);
 
+SourceLocation Location = Constructor->getLocation();
+
 // Constructors implicitly reference the base and member
 // destructors.
-MarkBaseAndMemberDestructorsReferenced(Constructor->getLocation(),
-   Constructor->getParent());
+
+for (CXXCtorInitializer *Initializer : Info.AllToInit) {
+  FieldDecl *Field = Initializer->getAnyMember();
+  if (!Field)
+continue;
+
+  MarkFieldDestructorReferenced(Location, Field);

momo5502 wrote:

done

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-04 Thread Maurice Heumann via cfe-commits

https://github.com/momo5502 updated 
https://github.com/llvm/llvm-project/pull/128866

>From bb4091d2f9b7062aa83e5bee2ba525478a7dbd0a Mon Sep 17 00:00:00 2001
From: Maurice Heumann 
Date: Wed, 26 Feb 2025 14:31:47 +0100
Subject: [PATCH 1/3] Instantiate destructors from initialized anonymous union
 fields

---
 clang/include/clang/Sema/Sema.h   |  2 +
 clang/lib/Sema/SemaDeclCXX.cpp| 95 ---
 clang/test/SemaCXX/cxx0x-nontrivial-union.cpp |  6 +-
 .../test/SemaCXX/union-member-destructor.cpp  | 48 ++
 4 files changed, 113 insertions(+), 38 deletions(-)
 create mode 100644 clang/test/SemaCXX/union-member-destructor.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5b5cee5810488..c5b2d58a78fd2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5432,6 +5432,8 @@ class Sema final : public SemaBase {
   void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
   CXXRecordDecl *Record);
 
+  void MarkFieldDestructorReferenced(SourceLocation Loc, FieldDecl *Field);
+
   /// Mark destructors of virtual bases of this class referenced. In the 
Itanium
   /// C++ ABI, this is done when emitting a destructor for any non-abstract
   /// class. In the Microsoft C++ ABI, this is done any time a class's
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a3a028b9485d6..761f6a09037a7 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -5450,10 +5450,31 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl 
*Constructor, bool AnyErrors,
NumInitializers * sizeof(CXXCtorInitializer*));
 Constructor->setCtorInitializers(baseOrMemberInitializers);
 
+SourceLocation Location = Constructor->getLocation();
+
+for (CXXCtorInitializer *Initializer : Info.AllToInit) {
+  FieldDecl *Field = Initializer->getAnyMember();
+  if (!Field)
+continue;
+
+  RecordDecl *Parent = Field->getParent();
+
+  while (Parent) {
+if (Parent->isUnion()) {
+  MarkFieldDestructorReferenced(Location, Field);
+  break;
+}
+
+if (!Parent->isAnonymousStructOrUnion() || Parent == ClassDecl) {
+  break;
+}
+
+Parent = cast(Parent->getDeclContext());
+  }
+}
 // Constructors implicitly reference the base and member
 // destructors.
-MarkBaseAndMemberDestructorsReferenced(Constructor->getLocation(),
-   Constructor->getParent());
+MarkBaseAndMemberDestructorsReferenced(Location, Constructor->getParent());
   }
 
   return HadError;
@@ -5758,6 +5779,42 @@ void Sema::ActOnMemInitializers(Decl *ConstructorDecl,
   DiagnoseUninitializedFields(*this, Constructor);
 }
 
+void Sema::MarkFieldDestructorReferenced(SourceLocation Location,
+ FieldDecl *Field) {
+  if (Field->isInvalidDecl())
+return;
+
+  // Don't destroy incomplete or zero-length arrays.
+  if (isIncompleteOrZeroLengthArrayType(Context, Field->getType()))
+return;
+
+  QualType FieldType = Context.getBaseElementType(Field->getType());
+
+  const RecordType *RT = FieldType->getAs();
+  if (!RT)
+return;
+
+  CXXRecordDecl *FieldClassDecl = cast(RT->getDecl());
+  if (FieldClassDecl->isInvalidDecl())
+return;
+  if (FieldClassDecl->hasIrrelevantDestructor())
+return;
+  // The destructor for an implicit anonymous union member is never invoked.
+  if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
+return;
+
+  CXXDestructorDecl *Dtor = LookupDestructor(FieldClassDecl);
+  // Dtor might still be missing, e.g because it's invalid.
+  if (!Dtor)
+return;
+  CheckDestructorAccess(Field->getLocation(), Dtor,
+PDiag(diag::err_access_dtor_field)
+<< Field->getDeclName() << FieldType);
+
+  MarkFunctionReferenced(Location, Dtor);
+  DiagnoseUseOfDecl(Dtor, Location);
+}
+
 void
 Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
  CXXRecordDecl *ClassDecl) {
@@ -5773,39 +5830,7 @@ 
Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
 
   // Non-static data members.
   for (auto *Field : ClassDecl->fields()) {
-if (Field->isInvalidDecl())
-  continue;
-
-// Don't destroy incomplete or zero-length arrays.
-if (isIncompleteOrZeroLengthArrayType(Context, Field->getType()))
-  continue;
-
-QualType FieldType = Context.getBaseElementType(Field->getType());
-
-const RecordType* RT = FieldType->getAs();
-if (!RT)
-  continue;
-
-CXXRecordDecl *FieldClassDecl = cast(RT->getDecl());
-if (FieldClassDecl->isInvalidDecl())
-  continue;
-if (FieldClassDecl->hasIrrelevantDestructor())
-  continue;
-// The destructor for an implicit anonymous

[clang] [llvm] [RISCV] Mark {vl, vtype} as clobber in inline assembly (PR #128636)

2025-03-04 Thread Pengcheng Wang via cfe-commits

wangpc-pp wrote:

Agree, we should try the RISCVInsertVSETVLI approach.

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-04 Thread Maurice Heumann via cfe-commits


@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+namespace t1{
+template  struct VSX {
+  ~VSX() { static_assert(sizeof(T) != 4, ""); } // expected-error {{static 
assertion failed due to requirement 'sizeof(int) != 4':}} \
+// expected-note {{expression 
evaluates to '4 != 4'}}
+};
+struct VS {
+  union {
+VSX _Tail;
+  };
+  ~VS() { }
+  VS(short);
+};
+VS::VS(short) : _Tail() { } // expected-note {{in instantiation of member 
function 't1::VSX::~VSX' requested here}}

momo5502 wrote:

I added a delegating constructor to the test. As the delegating constructor 
invokes the one that triggers the assertion, the assertion has to come either 
way. Therefore, I assume the test should assert that the note does not appear 
at the delegating constructor.

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


[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-03-04 Thread Trevor Gross via cfe-commits

tgross35 wrote:

Looks like GCC uses option 3 https://gcc.godbolt.org/z/fM1EbK6Mn.

If you only need something to test against locally, I was able to get our s390x 
rust dist built against your patches 
https://github.com/rust-lang-ci/rust/actions/runs/13668570835. 
`rust-std-s390x-unknown-linux-gnu/lib/rustlib/s390x-unknown-linux-gnu/lib/libcompiler_builtins-77321e818a95f60c.rlib`
 has all six conversion symbols, though I haven't been able to test their 
correctness on the platform.

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


[clang] 27757fb - [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (#128409)

2025-03-04 Thread via cfe-commits

Author: Yingwei Zheng
Date: 2025-03-05T14:01:24+08:00
New Revision: 27757fb87429c89a65bb5e1f619ad700928db0fd

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

LOG: [Clang] Treat constexpr-unknown value as invalid in 
`EvaluateAsInitializer` (#128409)

It is an alternative to
https://github.com/llvm/llvm-project/pull/127525.
Close https://github.com/llvm/llvm-project/issues/127475.

Added: 
clang/test/CodeGenCXX/cxx23-p2280r4.cpp

Modified: 
clang/lib/AST/ExprConstant.cpp
clang/lib/CodeGen/CGExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 7244120d1be51..d9a1e5bb42343 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3628,8 +3628,6 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const 
Expr *E,
   if (AllowConstexprUnknown) {
 if (!Result)
   Result = &Info.CurrentCall->createConstexprUnknownAPValues(VD, Base);
-else
-  Result->setConstexprUnknown();
   }
   return true;
 }
@@ -16995,6 +16993,18 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const 
ASTContext &Ctx,
 
 if (!Info.discardCleanups())
   llvm_unreachable("Unhandled cleanup; missing full expression marker?");
+
+if (Value.allowConstexprUnknown()) {
+  assert(Value.isLValue() && "Expected an lvalue");
+  auto Base = Value.getLValueBase();
+  const auto *NewVD = Base.dyn_cast();
+  if (!NewVD)
+NewVD = VD;
+  Info.FFDiag(getExprLoc(), diag::note_constexpr_var_init_non_constant, 1)
+  << NewVD;
+  NoteLValueLocation(Info, Base);
+  return false;
+}
   }
 
   return CheckConstantExpression(Info, DeclLoc, DeclTy, Value,

diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index ee5874b26f534..08e42a9e1dcf3 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1883,8 +1883,11 @@ llvm::Constant 
*ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &D) {
 
   // Try to emit the initializer.  Note that this can allow some things that
   // are not allowed by tryEmitPrivateForMemory alone.
-  if (APValue *value = D.evaluateValue())
+  if (APValue *value = D.evaluateValue()) {
+assert(!value->allowConstexprUnknown() &&
+   "Constexpr unknown values are not allowed in CodeGen");
 return tryEmitPrivateForMemory(*value, destType);
+  }
 
   return nullptr;
 }

diff  --git a/clang/test/CodeGenCXX/cxx23-p2280r4.cpp 
b/clang/test/CodeGenCXX/cxx23-p2280r4.cpp
new file mode 100644
index 0..d5409be451df0
--- /dev/null
+++ b/clang/test/CodeGenCXX/cxx23-p2280r4.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++23 %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++17 %s -emit-llvm -o - | 
FileCheck %s
+
+extern int& s;
+
+// CHECK: @_Z4testv()
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[I:%.*]] = alloca ptr, align {{.*}}
+// CHECK-NEXT: [[X:%.*]] = load ptr, ptr @s, align {{.*}}
+// CHECK-NEXT: store ptr [[X]], ptr [[I]], align {{.*}}
+int& test() {
+  auto &i = s;
+  return i;
+}



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


[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-03-04 Thread Trevor Gross via cfe-commits

tgross35 wrote:

I think something like the following precedence would make sense for all 
targets:

1. Direct asm: Lower to assembly if hardware support is available
2. Indirect mixed: libcall f16->f32 then asm the second conversion (f32->f64 or 
f32->f128) if hardware is available. The advantage is only linking one libcall 
(extendhfsf)
3. Direct libcall: If f32->f64 or f32->f128 are not hardware supported, use 
extendhfsf, extendhfdf, or extendhftf to lower f16->f32, f16->f64, a f16->f128
4. Indirect libcalls: this is LLVM's current behavior without hard float, i.e. 
libcall f16->f32 and then libcall again for f32->f64 or f32->f128

Option 2 is probably best here. Does s390x have `+soft-float` or any features 
that toggle the availability of float conversion ops? In these cases I think 
option 3 is preferable to option 4. (Although since the other targets seem to 
fall back to option 4, maybe this something that could be fixed globally?)

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


[clang] [llvm] [RISCV] Mark {vl, vtype} as clobber in inline assembly (PR #128636)

2025-03-04 Thread Craig Topper via cfe-commits

topperc wrote:

> I am not familiar with the target attribute implementation, can we get the 
> list of function features here and add the clobbers at:
> 
> https://github.com/llvm/llvm-project/blob/6d93280aabc2fd132f54e5aa615d25abeadabe7b/clang/lib/CodeGen/CGStmt.cpp#L3087-L3093
> 
> 
> cc @topperc @4vtomat

I'm not sure. But I don't understand why we need to check for Zve32x at all?

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


[clang] [llvm] [RISCV] Mark {vl, vtype} as clobber in inline assembly (PR #128636)

2025-03-04 Thread Craig Topper via cfe-commits

topperc wrote:

> > But the purpose we add vl/vtype dependencies is to prevent the Post-RA 
> > scheduler moving vsetvl instruction across inline assembly. I'm not sure if 
> > there's better approach to solve this problem.
> 
> Maybe have RISCVInsertVSETVLI add implicit use operands to the inline 
> assembly at that point? It's what we do for all the vector instructions. In 
> this case, you might want implicit defs.

I think we should try this RISCVInsertVSETVLI idea.

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


[clang-tools-extra] [clangd] Add `HeaderInsertion` yaml config option (PR #128503)

2025-03-04 Thread via cfe-commits

MythreyaK wrote:

Ping

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


[clang] [Clang] Add support for missing OpenCL extensions (PR #129777)

2025-03-04 Thread Michal Paszkowski via cfe-commits

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


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


[clang] [clang][CodeGen][OpenCL] Fix `alloca` handling (PR #113930)

2025-03-04 Thread Matt Arsenault via cfe-commits


@@ -103,11 +103,15 @@ RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type 
*Ty, CharUnits Align,
   if (AllocaAddr)
 *AllocaAddr = Alloca;
   llvm::Value *V = Alloca.getPointer();
+  assert((!getLangOpts().OpenCL ||
+  CGM.getTarget().getTargetAddressSpace(getASTAllocaAddressSpace()) ==
+  CGM.getTarget().getTargetAddressSpace(LangAS::opencl_private)) &&
+ "For OpenCL allocas must allocate in the private address space!");
   // Alloca always returns a pointer in alloca address space, which may
   // be different from the type defined by the language. For example,
   // in C++ the auto variables are in the default address space. Therefore
   // cast alloca to the default address space when necessary.
-  if (getASTAllocaAddressSpace() != LangAS::Default) {
+  if (!getLangOpts().OpenCL && getASTAllocaAddressSpace() != LangAS::Default) {

arsenm wrote:

Ok , this is the version with the cast. I think the naming / default should be 
inverted, but that's an issue for another day.

There still shouldn't be modality here, and at least one other context is using 
the wrong version

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


[clang] Diagnose potential size confusion with VLA params (PR #129772)

2025-03-04 Thread Martin Uecker via cfe-commits

uecker wrote:

And a final comment. While the main motivating use case for you may  be VLAs in 
parameter declarations (although as heavy user of those, I never felt the need 
for such a warning), it would seem the warning would be  relevant in cases 
where the arrays are not actually VLAs.  In general, it seems a warning about 
shadowing a visible identifier somewhere and just having it used with the old 
definition. So I wonder whether it should be renamed?

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


[clang] [llvm] [SPARC] Align i128 to 16 bytes in SPARC datalayouts (PR #106951)

2025-03-04 Thread Alex Rønne Petersen via cfe-commits


@@ -151,7 +151,7 @@ class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public 
SparcTargetInfo {
 public:
   SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : SparcTargetInfo(Triple, Opts) {
-resetDataLayout("E-m:e-p:32:32-i64:64-f128:64-n32-S64");
+resetDataLayout("E-m:e-p:32:32-i64:64-i128:128-f128:64-n32-S64");

alexrp wrote:

@koachan I realize I'm late to the party, but the original bug report in 
#102783 says that the bug is only for 64-bit SPARC. Was this change for 32-bit 
intentional?

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


[clang] clang: Do not implicitly addrspacecast in EmitAggExprToLValue (PR #129837)

2025-03-04 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/129837

This fixes breaking the ABI for calls to the kernel enqueue
implementation functions in OpenCL. The ABI passes these by stack
byref or byval, but this was incorrectly casting the stack slot
and passing to the use function.

I think nearly all uses of CreateMemTemp should not be inserting
this cast, but that will require a larger change with many more test
updates.

>From c62373c846263048b7c21abd239d3323af1aca58 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Wed, 5 Mar 2025 13:13:09 +0700
Subject: [PATCH] clang: Do not implicitly addrspacecast in EmitAggExprToLValue

This fixes breaking the ABI for calls to the kernel enqueue
implementation functions in OpenCL. The ABI passes these by stack
byref or byval, but this was incorrectly casting the stack slot
and passing to the use function.

I think nearly all uses of CreateMemTemp should not be inserting
this cast, but that will require a larger change with many more test
updates.
---
 clang/lib/CodeGen/CGExprAgg.cpp   |  2 +-
 .../CodeGenOpenCL/amdgpu-enqueue-kernel.cl| 50 ---
 2 files changed, 21 insertions(+), 31 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index c8bdda375d1b1..e9902f70c05eb 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -2219,7 +2219,7 @@ void CodeGenFunction::EmitAggExpr(const Expr *E, 
AggValueSlot Slot) {
 
 LValue CodeGenFunction::EmitAggExprToLValue(const Expr *E) {
   assert(hasAggregateEvaluationKind(E->getType()) && "Invalid argument!");
-  Address Temp = CreateMemTemp(E->getType());
+  Address Temp = CreateMemTempWithoutCast(E->getType());
   LValue LV = MakeAddrLValue(Temp, E->getType());
   EmitAggExpr(E, AggValueSlot::forLValue(LV, AggValueSlot::IsNotDestructed,
  AggValueSlot::DoesNotNeedGCBarriers,
diff --git a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl 
b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
index ace34dd0ca6dc..345dfaafa67e5 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
@@ -110,16 +110,12 @@ kernel void test_target_features_kernel(global int *i) {
 // NOCPU-NEXT:[[DEFAULT_QUEUE_ASCAST:%.*]] = addrspacecast ptr 
addrspace(5) [[DEFAULT_QUEUE]] to ptr
 // NOCPU-NEXT:[[FLAGS_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[FLAGS]] to ptr
 // NOCPU-NEXT:[[NDRANGE_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[NDRANGE]] to ptr
-// NOCPU-NEXT:[[TMP_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[TMP]] 
to ptr
 // NOCPU-NEXT:[[BLOCK_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BLOCK]] to ptr
-// NOCPU-NEXT:[[TMP2_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[VARTMP2]] to ptr
 // NOCPU-NEXT:[[BLOCK3_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BLOCK3]] to ptr
-// NOCPU-NEXT:[[TMP11_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[VARTMP11]] to ptr
 // NOCPU-NEXT:[[BLOCK12_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BLOCK12]] to ptr
 // NOCPU-NEXT:[[BLOCK_SIZES_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BLOCK_SIZES]] to ptr
 // NOCPU-NEXT:[[BLOCK20_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BLOCK20]] to ptr
 // NOCPU-NEXT:[[BLOCK21_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BLOCK21]] to ptr
-// NOCPU-NEXT:[[TMP27_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[VARTMP27]] to ptr
 // NOCPU-NEXT:store ptr addrspace(1) [[A]], ptr [[A_ADDR_ASCAST]], align 8
 // NOCPU-NEXT:store i8 [[B]], ptr [[B_ADDR_ASCAST]], align 1
 // NOCPU-NEXT:store ptr addrspace(1) [[C]], ptr [[C_ADDR_ASCAST]], align 8
@@ -127,7 +123,7 @@ kernel void test_target_features_kernel(global int *i) {
 // NOCPU-NEXT:store i32 0, ptr [[FLAGS_ASCAST]], align 4
 // NOCPU-NEXT:[[TMP0:%.*]] = load ptr addrspace(1), ptr 
[[DEFAULT_QUEUE_ASCAST]], align 8
 // NOCPU-NEXT:[[TMP1:%.*]] = load i32, ptr [[FLAGS_ASCAST]], align 4
-// NOCPU-NEXT:call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[TMP_ASCAST]], 
ptr align 4 [[NDRANGE_ASCAST]], i64 4, i1 false)
+// NOCPU-NEXT:call void @llvm.memcpy.p5.p0.i64(ptr addrspace(5) align 4 
[[TMP]], ptr align 4 [[NDRANGE_ASCAST]], i64 4, i1 false)
 // NOCPU-NEXT:[[BLOCK_SIZE:%.*]] = getelementptr inbounds nuw <{ i32, i32, 
ptr, ptr addrspace(1), i8 }>, ptr [[BLOCK_ASCAST]], i32 0, i32 0
 // NOCPU-NEXT:store i32 25, ptr [[BLOCK_SIZE]], align 8
 // NOCPU-NEXT:[[BLOCK_ALIGN:%.*]] = getelementptr inbounds nuw <{ i32, 
i32, ptr, ptr addrspace(1), i8 }>, ptr [[BLOCK_ASCAST]], i32 0, i32 1
@@ -140,10 +136,10 @@ kernel void test_target_features_kernel(global int *i) {
 // NOCPU-NEXT:[[BLOCK_CAPTURED1:%.*]] = getelementptr inbounds nuw <{ i32, 
i32, ptr, ptr addrspace(1), i8 }>, ptr [[BLOCK_ASCAST]], i32 0, i32 4
 // NOCPU-NEXT:[[TMP3:%.*]] = load i8, ptr [[B_ADDR_ASCAST]], align 1
 

[clang] clang: Do not implicitly addrspacecast in EmitAggExprToLValue (PR #129837)

2025-03-04 Thread Matt Arsenault via cfe-commits

arsenm wrote:

* **#129837** https://app.graphite.dev/github/pr/llvm/llvm-project/129837?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/129837?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


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


[clang] clang: Do not implicitly addrspacecast in EmitAggExprToLValue (PR #129837)

2025-03-04 Thread Matt Arsenault via cfe-commits

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


[clang] clang: Regenerate test checks (PR #129834)

2025-03-04 Thread Matt Arsenault via cfe-commits

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


[clang] 3105290 - clang: Regenerate test checks (#129834)

2025-03-04 Thread via cfe-commits

Author: Matt Arsenault
Date: 2025-03-05T13:36:25+07:00
New Revision: 310529065ae9680a9827742e16dd6dd51f00a4f8

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

LOG: clang: Regenerate test checks (#129834)

The previous checks missed the new metadata at the end of the line.
Regenerate to avoid future spurious diffs.

Added: 


Modified: 
clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp 
b/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
index 4f3b5a4ce7760..5920ceda4a811 100644
--- a/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
+++ b/clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
@@ -13,12 +13,12 @@
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[TMP1]], align 4
-// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i32 
[[TMP2]] syncscope("workgroup") seq_cst, align 4
+// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i32 
[[TMP2]] syncscope("workgroup") seq_cst, align 4, 
!amdgpu.no.fine.grained.memory [[META4:![0-9]+]]
 // CHECK-NEXT:store i32 [[TMP3]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP5:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP6:%.*]] = load i32, ptr [[TMP5]], align 4
-// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i32 
[[TMP6]] syncscope("workgroup") seq_cst, align 4
+// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i32 
[[TMP6]] syncscope("workgroup") seq_cst, align 4, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i32 [[TMP7]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:ret void
 //
@@ -39,12 +39,12 @@ __attribute__((device)) void 
test_non_volatile_parameter32(__UINT32_TYPE__ *ptr)
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP2:%.*]] = load i64, ptr [[TMP1]], align 8
-// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i64 
[[TMP2]] syncscope("workgroup") seq_cst, align 8
+// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw uinc_wrap ptr [[TMP0]], i64 
[[TMP2]] syncscope("workgroup") seq_cst, align 8, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i64 [[TMP3]], ptr [[RES_ASCAST]], align 8
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP5:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP6:%.*]] = load i64, ptr [[TMP5]], align 8
-// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i64 
[[TMP6]] syncscope("workgroup") seq_cst, align 8
+// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw udec_wrap ptr [[TMP4]], i64 
[[TMP6]] syncscope("workgroup") seq_cst, align 8, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i64 [[TMP7]], ptr [[RES_ASCAST]], align 8
 // CHECK-NEXT:ret void
 //
@@ -65,12 +65,12 @@ __attribute__((device)) void 
test_non_volatile_parameter64(__UINT64_TYPE__ *ptr)
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP2:%.*]] = load volatile i32, ptr [[TMP1]], align 4
-// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw volatile uinc_wrap ptr [[TMP0]], 
i32 [[TMP2]] syncscope("workgroup") seq_cst, align 4
+// CHECK-NEXT:[[TMP3:%.*]] = atomicrmw volatile uinc_wrap ptr [[TMP0]], 
i32 [[TMP2]] syncscope("workgroup") seq_cst, align 4, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i32 [[TMP3]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:[[TMP4:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP5:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP6:%.*]] = load volatile i32, ptr [[TMP5]], align 4
-// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw volatile udec_wrap ptr [[TMP4]], 
i32 [[TMP6]] syncscope("workgroup") seq_cst, align 4
+// CHECK-NEXT:[[TMP7:%.*]] = atomicrmw volatile udec_wrap ptr [[TMP4]], 
i32 [[TMP6]] syncscope("workgroup") seq_cst, align 4, 
!amdgpu.no.fine.grained.memory [[META4]]
 // CHECK-NEXT:store i32 [[TMP7]], ptr [[RES_ASCAST]], align 4
 // CHECK-NEXT:ret void
 //
@@ -91,12 +91,12 @@ __attribute__((device)) void 
test_volatile_parameter32(volatile __UINT32_TYPE__
 // CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR_ASCAST]], align 8
 // CHECK-NEXT:[[TMP1:%.*]] = load ptr, ptr [[PTR_ADD

[clang] [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (PR #128409)

2025-03-04 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#129836

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


[clang] [clang][CodeGen][OpenCL] Fix `alloca` handling (PR #113930)

2025-03-04 Thread Matt Arsenault via cfe-commits


@@ -103,11 +103,15 @@ RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type 
*Ty, CharUnits Align,
   if (AllocaAddr)
 *AllocaAddr = Alloca;
   llvm::Value *V = Alloca.getPointer();
+  assert((!getLangOpts().OpenCL ||
+  CGM.getTarget().getTargetAddressSpace(getASTAllocaAddressSpace()) ==
+  CGM.getTarget().getTargetAddressSpace(LangAS::opencl_private)) &&
+ "For OpenCL allocas must allocate in the private address space!");
   // Alloca always returns a pointer in alloca address space, which may
   // be different from the type defined by the language. For example,
   // in C++ the auto variables are in the default address space. Therefore
   // cast alloca to the default address space when necessary.
-  if (getASTAllocaAddressSpace() != LangAS::Default) {
+  if (!getLangOpts().OpenCL && getASTAllocaAddressSpace() != LangAS::Default) {

arsenm wrote:

Baby step that fixes my immediate issue: #129837

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


[clang] [llvm] [RISCV] Mark {vl, vtype} as clobber in inline assembly (PR #128636)

2025-03-04 Thread Hank Chang via cfe-commits

HankChang736 wrote:

I tested the following case without passing the 'v' extension in the Clang 
command line argument:
```c
__attribute__((target("arch=rv32gcv_zve32x")))
void test_A(int *p) {
  asm volatile("" :: "A"(*p));
}
```
The generated LLVM IR result is:
```
; Function Attrs: nounwind
define dso_local void @test_A(ptr noundef %p) local_unnamed_addr #0 {
entry:
  tail call void asm sideeffect "", "*A"(ptr elementtype(i32) %p) #1, !srcloc !6
  ret void
}

attributes #0 = { nounwind "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="generic-rv32" 
"target-features"="+32bit,+a,+c,+d,+f,+m,+relax,+v,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b
 ... 

```
>From this result, it appears that the target attribute does not have the 
>intended effect in this case. Given this, perhaps we should keep the initial 
>implementation temporary and try the RISCVInsertVSETVLI approach for future 
>improvements.

cc @wangpc-pp @topperc 

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


[clang] clang: Do not implicitly addrspacecast in EmitAggExprToLValue (PR #129837)

2025-03-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Matt Arsenault (arsenm)


Changes

This fixes breaking the ABI for calls to the kernel enqueue
implementation functions in OpenCL. The ABI passes these by stack
byref or byval, but this was incorrectly casting the stack slot
and passing to the use function.

I think nearly all uses of CreateMemTemp should not be inserting
this cast, but that will require a larger change with many more test
updates.

---

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGExprAgg.cpp (+1-1) 
- (modified) clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl (+20-30) 


``diff
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index c8bdda375d1b1..e9902f70c05eb 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -2219,7 +2219,7 @@ void CodeGenFunction::EmitAggExpr(const Expr *E, 
AggValueSlot Slot) {
 
 LValue CodeGenFunction::EmitAggExprToLValue(const Expr *E) {
   assert(hasAggregateEvaluationKind(E->getType()) && "Invalid argument!");
-  Address Temp = CreateMemTemp(E->getType());
+  Address Temp = CreateMemTempWithoutCast(E->getType());
   LValue LV = MakeAddrLValue(Temp, E->getType());
   EmitAggExpr(E, AggValueSlot::forLValue(LV, AggValueSlot::IsNotDestructed,
  AggValueSlot::DoesNotNeedGCBarriers,
diff --git a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl 
b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
index ace34dd0ca6dc..345dfaafa67e5 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
@@ -110,16 +110,12 @@ kernel void test_target_features_kernel(global int *i) {
 // NOCPU-NEXT:[[DEFAULT_QUEUE_ASCAST:%.*]] = addrspacecast ptr 
addrspace(5) [[DEFAULT_QUEUE]] to ptr
 // NOCPU-NEXT:[[FLAGS_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[FLAGS]] to ptr
 // NOCPU-NEXT:[[NDRANGE_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[NDRANGE]] to ptr
-// NOCPU-NEXT:[[TMP_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[TMP]] 
to ptr
 // NOCPU-NEXT:[[BLOCK_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BLOCK]] to ptr
-// NOCPU-NEXT:[[TMP2_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[VARTMP2]] to ptr
 // NOCPU-NEXT:[[BLOCK3_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BLOCK3]] to ptr
-// NOCPU-NEXT:[[TMP11_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[VARTMP11]] to ptr
 // NOCPU-NEXT:[[BLOCK12_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BLOCK12]] to ptr
 // NOCPU-NEXT:[[BLOCK_SIZES_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BLOCK_SIZES]] to ptr
 // NOCPU-NEXT:[[BLOCK20_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BLOCK20]] to ptr
 // NOCPU-NEXT:[[BLOCK21_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[BLOCK21]] to ptr
-// NOCPU-NEXT:[[TMP27_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[VARTMP27]] to ptr
 // NOCPU-NEXT:store ptr addrspace(1) [[A]], ptr [[A_ADDR_ASCAST]], align 8
 // NOCPU-NEXT:store i8 [[B]], ptr [[B_ADDR_ASCAST]], align 1
 // NOCPU-NEXT:store ptr addrspace(1) [[C]], ptr [[C_ADDR_ASCAST]], align 8
@@ -127,7 +123,7 @@ kernel void test_target_features_kernel(global int *i) {
 // NOCPU-NEXT:store i32 0, ptr [[FLAGS_ASCAST]], align 4
 // NOCPU-NEXT:[[TMP0:%.*]] = load ptr addrspace(1), ptr 
[[DEFAULT_QUEUE_ASCAST]], align 8
 // NOCPU-NEXT:[[TMP1:%.*]] = load i32, ptr [[FLAGS_ASCAST]], align 4
-// NOCPU-NEXT:call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[TMP_ASCAST]], 
ptr align 4 [[NDRANGE_ASCAST]], i64 4, i1 false)
+// NOCPU-NEXT:call void @llvm.memcpy.p5.p0.i64(ptr addrspace(5) align 4 
[[TMP]], ptr align 4 [[NDRANGE_ASCAST]], i64 4, i1 false)
 // NOCPU-NEXT:[[BLOCK_SIZE:%.*]] = getelementptr inbounds nuw <{ i32, i32, 
ptr, ptr addrspace(1), i8 }>, ptr [[BLOCK_ASCAST]], i32 0, i32 0
 // NOCPU-NEXT:store i32 25, ptr [[BLOCK_SIZE]], align 8
 // NOCPU-NEXT:[[BLOCK_ALIGN:%.*]] = getelementptr inbounds nuw <{ i32, 
i32, ptr, ptr addrspace(1), i8 }>, ptr [[BLOCK_ASCAST]], i32 0, i32 1
@@ -140,10 +136,10 @@ kernel void test_target_features_kernel(global int *i) {
 // NOCPU-NEXT:[[BLOCK_CAPTURED1:%.*]] = getelementptr inbounds nuw <{ i32, 
i32, ptr, ptr addrspace(1), i8 }>, ptr [[BLOCK_ASCAST]], i32 0, i32 4
 // NOCPU-NEXT:[[TMP3:%.*]] = load i8, ptr [[B_ADDR_ASCAST]], align 1
 // NOCPU-NEXT:store i8 [[TMP3]], ptr [[BLOCK_CAPTURED1]], align 8
-// NOCPU-NEXT:[[TMP4:%.*]] = call i32 @__enqueue_kernel_basic(ptr 
addrspace(1) [[TMP0]], i32 [[TMP1]], ptr [[TMP_ASCAST]], ptr 
@__test_block_invoke_kernel, ptr [[BLOCK_ASCAST]])
+// NOCPU-NEXT:[[TMP4:%.*]] = call i32 @__enqueue_kernel_basic(ptr 
addrspace(1) [[TMP0]], i32 [[TMP1]], ptr addrspace(5) [[TMP]], ptr 
@__test_block_invoke_kernel, ptr [[BLOCK_ASCAST]])
 // NOCPU-NEXT:

[clang] [CIR] Upstream global variable linkage types (PR #129072)

2025-03-04 Thread Henrich Lauko via cfe-commits


@@ -0,0 +1,119 @@
+//===--===//
+//-*-===//

xlauko wrote:

```suggestion
```

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


[clang] [clang][CodeGen][OpenCL] Fix `alloca` handling (PR #113930)

2025-03-04 Thread Matt Arsenault via cfe-commits


@@ -103,11 +103,15 @@ RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type 
*Ty, CharUnits Align,
   if (AllocaAddr)
 *AllocaAddr = Alloca;
   llvm::Value *V = Alloca.getPointer();
+  assert((!getLangOpts().OpenCL ||
+  CGM.getTarget().getTargetAddressSpace(getASTAllocaAddressSpace()) ==
+  CGM.getTarget().getTargetAddressSpace(LangAS::opencl_private)) &&
+ "For OpenCL allocas must allocate in the private address space!");
   // Alloca always returns a pointer in alloca address space, which may
   // be different from the type defined by the language. For example,
   // in C++ the auto variables are in the default address space. Therefore
   // cast alloca to the default address space when necessary.
-  if (getASTAllocaAddressSpace() != LangAS::Default) {
+  if (!getLangOpts().OpenCL && getASTAllocaAddressSpace() != LangAS::Default) {

arsenm wrote:

Switching CreateMemTemp to use CreateTempAllocaWithoutCast seems to help 

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


[clang] Fix quadratic slowdown in AST matcher parent map generation (PR #87824)

2025-03-04 Thread Michael Jabbour via cfe-commits

michael-jabbour-sonarsource wrote:

Hello,
This seems to cause a noticeable increase in memory consumption on some 
examples. See 
https://github.com/llvm/llvm-project/issues/129808#issuecomment-2700015065.

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


[clang] clang: Regenerate test checks (PR #129834)

2025-03-04 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-aarch64-quick` 
running on `linaro-clang-aarch64-quick` while building `clang` at step 5 "ninja 
check 1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'lit :: googletest-timeout.py' FAILED 

Exit Code: 1

Command Output (stdout):
--
# RUN: at line 9
not env -u FILECHECK_OPTS "/usr/bin/python3.10" 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/llvm/utils/lit/lit.py -j1 
--order=lexical -v Inputs/googletest-timeout--param 
gtest_filter=InfiniteLoopSubTest --timeout=1 > 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/Output/googletest-timeout.py.tmp.cmd.out
# executed command: not env -u FILECHECK_OPTS /usr/bin/python3.10 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/llvm/utils/lit/lit.py -j1 
--order=lexical -v Inputs/googletest-timeout --param 
gtest_filter=InfiniteLoopSubTest --timeout=1
# .---command stderr
# | lit.py: 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 1 seconds was requested on the command line. Forcing 
timeout to be 1 seconds.
# `-
# RUN: at line 11
FileCheck --check-prefix=CHECK-INF < 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/Output/googletest-timeout.py.tmp.cmd.out
 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/googletest-timeout.py
# executed command: FileCheck --check-prefix=CHECK-INF 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/googletest-timeout.py
# .---command stderr
# | 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/googletest-timeout.py:34:14:
 error: CHECK-INF: expected string not found in input
# | # CHECK-INF: Timed Out: 1
# |  ^
# | :13:29: note: scanning from here
# | Reached timeout of 1 seconds
# | ^
# | :37:2: note: possible intended match here
# |  Timed Out: 2 (100.00%)
# |  ^
# | 
# | Input file: 
# | Check file: 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/googletest-timeout.py
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<
# | .
# | .
# | .
# | 8:  
# | 9:  
# |10: -- 
# |11: exit: -9 
# |12: -- 
# |13: Reached timeout of 1 seconds 
# | check:34'0 X error: no match found
# |14:  
# | check:34'0 ~
# |15: TIMEOUT: googletest-timeout :: DummySubDir/OneTest.py/1/2 (2 
of 2) 
# | check:34'0 
~~~
# |16:  TEST 'googletest-timeout :: 
DummySubDir/OneTest.py/1/2' FAILED  
# | check:34'0 
~
# |17: Script(shard): 
# | check:34'0 ~~~
...

```



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


[clang] [Clang][CodeGen] Bail out on constexpr unknown values in ConstantEmitter (PR #127525)

2025-03-04 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

> That said, this patch might be worth having in that branch AS WELL to cover 
> any other missed cases. I would be OK having this patch HERE only on that 
> branch or replaced with an assert in main.

#128409 should cover all the cases this patch would cover.  I'm a little 
concerned #128409 still isn't broad enough... but not in a way that would 
trigger this check.  I'll continue discussion there.

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


[clang] [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (PR #128409)

2025-03-04 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Opened #129844 with a case that still fails.  Other entry-points to constant 
evaluation need similar treatment to EvaluateAsInitializer.

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-04 Thread Maurice Heumann via cfe-commits

https://github.com/momo5502 updated 
https://github.com/llvm/llvm-project/pull/128866

>From bb4091d2f9b7062aa83e5bee2ba525478a7dbd0a Mon Sep 17 00:00:00 2001
From: Maurice Heumann 
Date: Wed, 26 Feb 2025 14:31:47 +0100
Subject: [PATCH 1/4] Instantiate destructors from initialized anonymous union
 fields

---
 clang/include/clang/Sema/Sema.h   |  2 +
 clang/lib/Sema/SemaDeclCXX.cpp| 95 ---
 clang/test/SemaCXX/cxx0x-nontrivial-union.cpp |  6 +-
 .../test/SemaCXX/union-member-destructor.cpp  | 48 ++
 4 files changed, 113 insertions(+), 38 deletions(-)
 create mode 100644 clang/test/SemaCXX/union-member-destructor.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5b5cee5810488..c5b2d58a78fd2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5432,6 +5432,8 @@ class Sema final : public SemaBase {
   void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
   CXXRecordDecl *Record);
 
+  void MarkFieldDestructorReferenced(SourceLocation Loc, FieldDecl *Field);
+
   /// Mark destructors of virtual bases of this class referenced. In the 
Itanium
   /// C++ ABI, this is done when emitting a destructor for any non-abstract
   /// class. In the Microsoft C++ ABI, this is done any time a class's
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a3a028b9485d6..761f6a09037a7 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -5450,10 +5450,31 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl 
*Constructor, bool AnyErrors,
NumInitializers * sizeof(CXXCtorInitializer*));
 Constructor->setCtorInitializers(baseOrMemberInitializers);
 
+SourceLocation Location = Constructor->getLocation();
+
+for (CXXCtorInitializer *Initializer : Info.AllToInit) {
+  FieldDecl *Field = Initializer->getAnyMember();
+  if (!Field)
+continue;
+
+  RecordDecl *Parent = Field->getParent();
+
+  while (Parent) {
+if (Parent->isUnion()) {
+  MarkFieldDestructorReferenced(Location, Field);
+  break;
+}
+
+if (!Parent->isAnonymousStructOrUnion() || Parent == ClassDecl) {
+  break;
+}
+
+Parent = cast(Parent->getDeclContext());
+  }
+}
 // Constructors implicitly reference the base and member
 // destructors.
-MarkBaseAndMemberDestructorsReferenced(Constructor->getLocation(),
-   Constructor->getParent());
+MarkBaseAndMemberDestructorsReferenced(Location, Constructor->getParent());
   }
 
   return HadError;
@@ -5758,6 +5779,42 @@ void Sema::ActOnMemInitializers(Decl *ConstructorDecl,
   DiagnoseUninitializedFields(*this, Constructor);
 }
 
+void Sema::MarkFieldDestructorReferenced(SourceLocation Location,
+ FieldDecl *Field) {
+  if (Field->isInvalidDecl())
+return;
+
+  // Don't destroy incomplete or zero-length arrays.
+  if (isIncompleteOrZeroLengthArrayType(Context, Field->getType()))
+return;
+
+  QualType FieldType = Context.getBaseElementType(Field->getType());
+
+  const RecordType *RT = FieldType->getAs();
+  if (!RT)
+return;
+
+  CXXRecordDecl *FieldClassDecl = cast(RT->getDecl());
+  if (FieldClassDecl->isInvalidDecl())
+return;
+  if (FieldClassDecl->hasIrrelevantDestructor())
+return;
+  // The destructor for an implicit anonymous union member is never invoked.
+  if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
+return;
+
+  CXXDestructorDecl *Dtor = LookupDestructor(FieldClassDecl);
+  // Dtor might still be missing, e.g because it's invalid.
+  if (!Dtor)
+return;
+  CheckDestructorAccess(Field->getLocation(), Dtor,
+PDiag(diag::err_access_dtor_field)
+<< Field->getDeclName() << FieldType);
+
+  MarkFunctionReferenced(Location, Dtor);
+  DiagnoseUseOfDecl(Dtor, Location);
+}
+
 void
 Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
  CXXRecordDecl *ClassDecl) {
@@ -5773,39 +5830,7 @@ 
Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
 
   // Non-static data members.
   for (auto *Field : ClassDecl->fields()) {
-if (Field->isInvalidDecl())
-  continue;
-
-// Don't destroy incomplete or zero-length arrays.
-if (isIncompleteOrZeroLengthArrayType(Context, Field->getType()))
-  continue;
-
-QualType FieldType = Context.getBaseElementType(Field->getType());
-
-const RecordType* RT = FieldType->getAs();
-if (!RT)
-  continue;
-
-CXXRecordDecl *FieldClassDecl = cast(RT->getDecl());
-if (FieldClassDecl->isInvalidDecl())
-  continue;
-if (FieldClassDecl->hasIrrelevantDestructor())
-  continue;
-// The destructor for an implicit anonymous

[clang] [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (PR #128409)

2025-03-04 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

And the check for allowConstexprUnknown() isn't catching all the relevant 
cases; opened #129845.

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


[clang] 680391f - [clang][dataflow] Fix unsupported types always being equal (#129502)

2025-03-04 Thread via cfe-commits

Author: Discookie
Date: 2025-03-04T10:38:06Z
New Revision: 680391f07a45272bb9bfd385cf4c6846b8be32dd

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

LOG: [clang][dataflow] Fix unsupported types always being equal (#129502)

Previously when the framework encountered unsupported values (such as
enum classes), they were always treated as equal when comparing with
`==`, regardless of their actual values being different.
Now the two sides are only equal if there's a Value assigned to them.

Added a Value assignment for `nullptr`, to handle the special case of
`nullptr == nullptr`.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 9c54eb16d2224..e17a16a3b75d0 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -60,7 +60,9 @@ static BoolValue &evaluateBooleanEquality(const Expr &LHS, 
const Expr &RHS,
   Value *LHSValue = Env.getValue(LHS);
   Value *RHSValue = Env.getValue(RHS);
 
-  if (LHSValue == RHSValue)
+  // When two unsupported values are compared, both are nullptr. Only supported
+  // values should evaluate to equal.
+  if (LHSValue == RHSValue && LHSValue)
 return Env.getBoolLiteralValue(true);
 
   if (auto *LHSBool = dyn_cast_or_null(LHSValue))
@@ -798,6 +800,14 @@ class TransferVisitor : public 
ConstStmtVisitor {
 Env.setValue(*S, Env.getIntLiteralValue(S->getValue()));
   }
 
+  // Untyped nullptr's aren't handled by NullToPointer casts, so they need to 
be
+  // handled separately.
+  void VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
+auto &NullPointerVal =
+Env.getOrCreateNullPointerValue(S->getType()->getPointeeType());
+Env.setValue(*S, NullPointerVal);
+  }
+
   void VisitParenExpr(const ParenExpr *S) {
 // The CFG does not contain `ParenExpr` as top-level statements in basic
 // blocks, however manual traversal to sub-expressions may encounter them.

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 0f731f4532535..f52b73dbbdc57 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4974,6 +4974,41 @@ TEST(TransferTest, IntegerLiteralEquality) {
   });
 }
 
+TEST(TransferTest, UnsupportedValueEquality) {
+  std::string Code = R"(
+// An explicitly unsupported type by the framework.
+enum class EC {
+  A,
+  B
+};
+  
+void target() {
+  EC ec = EC::A;
+
+  bool unsupported_eq_same = (EC::A == EC::A);
+  bool unsupported_eq_other = (EC::A == EC::B);
+  bool unsupported_eq_var = (ec == EC::B);
+
+  (void)0; // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+// We do not model the values of unsupported types, so this
+// seemingly-trivial case will not be true either.
+EXPECT_TRUE(isa(
+getValueForDecl(ASTCtx, Env, "unsupported_eq_same")));
+EXPECT_TRUE(isa(
+getValueForDecl(ASTCtx, Env, "unsupported_eq_other")));
+EXPECT_TRUE(isa(
+getValueForDecl(ASTCtx, Env, "unsupported_eq_var")));
+  });
+}
+
 TEST(TransferTest, CorrelatedBranches) {
   std::string Code = R"(
 void target(bool B, bool C) {



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


[clang-tools-extra] 8266cd9 - [clangd] Disable cppcoreguidelines-macro-to-enum clang-tidy checker (#129478)

2025-03-04 Thread via cfe-commits

Author: Nathan Ridge
Date: 2025-03-04T03:46:54-05:00
New Revision: 8266cd9f84b5a7d334ade7ff41393458b3789047

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

LOG: [clangd] Disable cppcoreguidelines-macro-to-enum clang-tidy checker 
(#129478)

Clangd does not support its checker because the checker relies on having
seen preprocessor conditionals that occur in the preamble, and clangd
does not currently replay those.

This checker was already disabled under its main name,
modernize-macro-to-enum (https://github.com/clangd/clangd/issues/1464).
This commit disables it under the alternative name
cppcoreguidelines-macro-to-enum as well.

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

Added: 


Modified: 
clang-tools-extra/clangd/TidyProvider.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/TidyProvider.cpp 
b/clang-tools-extra/clangd/TidyProvider.cpp
index 2ac123246a4cb..1d79a7a7399ec 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -210,6 +210,7 @@ TidyProvider 
disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) {
   // Check relies on seeing ifndef/define/endif directives,
   // clangd doesn't replay those when using a preamble.
   "-llvm-header-guard", "-modernize-macro-to-enum",
+  "-cppcoreguidelines-macro-to-enum",
 
   // - Crashing Checks -
 

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 7a47d6ebebf3b..f9ff6f21009f3 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -823,6 +823,21 @@ TEST(DiagnosticTest, ClangTidyNoLiteralDataInMacroToken) {
   EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre()); // no-crash
 }
 
+TEST(DiagnosticTest, ClangTidyMacroToEnumCheck) {
+  Annotations Main(R"cpp(
+#if 1
+auto foo();
+#endif
+  )cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  std::vector Providers;
+  Providers.push_back(
+  
addTidyChecks("cppcoreguidelines-macro-to-enum,modernize-macro-to-enum"));
+  Providers.push_back(disableUnusableChecks());
+  TU.ClangTidyProvider = combine(std::move(Providers));
+  EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre()); // no-crash
+}
+
 TEST(DiagnosticTest, ElseAfterReturnRange) {
   Annotations Main(R"cpp(
 int foo(int cond) {



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


[clang] a619a2e - [ARM] Fix lane ordering for AdvSIMD intrinsics on big-endian targets (#127068)

2025-03-04 Thread via cfe-commits

Author: Oliver Stannard
Date: 2025-03-04T08:10:22Z
New Revision: a619a2e53a9ba09ba18a047b8389bf4dd1912b72

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

LOG: [ARM] Fix lane ordering for AdvSIMD intrinsics on big-endian targets 
(#127068)

In arm-neon.h, we insert shufflevectors around each intrinsic when the
target is big-endian, to compensate for the difference between the
ABI-defined memory format of vectors (with the whole vector stored as
one big-endian access) and LLVM's target-independent expectations (with
the lowest-numbered lane in the lowest address). However, this code was
written for the AArch64 ABI, and the AArch32 ABI differs slightly: it
requires that vectors are stored in memory as-if stored with VSTM, which
does a series of 64-bit accesses, instead of the AArch64 VSTR, which
does a single 128-bit access. This means that for AArch32 we need to
reverse the lanes in each 64-bit chunk of the vector, instead of in the
whole vector.

Since there are only a small number of different shufflevector orderings
needed, I've split them out into macros, so that this doesn't need
separate conditions in each intrinsic definition.

Added: 
clang/test/CodeGen/arm-neon-endianness.c

Modified: 
clang/utils/TableGen/NeonEmitter.cpp

Removed: 




diff  --git a/clang/test/CodeGen/arm-neon-endianness.c 
b/clang/test/CodeGen/arm-neon-endianness.c
new file mode 100644
index 0..ba2471ee39d3e
--- /dev/null
+++ b/clang/test/CodeGen/arm-neon-endianness.c
@@ -0,0 +1,115 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+
+// REQUIRES: arm-registered-target
+
+// RUN: %clang_cc1 -triple armv8a-arm-none-eabihf -target-cpu generic 
-emit-llvm -o - %s -disable-O0-optnone | \
+// RUN: opt -S -passes=instcombine -o - | FileCheck %s --check-prefix=LE
+// RUN: %clang_cc1 -triple armebv8a-arm-none-eabihf -target-cpu generic 
-emit-llvm -o - %s -disable-O0-optnone | \
+// RUN: opt -S -passes=instcombine -o - | FileCheck %s --check-prefix=BE
+
+#include 
+
+// LE-LABEL: define dso_local i32 @int32x4_t_lane_0(
+// LE-SAME: <4 x i32> noundef [[A:%.*]]) #[[ATTR0:[0-9]+]] {
+// LE-NEXT:  [[ENTRY:.*:]]
+// LE-NEXT:[[VGET_LANE:%.*]] = extractelement <4 x i32> [[A]], i64 0
+// LE-NEXT:ret i32 [[VGET_LANE]]
+//
+// BE-LABEL: define dso_local i32 @int32x4_t_lane_0(
+// BE-SAME: <4 x i32> noundef [[A:%.*]]) #[[ATTR0:[0-9]+]] {
+// BE-NEXT:  [[ENTRY:.*:]]
+// BE-NEXT:[[VGET_LANE:%.*]] = extractelement <4 x i32> [[A]], i64 1
+// BE-NEXT:ret i32 [[VGET_LANE]]
+//
+int int32x4_t_lane_0(int32x4_t a) { return vgetq_lane_s32(a, 0); }
+// LE-LABEL: define dso_local i32 @int32x4_t_lane_1(
+// LE-SAME: <4 x i32> noundef [[A:%.*]]) #[[ATTR0]] {
+// LE-NEXT:  [[ENTRY:.*:]]
+// LE-NEXT:[[VGET_LANE:%.*]] = extractelement <4 x i32> [[A]], i64 1
+// LE-NEXT:ret i32 [[VGET_LANE]]
+//
+// BE-LABEL: define dso_local i32 @int32x4_t_lane_1(
+// BE-SAME: <4 x i32> noundef [[A:%.*]]) #[[ATTR0]] {
+// BE-NEXT:  [[ENTRY:.*:]]
+// BE-NEXT:[[VGET_LANE:%.*]] = extractelement <4 x i32> [[A]], i64 0
+// BE-NEXT:ret i32 [[VGET_LANE]]
+//
+int int32x4_t_lane_1(int32x4_t a) { return vgetq_lane_s32(a, 1); }
+// LE-LABEL: define dso_local i32 @int32x4_t_lane_2(
+// LE-SAME: <4 x i32> noundef [[A:%.*]]) #[[ATTR0]] {
+// LE-NEXT:  [[ENTRY:.*:]]
+// LE-NEXT:[[VGET_LANE:%.*]] = extractelement <4 x i32> [[A]], i64 2
+// LE-NEXT:ret i32 [[VGET_LANE]]
+//
+// BE-LABEL: define dso_local i32 @int32x4_t_lane_2(
+// BE-SAME: <4 x i32> noundef [[A:%.*]]) #[[ATTR0]] {
+// BE-NEXT:  [[ENTRY:.*:]]
+// BE-NEXT:[[VGET_LANE:%.*]] = extractelement <4 x i32> [[A]], i64 3
+// BE-NEXT:ret i32 [[VGET_LANE]]
+//
+int int32x4_t_lane_2(int32x4_t a) { return vgetq_lane_s32(a, 2); }
+// LE-LABEL: define dso_local i32 @int32x4_t_lane_3(
+// LE-SAME: <4 x i32> noundef [[A:%.*]]) #[[ATTR0]] {
+// LE-NEXT:  [[ENTRY:.*:]]
+// LE-NEXT:[[VGET_LANE:%.*]] = extractelement <4 x i32> [[A]], i64 3
+// LE-NEXT:ret i32 [[VGET_LANE]]
+//
+// BE-LABEL: define dso_local i32 @int32x4_t_lane_3(
+// BE-SAME: <4 x i32> noundef [[A:%.*]]) #[[ATTR0]] {
+// BE-NEXT:  [[ENTRY:.*:]]
+// BE-NEXT:[[VGET_LANE:%.*]] = extractelement <4 x i32> [[A]], i64 2
+// BE-NEXT:ret i32 [[VGET_LANE]]
+//
+int int32x4_t_lane_3(int32x4_t a) { return vgetq_lane_s32(a, 3); }
+// LE-LABEL: define dso_local i32 @int32x2_t_lane_0(
+// LE-SAME: <2 x i32> noundef [[A:%.*]]) #[[ATTR0]] {
+// LE-NEXT:  [[ENTRY:.*:]]
+// LE-NEXT:[[VGET_LANE:%.*]] = extractelement <2 x i32> [[A]], i64 0
+// LE-NEXT:ret i32 [[VGET_LANE]]
+//
+// BE-LABEL: define dso_local i32 @int32x2_t_lane_0(
+// BE-SAME: <2 x i32> noundef [[A:%.*]]) #[[ATTR0]] {
+// BE-NEXT:  [[ENTRY:.*:]]
+// BE-NEXT:[[VGET_LANE:%

[clang] d6942d5 - [MS][clang] Add support for vector deleting destructors (#126240)

2025-03-04 Thread via cfe-commits

Author: Mariya Podchishchaeva
Date: 2025-03-04T09:17:50+01:00
New Revision: d6942d54f677000cf713d2b0eba57b641452beb4

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

LOG: [MS][clang] Add support for vector deleting destructors (#126240)

Whereas it is UB in terms of the standard to delete an array of objects
via pointer whose static type doesn't match its dynamic type, MSVC
supports an extension allowing to do it.
Aside from array deletion not working correctly in the mentioned case,
currently not having this extension implemented causes clang to generate
code that is not compatible with the code generated by MSVC, because
clang always puts scalar deleting destructor to the vftable. This PR
aims to resolve these problems.

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

Added: 
clang/test/CodeGenCXX/microsoft-vector-deleting-dtors.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/VTableBuilder.h
clang/include/clang/Basic/ABI.h
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/AST/VTableBuilder.cpp
clang/lib/CodeGen/CGCXX.cpp
clang/lib/CodeGen/CGCXXABI.cpp
clang/lib/CodeGen/CGCXXABI.h
clang/lib/CodeGen/CGClass.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/CodeGen/CGVTables.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenCXX/debug-info-windows-dtor.cpp
clang/test/CodeGenCXX/dllexport.cpp
clang/test/CodeGenCXX/microsoft-abi-extern-template.cpp
clang/test/CodeGenCXX/microsoft-abi-structors.cpp
clang/test/CodeGenCXX/microsoft-abi-thunks.cpp
clang/test/CodeGenCXX/microsoft-abi-vftables.cpp
clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp

clang/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance-vdtors.cpp
clang/test/CodeGenCXX/microsoft-abi-vtables-return-thunks.cpp
clang/test/CodeGenCXX/microsoft-abi-vtables-single-inheritance.cpp

clang/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-vtordisps.cpp
clang/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp
clang/test/CodeGenCXX/microsoft-no-rtti-data.cpp
clang/test/CodeGenCXX/vtable-consteval.cpp
clang/test/Modules/vtable-windows.cppm
clang/test/Profile/cxx-abc-deleting-dtor.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 688d50a394c62..97b8e32f03b57 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -308,6 +308,8 @@ Android Support
 Windows Support
 ^^^
 
+- Clang now supports MSVC vector deleting destructors (GH19772).
+
 LoongArch Support
 ^
 

diff  --git a/clang/include/clang/AST/VTableBuilder.h 
b/clang/include/clang/AST/VTableBuilder.h
index a5de41dbc22f1..e1efe8cddcc5e 100644
--- a/clang/include/clang/AST/VTableBuilder.h
+++ b/clang/include/clang/AST/VTableBuilder.h
@@ -150,7 +150,7 @@ class VTableComponent {
 
   bool isRTTIKind() const { return isRTTIKind(getKind()); }
 
-  GlobalDecl getGlobalDecl() const {
+  GlobalDecl getGlobalDecl(bool HasVectorDeletingDtors) const {
 assert(isUsedFunctionPointerKind() &&
"GlobalDecl can be created only from virtual function");
 
@@ -161,7 +161,9 @@ class VTableComponent {
 case CK_CompleteDtorPointer:
   return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Complete);
 case CK_DeletingDtorPointer:
-  return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Deleting);
+  return GlobalDecl(DtorDecl, (HasVectorDeletingDtors)
+  ? CXXDtorType::Dtor_VectorDeleting
+  : CXXDtorType::Dtor_Deleting);
 case CK_VCallOffset:
 case CK_VBaseOffset:
 case CK_OffsetToTop:

diff  --git a/clang/include/clang/Basic/ABI.h b/clang/include/clang/Basic/ABI.h
index 231bad799a42c..48969e4f295c3 100644
--- a/clang/include/clang/Basic/ABI.h
+++ b/clang/include/clang/Basic/ABI.h
@@ -31,10 +31,11 @@ enum CXXCtorType {
 
 /// C++ destructor types.
 enum CXXDtorType {
-Dtor_Deleting, ///< Deleting dtor
-Dtor_Complete, ///< Complete object dtor
-Dtor_Base, ///< Base object dtor
-Dtor_Comdat///< The COMDAT used for dtors
+  Dtor_Deleting,  ///< Deleting dtor
+  Dtor_Complete,  ///< Complete object dtor
+  Dtor_Base,  ///< Base object dtor
+  Dtor_Comdat,///< The COMDAT used for dtors
+  Dtor_VectorDeleting ///< Vector deleting dtor
 };
 
 } // end namespace clang

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b6ba36784f38a..b80dd1c86092f 100644
--- a/c

[clang] 6720465 - [ObjC] Expand isClassLayoutKnownStatically to base classes as long as the implementation of it is known (#85465)

2025-03-04 Thread via cfe-commits

Author: AZero13
Date: 2025-03-04T08:34:18-08:00
New Revision: 6720465c47303cafcd448c64af97e7b627c399a8

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

LOG: [ObjC] Expand isClassLayoutKnownStatically to base classes as long as the 
implementation of it is known (#85465)

Only NSObject we can trust the layout of won't change even though we
cannot directly see its @implementation

Added: 


Modified: 
clang/lib/CodeGen/CGObjCMac.cpp
clang/test/CodeGenObjC/arc-blocks.m
clang/test/CodeGenObjC/arc-property.m
clang/test/CodeGenObjC/arc-weak-property.m
clang/test/CodeGenObjC/arc.m
clang/test/CodeGenObjC/arm64-int32-ivar.m
clang/test/CodeGenObjC/bitfield-ivar-offsets.m
clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
clang/test/CodeGenObjC/direct-method.m
clang/test/CodeGenObjC/hidden-visibility.m
clang/test/CodeGenObjC/interface-layout-64.m
clang/test/CodeGenObjC/ivar-base-as-invariant-load.m
clang/test/CodeGenObjC/metadata-symbols-64.m
clang/test/CodeGenObjC/nontrivial-c-struct-property.m
clang/test/CodeGenObjC/objc-asm-attribute-test.m
clang/test/CodeGenObjC/ubsan-bool.m

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 01552b6e53d00..639c38e7c4555 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1545,7 +1545,8 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
   bool isClassLayoutKnownStatically(const ObjCInterfaceDecl *ID) {
 // Test a class by checking its superclasses up to
 // its base class if it has one.
-for (; ID; ID = ID->getSuperClass()) {
+assert(ID != nullptr && "Passed a null class to check layout");
+for (; ID != nullptr; ID = ID->getSuperClass()) {
   // The layout of base class NSObject
   // is guaranteed to be statically known
   if (ID->getIdentifier()->getName() == "NSObject")
@@ -1556,7 +1557,9 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
   if (!ID->getImplementation())
 return false;
 }
-return false;
+
+// We know the layout of all the intermediate classes and superclasses.
+return true;
   }
 
 public:

diff  --git a/clang/test/CodeGenObjC/arc-blocks.m 
b/clang/test/CodeGenObjC/arc-blocks.m
index bed55bf18fe59..72bf35c2e117e 100644
--- a/clang/test/CodeGenObjC/arc-blocks.m
+++ b/clang/test/CodeGenObjC/arc-blocks.m
@@ -422,16 +422,16 @@ @interface Test12
 @implementation Test12
 @synthesize ablock, nblock;
 // CHECK:define internal ptr @"\01-[Test12 ablock]"(
-// CHECK:call ptr @objc_getProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef {{%.*}}, i1 noundef zeroext true)
+// CHECK:call ptr @objc_getProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef 0, i1 noundef zeroext true)
 
 // CHECK:define internal void @"\01-[Test12 setAblock:]"(
-// CHECK:call void @objc_setProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef {{%.*}}, ptr noundef {{%.*}}, i1 noundef zeroext true, i1 
noundef zeroext true)
+// CHECK:call void @objc_setProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef 0, ptr noundef {{%.*}}, i1 noundef zeroext true, i1 
noundef zeroext true)
 
 // CHECK:define internal ptr @"\01-[Test12 nblock]"(
-// CHECK:%add.ptr = getelementptr inbounds i8, ptr %0, i64 %ivar
+// CHECK:%add.ptr = getelementptr inbounds i8, ptr %0, i64 8
 
 // CHECK:define internal void @"\01-[Test12 setNblock:]"(
-// CHECK:call void @objc_setProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef {{%.*}}, ptr noundef {{%.*}}, i1 noundef zeroext false, i1 
noundef zeroext true)
+// CHECK:call void @objc_setProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef 8, ptr noundef {{%.*}}, i1 noundef zeroext false, i1 
noundef zeroext true)
 @end
 
 void test13(id x) {

diff  --git a/clang/test/CodeGenObjC/arc-property.m 
b/clang/test/CodeGenObjC/arc-property.m
index f57be6b4f6be4..3209993cc6d32 100644
--- a/clang/test/CodeGenObjC/arc-property.m
+++ b/clang/test/CodeGenObjC/arc-property.m
@@ -22,16 +22,14 @@ @implementation Test1
 @end
 //   The getter should be a simple load.
 // CHECK:define internal ptr @"\01-[Test1 pointer]"(
-// CHECK:  [[OFFSET:%.*]] = load i64, ptr @"OBJC_IVAR_$_Test1.pointer"
-// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8, ptr {{%.*}}, i64 
[[OFFSET]]
+// CHECK: [[T1:%.*]] = getelementptr inbounds i8, ptr {{%.*}}, i64 0
 // CHECK-NEXT: [[T3:%.*]] = load ptr, ptr [[T1]], align 8
 // CHECK-NEXT: ret ptr [[T3]]
 
 //   The setter should be using objc_setProperty.
 // CHECK:define internal void @"\01-[Test1 setPointer:]"(
-// CHECK: [[OFFSET:%.*]] = load i64, ptr @"OBJC_IVAR_$_Test1.pointer"
-// CHECK

[clang] d6301b2 - Revert "[clang][dataflow] Fix unsupported types always being equal" (#129761)

2025-03-04 Thread via cfe-commits

Author: Jan Voung
Date: 2025-03-04T15:48:42-05:00
New Revision: d6301b218c6698ceb0db1753c8de480d37d11cf8

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

LOG: Revert "[clang][dataflow] Fix unsupported types always being equal" 
(#129761)

Reverts llvm/llvm-project#129502

seeing new crashes around
https://github.com/google/crubit/blob/859520eca82d60a169fb85cdbf648c57d0a14a99/nullability/test/smart_pointers_diagnosis.cc#L57

Would like some time to investigate.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index e17a16a3b75d0..9c54eb16d2224 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -60,9 +60,7 @@ static BoolValue &evaluateBooleanEquality(const Expr &LHS, 
const Expr &RHS,
   Value *LHSValue = Env.getValue(LHS);
   Value *RHSValue = Env.getValue(RHS);
 
-  // When two unsupported values are compared, both are nullptr. Only supported
-  // values should evaluate to equal.
-  if (LHSValue == RHSValue && LHSValue)
+  if (LHSValue == RHSValue)
 return Env.getBoolLiteralValue(true);
 
   if (auto *LHSBool = dyn_cast_or_null(LHSValue))
@@ -800,14 +798,6 @@ class TransferVisitor : public 
ConstStmtVisitor {
 Env.setValue(*S, Env.getIntLiteralValue(S->getValue()));
   }
 
-  // Untyped nullptr's aren't handled by NullToPointer casts, so they need to 
be
-  // handled separately.
-  void VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
-auto &NullPointerVal =
-Env.getOrCreateNullPointerValue(S->getType()->getPointeeType());
-Env.setValue(*S, NullPointerVal);
-  }
-
   void VisitParenExpr(const ParenExpr *S) {
 // The CFG does not contain `ParenExpr` as top-level statements in basic
 // blocks, however manual traversal to sub-expressions may encounter them.

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index f52b73dbbdc57..0f731f4532535 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4974,41 +4974,6 @@ TEST(TransferTest, IntegerLiteralEquality) {
   });
 }
 
-TEST(TransferTest, UnsupportedValueEquality) {
-  std::string Code = R"(
-// An explicitly unsupported type by the framework.
-enum class EC {
-  A,
-  B
-};
-  
-void target() {
-  EC ec = EC::A;
-
-  bool unsupported_eq_same = (EC::A == EC::A);
-  bool unsupported_eq_other = (EC::A == EC::B);
-  bool unsupported_eq_var = (ec == EC::B);
-
-  (void)0; // [[p]]
-}
-  )";
-  runDataflow(
-  Code,
-  [](const llvm::StringMap> &Results,
- ASTContext &ASTCtx) {
-const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
-
-// We do not model the values of unsupported types, so this
-// seemingly-trivial case will not be true either.
-EXPECT_TRUE(isa(
-getValueForDecl(ASTCtx, Env, "unsupported_eq_same")));
-EXPECT_TRUE(isa(
-getValueForDecl(ASTCtx, Env, "unsupported_eq_other")));
-EXPECT_TRUE(isa(
-getValueForDecl(ASTCtx, Env, "unsupported_eq_var")));
-  });
-}
-
 TEST(TransferTest, CorrelatedBranches) {
   std::string Code = R"(
 void target(bool B, bool C) {



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


[clang] 6f25614 - [CIR] Clean up warnings (#129604)

2025-03-04 Thread via cfe-commits

Author: Andy Kaylor
Date: 2025-03-04T10:50:06-08:00
New Revision: 6f256145c00cef851b2b439e240fbc3eed9413a6

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

LOG: [CIR] Clean up warnings (#129604)

Previous CIR commits have introduced a few warnings. This change fixes
those.

There are still warnings present when building with GCC because GCC
warns about virtual functions being hidden in the mlir::OpConversion
classes. A separate discussion will be required to decide what should be
done about those.

Added: 


Modified: 
clang/lib/CIR/CodeGen/CIRGenDecl.cpp
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
clang/lib/CIR/CodeGen/CIRGenFunction.cpp
clang/lib/CIR/CodeGen/CIRGenFunction.h

Removed: 




diff  --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp 
b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
index c34d42eff6966..406026b0b9f27 100644
--- a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
@@ -62,7 +62,7 @@ void CIRGenFunction::emitAutoVarInit(const clang::VarDecl &d) 
{
 
 void CIRGenFunction::emitAutoVarCleanups(const clang::VarDecl &d) {
   // Check the type for a cleanup.
-  if (QualType::DestructionKind dtorKind = d.needsDestruction(getContext()))
+  if (d.needsDestruction(getContext()))
 cgm.errorNYI(d.getSourceRange(), "emitAutoVarCleanups: type cleanup");
 
   assert(!cir::MissingFeatures::opAllocaPreciseLifetime());

diff  --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 32fab85cd3db4..b9e56dc4123d6 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -107,6 +107,7 @@ class ScalarExprEmitter : public 
StmtVisitor {
 
 cgf.getCIRGenModule().errorNYI(loc,
"emitScalarConversion for unequal types");
+return {};
   }
 };
 

diff  --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp 
b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
index 7861a48c93244..47d296b70d789 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
@@ -13,6 +13,7 @@
 #include "CIRGenFunction.h"
 
 #include "CIRGenCall.h"
+#include "CIRGenValue.h"
 #include "mlir/IR/Location.h"
 #include "clang/AST/GlobalDecl.h"
 #include "clang/CIR/MissingFeatures.h"
@@ -134,10 +135,9 @@ mlir::Location CIRGenFunction::getLoc(mlir::Location lhs, 
mlir::Location rhs) {
   return mlir::FusedLoc::get(locs, metadata, &getMLIRContext());
 }
 
-mlir::LogicalResult CIRGenFunction::declare(mlir::Value addrVal,
-const Decl *var, QualType ty,
-mlir::Location loc,
-CharUnits alignment, bool isParam) 
{
+void CIRGenFunction::declare(mlir::Value addrVal, const Decl *var, QualType ty,
+ mlir::Location loc, CharUnits alignment,
+ bool isParam) {
   const auto *namedVar = dyn_cast_or_null(var);
   assert(namedVar && "Needs a named decl");
   assert(!cir::MissingFeatures::cgfSymbolTable());
@@ -147,8 +147,6 @@ mlir::LogicalResult CIRGenFunction::declare(mlir::Value 
addrVal,
 allocaOp.setInitAttr(mlir::UnitAttr::get(&getMLIRContext()));
   if (ty->isReferenceType() || ty.isConstQualified())
 allocaOp.setConstantAttr(mlir::UnitAttr::get(&getMLIRContext()));
-
-  return mlir::success();
 }
 
 void CIRGenFunction::startFunction(GlobalDecl gd, QualType returnType,
@@ -306,7 +304,7 @@ LValue CIRGenFunction::emitLValue(const Expr *e) {
 getCIRGenModule().errorNYI(e->getSourceRange(),
std::string("l-value not implemented for '") +
e->getStmtClassName() + "'");
-break;
+return LValue();
   case Expr::DeclRefExprClass:
 return emitDeclRefLValue(cast(e));
   }

diff  --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h 
b/clang/lib/CIR/CodeGen/CIRGenFunction.h
index 6b383378ae764..cf896d3c0a946 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h
@@ -97,9 +97,9 @@ class CIRGenFunction : public CIRGenTypeCache {
 private:
   /// Declare a variable in the current scope, return success if the variable
   /// wasn't declared yet.
-  mlir::LogicalResult declare(mlir::Value addrVal, const clang::Decl *var,
-  clang::QualType ty, mlir::Location loc,
-  clang::CharUnits alignment, bool isParam = 
false);
+  void declare(mlir::Value addrVal, const clang::Decl *var, clang::QualType ty,
+   mlir::Location loc, clang::CharUnits alignment,
+   bool isParam = false);
 
 public:
   mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty,



__

[clang] ee4bc5a - [RISCV] Remove Last Traces of User Interrupts (#129300)

2025-03-04 Thread via cfe-commits

Author: Sam Elliott
Date: 2025-03-04T11:36:16-08:00
New Revision: ee4bc5a8ca94e915a40daddd79237bf3b7520bf9

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

LOG: [RISCV] Remove Last Traces of User Interrupts (#129300)

These were left over from when Craig removed
`__attribute__((interrupt("user")))` support in
05d0caef6081e1a6cb23a5a5afe43dc82e8ca558.

The tests change "interrupt"="user" into "interrupt"="machine" as they
are still intending to be interrupt tests. ISelLowering will now reject
"interrupt"="user". The docs no longer mention "user" as a possible
interrupt attribute argument.

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/lpad.ll
llvm/test/CodeGen/RISCV/push-pop-popret.ll

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 24f795628a763..f44fad95423ee 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2828,8 +2828,8 @@ targets. This attribute may be attached to a function 
definition and instructs
 the backend to generate appropriate function entry/exit code so that it can be
 used directly as an interrupt service routine.
 
-Permissible values for this parameter are ``user``, ``supervisor``,
-and ``machine``. If there is no parameter, then it defaults to machine.
+Permissible values for this parameter are ``supervisor`` and ``machine``. If
+there is no parameter, then it defaults to ``machine``.
 
 Repeated interrupt attribute on the same declaration will cause a warning
 to be emitted. In case of repeated declarations, the last one prevails.

diff  --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 6d3241e79adfe..73f8de7208cbe 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -20831,7 +20831,7 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
 StringRef Kind =
   MF.getFunction().getFnAttribute("interrupt").getValueAsString();
 
-if (!(Kind == "user" || Kind == "supervisor" || Kind == "machine"))
+if (!(Kind == "supervisor" || Kind == "machine"))
   report_fatal_error(
 "Function interrupt attribute argument not supported!");
   }

diff  --git a/llvm/test/CodeGen/RISCV/lpad.ll b/llvm/test/CodeGen/RISCV/lpad.ll
index f5d06f0924c54..93eda6f10eedb 100644
--- a/llvm/test/CodeGen/RISCV/lpad.ll
+++ b/llvm/test/CodeGen/RISCV/lpad.ll
@@ -279,7 +279,7 @@ define internal void @internal2() {
 }
 
 ; Check interrupt function does not need landing pad.
-define void @interrupt() "interrupt"="user" {
+define void @interrupt() "interrupt"="machine" {
 ; CHECK-LABEL: interrupt:
 ; CHECK:   # %bb.0:
 ; CHECK-NEXT:mret

diff  --git a/llvm/test/CodeGen/RISCV/push-pop-popret.ll 
b/llvm/test/CodeGen/RISCV/push-pop-popret.ll
index 1fbdaa76dfb68..65f58d0ecbf24 100644
--- a/llvm/test/CodeGen/RISCV/push-pop-popret.ll
+++ b/llvm/test/CodeGen/RISCV/push-pop-popret.ll
@@ -1769,7 +1769,7 @@ define void @alloca(i32 %n) {
 declare i32 @foo_test_irq(...)
 @var_test_irq = global [32 x i32] zeroinitializer
 
-define void @foo_with_irq() "interrupt"="user" {
+define void @foo_with_irq() "interrupt"="machine" {
 ; RV32IZCMP-LABEL: foo_with_irq:
 ; RV32IZCMP:   # %bb.0:
 ; RV32IZCMP-NEXT:cm.push {ra}, -64
@@ -2273,7 +2273,7 @@ define void @foo_no_irq() {
   ret void
 }
 
-define void @callee_with_irq() "interrupt"="user" {
+define void @callee_with_irq() "interrupt"="machine" {
 ; RV32IZCMP-LABEL: callee_with_irq:
 ; RV32IZCMP:   # %bb.0:
 ; RV32IZCMP-NEXT:cm.push {ra, s0-s11}, -112



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


[clang] [Clang] Bump `__cpp_constexpr` to `202002L` in C++20 mode (PR #129814)

2025-03-04 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja created 
https://github.com/llvm/llvm-project/pull/129814

Per P2493R0 and SD6, `__cpp_constexpr` of value `202002L` indicates that 
P1330R0 "Changing the active member of a union inside constexpr" is 
implemented, which is true for Clang 9 and later.

Fixes #129730.

>From 002490cf1979bbbecef3bc0958ef413f5b85f849 Mon Sep 17 00:00:00 2001
From: "A. Jiang" 
Date: Wed, 5 Mar 2025 09:41:33 +0800
Subject: [PATCH] [Clang] Bump `__cpp_constexpr` to `202002L` in C++20 mode

Per P2493R0 and SD6, `__cpp_constexpr` of value `202002L` indicates
that P1330R0 "Changing the active member of a union inside constexpr"
is implemented, which is true for Clang 9 and later.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/lib/Frontend/InitPreprocessor.cpp | 2 +-
 clang/test/Lexer/cxx-features.cpp   | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37ea963bf337d..9b5bf115694f7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -96,6 +96,9 @@ Resolutions to C++ Defect Reports
 - Implemented `CWG2918 Consideration of constraints for address of overloaded `
   `function `_
 
+- Bumped the ``__cpp_constexpr`` feature-test macro to ``202002L`` in C++20 
mode as indicated in
+  `P2493R0 `_.
+
 C Language Changes
 --
 
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e1dc728558def..1a816cb6269d4 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -664,7 +664,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 Builder.defineMacro("__cpp_lambdas", "200907L");
 Builder.defineMacro("__cpp_constexpr", LangOpts.CPlusPlus26   ? "202406L"
: LangOpts.CPlusPlus23 ? "202211L"
-   : LangOpts.CPlusPlus20 ? "201907L"
+   : LangOpts.CPlusPlus20 ? "202002L"
: LangOpts.CPlusPlus17 ? "201603L"
: LangOpts.CPlusPlus14 ? "201304L"
   : "200704");
diff --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index ff9a1a1210c44..8c1867d5c7365 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -314,7 +314,7 @@
 #error "wrong value for __cpp_lambdas"
 #endif
 
-#if check(constexpr, 0, 200704, 201304, 201603, 201907, 202211, 202406L)
+#if check(constexpr, 0, 200704, 201304, 201603, 202002, 202211, 202406L)
 #error "wrong value for __cpp_constexpr"
 #endif
 

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


[clang] [C++20] [Modules] Support generating in-class defined function with try-catch body (PR #129212)

2025-03-04 Thread Matheus Izvekov via cfe-commits

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

Perfect, TYVM!

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


[clang] [Clang] Don't give up on an unsuccessful function instantiation (PR #126723)

2025-03-04 Thread Younan Zhang via cfe-commits

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

>From 21ca76a13ca62715ce98fb2c8b0361df727769b0 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 11 Feb 2025 17:13:34 +0800
Subject: [PATCH 1/3] [Clang] Don't give up on an unsuccessful function
 instantiation

For constexpr function templates, we immediately instantiate them
upon reference. However, if the function isn't defined at the
point of instantiation, even though it might be defined later,
the instantiation would simply fail.

This patch corrects the behavior by popping up failed instantiations
through PendingInstantiations, so that we are able to instantiate
them again in the future (e.g. at the end of TU.)
---
 clang/include/clang/Sema/Sema.h   | 23 ++---
 clang/lib/Interpreter/IncrementalParser.cpp   |  5 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 47 ---
 .../function-template-specialization.cpp  | 19 +++-
 4 files changed, 67 insertions(+), 27 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 472a0e25adc97..2083a2c2ca40d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13588,12 +13588,16 @@ class Sema final : public SemaBase {
 
   class LocalEagerInstantiationScope {
   public:
-LocalEagerInstantiationScope(Sema &S) : S(S) {
+LocalEagerInstantiationScope(Sema &S, bool AtEndOfTU)
+: S(S), AtEndOfTU(AtEndOfTU) {
   SavedPendingLocalImplicitInstantiations.swap(
   S.PendingLocalImplicitInstantiations);
 }
 
-void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); }
+void perform() {
+  S.PerformPendingInstantiations(/*LocalOnly=*/true,
+ /*AtEndOfTU=*/AtEndOfTU);
+}
 
 ~LocalEagerInstantiationScope() {
   assert(S.PendingLocalImplicitInstantiations.empty() &&
@@ -13604,6 +13608,7 @@ class Sema final : public SemaBase {
 
   private:
 Sema &S;
+bool AtEndOfTU;
 std::deque
 SavedPendingLocalImplicitInstantiations;
   };
@@ -13626,8 +13631,8 @@ class Sema final : public SemaBase {
 
   class GlobalEagerInstantiationScope {
   public:
-GlobalEagerInstantiationScope(Sema &S, bool Enabled)
-: S(S), Enabled(Enabled) {
+GlobalEagerInstantiationScope(Sema &S, bool Enabled, bool AtEndOfTU)
+: S(S), Enabled(Enabled), AtEndOfTU(AtEndOfTU) {
   if (!Enabled)
 return;
 
@@ -13641,7 +13646,8 @@ class Sema final : public SemaBase {
 void perform() {
   if (Enabled) {
 S.DefineUsedVTables();
-S.PerformPendingInstantiations();
+S.PerformPendingInstantiations(/*LocalOnly=*/false,
+   /*AtEndOfTU=*/AtEndOfTU);
   }
 }
 
@@ -13656,7 +13662,8 @@ class Sema final : public SemaBase {
   S.SavedVTableUses.pop_back();
 
   // Restore the set of pending implicit instantiations.
-  if (S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) {
+  if ((S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) &&
+  AtEndOfTU) {
 assert(S.PendingInstantiations.empty() &&
"PendingInstantiations should be empty before it is 
discarded.");
 S.PendingInstantiations.swap(S.SavedPendingInstantiations.back());
@@ -13675,6 +13682,7 @@ class Sema final : public SemaBase {
   private:
 Sema &S;
 bool Enabled;
+bool AtEndOfTU;
   };
 
   ExplicitSpecifier instantiateExplicitSpecifier(
@@ -13860,7 +13868,8 @@ class Sema final : public SemaBase {
 
   /// Performs template instantiation for all implicit template
   /// instantiations we have seen until this point.
-  void PerformPendingInstantiations(bool LocalOnly = false);
+  void PerformPendingInstantiations(bool LocalOnly = false,
+bool AtEndOfTU = true);
 
   TemplateParameterList *
   SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index e43cea1baf43a..41d6304bd5f65 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -41,8 +41,9 @@ llvm::Expected
 IncrementalParser::ParseOrWrapTopLevelDecl() {
   // Recover resources if we crash before exiting this method.
   llvm::CrashRecoveryContextCleanupRegistrar CleanupSema(&S);
-  Sema::GlobalEagerInstantiationScope GlobalInstantiations(S, 
/*Enabled=*/true);
-  Sema::LocalEagerInstantiationScope LocalInstantiations(S);
+  Sema::GlobalEagerInstantiationScope GlobalInstantiations(S, /*Enabled=*/true,
+   /*AtEndOfTU=*/true);
+  Sema::LocalEagerInstantiationScope LocalInstantiations(S, 
/*AtEndOfTU=*/true);
 
   // Add a new PTU.
   ASTContext &C = S.getASTContext();
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/

[clang] c1468e9 - [Clang] Don't give up on an unsuccessful function instantiation (#126723)

2025-03-04 Thread via cfe-commits

Author: Younan Zhang
Date: 2025-03-05T11:50:37+08:00
New Revision: c1468e9cbca1002a24772af1a0e7a771f93f6910

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

LOG: [Clang] Don't give up on an unsuccessful function instantiation (#126723)

For constexpr function templates, we immediately instantiate them upon
reference. However, if the function isn't defined at the time of
instantiation, even though it might be defined later, the instantiation
would forever fail.

This patch corrects the behavior by popping up failed instantiations
through PendingInstantiations, so that we are able to instantiate them
again in the future (e.g. at the end of TU.)

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Interpreter/IncrementalParser.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/CodeGenCXX/function-template-specialization.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37ea963bf337d..5098e5e983103 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -264,6 +264,8 @@ Bug Fixes to C++ Support
 - Clang is now better at keeping track of friend function template instance 
contexts. (#GH55509)
 - Clang now prints the correct instantiation context for diagnostics suppressed
   by template argument deduction.
+- Clang is now better at instantiating the function definition after its use 
inside
+  of a constexpr lambda. (#GH125747)
 - The initialization kind of elements of structured bindings
   direct-list-initialized from an array is corrected to direct-initialization.
 - Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. 
(#GH127327)

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2da5f5e311fc7..80177996b48b0 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13657,12 +13657,16 @@ class Sema final : public SemaBase {
 
   class LocalEagerInstantiationScope {
   public:
-LocalEagerInstantiationScope(Sema &S) : S(S) {
+LocalEagerInstantiationScope(Sema &S, bool AtEndOfTU)
+: S(S), AtEndOfTU(AtEndOfTU) {
   SavedPendingLocalImplicitInstantiations.swap(
   S.PendingLocalImplicitInstantiations);
 }
 
-void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); }
+void perform() {
+  S.PerformPendingInstantiations(/*LocalOnly=*/true,
+ /*AtEndOfTU=*/AtEndOfTU);
+}
 
 ~LocalEagerInstantiationScope() {
   assert(S.PendingLocalImplicitInstantiations.empty() &&
@@ -13673,6 +13677,7 @@ class Sema final : public SemaBase {
 
   private:
 Sema &S;
+bool AtEndOfTU;
 std::deque
 SavedPendingLocalImplicitInstantiations;
   };
@@ -13695,8 +13700,8 @@ class Sema final : public SemaBase {
 
   class GlobalEagerInstantiationScope {
   public:
-GlobalEagerInstantiationScope(Sema &S, bool Enabled)
-: S(S), Enabled(Enabled) {
+GlobalEagerInstantiationScope(Sema &S, bool Enabled, bool AtEndOfTU)
+: S(S), Enabled(Enabled), AtEndOfTU(AtEndOfTU) {
   if (!Enabled)
 return;
 
@@ -13710,7 +13715,8 @@ class Sema final : public SemaBase {
 void perform() {
   if (Enabled) {
 S.DefineUsedVTables();
-S.PerformPendingInstantiations();
+S.PerformPendingInstantiations(/*LocalOnly=*/false,
+   /*AtEndOfTU=*/AtEndOfTU);
   }
 }
 
@@ -13725,7 +13731,8 @@ class Sema final : public SemaBase {
   S.SavedVTableUses.pop_back();
 
   // Restore the set of pending implicit instantiations.
-  if (S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) {
+  if ((S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) &&
+  AtEndOfTU) {
 assert(S.PendingInstantiations.empty() &&
"PendingInstantiations should be empty before it is 
discarded.");
 S.PendingInstantiations.swap(S.SavedPendingInstantiations.back());
@@ -13744,6 +13751,7 @@ class Sema final : public SemaBase {
   private:
 Sema &S;
 bool Enabled;
+bool AtEndOfTU;
   };
 
   ExplicitSpecifier instantiateExplicitSpecifier(
@@ -13929,7 +13937,8 @@ class Sema final : public SemaBase {
 
   /// Performs template instantiation for all implicit template
   /// instantiations we have seen until this point.
-  void PerformPendingInstantiations(bool LocalOnly = false);
+  void PerformPendingInstantiations(bool LocalOnly = false,
+bool AtEndOfTU = true);
 
   TemplateParameterList *
   SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,

[clang] [clang dependency scanning] Make Current Working Directory Optimization Off by Default (PR #129809)

2025-03-04 Thread Michael Spencer via cfe-commits

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

Looks good with the added comment.

I was going to say this should also update the documentation, but we don't 
actually have any here. This patch doesn't need to add it, but it would be good 
to have some documentation on how to actually use clang-scan-deps and the 
scanning API.

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


[clang] [clang dependency scanning] Make Current Working Directory Optimization Off by Default (PR #129809)

2025-03-04 Thread Michael Spencer via cfe-commits

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


[clang] [clang dependency scanning] Make Current Working Directory Optimization Off by Default (PR #129809)

2025-03-04 Thread Michael Spencer via cfe-commits


@@ -67,7 +67,7 @@ enum class ScanningOptimizations {
   IgnoreCWD = (1 << 4),
 
   DSS_LAST_BITMASK_ENUM(IgnoreCWD),
-  Default = All
+  Default = All & (~IgnoreCWD)

Bigcheese wrote:

I think there should be a comment here with basically what you said in the 
commit message to explain why this is off by default.

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


[clang] [clang][deps] Remove dependency on llvm targets from lib DependencyScanning (PR #129774)

2025-03-04 Thread Michael Spencer via cfe-commits

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


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


[clang] [C++20] [Modules] Support generating in-class defined function with try-catch body (PR #129212)

2025-03-04 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> > Thanks, LGTM.
> > With just a little more effort you could add the EOF stuff in there too.
> 
> What do you mean by EOF stuff?

It seems you can deduplicate by moving this block into the scope guard:
```C++
  while (Tok.isNot(tok::eof))
ConsumeAnyToken();
  if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
ConsumeAnyToken();
```

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


[clang] [C++20] [Modules] Support generating in-class defined function with try-catch body (PR #129212)

2025-03-04 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/129212

>From 8876ef70a08f8547d49b89275a3b1b455221abd0 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Fri, 28 Feb 2025 17:03:49 +0800
Subject: [PATCH 1/3] [C++20] [Modules] Support generating in-class defined
 function with try-catch body

See the example:

```
export module func;
class C {
public:
void member() try {

} catch (...) {

}
};
```

We woudln't generate the definition for `C::member` but we should. Since
the function is non-inline in modules.

This turns out to be an oversight in parser to me. Since the try-catch
body is relatively rare, so maybe we just forgot it.
---
 clang/lib/Parse/ParseCXXInlineMethods.cpp |  5 +
 clang/test/Modules/try-func-body.cppm | 13 +
 2 files changed, 18 insertions(+)
 create mode 100644 clang/test/Modules/try-func-body.cppm

diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp 
b/clang/lib/Parse/ParseCXXInlineMethods.cpp
index 6c01af55ef3c4..723ebfa59fc03 100644
--- a/clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -632,6 +632,11 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) {
 
 if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
   ConsumeAnyToken();
+
+if (auto *FD = dyn_cast_or_null(LM.D))
+  if (isa(FD) ||
+  FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend))
+Actions.ActOnFinishInlineFunctionDef(FD);
 return;
   }
   if (Tok.is(tok::colon)) {
diff --git a/clang/test/Modules/try-func-body.cppm 
b/clang/test/Modules/try-func-body.cppm
new file mode 100644
index 0..379f5e47f4f8e
--- /dev/null
+++ b/clang/test/Modules/try-func-body.cppm
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++20 %s -fexceptions -fcxx-exceptions -emit-llvm 
-triple %itanium_abi_triple -o - | FileCheck %s
+
+export module func;
+class C {
+public:
+void member() try {
+
+} catch (...) {
+
+}
+};
+
+// CHECK: define {{.*}}@_ZNW4func1C6memberEv

>From deb965a5ff5e94dcd860cd6c28ecbafda90ae3cf Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Tue, 4 Mar 2025 10:05:26 +0800
Subject: [PATCH 2/3] Update

---
 clang/lib/Parse/ParseCXXInlineMethods.cpp | 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp 
b/clang/lib/Parse/ParseCXXInlineMethods.cpp
index 723ebfa59fc03..3b440743a4c59 100644
--- a/clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -17,6 +17,7 @@
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
 #include "clang/Sema/Scope.h"
+#include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
 
@@ -624,6 +625,13 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) {
 
   Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D);
 
+  auto _ = llvm::make_scope_exit([&]() {
+if (auto *FD = dyn_cast_or_null(LM.D))
+  if (isa(FD) ||
+  FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend))
+Actions.ActOnFinishInlineFunctionDef(FD);
+  });
+
   if (Tok.is(tok::kw_try)) {
 ParseFunctionTryBlock(LM.D, FnScope);
 
@@ -632,11 +640,6 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) {
 
 if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
   ConsumeAnyToken();
-
-if (auto *FD = dyn_cast_or_null(LM.D))
-  if (isa(FD) ||
-  FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend))
-Actions.ActOnFinishInlineFunctionDef(FD);
 return;
   }
   if (Tok.is(tok::colon)) {
@@ -671,11 +674,6 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) {
 
   if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
 ConsumeAnyToken();
-
-  if (auto *FD = dyn_cast_or_null(LM.D))
-if (isa(FD) ||
-FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend))
-  Actions.ActOnFinishInlineFunctionDef(FD);
 }
 
 /// ParseLexedMemberInitializers - We finished parsing the member specification

>From debbd847ec414c84d6c120f9e08e3371e5eea34e Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 5 Mar 2025 10:10:41 +0800
Subject: [PATCH 3/3] Update

---
 clang/lib/Parse/ParseCXXInlineMethods.cpp | 24 ++-
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp 
b/clang/lib/Parse/ParseCXXInlineMethods.cpp
index 3b440743a4c59..b1064eb02b907 100644
--- a/clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -626,6 +626,12 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) {
   Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D);
 
   auto _ = llvm::make_scope_exit([&]() {
+while (Tok.isNot(tok::eof))
+  ConsumeAnyToken();
+
+if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
+  ConsumeAnyToken();
+
 if (auto *FD = dyn_cast_or_null(LM.D))
   if (isa(FD) ||
   FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend))
@@ -634,12 +640,6 @@ void Parser::Par

[clang] [llvm] [RISCV] Mark {vl, vtype} as clobber in inline assembly (PR #128636)

2025-03-04 Thread Hank Chang via cfe-commits

HankChang736 wrote:

I tried the test case below without passing 'v' extension in Clang command line 
argument.
`__attribute__((target("zve32x")))
void test_A(int *p) {
  asm volatile("" :: "A"(*p));
}
`
The generated LLVM IR result is :
`; Function Attrs: nounwind
define dso_local void @test_A(ptr noundef %p) local_unnamed_addr #0 {
entry:
  tail call void asm sideeffect "", "*A"(ptr elementtype(i32) %p) #1, !srcloc !6
  ret void
}
`

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


[clang] [Clang] Bump `__cpp_constexpr` to `202002L` in C++20 mode (PR #129814)

2025-03-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: A. Jiang (frederick-vs-ja)


Changes

Per P2493R0 and SD6, `__cpp_constexpr` of value `202002L` indicates that 
P1330R0 "Changing the active member of a union inside constexpr" is 
implemented, which is true for Clang 9 and later.

Fixes #129730.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+1-1) 
- (modified) clang/test/Lexer/cxx-features.cpp (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37ea963bf337d..9b5bf115694f7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -96,6 +96,9 @@ Resolutions to C++ Defect Reports
 - Implemented `CWG2918 Consideration of constraints for address of overloaded `
   `function `_
 
+- Bumped the ``__cpp_constexpr`` feature-test macro to ``202002L`` in C++20 
mode as indicated in
+  `P2493R0 `_.
+
 C Language Changes
 --
 
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e1dc728558def..1a816cb6269d4 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -664,7 +664,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 Builder.defineMacro("__cpp_lambdas", "200907L");
 Builder.defineMacro("__cpp_constexpr", LangOpts.CPlusPlus26   ? "202406L"
: LangOpts.CPlusPlus23 ? "202211L"
-   : LangOpts.CPlusPlus20 ? "201907L"
+   : LangOpts.CPlusPlus20 ? "202002L"
: LangOpts.CPlusPlus17 ? "201603L"
: LangOpts.CPlusPlus14 ? "201304L"
   : "200704");
diff --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index ff9a1a1210c44..8c1867d5c7365 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -314,7 +314,7 @@
 #error "wrong value for __cpp_lambdas"
 #endif
 
-#if check(constexpr, 0, 200704, 201304, 201603, 201907, 202211, 202406L)
+#if check(constexpr, 0, 200704, 201304, 201603, 202002, 202211, 202406L)
 #error "wrong value for __cpp_constexpr"
 #endif
 

``




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


[clang] [C++20] [Modules] Support generating in-class defined function with try-catch body (PR #129212)

2025-03-04 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > > Thanks, LGTM.
> > > With just a little more effort you could add the EOF stuff in there too.
> > 
> > 
> > What do you mean by EOF stuff?
> 
> It seems you can deduplicate by moving this block into the scope guard:
> 
> ```c++
>   while (Tok.isNot(tok::eof))
> ConsumeAnyToken();
>   if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
> ConsumeAnyToken();
> ```

Done

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


[clang] 68427bc - [C++20] [Modules] Support generating in-class defined function with try-catch body (#129212)

2025-03-04 Thread via cfe-commits

Author: Chuanqi Xu
Date: 2025-03-05T10:32:19+08:00
New Revision: 68427bc8d808a8f70ed345278fc498a1e0b5a8d2

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

LOG: [C++20] [Modules] Support generating in-class defined function with 
try-catch body (#129212)

See the example:

```
export module func;
class C {
public:
void member() try {

} catch (...) {

}
};
```

We woudln't generate the definition for `C::member` but we should. Since
the function is non-inline in modules.

This turns out to be an oversight in parser to me. Since the try-catch
body is relatively rare, so maybe we just forgot it.

Added: 
clang/test/Modules/try-func-body.cppm

Modified: 
clang/lib/Parse/ParseCXXInlineMethods.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp 
b/clang/lib/Parse/ParseCXXInlineMethods.cpp
index 6c01af55ef3c4..b1064eb02b907 100644
--- a/clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -17,6 +17,7 @@
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
 #include "clang/Sema/Scope.h"
+#include "llvm/ADT/ScopeExit.h"
 
 using namespace clang;
 
@@ -624,14 +625,21 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) {
 
   Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D);
 
-  if (Tok.is(tok::kw_try)) {
-ParseFunctionTryBlock(LM.D, FnScope);
-
+  auto _ = llvm::make_scope_exit([&]() {
 while (Tok.isNot(tok::eof))
   ConsumeAnyToken();
 
 if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
   ConsumeAnyToken();
+
+if (auto *FD = dyn_cast_or_null(LM.D))
+  if (isa(FD) ||
+  FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend))
+Actions.ActOnFinishInlineFunctionDef(FD);
+  });
+
+  if (Tok.is(tok::kw_try)) {
+ParseFunctionTryBlock(LM.D, FnScope);
 return;
   }
   if (Tok.is(tok::colon)) {
@@ -641,12 +649,6 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) {
 if (!Tok.is(tok::l_brace)) {
   FnScope.Exit();
   Actions.ActOnFinishFunctionBody(LM.D, nullptr);
-
-  while (Tok.isNot(tok::eof))
-ConsumeAnyToken();
-
-  if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
-ConsumeAnyToken();
   return;
 }
   } else
@@ -660,17 +662,6 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) {
  "current template being instantiated!");
 
   ParseFunctionStatementBody(LM.D, FnScope);
-
-  while (Tok.isNot(tok::eof))
-ConsumeAnyToken();
-
-  if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
-ConsumeAnyToken();
-
-  if (auto *FD = dyn_cast_or_null(LM.D))
-if (isa(FD) ||
-FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend))
-  Actions.ActOnFinishInlineFunctionDef(FD);
 }
 
 /// ParseLexedMemberInitializers - We finished parsing the member specification

diff  --git a/clang/test/Modules/try-func-body.cppm 
b/clang/test/Modules/try-func-body.cppm
new file mode 100644
index 0..379f5e47f4f8e
--- /dev/null
+++ b/clang/test/Modules/try-func-body.cppm
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++20 %s -fexceptions -fcxx-exceptions -emit-llvm 
-triple %itanium_abi_triple -o - | FileCheck %s
+
+export module func;
+class C {
+public:
+void member() try {
+
+} catch (...) {
+
+}
+};
+
+// CHECK: define {{.*}}@_ZNW4func1C6memberEv



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


[clang] [C++20] [Modules] Support generating in-class defined function with try-catch body (PR #129212)

2025-03-04 Thread Chuanqi Xu via cfe-commits

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


[clang] [C++20] [Modules] Support generating in-class defined function with try-catch body (PR #129212)

2025-03-04 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-armv8-quick` running 
on `linaro-clang-armv8-quick` while building `clang` at step 5 "ninja check 1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Clangd Unit Tests :: ./ClangdTests/49/161' FAILED 

Script(shard):
--
GTEST_OUTPUT=json:/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests-Clangd
 Unit Tests-2252840-49-161.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=161 
GTEST_SHARD_INDEX=49 
/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests
--

Note: This is test shard 50 of 161.
[==] Running 8 tests from 8 test suites.
[--] Global test environment set-up.
[--] 1 test from ClangdServerTest
[ RUN  ] ClangdServerTest.ForceReparseCompileCommand
ASTWorker building file /clangd-test/foo.cpp version null with command 
[/clangd-test]
clang -xc /clangd-test/foo.cpp
Driver produced command: cc1 -cc1 -triple armv8a-unknown-linux-gnueabihf 
-fsyntax-only -disable-free -clear-ast-before-backend -main-file-name foo.cpp 
-mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all 
-fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases 
-target-cpu generic -target-feature +read-tp-tpidruro -target-feature +vfp2 
-target-feature +vfp2sp -target-feature +vfp3 -target-feature +vfp3d16 
-target-feature +vfp3d16sp -target-feature +vfp3sp -target-feature +fp16 
-target-feature +vfp4 -target-feature +vfp4d16 -target-feature +vfp4d16sp 
-target-feature +vfp4sp -target-feature +fp-armv8 -target-feature +fp-armv8d16 
-target-feature +fp-armv8d16sp -target-feature +fp-armv8sp -target-feature 
-fullfp16 -target-feature +fp64 -target-feature +d32 -target-feature +neon 
-target-feature +sha2 -target-feature +aes -target-feature -fp16fml -target-abi 
aapcs-linux -mfloat-abi hard -debugger-tuning=gdb 
-fdebug-compilation-dir=/clangd-test -fcoverage-compilation-dir=/clangd-test 
-resource-dir lib/clang/21 -internal-isystem lib/clang/21/include 
-internal-isystem /usr/local/include -internal-externc-isystem /include 
-internal-externc-isystem /usr/include -ferror-limit 19 -fno-signed-char 
-fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -no-round-trip-args -faddrsig -x c 
/clangd-test/foo.cpp
Building first preamble for /clangd-test/foo.cpp version null
Built preamble of size 408800 for file /clangd-test/foo.cpp version null in 
6.57 seconds
not idle after addDocument
UNREACHABLE executed at 
../llvm/clang-tools-extra/clangd/unittests/SyncAPI.cpp:22!
#0 0x01355fd4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests+0xaabfd4)
#1 0x013539c4 llvm::sys::RunSignalHandlers() 
(/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests+0xaa99c4)
#2 0x0135689c SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0xf759d6f0 __default_rt_sa_restorer 
./signal/../sysdeps/unix/sysv/linux/arm/sigrestorer.S:80:0
#4 0xf758db06 ./csu/../sysdeps/unix/sysv/linux/arm/libc-do-syscall.S:47:0
#5 0xf75cd292 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#6 0xf759c840 gsignal ./signal/../sysdeps/posix/raise.c:27:6

--
exit: -6
--
shard JSON output does not exist: 
/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests-Clangd
 Unit Tests-2252840-49-161.json



```



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


[clang] [clang dependency scanning] Make Current Working Directory Optimization Off by Default (PR #129809)

2025-03-04 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu updated 
https://github.com/llvm/llvm-project/pull/129809

>From 2037abd8cb44be6a70850225626d9fde4b8058f2 Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Tue, 4 Mar 2025 16:48:20 -0800
Subject: [PATCH 1/2] Update ScanningOptimizations's default so CWD
 optimization is off.

---
 .../DependencyScanning/DependencyScanningService.h |  2 +-
 clang/test/ClangScanDeps/modules-context-hash-cwd.c| 10 +-
 clang/test/ClangScanDeps/modules-debug-dir.c   |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
index f002f8645d3f6..b22ba0b1c1dea 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
@@ -67,7 +67,7 @@ enum class ScanningOptimizations {
   IgnoreCWD = (1 << 4),
 
   DSS_LAST_BITMASK_ENUM(IgnoreCWD),
-  Default = All
+  Default = All & (~IgnoreCWD)
 };
 
 #undef DSS_LAST_BITMASK_ENUM
diff --git a/clang/test/ClangScanDeps/modules-context-hash-cwd.c 
b/clang/test/ClangScanDeps/modules-context-hash-cwd.c
index 459d2c90debe6..c609a7dcbc80e 100644
--- a/clang/test/ClangScanDeps/modules-context-hash-cwd.c
+++ b/clang/test/ClangScanDeps/modules-context-hash-cwd.c
@@ -9,14 +9,14 @@
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb3.json.in > %t/cdb3.json
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb4.json.in > %t/cdb4.json
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb5.json.in > %t/cdb5.json
-// RUN: clang-scan-deps -compilation-database %t/cdb0.json -format 
experimental-full > %t/result0.json
-// RUN: clang-scan-deps -compilation-database %t/cdb1.json -format 
experimental-full > %t/result1.json
+// RUN: clang-scan-deps -compilation-database %t/cdb0.json -format 
experimental-full -optimize-args=all > %t/result0.json
+// RUN: clang-scan-deps -compilation-database %t/cdb1.json -format 
experimental-full -optimize-args=all > %t/result1.json
 // It is not a typo to use cdb1.json for result2. We intend to use the same
 // compilation database, but different clang-scan-deps optimize-args options.
 // RUN: clang-scan-deps -compilation-database %t/cdb1.json -format 
experimental-full 
-optimize-args=header-search,system-warnings,vfs,canonicalize-macros > 
%t/result2.json
-// RUN: clang-scan-deps -compilation-database %t/cdb3.json -format 
experimental-full > %t/result3.json
-// RUN: clang-scan-deps -compilation-database %t/cdb4.json -format 
experimental-full > %t/result4.json
-// RUN: clang-scan-deps -compilation-database %t/cdb5.json -format 
experimental-full > %t/result5.json
+// RUN: clang-scan-deps -compilation-database %t/cdb3.json -format 
experimental-full -optimize-args=all > %t/result3.json
+// RUN: clang-scan-deps -compilation-database %t/cdb4.json -format 
experimental-full -optimize-args=all > %t/result4.json
+// RUN: clang-scan-deps -compilation-database %t/cdb5.json -format 
experimental-full -optimize-args=all > %t/result5.json
 // RUN: cat %t/result0.json %t/result1.json | FileCheck %s
 // RUN: cat %t/result0.json %t/result2.json | FileCheck %s 
-check-prefix=SKIPOPT
 // RUN: cat %t/result3.json %t/result4.json | FileCheck %s 
-check-prefix=RELPATH
diff --git a/clang/test/ClangScanDeps/modules-debug-dir.c 
b/clang/test/ClangScanDeps/modules-debug-dir.c
index fadec1ad52e35..c4fb4982ed791 100644
--- a/clang/test/ClangScanDeps/modules-debug-dir.c
+++ b/clang/test/ClangScanDeps/modules-debug-dir.c
@@ -4,7 +4,7 @@
 // RUN: split-file %s %t
 // RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format \
-// RUN:   experimental-full > %t/result.json
+// RUN:   experimental-full -optimize-args=all > %t/result.json
 // RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s
 
 //--- cdb.json.in

>From 41f7ca51ebf204f419e67a2b1e921a61cf1b9547 Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Tue, 4 Mar 2025 18:59:36 -0800
Subject: [PATCH 2/2] Adding comments explaining the default behaviour.

---
 .../Tooling/DependencyScanning/DependencyScanningService.h| 4 
 1 file changed, 4 insertions(+)

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
index b22ba0b1c1dea..816e122eb3003 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
@@ -67,6 +67,10 @@ enum class ScanningOptimizations {
   IgnoreCWD = (1 << 4),
 
   DSS_LAST_BITMASK_ENUM(IgnoreCWD),
+
+  // The build system needs to be aware that the current working
+  // directory is ignored. Without a good way of notifying the build
+  // system, it is less risky to default to off.
   Default = All & (~IgnoreCWD)
 };
 

_

[clang] [clang dependency scanning] Make Current Working Directory Optimization Off by Default (PR #129809)

2025-03-04 Thread Qiongsi Wu via cfe-commits


@@ -67,7 +67,7 @@ enum class ScanningOptimizations {
   IgnoreCWD = (1 << 4),
 
   DSS_LAST_BITMASK_ENUM(IgnoreCWD),
-  Default = All
+  Default = All & (~IgnoreCWD)

qiongsiwu wrote:

Comments added. 

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-04 Thread Shafik Yaghmour via cfe-commits

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-04 Thread Shafik Yaghmour via cfe-commits


@@ -5450,10 +5450,20 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl 
*Constructor, bool AnyErrors,
NumInitializers * sizeof(CXXCtorInitializer*));
 Constructor->setCtorInitializers(baseOrMemberInitializers);
 
+SourceLocation Location = Constructor->getLocation();
+
 // Constructors implicitly reference the base and member
 // destructors.
-MarkBaseAndMemberDestructorsReferenced(Constructor->getLocation(),
-   Constructor->getParent());
+
+for (CXXCtorInitializer *Initializer : Info.AllToInit) {
+  FieldDecl *Field = Initializer->getAnyMember();
+  if (!Field)
+continue;
+
+  MarkFieldDestructorReferenced(Location, Field);

shafik wrote:

We should include a standard reference here, I believe the correct reference 
would be: https://eel.is/c++draft/class.base.init#12

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-04 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

This requires a release note, especially b/c this is a conformance fix.

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


[clang] [Sema] Instantiate destructors for initialized anonymous union fields (PR #128866)

2025-03-04 Thread Shafik Yaghmour via cfe-commits


@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+namespace t1{
+template  struct VSX {
+  ~VSX() { static_assert(sizeof(T) != 4, ""); } // expected-error {{static 
assertion failed due to requirement 'sizeof(int) != 4':}} \
+// expected-note {{expression 
evaluates to '4 != 4'}}
+};
+struct VS {
+  union {
+VSX _Tail;
+  };
+  ~VS() { }
+  VS(short);
+};
+VS::VS(short) : _Tail() { } // expected-note {{in instantiation of member 
function 't1::VSX::~VSX' requested here}}

shafik wrote:

Based on https://eel.is/c++draft/class.base.init#12 this should not apply to 
delegating constructors, can we add a test if once does not exist that verifies 
this.

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


[clang] [llvm] [RISCV] Mark {vl, vtype} as clobber in inline assembly (PR #128636)

2025-03-04 Thread Pengcheng Wang via cfe-commits

wangpc-pp wrote:

I am not familiar with the target attribute implementation, can we get the list 
of function features here and add the clobbers at: 
https://github.com/llvm/llvm-project/blob/6d93280aabc2fd132f54e5aa615d25abeadabe7b/clang/lib/CodeGen/CGStmt.cpp#L3087-L3093
cc @topperc @4vtomat 

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


[clang] [clang][CodeGen][OpenCL] Fix `alloca` handling (PR #113930)

2025-03-04 Thread Matt Arsenault via cfe-commits


@@ -103,11 +103,15 @@ RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type 
*Ty, CharUnits Align,
   if (AllocaAddr)
 *AllocaAddr = Alloca;
   llvm::Value *V = Alloca.getPointer();
+  assert((!getLangOpts().OpenCL ||
+  CGM.getTarget().getTargetAddressSpace(getASTAllocaAddressSpace()) ==
+  CGM.getTarget().getTargetAddressSpace(LangAS::opencl_private)) &&
+ "For OpenCL allocas must allocate in the private address space!");
   // Alloca always returns a pointer in alloca address space, which may
   // be different from the type defined by the language. For example,
   // in C++ the auto variables are in the default address space. Therefore
   // cast alloca to the default address space when necessary.
-  if (getASTAllocaAddressSpace() != LangAS::Default) {
+  if (!getLangOpts().OpenCL && getASTAllocaAddressSpace() != LangAS::Default) {

arsenm wrote:

This whole casting block should be deleted. A memory temporary should be the 
natural alloca type. Any user that wants the cast should handle this in the 
narrow use case.

This cannot be language dependent. The current behavior is ABI breaking for 
aggregates passed on the stack (see the device enqueue tests for an example, 
the byref temporary argument is broken to be a flat pointer). We are also just 
creating a lot of unnecessary casting spam for later passes to clean up in most 
contexts 

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


[clang] [HLSL] Reorganize aliased intrinsics into their own file (PR #129619)

2025-03-04 Thread Farzon Lotfi via cfe-commits

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


[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-04 Thread Madhur Amilkanthwar via cfe-commits


@@ -7380,12 +7380,27 @@ bool 
AArch64DAGToDAGISel::SelectAddrModeIndexedSVE(SDNode *Root, SDValue N,
 return false;
 
   SDValue VScale = N.getOperand(1);
-  if (VScale.getOpcode() != ISD::VSCALE)
+  int64_t MulImm = std::numeric_limits::max();
+  if (VScale.getOpcode() == ISD::VSCALE)

madhur13490 wrote:

This should be enclosed in `{}` to keep it unified with the `else` block per 
coding standards 
[guidelines](https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements).

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


[clang] [llvm] [RISCV] Mark {vl, vtype} as clobber in inline assembly (PR #128636)

2025-03-04 Thread Pengcheng Wang via cfe-commits

wangpc-pp wrote:

> > I am not familiar with the target attribute implementation, can we get the 
> > list of function features here and add the clobbers at:
> > https://github.com/llvm/llvm-project/blob/6d93280aabc2fd132f54e5aa615d25abeadabe7b/clang/lib/CodeGen/CGStmt.cpp#L3087-L3093
> > 
> > cc @topperc @4vtomat
> 
> I'm not sure. But I don't understand why we need to check for Zve32x at all?

Just see the previous discussion, it is weird to add vector CSRs to clobbers if 
no vector support.

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