[clang] [clang] return first Decl for CanonicalDecl in TranslationUnitDecl (PR #110101)
github-actions[bot] wrote: @Vipul-Cariappa Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/110101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 61c8b71 - [clang] return first Decl for CanonicalDecl in TranslationUnitDecl (#110101)
Author: Vipul Cariappa Date: 2024-09-27T10:03:32+03:00 New Revision: 61c8b7159a740d43a6a0fa52756eb479e1a9c1c3 URL: https://github.com/llvm/llvm-project/commit/61c8b7159a740d43a6a0fa52756eb479e1a9c1c3 DIFF: https://github.com/llvm/llvm-project/commit/61c8b7159a740d43a6a0fa52756eb479e1a9c1c3.diff LOG: [clang] return first Decl for CanonicalDecl in TranslationUnitDecl (#110101) Return the first `Decl` when using `TranslationUnitDecl::getCanonicalDecl` Added: Modified: clang/include/clang/AST/Decl.h clang/unittests/Interpreter/InterpreterTest.cpp Removed: diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 0600ecc4d14a18..7ff35d73df5997 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -133,6 +133,10 @@ class TranslationUnitDecl : public Decl, static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) { return static_cast(const_cast(DC)); } + + /// Retrieves the canonical declaration of this translation unit. + TranslationUnitDecl *getCanonicalDecl() override { return getFirstDecl(); } + const TranslationUnitDecl *getCanonicalDecl() const { return getFirstDecl(); } }; /// Represents a `#pragma comment` line. Always a child of diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp index a2e960f1431117..30b051e747f928 100644 --- a/clang/unittests/Interpreter/InterpreterTest.cpp +++ b/clang/unittests/Interpreter/InterpreterTest.cpp @@ -381,4 +381,26 @@ TEST_F(InterpreterTest, Value) { EXPECT_TRUE(V9.isManuallyAlloc()); } +TEST_F(InterpreterTest, TranslationUnit_CanonicalDecl) { + std::vector Args; + std::unique_ptr Interp = createInterpreter(Args); + + Sema &sema = Interp->getCompilerInstance()->getSema(); + + llvm::cantFail(Interp->ParseAndExecute("int x = 42;")); + + TranslationUnitDecl *TU = + sema.getASTContext().getTranslationUnitDecl()->getCanonicalDecl(); + + llvm::cantFail(Interp->ParseAndExecute("long y = 84;")); + + EXPECT_EQ(TU, +sema.getASTContext().getTranslationUnitDecl()->getCanonicalDecl()); + + llvm::cantFail(Interp->ParseAndExecute("char z = 'z';")); + + EXPECT_EQ(TU, +sema.getASTContext().getTranslationUnitDecl()->getCanonicalDecl()); +} + } // end anonymous namespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] WebKit Checkers should set DeclWithIssue. (PR #109389)
https://github.com/rniwa closed https://github.com/llvm/llvm-project/pull/109389 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] return first Decl for CanonicalDecl in TranslationUnitDecl (PR #110101)
https://github.com/vgvassilev approved this pull request. Lgtm! https://github.com/llvm/llvm-project/pull/110101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] return first Decl for CanonicalDecl in TranslationUnitDecl (PR #110101)
https://github.com/vgvassilev closed https://github.com/llvm/llvm-project/pull/110101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CGExpr] Avoid Type::getPointerTo() (NFC) (PR #110209)
https://github.com/JOE1994 closed https://github.com/llvm/llvm-project/pull/110209 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 880ee48 - [clang][CGExpr] Avoid Type::getPointerTo() (NFC) (#110209)
Author: Youngsuk Kim Date: 2024-09-27T03:07:44-04:00 New Revision: 880ee48d5c9d88be1c611451e84f16eafcebd1a6 URL: https://github.com/llvm/llvm-project/commit/880ee48d5c9d88be1c611451e84f16eafcebd1a6 DIFF: https://github.com/llvm/llvm-project/commit/880ee48d5c9d88be1c611451e84f16eafcebd1a6.diff LOG: [clang][CGExpr] Avoid Type::getPointerTo() (NFC) (#110209) `Type::getPointerTo()` is to be removed soon. This also removes the whole code section for "C99 6.5.2.2p6"; It's essentially a no-op since llvm uses opaque pointers. Added: Modified: clang/lib/CodeGen/CGExpr.cpp Removed: diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 9166db4c74128c..df4994ba9af6e1 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -122,7 +122,7 @@ RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, CharUnits Align, Builder.SetInsertPoint(getPostAllocaInsertPoint()); V = getTargetHooks().performAddrSpaceCast( *this, V, getASTAllocaAddressSpace(), LangAS::Default, -Ty->getPointerTo(DestAddrSpace), /*non-null*/ true); +Builder.getPtrTy(DestAddrSpace), /*non-null*/ true); } return RawAddress(V, Ty, Align, KnownNonNull); @@ -469,7 +469,8 @@ static RawAddress createReferenceTemporary(CodeGenFunction &CGF, if (AS != LangAS::Default) C = TCG.performAddrSpaceCast( CGF.CGM, GV, AS, LangAS::Default, - GV->getValueType()->getPointerTo( + llvm::PointerType::get( + CGF.getLLVMContext(), CGF.getContext().getTargetAddressSpace(LangAS::Default))); // FIXME: Should we put the new global into a COMDAT? return RawAddress(C, GV->getValueType(), alignment); @@ -3207,7 +3208,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { if (AS != T.getAddressSpace()) { auto TargetAS = getContext().getTargetAddressSpace(T.getAddressSpace()); - auto PtrTy = ATPO.getElementType()->getPointerTo(TargetAS); + auto PtrTy = llvm::PointerType::get(CGM.getLLVMContext(), TargetAS); auto ASC = getTargetHooks().performAddrSpaceCast( CGM, ATPO.getPointer(), AS, T.getAddressSpace(), PtrTy); ATPO = ConstantAddress(ASC, ATPO.getElementType(), ATPO.getAlignment()); @@ -3835,9 +3836,7 @@ void CodeGenFunction::EmitCfiCheckFail() { llvm::StructType::get(Int8Ty, SourceLocationTy, VoidPtrTy); llvm::Value *V = Builder.CreateConstGEP2_32( - CfiCheckFailDataTy, - Builder.CreatePointerCast(Data, CfiCheckFailDataTy->getPointerTo(0)), 0, - 0); + CfiCheckFailDataTy, Builder.CreatePointerCast(Data, UnqualPtrTy), 0, 0); Address CheckKindAddr(V, Int8Ty, getIntAlign()); llvm::Value *CheckKind = Builder.CreateLoad(CheckKindAddr); @@ -6115,36 +6114,6 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, if (ResolvedFnInfo) *ResolvedFnInfo = &FnInfo; - // C99 6.5.2.2p6: - // If the expression that denotes the called function has a type - // that does not include a prototype, [the default argument - // promotions are performed]. If the number of arguments does not - // equal the number of parameters, the behavior is undefined. If - // the function is defined with a type that includes a prototype, - // and either the prototype ends with an ellipsis (, ...) or the - // types of the arguments after promotion are not compatible with - // the types of the parameters, the behavior is undefined. If the - // function is defined with a type that does not include a - // prototype, and the types of the arguments after promotion are - // not compatible with those of the parameters after promotion, - // the behavior is undefined [except in some trivial cases]. - // That is, in the general case, we should assume that a call - // through an unprototyped function type works like a *non-variadic* - // call. The way we make this work is to cast to the exact type - // of the promoted arguments. - // - // Chain calls use this same code path to add the invisible chain parameter - // to the function type. - if (isa(FnType) || Chain) { -llvm::Type *CalleeTy = getTypes().GetFunctionType(FnInfo); -int AS = Callee.getFunctionPointer()->getType()->getPointerAddressSpace(); -CalleeTy = CalleeTy->getPointerTo(AS); - -llvm::Value *CalleePtr = Callee.getFunctionPointer(); -CalleePtr = Builder.CreateBitCast(CalleePtr, CalleeTy, "callee.knr.cast"); -Callee.setFunctionPointer(CalleePtr); - } - // HIP function pointer contains kernel handle when it is used in triple // chevron. The kernel stub needs to be loaded from kernel handle and used // as callee. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo
[clang] [flang] [llvm] [openmp] [flang][driver] rename flang-new to flang (PR #110023)
mjklemm wrote: Since we are making this change now, should this PR be updated to follow clang's scheme of having `clang` point to `clang-$version`? https://github.com/llvm/llvm-project/pull/110023 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ItaniumMangle] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)
https://github.com/tcwzxx updated https://github.com/llvm/llvm-project/pull/109970 >From f9a25251087a160f2dc9e7f589aeb7b215bef60f Mon Sep 17 00:00:00 2001 From: tcwzxx Date: Wed, 25 Sep 2024 19:19:08 +0800 Subject: [PATCH 1/4] Rename mangleNameOrStandardSubstitution to mangleCXXRecordDecl and add Record to the substitution --- clang/lib/AST/ItaniumMangle.cpp | 18 ++ clang/test/CodeGenCXX/mangle.cpp | 24 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index b6e1da0c3192da..2c3321ad564781 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -464,7 +464,7 @@ class CXXNameMangler { void mangleSeqID(unsigned SeqID); void mangleName(GlobalDecl GD); void mangleType(QualType T); - void mangleNameOrStandardSubstitution(const NamedDecl *ND); + void mangleCXXRecordDecl(const CXXRecordDecl *Record); void mangleLambdaSig(const CXXRecordDecl *Lambda); void mangleModuleNamePrefix(StringRef Name, bool IsPartition = false); void mangleVendorQualifier(StringRef Name); @@ -3029,9 +3029,11 @@ void CXXNameMangler::mangleType(QualType T) { addSubstitution(T); } -void CXXNameMangler::mangleNameOrStandardSubstitution(const NamedDecl *ND) { - if (!mangleStandardSubstitution(ND)) -mangleName(ND); +void CXXNameMangler::mangleCXXRecordDecl(const CXXRecordDecl *Record) { + if (mangleSubstitution(Record)) +return; + mangleName(Record); + addSubstitution(Record); } void CXXNameMangler::mangleType(const BuiltinType *T) { @@ -7309,7 +7311,7 @@ void ItaniumMangleContextImpl::mangleCXXVTable(const CXXRecordDecl *RD, // ::= TV # virtual table CXXNameMangler Mangler(*this, Out); Mangler.getStream() << "_ZTV"; - Mangler.mangleNameOrStandardSubstitution(RD); + Mangler.mangleCXXRecordDecl(RD); } void ItaniumMangleContextImpl::mangleCXXVTT(const CXXRecordDecl *RD, @@ -7317,7 +7319,7 @@ void ItaniumMangleContextImpl::mangleCXXVTT(const CXXRecordDecl *RD, // ::= TT # VTT structure CXXNameMangler Mangler(*this, Out); Mangler.getStream() << "_ZTT"; - Mangler.mangleNameOrStandardSubstitution(RD); + Mangler.mangleCXXRecordDecl(RD); } void ItaniumMangleContextImpl::mangleCXXCtorVTable(const CXXRecordDecl *RD, @@ -7327,10 +7329,10 @@ void ItaniumMangleContextImpl::mangleCXXCtorVTable(const CXXRecordDecl *RD, // ::= TC _ CXXNameMangler Mangler(*this, Out); Mangler.getStream() << "_ZTC"; - Mangler.mangleNameOrStandardSubstitution(RD); + Mangler.mangleCXXRecordDecl(RD); Mangler.getStream() << Offset; Mangler.getStream() << '_'; - Mangler.mangleNameOrStandardSubstitution(Type); + Mangler.mangleCXXRecordDecl(Type); } void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) { diff --git a/clang/test/CodeGenCXX/mangle.cpp b/clang/test/CodeGenCXX/mangle.cpp index d0800af55c87e8..848b026028be76 100644 --- a/clang/test/CodeGenCXX/mangle.cpp +++ b/clang/test/CodeGenCXX/mangle.cpp @@ -11,6 +11,8 @@ struct Y { }; //CHECK: @pr5966_i = external global //CHECK: @_ZL8pr5966_j = internal global +//CHECK: @_ZTCN6test624InstE0_NS_1A4ImplINS1_4WrapEEE + // CHECK-LABEL: define{{.*}} zeroext i1 @_ZplRK1YRA100_P1X bool operator+(const Y&, X* (&xs)[100]) { return false; } @@ -1214,3 +1216,25 @@ namespace test61 { // CHECK-LABEL: @_ZN6test611fINS_1XEEEvNT_1Y1aENS3_1bE template void f(int, int); } + +namespace test62 { +namespace A { + +class VBase { + public: + virtual ~VBase() {}; +}; + +struct Wrap {}; + +template +class Impl : public virtual VBase { + public: +}; + +} // namespace A + +struct Inst : public A::Impl {}; + +void Test() { Inst a; } +} >From 9599a60133e2b32cd45c88c50c2d6dc6ebf601b8 Mon Sep 17 00:00:00 2001 From: tcwzxx Date: Fri, 27 Sep 2024 14:17:27 +0800 Subject: [PATCH 2/4] move test case to mangle-subst.cpp --- clang/test/CodeGenCXX/mangle-subst.cpp | 27 ++ clang/test/CodeGenCXX/mangle.cpp | 23 -- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/clang/test/CodeGenCXX/mangle-subst.cpp b/clang/test/CodeGenCXX/mangle-subst.cpp index 20f33a72fff830..524e0febe479a8 100644 --- a/clang/test/CodeGenCXX/mangle-subst.cpp +++ b/clang/test/CodeGenCXX/mangle-subst.cpp @@ -1,4 +1,8 @@ // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fclang-abi-compat=19 | FileCheck %s --check-prefix=CHECK-CLANG-19 + +//CHECK: @_ZTCN16MangleCtorVTable4InstE0_NS_1A4ImplINS1_4WrapEEE +//CHECK-CLANG-19: @_ZTCN16MangleCtorVTable4InstE0_NS_1A4ImplINS0_4WrapEEE struct X {}; @@ -96,3 +100,26 @@ typename X::template Y::type f(typename X::template Y::type2) { retu // CHECK: @_ZN12ManglePrefix1fIiEENS_1XIT_E1YIS2_E4typeENS5_5type2E template int f(int); } + +namespace MangleCtorVTable { +namespace A { + +class VB
[clang] ff8a992 - WebKit Checkers should set DeclWithIssue. (#109389)
Author: Ryosuke Niwa Date: 2024-09-27T00:02:59-07:00 New Revision: ff8a9921ec9425e31aa1da273c2e4836f9e4069e URL: https://github.com/llvm/llvm-project/commit/ff8a9921ec9425e31aa1da273c2e4836f9e4069e DIFF: https://github.com/llvm/llvm-project/commit/ff8a9921ec9425e31aa1da273c2e4836f9e4069e.diff LOG: WebKit Checkers should set DeclWithIssue. (#109389) Set DeclWithIssue in alpha.webkit.UncountedCallArgsChecker and alpha.webkit.UncountedLocalVarsChecker. Added: Modified: clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp Removed: diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp index 31e9b3c4b9d412..0ed93ab26bf5ca 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp @@ -18,6 +18,8 @@ #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" #include "clang/StaticAnalyzer/Core/Checker.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/Support/SaveAndRestore.h" #include using namespace clang; @@ -44,7 +46,11 @@ class UncountedCallArgsChecker // visit template instantiations or lambda classes. We // want to visit those, so we make our own RecursiveASTVisitor. struct LocalVisitor : public RecursiveASTVisitor { + using Base = RecursiveASTVisitor; + const UncountedCallArgsChecker *Checker; + Decl *DeclWithIssue{nullptr}; + explicit LocalVisitor(const UncountedCallArgsChecker *Checker) : Checker(Checker) { assert(Checker); @@ -56,12 +62,18 @@ class UncountedCallArgsChecker bool TraverseClassTemplateDecl(ClassTemplateDecl *Decl) { if (isRefType(safeGetName(Decl))) return true; -return RecursiveASTVisitor::TraverseClassTemplateDecl( -Decl); +return Base::TraverseClassTemplateDecl(Decl); + } + + bool TraverseDecl(Decl *D) { +llvm::SaveAndRestore SavedDecl(DeclWithIssue); +if (D && (isa(D) || isa(D))) + DeclWithIssue = D; +return Base::TraverseDecl(D); } bool VisitCallExpr(const CallExpr *CE) { -Checker->visitCallExpr(CE); +Checker->visitCallExpr(CE, DeclWithIssue); return true; } }; @@ -70,7 +82,7 @@ class UncountedCallArgsChecker visitor.TraverseDecl(const_cast(TUD)); } - void visitCallExpr(const CallExpr *CE) const { + void visitCallExpr(const CallExpr *CE, const Decl *D) const { if (shouldSkipCall(CE)) return; @@ -89,7 +101,7 @@ class UncountedCallArgsChecker QualType ArgType = MemberCallExpr->getObjectType().getCanonicalType(); std::optional IsUncounted = isUncounted(ArgType); if (IsUncounted && *IsUncounted && !isPtrOriginSafe(E)) - reportBugOnThis(E); + reportBugOnThis(E, D); } for (auto P = F->param_begin(); @@ -120,7 +132,7 @@ class UncountedCallArgsChecker if (isPtrOriginSafe(Arg)) continue; -reportBug(Arg, *P); +reportBug(Arg, *P, D); } } } @@ -241,7 +253,8 @@ class UncountedCallArgsChecker ClsName.ends_with("String")); } - void reportBug(const Expr *CallArg, const ParmVarDecl *Param) const { + void reportBug(const Expr *CallArg, const ParmVarDecl *Param, + const Decl *DeclWithIssue) const { assert(CallArg); SmallString<100> Buf; @@ -262,10 +275,11 @@ class UncountedCallArgsChecker PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager()); auto Report = std::make_unique(Bug, Os.str(), BSLoc); Report->addRange(CallArg->getSourceRange()); +Report->setDeclWithIssue(DeclWithIssue); BR->emitReport(std::move(Report)); } - void reportBugOnThis(const Expr *CallArg) const { + void reportBugOnThis(const Expr *CallArg, const Decl *DeclWithIssue) const { assert(CallArg); const SourceLocation SrcLocToReport = CallArg->getSourceRange().getBegin(); @@ -275,6 +289,7 @@ class UncountedCallArgsChecker Bug, "Call argument for 'this' parameter is uncounted and unsafe.", BSLoc); Report->addRange(CallArg->getSourceRange()); +Report->setDeclWithIssue(DeclWithIssue); BR->emitReport(std::move(Report)); } }; diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp index 274da0baf2ce5c..9d0a3bb5da7325 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp @@ -121,6 +121,7
[clang] [ItaniumMangle] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)
tcwzxx wrote: Thanks for the review. I have added the ABI version 19 and the release notes. https://github.com/llvm/llvm-project/pull/109970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ItaniumMangle] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 614aeda93b2225c6eb42b00ba189ba7ca2585c60 b2c397bd45f690394e55e889f11080c0b718eb5d --extensions h,cpp -- clang/include/clang/Basic/LangOptions.h clang/lib/AST/ItaniumMangle.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/test/CodeGenCXX/mangle-subst.cpp clang/test/CodeGenCXX/mangle.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 83c38a63a3..80cb2dba6c 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -242,7 +242,6 @@ public: /// - Incorrect Mangling of CXXCtorVTable Ver19, - /// Conform to the underlying platform's C and C++ ABIs as closely /// as we can. Latest `` https://github.com/llvm/llvm-project/pull/109970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] isUncountedPtr should take QualType as an argument. (PR #110213)
https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/110213 Make isUncountedPtr take QualType as an argument instead of Type*. This simplifies some code. >From 4c82195acf092fd9a92c999040f8f66947585fde Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Fri, 27 Sep 2024 00:07:12 -0700 Subject: [PATCH] isUncountedPtr should take QualType as an argument. Make isUncountedPtr take QualType as an argument instead of Type*. This simplifies some code. --- .../Checkers/WebKit/PtrTypesSemantics.cpp | 15 --- .../Checkers/WebKit/PtrTypesSemantics.h | 2 +- .../Checkers/WebKit/UncountedCallArgsChecker.cpp | 6 +- .../WebKit/UncountedLambdaCapturesChecker.cpp | 10 +- .../Checkers/WebKit/UncountedLocalVarsChecker.cpp | 6 +- 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 54c99c3c1b37f9..38582e6d543cd4 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -165,14 +165,11 @@ std::optional isUncounted(const CXXRecordDecl* Class) return (*IsRefCountable); } -std::optional isUncountedPtr(const Type* T) +std::optional isUncountedPtr(const QualType T) { - assert(T); - if (T->isPointerType() || T->isReferenceType()) { -if (auto *CXXRD = T->getPointeeCXXRecordDecl()) { +if (auto *CXXRD = T->getPointeeCXXRecordDecl()) return isUncounted(CXXRD); -} } return false; } @@ -196,12 +193,8 @@ std::optional isGetterOfRefCounted(const CXXMethodDecl* M) // Ref -> T conversion // FIXME: Currently allowing any Ref -> whatever cast. if (isRefType(className)) { - if (auto *maybeRefToRawOperator = dyn_cast(M)) { -if (auto *targetConversionType = -maybeRefToRawOperator->getConversionType().getTypePtrOrNull()) { - return isUncountedPtr(targetConversionType); -} - } + if (auto *maybeRefToRawOperator = dyn_cast(M)) + return isUncountedPtr(maybeRefToRawOperator->getConversionType()); } } return false; diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h index e2d0342bebd52c..4988f604c52283 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h @@ -53,7 +53,7 @@ std::optional isUncounted(const clang::CXXRecordDecl* Class); /// \returns true if \p T is either a raw pointer or reference to an uncounted /// class, false if not, std::nullopt if inconclusive. -std::optional isUncountedPtr(const clang::Type* T); +std::optional isUncountedPtr(const clang::QualType T); /// \returns true if Name is a RefPtr, Ref, or its variant, false if not. bool isRefType(const std::string &Name); diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp index 31e9b3c4b9d412..8071b6f70f58dc 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp @@ -103,12 +103,8 @@ class UncountedCallArgsChecker // continue; QualType ArgType = (*P)->getType().getCanonicalType(); -const auto *TypePtr = ArgType.getTypePtrOrNull(); -if (!TypePtr) - continue; // FIXME? Should we bail? - // FIXME: more complex types (arrays, references to raw pointers, etc) -std::optional IsUncounted = isUncountedPtr(TypePtr); +std::optional IsUncounted = isUncountedPtr(ArgType); if (!IsUncounted || !(*IsUncounted)) continue; diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp index a226a01ec0a579..998bd4ccee07db 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp @@ -59,11 +59,11 @@ class UncountedLambdaCapturesChecker for (const LambdaCapture &C : L->captures()) { if (C.capturesVariable()) { ValueDecl *CapturedVar = C.getCapturedVar(); -if (auto *CapturedVarType = CapturedVar->getType().getTypePtrOrNull()) { -std::optional IsUncountedPtr = isUncountedPtr(CapturedVarType); -if (IsUncountedPtr && *IsUncountedPtr) { -reportBug(C, CapturedVar, CapturedVarType); -} +QualType CapturedVarQualType = CapturedVar->getType(); +if (auto *CapturedVarType = CapturedVarQualType.getTypePtrOrNull()) { + auto IsUncountedPtr = isUncountedPtr(CapturedVarQualType); +
[clang] isUncountedPtr should take QualType as an argument. (PR #110213)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) Changes Make isUncountedPtr take QualType as an argument instead of Type*. This simplifies some code. --- Full diff: https://github.com/llvm/llvm-project/pull/110213.diff 5 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp (+4-11) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h (+1-1) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp (+1-5) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp (+5-5) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp (+1-5) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 54c99c3c1b37f9..38582e6d543cd4 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -165,14 +165,11 @@ std::optional isUncounted(const CXXRecordDecl* Class) return (*IsRefCountable); } -std::optional isUncountedPtr(const Type* T) +std::optional isUncountedPtr(const QualType T) { - assert(T); - if (T->isPointerType() || T->isReferenceType()) { -if (auto *CXXRD = T->getPointeeCXXRecordDecl()) { +if (auto *CXXRD = T->getPointeeCXXRecordDecl()) return isUncounted(CXXRD); -} } return false; } @@ -196,12 +193,8 @@ std::optional isGetterOfRefCounted(const CXXMethodDecl* M) // Ref -> T conversion // FIXME: Currently allowing any Ref -> whatever cast. if (isRefType(className)) { - if (auto *maybeRefToRawOperator = dyn_cast(M)) { -if (auto *targetConversionType = -maybeRefToRawOperator->getConversionType().getTypePtrOrNull()) { - return isUncountedPtr(targetConversionType); -} - } + if (auto *maybeRefToRawOperator = dyn_cast(M)) + return isUncountedPtr(maybeRefToRawOperator->getConversionType()); } } return false; diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h index e2d0342bebd52c..4988f604c52283 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h @@ -53,7 +53,7 @@ std::optional isUncounted(const clang::CXXRecordDecl* Class); /// \returns true if \p T is either a raw pointer or reference to an uncounted /// class, false if not, std::nullopt if inconclusive. -std::optional isUncountedPtr(const clang::Type* T); +std::optional isUncountedPtr(const clang::QualType T); /// \returns true if Name is a RefPtr, Ref, or its variant, false if not. bool isRefType(const std::string &Name); diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp index 31e9b3c4b9d412..8071b6f70f58dc 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp @@ -103,12 +103,8 @@ class UncountedCallArgsChecker // continue; QualType ArgType = (*P)->getType().getCanonicalType(); -const auto *TypePtr = ArgType.getTypePtrOrNull(); -if (!TypePtr) - continue; // FIXME? Should we bail? - // FIXME: more complex types (arrays, references to raw pointers, etc) -std::optional IsUncounted = isUncountedPtr(TypePtr); +std::optional IsUncounted = isUncountedPtr(ArgType); if (!IsUncounted || !(*IsUncounted)) continue; diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp index a226a01ec0a579..998bd4ccee07db 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp @@ -59,11 +59,11 @@ class UncountedLambdaCapturesChecker for (const LambdaCapture &C : L->captures()) { if (C.capturesVariable()) { ValueDecl *CapturedVar = C.getCapturedVar(); -if (auto *CapturedVarType = CapturedVar->getType().getTypePtrOrNull()) { -std::optional IsUncountedPtr = isUncountedPtr(CapturedVarType); -if (IsUncountedPtr && *IsUncountedPtr) { -reportBug(C, CapturedVar, CapturedVarType); -} +QualType CapturedVarQualType = CapturedVar->getType(); +if (auto *CapturedVarType = CapturedVarQualType.getTypePtrOrNull()) { + auto IsUncountedPtr = isUncountedPtr(CapturedVarQualType); + if (IsUncountedPtr && *IsUncountedPtr) +reportBug(C, CapturedVar, CapturedVarType); }
[clang] [clang][CGExpr] Avoid Type::getPointerTo() (NFC) (PR #110209)
https://github.com/nikic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/110209 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] isUncountedPtr should take QualType as an argument. (PR #110213)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Ryosuke Niwa (rniwa) Changes Make isUncountedPtr take QualType as an argument instead of Type*. This simplifies some code. --- Full diff: https://github.com/llvm/llvm-project/pull/110213.diff 5 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp (+4-11) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h (+1-1) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp (+1-5) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp (+5-5) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp (+1-5) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 54c99c3c1b37f9..38582e6d543cd4 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -165,14 +165,11 @@ std::optional isUncounted(const CXXRecordDecl* Class) return (*IsRefCountable); } -std::optional isUncountedPtr(const Type* T) +std::optional isUncountedPtr(const QualType T) { - assert(T); - if (T->isPointerType() || T->isReferenceType()) { -if (auto *CXXRD = T->getPointeeCXXRecordDecl()) { +if (auto *CXXRD = T->getPointeeCXXRecordDecl()) return isUncounted(CXXRD); -} } return false; } @@ -196,12 +193,8 @@ std::optional isGetterOfRefCounted(const CXXMethodDecl* M) // Ref -> T conversion // FIXME: Currently allowing any Ref -> whatever cast. if (isRefType(className)) { - if (auto *maybeRefToRawOperator = dyn_cast(M)) { -if (auto *targetConversionType = -maybeRefToRawOperator->getConversionType().getTypePtrOrNull()) { - return isUncountedPtr(targetConversionType); -} - } + if (auto *maybeRefToRawOperator = dyn_cast(M)) + return isUncountedPtr(maybeRefToRawOperator->getConversionType()); } } return false; diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h index e2d0342bebd52c..4988f604c52283 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h @@ -53,7 +53,7 @@ std::optional isUncounted(const clang::CXXRecordDecl* Class); /// \returns true if \p T is either a raw pointer or reference to an uncounted /// class, false if not, std::nullopt if inconclusive. -std::optional isUncountedPtr(const clang::Type* T); +std::optional isUncountedPtr(const clang::QualType T); /// \returns true if Name is a RefPtr, Ref, or its variant, false if not. bool isRefType(const std::string &Name); diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp index 31e9b3c4b9d412..8071b6f70f58dc 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp @@ -103,12 +103,8 @@ class UncountedCallArgsChecker // continue; QualType ArgType = (*P)->getType().getCanonicalType(); -const auto *TypePtr = ArgType.getTypePtrOrNull(); -if (!TypePtr) - continue; // FIXME? Should we bail? - // FIXME: more complex types (arrays, references to raw pointers, etc) -std::optional IsUncounted = isUncountedPtr(TypePtr); +std::optional IsUncounted = isUncountedPtr(ArgType); if (!IsUncounted || !(*IsUncounted)) continue; diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp index a226a01ec0a579..998bd4ccee07db 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp @@ -59,11 +59,11 @@ class UncountedLambdaCapturesChecker for (const LambdaCapture &C : L->captures()) { if (C.capturesVariable()) { ValueDecl *CapturedVar = C.getCapturedVar(); -if (auto *CapturedVarType = CapturedVar->getType().getTypePtrOrNull()) { -std::optional IsUncountedPtr = isUncountedPtr(CapturedVarType); -if (IsUncountedPtr && *IsUncountedPtr) { -reportBug(C, CapturedVar, CapturedVarType); -} +QualType CapturedVarQualType = CapturedVar->getType(); +if (auto *CapturedVarType = CapturedVarQualType.getTypePtrOrNull()) { + auto IsUncountedPtr = isUncountedPtr(CapturedVarQualType); + if (IsUncountedPtr && *IsUncountedPtr) +reportBug(C, CapturedVar, CapturedVarT
[clang] [alpha.webkit.UncountedCallArgsChecker] Use canonical type (PR #109393)
@@ -102,12 +102,13 @@ class UncountedCallArgsChecker // if ((*P)->hasAttr()) // continue; -const auto *ArgType = (*P)->getType().getTypePtrOrNull(); -if (!ArgType) +QualType ArgType = (*P)->getType().getCanonicalType(); +const auto *TypePtr = ArgType.getTypePtrOrNull(); rniwa wrote: https://github.com/llvm/llvm-project/pull/110213 https://github.com/llvm/llvm-project/pull/109393 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ItaniumMangle] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)
https://github.com/tcwzxx updated https://github.com/llvm/llvm-project/pull/109970 >From f9a25251087a160f2dc9e7f589aeb7b215bef60f Mon Sep 17 00:00:00 2001 From: tcwzxx Date: Wed, 25 Sep 2024 19:19:08 +0800 Subject: [PATCH 1/5] Rename mangleNameOrStandardSubstitution to mangleCXXRecordDecl and add Record to the substitution --- clang/lib/AST/ItaniumMangle.cpp | 18 ++ clang/test/CodeGenCXX/mangle.cpp | 24 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index b6e1da0c3192da..2c3321ad564781 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -464,7 +464,7 @@ class CXXNameMangler { void mangleSeqID(unsigned SeqID); void mangleName(GlobalDecl GD); void mangleType(QualType T); - void mangleNameOrStandardSubstitution(const NamedDecl *ND); + void mangleCXXRecordDecl(const CXXRecordDecl *Record); void mangleLambdaSig(const CXXRecordDecl *Lambda); void mangleModuleNamePrefix(StringRef Name, bool IsPartition = false); void mangleVendorQualifier(StringRef Name); @@ -3029,9 +3029,11 @@ void CXXNameMangler::mangleType(QualType T) { addSubstitution(T); } -void CXXNameMangler::mangleNameOrStandardSubstitution(const NamedDecl *ND) { - if (!mangleStandardSubstitution(ND)) -mangleName(ND); +void CXXNameMangler::mangleCXXRecordDecl(const CXXRecordDecl *Record) { + if (mangleSubstitution(Record)) +return; + mangleName(Record); + addSubstitution(Record); } void CXXNameMangler::mangleType(const BuiltinType *T) { @@ -7309,7 +7311,7 @@ void ItaniumMangleContextImpl::mangleCXXVTable(const CXXRecordDecl *RD, // ::= TV # virtual table CXXNameMangler Mangler(*this, Out); Mangler.getStream() << "_ZTV"; - Mangler.mangleNameOrStandardSubstitution(RD); + Mangler.mangleCXXRecordDecl(RD); } void ItaniumMangleContextImpl::mangleCXXVTT(const CXXRecordDecl *RD, @@ -7317,7 +7319,7 @@ void ItaniumMangleContextImpl::mangleCXXVTT(const CXXRecordDecl *RD, // ::= TT # VTT structure CXXNameMangler Mangler(*this, Out); Mangler.getStream() << "_ZTT"; - Mangler.mangleNameOrStandardSubstitution(RD); + Mangler.mangleCXXRecordDecl(RD); } void ItaniumMangleContextImpl::mangleCXXCtorVTable(const CXXRecordDecl *RD, @@ -7327,10 +7329,10 @@ void ItaniumMangleContextImpl::mangleCXXCtorVTable(const CXXRecordDecl *RD, // ::= TC _ CXXNameMangler Mangler(*this, Out); Mangler.getStream() << "_ZTC"; - Mangler.mangleNameOrStandardSubstitution(RD); + Mangler.mangleCXXRecordDecl(RD); Mangler.getStream() << Offset; Mangler.getStream() << '_'; - Mangler.mangleNameOrStandardSubstitution(Type); + Mangler.mangleCXXRecordDecl(Type); } void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) { diff --git a/clang/test/CodeGenCXX/mangle.cpp b/clang/test/CodeGenCXX/mangle.cpp index d0800af55c87e8..848b026028be76 100644 --- a/clang/test/CodeGenCXX/mangle.cpp +++ b/clang/test/CodeGenCXX/mangle.cpp @@ -11,6 +11,8 @@ struct Y { }; //CHECK: @pr5966_i = external global //CHECK: @_ZL8pr5966_j = internal global +//CHECK: @_ZTCN6test624InstE0_NS_1A4ImplINS1_4WrapEEE + // CHECK-LABEL: define{{.*}} zeroext i1 @_ZplRK1YRA100_P1X bool operator+(const Y&, X* (&xs)[100]) { return false; } @@ -1214,3 +1216,25 @@ namespace test61 { // CHECK-LABEL: @_ZN6test611fINS_1XEEEvNT_1Y1aENS3_1bE template void f(int, int); } + +namespace test62 { +namespace A { + +class VBase { + public: + virtual ~VBase() {}; +}; + +struct Wrap {}; + +template +class Impl : public virtual VBase { + public: +}; + +} // namespace A + +struct Inst : public A::Impl {}; + +void Test() { Inst a; } +} >From 9599a60133e2b32cd45c88c50c2d6dc6ebf601b8 Mon Sep 17 00:00:00 2001 From: tcwzxx Date: Fri, 27 Sep 2024 14:17:27 +0800 Subject: [PATCH 2/5] move test case to mangle-subst.cpp --- clang/test/CodeGenCXX/mangle-subst.cpp | 27 ++ clang/test/CodeGenCXX/mangle.cpp | 23 -- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/clang/test/CodeGenCXX/mangle-subst.cpp b/clang/test/CodeGenCXX/mangle-subst.cpp index 20f33a72fff830..524e0febe479a8 100644 --- a/clang/test/CodeGenCXX/mangle-subst.cpp +++ b/clang/test/CodeGenCXX/mangle-subst.cpp @@ -1,4 +1,8 @@ // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fclang-abi-compat=19 | FileCheck %s --check-prefix=CHECK-CLANG-19 + +//CHECK: @_ZTCN16MangleCtorVTable4InstE0_NS_1A4ImplINS1_4WrapEEE +//CHECK-CLANG-19: @_ZTCN16MangleCtorVTable4InstE0_NS_1A4ImplINS0_4WrapEEE struct X {}; @@ -96,3 +100,26 @@ typename X::template Y::type f(typename X::template Y::type2) { retu // CHECK: @_ZN12ManglePrefix1fIiEENS_1XIT_E1YIS2_E4typeENS5_5type2E template int f(int); } + +namespace MangleCtorVTable { +namespace A { + +class VB
[clang] isUncountedPtr should take QualType as an argument. (PR #110213)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 9a361684c80a779c28d8315503a423e05f0cc061 4c82195acf092fd9a92c999040f8f66947585fde --extensions cpp,h -- clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 38582e6d54..c4cb8f7dfc 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -165,8 +165,7 @@ std::optional isUncounted(const CXXRecordDecl* Class) return (*IsRefCountable); } -std::optional isUncountedPtr(const QualType T) -{ +std::optional isUncountedPtr(const QualType T) { if (T->isPointerType() || T->isReferenceType()) { if (auto *CXXRD = T->getPointeeCXXRecordDecl()) return isUncounted(CXXRD); @@ -194,7 +193,7 @@ std::optional isGetterOfRefCounted(const CXXMethodDecl* M) // FIXME: Currently allowing any Ref -> whatever cast. if (isRefType(className)) { if (auto *maybeRefToRawOperator = dyn_cast(M)) - return isUncountedPtr(maybeRefToRawOperator->getConversionType()); +return isUncountedPtr(maybeRefToRawOperator->getConversionType()); } } return false; `` https://github.com/llvm/llvm-project/pull/110213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] isUncountedPtr should take QualType as an argument. (PR #110213)
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/110213 >From 4c82195acf092fd9a92c999040f8f66947585fde Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Fri, 27 Sep 2024 00:07:12 -0700 Subject: [PATCH 1/2] isUncountedPtr should take QualType as an argument. Make isUncountedPtr take QualType as an argument instead of Type*. This simplifies some code. --- .../Checkers/WebKit/PtrTypesSemantics.cpp | 15 --- .../Checkers/WebKit/PtrTypesSemantics.h | 2 +- .../Checkers/WebKit/UncountedCallArgsChecker.cpp | 6 +- .../WebKit/UncountedLambdaCapturesChecker.cpp | 10 +- .../Checkers/WebKit/UncountedLocalVarsChecker.cpp | 6 +- 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 54c99c3c1b37f9..38582e6d543cd4 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -165,14 +165,11 @@ std::optional isUncounted(const CXXRecordDecl* Class) return (*IsRefCountable); } -std::optional isUncountedPtr(const Type* T) +std::optional isUncountedPtr(const QualType T) { - assert(T); - if (T->isPointerType() || T->isReferenceType()) { -if (auto *CXXRD = T->getPointeeCXXRecordDecl()) { +if (auto *CXXRD = T->getPointeeCXXRecordDecl()) return isUncounted(CXXRD); -} } return false; } @@ -196,12 +193,8 @@ std::optional isGetterOfRefCounted(const CXXMethodDecl* M) // Ref -> T conversion // FIXME: Currently allowing any Ref -> whatever cast. if (isRefType(className)) { - if (auto *maybeRefToRawOperator = dyn_cast(M)) { -if (auto *targetConversionType = -maybeRefToRawOperator->getConversionType().getTypePtrOrNull()) { - return isUncountedPtr(targetConversionType); -} - } + if (auto *maybeRefToRawOperator = dyn_cast(M)) + return isUncountedPtr(maybeRefToRawOperator->getConversionType()); } } return false; diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h index e2d0342bebd52c..4988f604c52283 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h @@ -53,7 +53,7 @@ std::optional isUncounted(const clang::CXXRecordDecl* Class); /// \returns true if \p T is either a raw pointer or reference to an uncounted /// class, false if not, std::nullopt if inconclusive. -std::optional isUncountedPtr(const clang::Type* T); +std::optional isUncountedPtr(const clang::QualType T); /// \returns true if Name is a RefPtr, Ref, or its variant, false if not. bool isRefType(const std::string &Name); diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp index 31e9b3c4b9d412..8071b6f70f58dc 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp @@ -103,12 +103,8 @@ class UncountedCallArgsChecker // continue; QualType ArgType = (*P)->getType().getCanonicalType(); -const auto *TypePtr = ArgType.getTypePtrOrNull(); -if (!TypePtr) - continue; // FIXME? Should we bail? - // FIXME: more complex types (arrays, references to raw pointers, etc) -std::optional IsUncounted = isUncountedPtr(TypePtr); +std::optional IsUncounted = isUncountedPtr(ArgType); if (!IsUncounted || !(*IsUncounted)) continue; diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp index a226a01ec0a579..998bd4ccee07db 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp @@ -59,11 +59,11 @@ class UncountedLambdaCapturesChecker for (const LambdaCapture &C : L->captures()) { if (C.capturesVariable()) { ValueDecl *CapturedVar = C.getCapturedVar(); -if (auto *CapturedVarType = CapturedVar->getType().getTypePtrOrNull()) { -std::optional IsUncountedPtr = isUncountedPtr(CapturedVarType); -if (IsUncountedPtr && *IsUncountedPtr) { -reportBug(C, CapturedVar, CapturedVarType); -} +QualType CapturedVarQualType = CapturedVar->getType(); +if (auto *CapturedVarType = CapturedVarQualType.getTypePtrOrNull()) { + auto IsUncountedPtr = isUncountedPtr(CapturedVarQualType); + if (IsUncountedPtr && *IsUncountedPtr) +reportBug(C, CapturedVar, CapturedVa
[clang] [llvm] [RISCV] Implement Clang Builtins for XCValu Extension in CV32E40P (PR #100684)
https://github.com/realqhc edited https://github.com/llvm/llvm-project/pull/100684 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [openmp] [flang][driver] rename flang-new to flang (PR #110023)
banach-space wrote: Having multiple active PR's for one change is IMHO rather confusing. It creates unnecessary duplication - why do we expect people to review the same change twice? As a case in point: > Since we are making this change now, should this PR be updated to follow > clang's scheme of having clang point to clang-$version? That was already included in #74377. It is absolutely secondary who commits this change (just acknowledging that there are two implementations). However, please make sure that: * there is a well documented transition period during which `flang-new` is still available as a sym-link (please define _when_ such transition period would end), * we use this as an opportunity to improve Flang's consistency with Clang (please introduce `flang-$version`), * this change does not break Flang's buildbots and all customers are well supported throughout the renaming (there might be a stream of bug reports following this), * community members who contributed to the previous PRs for this (either through code, reviews or testing) are aware that the discussion has moved here and all changes have been attributed accordingly. Thank you all for working on this! 🙏🏻 https://github.com/llvm/llvm-project/pull/110023 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebKit Checkers] Allow a guardian CheckedPtr/CheckedRef (PR #110222)
https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/110222 This PR makes WebKit checkers allow a guardian variable which is CheckedPtr or CheckedRef as in addition to RefPtr or Ref. >From 6e842a0135d097ffcb3c5991bc97543179972405 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Fri, 27 Sep 2024 02:05:25 -0700 Subject: [PATCH] [WebKit Checkers] Allow a guardian CheckedPtr/CheckedRef This PR makes WebKit checkers allow a guardian variable which is CheckedPtr or CheckedRef as in addition to RefPtr or Ref. --- .../Checkers/WebKit/ASTUtils.cpp | 17 --- .../Checkers/WebKit/PtrTypesSemantics.cpp | 44 ++-- .../Checkers/WebKit/PtrTypesSemantics.h | 17 +-- .../WebKit/UncountedCallArgsChecker.cpp | 2 + .../WebKit/UncountedLocalVarsChecker.cpp | 1 + .../Checkers/WebKit/call-args-checked.cpp | 46 + .../Analysis/Checkers/WebKit/mock-types.h | 16 -- .../Checkers/WebKit/uncounted-local-vars.cpp | 51 +++ 8 files changed, 177 insertions(+), 17 deletions(-) create mode 100644 clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index 394cb26f03cf99..1b7614d3feeca5 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp @@ -17,6 +17,10 @@ namespace clang { +bool isSafePtr(clang::CXXRecordDecl *Decl) { + return isRefCounted(Decl) || isCheckedPtr(Decl); +} + bool tryToFindPtrOrigin( const Expr *E, bool StopAtFirstRefCountedObj, std::function callback) { @@ -31,7 +35,7 @@ bool tryToFindPtrOrigin( } if (auto *tempExpr = dyn_cast(E)) { if (auto *C = tempExpr->getConstructor()) { -if (auto *Class = C->getParent(); Class && isRefCounted(Class)) +if (auto *Class = C->getParent(); Class && isSafePtr(Class)) return callback(E, true); break; } @@ -56,7 +60,8 @@ bool tryToFindPtrOrigin( if (StopAtFirstRefCountedObj) { if (auto *ConversionFunc = dyn_cast_or_null(cast->getConversionFunction())) { - if (isCtorOfRefCounted(ConversionFunc)) + if (isCtorOfRefCounted(ConversionFunc) || + isCtorOfCheckedPtr(ConversionFunc)) return callback(E, true); } } @@ -68,7 +73,7 @@ bool tryToFindPtrOrigin( if (auto *call = dyn_cast(E)) { if (auto *memberCall = dyn_cast(call)) { if (auto *decl = memberCall->getMethodDecl()) { - std::optional IsGetterOfRefCt = isGetterOfRefCounted(decl); + std::optional IsGetterOfRefCt = isGetterOfSafePtr(decl); if (IsGetterOfRefCt && *IsGetterOfRefCt) { E = memberCall->getImplicitObjectArgument(); if (StopAtFirstRefCountedObj) { @@ -87,7 +92,7 @@ bool tryToFindPtrOrigin( } if (auto *callee = call->getDirectCallee()) { -if (isCtorOfRefCounted(callee)) { +if (isCtorOfRefCounted(callee) || isCtorOfCheckedPtr(callee)) { if (StopAtFirstRefCountedObj) return callback(E, true); @@ -95,7 +100,7 @@ bool tryToFindPtrOrigin( continue; } -if (isRefType(callee->getReturnType())) +if (isSafePtrType(callee->getReturnType())) return callback(E, true); if (isSingleton(callee)) @@ -109,7 +114,7 @@ bool tryToFindPtrOrigin( } if (auto *ObjCMsgExpr = dyn_cast(E)) { if (auto *Method = ObjCMsgExpr->getMethodDecl()) { -if (isRefType(Method->getReturnType())) +if (isSafePtrType(Method->getReturnType())) return callback(E, true); } } diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 4d145be808f6d8..b40e470dc71e03 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -135,7 +135,12 @@ bool isCtorOfRefCounted(const clang::FunctionDecl *F) { || FunctionName == "Identifier"; } -bool isRefType(const clang::QualType T) { +bool isCtorOfCheckedPtr(const clang::FunctionDecl *F) { + assert(F); + return isCheckedPtr(safeGetName(F)); +} + +bool isSafePtrType(const clang::QualType T) { QualType type = T; while (!type.isNull()) { if (auto *elaboratedT = type->getAs()) { @@ -145,7 +150,7 @@ bool isRefType(const clang::QualType T) { if (auto *specialT = type->getAs()) { if (auto *decl = specialT->getTemplateName().getAsTemplateDecl()) { auto name = decl->getNameAsString(); -return isRefType(name); +return isRefType(name) || isCheckedPtr(name); } return false; } @@ -177,6 +182,12 @@ std::optional isUncounted(const CXXRecordDecl* Class) return (*
[clang] [WebKit Checkers] Allow a guardian CheckedPtr/CheckedRef (PR #110222)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) Changes This PR makes WebKit checkers allow a guardian variable which is CheckedPtr or CheckedRef as in addition to RefPtr or Ref. --- Full diff: https://github.com/llvm/llvm-project/pull/110222.diff 8 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+11-6) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp (+39-5) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h (+14-3) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp (+2) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp (+1) - (added) clang/test/Analysis/Checkers/WebKit/call-args-checked.cpp (+46) - (modified) clang/test/Analysis/Checkers/WebKit/mock-types.h (+13-3) - (modified) clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp (+51) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index 394cb26f03cf99..1b7614d3feeca5 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp @@ -17,6 +17,10 @@ namespace clang { +bool isSafePtr(clang::CXXRecordDecl *Decl) { + return isRefCounted(Decl) || isCheckedPtr(Decl); +} + bool tryToFindPtrOrigin( const Expr *E, bool StopAtFirstRefCountedObj, std::function callback) { @@ -31,7 +35,7 @@ bool tryToFindPtrOrigin( } if (auto *tempExpr = dyn_cast(E)) { if (auto *C = tempExpr->getConstructor()) { -if (auto *Class = C->getParent(); Class && isRefCounted(Class)) +if (auto *Class = C->getParent(); Class && isSafePtr(Class)) return callback(E, true); break; } @@ -56,7 +60,8 @@ bool tryToFindPtrOrigin( if (StopAtFirstRefCountedObj) { if (auto *ConversionFunc = dyn_cast_or_null(cast->getConversionFunction())) { - if (isCtorOfRefCounted(ConversionFunc)) + if (isCtorOfRefCounted(ConversionFunc) || + isCtorOfCheckedPtr(ConversionFunc)) return callback(E, true); } } @@ -68,7 +73,7 @@ bool tryToFindPtrOrigin( if (auto *call = dyn_cast(E)) { if (auto *memberCall = dyn_cast(call)) { if (auto *decl = memberCall->getMethodDecl()) { - std::optional IsGetterOfRefCt = isGetterOfRefCounted(decl); + std::optional IsGetterOfRefCt = isGetterOfSafePtr(decl); if (IsGetterOfRefCt && *IsGetterOfRefCt) { E = memberCall->getImplicitObjectArgument(); if (StopAtFirstRefCountedObj) { @@ -87,7 +92,7 @@ bool tryToFindPtrOrigin( } if (auto *callee = call->getDirectCallee()) { -if (isCtorOfRefCounted(callee)) { +if (isCtorOfRefCounted(callee) || isCtorOfCheckedPtr(callee)) { if (StopAtFirstRefCountedObj) return callback(E, true); @@ -95,7 +100,7 @@ bool tryToFindPtrOrigin( continue; } -if (isRefType(callee->getReturnType())) +if (isSafePtrType(callee->getReturnType())) return callback(E, true); if (isSingleton(callee)) @@ -109,7 +114,7 @@ bool tryToFindPtrOrigin( } if (auto *ObjCMsgExpr = dyn_cast(E)) { if (auto *Method = ObjCMsgExpr->getMethodDecl()) { -if (isRefType(Method->getReturnType())) +if (isSafePtrType(Method->getReturnType())) return callback(E, true); } } diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 4d145be808f6d8..b40e470dc71e03 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -135,7 +135,12 @@ bool isCtorOfRefCounted(const clang::FunctionDecl *F) { || FunctionName == "Identifier"; } -bool isRefType(const clang::QualType T) { +bool isCtorOfCheckedPtr(const clang::FunctionDecl *F) { + assert(F); + return isCheckedPtr(safeGetName(F)); +} + +bool isSafePtrType(const clang::QualType T) { QualType type = T; while (!type.isNull()) { if (auto *elaboratedT = type->getAs()) { @@ -145,7 +150,7 @@ bool isRefType(const clang::QualType T) { if (auto *specialT = type->getAs()) { if (auto *decl = specialT->getTemplateName().getAsTemplateDecl()) { auto name = decl->getNameAsString(); -return isRefType(name); +return isRefType(name) || isCheckedPtr(name); } return false; } @@ -177,6 +182,12 @@ std::optional isUncounted(const CXXRecordDecl* Class) return (*IsRefCountable); } +std::optional isUnchecked(const CXXRecordDecl *Class) { + if (isCheckedPtr(Class)) +return false; // Cheaper than below + return isCheckedPtrCapable(Class); +} + std::op
[clang] [ItaniumMangle] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)
@@ -11,6 +11,7 @@ struct Y { }; //CHECK: @pr5966_i = external global //CHECK: @_ZL8pr5966_j = internal global + zyn0217 wrote: nit: revert the blank line https://github.com/llvm/llvm-project/pull/109970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ItaniumMangle] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)
https://github.com/zyn0217 approved this pull request. Some nits, otherwise LGTM as well. https://github.com/llvm/llvm-project/pull/109970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][test] add testing for the AST matcher reference (PR #94248)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/94248 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #105935)
https://github.com/5chmidti closed https://github.com/llvm/llvm-project/pull/105935 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 581c015 - [clang][bytecode] Implement fixed point negation (#110237)
Author: Timm Baeder Date: 2024-09-27T13:29:14+02:00 New Revision: 581c015ed0cfe05d8dd3450375cd3db316e334f1 URL: https://github.com/llvm/llvm-project/commit/581c015ed0cfe05d8dd3450375cd3db316e334f1 DIFF: https://github.com/llvm/llvm-project/commit/581c015ed0cfe05d8dd3450375cd3db316e334f1.diff LOG: [clang][bytecode] Implement fixed point negation (#110237) Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp clang/lib/AST/ByteCode/FixedPoint.h clang/lib/AST/ByteCode/Opcodes.td clang/lib/AST/ByteCode/PrimType.h clang/test/AST/ByteCode/fixed-point.cpp Removed: diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index aac3fd384130d7..78ba1a7eec6620 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -724,9 +724,9 @@ bool Compiler::VisitFixedPointLiteral(const FixedPointLiteral *E) { assert(E->getType()->isFixedPointType()); assert(classifyPrim(E) == PT_FixedPoint); - // FIXME: Semantics. + auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->getType()); APInt Value = E->getValue(); - return this->emitConstFixedPoint(Value, E); + return this->emitConstFixedPoint(FixedPoint(Value, Sem), E); } template diff --git a/clang/lib/AST/ByteCode/FixedPoint.h b/clang/lib/AST/ByteCode/FixedPoint.h index 5c4043f060ec56..fba793cd59e7e1 100644 --- a/clang/lib/AST/ByteCode/FixedPoint.h +++ b/clang/lib/AST/ByteCode/FixedPoint.h @@ -17,16 +17,16 @@ namespace clang { namespace interp { using APInt = llvm::APInt; +using APSInt = llvm::APSInt; /// Wrapper around fixed point types. class FixedPoint final { private: llvm::APFixedPoint V; + FixedPoint(llvm::APFixedPoint &&V) : V(std::move(V)) {} public: - FixedPoint(APInt V) - : V(V, - llvm::FixedPointSemantics(V.getBitWidth(), 0, false, false, false)) {} + FixedPoint(APInt V, llvm::FixedPointSemantics Sem) : V(V, Sem) {} // This needs to be default-constructible so llvm::endian::read works. FixedPoint() : V(APInt(0, 0ULL, false), @@ -42,12 +42,22 @@ class FixedPoint final { void print(llvm::raw_ostream &OS) const { OS << V; } APValue toAPValue(const ASTContext &) const { return APValue(V); } + APSInt toAPSInt(unsigned BitWidth) const { return V.getValue(); } + + unsigned bitWidth() const { return V.getWidth(); } + bool isSigned() const { return V.isSigned(); } ComparisonCategoryResult compare(const FixedPoint &Other) const { if (Other.V == V) return ComparisonCategoryResult::Equal; return ComparisonCategoryResult::Unordered; } + + static bool neg(const FixedPoint &A, FixedPoint *R) { +bool Overflow = false; +*R = FixedPoint(A.V.negate(&Overflow)); +return Overflow; + } }; inline FixedPoint getSwappedBytes(FixedPoint F) { return F; } diff --git a/clang/lib/AST/ByteCode/Opcodes.td b/clang/lib/AST/ByteCode/Opcodes.td index 84c5a1d1ab4c0d..5fdafd1bf81984 100644 --- a/clang/lib/AST/ByteCode/Opcodes.td +++ b/clang/lib/AST/ByteCode/Opcodes.td @@ -106,7 +106,7 @@ def PtrTypeClass : TypeClass { } def NonPtrTypeClass : TypeClass { - let Types = !listconcat(IntegerTypeClass.Types, [Bool], [Float]); + let Types = !listconcat(IntegerTypeClass.Types, [Bool], [Float], [FixedPoint]); } def AllTypeClass : TypeClass { diff --git a/clang/lib/AST/ByteCode/PrimType.h b/clang/lib/AST/ByteCode/PrimType.h index 23ca8027599cd5..59c04c4673d936 100644 --- a/clang/lib/AST/ByteCode/PrimType.h +++ b/clang/lib/AST/ByteCode/PrimType.h @@ -43,11 +43,11 @@ enum PrimType : unsigned { PT_IntAP = 8, PT_IntAPS = 9, PT_Bool = 10, - PT_Float = 11, - PT_Ptr = 12, - PT_FnPtr = 13, - PT_MemberPtr = 14, - PT_FixedPoint = 15, + PT_FixedPoint = 11, + PT_Float = 12, + PT_Ptr = 13, + PT_FnPtr = 14, + PT_MemberPtr = 15, }; inline constexpr bool isPtrType(PrimType T) { @@ -71,7 +71,7 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, return OS; } -constexpr bool isIntegralType(PrimType T) { return T <= PT_Bool; } +constexpr bool isIntegralType(PrimType T) { return T <= PT_FixedPoint; } /// Mapping from primitive types to their representation. template struct PrimConv; diff --git a/clang/test/AST/ByteCode/fixed-point.cpp b/clang/test/AST/ByteCode/fixed-point.cpp index 24595ed96c166d..42ebdf64e1a9fe 100644 --- a/clang/test/AST/ByteCode/fixed-point.cpp +++ b/clang/test/AST/ByteCode/fixed-point.cpp @@ -7,3 +7,5 @@ static_assert((bool)0.0k); // both-error {{static assertion failed}} static_assert(1.0k == 1.0k); static_assert(1.0k != 1.0k); // both-error {{failed due to requirement '1.0k != 1.0k'}} +static_assert(-12.0k == -(-(-12.0k))); + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ItaniumMangle] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)
https://github.com/tcwzxx edited https://github.com/llvm/llvm-project/pull/109970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ItaniumMangle] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)
@@ -1,4 +1,8 @@ // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fclang-abi-compat=19 | FileCheck %s --check-prefix=CHECK-CLANG-19 + +//CHECK: @_ZTCN16MangleCtorVTable4InstE0_NS_1A4ImplINS1_4WrapEEE +//CHECK-CLANG-19: @_ZTCN16MangleCtorVTable4InstE0_NS_1A4ImplINS0_4WrapEEE tcwzxx wrote: The construction vtable name is a global variable, so it cannot be moved above the corresponding code. https://github.com/llvm/llvm-project/pull/109970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ItaniumMangle] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)
@@ -237,6 +237,11 @@ class LangOptionsBase { /// in the initializers of members of local classes. Ver18, +/// Attempt to be ABI-compatible with code generated by Clang 19.0.x. +/// This causes clang to: +/// - Incorrect Mangling of CXXCtorVTable zyn0217 wrote: ```suggestion /// - Incorrectly mangle CXX vtable substitutions in some cases... ``` It would be great if you could flesh out the behavior changes here. https://github.com/llvm/llvm-project/pull/109970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxxabi] [clang][ItaniumMangle] Mangle friend function templates with a constr… (PR #110247)
https://github.com/VitaNuo created https://github.com/llvm/llvm-project/pull/110247 …aint that depends on a template parameter from an enclosing template as members of the enclosing class. Such function templates should be considered member-like constrained friends per [temp.friend]p9 and https://github.com/itanium-cxx-abi/cxx-abi/issues/24#issuecomment-934977198). >From f8d897f5f3a89a5664e95a45948f9725101aa36f Mon Sep 17 00:00:00 2001 From: Viktoriia Bakalova Date: Fri, 27 Sep 2024 11:33:17 + Subject: [PATCH] [clang][ItaniumMangle] Mangle friend function templates with a constraint that depends on a template parameter from an enclosing template as members of the enclosing class. Such function templates should be considered member-like constrained friends per [temp.friend]p9 and https://github.com/itanium-cxx-abi/cxx-abi/issues/24#issuecomment-934977198). --- clang/lib/AST/ItaniumMangle.cpp | 8 clang/test/CodeGenCXX/mangle-concept.cpp | 6 +++--- libcxxabi/test/test_demangle.pass.cpp| 6 +++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index b6e1da0c3192da..172561f73b9a74 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -2270,6 +2270,14 @@ void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD, mangleTemplateParameter(TTP->getDepth(), TTP->getIndex()); } else { const DeclContext *DC = Context.getEffectiveDeclContext(ND); +if (const auto *FD = dyn_cast(GD.getDecl())) { + // Member-like constrained friends are mangled as if they were members of + // the enclosing class. + if (FD->getTemplatedDecl()->isMemberLikeConstrainedFriend() && + getASTContext().getLangOpts().getClangABICompat() > + LangOptions::ClangABI::Ver17) + DC = GD.getDecl()->getLexicalDeclContext()->getRedeclContext(); +} manglePrefix(DC, NoFunction); if (isa(ND) || isa(ND)) mangleUnqualifiedName(GD, DC, nullptr); diff --git a/clang/test/CodeGenCXX/mangle-concept.cpp b/clang/test/CodeGenCXX/mangle-concept.cpp index 91dc1b0e688e0d..6053511c00a7b5 100644 --- a/clang/test/CodeGenCXX/mangle-concept.cpp +++ b/clang/test/CodeGenCXX/mangle-concept.cpp @@ -58,19 +58,19 @@ namespace test2 { // CHECK: call {{.*}}@_ZN5test21AIiEF1fEzQ4TrueIT_E( // CLANG17: call {{.*}}@_ZN5test21fEz( f(ai); -// CHECK: call {{.*}}@_ZN5test2F1gIvEEvzQaa4TrueIT_E4TrueITL0__E( +// CHECK: call {{.*}}@_ZN5test21AIiEF1gIvEEvzQaa4TrueIT_E4TrueITL0__E( // CLANG17: call {{.*}}@_ZN5test21gIvEEvz( g(ai); // CHECK: call {{.*}}@_ZN5test21hIvEEvzQ4TrueITL0__E( // CLANG17: call {{.*}}@_ZN5test21hIvEEvz( h(ai); -// CHECK: call {{.*}}@_ZN5test2F1iIvQaa4TrueIT_E4TrueITL0__EEEvz( +// CHECK: call {{.*}}@_ZN5test21AIiEF1iIvQaa4TrueIT_E4TrueITL0__EEEvz( // CLANG17: call {{.*}}@_ZN5test21iIvEEvz( i(ai); // CHECK: call {{.*}}@_ZN5test21jIvQ4TrueITL0__EEEvz( // CLANG17: call {{.*}}@_ZN5test21jIvEEvz( j(ai); -// CHECK: call {{.*}}@_ZN5test2F1kITk4TruevQ4TrueIT_EEEvz( +// CHECK: call {{.*}}@_ZN5test21AIiEF1kITk4TruevQ4TrueIT_EEEvz( // CLANG17: call {{.*}}@_ZN5test21kIvEEvz( k(ai); // CHECK: call {{.*}}@_ZN5test21lITk4TruevEEvz( diff --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp index 17786a3a486fcd..efe482aad1b76c 100644 --- a/libcxxabi/test/test_demangle.pass.cpp +++ b/libcxxabi/test/test_demangle.pass.cpp @@ -30128,11 +30128,11 @@ const char* cases[][2] = // C++20 concepts, see https://github.com/itanium-cxx-abi/cxx-abi/issues/24. {"_Z2f0IiE1SIX1CIT_EEEv", "S> f0()"}, {"_ZN5test21AIiEF1fEzQ4TrueIT_E", "test2::A::friend f(...) requires True"}, -{"_ZN5test2F1gIvEEvzQaa4TrueIT_E4TrueITL0__E", "void test2::friend g(...) requires True && True"}, +{"_ZN5test21AIiEF1gIvEEvzQaa4TrueIT_E4TrueITL0__E", "void test2::A::friend g(...) requires True && True"}, {"_ZN5test21hIvEEvzQ4TrueITL0__E", "void test2::h(...) requires True"}, -{"_ZN5test2F1iIvQaa4TrueIT_E4TrueITL0__EEEvz", "void test2::friend i(...)"}, +{"_ZN5test21AIiEF1iIvQaa4TrueIT_E4TrueITL0__EEEvz", "void test2::A::friend i(...)"}, {"_ZN5test21jIvQ4TrueITL0__EEEvz", "void test2::j(...)"}, -{"_ZN5test2F1kITk4TruevQ4TrueIT_EEEvz", "void test2::friend k(...)"}, +{"_ZN5test21AIiEF1kITk4TruevQ4TrueIT_EEEvz", "void test2::A::friend k(...)"}, {"_ZN5test21lITk4TruevEEvz", "void test2::l(...)"}, {"_ZN5test31dITnDaLi0EEEvv", "void test3::d<0>()"}, {"_ZN5test31eITnDcLi0EEEvv", "void test3::e<0>()"}, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxxabi] [clang][ItaniumMangle] Mangle friend function templates with a constr… (PR #110247)
llvmbot wrote: @llvm/pr-subscribers-libcxxabi @llvm/pr-subscribers-clang Author: Viktoriia Bakalova (VitaNuo) Changes …aint that depends on a template parameter from an enclosing template as members of the enclosing class. Such function templates should be considered member-like constrained friends per [temp.friend]p9 and https://github.com/itanium-cxx-abi/cxx-abi/issues/24#issuecomment-934977198). --- Full diff: https://github.com/llvm/llvm-project/pull/110247.diff 3 Files Affected: - (modified) clang/lib/AST/ItaniumMangle.cpp (+8) - (modified) clang/test/CodeGenCXX/mangle-concept.cpp (+3-3) - (modified) libcxxabi/test/test_demangle.pass.cpp (+3-3) ``diff diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index b6e1da0c3192da..172561f73b9a74 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -2270,6 +2270,14 @@ void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD, mangleTemplateParameter(TTP->getDepth(), TTP->getIndex()); } else { const DeclContext *DC = Context.getEffectiveDeclContext(ND); +if (const auto *FD = dyn_cast(GD.getDecl())) { + // Member-like constrained friends are mangled as if they were members of + // the enclosing class. + if (FD->getTemplatedDecl()->isMemberLikeConstrainedFriend() && + getASTContext().getLangOpts().getClangABICompat() > + LangOptions::ClangABI::Ver17) + DC = GD.getDecl()->getLexicalDeclContext()->getRedeclContext(); +} manglePrefix(DC, NoFunction); if (isa(ND) || isa(ND)) mangleUnqualifiedName(GD, DC, nullptr); diff --git a/clang/test/CodeGenCXX/mangle-concept.cpp b/clang/test/CodeGenCXX/mangle-concept.cpp index 91dc1b0e688e0d..6053511c00a7b5 100644 --- a/clang/test/CodeGenCXX/mangle-concept.cpp +++ b/clang/test/CodeGenCXX/mangle-concept.cpp @@ -58,19 +58,19 @@ namespace test2 { // CHECK: call {{.*}}@_ZN5test21AIiEF1fEzQ4TrueIT_E( // CLANG17: call {{.*}}@_ZN5test21fEz( f(ai); -// CHECK: call {{.*}}@_ZN5test2F1gIvEEvzQaa4TrueIT_E4TrueITL0__E( +// CHECK: call {{.*}}@_ZN5test21AIiEF1gIvEEvzQaa4TrueIT_E4TrueITL0__E( // CLANG17: call {{.*}}@_ZN5test21gIvEEvz( g(ai); // CHECK: call {{.*}}@_ZN5test21hIvEEvzQ4TrueITL0__E( // CLANG17: call {{.*}}@_ZN5test21hIvEEvz( h(ai); -// CHECK: call {{.*}}@_ZN5test2F1iIvQaa4TrueIT_E4TrueITL0__EEEvz( +// CHECK: call {{.*}}@_ZN5test21AIiEF1iIvQaa4TrueIT_E4TrueITL0__EEEvz( // CLANG17: call {{.*}}@_ZN5test21iIvEEvz( i(ai); // CHECK: call {{.*}}@_ZN5test21jIvQ4TrueITL0__EEEvz( // CLANG17: call {{.*}}@_ZN5test21jIvEEvz( j(ai); -// CHECK: call {{.*}}@_ZN5test2F1kITk4TruevQ4TrueIT_EEEvz( +// CHECK: call {{.*}}@_ZN5test21AIiEF1kITk4TruevQ4TrueIT_EEEvz( // CLANG17: call {{.*}}@_ZN5test21kIvEEvz( k(ai); // CHECK: call {{.*}}@_ZN5test21lITk4TruevEEvz( diff --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp index 17786a3a486fcd..efe482aad1b76c 100644 --- a/libcxxabi/test/test_demangle.pass.cpp +++ b/libcxxabi/test/test_demangle.pass.cpp @@ -30128,11 +30128,11 @@ const char* cases[][2] = // C++20 concepts, see https://github.com/itanium-cxx-abi/cxx-abi/issues/24. {"_Z2f0IiE1SIX1CIT_EEEv", "S> f0()"}, {"_ZN5test21AIiEF1fEzQ4TrueIT_E", "test2::A::friend f(...) requires True"}, -{"_ZN5test2F1gIvEEvzQaa4TrueIT_E4TrueITL0__E", "void test2::friend g(...) requires True && True"}, +{"_ZN5test21AIiEF1gIvEEvzQaa4TrueIT_E4TrueITL0__E", "void test2::A::friend g(...) requires True && True"}, {"_ZN5test21hIvEEvzQ4TrueITL0__E", "void test2::h(...) requires True"}, -{"_ZN5test2F1iIvQaa4TrueIT_E4TrueITL0__EEEvz", "void test2::friend i(...)"}, +{"_ZN5test21AIiEF1iIvQaa4TrueIT_E4TrueITL0__EEEvz", "void test2::A::friend i(...)"}, {"_ZN5test21jIvQ4TrueITL0__EEEvz", "void test2::j(...)"}, -{"_ZN5test2F1kITk4TruevQ4TrueIT_EEEvz", "void test2::friend k(...)"}, +{"_ZN5test21AIiEF1kITk4TruevQ4TrueIT_EEEvz", "void test2::A::friend k(...)"}, {"_ZN5test21lITk4TruevEEvz", "void test2::l(...)"}, {"_ZN5test31dITnDaLi0EEEvv", "void test3::d<0>()"}, {"_ZN5test31eITnDcLi0EEEvv", "void test3::e<0>()"}, `` https://github.com/llvm/llvm-project/pull/110247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][test] add testing for the AST matcher reference (PR #94248)
https://github.com/5chmidti closed https://github.com/llvm/llvm-project/pull/94248 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix static analyzer concerns (PR #110243)
@@ -9195,7 +9195,7 @@ static bool checkOpenMPIterationSpace( SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), diag::note_omp_collapse_ordered_expr) << 0 << CollapseLoopCountExpr->getSourceRange(); - else + else if (OrderedLoopCountExpr) Fznamznon wrote: The problem with this approach is that both `OrderedLoopCountExpr` and `CollapseLoopCountExpr` will be dereferenced on lines 9192 and 9193 if they're both are `nullptr`s. https://github.com/llvm/llvm-project/pull/110243 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Fix example code for memberPointerType() AST matcher (PR #109404)
5chmidti wrote: I have fixed this as part of the implementation of #94248 https://github.com/llvm/llvm-project/pull/109404 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7dfdca1 - [clang][test] add TestLanguage.def to specify all tested language versions (#94243)
Author: Julian Schmidt Date: 2024-09-27T13:03:23+02:00 New Revision: 7dfdca1961aadc75ca397818bfb9bd32f1879248 URL: https://github.com/llvm/llvm-project/commit/7dfdca1961aadc75ca397818bfb9bd32f1879248 DIFF: https://github.com/llvm/llvm-project/commit/7dfdca1961aadc75ca397818bfb9bd32f1879248.diff LOG: [clang][test] add TestLanguage.def to specify all tested language versions (#94243) Adds a def file to have a single location where tested language versions are specified. Removes the need to update multiple locations in the testing infrastructure to add a new language version to be tested. Test instatiation can now include all languages without needing to specify them. This patch also adds pretty printing for instantiated test names. That means, that a test instantiated with C++23 will have the name `...TestSuite/TestName/CXX23` instead ending with some number (index of the argument for instantiation of the test), which provides a better experience when encountering a test failure with a specific language version. The suffix will also contain an `_win` if the target contains `win`. - Co-authored-by: Sirraide Added: clang/include/clang/Testing/TestLanguage.def Modified: clang/include/clang/Testing/CommandLineArgs.h clang/include/clang/Testing/TestClangConfig.h clang/lib/Testing/CommandLineArgs.cpp clang/unittests/AST/MatchVerifier.h clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp clang/unittests/Tooling/Syntax/BuildTreeTest.cpp clang/unittests/Tooling/Syntax/MutationsTest.cpp clang/unittests/Tooling/Syntax/SynthesisTest.cpp clang/unittests/Tooling/Syntax/TreeTest.cpp clang/unittests/Tooling/Syntax/TreeTestBase.cpp Removed: diff --git a/clang/include/clang/Testing/CommandLineArgs.h b/clang/include/clang/Testing/CommandLineArgs.h index e71907e8bbd0c6..52beac7254fefc 100644 --- a/clang/include/clang/Testing/CommandLineArgs.h +++ b/clang/include/clang/Testing/CommandLineArgs.h @@ -21,19 +21,18 @@ namespace clang { enum TestLanguage { - Lang_C89, - Lang_C99, - Lang_CXX03, - Lang_CXX11, - Lang_CXX14, - Lang_CXX17, - Lang_CXX20, - Lang_CXX23, +#define TESTLANGUAGE(lang, version, std_flag, version_index) \ + Lang_##lang##version, +#include "clang/Testing/TestLanguage.def" + Lang_OpenCL, Lang_OBJC, - Lang_OBJCXX + Lang_OBJCXX, }; +std::vector getCOrLater(int MinimumStd); +std::vector getCXXOrLater(int MinimumStd); + std::vector getCommandLineArgsForTesting(TestLanguage Lang); std::vector getCC1ArgsForTesting(TestLanguage Lang); diff --git a/clang/include/clang/Testing/TestClangConfig.h b/clang/include/clang/Testing/TestClangConfig.h index 1b4efca80e9d47..e52aa37482dc10 100644 --- a/clang/include/clang/Testing/TestClangConfig.h +++ b/clang/include/clang/Testing/TestClangConfig.h @@ -27,37 +27,90 @@ struct TestClangConfig { /// The argument of the `-target` command line flag. std::string Target; - bool isC() const { return Language == Lang_C89 || Language == Lang_C99; } + bool isC() const { +return false +#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \ + || Language == Lang_##lang##version +#include "clang/Testing/TestLanguage.def" +; + } - bool isC99OrLater() const { return Language == Lang_C99; } + bool isC(int Version) const { +return false +#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \ + || (Version == version && Language == Lang_##lang##version) +#include "clang/Testing/TestLanguage.def" +; + } - bool isCXX() const { -return Language == Lang_CXX03 || Language == Lang_CXX11 || - Language == Lang_CXX14 || Language == Lang_CXX17 || - Language == Lang_CXX20 || Language == Lang_CXX23; + bool isCOrLater(int MinimumStdVersion) const { +const auto MinimumStdVersionIndex = 0 +#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \ + +(MinimumStdVersion == version ? version_index : 0) +#include "clang/Testing/TestLanguage.def" +; +switch (Language) { +#define TESTLANGUAGE_C(lang, version, std_flag, version_index) \ + case Lang_##lang##version: \ +return MinimumStdVersionIndex <= version_index; +#include "clang/Testing/TestLanguage.def" +default: + return false; +} } - bool isCXX11OrLater() const { -return Language == Lang_CXX11 || Language == Lang_CXX14 || - Language == Lang_CXX17 || Language == Lang_CXX20 || - Language == Lang_CXX23; + bool isC99OrLater() const { return isCOrLater(99); } + + bool isCOrEarlier(int MaximumStdVersion) const { +return isC() && (isC(MaximumStdVersion) || !isCOrLater(MaximumStdVersion)); } - bool isCXX14OrLater() const { -
[clang] [clang][test] add TestLanguage.def to specify all tested language versions (PR #94243)
https://github.com/5chmidti closed https://github.com/llvm/llvm-project/pull/94243 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][test] remove unused `run` overload in `BoundNodesCallback` (PR #105935)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/105935 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix static analyzer concerns (PR #110243)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Mariya Podchishchaeva (Fznamznon) Changes It seems in checkOpenMPIterationSpace `OrderedLoopCountExpr` can also be null, so check before dereferencing. --- Full diff: https://github.com/llvm/llvm-project/pull/110243.diff 1 Files Affected: - (modified) clang/lib/Sema/SemaOpenMP.cpp (+1-1) ``diff diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 9afb8cea26fe78..8615da4b044a82 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -9195,7 +9195,7 @@ static bool checkOpenMPIterationSpace( SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), diag::note_omp_collapse_ordered_expr) << 0 << CollapseLoopCountExpr->getSourceRange(); - else + else if (OrderedLoopCountExpr) SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), diag::note_omp_collapse_ordered_expr) << 1 << OrderedLoopCountExpr->getSourceRange(); `` https://github.com/llvm/llvm-project/pull/110243 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][LLVM][AArch64] Add intrinsic for LUTI4 SME2 instruction (#97755) (PR #109953)
https://github.com/CarolineConcatto updated https://github.com/llvm/llvm-project/pull/109953 >From bef293187f32e4e197035eda299f73a5fd8f8684 Mon Sep 17 00:00:00 2001 From: CarolineConcatto Date: Wed, 25 Sep 2024 09:53:23 +0100 Subject: [PATCH 1/3] [Clang][LLVM][AArch64] Add intrinsic for LUTI4 SME2 instruction (#97755) This patch was reverted because of a failing C test. It now has being solved and can be merged into main again This patch adds these intrinsics: // Variants are also available for: _s8 svuint8x4_t svluti4_zt_u8_x4(uint64_t zt0, svuint8x2_t zn) __arm_streaming __arm_in("zt0"); according to PR#324[1] [1]ARM-software/acle#324 OBS.: Fix the clang test run line Address comments about the functions SelectMultiVectorLuti --- clang/include/clang/Basic/arm_sme.td | 5 ++ .../acle_sme2_luti4_zt.c | 86 +++ .../aarch64-sme2-intrinsics/acle_sme2_imm.cpp | 5 ++ llvm/include/llvm/IR/IntrinsicsAArch64.td | 6 ++ .../Target/AArch64/AArch64ISelDAGToDAG.cpp| 54 ++-- .../lib/Target/AArch64/AArch64SMEInstrInfo.td | 2 +- .../CodeGen/AArch64/sme2-intrinsics-luti4.ll | 17 7 files changed, 165 insertions(+), 10 deletions(-) create mode 100644 clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-luti4.ll diff --git a/clang/include/clang/Basic/arm_sme.td b/clang/include/clang/Basic/arm_sme.td index ae6b55e98827ff..9c9f31f3884069 100644 --- a/clang/include/clang/Basic/arm_sme.td +++ b/clang/include/clang/Basic/arm_sme.td @@ -817,4 +817,9 @@ multiclass ZAReadzArray{ defm SVREADZ_VG2 : ZAReadzArray<"2">; defm SVREADZ_VG4 : ZAReadzArray<"4">; + +let SMETargetGuard = "sme2,sme-lutv2" in { + def SVLUTI4_ZT_X4 : SInst<"svluti4_zt_{d}_x4", "4i2.u", "cUc", MergeNone, "aarch64_sme_luti4_zt_x4", [IsStreaming, IsInZT0], [ImmCheck<0, ImmCheck0_0>]>; +} + } // let SVETargetGuard = InvalidMode diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c new file mode 100644 index 00..fc4b6fa299f90f --- /dev/null +++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c @@ -0,0 +1,86 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 + +// REQUIRES: aarch64-registered-target + +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -disable-O0-optnone -Werror -Wall -o /dev/null %s + + +#include + +// CHECK-LABEL: define dso_local { , , , } @test_luti4_zt_u8_x4( +// CHECK-SAME: [[OP_COERCE0:%.*]], [[OP_COERCE1:%.*]]) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:[[RETVAL:%.*]] = alloca { , , , }, align 16 +// CHECK-NEXT:[[TMP0:%.*]] = tail call { , , , } @llvm.aarch64.sme.luti4.zt.x4.nxv16i8(i32 0, [[OP_COERCE0]], [[OP_COERCE1]]) +// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { , , , } [[TMP0]], 0 +// CHECK-NEXT:[[TMP2:%.*]] = tail call @llvm.vector.insert.nxv64i8.nxv16i8( poison, [[TMP1]], i64 0) +// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , , , } [[TMP0]], 1 +// CHECK-NEXT:[[TMP4:%.*]] = tail call @llvm.vector.insert.nxv64i8.nxv16i8( [[TMP2]], [[TMP3]], i64 16) +// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , , , } [[TMP0]], 2 +// CHECK-NEXT:[[TMP6:%.*]] = tail call @llvm.vector.insert.nxv64i8.nxv16i8( [[TMP4]], [[TMP5]], i64 32) +// CHECK-NEXT:[[TMP7:%.*]] = extractvalue { , , , } [[TMP0]], 3 +// CHECK-NEXT:[[TMP8:%.*]] = tail call @llvm.vector.insert.nxv64i8.nxv16i8( [[TMP6]], [[TMP7]], i64 48) +// CHECK-NEXT:store [[TMP8]], ptr [[RETVAL]], align 16 +// CHECK-NEXT:[[TMP9:%.*]] = load { , , , }, ptr [[RETVAL]], align 16 +// CHECK-NEXT:ret { , , , } [[TMP9]] +// +// CPP-CHECK-LABEL: define dso_local { , , , } @_Z19test_luti4_zt_u8_x411svuint8x2_t( +// CPP-CHECK-SAME: [[OP_COERCE0:%.*]], [[OP_COERCE1:%.*]]) #[[ATTR0:[0-9]+]] { +// CPP-CHECK-NEXT: [[ENTRY:.*:]] +// CPP-CHECK-NEXT:[[RETVAL:%.*]] = alloca { , , , }, align 16 +// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call { , , , } @llvm.aarch64.sme.luti4.zt.x4.nxv16i8(i32 0, [[OP_COERCE0]], [[OP_COERCE1]]) +// CPP-CHECK-NEXT:[[TMP1:%.*]] = extractvalue { , , , } [[TMP0]], 0 +// CPP-CHECK-NEXT:[[TMP2:%.*]] = t
[clang] [clang] Fix static analyzer concerns (PR #110243)
https://github.com/Fznamznon created https://github.com/llvm/llvm-project/pull/110243 It seems in checkOpenMPIterationSpace `OrderedLoopCountExpr` can also be null, so check before dereferencing. >From 314a8f4d4f8e003881bed0c320f9ee80ba0b8f8c Mon Sep 17 00:00:00 2001 From: "Podchishchaeva, Mariya" Date: Fri, 27 Sep 2024 04:00:31 -0700 Subject: [PATCH] [clang] Fix static analyzer concerns It seems in checkOpenMPIterationSpace `OrderedLoopCountExpr` can also be null, so check before dereferencing. --- clang/lib/Sema/SemaOpenMP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 9afb8cea26fe78..8615da4b044a82 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -9195,7 +9195,7 @@ static bool checkOpenMPIterationSpace( SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), diag::note_omp_collapse_ordered_expr) << 0 << CollapseLoopCountExpr->getSourceRange(); - else + else if (OrderedLoopCountExpr) SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), diag::note_omp_collapse_ordered_expr) << 1 << OrderedLoopCountExpr->getSourceRange(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [AArch64] Split FeatureMTE to FEAT_MTE and FEAT_MTE2. (PR #109299)
https://github.com/tmatheson-arm deleted https://github.com/llvm/llvm-project/pull/109299 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add/enhance documentation for some important classes. (PR #109795)
https://github.com/kadircet edited https://github.com/llvm/llvm-project/pull/109795 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add/enhance documentation for some important classes. (PR #109795)
@@ -1802,32 +1802,32 @@ enum class ArraySizeModifier; enum class ElaboratedTypeKeyword; enum class VectorKind; -/// The base class of the type hierarchy. +/// A type in the program, such as `int` or `vector`. +/// This the base class for a hierarchy: PointerType, BuiltinType etc. /// -/// A central concept with types is that each type always has a canonical -/// type. A canonical type is the type with any typedef names stripped out -/// of it or the types it references. For example, consider: +/// Types appear throughout the AST: expressions and (some) declarations have +/// types; casts, new-expressions, and template-arguments refer to types, etc. +/// A Type is not tied to a specific place where it was written (see TypeLoc). /// -/// typedef int foo; -/// typedef foo* bar; -///'int *''foo *''bar' +/// For each distinct type (per language rules) there is one canonical Type. +/// Compound types are formed as trees of simpler types. +/// e.g `int*`: a PointerType(pointee = BuiltinType(kind = Int)). +/// Types are interned: you can compare canonical type equality by pointer. /// -/// There will be a Type object created for 'int'. Since int is canonical, its -/// CanonicalType pointer points to itself. There is also a Type for 'foo' (a -/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next -/// there is a PointerType that represents 'int*', which, like 'int', is -/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical -/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type -/// is also 'int*'. +/// There are also non-canonical "sugar" types, which also describe e.g. what +/// typedef was used. For example: /// -/// Non-canonical types are useful for emitting diagnostics, without losing -/// information about typedefs being used. Canonical types are useful for type -/// comparisons (they allow by-pointer equality tests) and useful for reasoning -/// about whether something has a particular form (e.g. is a function type), -/// because they implicitly, recursively, strip all typedefs out of a type. +/// using Integer = int; // BuiltinType(kind = int) +/// Integer* x; // PointerType(pointee = TypedefType(decl=Integer)) /// -/// Types, once created, are immutable. +/// The Type obtained from the VarDecl for x reflects how that declaration was +/// written. This is useful for diagnostic messages, for example. +/// Each Type has a pointer to its canonical type, and these should be used for +/// semantic checks: are two types equal, is this a function type, etc. /// +/// All types are allocated within the ASTContext, interned, and immutable. kadircet wrote: i think we should preserve the previous comment that expands on `interned` by mentioning `pointer-equality`. https://github.com/llvm/llvm-project/pull/109795 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add/enhance documentation for some important classes. (PR #109795)
@@ -79,8 +79,24 @@ enum class StringLiteralKind; // AST classes for statements. //===--===// -/// Stmt - This represents one statement. +/// A statement or expression in the program. /// +/// This is the base for the hierarchy of statements (ForStmt, ReturnStmt...) +/// as well as expressions (Expr, CastExpr, IntegerLiteral...). +/// Classing expressions as Stmt allows them to appear as statements without +/// needing an extra "expression-statement" node. +/// +/// Statements can have children and so form trees. e.g. `while (i>0) i--;`: +/// +/// WhileStmt +/// |-BinaryOperator > +/// | |-DeclRefExpr i +/// | `-IntegerLiteral 0 +/// `-UnaryOperator -- +/// `-DeclRefExpr i +/// +/// These trees are often rooted at function bodies, and attach to the rest +/// of the AST via FunctionDecls. kadircet wrote: i am not sure what's the value we get out of this paragraph. maybe just emphasize they usually attach the AST via Decls? https://github.com/llvm/llvm-project/pull/109795 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add/enhance documentation for some important classes. (PR #109795)
https://github.com/kadircet approved this pull request. thanks a lot for doing this! https://github.com/llvm/llvm-project/pull/109795 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] Reapply "Deprecate the `-fbasic-block-sections=labels` option." (PR #110039)
steelannelida wrote: This broke on of our tests. Here's a repro: https://godbolt.org/z/5xc7GfxcY I'm not sure if that's intentional or a bug. https://github.com/llvm/llvm-project/pull/110039 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ItaniumMangle] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)
@@ -237,6 +237,11 @@ class LangOptionsBase { /// in the initializers of members of local classes. Ver18, +/// Attempt to be ABI-compatible with code generated by Clang 19.0.x. +/// This causes clang to: +/// - Incorrect Mangling of CXXCtorVTable tcwzxx wrote: Thanks. Updated. https://github.com/llvm/llvm-project/pull/109970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates (PR #107786)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/107786 >From e9948a1004cc2b486a0422d83e88392754e9f7e9 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 23 Sep 2024 17:17:30 +0300 Subject: [PATCH 1/2] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates --- clang/docs/ReleaseNotes.rst | 2 ++ clang/include/clang/Sema/Sema.h | 4 ++- clang/lib/Sema/SemaExpr.cpp | 12 +-- clang/lib/Sema/SemaOverload.cpp | 2 +- .../SemaTemplate/recovery-crash-cxx20.cpp | 32 +++ 5 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 clang/test/SemaTemplate/recovery-crash-cxx20.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b47e06cb0c5d68..110f75d739c072 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -424,6 +424,8 @@ Bug Fixes to C++ Support - Fixed an assertion failure in debug mode, and potential crashes in release mode, when diagnosing a failed cast caused indirectly by a failed implicit conversion to the type of the constructor parameter. - Fixed an assertion failure by adjusting integral to boolean vector conversions (#GH108326) +- Fixed an assertion failure when invoking recovery call expressions with explicit attributes + and undeclared templates. (#GH107047, #GH49093) Bug Fixes to AST Handling ^ diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index e1c3a99cfa167e..b2eefdbd1c56d1 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -6753,7 +6753,9 @@ class Sema final : public SemaBase { /// /// Return \c true if the error is unrecoverable, or \c false if the caller /// should attempt to recover using these lookup results. - bool DiagnoseDependentMemberLookup(const LookupResult &R); + bool DiagnoseDependentMemberLookup( + const LookupResult &R, + TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); /// Diagnose an empty lookup. /// diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 66df9c969256a2..a5770ae8848517 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2385,7 +2385,15 @@ static void emitEmptyLookupTypoDiagnostic( SemaRef.PDiag(NoteID)); } -bool Sema::DiagnoseDependentMemberLookup(const LookupResult &R) { +bool Sema::DiagnoseDependentMemberLookup( +const LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs) { + auto IsTemplated = [](NamedDecl *D) { return D->isTemplated(); }; + if (ExplicitTemplateArgs && !llvm::all_of(R, IsTemplated)) { +Diag(R.getNameLoc(), diag::err_non_template_in_template_id) +<< R.getLookupName(); +return true; + } + // During a default argument instantiation the CurContext points // to a CXXMethodDecl; but we can't apply a this-> fixit inside a // function parameter list, hence add an explicit check. @@ -2487,7 +2495,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, R.resolveKind(); } -return DiagnoseDependentMemberLookup(R); +return DiagnoseDependentMemberLookup(R, ExplicitTemplateArgs); } R.clear(); diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index d304f322aced64..fe9b16e1890c16 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -13860,7 +13860,7 @@ BuildRecoveryCallExpr(Sema &SemaRef, Scope *S, Expr *Fn, // enclosing class. // FIXME: We should also explain why the candidates found by name lookup // were not viable. -if (SemaRef.DiagnoseDependentMemberLookup(R)) +if (SemaRef.DiagnoseDependentMemberLookup(R, ExplicitTemplateArgs)) return ExprError(); } else { // We had viable candidates and couldn't recover; let the caller diagnose diff --git a/clang/test/SemaTemplate/recovery-crash-cxx20.cpp b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp new file mode 100644 index 00..3651b986dfd989 --- /dev/null +++ b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s + +namespace GH49093 { + class B { + public: +static int a() { return 0; } +decltype(a< 0 >(0)) test; // expected-error {{'a' does not name a template but is followed by template arguments}} + }; + + struct C { + static int a() { return 0; } + decltype(a < 0 > (0)) test; // expected-error {{'a' does not name a template but is followed by template arguments}} + }; + + void test_is_bool(bool t) {} + void test_is_bool(int t) {} + + int main() { +B b; +test_is_bool(b.test); + +C c; +test_is_bool(c.test); + } +} + +namespace GH107047 { + struct A { +static constexpr auto test() { return 1; } +
[clang] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates (PR #107786)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/107786 >From e9948a1004cc2b486a0422d83e88392754e9f7e9 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 23 Sep 2024 17:17:30 +0300 Subject: [PATCH 1/2] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates --- clang/docs/ReleaseNotes.rst | 2 ++ clang/include/clang/Sema/Sema.h | 4 ++- clang/lib/Sema/SemaExpr.cpp | 12 +-- clang/lib/Sema/SemaOverload.cpp | 2 +- .../SemaTemplate/recovery-crash-cxx20.cpp | 32 +++ 5 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 clang/test/SemaTemplate/recovery-crash-cxx20.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b47e06cb0c5d68..110f75d739c072 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -424,6 +424,8 @@ Bug Fixes to C++ Support - Fixed an assertion failure in debug mode, and potential crashes in release mode, when diagnosing a failed cast caused indirectly by a failed implicit conversion to the type of the constructor parameter. - Fixed an assertion failure by adjusting integral to boolean vector conversions (#GH108326) +- Fixed an assertion failure when invoking recovery call expressions with explicit attributes + and undeclared templates. (#GH107047, #GH49093) Bug Fixes to AST Handling ^ diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index e1c3a99cfa167e..b2eefdbd1c56d1 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -6753,7 +6753,9 @@ class Sema final : public SemaBase { /// /// Return \c true if the error is unrecoverable, or \c false if the caller /// should attempt to recover using these lookup results. - bool DiagnoseDependentMemberLookup(const LookupResult &R); + bool DiagnoseDependentMemberLookup( + const LookupResult &R, + TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); /// Diagnose an empty lookup. /// diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 66df9c969256a2..a5770ae8848517 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2385,7 +2385,15 @@ static void emitEmptyLookupTypoDiagnostic( SemaRef.PDiag(NoteID)); } -bool Sema::DiagnoseDependentMemberLookup(const LookupResult &R) { +bool Sema::DiagnoseDependentMemberLookup( +const LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs) { + auto IsTemplated = [](NamedDecl *D) { return D->isTemplated(); }; + if (ExplicitTemplateArgs && !llvm::all_of(R, IsTemplated)) { +Diag(R.getNameLoc(), diag::err_non_template_in_template_id) +<< R.getLookupName(); +return true; + } + // During a default argument instantiation the CurContext points // to a CXXMethodDecl; but we can't apply a this-> fixit inside a // function parameter list, hence add an explicit check. @@ -2487,7 +2495,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, R.resolveKind(); } -return DiagnoseDependentMemberLookup(R); +return DiagnoseDependentMemberLookup(R, ExplicitTemplateArgs); } R.clear(); diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index d304f322aced64..fe9b16e1890c16 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -13860,7 +13860,7 @@ BuildRecoveryCallExpr(Sema &SemaRef, Scope *S, Expr *Fn, // enclosing class. // FIXME: We should also explain why the candidates found by name lookup // were not viable. -if (SemaRef.DiagnoseDependentMemberLookup(R)) +if (SemaRef.DiagnoseDependentMemberLookup(R, ExplicitTemplateArgs)) return ExprError(); } else { // We had viable candidates and couldn't recover; let the caller diagnose diff --git a/clang/test/SemaTemplate/recovery-crash-cxx20.cpp b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp new file mode 100644 index 00..3651b986dfd989 --- /dev/null +++ b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s + +namespace GH49093 { + class B { + public: +static int a() { return 0; } +decltype(a< 0 >(0)) test; // expected-error {{'a' does not name a template but is followed by template arguments}} + }; + + struct C { + static int a() { return 0; } + decltype(a < 0 > (0)) test; // expected-error {{'a' does not name a template but is followed by template arguments}} + }; + + void test_is_bool(bool t) {} + void test_is_bool(int t) {} + + int main() { +B b; +test_is_bool(b.test); + +C c; +test_is_bool(c.test); + } +} + +namespace GH107047 { + struct A { +static constexpr auto test() { return 1; } +
[clang] [Clang] Update Interpreter tests to use clang_target_link_libraries (PR #110154)
https://github.com/vgvassilev updated https://github.com/llvm/llvm-project/pull/110154 >From a9d8655d493e6de3b36ccd9f24fa8fefe17fbff6 Mon Sep 17 00:00:00 2001 From: Thomas Fransham Date: Thu, 26 Sep 2024 18:59:33 +0100 Subject: [PATCH] [Clang] Update Interpreter tests to use clang_target_link_libraries This will fix duplicate and missing linker symbol errors when using CLANG_LINK_CLANG_DYLIB on windows and explicit visibility macros are used. This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and plugins on window. --- clang/unittests/Interpreter/CMakeLists.txt | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/unittests/Interpreter/CMakeLists.txt b/clang/unittests/Interpreter/CMakeLists.txt index ec6f81ea19b960..1ed1216c772e8f 100644 --- a/clang/unittests/Interpreter/CMakeLists.txt +++ b/clang/unittests/Interpreter/CMakeLists.txt @@ -16,13 +16,15 @@ add_clang_unittest(ClangReplInterpreterTests EXPORT_SYMBOLS ) -target_link_libraries(ClangReplInterpreterTests PUBLIC + +target_link_libraries(ClangReplInterpreterTests PUBLIC LLVMTestingSupport) + +clang_target_link_libraries(ClangReplInterpreterTests PRIVATE clangAST clangBasic clangInterpreter clangFrontend clangSema - LLVMTestingSupport ) # Exceptions on Windows are not yet supported. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Start implementing fixed point types (PR #110216)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/110216 Add the primitive type and implement to-bool casts. >From 7378e7ed04aa8ee853b718649b21c7b71ad07b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Fri, 27 Sep 2024 09:44:30 +0200 Subject: [PATCH] [clang][bytecode] Start implementing fixed point types --- clang/lib/AST/ByteCode/ByteCodeEmitter.cpp | 1 + clang/lib/AST/ByteCode/Compiler.cpp| 18 ++- clang/lib/AST/ByteCode/Compiler.h | 1 + clang/lib/AST/ByteCode/Context.cpp | 3 ++ clang/lib/AST/ByteCode/Descriptor.cpp | 1 + clang/lib/AST/ByteCode/Disasm.cpp | 3 ++ clang/lib/AST/ByteCode/FixedPoint.h| 57 ++ clang/lib/AST/ByteCode/Interp.h| 1 + clang/lib/AST/ByteCode/InterpStack.cpp | 1 + clang/lib/AST/ByteCode/InterpStack.h | 3 ++ clang/lib/AST/ByteCode/Opcodes.td | 7 ++- clang/lib/AST/ByteCode/PrimType.cpp| 1 + clang/lib/AST/ByteCode/PrimType.h | 6 +++ clang/test/AST/ByteCode/fixed-point.cpp| 6 +++ 14 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 clang/lib/AST/ByteCode/FixedPoint.h create mode 100644 clang/test/AST/ByteCode/fixed-point.cpp diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp index b8778f6027894c..4fd697ebe4938d 100644 --- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp +++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp @@ -8,6 +8,7 @@ #include "ByteCodeEmitter.h" #include "Context.h" +#include "FixedPoint.h" #include "Floating.h" #include "IntegralAP.h" #include "Opcode.h" diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 93008acde65f9d..aac3fd384130d7 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -9,6 +9,7 @@ #include "Compiler.h" #include "ByteCodeEmitter.h" #include "Context.h" +#include "FixedPoint.h" #include "Floating.h" #include "Function.h" #include "InterpShared.h" @@ -470,6 +471,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) { } case CK_IntegralToBoolean: + case CK_FixedPointToBoolean: case CK_BooleanToSignedIntegral: case CK_IntegralCast: { if (DiscardResult) @@ -717,6 +719,16 @@ bool Compiler::VisitImaginaryLiteral(const ImaginaryLiteral *E) { return this->visitArrayElemInit(1, SubExpr); } +template +bool Compiler::VisitFixedPointLiteral(const FixedPointLiteral *E) { + assert(E->getType()->isFixedPointType()); + assert(classifyPrim(E) == PT_FixedPoint); + + // FIXME: Semantics. + APInt Value = E->getValue(); + return this->emitConstFixedPoint(Value, E); +} + template bool Compiler::VisitParenExpr(const ParenExpr *E) { return this->delegate(E->getSubExpr()); @@ -3685,9 +3697,10 @@ bool Compiler::visitZeroInitializer(PrimType T, QualType QT, return this->emitNullFnPtr(nullptr, E); case PT_MemberPtr: return this->emitNullMemberPtr(nullptr, E); - case PT_Float: { + case PT_Float: return this->emitConstFloat(APFloat::getZero(Ctx.getFloatSemantics(QT)), E); - } + case PT_FixedPoint: +llvm_unreachable("Implement"); } llvm_unreachable("unknown primitive type"); } @@ -3798,6 +3811,7 @@ bool Compiler::emitConst(T Value, PrimType Ty, const Expr *E) { case PT_Float: case PT_IntAP: case PT_IntAPS: + case PT_FixedPoint: llvm_unreachable("Invalid integral type"); break; } diff --git a/clang/lib/AST/ByteCode/Compiler.h b/clang/lib/AST/ByteCode/Compiler.h index 94c0a5cb295b08..d1911f11603a08 100644 --- a/clang/lib/AST/ByteCode/Compiler.h +++ b/clang/lib/AST/ByteCode/Compiler.h @@ -125,6 +125,7 @@ class Compiler : public ConstStmtVisitor, bool>, bool VisitIntegerLiteral(const IntegerLiteral *E); bool VisitFloatingLiteral(const FloatingLiteral *E); bool VisitImaginaryLiteral(const ImaginaryLiteral *E); + bool VisitFixedPointLiteral(const FixedPointLiteral *E); bool VisitParenExpr(const ParenExpr *E); bool VisitBinaryOperator(const BinaryOperator *E); bool VisitLogicalBinOp(const BinaryOperator *E); diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index 8661acf536658f..9bca8138cd9f6f 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -198,6 +198,9 @@ std::optional Context::classify(QualType T) const { if (const auto *DT = dyn_cast(T)) return classify(DT->getUnderlyingType()); + if (T->isFixedPointType()) +return PT_FixedPoint; + return std::nullopt; } diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp b/clang/lib/AST/ByteCode/Descriptor.cpp index 44a7b88b2a1ee9..65ac7a3129abaf 100644 --- a/clang/lib/AST/ByteCode/Descriptor.cpp +++ b/clang/lib/AST/ByteCode/Descriptor.cpp @@ -8,6 +8,7 @@ #include "Descriptor.h" #include "Boolean.h" +#include "FixedPoint.h" #include "Floating.h" #include "FunctionPoin
[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)
@@ -251,6 +251,20 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, } else /*-mno-lasx*/ Features.push_back("-lasx"); } + + // Select frecipe feature determined by -m[no-]frecipe. + if (const Arg *A = + Args.getLastArg(options::OPT_mfrecipe, options::OPT_mno_frecipe)) { +// FRECIPE depends on 64-bit FPU. heiher wrote: Why doesn't `frecipe.s` work with only `+f`? https://github.com/llvm/llvm-project/pull/109917 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][LLVM][AArch64] Add intrinsic for MOVT SME2 instruction (PR #97602)
https://github.com/CarolineConcatto updated https://github.com/llvm/llvm-project/pull/97602 >From ac405d7516ea92cf3c63220d1bdf0677dd7dd372 Mon Sep 17 00:00:00 2001 From: Caroline Concatto Date: Wed, 3 Jul 2024 15:55:45 + Subject: [PATCH 1/7] [Clang][LLVM][AArch64] Add intrinsic for MOVT SME2 instruction This patch adds these intrinsics: // Variants are also available for: // [_s8], [_u16], [_s16], [_u32], [_s32], [_u64], [_s64] // [_bf16], [_f16], [_f32], [_f64] void svwrite_lane_zt[_u8](uint64_t zt0, svuint8_t zt, uint64_t idx) __arm_streaming __arm_inout("zt0"); void svwrite_zt[_u8](uint64_t zt0, svuint8_t zt) __arm_streaming __arm_inout("zt0"); according to PR#324[1] [1]https://github.com/ARM-software/acle/pull/324 --- clang/include/clang/Basic/arm_sme.td | 6 + .../acle_sme2_write_lane_zt.c | 401 ++ .../aarch64-sme2-intrinsics/acle_sme2_imm.cpp | 15 +- llvm/include/llvm/IR/IntrinsicsAArch64.td | 9 + .../Target/AArch64/AArch64ISelLowering.cpp| 2 + .../lib/Target/AArch64/AArch64SMEInstrInfo.td | 2 +- llvm/lib/Target/AArch64/SMEInstrFormats.td| 42 +- .../AArch64/sme2-intrinsics-read-zt.ll| 162 +++ 8 files changed, 636 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_write_lane_zt.c create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-read-zt.ll diff --git a/clang/include/clang/Basic/arm_sme.td b/clang/include/clang/Basic/arm_sme.td index ae6b55e98827ff..52997f67b5cd9f 100644 --- a/clang/include/clang/Basic/arm_sme.td +++ b/clang/include/clang/Basic/arm_sme.td @@ -817,4 +817,10 @@ multiclass ZAReadzArray{ defm SVREADZ_VG2 : ZAReadzArray<"2">; defm SVREADZ_VG4 : ZAReadzArray<"4">; + +let SMETargetGuard = "sme2,sme-lutv2" in { + def SVLUTI4_ZT_X4 : SInst<"svluti4_zt_{d}_x4", "4i2.u", "cUc", MergeNone, "aarch64_sme_luti4_zt_x4", [IsStreaming, IsInZT0], [ImmCheck<0, ImmCheck0_0>]>; + def SVWRITE_LANE_ZT : SInst<"svwrite_lane_zt[_{d}]", "vidi", "cUcsUsiUilUlfhdb", MergeNone, "aarch64_sme_write_lane_zt", [IsStreaming, IsInOutZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>; + def SVWRITE_ZT : SInst<"svwrite_zt[_{d}]", "vid", "cUcsUsiUilUlfhdb", MergeNone, "aarch64_sme_write_zt", [IsStreaming, IsInOutZT0], [ImmCheck<0, ImmCheck0_0>]>; +} } // let SVETargetGuard = InvalidMode diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_write_lane_zt.c b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_write_lane_zt.c new file mode 100644 index 00..9bdc3481953a21 --- /dev/null +++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_write_lane_zt.c @@ -0,0 +1,401 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -x c++ -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK-CXX +// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -x c++ -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK-CXX + +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -O2 -S -Werror -Wall -o /dev/null %s +// REQUIRES: aarch64-registered-target + +#ifdef SVE_OVERLOADED_FORMS +#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1 +#else +#define SVE_ACLE_FUNC(A1,A2) A1##A2 +#endif + +#include + +// CHECK-LABEL: define dso_local void @test_write_lane_zt_u8_1( +// CHECK-SAME: [[V:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:tail call void @llvm.aarch64.sme.write.lane.zt.nxv16i8(i32 0, [[V]], i32 1) +// CHECK-NEXT:ret void +// +// CHECK-CXX-LABEL: define dso_local void @_Z23test_write_lane_zt_u8_1u11__SVUint8_t( +// CHECK-CXX-SAME: [[V:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-CXX-NEXT: [[ENTRY:.*:]] +// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.write.lane.zt.nxv16i8(i32 0, [[V]], i32 1) +// CHECK-CXX-NEXT:ret void +// +void test_write_lane_zt_u8_1(svuint8_t v) __arm_streaming __arm_inout("zt0") { + SVE_ACLE_FUNC(svwrite_lane_zt, _u8)(0, v, 1); +} + +// CHECK-LABEL: define dso_local void @test_write_lane_zt_s8_2( +// CHECK-SAME: [[V:%.*]]) local_unnamed_addr #[[ATTR0]] { +// CHECK-NEXT: [
[clang] [Clang] GH93099 (PR #110238)
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/110238 >From 23a765ac6d8e455121346405332d2066dcc0861e Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Fri, 27 Sep 2024 18:23:47 +0800 Subject: [PATCH 1/2] [Clang] GH93099 --- clang/include/clang/Sema/Sema.h | 4 ++- clang/lib/Sema/SemaTemplateVariadic.cpp | 20 +++ clang/lib/Sema/TreeTransform.h| 16 ++--- .../SemaTemplate/concepts-out-of-line-def.cpp | 34 +++ 4 files changed, 61 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index e1c3a99cfa167e..1fce74880026ce 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -14264,7 +14264,9 @@ class Sema final : public SemaBase { /// /// This is intended for use when transforming 'sizeof...(Arg)' in order to /// avoid actually expanding the pack where possible. - std::optional getFullyPackExpandedSize(TemplateArgument Arg); + std::optional + getFullyPackExpandedSize(TemplateArgument Arg, + const NamedDecl *&ParameterPack); /// Called when an expression computing the size of a parameter pack /// is parsed. diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp index 40522a07f6339c..79e2f1f610b11f 100644 --- a/clang/lib/Sema/SemaTemplateVariadic.cpp +++ b/clang/lib/Sema/SemaTemplateVariadic.cpp @@ -1211,7 +1211,9 @@ TemplateArgumentLoc Sema::getTemplateArgumentPackExpansionPattern( llvm_unreachable("Invalid TemplateArgument Kind!"); } -std::optional Sema::getFullyPackExpandedSize(TemplateArgument Arg) { +std::optional +Sema::getFullyPackExpandedSize(TemplateArgument Arg, + const NamedDecl *&ParameterPack) { assert(Arg.containsUnexpandedParameterPack()); // If this is a substituted pack, grab that pack. If not, we don't know @@ -1222,17 +1224,20 @@ std::optional Sema::getFullyPackExpandedSize(TemplateArgument Arg) { TemplateArgument Pack; switch (Arg.getKind()) { case TemplateArgument::Type: -if (auto *Subst = Arg.getAsType()->getAs()) +if (auto *Subst = Arg.getAsType()->getAs()) { Pack = Subst->getArgumentPack(); -else + ParameterPack = Subst->getReplacedParameter(); +} else return std::nullopt; break; case TemplateArgument::Expression: if (auto *Subst = -dyn_cast(Arg.getAsExpr())) +dyn_cast(Arg.getAsExpr())) { Pack = Subst->getArgumentPack(); -else if (auto *Subst = dyn_cast(Arg.getAsExpr())) { + ParameterPack = Subst->getParameterPack(); +} else if (auto *Subst = dyn_cast(Arg.getAsExpr())) { + ParameterPack = Subst->getParameterPack(); for (VarDecl *PD : *Subst) if (PD->isParameterPack()) return std::nullopt; @@ -1243,9 +1248,10 @@ std::optional Sema::getFullyPackExpandedSize(TemplateArgument Arg) { case TemplateArgument::Template: if (SubstTemplateTemplateParmPackStorage *Subst = -Arg.getAsTemplate().getAsSubstTemplateTemplateParmPack()) +Arg.getAsTemplate().getAsSubstTemplateTemplateParmPack()) { Pack = Subst->getArgumentPack(); -else + ParameterPack = Subst->getParameterPack(); +} else return std::nullopt; break; diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 91cb980ee26b26..3a029e88e865df 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -15237,6 +15237,7 @@ TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) { // Try to compute the result without performing a partial substitution. std::optional Result = 0; + NamedDecl *NewPack = E->getPack(); for (const TemplateArgument &Arg : PackArgs) { if (!Arg.isPackExpansion()) { Result = *Result + 1; @@ -15260,9 +15261,14 @@ TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) { /*Uneval*/ true)) return true; +const NamedDecl *TransformedParameterPack = nullptr; // See if we can determine the number of arguments from the result. -std::optional NumExpansions = -getSema().getFullyPackExpandedSize(OutPattern.getArgument()); +std::optional NumExpansions = getSema().getFullyPackExpandedSize( +OutPattern.getArgument(), TransformedParameterPack); +if (TransformedParameterPack && !E->isPartiallySubstituted()) { + assert(PackArgs.size() == 1); + NewPack = const_cast(TransformedParameterPack); +} if (!NumExpansions) { // No: we must be in an alias template expansion, and we're going to need // to actually expand the packs. @@ -15277,7 +15283,7 @@ TreeTransform::TransformSizeOfPackExpr(SizeOfPackExpr *E) { // substituting. if (Result) return getDerived().RebuildSizeOfPackExpr( -E->getOperatorLoc(), E->getPa
[clang] [clang] fix the unexpected control flow in ParseTentative.cpp (PR #109298)
c8ef wrote: I'm sorry, but I can't identify a case that would trigger this code path. I might not be that familiar with ObjC... https://github.com/llvm/llvm-project/pull/109298 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix the local parameter of void type inside the `Requires` expression. (PR #109831)
c8ef wrote: > I think I agree with @mizvekov's idea of merging the parameter checks into > SemaType; we can probably in part reuse GetTypeForDeclarator. I would > appreciate it if we can see some exploration here. Apologies for the delayed response. The implementation I provided is actually derived from `GetTypeForDeclarator`, specifically `GetFullTypeForDeclarator`. The challenge I faced is that this function handles numerous cases. My initial idea was to extract a function from `GetTypeForDeclarator` to manage function parameters, but I'm uncertain if this is the best approach. I'm wondering what level of granularity we should aim for when reusing the current implementation in `GetTypeForDeclarator`? https://github.com/llvm/llvm-project/pull/109831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add "debug_transparent" attribute (PR #110188)
@@ -109,6 +110,20 @@ static bool IsArtificial(VarDecl const *VD) { cast(VD->getDeclContext())->isImplicit()); } +static bool usesDebugTransparent(const Decl *D, const CodeGenModule &CGM) { + if (!D) +return false; + + if (auto *attr = D->getAttr()) { +if (CGM.getCodeGenOpts().DwarfVersion == 0) { + CGM.getDiags().Report(attr->getLocation(), diag::warn_debug_transparent_ignored); +} Michael137 wrote: Nit: ```suggestion if (CGM.getCodeGenOpts().DwarfVersion == 0) CGM.getDiags().Report(attr->getLocation(), diag::warn_debug_transparent_ignored); ``` https://github.com/llvm/llvm-project/pull/110188 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add "debug_transparent" attribute (PR #110188)
https://github.com/Michael137 commented: Can we add tests that we do the right thing for constructors/destructors/inlined functions? https://github.com/llvm/llvm-project/pull/110188 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add "debug_transparent" attribute (PR #110188)
@@ -4566,6 +4583,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D); llvm::DISubroutineType *STy = getOrCreateFunctionType(D, FnType, Unit); + Michael137 wrote: stray newline https://github.com/llvm/llvm-project/pull/110188 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan] Update docs to include run-time flags (PR #110296)
https://github.com/cjappl updated https://github.com/llvm/llvm-project/pull/110296 >From eb8712a4eb82495a84e593c375f787017380de40 Mon Sep 17 00:00:00 2001 From: Chris Apple Date: Fri, 27 Sep 2024 09:40:11 -0700 Subject: [PATCH] [rtsan] Update docs to include run-time flags --- clang/docs/RealtimeSanitizer.rst | 69 1 file changed, 69 insertions(+) diff --git a/clang/docs/RealtimeSanitizer.rst b/clang/docs/RealtimeSanitizer.rst index 5e281a2a357907..bddf39ecaf1c5a 100644 --- a/clang/docs/RealtimeSanitizer.rst +++ b/clang/docs/RealtimeSanitizer.rst @@ -84,6 +84,75 @@ non-zero exit code. #14 0x0001958960dc () #15 0x2f557ffc () +Run-time flags +-- + +RealtimeSanitizer supports a number of run-time flags, which can be specified in the ``RTSAN_OPTIONS`` environment variable: + +.. code-block:: console + + % RTSAN_OPTIONS=option_1=true:path_option_2="/some/file.txt" ./a.out + ... + +Or at compiler time by overloading the symbol ``__rtsan_default_options``: + +.. code-block:: c + + extern "C" const char *__rtsan_default_options() { +return "symbolize=false:abort_on_error=0:log_to_syslog=0"; + } + +You can see all sanitizer options (some of which are unsupported) by using the ``help`` flag: + +.. code-block:: console + + % RTSAN_OPTIONS=help=true ./a.out + +A **partial** list of flags RealtimeSanitizer respects: + +.. list-table:: Run-time Flags + :widths: 20 10 10 70 + :header-rows: 1 + + * - Flag name + - Default value + - Type + - Short description + * - ``halt_on_error`` + - ``true`` + - boolean + - Exit after first reported error. If false (continue after a detected error), deduplicates error stacks so errors appear only once. + * - ``print_stats_on_exit`` + - ``false`` + - boolean + - Print stats on exit. Includes total and unique errors. + * - ``color`` + - ``"auto"`` + - string + - Colorize reports: (always|never|auto). + * - ``fast_unwind_on_fatal`` + - ``false`` + - boolean + - If available, use the fast frame-pointer-based unwinder on detected errors. If true, ensure the code under test has been compiled with frame pointers with ``-fno-omit-frame-pointers`` or similar. + * - ``abort_on_error`` + - OS dependent + - boolean + - If true, the tool calls abort() instead of _exit() after printing the error report. On some OSes (OSX, for exmple) this is beneficial because a better stack trace is emitted on crash. + * - ``symbolize`` + - ``true`` + - boolean + - If set, use the symbolizer to turn virtual addresses to file/line locations. If false, can greatly speed up the error reporting. + + +Some issues with flags can be debugged using the ``verbosity=$NUM`` flag: + +.. code-block:: console + + % RTSAN_OPTIONS=verbosity=1:misspelled_flag=true ./a.out + WARNING: found 1 unrecognized flag(s): + misspelled_flag + ... + Disabling - ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
@@ -6457,6 +6472,18 @@ void InitializationSequence::InitializeFrom(Sema &S, } } + if (!S.getLangOpts().CPlusPlus && + Kind.getKind() == InitializationKind::IK_Default) { +RecordDecl *Rec = DestType->getAsRecordDecl(); +if (Rec && Rec->hasUninitializedExplicitInitFields()) { + VarDecl *Var = dyn_cast_or_null(Entity.getDecl()); + if (Var && !Initializer) { +S.Diag(Var->getLocation(), diag::warn_field_requires_explicit_init) +<< true << Rec; erichkeane wrote: I don't doubt it :/ We've got quite a bit of 'uncleaned up' code around as we've learned the downsides of allowing things like this that have never caused a problem, so have never been cleaned up. https://github.com/llvm/llvm-project/pull/102040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [cuda][HIP] `__constant__` should imply constant (PR #110182)
https://github.com/Artem-B approved this pull request. https://github.com/llvm/llvm-project/pull/110182 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)
@@ -2994,6 +2994,29 @@ A "convergencectrl" operand bundle is only valid on a ``convergent`` operation. When present, the operand bundle must contain exactly one value of token type. See the :doc:`ConvergentOperations` document for details. +.. _ob_fpe: + +Floating-point Environment Operand Bundles spavloff wrote: I think we could introduce additional "memory" resources in addition to inaccessible memory to represent FP environment. In this case intrinsisc like `sqrt` would have effect like "reads control modes" and "sets status bits", which would characterize FP intrinsics. In the case of default FP environment these properties should be erased however. Hopefully more fine-grained FP environment access could avoid unneeded ordering and increase performance of non-default execution modes. https://github.com/llvm/llvm-project/pull/109798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
@@ -4561,6 +4569,13 @@ static void TryConstructorInitialization(Sema &S, CXXConstructorDecl *CtorDecl = cast(Best->Function); if (Result != OR_Deleted) { +if (!IsListInit && Kind.getKind() == InitializationKind::IK_Default && +DestRecordDecl != nullptr && DestRecordDecl->isAggregate() && +DestRecordDecl->hasUninitializedExplicitInitFields()) { + S.Diag(Kind.getLocation(), diag::warn_field_requires_explicit_init) + << true << DestRecordDecl; erichkeane wrote: See below! https://github.com/llvm/llvm-project/pull/102040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Use HLSLToolChain for Vulkan (PR #110306)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Steven Perron (s-perron) Changes The options are not translated correctly when targeting Vulkan using the dxc driver mode. Resuing the translator used for HLSL. Fixes problem 2 in https://github.com/llvm/llvm-project/issues/108567. --- Full diff: https://github.com/llvm/llvm-project/pull/110306.diff 3 Files Affected: - (modified) clang/lib/Driver/Driver.cpp (+1) - (modified) clang/test/CodeGenHLSL/entry.hlsl (+4) - (modified) clang/test/Driver/dxc_E.hlsl (+1) ``diff diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index d0c8bdba0ede95..fba6a8853c3960 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -6481,6 +6481,7 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, case llvm::Triple::ZOS: TC = std::make_unique(*this, Target, Args); break; +case llvm::Triple::Vulkan: case llvm::Triple::ShaderModel: TC = std::make_unique(*this, Target, Args); break; diff --git a/clang/test/CodeGenHLSL/entry.hlsl b/clang/test/CodeGenHLSL/entry.hlsl index ec4254e76fb66b..cd3bf948df48c4 100644 --- a/clang/test/CodeGenHLSL/entry.hlsl +++ b/clang/test/CodeGenHLSL/entry.hlsl @@ -2,6 +2,10 @@ // RUN: dxil-pc-shadermodel6.3-compute %s -hlsl-entry foo \ // RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: spirv-unknown-vulkan-compute %s -hlsl-entry foo \ +// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s + // Make sure not mangle entry. // CHECK:define void @foo() // Make sure add function attribute and numthreads attribute. diff --git a/clang/test/Driver/dxc_E.hlsl b/clang/test/Driver/dxc_E.hlsl index 05cfca685c9a65..07715a2e2259af 100644 --- a/clang/test/Driver/dxc_E.hlsl +++ b/clang/test/Driver/dxc_E.hlsl @@ -1,4 +1,5 @@ // RUN: not %clang_dxc -Efoo -Tlib_6_7 foo.hlsl -### %s 2>&1 | FileCheck %s +// RUN: not %clang_dxc -Efoo -Tlib_6_7 -spirv foo.hlsl -### %s 2>&1 | FileCheck %s // Make sure E option flag which translated into "-hlsl-entry". // CHECK:"-hlsl-entry" "foo" `` https://github.com/llvm/llvm-project/pull/110306 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
@@ -1472,3 +1472,56 @@ template struct Outer { }; }; Outer::Inner outerinner; + +void aggregate() { + struct NonAgg { +NonAgg() { } +[[clang::requires_explicit_initialization]] int f; // expected-warning {{attribute is ignored}} + }; + NonAgg nonagg; + (void)nonagg; + + struct S { +[[clang::requires_explicit_initialization]] int x; // expected-note 4{{declared here}} +int y; +int z = 12; +[[clang::requires_explicit_initialization]] int q = 100; // expected-note 4{{declared}} +static void foo(S) { } + }; + + struct D : S { // expected-warning {{field in 'S' is not explicitly initialized, but was marked as requiring explicit initialization}} +int f1; +int f2 [[clang::requires_explicit_initialization]]; // expected-note 2{{declared}} + }; + + struct C { +[[clang::requires_explicit_initialization]] int w; +C() = default; // Test pre-C++20 aggregates + }; + + S::foo(S{1, 2, 3, 4}); + S::foo(S{.x = 100, .q = 100}); + S::foo(S{.x = 100}); // expected-warning {{field 'q' is not explicitly initialized, but was marked as requiring explicit initialization}} + S s{.x = 100, .q = 100}; + (void)s; + S t{.q = 100}; // expected-warning {{field 'x' is not explicitly initialized, but was marked as requiring explicit initialization}} + (void)t; + S *ptr1 = new S; // expected-warning {{field in 'S' is not explicitly initialized, but was marked as requiring explicit initialization}} + delete ptr1; + S *ptr2 = new S{.x = 100, .q = 100}; + delete ptr2; +#if __cplusplus >= 202002L + D a({}, 0); // expected-warning {{field 'x' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-warning {{field 'f2' is not explicitly initialized, but was marked as requiring explicit initialization}} + (void)a; +#else + C a; // expected-warning {{field in 'C' is not explicitly initialized, but was marked as requiring explicit initialization}} erichkeane wrote: Why do we have the 'in' on the diagnostic here? It seems we should know the field, right? Or did I forget something from earlier? https://github.com/llvm/llvm-project/pull/102040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][test] add testing for the AST matcher reference (PR #94248)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-win-fast` running on `as-builder-3` while building `clang` at step 8 "test-build-unified-tree-check-clang-unit". Full details are available at: https://lab.llvm.org/buildbot/#/builders/2/builds/7739 Here is the relevant piece of the build log for the reference ``` Step 8 (test-build-unified-tree-check-clang-unit) failure: test (failure) ... [37/314] Building CXX object tools\clang\unittests\Lex\CMakeFiles\LexTests.dir\PPDependencyDirectivesTest.cpp.obj [38/314] Building CXX object tools\clang\unittests\AST\CMakeFiles\ASTTests.dir\CommentLexer.cpp.obj [39/314] Building CXX object tools\clang\unittests\AST\CMakeFiles\ASTTests.dir\CommentTextTest.cpp.obj [40/314] Building CXX object tools\clang\unittests\AST\CMakeFiles\ASTTests.dir\ASTVectorTest.cpp.obj [41/314] Building CXX object tools\clang\unittests\AST\CMakeFiles\ASTTests.dir\CommentParser.cpp.obj [42/314] Building CXX object tools\clang\lib\Testing\CMakeFiles\clangTesting.dir\TestAST.cpp.obj [43/314] Linking CXX static library lib\clangTesting.lib [44/314] Building CXX object tools\clang\unittests\Driver\CMakeFiles\ClangDriverTests.dir\ToolChainTest.cpp.obj [45/314] Building CXX object tools\clang\unittests\Driver\CMakeFiles\ClangDriverTests.dir\DXCModeTest.cpp.obj [46/314] Generating ASTMatchersDocTests.cpp FAILED: tools/clang/unittests/ASTMatchers/ASTMatchersDocTests.cpp C:/buildbot/as-builder-3/llvm-clang-x86_64-win-fast/build/tools/clang/unittests/ASTMatchers/ASTMatchersDocTests.cpp cmd.exe /C "cd /D C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\tools\clang\unittests\ASTMatchers && C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\clang\utils\generate_ast_matcher_doc_tests.py --input-file C:/buildbot/as-builder-3/llvm-clang-x86_64-win-fast/llvm-project/clang/include/clang/ASTMatchers/ASTMatchers.h --output-file C:/buildbot/as-builder-3/llvm-clang-x86_64-win-fast/build/tools/clang/unittests/ASTMatchers/ASTMatchersDocTests.cpp" Traceback (most recent call last): File "C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\clang\utils\generate_ast_matcher_doc_tests.py", line 94, in statistics = defaultdict[str, int](int) TypeError: 'type' object is not subscriptable [47/314] Linking CXX executable tools\clang\unittests\Basic\BasicTests.exe [48/314] Building CXX object tools\clang\unittests\Analysis\CMakeFiles\ClangAnalysisTests.dir\CloneDetectionTest.cpp.obj [49/314] Building CXX object tools\clang\unittests\StaticAnalyzer\CMakeFiles\StaticAnalysisTests.dir\APSIntTypeTest.cpp.obj [50/314] Building CXX object tools\clang\unittests\Lex\CMakeFiles\LexTests.dir\PPCallbacksTest.cpp.obj [51/314] Building CXX object tools\clang\unittests\StaticAnalyzer\CMakeFiles\StaticAnalysisTests.dir\RangeSetTest.cpp.obj [52/314] Building CXX object tools\clang\unittests\Analysis\CMakeFiles\ClangAnalysisTests.dir\MacroExpansionContextTest.cpp.obj [53/314] Building CXX object tools\clang\unittests\StaticAnalyzer\CMakeFiles\StaticAnalysisTests.dir\ExprEngineVisitTest.cpp.obj [54/314] Building CXX object tools\clang\unittests\StaticAnalyzer\CMakeFiles\StaticAnalysisTests.dir\NoStateChangeFuncVisitorTest.cpp.obj [55/314] Building CXX object tools\clang\unittests\StaticAnalyzer\CMakeFiles\StaticAnalysisTests.dir\CallEventTest.cpp.obj [56/314] Building CXX object tools\clang\unittests\StaticAnalyzer\CMakeFiles\StaticAnalysisTests.dir\ConflictingEvalCallsTest.cpp.obj [57/314] Building CXX object tools\clang\unittests\StaticAnalyzer\CMakeFiles\StaticAnalysisTests.dir\TestReturnValueUnderConstruction.cpp.obj [58/314] Building CXX object tools\clang\unittests\StaticAnalyzer\CMakeFiles\StaticAnalysisTests.dir\MemRegionDescriptiveNameTest.cpp.obj [59/314] Building CXX object tools\clang\unittests\StaticAnalyzer\CMakeFiles\StaticAnalysisTests.dir\RegisterCustomCheckersTest.cpp.obj [60/314] Building CXX object tools\clang\unittests\StaticAnalyzer\CMakeFiles\StaticAnalysisTests.dir\SValTest.cpp.obj [61/314] Building CXX object tools\clang\unittests\AST\CMakeFiles\ASTTests.dir\EvaluateAsRValueTest.cpp.obj [62/314] Linking CXX executable tools\clang\unittests\Driver\ClangDriverTests.exe [63/314] Building CXX object tools\clang\unittests\AST\CMakeFiles\ASTTests.dir\ASTImporterFixtures.cpp.obj [64/314] Building CXX object tools\clang\unittests\ASTMatchers\Dynamic\CMakeFiles\DynamicASTMatchersTests.dir\RegistryTest.cpp.obj [65/314] Building CXX object tools\clang\unittests\ASTMatchers\Dynamic\CMakeFiles\DynamicASTMatchersTests.dir\ParserTest.cpp.obj [66/314] Building CXX object tools\clang\unittests\Analysis\FlowSensitive\CMakeFiles\ClangAnalysisFlowSensitiveTests.dir\MapLatticeTest.cpp.obj [67/314] Building CXX object tools\clang\unittests\Analysis\FlowSensitive\CMakeFiles\ClangAnalysisFlowSensitiveTests.dir\ChromiumCheckModelTest.cpp.obj [68/314] Building CXX object tools\clang\unittests\AST\CMakeFiles\ASTTests.di
[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
@@ -6457,6 +6472,18 @@ void InitializationSequence::InitializeFrom(Sema &S, } } + if (!S.getLangOpts().CPlusPlus && + Kind.getKind() == InitializationKind::IK_Default) { +RecordDecl *Rec = DestType->getAsRecordDecl(); +if (Rec && Rec->hasUninitializedExplicitInitFields()) { + VarDecl *Var = dyn_cast_or_null(Entity.getDecl()); + if (Var && !Initializer) { +S.Diag(Var->getLocation(), diag::warn_field_requires_explicit_init) +<< true << Rec; higher-performance wrote: Ah, I see. Done. https://github.com/llvm/llvm-project/pull/102040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Adding splitdouble HLSL function (PR #109331)
@@ -0,0 +1,63 @@ +; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s + +; ModuleID = '../clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl' +source_filename = "../clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl" +target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64" +target triple = "dxilv1.3-pc-shadermodel6.3-library" + +; Function Attrs: alwaysinline mustprogress nofree norecurse nosync nounwind willreturn memory(none) +define noundef float @"?test_scalar@@YAMN@Z"(double noundef %D) local_unnamed_addr #0 { farzonl wrote: get rid of the mangled names and give this test symbol names like so: ```suggestion define noundef float @test_scalar_double_split(double noundef %D) local_unnamed_addr { ``` Also drop the `#0` https://github.com/llvm/llvm-project/pull/109331 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Adding splitdouble HLSL function (PR #109331)
@@ -0,0 +1,63 @@ +; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s + +; ModuleID = '../clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl' +source_filename = "../clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl" +target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64" +target triple = "dxilv1.3-pc-shadermodel6.3-library" + +; Function Attrs: alwaysinline mustprogress nofree norecurse nosync nounwind willreturn memory(none) +define noundef float @"?test_scalar@@YAMN@Z"(double noundef %D) local_unnamed_addr #0 { farzonl wrote: Add a `CHECK-LABEL` before each test case. https://github.com/llvm/llvm-project/pull/109331 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan] Update docs to include run-time flags (PR #110296)
https://github.com/cjappl created https://github.com/llvm/llvm-project/pull/110296 None >From 128f414de9f19596e81db6afe5e1d0b166888775 Mon Sep 17 00:00:00 2001 From: Chris Apple Date: Fri, 27 Sep 2024 09:40:11 -0700 Subject: [PATCH] [rtsan] Update docs to include run-time flags --- clang/docs/RealtimeSanitizer.rst | 69 1 file changed, 69 insertions(+) diff --git a/clang/docs/RealtimeSanitizer.rst b/clang/docs/RealtimeSanitizer.rst index 5e281a2a357907..bddf39ecaf1c5a 100644 --- a/clang/docs/RealtimeSanitizer.rst +++ b/clang/docs/RealtimeSanitizer.rst @@ -84,6 +84,75 @@ non-zero exit code. #14 0x0001958960dc () #15 0x2f557ffc () +Run-time flags +-- + +RealtimeSanitizer supports a number of run-time flags, which can be specified in the ``RTSAN_OPTIONS`` environment variable: + +.. code-block:: console + + % RTSAN_OPTIONS=option_1=true:path_option_2="/some/file.txt" ./a.out + ... + +Or at compiler time by overloading the symbol ``__rtsan_default_options``: + +.. code-block:: c + + extern "C" const char *__rtsan_default_options() { +return "symbolize=false:abort_on_error=0:log_to_syslog=0"; + } + +You can see all sanitizer options (some of which are unsupported) by using the ``help`` flag: + +.. code-block:: console + + % RTSAN_OPTIONS=help=true ./a.out + +A **partial** list of flags RealtimeSanitizer respects: + +.. list-table:: Run-time Flags + :widths: 20 10 10 70 + :header-rows: 1 + + * - Flag name + - Default value + - Type + - Short description + * - ``halt_on_error`` + - ``true`` + - boolean + - Exit after first reported error. If false (continue after a detected error), deduplicates error stacks so errors appear only once. + * - ``print_stats_on_exit`` + - ``false`` + - boolean + - Print stats on exit. Includes total and unique errors. + * - ``color`` + - ``"auto"`` + - string + - Colorize reports: (always|never|auto). + * - ``fast_unwind_on_fatal`` + - ``false`` + - boolean + - If available, use the fast frame-pointer-based unwinder on detected errors. If true, ensure the code under test has been compiled with frame pointers with ``-fno-omit-frame-pointers`` or similar. + * - ``abort_on_error`` + - OS dependent + - boolean + - If true, the tool calls abort() instead of _exit() after printing the error report. On some OSes (OSX, for exmple) this is beneficial because a better stack trace is emitted on crash. + * - ``symbolize`` + - ``true`` + - boolean + - If set, use the symbolizer to turn virtual addresses to file/line locations. If false, can greatly speed up the error reporting. + + +Some issues with flags can be debugged using the ``verbosity=$NUM`` flag: + +.. code-block:: console + + % RTSAN_OPTIONS=verbosity=1:misspelled_flag=true ./a.out + WARNING: found 1 unrecognized flag(s): + misspelled_flag + ... + Disabling - ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)
jhuber6 wrote: > Probably want a longer prefix. _gpu or_llvm or similar. Yeah, just wasn't sure. Also, do resource headers need to be in a reserved namespace? Probably nothing wrong with `gpu_get_thread_id` vs `_gpu_get_thread_id`. > If the shared header gets the declarations then people can include the > intrin.h and look at it to see what functions they have available, without > going and looking through all the implementations. That seems like a good > thing. Can put descriptive comments in the main header then. Yeah I was actually wondering if I should go for something like this: ```c #ifdef __NVPTX__ uint32_t nvptx_get_thread_id_x() { return __nvvm_ptx_read_sreg_tid_x(); } #define IMPL nvptx #endif uint32_t gpu_get_thread_id_x() { return ##IMPL##_get_thread_id_x(); } #undef IMPL ``` https://github.com/llvm/llvm-project/pull/110179 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
@@ -3141,6 +3148,10 @@ def warn_attribute_ignored_no_calls_in_stmt: Warning< "statement">, InGroup; +def warn_attribute_needs_aggregate : Warning< higher-performance wrote: > we have precedent for it What example(s) are you thinking of? https://github.com/llvm/llvm-project/pull/102040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [DebugInfo] Correct the line attribution for IF branches (PR #108300)
pogo59 wrote: Filed #110313 as the followup for looking at the `for` statement. https://github.com/llvm/llvm-project/pull/108300 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [FMV][AArch64] Unify features ssbs and ssbs2. (PR #110297)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Alexandros Lamprineas (labrinea) Changes According to https://developer.arm.com/documentation/102105/latest Arm Architecture Reference Manual for A-profile architecture: Known issues 2.206 D22789 In section C5.2.25 "SSBS, Speculative Store Bypass Safe", under the heading 'Configurations', the text that reads: "This register is present only when FEAT_SSBS is implemented. Otherwise, direct accesses to SSBS are UNDEFINED." is changed to read: "This register is present only when FEAT_SSBS2 is implemented. Otherwise, direct accesses to SSBS are UNDEFINED." This suggests that it's not worth splitting FEAT_SSBS2 from FEAT_SSBS in the compiler, since FEAT_SSBS cannot be used for predicating the MRS/MSR instructions. Those can access PSTATE.SSBS only when FEAT_SSBS2 is available. Moreover, there are no hardware implementations which implement FEAT_SSBS without FEAT_SSBS2, therefore unifying these features in the specification should not be a regression for feature detection. Approved in ACLE as https://github.com/ARM-software/acle/pull/350 --- Patch is 27.69 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/110297.diff 10 Files Affected: - (modified) clang/test/CodeGen/aarch64-fmv-dependencies.c (+2-5) - (modified) clang/test/CodeGen/attr-target-version.c (+52-51) - (modified) clang/test/CodeGenCXX/attr-target-clones-aarch64.cpp (+5-5) - (modified) clang/test/Sema/attr-target-clones-aarch64.c (+1-4) - (modified) clang/test/SemaCXX/attr-target-version.cpp (+2-2) - (modified) compiler-rt/lib/builtins/cpu_model/AArch64CPUFeatures.inc (+1-1) - (modified) compiler-rt/lib/builtins/cpu_model/aarch64/fmv/apple.inc (-4) - (modified) compiler-rt/lib/builtins/cpu_model/aarch64/fmv/mrs.inc (+1-3) - (modified) llvm/include/llvm/TargetParser/AArch64CPUFeatures.inc (+1-1) - (modified) llvm/lib/Target/AArch64/AArch64FMV.td (+1-2) ``diff diff --git a/clang/test/CodeGen/aarch64-fmv-dependencies.c b/clang/test/CodeGen/aarch64-fmv-dependencies.c index 681f7e82634fa8..f4229a5d233970 100644 --- a/clang/test/CodeGen/aarch64-fmv-dependencies.c +++ b/clang/test/CodeGen/aarch64-fmv-dependencies.c @@ -135,12 +135,9 @@ __attribute__((target_version("sme-i16i64"))) int fmv(void) { return 0; } // CHECK: define dso_local i32 @fmv._Msme2() #[[sme2:[0-9]+]] { __attribute__((target_version("sme2"))) int fmv(void) { return 0; } -// CHECK: define dso_local i32 @fmv._Mssbs() #[[ATTR0:[0-9]+]] { +// CHECK: define dso_local i32 @fmv._Mssbs() #[[ssbs:[0-9]+]] { __attribute__((target_version("ssbs"))) int fmv(void) { return 0; } -// CHECK: define dso_local i32 @fmv._Mssbs2() #[[ssbs2:[0-9]+]] { -__attribute__((target_version("ssbs2"))) int fmv(void) { return 0; } - // CHECK: define dso_local i32 @fmv._Msve() #[[sve:[0-9]+]] { __attribute__((target_version("sve"))) int fmv(void) { return 0; } @@ -219,7 +216,7 @@ int caller() { // CHECK: attributes #[[sme_f64f64]] = { {{.*}} "target-features"="+bf16,+fp-armv8,+neon,+outline-atomics,+sme,+sme-f64f64,+v8a" // CHECK: attributes #[[sme_i16i64]] = { {{.*}} "target-features"="+bf16,+fp-armv8,+neon,+outline-atomics,+sme,+sme-i16i64,+v8a" // CHECK: attributes #[[sme2]] = { {{.*}} "target-features"="+bf16,+fp-armv8,+neon,+outline-atomics,+sme,+sme2,+v8a" -// CHECK: attributes #[[ssbs2]] = { {{.*}} "target-features"="+fp-armv8,+neon,+outline-atomics,+ssbs,+v8a" +// CHECK: attributes #[[ssbs]] = { {{.*}} "target-features"="+fp-armv8,+neon,+outline-atomics,+ssbs,+v8a" // CHECK: attributes #[[sve]] = { {{.*}} "target-features"="+fp-armv8,+fullfp16,+neon,+outline-atomics,+sve,+v8a" // CHECK: attributes #[[sve_bf16_ebf16]] = { {{.*}} "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sve,+v8a" // CHECK: attributes #[[sve_i8mm]] = { {{.*}} "target-features"="+fp-armv8,+fullfp16,+i8mm,+neon,+outline-atomics,+sve,+v8a" diff --git a/clang/test/CodeGen/attr-target-version.c b/clang/test/CodeGen/attr-target-version.c index 228435a0494c3e..e74e8c254b3952 100644 --- a/clang/test/CodeGen/attr-target-version.c +++ b/clang/test/CodeGen/attr-target-version.c @@ -296,7 +296,7 @@ int caller(void) { return used_def_without_default_decl() + used_decl_without_de // // CHECK: Function Attrs: noinline nounwind optnone // CHECK-LABEL: define {{[^@]+}}@fmv_c._Mssbs -// CHECK-SAME: () #[[ATTR9]] { +// CHECK-SAME: () #[[ATTR13:[0-9]+]] { // CHECK-NEXT: entry: // CHECK-NEXT:ret void // @@ -354,14 +354,14 @@ int caller(void) { return used_def_without_default_decl() + used_decl_without_de // // CHECK: Function Attrs: noinline nounwind optnone // CHECK-LABEL: define {{[^@]+}}@unused_with_forward_default_decl._Mmops -// CHECK-SAME: () #[[ATTR14:[0-9]+]] { +// CHECK-SAME: () #[[ATTR15:[0-9]+]] { // CHECK-NEXT: entry: // CHECK-NEXT:ret i32 0 // // // CHECK: Function Attrs: noinline nounwind optnone // CHECK-LABEL: define {{[^@]+}}@unused_wi
[clang] [Clang] Update Interpreter tests to use clang_target_link_libraries (PR #110154)
https://github.com/fsfod updated https://github.com/llvm/llvm-project/pull/110154 >From 064bc85cea9bab0295c92aac3c73df8054b0a036 Mon Sep 17 00:00:00 2001 From: Thomas Fransham Date: Thu, 26 Sep 2024 18:59:33 +0100 Subject: [PATCH] [Clang] Update Interpreter tests to use clang_target_link_libraries This will fix duplicate and missing linker symbol errors when using CLANG_LINK_CLANG_DYLIB on windows and explicit visibility macros are used. This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and plugins on window. --- clang/unittests/Interpreter/CMakeLists.txt | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/unittests/Interpreter/CMakeLists.txt b/clang/unittests/Interpreter/CMakeLists.txt index ec6f81ea19b960..1ed1216c772e8f 100644 --- a/clang/unittests/Interpreter/CMakeLists.txt +++ b/clang/unittests/Interpreter/CMakeLists.txt @@ -16,13 +16,15 @@ add_clang_unittest(ClangReplInterpreterTests EXPORT_SYMBOLS ) -target_link_libraries(ClangReplInterpreterTests PUBLIC + +target_link_libraries(ClangReplInterpreterTests PUBLIC LLVMTestingSupport) + +clang_target_link_libraries(ClangReplInterpreterTests PRIVATE clangAST clangBasic clangInterpreter clangFrontend clangSema - LLVMTestingSupport ) # Exceptions on Windows are not yet supported. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NVPTX] Add a clang builtin for the `warpsize` intrinsic (PR #110316)
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/110316 Summary: There's an intrinsic for the warp size, we want to expose this to make the interface proposed in https://github.com/llvm/llvm-project/pull/110179 more generic. >From 63d45843ee15c940680e4d6a3ea87138ebfc5b69 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Fri, 27 Sep 2024 14:08:51 -0500 Subject: [PATCH] [NVPTX] Add a clang builtin for the `warpsize` intrinsic Summary: There's an intrinsic for the warp size, we want to expose this to make the interface proposed in https://github.com/llvm/llvm-project/pull/110179 more generic. --- clang/include/clang/Basic/BuiltinsNVPTX.def | 1 + clang/test/CodeGen/builtins-nvptx.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/BuiltinsNVPTX.def b/clang/include/clang/Basic/BuiltinsNVPTX.def index 6fff562165080a..6b7bce5bc00d4f 100644 --- a/clang/include/clang/Basic/BuiltinsNVPTX.def +++ b/clang/include/clang/Basic/BuiltinsNVPTX.def @@ -139,6 +139,7 @@ TARGET_BUILTIN(__nvvm_is_explicit_cluster, "b", "nc", AND(SM_90, PTX78)) BUILTIN(__nvvm_read_ptx_sreg_laneid, "i", "nc") BUILTIN(__nvvm_read_ptx_sreg_warpid, "i", "nc") BUILTIN(__nvvm_read_ptx_sreg_nwarpid, "i", "nc") +BUILTIN(__nvvm_read_ptx_sreg_warpsize, "i", "nc") BUILTIN(__nvvm_read_ptx_sreg_smid, "i", "nc") BUILTIN(__nvvm_read_ptx_sreg_nsmid, "i", "nc") diff --git a/clang/test/CodeGen/builtins-nvptx.c b/clang/test/CodeGen/builtins-nvptx.c index bfa72e8bd69454..0d0e3ecdb90c9e 100644 --- a/clang/test/CodeGen/builtins-nvptx.c +++ b/clang/test/CodeGen/builtins-nvptx.c @@ -114,6 +114,7 @@ __device__ int read_ids() { // CHECK: call i32 @llvm.nvvm.read.ptx.sreg.smid() // CHECK: call i32 @llvm.nvvm.read.ptx.sreg.nsmid() // CHECK: call i32 @llvm.nvvm.read.ptx.sreg.gridid() +// CHECK: call i32 @llvm.nvvm.read.ptx.sreg.warpsize() int a = __nvvm_read_ptx_sreg_laneid(); int b = __nvvm_read_ptx_sreg_warpid(); @@ -121,8 +122,9 @@ __device__ int read_ids() { int d = __nvvm_read_ptx_sreg_smid(); int e = __nvvm_read_ptx_sreg_nsmid(); int f = __nvvm_read_ptx_sreg_gridid(); + int g = __nvvm_read_ptx_sreg_warpsize(); - return a + b + c + d + e + f; + return a + b + c + d + e + f + g; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
zygoloid wrote: I found this: https://fuchsia.googlesource.com/third_party/github.com/fmtlib/fmt/+/refs/heads/upstream/main/include/fmt/base.h#2664 Note that this is passing `s` separately both to `parse_format_string` and to `checker`. Here, `s` is a lambda that implicitly converts to a string view by evaluating a string literal. Those two evaluations can return different string literal objects, and I'm assuming pointers to those strings are what we end up subtracting. So yes, this fmtlib code is wrong -- it's incorrectly assuming that a string literal will always evaluate to the same value, which is not true at runtime or (after this Clang change) at compile time. The correct thing to do would be what is done a few lines below in the next constructor: convert the `S` object to a string view once, and then use that same value for both calls. https://github.com/llvm/llvm-project/pull/109208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstrPGO] Instrument sampling profile based cold function (PR #110330)
https://github.com/wlei-llvm created https://github.com/llvm/llvm-project/pull/110330 None >From d660d3b9a043a3530a735c1b95790116f6366062 Mon Sep 17 00:00:00 2001 From: wlei Date: Sun, 22 Sep 2024 20:23:20 -0700 Subject: [PATCH 1/2] [InstrPGO] Instrument sampling profile based cold function --- clang/include/clang/Driver/Options.td | 6 + clang/lib/Driver/ToolChain.cpp| 4 +++- clang/lib/Driver/ToolChains/Clang.cpp | 13 ++ llvm/lib/Passes/PassBuilderPipelines.cpp | 17 + .../Instrumentation/PGOInstrumentation.cpp| 14 +++ .../PGOProfile/instr-gen-cold-function.ll | 24 +++ 6 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Transforms/PGOProfile/instr-gen-cold-function.ll diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index aedc4c16d4e9d5..230b9604b8a8aa 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1785,6 +1785,12 @@ defm debug_info_for_profiling : BoolFOption<"debug-info-for-profiling", PosFlag, NegFlag>; +def fprofile_sample_cold_function : Flag<["-"], "fprofile-sample-cold-function">, +Group, Visibility<[ClangOption, CLOption]>, +HelpText<"Generate instrumented code to cold functions guided by sampling-based profile into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">; +def fprofile_sample_cold_function_EQ : Joined<["-"], "fprofile-sample-cold-function=">, +Group, Visibility<[ClangOption, CLOption]>, MetaVarName<"">, +HelpText<"Generate instrumented code to cold functions guided by sampling-based profile into (overridden by LLVM_PROFILE_FILE env var)">; def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">, Group, Visibility<[ClangOption, CLOption]>, HelpText<"Generate instrumented code to collect execution counts into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">; diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 16f9b629fc538c..5cd821cfe780c4 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -889,7 +889,9 @@ bool ToolChain::needsProfileRT(const ArgList &Args) { Args.hasArg(options::OPT_fprofile_instr_generate) || Args.hasArg(options::OPT_fprofile_instr_generate_EQ) || Args.hasArg(options::OPT_fcreate_profile) || - Args.hasArg(options::OPT_forder_file_instrumentation); + Args.hasArg(options::OPT_forder_file_instrumentation) || + Args.hasArg(options::OPT_fprofile_sample_cold_function) || + Args.hasArg(options::OPT_fprofile_sample_cold_function_EQ); } bool ToolChain::needsGCovInstrumentation(const llvm::opt::ArgList &Args) { diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index b9987288d82d10..fced94833aaf79 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -649,6 +649,19 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C, } } + if (auto *SampleColdArg = + Args.getLastArg(options::OPT_fprofile_sample_cold_function, + options::OPT_fprofile_sample_cold_function_EQ)) { +SmallString<128> Path(SampleColdArg->getOption().matches( + options::OPT_fprofile_sample_cold_function_EQ) + ? SampleColdArg->getValue() + : ""); +llvm::sys::path::append(Path, "default_%m.profraw"); +CmdArgs.push_back("-mllvm"); +CmdArgs.push_back(Args.MakeArgString( +Twine("--instrument-sample-cold-function-path=") + Path)); + } + Arg *PGOGenArg = nullptr; if (PGOGenerateArg) { assert(!CSPGOGenerateArg); diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index 8f151a99b11709..0514d17db20721 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -296,7 +296,13 @@ static cl::opt UseLoopVersioningLICM( "enable-loop-versioning-licm", cl::init(false), cl::Hidden, cl::desc("Enable the experimental Loop Versioning LICM pass")); +static cl::opt InstrumentSampleColdFuncPath( +"instrument-sample-cold-function-path", cl::init(""), +cl::desc("File path for instrumenting sampling PGO guided cold functions"), +cl::Hidden); + extern cl::opt UseCtxProfile; +extern cl::opt InstrumentColdFunction; namespace llvm { extern cl::opt EnableMemProfContextDisambiguation; @@ -1119,6 +1125,17 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, // removed. MPM.addPass( PGOIndirectCallPromotion(true /* IsInLTO */, true /* SamplePGO */)); + +if (InstrumentSampleColdFuncPath.getNumOccurrences() && +Phase != ThinOrF
[clang] [llvm] [InstrPGO] Instrument sampling profile based cold function v2 (PR #110330)
https://github.com/wlei-llvm edited https://github.com/llvm/llvm-project/pull/110330 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [InstrPGO] Instrument sampling profile based cold function (PR #109837)
https://github.com/wlei-llvm edited https://github.com/llvm/llvm-project/pull/109837 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)
@@ -944,12 +950,72 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate) { return {Template, AliasRhsTemplateArgs}; } +struct InheritedConstructorDeductionInfo { + // Class template for which we are declaring deduction guides + // This is `C` in the standard wording + TemplateDecl *DerivedClassTemplate; + + // `template CC` in the standard wording + // This is the type of template that is substituted in the deduction guide + // return type `CC` + TypeSourceInfo *CCType; +}; + +// Build the type for a deduction guide generated from an inherited constructor +// [over.match.class.deduct]p1.10: +// ... the set contains the guides of A with the return type R +// of each guide replaced with `typename CC::type` ... +TypeSourceInfo *buildInheritedConstructorDeductionGuideType( +Sema &SemaRef, const InheritedConstructorDeductionInfo &Info, +TypeSourceInfo *SourceGuideTSI) { + auto &Context = SemaRef.Context; + const auto *FPT = SourceGuideTSI->getType()->getAs(); + assert(FPT && "Source Guide type should be a FunctionProtoType"); + + // This substitution can fail in cases where the source return type + // is not dependent and the derived class is not deducible + Sema::SFINAETrap Trap(SemaRef); + + MultiLevelTemplateArgumentList Args; + Args.addOuterTemplateArguments(Info.DerivedClassTemplate, + TemplateArgument(FPT->getReturnType()), false); mizvekov wrote: Please add a comment for the boolean argument. https://github.com/llvm/llvm-project/pull/98788 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
zygoloid wrote: I've filed a fmtlib bug: https://github.com/fmtlib/fmt/issues/4177 https://github.com/llvm/llvm-project/pull/109208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Portability Template Virtual Member Function Check (PR #110099)
https://github.com/isuckatcs updated https://github.com/llvm/llvm-project/pull/110099 >From 9cdba3e947705053b14f8eeca39c281fd18e21ce Mon Sep 17 00:00:00 2001 From: isuckatcs <65320245+isucka...@users.noreply.github.com> Date: Thu, 26 Sep 2024 11:43:10 +0200 Subject: [PATCH 1/7] [clang-tidy] Portability Template Virtual Member Function Check --- .../clang-tidy/portability/CMakeLists.txt | 1 + .../portability/PortabilityTidyModule.cpp | 3 + .../TemplateVirtualMemberFunctionCheck.cpp| 49 +++ .../TemplateVirtualMemberFunctionCheck.h | 36 + clang-tools-extra/docs/ReleaseNotes.rst | 7 + .../docs/clang-tidy/checks/list.rst | 1 + .../template-virtual-member-function.rst | 33 + .../template-virtual-member-function.cpp | 134 ++ 8 files changed, 264 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/portability/template-virtual-member-function.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/portability/template-virtual-member-function.cpp diff --git a/clang-tools-extra/clang-tidy/portability/CMakeLists.txt b/clang-tools-extra/clang-tidy/portability/CMakeLists.txt index 01a86d686daa76..df08cf2c8e292c 100644 --- a/clang-tools-extra/clang-tidy/portability/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/portability/CMakeLists.txt @@ -9,6 +9,7 @@ add_clang_library(clangTidyPortabilityModule RestrictSystemIncludesCheck.cpp SIMDIntrinsicsCheck.cpp StdAllocatorConstCheck.cpp + TemplateVirtualMemberFunctionCheck.cpp LINK_LIBS clangTidy diff --git a/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp b/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp index b3759a754587d7..316b98b46cf3f2 100644 --- a/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp @@ -12,6 +12,7 @@ #include "RestrictSystemIncludesCheck.h" #include "SIMDIntrinsicsCheck.h" #include "StdAllocatorConstCheck.h" +#include "TemplateVirtualMemberFunctionCheck.h" namespace clang::tidy { namespace portability { @@ -25,6 +26,8 @@ class PortabilityModule : public ClangTidyModule { "portability-simd-intrinsics"); CheckFactories.registerCheck( "portability-std-allocator-const"); +CheckFactories.registerCheck( +"portability-template-virtual-member-function"); } }; diff --git a/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp new file mode 100644 index 00..6b7b50798798fa --- /dev/null +++ b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp @@ -0,0 +1,49 @@ +//===--- TemplateVirtualMemberFunctionCheck.cpp - clang-tidy +//---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "TemplateVirtualMemberFunctionCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::portability { + +void TemplateVirtualMemberFunctionCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(classTemplateSpecializationDecl().bind("specialization"), + this); +} + +void TemplateVirtualMemberFunctionCheck::check( +const MatchFinder::MatchResult &Result) { + const auto *MatchedDecl = + Result.Nodes.getNodeAs("specialization"); + + if (MatchedDecl->isExplicitSpecialization()) +return; + + for (auto &&Method : MatchedDecl->methods()) { +if (!Method->isVirtual()) + continue; + +if (const auto *Dtor = llvm::dyn_cast(Method); +Dtor && Dtor->isDefaulted()) + continue; + +if (!Method->isUsed()) { + diag(Method->getLocation(), + "unspecified virtual member function instantiation; the virtual " + "member function is not instantiated but it might be with a " + "different compiler"); + diag(MatchedDecl->getPointOfInstantiation(), "template instantiated here", + DiagnosticIDs::Note); +} + } +} + +} // namespace clang::tidy::portability diff --git a/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.h b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.h new file mode 100644 index 00..9d7918dbdba612 --- /dev/null +++ b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.h @@ -0,0
[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
@@ -4561,6 +4569,13 @@ static void TryConstructorInitialization(Sema &S, CXXConstructorDecl *CtorDecl = cast(Best->Function); if (Result != OR_Deleted) { +if (!IsListInit && Kind.getKind() == InitializationKind::IK_Default && erichkeane wrote: Ok, perhaps I'm missing something here... how do we know that a field marked with the attribute wasn't initialized here? Also, we have `DestRecordDecl`, so we have access to the `FieldDecl`s associated with it, right? https://github.com/llvm/llvm-project/pull/102040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
@@ -2837,6 +2837,10 @@ bool QualType::hasNonTrivialToPrimitiveCopyCUnion(const RecordDecl *RD) { return RD->hasNonTrivialToPrimitiveCopyCUnion(); } +bool QualType::hasUninitializedExplicitInitFields(const RecordDecl *RD) { erichkeane wrote: This is a bit of a weird one, why is this in `QualTYpe` but takes the thing anyway? Should the implementation here be `getAsRecordDecl()->hasUnin...` ? https://github.com/llvm/llvm-project/pull/102040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [OpenMP][Clang] Migrate OpenMP UserDefinedMapper from Clang to OMPIRBuilder (PR #110001)
jplehr wrote: Thank you. Will take a closer look next week. So far, I ran this through one of our buildbot configs and did not see an issue there. https://github.com/llvm/llvm-project/pull/110001 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)
@@ -0,0 +1,184 @@ +//===-- nvptxintrin.h - NVPTX intrinsic functions -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef __NVPTXINTRIN_H +#define __NVPTXINTRIN_H + +#ifndef __NVPTX__ +#error "This file is intended for NVPTX targets or offloading to NVPTX +#endif + +#include +#include + +#if defined(__HIP__) || defined(__CUDA__) +#define _DEFAULT_ATTRS __attribute__((device)) __attribute__((always_inline)) +#else +#define _DEFAULT_ATTRS __attribute__((always_inline)) +#endif + +#pragma omp begin declare target device_type(nohost) +#pragma omp begin declare variant match(device = {arch(nvptx64)}) + +// Type aliases to the address spaces used by the NVPTX backend. +#define _private __attribute__((opencl_private)) +#define _constant __attribute__((opencl_constant)) +#define _local __attribute__((opencl_local)) +#define _global __attribute__((opencl_global)) + +// Attribute to declare a function as a kernel. +#define _kernel __attribute__((nvptx_kernel)) + +// Returns the number of CUDA blocks in the 'x' dimension. +_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_x() { + return __nvvm_read_ptx_sreg_nctaid_x(); +} + +// Returns the number of CUDA blocks in the 'y' dimension. +_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_y() { + return __nvvm_read_ptx_sreg_nctaid_y(); +} + +// Returns the number of CUDA blocks in the 'z' dimension. +_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_z() { + return __nvvm_read_ptx_sreg_nctaid_z(); +} + +// Returns the total number of CUDA blocks. +_DEFAULT_ATTRS static inline uint64_t _get_num_blocks() { + return _get_num_blocks_x() * _get_num_blocks_y() * _get_num_blocks_z(); +} + +// Returns the 'x' dimension of the current CUDA block's id. +_DEFAULT_ATTRS static inline uint32_t _get_block_id_x() { + return __nvvm_read_ptx_sreg_ctaid_x(); +} + +// Returns the 'y' dimension of the current CUDA block's id. +_DEFAULT_ATTRS static inline uint32_t _get_block_id_y() { + return __nvvm_read_ptx_sreg_ctaid_y(); +} + +// Returns the 'z' dimension of the current CUDA block's id. +_DEFAULT_ATTRS static inline uint32_t _get_block_id_z() { + return __nvvm_read_ptx_sreg_ctaid_z(); +} + +// Returns the absolute id of the CUDA block. +_DEFAULT_ATTRS static inline uint64_t _get_block_id() { + return _get_block_id_x() + _get_num_blocks_x() * _get_block_id_y() + + _get_num_blocks_x() * _get_num_blocks_y() * _get_block_id_z(); +} + +// Returns the number of CUDA threads in the 'x' dimension. +_DEFAULT_ATTRS static inline uint32_t _get_num_threads_x() { + return __nvvm_read_ptx_sreg_ntid_x(); +} + +// Returns the number of CUDA threads in the 'y' dimension. +_DEFAULT_ATTRS static inline uint32_t _get_num_threads_y() { + return __nvvm_read_ptx_sreg_ntid_y(); +} + +// Returns the number of CUDA threads in the 'z' dimension. +_DEFAULT_ATTRS static inline uint32_t _get_num_threads_z() { + return __nvvm_read_ptx_sreg_ntid_z(); +} + +// Returns the total number of threads in the block. +_DEFAULT_ATTRS static inline uint64_t _get_num_threads() { + return _get_num_threads_x() * _get_num_threads_y() * _get_num_threads_z(); +} + +// Returns the 'x' dimension id of the thread in the current CUDA block. +_DEFAULT_ATTRS static inline uint32_t _get_thread_id_x() { + return __nvvm_read_ptx_sreg_tid_x(); +} + +// Returns the 'y' dimension id of the thread in the current CUDA block. +_DEFAULT_ATTRS static inline uint32_t _get_thread_id_y() { + return __nvvm_read_ptx_sreg_tid_y(); +} + +// Returns the 'z' dimension id of the thread in the current CUDA block. +_DEFAULT_ATTRS static inline uint32_t _get_thread_id_z() { + return __nvvm_read_ptx_sreg_tid_z(); +} + +// Returns the absolute id of the thread in the current CUDA block. +_DEFAULT_ATTRS static inline uint64_t _get_thread_id() { + return _get_thread_id_x() + _get_num_threads_x() * _get_thread_id_y() + + _get_num_threads_x() * _get_num_threads_y() * _get_thread_id_z(); +} + +// Returns the size of a CUDA warp, always 32 on NVIDIA hardware. +_DEFAULT_ATTRS static inline uint32_t _get_lane_size() { return 32; } jhuber6 wrote: That's not exposed to `clang` as a builtin, but I could (and probably should) add it. https://github.com/llvm/llvm-project/pull/110179 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Adding splitdouble HLSL function (PR #109331)
@@ -88,4 +88,9 @@ def int_dx_rsqrt : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>] def int_dx_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>; def int_dx_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>; def int_dx_step : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty, LLVMMatchType<0>], [IntrNoMem]>; + +def int_dx_splitdouble : DefaultAttrsIntrinsic< +[llvm_anyint_ty, LLVMMatchType<0>], farzonl wrote: so why `llvm_anyint_ty` instead of a vector type? This means the the return type isn't preserving the vector length provided by the double argument. I think this is part of why you are having to do your own custom scalarization. https://github.com/llvm/llvm-project/pull/109331 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)
jdoerfert wrote: > This way the common intrinsics would be defined in a single location, and it > would be harder for someone to add a new intrinsic without realizing that all > files should implement a common interface. That's one of the reasons mapping.{h,cpp} in DeviceRTL uses the extra level of indirection. https://github.com/llvm/llvm-project/pull/110179 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [rtsan] Update docs to include run-time flags (PR #110296)
@@ -84,6 +84,75 @@ non-zero exit code. #14 0x0001958960dc () #15 0x2f557ffc () +Run-time flags +-- + +RealtimeSanitizer supports a number of run-time flags, which can be specified in the ``RTSAN_OPTIONS`` environment variable: + +.. code-block:: console + + % RTSAN_OPTIONS=option_1=true:path_option_2="/some/file.txt" ./a.out + ... + +Or at compile-time by overloading the symbol ``__rtsan_default_options``: cjappl wrote: Thanks for catching that, I agree "provide" is better. Do you have any suggestions on how I might word a note on visibility? https://github.com/llvm/llvm-project/pull/110296 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Adding splitdouble HLSL function (PR #109331)
@@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -O1 -o - | FileCheck %s +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple spirv--vulkan-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefix=SPIRV + + +// CHECK: define {{.*}} float {{.*}}test_scalar{{.*}}(double {{.*}} [[VALD:%.*]]) +// CHECK: [[VALRET:%.*]] = tail call { i32, i32 } @llvm.dx.splitdouble.i32(double [[VALD]]) +// CHECK-NEXT: extractvalue { i32, i32 } [[VALRET]], 0 +// CHECK-NEXT: extractvalue { i32, i32 } [[VALRET]], 1 +// SPIRV: define spir_func {{.*}} float {{.*}}test_scalar{{.*}}(double {{.*}} [[VALD:%.*]]) +// SPIRV-NOT: @llvm.dx.splitdouble +// SPIRV: [[REG:%.*]] = load double, ptr [[VALD]].addr +// SPIRV: call spir_func void {{.*}}asuint{{.*}}(double {{.*}} [[REG]], {{.*}}) +float test_scalar(double D) { + uint A, B; + asuint(D, A, B); + return A + B; +} + +// CHECK: define {{.*}} <3 x float> {{.*}}test_vector{{.*}}(<3 x double> {{.*}} [[VALD:%.*]]) +// CHECK-COUNT-3: [[VALREG:%.*]] = extractelement <3 x double> [[VALD]], i64 [[VALIDX:[0-3]]] +// CHECK-NEXT: [[VALRET:%.*]] = tail call { i32, i32 } @llvm.dx.splitdouble.i32(double [[VALREG]]) farzonl wrote: Why is this a tail call? Seems weird that we would have or want recursion for a library api? Am I misunderstanding something? https://github.com/llvm/llvm-project/pull/109331 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)
@@ -0,0 +1,187 @@ +//===-- amdgpuintrin.h - AMDPGU intrinsic functions ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef __AMDGPUINTRIN_H +#define __AMDGPUINTRIN_H + +#ifndef __AMDGPU__ +#error "This file is intended for AMDGPU targets or offloading to AMDGPU +#endif + +#include +#include + +#if defined(__HIP__) || defined(__CUDA__) +#define _DEFAULT_ATTRS __attribute__((device)) __attribute__((always_inline)) +#else +#define _DEFAULT_ATTRS __attribute__((always_inline)) +#endif + +#pragma omp begin declare target device_type(nohost) +#pragma omp begin declare variant match(device = {arch(amdgcn)}) + +// Type aliases to the address spaces used by the AMDGPU backend. +#define _private __attribute__((opencl_private)) +#define _constant __attribute__((opencl_constant)) +#define _local __attribute__((opencl_local)) +#define _global __attribute__((opencl_global)) + +// Attribute to declare a function as a kernel. +#define _kernel __attribute__((amdgpu_kernel, visibility("protected"))) + +// Returns the number of workgroups in the 'x' dimension of the grid. +_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_x() { + return __builtin_amdgcn_grid_size_x() / __builtin_amdgcn_workgroup_size_x(); +} + +// Returns the number of workgroups in the 'y' dimension of the grid. +_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_y() { + return __builtin_amdgcn_grid_size_y() / __builtin_amdgcn_workgroup_size_y(); +} + +// Returns the number of workgroups in the 'z' dimension of the grid. +_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_z() { + return __builtin_amdgcn_grid_size_z() / __builtin_amdgcn_workgroup_size_z(); +} + +// Returns the total number of workgruops in the grid. +_DEFAULT_ATTRS static inline uint64_t _get_num_blocks() { + return _get_num_blocks_x() * _get_num_blocks_y() * _get_num_blocks_z(); +} + +// Returns the 'x' dimension of the current AMD workgroup's id. +_DEFAULT_ATTRS static inline uint32_t _get_block_id_x() { + return __builtin_amdgcn_workgroup_id_x(); +} + +// Returns the 'y' dimension of the current AMD workgroup's id. +_DEFAULT_ATTRS static inline uint32_t _get_block_id_y() { + return __builtin_amdgcn_workgroup_id_y(); +} + +// Returns the 'z' dimension of the current AMD workgroup's id. +_DEFAULT_ATTRS static inline uint32_t _get_block_id_z() { + return __builtin_amdgcn_workgroup_id_z(); +} + +// Returns the absolute id of the AMD workgroup. +_DEFAULT_ATTRS static inline uint64_t _get_block_id() { + return _get_block_id_x() + _get_num_blocks_x() * _get_block_id_y() + + _get_num_blocks_x() * _get_num_blocks_y() * _get_block_id_z(); +} + +// Returns the number of workitems in the 'x' dimension. +_DEFAULT_ATTRS static inline uint32_t _get_num_threads_x() { + return __builtin_amdgcn_workgroup_size_x(); +} + +// Returns the number of workitems in the 'y' dimension. +_DEFAULT_ATTRS static inline uint32_t _get_num_threads_y() { + return __builtin_amdgcn_workgroup_size_y(); +} + +// Returns the number of workitems in the 'z' dimension. +_DEFAULT_ATTRS static inline uint32_t _get_num_threads_z() { + return __builtin_amdgcn_workgroup_size_z(); +} + +// Returns the total number of workitems in the workgroup. +_DEFAULT_ATTRS static inline uint64_t _get_num_threads() { + return _get_num_threads_x() * _get_num_threads_y() * _get_num_threads_z(); +} + +// Returns the 'x' dimension id of the workitem in the current AMD workgroup. +_DEFAULT_ATTRS static inline uint32_t _get_thread_id_x() { + return __builtin_amdgcn_workitem_id_x(); +} + +// Returns the 'y' dimension id of the workitem in the current AMD workgroup. +_DEFAULT_ATTRS static inline uint32_t _get_thread_id_y() { + return __builtin_amdgcn_workitem_id_y(); +} + +// Returns the 'z' dimension id of the workitem in the current AMD workgroup. +_DEFAULT_ATTRS static inline uint32_t _get_thread_id_z() { + return __builtin_amdgcn_workitem_id_z(); +} + +// Returns the absolute id of the thread in the current AMD workgroup. +_DEFAULT_ATTRS static inline uint64_t _get_thread_id() { + return _get_thread_id_x() + _get_num_threads_x() * _get_thread_id_y() + + _get_num_threads_x() * _get_num_threads_y() * _get_thread_id_z(); +} + +// Returns the size of an AMD wavefront, either 32 or 64 depending on hardware +// and compilation options. +_DEFAULT_ATTRS static inline uint32_t _get_lane_size() { jhuber6 wrote: Yeah, this is the one name that I really struggled with since there's a lot of different words. It could be `get_num_lanes()` to indicate more that it's the SIMT level. Either that or just accept `wave` or `warp` as the go-to word. https://github.com/llvm/llvm-project/pull/110179 __
[clang] [libclang/python] Do not rely on `ctypes`' `errcheck` (PR #105490)
DeinAlptraum wrote: @Endilll I rebased with the added tests from #109846 and checked with [diff-cover](https://pypi.org/project/diff-cover/) that all changed lines are covered by tests https://github.com/llvm/llvm-project/pull/105490 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)
@@ -0,0 +1,187 @@ +//===-- amdgpuintrin.h - AMDPGU intrinsic functions ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef __AMDGPUINTRIN_H +#define __AMDGPUINTRIN_H + +#ifndef __AMDGPU__ +#error "This file is intended for AMDGPU targets or offloading to AMDGPU +#endif + +#include +#include + +#if defined(__HIP__) || defined(__CUDA__) +#define _DEFAULT_ATTRS __attribute__((device)) __attribute__((always_inline)) +#else +#define _DEFAULT_ATTRS __attribute__((always_inline)) +#endif + +#pragma omp begin declare target device_type(nohost) +#pragma omp begin declare variant match(device = {arch(amdgcn)}) + +// Type aliases to the address spaces used by the AMDGPU backend. +#define _private __attribute__((opencl_private)) +#define _constant __attribute__((opencl_constant)) +#define _local __attribute__((opencl_local)) +#define _global __attribute__((opencl_global)) + +// Attribute to declare a function as a kernel. +#define _kernel __attribute__((amdgpu_kernel, visibility("protected"))) + +// Returns the number of workgroups in the 'x' dimension of the grid. +_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_x() { + return __builtin_amdgcn_grid_size_x() / __builtin_amdgcn_workgroup_size_x(); +} + +// Returns the number of workgroups in the 'y' dimension of the grid. +_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_y() { + return __builtin_amdgcn_grid_size_y() / __builtin_amdgcn_workgroup_size_y(); +} + +// Returns the number of workgroups in the 'z' dimension of the grid. +_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_z() { + return __builtin_amdgcn_grid_size_z() / __builtin_amdgcn_workgroup_size_z(); +} + +// Returns the total number of workgruops in the grid. +_DEFAULT_ATTRS static inline uint64_t _get_num_blocks() { + return _get_num_blocks_x() * _get_num_blocks_y() * _get_num_blocks_z(); +} + +// Returns the 'x' dimension of the current AMD workgroup's id. +_DEFAULT_ATTRS static inline uint32_t _get_block_id_x() { + return __builtin_amdgcn_workgroup_id_x(); +} + +// Returns the 'y' dimension of the current AMD workgroup's id. +_DEFAULT_ATTRS static inline uint32_t _get_block_id_y() { + return __builtin_amdgcn_workgroup_id_y(); +} + +// Returns the 'z' dimension of the current AMD workgroup's id. +_DEFAULT_ATTRS static inline uint32_t _get_block_id_z() { + return __builtin_amdgcn_workgroup_id_z(); +} + +// Returns the absolute id of the AMD workgroup. +_DEFAULT_ATTRS static inline uint64_t _get_block_id() { + return _get_block_id_x() + _get_num_blocks_x() * _get_block_id_y() + + _get_num_blocks_x() * _get_num_blocks_y() * _get_block_id_z(); +} + +// Returns the number of workitems in the 'x' dimension. +_DEFAULT_ATTRS static inline uint32_t _get_num_threads_x() { + return __builtin_amdgcn_workgroup_size_x(); +} + +// Returns the number of workitems in the 'y' dimension. +_DEFAULT_ATTRS static inline uint32_t _get_num_threads_y() { + return __builtin_amdgcn_workgroup_size_y(); +} + +// Returns the number of workitems in the 'z' dimension. +_DEFAULT_ATTRS static inline uint32_t _get_num_threads_z() { + return __builtin_amdgcn_workgroup_size_z(); +} + +// Returns the total number of workitems in the workgroup. +_DEFAULT_ATTRS static inline uint64_t _get_num_threads() { + return _get_num_threads_x() * _get_num_threads_y() * _get_num_threads_z(); +} + +// Returns the 'x' dimension id of the workitem in the current AMD workgroup. +_DEFAULT_ATTRS static inline uint32_t _get_thread_id_x() { + return __builtin_amdgcn_workitem_id_x(); +} + +// Returns the 'y' dimension id of the workitem in the current AMD workgroup. +_DEFAULT_ATTRS static inline uint32_t _get_thread_id_y() { + return __builtin_amdgcn_workitem_id_y(); +} + +// Returns the 'z' dimension id of the workitem in the current AMD workgroup. +_DEFAULT_ATTRS static inline uint32_t _get_thread_id_z() { + return __builtin_amdgcn_workitem_id_z(); +} + +// Returns the absolute id of the thread in the current AMD workgroup. +_DEFAULT_ATTRS static inline uint64_t _get_thread_id() { + return _get_thread_id_x() + _get_num_threads_x() * _get_thread_id_y() + + _get_num_threads_x() * _get_num_threads_y() * _get_thread_id_z(); +} + +// Returns the size of an AMD wavefront, either 32 or 64 depending on hardware +// and compilation options. +_DEFAULT_ATTRS static inline uint32_t _get_lane_size() { + return __builtin_amdgcn_wavefrontsize(); +} + +// Returns the id of the thread inside of an AMD wavefront executing together. +_DEFAULT_ATTRS [[clang::convergent]] static inline uint32_t _get_lane_id() { + return __builtin_amdgcn_mbcnt_hi(~0u, __builtin_amdgcn_mbcnt_lo(~0u, 0u)); +} + +// Returns the bit-mask of active threads in
[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
@@ -6457,6 +6472,18 @@ void InitializationSequence::InitializeFrom(Sema &S, } } + if (!S.getLangOpts().CPlusPlus && + Kind.getKind() == InitializationKind::IK_Default) { +RecordDecl *Rec = DestType->getAsRecordDecl(); +if (Rec && Rec->hasUninitializedExplicitInitFields()) { + VarDecl *Var = dyn_cast_or_null(Entity.getDecl()); + if (Var && !Initializer) { erichkeane wrote: What is the `VarDecl` here? Again, we have access to the record-decl, so why can't we get the field name here? https://github.com/llvm/llvm-project/pull/102040 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)
@@ -0,0 +1,187 @@ +//===-- amdgpuintrin.h - AMDPGU intrinsic functions ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef __AMDGPUINTRIN_H +#define __AMDGPUINTRIN_H + +#ifndef __AMDGPU__ +#error "This file is intended for AMDGPU targets or offloading to AMDGPU +#endif + +#include +#include + +#if defined(__HIP__) || defined(__CUDA__) +#define _DEFAULT_ATTRS __attribute__((device)) __attribute__((always_inline)) +#else +#define _DEFAULT_ATTRS __attribute__((always_inline)) +#endif + +#pragma omp begin declare target device_type(nohost) +#pragma omp begin declare variant match(device = {arch(amdgcn)}) + +// Type aliases to the address spaces used by the AMDGPU backend. +#define _private __attribute__((opencl_private)) +#define _constant __attribute__((opencl_constant)) +#define _local __attribute__((opencl_local)) +#define _global __attribute__((opencl_global)) + +// Attribute to declare a function as a kernel. +#define _kernel __attribute__((amdgpu_kernel, visibility("protected"))) + +// Returns the number of workgroups in the 'x' dimension of the grid. +_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_x() { + return __builtin_amdgcn_grid_size_x() / __builtin_amdgcn_workgroup_size_x(); +} + +// Returns the number of workgroups in the 'y' dimension of the grid. +_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_y() { + return __builtin_amdgcn_grid_size_y() / __builtin_amdgcn_workgroup_size_y(); +} + +// Returns the number of workgroups in the 'z' dimension of the grid. +_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_z() { + return __builtin_amdgcn_grid_size_z() / __builtin_amdgcn_workgroup_size_z(); +} + +// Returns the total number of workgruops in the grid. +_DEFAULT_ATTRS static inline uint64_t _get_num_blocks() { jhuber6 wrote: This is being conservative with the API as listed, AFAIK CUDA says that the maximum X block size is 2^31 - 1 and Y and Z are 2^16 -1, meaning if you get the "global" ID, it could technically be more than 2^32 - 1. Maybe @Artem-B could chime in here. https://github.com/llvm/llvm-project/pull/110179 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits