[clang] [llvm] adding clang codegen (PR #109331)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/109331 >From 50d21754119ac10c2ee2376ed8f79d12f73cd137 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Thu, 19 Sep 2024 00:13:51 + Subject: [PATCH 1/3] Codegen builtin --- clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 38 clang/lib/CodeGen/CGCall.cpp | 5 ++ clang/lib/CodeGen/CGExpr.cpp | 15 - clang/lib/CodeGen/CodeGenFunction.h | 10 +++- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 20 +++ clang/lib/Sema/SemaHLSL.cpp | 58 --- .../builtins/asuint-splitdouble.hlsl | 10 llvm/include/llvm/IR/IntrinsicsDirectX.td | 5 ++ llvm/lib/Target/DirectX/DXIL.td | 1 + .../Target/DirectX/DXILIntrinsicExpansion.cpp | 13 + 11 files changed, 167 insertions(+), 14 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..b38957f6e3f15d 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4788,6 +4788,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLAsUintSplitDouble: LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_asuint_splitdouble"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + // Builtins for XRay. def XRayCustomEvent : Builtin { let Spellings = ["__xray_customevent"]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 249aead33ad73d..f7695b8693f3dc 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18843,6 +18843,44 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: { retType, CGM.getHLSLRuntime().getSignIntrinsic(), ArrayRef{Op0}, nullptr, "hlsl.sign"); } + // This should only be called when targeting DXIL + case Builtin::BI__builtin_hlsl_asuint_splitdouble: { + +assert((E->getArg(0)->getType()->hasFloatingRepresentation() && +E->getArg(1)->getType()->hasUnsignedIntegerRepresentation() && +E->getArg(2)->getType()->hasUnsignedIntegerRepresentation()) && + "asuint operands types mismatch"); + +Value *Op0 = EmitScalarExpr(E->getArg(0)); +const HLSLOutArgExpr *OutArg1 = dyn_cast(E->getArg(1)); +const HLSLOutArgExpr *OutArg2 = dyn_cast(E->getArg(2)); + +CallArgList Args; +LValue Op1TmpLValue = EmitHLSLOutArgExpr(OutArg1, Args, OutArg1->getType()); +LValue Op2TmpLValue = EmitHLSLOutArgExpr(OutArg2, Args, OutArg2->getType()); + +llvm::Type *retType = llvm::StructType::get(Int32Ty, Int32Ty); +if (Op0->getType()->isVectorTy()) { + auto *XVecTy = E->getArg(0)->getType()->getAs(); + + llvm::VectorType *i32VecTy = llvm::VectorType::get( + Int32Ty, ElementCount::getFixed(XVecTy->getNumElements())); + + retType = llvm::StructType::get(i32VecTy, i32VecTy); +} + +CallInst *CI = +Builder.CreateIntrinsic(retType, llvm::Intrinsic::dx_asuint_splitdouble, +{Op0}, nullptr, "hlsl.asuint"); + +Value *arg0 = Builder.CreateExtractValue(CI, 0); +Value *arg1 = Builder.CreateExtractValue(CI, 1); + +Builder.CreateStore(arg0, Op1TmpLValue.getAddress()); +auto *s = Builder.CreateStore(arg1, Op2TmpLValue.getAddress()); +EmitWritebacks(*this, Args); +return s; + } } return nullptr; } diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 4ae981e4013e9c..096bbafa4cc694 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -4681,6 +4681,11 @@ void CallArg::copyInto(CodeGenFunction &CGF, Address Addr) const { IsUsed = true; } +void CodeGenFunction::EmitWritebacks(CodeGenFunction &CGF, + const CallArgList &args) { + emitWritebacks(CGF, args); +} + void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E, QualType type) { DisableDebugLocationUpdates Dis(*this, E); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 9166db4c74128c..1c299c4a932ca0 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -19,6 +19,7 @@ #include "CGObjCRuntime.h" #include "CGOpenMPRuntime.h" #include "CGRecordLayout.h" +#include "CGValue.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "ConstantEmitter.h" @@ -28,6 +29,7 @@ #include "clang/AST/DeclObjC.h" #include "clang/AST/NSAPI.h" #include "clang/AST/StmtVisitor.h" +#include "clang/AST/Type.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/CodeGenOptions.h" #include "clang/Basic/SourceManager.h" @@ -5458,9 +5460,8 @@ LValue CodeGenFunction::EmitOpaqueValueLValu
[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)
@@ -4719,8 +4719,9 @@ class FunctionEffect { NonBlocking = 1, Sirraide wrote: (github being confusing again; this is meant to reference the line above that one in case that’s not obvious...) https://github.com/llvm/llvm-project/pull/99656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] Fix musttail calls (PR #109943)
@@ -12658,10 +12658,10 @@ This instruction requires several arguments: the return value of the callee is returned to the caller's caller, even if a void return type is in use. - Both markers imply that the callee does not access allocas from the caller. - The ``tail`` marker additionally implies that the callee does not access - varargs from the caller. Calls marked ``musttail`` must obey the following - additional rules: + Both markers imply that the callee does not access allocas or ``byval`` + arguments from the caller. The ``tail`` marker additionally implies that the rnk wrote: I think you want to say that this case is not supported: ``` struct ByVal { int large[5]; }; void f(ByVal*); void g(ByVal o) { [[clang::musttail]] f(&o); } ``` The LangRef needs to permit *forwarding* cases like this, though: ``` struct ByVal { int large[5]; }; void f(ByVal a, ByVal b); void g(ByVal a, ByVal b) { [[clang::musttail]] f(b, a); } ``` We can make this work by copying the arguments out and back in before tearing down the call frame. Can you please clarify? https://github.com/llvm/llvm-project/pull/109943 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] Fix musttail calls (PR #109943)
https://github.com/rnk commented: Thanks for prioritizing this! I have triaged many internal issues about this. https://github.com/llvm/llvm-project/pull/109943 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] Fix musttail calls (PR #109943)
https://github.com/rnk edited https://github.com/llvm/llvm-project/pull/109943 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Bugfixes and improved support for `AttributedType`s in lambdas (PR #85325)
Sirraide wrote: ping https://github.com/llvm/llvm-project/pull/85325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [NFC] Add implicit cast kinds for function pointer conversions (PR #110047)
https://github.com/ahatanak created https://github.com/llvm/llvm-project/pull/110047 The new cast kinds are needed to distinguish between no-op conversions and conversions from pointers to noexcept functions to pointers to functions without noexcept as the latter can cause function pointers to be re-signed on arm64e. See https://github.com/llvm/llvm-project/pull/109056 for background. >From 1113c14d7ea25baf6c328e69661f4b94e437a4b4 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Wed, 25 Sep 2024 14:30:22 -0700 Subject: [PATCH] [NFC] Add implicit cast kinds for function pointer conversions The new cast kinds are needed to distinguish between no-op conversions and conversions from pointers to noexcept functions to pointers to functions without noexcept as the latter can cause function pointers to be re-signed on arm64e. See https://github.com/llvm/llvm-project/pull/109056 for background. --- .../bugprone/SwappedArgumentsCheck.cpp| 2 + .../ProTypeCstyleCastCheck.cpp| 4 +- .../google/AvoidCStyleCastsCheck.cpp | 7 +- .../clang-tidy/modernize/LoopConvertCheck.cpp | 4 +- .../ImplicitConversionInLoopCheck.cpp | 4 +- .../MakeMemberFunctionConstCheck.cpp | 9 +- .../clang-tidy/utils/DeclRefExprUtils.cpp | 2 + clang-tools-extra/clangd/Hover.cpp| 2 + clang/include/clang/AST/IgnoreExpr.h | 4 +- clang/include/clang/AST/OperationKinds.def| 8 + .../lib/ARCMigrate/TransBlockObjCVariable.cpp | 6 +- clang/lib/AST/ByteCode/Compiler.cpp | 4 + clang/lib/AST/Expr.cpp| 28 ++- clang/lib/AST/ExprCXX.cpp | 6 +- clang/lib/AST/ExprConstant.cpp| 17 +- clang/lib/Analysis/CFG.cpp| 2 + clang/lib/Analysis/ExprMutationAnalyzer.cpp | 12 +- clang/lib/Analysis/FlowSensitive/Transfer.cpp | 8 +- clang/lib/Analysis/ThreadSafety.cpp | 6 +- clang/lib/Analysis/ThreadSafetyCommon.cpp | 2 + clang/lib/CodeGen/CGDecl.cpp | 2 + clang/lib/CodeGen/CGExpr.cpp | 6 +- clang/lib/CodeGen/CGExprAgg.cpp | 4 + clang/lib/CodeGen/CGExprComplex.cpp | 2 + clang/lib/CodeGen/CGExprConstant.cpp | 2 + clang/lib/CodeGen/CGExprScalar.cpp| 4 +- clang/lib/CodeGen/CGHLSLRuntime.cpp | 1 - clang/lib/CodeGen/CodeGenModule.cpp | 20 +- clang/lib/Edit/RewriteObjCFoundationAPI.cpp | 2 + clang/lib/Sema/CheckExprLifetime.cpp | 2 + clang/lib/Sema/SemaChecking.cpp | 4 + clang/lib/Sema/SemaDecl.cpp | 4 +- clang/lib/Sema/SemaDeclCXX.cpp| 4 +- clang/lib/Sema/SemaExpr.cpp | 2 + clang/lib/Sema/SemaExprCXX.cpp| 6 +- clang/lib/Sema/SemaInit.cpp | 4 +- clang/lib/Sema/SemaOpenMP.cpp | 211 +- clang/lib/Sema/SemaOverload.cpp | 6 +- clang/lib/Sema/SemaStmt.cpp | 2 + clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp | 2 + clang/lib/StaticAnalyzer/Core/SValBuilder.cpp | 2 + .../ast-dump-function-pointer-conversion.cpp | 30 +++ .../dcl.decl/dcl.init/dcl.init.ref/p4-ast.cpp | 4 +- .../GlobalConstructorFunction.hlsl| 31 +-- .../CodeGenHLSL/GlobalConstructorLib.hlsl | 23 +- clang/test/CodeGenHLSL/GlobalDestructors.hlsl | 51 ++--- .../builtins/RWBuffer-constructor.hlsl| 1 - .../builtins/RWBuffer-subscript.hlsl | 5 +- .../test/CodeGenHLSL/inline-constructors.hlsl | 76 --- clang/test/CodeGenHLSL/inline-functions.hlsl | 116 -- llvm/include/llvm/CodeGen/VirtRegMap.h| 8 +- llvm/include/llvm/SandboxIR/SandboxIR.h | 34 +++ llvm/lib/CodeGen/MachineVerifier.cpp | 2 +- llvm/lib/SandboxIR/SandboxIR.cpp | 24 ++ .../test_g_insert_subvector.mir | 3 + llvm/unittests/SandboxIR/SandboxIRTest.cpp| 66 ++ llvm/unittests/SandboxIR/TrackerTest.cpp | 31 +++ 57 files changed, 506 insertions(+), 428 deletions(-) create mode 100644 clang/test/AST/ast-dump-function-pointer-conversion.cpp delete mode 100644 clang/test/CodeGenHLSL/inline-constructors.hlsl delete mode 100644 clang/test/CodeGenHLSL/inline-functions.hlsl diff --git a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp index 8989444dde1300..acb7112fa2abed 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp @@ -27,6 +27,8 @@ void SwappedArgumentsCheck::registerMatchers(MatchFinder *Finder) { static const Expr *ignoreNoOpCasts(const Expr *E) { if (auto *Cast = dyn_cast(E)) if (Cast->getCastKind() == CK_LValueToRValue || +Cast->getCastKind() == CK_FunctionPointer
[clang] [clang-tools-extra] [llvm] [NFC] Add implicit cast kinds for function pointer conversions (PR #110047)
https://github.com/ahatanak closed https://github.com/llvm/llvm-project/pull/110047 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Vector Usual Arithmetic Conversions (PR #108659)
@@ -401,6 +401,194 @@ void SemaHLSL::DiagnoseAttrStageMismatch( << (AllowedStages.size() != 1) << join(StageStrings, ", "); } +template +static void castVector(Sema &S, ExprResult &E, QualType &Ty, unsigned Sz) { + if (const auto *VTy = Ty->getAs()) +Ty = VTy->getElementType(); + Ty = S.getASTContext().getExtVectorType(Ty, Sz); + E = S.ImpCastExprToType(E.get(), Ty, Kind); +} + +template +static QualType castElement(Sema &S, ExprResult &E, QualType Ty) { + E = S.ImpCastExprToType(E.get(), Ty, Kind); + return Ty; +} + +static QualType handleFloatVectorBinOpConversion( +Sema &SemaRef, ExprResult &LHS, ExprResult &RHS, QualType LHSType, +QualType RHSType, QualType LElTy, QualType RElTy, bool IsCompAssign) { + bool LHSFloat = LElTy->isRealFloatingType(); + bool RHSFloat = RElTy->isRealFloatingType(); + + if (LHSFloat && RHSFloat) { +if (IsCompAssign || +SemaRef.getASTContext().getFloatingTypeOrder(LElTy, RElTy) > 0) + return castElement(SemaRef, RHS, LHSType); + +return castElement(SemaRef, LHS, RHSType); + } + + if (LHSFloat) +return castElement(SemaRef, RHS, LHSType); + + assert(RHSFloat); + if (IsCompAssign) +return castElement(SemaRef, RHS, LHSType); + + return castElement(SemaRef, LHS, RHSType); +} + +static QualType handleIntegerVectorBinOpConversion( +Sema &SemaRef, ExprResult &LHS, ExprResult &RHS, QualType LHSType, +QualType RHSType, QualType LElTy, QualType RElTy, bool IsCompAssign) { + + int IntOrder = SemaRef.Context.getIntegerTypeOrder(LElTy, RElTy); + bool LHSSigned = LElTy->hasSignedIntegerRepresentation(); + bool RHSSigned = RElTy->hasSignedIntegerRepresentation(); + auto &Ctx = SemaRef.getASTContext(); + + // If both types have the same signedness, use the higher ranked type. + if (LHSSigned == RHSSigned) { +if (IsCompAssign || IntOrder >= 0) + return castElement(SemaRef, RHS, LHSType); + +return castElement(SemaRef, LHS, RHSType); + } + + // If the unsigned type has greater than or equal rank of the signed type, use + // the unsigned type. + if (IntOrder != (LHSSigned ? 1 : -1)) { +if (IsCompAssign || RHSSigned) + return castElement(SemaRef, RHS, LHSType); +return castElement(SemaRef, LHS, RHSType); + } + + // At this point the signed type has higher rank than the unsigned type, which + // means it will be the same size or bigger. If the signed type is bigger, it + // can represent all the values of the unsigned type, so select it. + if (Ctx.getIntWidth(LElTy) != Ctx.getIntWidth(RElTy)) { +if (IsCompAssign || LHSSigned) + return castElement(SemaRef, RHS, LHSType); +return castElement(SemaRef, LHS, RHSType); + } + + // This is a bit of an odd duck case in HLSL. It shouldn't happen, but can due + // to C/C++ leaking through. The place this happens today is long vs long + // long. When arguments are vector and vector, + // the long long has higher rank than long even though they are the same size. bogner wrote: Should we assert on the types to make sure this is indeed the `long`/`long long` case? If we somehow got here for some other case I'm not convinced what we do below would be correct. https://github.com/llvm/llvm-project/pull/108659 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Vector Usual Arithmetic Conversions (PR #108659)
https://github.com/bogner approved this pull request. https://github.com/llvm/llvm-project/pull/108659 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Bugfixes and improved support for `AttributedType`s in lambdas (PR #85325)
https://github.com/erichkeane approved this pull request. I don't see any reason to hold this up, and its waited long enough. So I'm going to consider this 'baked' enough in review. https://github.com/llvm/llvm-project/pull/85325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Bugfixes and improved support for `AttributedType`s in lambdas (PR #85325)
Sirraide wrote: Alright, I’ll merge main and then merge this once CI is done. https://github.com/llvm/llvm-project/pull/85325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Bugfixes and improved support for `AttributedType`s in lambdas (PR #85325)
https://github.com/Sirraide updated https://github.com/llvm/llvm-project/pull/85325 >From 907210a3ad3d829a8e49a5c976d129f8653801bf Mon Sep 17 00:00:00 2001 From: Sirraide Date: Thu, 14 Mar 2024 18:24:37 +0100 Subject: [PATCH 01/16] [Clang] Add `dump()` method for `Attr` --- clang/include/clang/AST/Attr.h | 2 ++ clang/lib/AST/ASTDumper.cpp| 8 2 files changed, 10 insertions(+) diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h index 8e9b7ad8b46826..6400023947863f 100644 --- a/clang/include/clang/AST/Attr.h +++ b/clang/include/clang/AST/Attr.h @@ -112,6 +112,8 @@ class Attr : public AttributeCommonInfo { // Pretty print this attribute. void printPretty(raw_ostream &OS, const PrintingPolicy &Policy) const; + void dump() const; + static StringRef getDocumentation(attr::Kind); }; diff --git a/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp index 6efc5bb92e28d2..8d8b8621341ef7 100644 --- a/clang/lib/AST/ASTDumper.cpp +++ b/clang/lib/AST/ASTDumper.cpp @@ -361,3 +361,11 @@ LLVM_DUMP_METHOD void ConceptReference::dump(raw_ostream &OS) const { ASTDumper P(OS, Ctx, Ctx.getDiagnostics().getShowColors()); P.Visit(this); } + +//===--===// +// Attr method implementations +//===--===// +LLVM_DUMP_METHOD void Attr::dump() const { + ASTDumper P(llvm::errs(), /*ShowColors=*/false); + P.Visit(this); +} >From d719a7605c89ed4ea88734b5386b6009931450f6 Mon Sep 17 00:00:00 2001 From: Sirraide Date: Thu, 14 Mar 2024 18:25:18 +0100 Subject: [PATCH 02/16] [Clang] Do not instantiate the same (FunctionProto)Type twice --- clang/lib/Sema/TreeTransform.h | 22 -- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 2d22692f3ab750..cf781792935f18 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -7231,12 +7231,22 @@ QualType TreeTransform::TransformAttributedType( // FIXME: dependent operand expressions? if (getDerived().AlwaysRebuild() || modifiedType != oldType->getModifiedType()) { -TypeLocBuilder AuxiliaryTLB; -AuxiliaryTLB.reserve(TL.getFullDataSize()); -QualType equivalentType = -getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc()); -if (equivalentType.isNull()) - return QualType(); +// Do not transform the equivalent type if it is equal to the modified type. +// +// This is because, 1. it’s the same type, instantiating it again will yield +// the same result anyway, and if it doesn't, then that could be a bug in +// and of itself, and 2. instantiating the same TypeLoc twice is a really +// bad idea if it's a FunctionProtoType, because instantiating the same +// ParmVarDecls twice will cause assertion failures. +QualType equivalentType = modifiedType; +if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) { + TypeLocBuilder AuxiliaryTLB; + AuxiliaryTLB.reserve(TL.getFullDataSize()); + equivalentType = + getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc()); + if (equivalentType.isNull()) +return QualType(); +} // Check whether we can add nullability; it is only represented as // type sugar, and therefore cannot be diagnosed in any other way. >From a9c753ab46b40bd7da6f27eb11655fe43acb11de Mon Sep 17 00:00:00 2001 From: Sirraide Date: Thu, 14 Mar 2024 21:40:41 +0100 Subject: [PATCH 03/16] [Clang] Refactor instantiation of a lambda's FunctionProtoType - Co-authored-by: Yuxuan Chen --- clang/include/clang/Sema/Template.h| 14 +++- clang/lib/Sema/SemaTemplateInstantiate.cpp | 13 +++- clang/lib/Sema/TreeTransform.h | 90 +++--- 3 files changed, 49 insertions(+), 68 deletions(-) diff --git a/clang/include/clang/Sema/Template.h b/clang/include/clang/Sema/Template.h index ce44aca797b0fb..8c379f51ca3d5d 100644 --- a/clang/include/clang/Sema/Template.h +++ b/clang/include/clang/Sema/Template.h @@ -411,6 +411,11 @@ enum class TemplateSubstitutionKind : char { /// lookup will search our outer scope. bool CombineWithOuterScope; +/// Whether this scope is being used to instantiate a lambda expression, +/// in which case it should be reused for instantiating the lambda's +/// FunctionProtoType. +bool InstantiatingLambda = false; + /// If non-NULL, the template parameter pack that has been /// partially substituted per C++0x [temp.arg.explicit]p9. NamedDecl *PartiallySubstitutedPack = nullptr; @@ -425,9 +430,11 @@ enum class TemplateSubstitutionKind : char { unsigned NumArgsInPartiallySubstitutedPack; public: -LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope = false) +LocalInstantiationScop
[clang] [clang-tools-extra] [NFC] Add implicit cast kinds for function pointer conversions (PR #110048)
https://github.com/ahatanak created https://github.com/llvm/llvm-project/pull/110048 The new cast kinds are needed to distinguish between no-op conversions and conversions from pointers to noexcept functions to pointers to functions without noexcept as the latter can cause function pointers to be re-signed on arm64e. See https://github.com/llvm/llvm-project/pull/109056 for background. >From 75cd73ecda039750270e8bde0523f51e4698c4ea Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Wed, 25 Sep 2024 14:47:05 -0700 Subject: [PATCH] [NFC] Add implicit cast kinds for function pointer conversions The new cast kinds are needed to distinguish between no-op conversions and conversions from pointers to noexcept functions to pointers to functions without noexcept as the latter can cause function pointers to be re-signed on arm64e. See https://github.com/llvm/llvm-project/pull/109056 for background. --- .../bugprone/SwappedArgumentsCheck.cpp| 2 ++ .../ProTypeCstyleCastCheck.cpp| 4 ++- .../google/AvoidCStyleCastsCheck.cpp | 7 - .../clang-tidy/modernize/LoopConvertCheck.cpp | 4 ++- .../ImplicitConversionInLoopCheck.cpp | 4 ++- .../MakeMemberFunctionConstCheck.cpp | 9 -- .../clang-tidy/utils/DeclRefExprUtils.cpp | 2 ++ clang-tools-extra/clangd/Hover.cpp| 2 ++ clang/include/clang/AST/IgnoreExpr.h | 4 ++- clang/include/clang/AST/OperationKinds.def| 8 + .../lib/ARCMigrate/TransBlockObjCVariable.cpp | 6 ++-- clang/lib/AST/ByteCode/Compiler.cpp | 4 +++ clang/lib/AST/Expr.cpp| 28 + clang/lib/AST/ExprCXX.cpp | 6 +++- clang/lib/AST/ExprConstant.cpp| 17 +-- clang/lib/Analysis/CFG.cpp| 2 ++ clang/lib/Analysis/ExprMutationAnalyzer.cpp | 12 clang/lib/Analysis/FlowSensitive/Transfer.cpp | 8 +++-- clang/lib/Analysis/ThreadSafety.cpp | 6 ++-- clang/lib/Analysis/ThreadSafetyCommon.cpp | 2 ++ clang/lib/CodeGen/CGDecl.cpp | 2 ++ clang/lib/CodeGen/CGExpr.cpp | 6 +++- clang/lib/CodeGen/CGExprAgg.cpp | 4 +++ clang/lib/CodeGen/CGExprComplex.cpp | 2 ++ clang/lib/CodeGen/CGExprConstant.cpp | 2 ++ clang/lib/CodeGen/CGExprScalar.cpp| 4 ++- clang/lib/Edit/RewriteObjCFoundationAPI.cpp | 2 ++ clang/lib/Sema/CheckExprLifetime.cpp | 2 ++ clang/lib/Sema/SemaChecking.cpp | 4 +++ clang/lib/Sema/SemaDecl.cpp | 4 ++- clang/lib/Sema/SemaDeclCXX.cpp| 4 ++- clang/lib/Sema/SemaExpr.cpp | 2 ++ clang/lib/Sema/SemaExprCXX.cpp| 6 +++- clang/lib/Sema/SemaInit.cpp | 4 +-- clang/lib/Sema/SemaOverload.cpp | 6 +++- clang/lib/Sema/SemaStmt.cpp | 2 ++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp | 2 ++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp | 2 ++ .../ast-dump-function-pointer-conversion.cpp | 30 +++ .../dcl.decl/dcl.init/dcl.init.ref/p4-ast.cpp | 4 +-- 40 files changed, 194 insertions(+), 37 deletions(-) create mode 100644 clang/test/AST/ast-dump-function-pointer-conversion.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp index 8989444dde1300..acb7112fa2abed 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp @@ -27,6 +27,8 @@ void SwappedArgumentsCheck::registerMatchers(MatchFinder *Finder) { static const Expr *ignoreNoOpCasts(const Expr *E) { if (auto *Cast = dyn_cast(E)) if (Cast->getCastKind() == CK_LValueToRValue || +Cast->getCastKind() == CK_FunctionPointerConversion || +Cast->getCastKind() == CK_MemberFunctionPointerConversion || Cast->getCastKind() == CK_NoOp) return ignoreNoOpCasts(Cast->getSubExpr()); return E; diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp index 5e255dcaacd262..bab08496e90e86 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp @@ -90,7 +90,9 @@ void ProTypeCstyleCastCheck::check(const MatchFinder::MatchResult &Result) { return; } - if (MatchedCast->getCastKind() == CK_NoOp && + if ((MatchedCast->getCastKind() == CK_NoOp || + MatchedCast->getCastKind() == CK_FunctionPointerConversion || + MatchedCast->getCastKind() == CK_MemberFunctionPointerConversion) && needsConstCast(SourceType, MatchedCast->getType())) { diag(MatchedCast->getBeginLoc(), "do not use C-style cast to cast aw
[clang] [llvm] adding clang codegen (PR #109331)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/109331 >From 50d21754119ac10c2ee2376ed8f79d12f73cd137 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Thu, 19 Sep 2024 00:13:51 + Subject: [PATCH 1/3] Codegen builtin --- clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 38 clang/lib/CodeGen/CGCall.cpp | 5 ++ clang/lib/CodeGen/CGExpr.cpp | 15 - clang/lib/CodeGen/CodeGenFunction.h | 10 +++- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 20 +++ clang/lib/Sema/SemaHLSL.cpp | 58 --- .../builtins/asuint-splitdouble.hlsl | 10 llvm/include/llvm/IR/IntrinsicsDirectX.td | 5 ++ llvm/lib/Target/DirectX/DXIL.td | 1 + .../Target/DirectX/DXILIntrinsicExpansion.cpp | 13 + 11 files changed, 167 insertions(+), 14 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..b38957f6e3f15d 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4788,6 +4788,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLAsUintSplitDouble: LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_asuint_splitdouble"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + // Builtins for XRay. def XRayCustomEvent : Builtin { let Spellings = ["__xray_customevent"]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 249aead33ad73d..f7695b8693f3dc 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18843,6 +18843,44 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: { retType, CGM.getHLSLRuntime().getSignIntrinsic(), ArrayRef{Op0}, nullptr, "hlsl.sign"); } + // This should only be called when targeting DXIL + case Builtin::BI__builtin_hlsl_asuint_splitdouble: { + +assert((E->getArg(0)->getType()->hasFloatingRepresentation() && +E->getArg(1)->getType()->hasUnsignedIntegerRepresentation() && +E->getArg(2)->getType()->hasUnsignedIntegerRepresentation()) && + "asuint operands types mismatch"); + +Value *Op0 = EmitScalarExpr(E->getArg(0)); +const HLSLOutArgExpr *OutArg1 = dyn_cast(E->getArg(1)); +const HLSLOutArgExpr *OutArg2 = dyn_cast(E->getArg(2)); + +CallArgList Args; +LValue Op1TmpLValue = EmitHLSLOutArgExpr(OutArg1, Args, OutArg1->getType()); +LValue Op2TmpLValue = EmitHLSLOutArgExpr(OutArg2, Args, OutArg2->getType()); + +llvm::Type *retType = llvm::StructType::get(Int32Ty, Int32Ty); +if (Op0->getType()->isVectorTy()) { + auto *XVecTy = E->getArg(0)->getType()->getAs(); + + llvm::VectorType *i32VecTy = llvm::VectorType::get( + Int32Ty, ElementCount::getFixed(XVecTy->getNumElements())); + + retType = llvm::StructType::get(i32VecTy, i32VecTy); +} + +CallInst *CI = +Builder.CreateIntrinsic(retType, llvm::Intrinsic::dx_asuint_splitdouble, +{Op0}, nullptr, "hlsl.asuint"); + +Value *arg0 = Builder.CreateExtractValue(CI, 0); +Value *arg1 = Builder.CreateExtractValue(CI, 1); + +Builder.CreateStore(arg0, Op1TmpLValue.getAddress()); +auto *s = Builder.CreateStore(arg1, Op2TmpLValue.getAddress()); +EmitWritebacks(*this, Args); +return s; + } } return nullptr; } diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 4ae981e4013e9c..096bbafa4cc694 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -4681,6 +4681,11 @@ void CallArg::copyInto(CodeGenFunction &CGF, Address Addr) const { IsUsed = true; } +void CodeGenFunction::EmitWritebacks(CodeGenFunction &CGF, + const CallArgList &args) { + emitWritebacks(CGF, args); +} + void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E, QualType type) { DisableDebugLocationUpdates Dis(*this, E); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 9166db4c74128c..1c299c4a932ca0 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -19,6 +19,7 @@ #include "CGObjCRuntime.h" #include "CGOpenMPRuntime.h" #include "CGRecordLayout.h" +#include "CGValue.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "ConstantEmitter.h" @@ -28,6 +29,7 @@ #include "clang/AST/DeclObjC.h" #include "clang/AST/NSAPI.h" #include "clang/AST/StmtVisitor.h" +#include "clang/AST/Type.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/CodeGenOptions.h" #include "clang/Basic/SourceManager.h" @@ -5458,9 +5460,8 @@ LValue CodeGenFunction::EmitOpaqueValueLValu
[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)
@@ -0,0 +1,1572 @@ +//=== SemaFunctionEffects.cpp - Sema handling of function effects -===// +// +// 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 +// +//===--===// +// +// This file implements Sema handling of function effects. +// +//===--===// + +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/Type.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Sema/SemaInternal.h" + +#define DEBUG_TYPE "effectanalysis" + +using namespace clang; + +namespace { + +enum class ViolationID : uint8_t { + None = 0, // Sentinel for an empty Violation. + // These first few map to a %select{} in a diagnostic. + BaseDiagnosticIndex, + AllocatesMemory = BaseDiagnosticIndex, + ThrowsOrCatchesExceptions, + HasStaticLocalVariable, + AccessesThreadLocalVariable, + AccessesObjCMethodOrProperty, + + // These only apply to callees, where the analysis stops at the Decl. + DeclDisallowsInference, + + // These both apply to indirect calls. The difference is that sometimes + // we have an actual Decl (generally a variable) which is the function + // pointer being called, and sometimes, typically due to a cast, we only + // have an expression. + CallsDeclWithoutEffect, + CallsExprWithoutEffect, +}; + +// Information about the AST context in which a violation was found, so +// that diagnostics can point to the correct source. +class ViolationSite { +public: + enum class Kind : uint8_t { +Default = 0, // Function body. +MemberInitializer = 1, +DefaultArgExpr = 2 + }; + +private: + llvm::PointerIntPair Impl; + +public: + ViolationSite() = default; + + explicit ViolationSite(CXXDefaultArgExpr *E) + : Impl(E, Kind::DefaultArgExpr) {} + + Kind kind() const { return static_cast(Impl.getInt()); } + CXXDefaultArgExpr *defaultArgExpr() const { return Impl.getPointer(); } + + void setKind(Kind K) { Impl.setPointerAndInt(nullptr, K); } +}; + +// Represents a violation of the rules, potentially for the entire duration of +// the analysis phase, in order to refer to it when explaining why a caller has +// been made unsafe by a callee. Can be transformed into either a Diagnostic +// (warning or a note), depending on whether the violation pertains to a +// function failing to be verifed as holding an effect vs. a function failing to +// be inferred as holding that effect. +struct Violation { + FunctionEffect Effect; + FunctionEffect + CalleeEffectPreventingInference; // Only for certain IDs; can be None. + ViolationID ID = ViolationID::None; + ViolationSite Site; + SourceLocation Loc; + const Decl *Callee = nullptr; // Only valid for Calls*. + + Violation() = default; + + Violation(FunctionEffect Effect, ViolationID ID, ViolationSite VS, +SourceLocation Loc, const Decl *Callee = nullptr, +std::optional CalleeEffect = std::nullopt) + : Effect(Effect), CalleeEffectPreventingInference( +CalleeEffect.value_or(FunctionEffect())), +ID(ID), Site(VS), Loc(Loc), Callee(Callee) {} + + unsigned diagnosticSelectIndex() const { +return unsigned(ID) - unsigned(ViolationID::BaseDiagnosticIndex); + } +}; + +enum class SpecialFuncType : uint8_t { None, OperatorNew, OperatorDelete }; +enum class CallableType : uint8_t { + // Unknown: probably function pointer. + Unknown, + Function, + Virtual, + Block +}; + +// Return whether a function's effects CAN be verified. +// The question of whether it SHOULD be verified is independent. +static bool functionIsVerifiable(const FunctionDecl *FD) { + if (FD->isTrivial()) { +// Otherwise `struct x { int a; };` would have an unverifiable default +// constructor. +return true; + } + return FD->hasBody(); +} + +static bool isNoexcept(const FunctionDecl *FD) { + const auto *FPT = FD->getType()->castAs(); dougsonos wrote: I hope I haven't misunderstood you here. I did add a test involving a `noreturn` function in attr-nonblocking-constraints.c (distilled): ``` // Has no prototype, noreturn. [[noreturn]] void aborts(); void nb2(void) __attribute__((nonblocking)) { aborts(); // no diagnostic because it's noreturn. } ``` The idea is that abort/terminate is a "force majeure", outside the scope of the effect analysis. https://github.com/llvm/llvm-project/pull/99656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [LLVM][TableGen] Change SeachableTableEmitter to use const RecordKeeper (PR #110032)
https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/110032 >From 934b0bd5934327429d0b878a9ece8a0c61e89400 Mon Sep 17 00:00:00 2001 From: Rahul Joshi Date: Wed, 25 Sep 2024 09:53:45 -0700 Subject: [PATCH] [LLVM][TableGen] Change SeachableTableEmitter to use const RecordKeeper --- clang/utils/TableGen/ClangAttrEmitter.cpp | 2 +- llvm/include/llvm/TableGen/Record.h | 23 +-- llvm/lib/TableGen/Record.cpp | 50 +++ llvm/lib/TableGen/TGParser.cpp| 2 +- .../utils/TableGen/SearchableTableEmitter.cpp | 138 +- mlir/tools/mlir-tblgen/OmpOpGen.cpp | 2 +- mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp | 6 +- 7 files changed, 116 insertions(+), 107 deletions(-) diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index 87be48c215e230..7f950c3b08a4b0 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -1866,7 +1866,7 @@ static LateAttrParseKind getLateAttrParseKind(const Record *Attr) { auto *LAPK = Attr->getValueAsDef(LateParsedStr); // Typecheck the `LateParsed` field. - SmallVector SuperClasses; + SmallVector SuperClasses; LAPK->getDirectSuperClasses(SuperClasses); if (SuperClasses.size() != 1) PrintFatalError(Attr, "Field `" + Twine(LateParsedStr) + diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h index 4cd73c3f675527..b68fff605d12dd 100644 --- a/llvm/include/llvm/TableGen/Record.h +++ b/llvm/include/llvm/TableGen/Record.h @@ -226,8 +226,9 @@ class DagRecTy : public RecTy { /// /// The list of superclasses is non-redundant, i.e. only contains classes that /// are not the superclass of some other listed class. -class RecordRecTy final : public RecTy, public FoldingSetNode, - public TrailingObjects { +class RecordRecTy final : public RecTy, + public FoldingSetNode, + public TrailingObjects { friend class Record; friend detail::RecordKeeperImpl; @@ -248,23 +249,23 @@ class RecordRecTy final : public RecTy, public FoldingSetNode, } /// Get the record type with the given non-redundant list of superclasses. - static RecordRecTy *get(RecordKeeper &RK, ArrayRef Classes); - static RecordRecTy *get(Record *Class); + static RecordRecTy *get(RecordKeeper &RK, ArrayRef Classes); + static RecordRecTy *get(const Record *Class); void Profile(FoldingSetNodeID &ID) const; - ArrayRef getClasses() const { -return ArrayRef(getTrailingObjects(), NumClasses); + ArrayRef getClasses() const { +return ArrayRef(getTrailingObjects(), NumClasses); } - using const_record_iterator = Record * const *; + using const_record_iterator = const Record *const *; const_record_iterator classes_begin() const { return getClasses().begin(); } const_record_iterator classes_end() const { return getClasses().end(); } std::string getAsString() const override; - bool isSubClassOf(Record *Class) const; + bool isSubClassOf(const Record *Class) const; bool typeIsConvertibleTo(const RecTy *RHS) const override; bool typeIsA(const RecTy *RHS) const override; @@ -1556,7 +1557,7 @@ class RecordVal { bool IsUsed = false; /// Reference locations to this record value. - SmallVector ReferenceLocs; + mutable SmallVector ReferenceLocs; public: RecordVal(Init *N, RecTy *T, FieldKind K); @@ -1605,7 +1606,7 @@ class RecordVal { bool setValue(Init *V, SMLoc NewLoc); /// Add a reference to this record value. - void addReferenceLoc(SMRange Loc) { ReferenceLocs.push_back(Loc); } + void addReferenceLoc(SMRange Loc) const { ReferenceLocs.push_back(Loc); } /// Return the references of this record value. ArrayRef getReferenceLocs() const { return ReferenceLocs; } @@ -1763,7 +1764,7 @@ class Record { bool hasDirectSuperClass(const Record *SuperClass) const; /// Append the direct superclasses of this record to Classes. - void getDirectSuperClasses(SmallVectorImpl &Classes) const; + void getDirectSuperClasses(SmallVectorImpl &Classes) const; bool isTemplateArg(Init *Name) const { return llvm::is_contained(TemplateArgs, Name); diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index 0f99b4a13d2f95..2973ef40642554 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -226,22 +226,22 @@ std::string DagRecTy::getAsString() const { } static void ProfileRecordRecTy(FoldingSetNodeID &ID, - ArrayRef Classes) { + ArrayRef Classes) { ID.AddInteger(Classes.size()); - for (Record *R : Classes) + for (const Record *R : Classes) ID.AddPointer(R); } RecordRecTy *RecordRecTy::get(RecordKeeper &RK, - ArrayRef UnsortedClasses) { + ArrayRef UnsortedCla
[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)
@@ -0,0 +1,1572 @@ +//=== SemaFunctionEffects.cpp - Sema handling of function effects -===// +// +// 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 +// +//===--===// +// +// This file implements Sema handling of function effects. +// +//===--===// + +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/Type.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Sema/SemaInternal.h" + +#define DEBUG_TYPE "effectanalysis" + +using namespace clang; + +namespace { + +enum class ViolationID : uint8_t { + None = 0, // Sentinel for an empty Violation. + // These first few map to a %select{} in a diagnostic. + BaseDiagnosticIndex, + AllocatesMemory = BaseDiagnosticIndex, + ThrowsOrCatchesExceptions, + HasStaticLocalVariable, + AccessesThreadLocalVariable, + AccessesObjCMethodOrProperty, + + // These only apply to callees, where the analysis stops at the Decl. + DeclDisallowsInference, + + // These both apply to indirect calls. The difference is that sometimes + // we have an actual Decl (generally a variable) which is the function + // pointer being called, and sometimes, typically due to a cast, we only + // have an expression. + CallsDeclWithoutEffect, + CallsExprWithoutEffect, +}; + +// Information about the AST context in which a violation was found, so +// that diagnostics can point to the correct source. +class ViolationSite { +public: + enum class Kind : uint8_t { +Default = 0, // Function body. +MemberInitializer = 1, +DefaultArgExpr = 2 + }; + +private: + llvm::PointerIntPair Impl; + +public: + ViolationSite() = default; + + explicit ViolationSite(CXXDefaultArgExpr *E) + : Impl(E, Kind::DefaultArgExpr) {} + + Kind kind() const { return static_cast(Impl.getInt()); } + CXXDefaultArgExpr *defaultArgExpr() const { return Impl.getPointer(); } + + void setKind(Kind K) { Impl.setPointerAndInt(nullptr, K); } +}; + +// Represents a violation of the rules, potentially for the entire duration of +// the analysis phase, in order to refer to it when explaining why a caller has +// been made unsafe by a callee. Can be transformed into either a Diagnostic +// (warning or a note), depending on whether the violation pertains to a +// function failing to be verifed as holding an effect vs. a function failing to +// be inferred as holding that effect. +struct Violation { + FunctionEffect Effect; + FunctionEffect + CalleeEffectPreventingInference; // Only for certain IDs; can be None. + ViolationID ID = ViolationID::None; + ViolationSite Site; + SourceLocation Loc; + const Decl *Callee = nullptr; // Only valid for Calls*. + + Violation() = default; + + Violation(FunctionEffect Effect, ViolationID ID, ViolationSite VS, +SourceLocation Loc, const Decl *Callee = nullptr, +std::optional CalleeEffect = std::nullopt) + : Effect(Effect), CalleeEffectPreventingInference( +CalleeEffect.value_or(FunctionEffect())), +ID(ID), Site(VS), Loc(Loc), Callee(Callee) {} + + unsigned diagnosticSelectIndex() const { +return unsigned(ID) - unsigned(ViolationID::BaseDiagnosticIndex); + } +}; + +enum class SpecialFuncType : uint8_t { None, OperatorNew, OperatorDelete }; +enum class CallableType : uint8_t { + // Unknown: probably function pointer. + Unknown, + Function, + Virtual, + Block +}; + +// Return whether a function's effects CAN be verified. +// The question of whether it SHOULD be verified is independent. +static bool functionIsVerifiable(const FunctionDecl *FD) { + if (FD->isTrivial()) { +// Otherwise `struct x { int a; };` would have an unverifiable default +// constructor. +return true; + } + return FD->hasBody(); +} + +static bool isNoexcept(const FunctionDecl *FD) { + const auto *FPT = FD->getType()->castAs(); Sirraide wrote: Yeah, no that one is fine, but builtin functions should still overrule that, e.g. if `longjmp` is declared `noreturn`, it should be blocking regardless because it’s a builtin function we consider to be blocking, so what I was saying is that we should have a test for `longjmp` specifically (or any other builtin function that can conceivably be declared `noreturn` but blocks). https://github.com/llvm/llvm-project/pull/99656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)
https://github.com/Sirraide edited https://github.com/llvm/llvm-project/pull/99656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)
@@ -4719,8 +4719,9 @@ class FunctionEffect { NonBlocking = 1, dougsonos wrote: Good idea. I was afraid of a lot of fallout but it was actually quite an easy change to get rid of the sentinel value. https://github.com/llvm/llvm-project/pull/99656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)
@@ -78,22 +78,19 @@ class ViolationSite { // be inferred as holding that effect. struct Violation { FunctionEffect Effect; - FunctionEffect + std::optional CalleeEffectPreventingInference; // Only for certain IDs; can be None. Sirraide wrote: ```suggestion CalleeEffectPreventingInference; // Only for certain IDs; can be nullopt. ``` Comment still needs updating https://github.com/llvm/llvm-project/pull/99656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -616,6 +626,62 @@ class LineJoiner { return 1; } + unsigned tryMergeNamespace(SmallVectorImpl::const_iterator I, + SmallVectorImpl::const_iterator E, + unsigned Limit) { +if (Limit == 0) galenelias wrote: We can't take an `int` here, because when ColumnLimit = 0, then the calling code passes in `UINT_MAX` which would then underflow the int. I could technically take a int64_t, but in general it seems like the style is to pre-check for underflow before doing subtraction, which is the approach here (although it's a little indirect). See below. https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -616,6 +626,62 @@ class LineJoiner { return 1; } + unsigned tryMergeNamespace(SmallVectorImpl::const_iterator I, + SmallVectorImpl::const_iterator E, + unsigned Limit) { +if (Limit == 0) + return 0; +if (I[1]->InPPDirective != (*I)->InPPDirective || +(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline)) { + return 0; +} +if (I + 2 == E || I[2]->Type == LT_Invalid) + return 0; + +Limit = limitConsideringMacros(I + 1, E, Limit); + +if (!nextTwoLinesFitInto(I, Limit)) + return 0; + +// Check if it's a namespace inside a namespace, and call recursively if so +// '3' is the sizes of the whitespace and closing brace for " _inner_ }". +if (I[1]->First->is(tok::kw_namespace)) { + if (I[1]->Last->is(TT_LineComment)) +return 0; + + const unsigned InnerLimit = Limit - I[1]->Last->TotalLength - 3; + const unsigned MergedLines = tryMergeNamespace(I + 1, E, InnerLimit); + if (!MergedLines) galenelias wrote: This underflow is prevented by prior call to `nextTwoLinesFitInto`, which will ensure that Limit is large enough such that this won't underflow. https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Set target in test (PR #110068)
Sirraide wrote: Relevant pr: #85325 https://github.com/llvm/llvm-project/pull/110068 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Set target in test (PR #110068)
https://github.com/Sirraide closed https://github.com/llvm/llvm-project/pull/110068 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Bugfixes and improved support for `AttributedType`s in lambdas (PR #85325)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-armv8-quick` running on `linaro-clang-armv8-quick` while building `clang` at step 5 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/154/builds/5052 Here is the relevant piece of the build log for the reference ``` Step 5 (ninja check 1) failure: stage 1 checked (failure) TEST 'Clang :: SemaCXX/lambda-attributes.cpp' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/20/include -nostdsysteminc -std=c++23 -fsyntax-only -verify /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/SemaCXX/lambda-attributes.cpp + /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/20/include -nostdsysteminc -std=c++23 -fsyntax-only -verify /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/SemaCXX/lambda-attributes.cpp error: 'expected-warning' diagnostics seen but not expected: File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/SemaCXX/lambda-attributes.cpp Line 18: 'preserve_most' calling convention is not supported for this target File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/SemaCXX/lambda-attributes.cpp Line 29: 'preserve_most' calling convention is not supported for this target File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/SemaCXX/lambda-attributes.cpp Line 33: 'cdecl' calling convention is not supported for this target File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/SemaCXX/lambda-attributes.cpp Line 40: 'preserve_most' calling convention is not supported for this target Line 45: 'preserve_most' calling convention is not supported for this target Line 48: 'preserve_most' calling convention is not supported for this target Line 53: 'preserve_most' calling convention is not supported for this target 7 errors generated. -- ``` https://github.com/llvm/llvm-project/pull/85325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Bugfixes and improved support for `AttributedType`s in lambdas (PR #85325)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-sie-win` running on `sie-win-worker` while building `clang` at step 7 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/46/builds/5553 Here is the relevant piece of the build log for the reference ``` Step 7 (test-build-unified-tree-check-all) failure: test (failure) TEST 'Clang :: SemaCXX/lambda-attributes.cpp' FAILED Exit Code: 1 Command Output (stdout): -- # RUN: at line 1 z:\b\llvm-clang-x86_64-sie-win\build\bin\clang.exe -cc1 -internal-isystem Z:\b\llvm-clang-x86_64-sie-win\build\lib\clang\20\include -nostdsysteminc -std=c++23 -fsyntax-only -verify Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\SemaCXX\lambda-attributes.cpp # executed command: 'z:\b\llvm-clang-x86_64-sie-win\build\bin\clang.exe' -cc1 -internal-isystem 'Z:\b\llvm-clang-x86_64-sie-win\build\lib\clang\20\include' -nostdsysteminc -std=c++23 -fsyntax-only -verify 'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\SemaCXX\lambda-attributes.cpp' # .---command stderr # | error: 'expected-error' diagnostics seen but not expected: # | File Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\SemaCXX\lambda-attributes.cpp Line 18: 'preserve_most' calling convention is not supported for this target # | File Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\SemaCXX\lambda-attributes.cpp Line 29: 'preserve_most' calling convention is not supported for this target # | File Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\SemaCXX\lambda-attributes.cpp Line 40: 'preserve_most' calling convention is not supported for this target # | Line 45: 'preserve_most' calling convention is not supported for this target # | Line 48: 'preserve_most' calling convention is not supported for this target # | Line 53: 'preserve_most' calling convention is not supported for this target # | 6 errors generated. # `- # error: command failed with exit status: 1 -- ``` https://github.com/llvm/llvm-project/pull/85325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [flang][driver] rename flang-new to flang (PR #110023)
kawashima-fj wrote: Thanks for the PR. Is there a symbolic link `flang-new` -> `flang`? We would like to have a transitional period. 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] [compiler-rt] [UBSan] Diagnose assumption violation (PR #104741)
dtcxzyw wrote: > -fsanitize=address,fuzzer I think it is not related to this patch. It only works with `-fsanitize=builtin` or `-fsanitize=undefined`. https://github.com/llvm/llvm-project/pull/104741 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][bugprone-posix-return] support integer literals as LHS (PR #109302)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/109302 >From cc2c798193722b3a537c76e74981ff767d064efa Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 19 Sep 2024 23:46:16 +0800 Subject: [PATCH 1/4] [clang-tidy][bugprone-posix-return] support integer literals as LHS Refactor matches to give more generic checker. --- .../clang-tidy/bugprone/PosixReturnCheck.cpp | 61 +++ clang-tools-extra/docs/ReleaseNotes.rst | 4 ++ .../checkers/bugprone/posix-return.cpp| 25 +++- 3 files changed, 62 insertions(+), 28 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp index 378427a1eab000..9d70039080d332 100644 --- a/clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp @@ -7,19 +7,17 @@ //===--===// #include "PosixReturnCheck.h" -#include "../utils/Matchers.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Lex/Lexer.h" using namespace clang::ast_matchers; namespace clang::tidy::bugprone { -static StringRef getFunctionSpelling(const MatchFinder::MatchResult &Result, - const char *BindingStr) { - const CallExpr *MatchedCall = cast( - (Result.Nodes.getNodeAs(BindingStr))->getLHS()); +static StringRef getFunctionSpelling(const MatchFinder::MatchResult &Result) { + const auto *MatchedCall = Result.Nodes.getNodeAs("call"); const SourceManager &SM = *Result.SourceManager; return Lexer::getSourceText(CharSourceRange::getTokenRange( MatchedCall->getCallee()->getSourceRange()), @@ -27,32 +25,40 @@ static StringRef getFunctionSpelling(const MatchFinder::MatchResult &Result, } void PosixReturnCheck::registerMatchers(MatchFinder *Finder) { + const auto PosixCall = + callExpr(callee(functionDecl( + anyOf(matchesName("^::posix_"), matchesName("^::pthread_")), + unless(hasName("::posix_openpt") + .bind("call"); + const auto ZeroIntegerLiteral = integerLiteral(equals(0)); + const auto NegIntegerLiteral = + unaryOperator(hasOperatorName("-"), hasUnaryOperand(integerLiteral())); + Finder->addMatcher( binaryOperator( - hasOperatorName("<"), - hasLHS(callExpr(callee(functionDecl( - anyOf(matchesName("^::posix_"), matchesName("^::pthread_")), - unless(hasName("::posix_openpt")), - hasRHS(integerLiteral(equals(0 + anyOf(allOf(hasOperatorName("<"), hasLHS(PosixCall), + hasRHS(ZeroIntegerLiteral)), +allOf(hasOperatorName(">"), hasLHS(ZeroIntegerLiteral), + hasRHS(PosixCall .bind("ltzop"), this); Finder->addMatcher( binaryOperator( - hasOperatorName(">="), - hasLHS(callExpr(callee(functionDecl( - anyOf(matchesName("^::posix_"), matchesName("^::pthread_")), - unless(hasName("::posix_openpt")), - hasRHS(integerLiteral(equals(0 + anyOf(allOf(hasOperatorName(">="), hasLHS(PosixCall), + hasRHS(ZeroIntegerLiteral)), +allOf(hasOperatorName("<="), hasLHS(ZeroIntegerLiteral), + hasRHS(PosixCall .bind("atop"), this); + Finder->addMatcher(binaryOperator(hasAnyOperatorName("==", "!="), +hasOperands(PosixCall, NegIntegerLiteral)) + .bind("binop"), + this); Finder->addMatcher( - binaryOperator( - hasAnyOperatorName("==", "!=", "<=", "<"), - hasLHS(callExpr(callee(functionDecl( - anyOf(matchesName("^::posix_"), matchesName("^::pthread_")), - unless(hasName("::posix_openpt")), - hasRHS(unaryOperator(hasOperatorName("-"), - hasUnaryOperand(integerLiteral() + binaryOperator(anyOf(allOf(hasAnyOperatorName("<=", "<"), + hasLHS(PosixCall), hasRHS(NegIntegerLiteral)), + allOf(hasAnyOperatorName(">", ">="), + hasLHS(NegIntegerLiteral), hasRHS(PosixCall .bind("binop"), this); } @@ -61,10 +67,13 @@ void PosixReturnCheck::check(const MatchFinder::MatchResult &Result) { if (const auto *LessThanZeroOp = Result.Nodes.getNodeAs("ltzop")) { SourceLocation OperatorLoc = LessThanZeroOp->getOperatorLoc(); +char NewBinOp = LessThanZeroOp->getOpcode() == BinaryOperator::Opcode::BO_LT +? '>' +: '<'; diag(OperatorLoc, "the comparison
[clang-tools-extra] [clang-tidy] insert ``static`` keyword in correct position for misc-use-internal-linkage (PR #108792)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/108792 >From 795b3ae677210ff50f7710a0cf73d435889b68ae Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Mon, 16 Sep 2024 13:47:10 +0800 Subject: [PATCH] [clang-tidy] insert ``static`` keyword in correct position for misc-use-internal-linkage Fixes: #108760 --- .../misc/UseInternalLinkageCheck.cpp | 34 +-- .../clang-tidy/utils/LexerUtils.cpp | 4 ++- clang-tools-extra/docs/ReleaseNotes.rst | 4 +++ .../misc/use-internal-linkage-func.cpp| 21 .../misc/use-internal-linkage-var.cpp | 12 +++ 5 files changed, 72 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp index c086e7721e02bd..a92448c15ef3a9 100644 --- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp @@ -8,12 +8,15 @@ #include "UseInternalLinkageCheck.h" #include "../utils/FileExtensionsUtils.h" +#include "../utils/LexerUtils.h" #include "clang/AST/Decl.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/ASTMatchers/ASTMatchersMacros.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/Specifiers.h" +#include "clang/Basic/TokenKinds.h" +#include "clang/Lex/Token.h" #include "llvm/ADT/STLExtras.h" using namespace clang::ast_matchers; @@ -110,10 +113,36 @@ static constexpr StringRef Message = "%0 %1 can be made static or moved into an anonymous namespace " "to enforce internal linkage"; +static SourceLocation getQualifiedTypeStartLoc(SourceLocation L, + const SourceManager &SM, + const ASTContext &Context) { + const SourceLocation StartOfFile = SM.getLocForStartOfFile(SM.getFileID(L)); + if (L.isInvalid() || L.isMacroID()) +return L; + bool HasChanged = true; + while (HasChanged) { +if (L == StartOfFile) + return L; +auto [Tok, Loc] = +utils::lexer::getPreviousTokenAndStart(L, SM, Context.getLangOpts()); +if (Tok.is(tok::raw_identifier)) { + IdentifierInfo &Info = Context.Idents.get( + StringRef(SM.getCharacterData(Tok.getLocation()), Tok.getLength())); + Tok.setIdentifierInfo(&Info); + Tok.setKind(Info.getTokenID()); +} +HasChanged = Tok.isOneOf(tok::kw_const, tok::kw_volatile); +if (HasChanged) + L = Loc; + } + return L; +} + void UseInternalLinkageCheck::check(const MatchFinder::MatchResult &Result) { if (const auto *FD = Result.Nodes.getNodeAs("fn")) { DiagnosticBuilder DB = diag(FD->getLocation(), Message) << "function" << FD; -SourceLocation FixLoc = FD->getTypeSpecStartLoc(); +const SourceLocation FixLoc = getQualifiedTypeStartLoc( +FD->getTypeSpecStartLoc(), *Result.SourceManager, *Result.Context); if (FixLoc.isInvalid() || FixLoc.isMacroID()) return; if (FixMode == FixModeKind::UseStatic) @@ -128,7 +157,8 @@ void UseInternalLinkageCheck::check(const MatchFinder::MatchResult &Result) { return; DiagnosticBuilder DB = diag(VD->getLocation(), Message) << "variable" << VD; -SourceLocation FixLoc = VD->getTypeSpecStartLoc(); +const SourceLocation FixLoc = getQualifiedTypeStartLoc( +VD->getTypeSpecStartLoc(), *Result.SourceManager, *Result.Context); if (FixLoc.isInvalid() || FixLoc.isMacroID()) return; if (FixMode == FixModeKind::UseStatic) diff --git a/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp b/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp index df2b0bef576ca3..92c3e0ed7894e1 100644 --- a/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp +++ b/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp @@ -24,13 +24,15 @@ getPreviousTokenAndStart(SourceLocation Location, const SourceManager &SM, if (Location.isInvalid()) return {Token, Location}; - auto StartOfFile = SM.getLocForStartOfFile(SM.getFileID(Location)); + const auto StartOfFile = SM.getLocForStartOfFile(SM.getFileID(Location)); while (Location != StartOfFile) { Location = Lexer::GetBeginningOfToken(Location, SM, LangOpts); if (!Lexer::getRawToken(Location, Token, SM, LangOpts) && (!SkipComments || !Token.is(tok::comment))) { break; } +if (Location == StartOfFile) + return {Token, Location}; Location = Location.getLocWithOffset(-1); } return {Token, Location}; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 8d0c093b312dd5..7cbcc23f28efaf 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -128,6 +128,10 @@ Changes in existing checks ` check to avoid false positive for C++23 deducing this. +- Improved :doc
[clang-tools-extra] [clang-tidy] loop convert can handle lambda init capture (PR #109159)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/109159 >From 4fc1d24c4ff22a8da22454aebe7053ea76419767 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Wed, 18 Sep 2024 23:26:02 +0800 Subject: [PATCH] [clang-tidy] loop convert can handle lambda init capture Fixes: #109083 --- .../clang-tidy/modernize/LoopConvertUtils.cpp | 25 ++--- .../clang-tidy/modernize/LoopConvertUtils.h | 2 ++ clang-tools-extra/docs/ReleaseNotes.rst | 4 +++ .../checkers/modernize/loop-convert-basic.cpp | 27 +++ 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp index c0bf4903ec3911..90c16bfddd84f8 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp @@ -777,7 +777,7 @@ bool ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C, Expr *Init) { if (C->capturesVariable()) { -const ValueDecl *VDecl = C->getCapturedVar(); +ValueDecl *VDecl = C->getCapturedVar(); if (areSameVariable(IndexVar, VDecl)) { // FIXME: if the index is captured, it will count as an usage and the // alias (if any) won't work, because it is only used in case of having @@ -787,6 +787,8 @@ bool ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE, : Usage::UK_CaptureByRef, C->getLocation())); } +if (VDecl->isInitCapture()) + TraverseStmtImpl(cast(VDecl)->getInit()); } return VisitorBase::TraverseLambdaCapture(LE, C, Init); } @@ -816,6 +818,17 @@ bool ForLoopIndexUseVisitor::VisitDeclStmt(DeclStmt *S) { return true; } +bool ForLoopIndexUseVisitor::TraverseStmtImpl(Stmt *S) { + // All this pointer swapping is a mechanism for tracking immediate parentage + // of Stmts. + const Stmt *OldNextParent = NextStmtParent; + CurrStmtParent = NextStmtParent; + NextStmtParent = S; + bool Result = VisitorBase::TraverseStmt(S); + NextStmtParent = OldNextParent; + return Result; +} + bool ForLoopIndexUseVisitor::TraverseStmt(Stmt *S) { // If this is an initialization expression for a lambda capture, prune the // traversal so that we don't end up diagnosing the contained DeclRefExpr as @@ -828,15 +841,7 @@ bool ForLoopIndexUseVisitor::TraverseStmt(Stmt *S) { return true; } } - - // All this pointer swapping is a mechanism for tracking immediate parentage - // of Stmts. - const Stmt *OldNextParent = NextStmtParent; - CurrStmtParent = NextStmtParent; - NextStmtParent = S; - bool Result = VisitorBase::TraverseStmt(S); - NextStmtParent = OldNextParent; - return Result; + return TraverseStmtImpl(S); } std::string VariableNamer::createIndexName() { diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h index cfceb3b586842d..ca9c1855038b53 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h @@ -354,6 +354,8 @@ class ForLoopIndexUseVisitor bool VisitDeclStmt(DeclStmt *S); bool TraverseStmt(Stmt *S); + bool TraverseStmtImpl(Stmt *S); + /// Add an expression to the list of expressions on which the container /// expression depends. void addComponent(const Expr *E); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index d284bb62f7c7f4..2aa2fd961e721f 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -139,6 +139,10 @@ Changes in existing checks as a replacement for parameters of incomplete C array type in C++20 and ``std::array`` or ``std::vector`` before C++20. +- Improved :doc:`modernize-loop-convert + ` check to fix false positive when + using loop variable in initializer of lambda capture. + - Improved :doc:`modernize-use-std-format ` check to support replacing member function calls too. diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp index 695925a5d877c9..608e580591205c 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp @@ -980,3 +980,30 @@ namespace PR78381 { } } } + +namespace GH109083 { +void test() { + const int N = 6; + int Arr[N] = {1, 2, 3, 4, 5, 6}; + + for (int I = 0; I < N; ++I) { +auto V = [T = Arr[I]]() {}; + } + // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert] + // CH
[clang] [lld] [llvm] Reapply "Deprecate the `-fbasic-block-sections=labels` option." (PR #110039)
https://github.com/MaskRay approved this pull request. 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] [llvm] [AMDGPU] Change CF intrinsics lowering to reconverge on predecessors (PR #108596)
https://github.com/ruiling commented: With one trick mentioned inline, we can further reduce one instruction. In most cases, we would have to introduce one scalar instruction in if-block and one salu in flow-block compared with existing solution. Block prologue is unclear concept and not well implemented. And we don't know if there are any gaps in LLVM core framework to make prologue work correctly. We first introduced block prologue to get the insertion point past the `s_or_bnn exec` for valu instructions. For salu, we still allow them being inserted into the prologue because the `s_or_bnn exec` needs an input sgpr. for threaded-vgpr, we should always put them after prologue. But as we may also reload sgpr from wwm-vgpr, I think we also should put wwm-vgpr reload in block prologue. Another issue with the implementation is we should only count the instructions before the `s_or_bnn exec` as prologue. Like in the case below, the last prologue instruction should be the `S_OR_B64 exec`. >$exec = S_OR_B64 $exec, killed renamable $sgpr48_sgpr49, implicit-def $scc %129034:vgpr_32 = SI_SPILL_V32_RESTORE %stack.265, $sgpr32, 0, implicit $exec %129055:vgpr_32 = SI_SPILL_V32_RESTORE %stack.266, $sgpr32, 0, implicit $exec %129083:vgpr_32 = SI_SPILL_V32_RESTORE %stack.267, $sgpr32, 0, implicit $exec %129635:vgpr_32 = SI_SPILL_V32_RESTORE %stack.282, $sgpr32, 0, implicit $exec Although tuning the `isSpill()` check help for this case, we still possibly have other issues related to this. I think it would better we fix this, but I am not sure it can be easily done. Meanwhile I think it would definitely be helpful to figure out whether LiveRangeSplit can work with block prologue properly at least for the known cases. https://github.com/llvm/llvm-project/pull/108596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Change CF intrinsics lowering to reconverge on predecessors (PR #108596)
@@ -1391,24 +1419,28 @@ define amdgpu_ps float @test_control_flow_0(<8 x i32> inreg %rsrc, <4 x i32> inr ; GFX10-W32: ; %bb.0: ; %main_body ; GFX10-W32-NEXT:s_mov_b32 s12, exec_lo ; GFX10-W32-NEXT:s_wqm_b32 exec_lo, exec_lo -; GFX10-W32-NEXT:s_mov_b32 s13, exec_lo -; GFX10-W32-NEXT:v_cmpx_ne_u32_e32 0, v1 -; GFX10-W32-NEXT:s_xor_b32 s13, exec_lo, s13 -; GFX10-W32-NEXT:s_cbranch_execz .LBB27_2 +; GFX10-W32-NEXT:v_cmp_ne_u32_e32 vcc_lo, 0, v1 +; GFX10-W32-NEXT:s_xor_b32 s14, vcc_lo, exec_lo +; GFX10-W32-NEXT:s_cmp_lg_u32 vcc_lo, 0 +; GFX10-W32-NEXT:s_cmov_b32 exec_lo, vcc_lo +; GFX10-W32-NEXT:s_cbranch_scc0 .LBB27_2 ; GFX10-W32-NEXT: ; %bb.1: ; %ELSE -; GFX10-W32-NEXT:s_and_saveexec_b32 s14, s12 +; GFX10-W32-NEXT:s_and_saveexec_b32 s13, s12 ; GFX10-W32-NEXT:buffer_store_dword v2, v0, s[0:3], 0 idxen ; GFX10-W32-NEXT:; implicit-def: $vgpr0 -; GFX10-W32-NEXT:s_mov_b32 exec_lo, s14 +; GFX10-W32-NEXT:s_mov_b32 exec_lo, s13 +; GFX10-W32-NEXT:s_or_b32 exec_lo, exec_lo, s14 ; GFX10-W32-NEXT: .LBB27_2: ; %Flow -; GFX10-W32-NEXT:s_andn2_saveexec_b32 s13, s13 -; GFX10-W32-NEXT:s_cbranch_execz .LBB27_4 +; GFX10-W32-NEXT:s_xor_b32 s13, s14, exec_lo +; GFX10-W32-NEXT:s_cmp_lg_u32 s14, 0 +; GFX10-W32-NEXT:s_cmov_b32 exec_lo, s14 ruiling wrote: We are safe to use (no kill in the else region): s_and_saveexec s13, s14 s_cselect s14, s13ruil s_cbranch_scc0 https://github.com/llvm/llvm-project/pull/108596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Change CF intrinsics lowering to reconverge on predecessors (PR #108596)
@@ -446,8 +474,10 @@ define amdgpu_kernel void @add_i32_uniform(ptr addrspace(1) %out, ptr addrspace( ; GFX11W64-NEXT:; implicit-def: $vgpr1 ; GFX11W64-NEXT:s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1) ; GFX11W64-NEXT:v_mbcnt_hi_u32_b32 v0, s5, v0 -; GFX11W64-NEXT:v_cmpx_eq_u32_e32 0, v0 -; GFX11W64-NEXT:s_cbranch_execz .LBB1_2 +; GFX11W64-NEXT:v_cmp_eq_u32_e32 vcc, 0, v0 +; GFX11W64-NEXT:s_cmp_lg_u64 vcc, 0 +; GFX11W64-NEXT:s_cmov_b64 exec, vcc +; GFX11W64-NEXT:s_cbranch_scc0 .LBB1_2 ruiling wrote: We can merge the s_cmp_lg for updating SCC and the exec save into one s_and_saveexec ``` s_and_saveexec_b64 s[0:1], vcc s_cselect_b64 exec, vcc, s[0:1] s_cbranch_scc0 .LBB1_2 ``` so we don't need the separate `s_mov_b64 s[0:1], exec` at line 472 to save the exec. https://github.com/llvm/llvm-project/pull/108596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Change CF intrinsics lowering to reconverge on predecessors (PR #108596)
https://github.com/ruiling edited https://github.com/llvm/llvm-project/pull/108596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Change CF intrinsics lowering to reconverge on predecessors (PR #108596)
@@ -936,19 +978,20 @@ define amdgpu_kernel void @add_i32_varying_vdata(ptr addrspace(1) %out, ptr addr ; GFX12W32-NEXT:s_cbranch_scc1 .LBB2_1 ; GFX12W32-NEXT: ; %bb.2: ; %ComputeEnd ; GFX12W32-NEXT:v_mbcnt_lo_u32_b32 v1, exec_lo, 0 -; GFX12W32-NEXT:s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1) +; GFX12W32-NEXT:s_delay_alu instid0(VALU_DEP_1) ; GFX12W32-NEXT:v_cmp_eq_u32_e32 vcc_lo, 0, v1 ; GFX12W32-NEXT:; implicit-def: $vgpr1 -; GFX12W32-NEXT:s_and_saveexec_b32 s1, vcc_lo -; GFX12W32-NEXT:s_xor_b32 s1, exec_lo, s1 -; GFX12W32-NEXT:s_cbranch_execz .LBB2_4 +; GFX12W32-NEXT:s_xor_b32 s1, vcc_lo, exec_lo +; GFX12W32-NEXT:s_cmp_lg_u32 vcc_lo, 0 +; GFX12W32-NEXT:s_cmov_b32 exec_lo, vcc_lo +; GFX12W32-NEXT:s_cbranch_scc0 .LBB2_4 ruiling wrote: This can also be simplified into: s_and_saveexec_b32 s1, vcc_lo s_cselect_b32 exec_lo, vcc_lo, s1 s_cbranch_scc0 .LBB2_4 https://github.com/llvm/llvm-project/pull/108596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][Driver][Offload] Support -Xoffload-linker argument in Flang (PR #109907)
https://github.com/agozillon updated https://github.com/llvm/llvm-project/pull/109907 >From 6e29de9836f49e49558e7810ec0a8084017c22b4 Mon Sep 17 00:00:00 2001 From: agozillon Date: Wed, 25 Sep 2024 00:18:26 -0500 Subject: [PATCH 1/3] [Flang][Driver][Offload] Support -Xoffload-linker argument in Flang The -Xoffload-linker command allows forwarding of linker commands to the clang-linker-wrapper used for linking offload libraries into the resulting offload binaries amongst other tasks. This is a rather useful command to have to support the offloading programming models flang-new currently aims to support (OpenMP/OpenACC). Currently this flag is utilised in the check-offload tests after a recent addition and is used in conjunction with the Fortran OpenMP test suite there, which fails at the moment due to flang-new not recognizing the command, this fixes the issue. The alternative to this would of course be to setup the test config to avoid using this flag with Fortran, but I believe adding support of the flag to flang-new has more merit as having the same compatability/communication capabilities as Clang to the clang-linker-wrapper is important as it's a critical component of the offload pipeline, and the command will likely see more use in the near future. --- clang/include/clang/Driver/Options.td | 1 + flang/test/Driver/xoffload-linker.f90 | 7 +++ 2 files changed, 8 insertions(+) create mode 100644 flang/test/Driver/xoffload-linker.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 23bd686a85f526..da24bc3541abda 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1055,6 +1055,7 @@ def Xlinker : Separate<["-"], "Xlinker">, Flags<[LinkerInput, RenderAsInput]>, HelpText<"Pass to the linker">, MetaVarName<"">, Group; def Xoffload_linker : JoinedAndSeparate<["-"], "Xoffload-linker">, + Visibility<[ClangOption, CLOption, FlangOption, DXCOption]>, HelpText<"Pass to the offload linkers or the ones identified by -">, MetaVarName<" ">, Group; def Xpreprocessor : Separate<["-"], "Xpreprocessor">, Group, diff --git a/flang/test/Driver/xoffload-linker.f90 b/flang/test/Driver/xoffload-linker.f90 new file mode 100644 index 00..886e649c1e8760 --- /dev/null +++ b/flang/test/Driver/xoffload-linker.f90 @@ -0,0 +1,7 @@ +! Test the -Xoffload-linker flag that forwards link commands to the clang-linker-wrapper used +! to help link offloading device libraries + +! RUN: %flang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx90a \ +! RUN: -Xoffload-linker a %s 2>&1 | FileCheck %s --check-prefix=CHECK-XLINKER + +! CHECK-XLINKER: -device-linker=a{{.*}}-- >From 7b18b3a2cd1ff2e330ca577c1ce46aa31ddbab3a Mon Sep 17 00:00:00 2001 From: agozillon Date: Wed, 25 Sep 2024 11:51:05 -0500 Subject: [PATCH 2/3] [Flang][Driver][Offload] Add new test case and attempt to appease the CI gods --- flang/test/Driver/xoffload-linker.f90 | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/flang/test/Driver/xoffload-linker.f90 b/flang/test/Driver/xoffload-linker.f90 index 886e649c1e8760..aa7d3e78c66ced 100644 --- a/flang/test/Driver/xoffload-linker.f90 +++ b/flang/test/Driver/xoffload-linker.f90 @@ -4,4 +4,10 @@ ! RUN: %flang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx90a \ ! RUN: -Xoffload-linker a %s 2>&1 | FileCheck %s --check-prefix=CHECK-XLINKER -! CHECK-XLINKER: -device-linker=a{{.*}}-- +! CHECK-XLINKER: {{.*}}-device-linker=a{{.*}} + +! RUN: %flang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx90a \ +! RUN: -Xoffload-linker a -Xoffload-linker-amdgcn-amd-amdhsa b \ +! RUN: %s 2>&1 | FileCheck %s --check-prefix=CHECK-XLINKER-AMDGCN + +! CHECK-XLINKER-AMDGCN: {{.*}}-device-linker=a{{.*}}-device-linker=amdgcn-amd-amdhsa=b{{.*}} >From 8b10990b5c5a5b301e8773ce031c63a454ae6fb5 Mon Sep 17 00:00:00 2001 From: agozillon Date: Wed, 25 Sep 2024 23:59:19 -0500 Subject: [PATCH 3/3] Attempt at fixing CI error #2 --- flang/test/Driver/xoffload-linker.f90 | 13 ++--- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/flang/test/Driver/xoffload-linker.f90 b/flang/test/Driver/xoffload-linker.f90 index aa7d3e78c66ced..563914ae5e904d 100644 --- a/flang/test/Driver/xoffload-linker.f90 +++ b/flang/test/Driver/xoffload-linker.f90 @@ -1,13 +1,12 @@ ! Test the -Xoffload-linker flag that forwards link commands to the clang-linker-wrapper used ! to help link offloading device libraries -! RUN: %flang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx90a \ -! RUN: -Xoffload-linker a %s 2>&1 | FileCheck %s --check-prefix=CHECK-XLINKER +! RUN: %flang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx90a -Xoffload-linker a %s 2>&1 | FileCheck %s --check-prefix=CHECK-XLINKER -! CHECK-XLINKER: {{.*}}-device-linker=a{{.*}} +! CHECK-XLINKER:
[clang] [flang] [Flang][Driver][Offload] Support -Xoffload-linker argument in Flang (PR #109907)
https://github.com/agozillon updated https://github.com/llvm/llvm-project/pull/109907 >From 6e29de9836f49e49558e7810ec0a8084017c22b4 Mon Sep 17 00:00:00 2001 From: agozillon Date: Wed, 25 Sep 2024 00:18:26 -0500 Subject: [PATCH 1/4] [Flang][Driver][Offload] Support -Xoffload-linker argument in Flang The -Xoffload-linker command allows forwarding of linker commands to the clang-linker-wrapper used for linking offload libraries into the resulting offload binaries amongst other tasks. This is a rather useful command to have to support the offloading programming models flang-new currently aims to support (OpenMP/OpenACC). Currently this flag is utilised in the check-offload tests after a recent addition and is used in conjunction with the Fortran OpenMP test suite there, which fails at the moment due to flang-new not recognizing the command, this fixes the issue. The alternative to this would of course be to setup the test config to avoid using this flag with Fortran, but I believe adding support of the flag to flang-new has more merit as having the same compatability/communication capabilities as Clang to the clang-linker-wrapper is important as it's a critical component of the offload pipeline, and the command will likely see more use in the near future. --- clang/include/clang/Driver/Options.td | 1 + flang/test/Driver/xoffload-linker.f90 | 7 +++ 2 files changed, 8 insertions(+) create mode 100644 flang/test/Driver/xoffload-linker.f90 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 23bd686a85f526..da24bc3541abda 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1055,6 +1055,7 @@ def Xlinker : Separate<["-"], "Xlinker">, Flags<[LinkerInput, RenderAsInput]>, HelpText<"Pass to the linker">, MetaVarName<"">, Group; def Xoffload_linker : JoinedAndSeparate<["-"], "Xoffload-linker">, + Visibility<[ClangOption, CLOption, FlangOption, DXCOption]>, HelpText<"Pass to the offload linkers or the ones identified by -">, MetaVarName<" ">, Group; def Xpreprocessor : Separate<["-"], "Xpreprocessor">, Group, diff --git a/flang/test/Driver/xoffload-linker.f90 b/flang/test/Driver/xoffload-linker.f90 new file mode 100644 index 00..886e649c1e8760 --- /dev/null +++ b/flang/test/Driver/xoffload-linker.f90 @@ -0,0 +1,7 @@ +! Test the -Xoffload-linker flag that forwards link commands to the clang-linker-wrapper used +! to help link offloading device libraries + +! RUN: %flang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx90a \ +! RUN: -Xoffload-linker a %s 2>&1 | FileCheck %s --check-prefix=CHECK-XLINKER + +! CHECK-XLINKER: -device-linker=a{{.*}}-- >From 7b18b3a2cd1ff2e330ca577c1ce46aa31ddbab3a Mon Sep 17 00:00:00 2001 From: agozillon Date: Wed, 25 Sep 2024 11:51:05 -0500 Subject: [PATCH 2/4] [Flang][Driver][Offload] Add new test case and attempt to appease the CI gods --- flang/test/Driver/xoffload-linker.f90 | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/flang/test/Driver/xoffload-linker.f90 b/flang/test/Driver/xoffload-linker.f90 index 886e649c1e8760..aa7d3e78c66ced 100644 --- a/flang/test/Driver/xoffload-linker.f90 +++ b/flang/test/Driver/xoffload-linker.f90 @@ -4,4 +4,10 @@ ! RUN: %flang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx90a \ ! RUN: -Xoffload-linker a %s 2>&1 | FileCheck %s --check-prefix=CHECK-XLINKER -! CHECK-XLINKER: -device-linker=a{{.*}}-- +! CHECK-XLINKER: {{.*}}-device-linker=a{{.*}} + +! RUN: %flang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx90a \ +! RUN: -Xoffload-linker a -Xoffload-linker-amdgcn-amd-amdhsa b \ +! RUN: %s 2>&1 | FileCheck %s --check-prefix=CHECK-XLINKER-AMDGCN + +! CHECK-XLINKER-AMDGCN: {{.*}}-device-linker=a{{.*}}-device-linker=amdgcn-amd-amdhsa=b{{.*}} >From 8b10990b5c5a5b301e8773ce031c63a454ae6fb5 Mon Sep 17 00:00:00 2001 From: agozillon Date: Wed, 25 Sep 2024 23:59:19 -0500 Subject: [PATCH 3/4] Attempt at fixing CI error #2 --- flang/test/Driver/xoffload-linker.f90 | 13 ++--- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/flang/test/Driver/xoffload-linker.f90 b/flang/test/Driver/xoffload-linker.f90 index aa7d3e78c66ced..563914ae5e904d 100644 --- a/flang/test/Driver/xoffload-linker.f90 +++ b/flang/test/Driver/xoffload-linker.f90 @@ -1,13 +1,12 @@ ! Test the -Xoffload-linker flag that forwards link commands to the clang-linker-wrapper used ! to help link offloading device libraries -! RUN: %flang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx90a \ -! RUN: -Xoffload-linker a %s 2>&1 | FileCheck %s --check-prefix=CHECK-XLINKER +! RUN: %flang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx90a -Xoffload-linker a %s 2>&1 | FileCheck %s --check-prefix=CHECK-XLINKER -! CHECK-XLINKER: {{.*}}-device-linker=a{{.*}} +! CHECK-XLINKER:
[clang] [ItaniumMangle] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)
@@ -7326,11 +7326,13 @@ void ItaniumMangleContextImpl::mangleCXXCtorVTable(const CXXRecordDecl *RD, raw_ostream &Out) { // ::= TC _ CXXNameMangler Mangler(*this, Out); + QualType RDType = getASTContext().getRecordType(RD); + QualType TypeType = getASTContext().getRecordType(Type); Mangler.getStream() << "_ZTC"; - Mangler.mangleNameOrStandardSubstitution(RD); + Mangler.mangleType(RDType); mizvekov wrote: Yes, although as I said before, there should be no observable change for these other users, as we don't perform other manglings either before or after calling `mangleNameOrStandardSubstitution`. I would prefer the ergonomics of a function which takes a CXXRecordDecl. MangleType is also more complex and will perform a bunch of checks which are not necessary if you only would ever have a RecordType, so there is also some aspect of micro-optimization and ease of debugging in having a specialized function. 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] 7b7747d - Reapply "Deprecate the `-fbasic-block-sections=labels` option." (#110039)
Author: Rahman Lavaee Date: 2024-09-25T22:03:10-07:00 New Revision: 7b7747dc1d3da1a829503ea9505b4cecce4f5bda URL: https://github.com/llvm/llvm-project/commit/7b7747dc1d3da1a829503ea9505b4cecce4f5bda DIFF: https://github.com/llvm/llvm-project/commit/7b7747dc1d3da1a829503ea9505b4cecce4f5bda.diff LOG: Reapply "Deprecate the `-fbasic-block-sections=labels` option." (#110039) This reapplies commit 1911a50fae8a441b445eb835b98950710d28fc88 with a minor fix in lld/ELF/LTO.cpp which sets Options.BBAddrMap when `--lto-basic-block-sections=labels` is passed. Added: llvm/test/CodeGen/X86/basic-block-address-map-empty-block.ll llvm/test/CodeGen/X86/basic-block-address-map-empty-function.ll llvm/test/CodeGen/X86/basic-block-address-map-mir-parse.mir llvm/test/CodeGen/X86/basic-block-address-map-pgo-features.ll Modified: clang/docs/UsersManual.rst clang/include/clang/Basic/CodeGenOptions.h clang/include/clang/Driver/Options.td clang/lib/CodeGen/BackendUtil.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/fbasic-block-sections.c lld/ELF/LTO.cpp llvm/docs/CommandGuide/llvm-objdump.rst llvm/docs/Extensions.rst llvm/include/llvm/CodeGen/MachineFunction.h llvm/include/llvm/Target/TargetOptions.h llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp llvm/lib/CodeGen/BasicBlockSections.cpp llvm/lib/CodeGen/CommandFlags.cpp llvm/lib/CodeGen/MIRParser/MIParser.cpp llvm/lib/CodeGen/MIRParser/MIRParser.cpp llvm/lib/CodeGen/MachineFunction.cpp llvm/test/CodeGen/X86/basic-block-address-map-function-sections.ll llvm/test/CodeGen/X86/basic-block-address-map.ll llvm/test/CodeGen/X86/basic-block-sections-mir-print.ll Removed: llvm/test/CodeGen/X86/basic-block-labels-mir-parse.mir llvm/test/CodeGen/X86/basic-block-sections-labels-empty-block.ll llvm/test/CodeGen/X86/basic-block-sections-labels-empty-function.ll llvm/test/CodeGen/X86/basic-block-sections-labels-pgo-features.ll diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index 57d78f867bab6e..4f03388bc87bd0 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -2369,14 +2369,16 @@ are listed below. $ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o -.. option:: -fbasic-block-sections=[labels, all, list=, none] +.. option:: -f[no]-basic-block-address-map: + Emits a ``SHT_LLVM_BB_ADDR_MAP`` section which includes address offsets for each + basic block in the program, relative to the parent function address. + + +.. option:: -fbasic-block-sections=[all, list=, none] Controls how Clang emits text sections for basic blocks. With values ``all`` and ``list=``, each basic block or a subset of basic blocks can be placed - in its own unique section. With the "labels" value, normal text sections are - emitted, but a ``.bb_addr_map`` section is emitted which includes address - offsets for each basic block in the program, relative to the parent function - address. + in its own unique section. With the ``list=`` option, a file containing the subset of basic blocks that need to placed in unique sections can be specified. The format of the diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index f2a707a8ba8d76..814d4d4c99e575 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -107,18 +107,13 @@ class CodeGenOptions : public CodeGenOptionsBase { // This field stores one of the allowed values for the option // -fbasic-block-sections=. The allowed values with this option are: - // {"labels", "all", "list=", "none"}. + // {"all", "list=", "none"}. // - // "labels": Only generate basic block symbols (labels) for all basic - //blocks, do not generate unique sections for basic blocks. - //Use the machine basic block id in the symbol name to - //associate profile info from virtual address to machine - //basic block. // "all" :Generate basic block sections for all basic blocks. // "list=": Generate basic block sections for a subset of basic blocks. //The functions and the machine basic block ids are specified //in the file. - // "none":Disable sections/labels for basic blocks. + // "none":Disable sections for basic blocks. std::string BBSections; // If set, override the default value of MCAsmInfo::BinutilsVersion. If diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 23bd686a85f526..c22b07e9f8a6cb 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4244,8 +4244,8 @@ defm basic_bloc
[clang] [lld] [llvm] Reapply "Deprecate the `-fbasic-block-sections=labels` option." (PR #110039)
https://github.com/rlavaee closed 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] [llvm] Adding splitdouble HLSL function (PR #109331)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/109331 >From 50d21754119ac10c2ee2376ed8f79d12f73cd137 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Thu, 19 Sep 2024 00:13:51 + Subject: [PATCH 1/5] Codegen builtin --- clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 38 clang/lib/CodeGen/CGCall.cpp | 5 ++ clang/lib/CodeGen/CGExpr.cpp | 15 - clang/lib/CodeGen/CodeGenFunction.h | 10 +++- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 20 +++ clang/lib/Sema/SemaHLSL.cpp | 58 --- .../builtins/asuint-splitdouble.hlsl | 10 llvm/include/llvm/IR/IntrinsicsDirectX.td | 5 ++ llvm/lib/Target/DirectX/DXIL.td | 1 + .../Target/DirectX/DXILIntrinsicExpansion.cpp | 13 + 11 files changed, 167 insertions(+), 14 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..b38957f6e3f15d 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4788,6 +4788,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLAsUintSplitDouble: LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_asuint_splitdouble"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + // Builtins for XRay. def XRayCustomEvent : Builtin { let Spellings = ["__xray_customevent"]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 249aead33ad73d..f7695b8693f3dc 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18843,6 +18843,44 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: { retType, CGM.getHLSLRuntime().getSignIntrinsic(), ArrayRef{Op0}, nullptr, "hlsl.sign"); } + // This should only be called when targeting DXIL + case Builtin::BI__builtin_hlsl_asuint_splitdouble: { + +assert((E->getArg(0)->getType()->hasFloatingRepresentation() && +E->getArg(1)->getType()->hasUnsignedIntegerRepresentation() && +E->getArg(2)->getType()->hasUnsignedIntegerRepresentation()) && + "asuint operands types mismatch"); + +Value *Op0 = EmitScalarExpr(E->getArg(0)); +const HLSLOutArgExpr *OutArg1 = dyn_cast(E->getArg(1)); +const HLSLOutArgExpr *OutArg2 = dyn_cast(E->getArg(2)); + +CallArgList Args; +LValue Op1TmpLValue = EmitHLSLOutArgExpr(OutArg1, Args, OutArg1->getType()); +LValue Op2TmpLValue = EmitHLSLOutArgExpr(OutArg2, Args, OutArg2->getType()); + +llvm::Type *retType = llvm::StructType::get(Int32Ty, Int32Ty); +if (Op0->getType()->isVectorTy()) { + auto *XVecTy = E->getArg(0)->getType()->getAs(); + + llvm::VectorType *i32VecTy = llvm::VectorType::get( + Int32Ty, ElementCount::getFixed(XVecTy->getNumElements())); + + retType = llvm::StructType::get(i32VecTy, i32VecTy); +} + +CallInst *CI = +Builder.CreateIntrinsic(retType, llvm::Intrinsic::dx_asuint_splitdouble, +{Op0}, nullptr, "hlsl.asuint"); + +Value *arg0 = Builder.CreateExtractValue(CI, 0); +Value *arg1 = Builder.CreateExtractValue(CI, 1); + +Builder.CreateStore(arg0, Op1TmpLValue.getAddress()); +auto *s = Builder.CreateStore(arg1, Op2TmpLValue.getAddress()); +EmitWritebacks(*this, Args); +return s; + } } return nullptr; } diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 4ae981e4013e9c..096bbafa4cc694 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -4681,6 +4681,11 @@ void CallArg::copyInto(CodeGenFunction &CGF, Address Addr) const { IsUsed = true; } +void CodeGenFunction::EmitWritebacks(CodeGenFunction &CGF, + const CallArgList &args) { + emitWritebacks(CGF, args); +} + void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E, QualType type) { DisableDebugLocationUpdates Dis(*this, E); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 9166db4c74128c..1c299c4a932ca0 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -19,6 +19,7 @@ #include "CGObjCRuntime.h" #include "CGOpenMPRuntime.h" #include "CGRecordLayout.h" +#include "CGValue.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "ConstantEmitter.h" @@ -28,6 +29,7 @@ #include "clang/AST/DeclObjC.h" #include "clang/AST/NSAPI.h" #include "clang/AST/StmtVisitor.h" +#include "clang/AST/Type.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/CodeGenOptions.h" #include "clang/Basic/SourceManager.h" @@ -5458,9 +5460,8 @@ LValue CodeGenFunction::EmitOpaqueValueLValu
[clang] [llvm] Adding splitdouble HLSL function (PR #109331)
https://github.com/joaosaffran edited 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-tools-extra] [clangd] [C++20] [Modules] Support code complete for C++20 modules (PR #110083)
llvmbot wrote: @llvm/pr-subscribers-clang-modules Author: Chuanqi Xu (ChuanqiXu9) Changes According to https://github.com/ChuanqiXu9/clangd-for-modules/issues/9, I surprisingly found the support for C++20 modules doesn't support code completion well. After debugging, I found there are problems: (1) We forgot to call `adjustHeaderSearchOptions` in code complete. This may be an easy oversight. (2) In `CodeCompleteOptions::getClangCompleteOpts`, we may set `LoadExternal` as false when index is available. But we have support modules with index. So it is conflicting. Given modules are opt in now, I think it makes sense to to set LoadExternal as true when modules are enabled. This is a small fix and I wish it can land faster. --- Full diff: https://github.com/llvm/llvm-project/pull/110083.diff 3 Files Affected: - (modified) clang-tools-extra/clangd/CodeComplete.cpp (+13-5) - (modified) clang-tools-extra/clangd/CodeComplete.h (+1-1) - (modified) clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp (+40) ``diff diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index 89eee392837af4..f6f0d9a1be3c37 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -892,8 +892,9 @@ static bool isExcludedMember(const NamedDecl &D) { // within the callback. struct CompletionRecorder : public CodeCompleteConsumer { CompletionRecorder(const CodeCompleteOptions &Opts, + bool ForceLoadExternal, llvm::unique_function ResultsCallback) - : CodeCompleteConsumer(Opts.getClangCompleteOpts()), + : CodeCompleteConsumer(Opts.getClangCompleteOpts(ForceLoadExternal)), CCContext(CodeCompletionContext::CCC_Other), Opts(Opts), CCAllocator(std::make_shared()), CCTUInfo(CCAllocator), ResultsCallback(std::move(ResultsCallback)) { @@ -1409,6 +1410,9 @@ bool semaCodeComplete(std::unique_ptr Consumer, Clang->getPreprocessorOpts().SingleFileParseMode = CompletingInPreamble; Clang->setCodeCompletionConsumer(Consumer.release()); + if (Input.Preamble.RequiredModules) + Input.Preamble.RequiredModules->adjustHeaderSearchOptions(Clang->getHeaderSearchOpts()); + SyntaxOnlyAction Action; if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) { log("BeginSourceFile() failed when running codeComplete for {0}", @@ -1629,11 +1633,15 @@ class CodeCompleteFlow { SpecFuzzyFind->Result = startAsyncFuzzyFind(*Opts.Index, *SpecReq); } +// FIXME: If we're using C++20 modules, force the lookup process to load external decls, +// since currently the index doesn't support C++20 modules. +bool ForceLoadExternal = (bool)SemaCCInput.Preamble.RequiredModules; + // We run Sema code completion first. It builds an AST and calculates: // - completion results based on the AST. // - partial identifier and context. We need these for the index query. CodeCompleteResult Output; -auto RecorderOwner = std::make_unique(Opts, [&]() { +auto RecorderOwner = std::make_unique(Opts, ForceLoadExternal, [&]() { assert(Recorder && "Recorder is not set"); CCContextKind = Recorder->CCContext.getKind(); IsUsingDeclaration = Recorder->CCContext.isUsingDeclaration(); @@ -1691,7 +1699,7 @@ class CodeCompleteFlow { Recorder = RecorderOwner.get(); -semaCodeComplete(std::move(RecorderOwner), Opts.getClangCompleteOpts(), +semaCodeComplete(std::move(RecorderOwner), Opts.getClangCompleteOpts(ForceLoadExternal), SemaCCInput, &Includes); logResults(Output, Tracer); return Output; @@ -2108,7 +2116,7 @@ class CodeCompleteFlow { } // namespace -clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const { +clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts(bool ForceLoadExternal) const { clang::CodeCompleteOptions Result; Result.IncludeCodePatterns = EnableSnippets; Result.IncludeMacros = true; @@ -2122,7 +2130,7 @@ clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const { // When an is used, Sema is responsible for completing the main file, // the index can provide results from the preamble. // Tell Sema not to deserialize the preamble to look for results. - Result.LoadExternal = !Index; + Result.LoadExternal = ForceLoadExternal || !Index; Result.IncludeFixIts = IncludeFixIts; return Result; diff --git a/clang-tools-extra/clangd/CodeComplete.h b/clang-tools-extra/clangd/CodeComplete.h index a7c1ae95dcbf49..336e84f0a7724c 100644 --- a/clang-tools-extra/clangd/CodeComplete.h +++ b/clang-tools-extra/clangd/CodeComplete.h @@ -41,7 +41,7 @@ struct CodeCompletion; struct CodeCompleteOptions { /// Returns options that can be passed to clang's completion engine. - clang::CodeCompleteOptions getClangCompleteOpts() const; + clang::C
[clang-tools-extra] [clangd] [C++20] [Modules] Support code complete for C++20 modules (PR #110083)
https://github.com/ChuanqiXu9 created https://github.com/llvm/llvm-project/pull/110083 According to https://github.com/ChuanqiXu9/clangd-for-modules/issues/9, I surprisingly found the support for C++20 modules doesn't support code completion well. After debugging, I found there are problems: (1) We forgot to call `adjustHeaderSearchOptions` in code complete. This may be an easy oversight. (2) In `CodeCompleteOptions::getClangCompleteOpts`, we may set `LoadExternal` as false when index is available. But we have support modules with index. So it is conflicting. Given modules are opt in now, I think it makes sense to to set LoadExternal as true when modules are enabled. This is a small fix and I wish it can land faster. >From e35e600159c99736de7d2bc735c738002f592988 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Thu, 26 Sep 2024 13:43:51 +0800 Subject: [PATCH] [clangd] [C++20] [Modules] Support code complete for C++20 modules --- clang-tools-extra/clangd/CodeComplete.cpp | 18 ++--- clang-tools-extra/clangd/CodeComplete.h | 2 +- .../unittests/PrerequisiteModulesTest.cpp | 40 +++ 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index 89eee392837af4..f6f0d9a1be3c37 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -892,8 +892,9 @@ static bool isExcludedMember(const NamedDecl &D) { // within the callback. struct CompletionRecorder : public CodeCompleteConsumer { CompletionRecorder(const CodeCompleteOptions &Opts, + bool ForceLoadExternal, llvm::unique_function ResultsCallback) - : CodeCompleteConsumer(Opts.getClangCompleteOpts()), + : CodeCompleteConsumer(Opts.getClangCompleteOpts(ForceLoadExternal)), CCContext(CodeCompletionContext::CCC_Other), Opts(Opts), CCAllocator(std::make_shared()), CCTUInfo(CCAllocator), ResultsCallback(std::move(ResultsCallback)) { @@ -1409,6 +1410,9 @@ bool semaCodeComplete(std::unique_ptr Consumer, Clang->getPreprocessorOpts().SingleFileParseMode = CompletingInPreamble; Clang->setCodeCompletionConsumer(Consumer.release()); + if (Input.Preamble.RequiredModules) + Input.Preamble.RequiredModules->adjustHeaderSearchOptions(Clang->getHeaderSearchOpts()); + SyntaxOnlyAction Action; if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) { log("BeginSourceFile() failed when running codeComplete for {0}", @@ -1629,11 +1633,15 @@ class CodeCompleteFlow { SpecFuzzyFind->Result = startAsyncFuzzyFind(*Opts.Index, *SpecReq); } +// FIXME: If we're using C++20 modules, force the lookup process to load external decls, +// since currently the index doesn't support C++20 modules. +bool ForceLoadExternal = (bool)SemaCCInput.Preamble.RequiredModules; + // We run Sema code completion first. It builds an AST and calculates: // - completion results based on the AST. // - partial identifier and context. We need these for the index query. CodeCompleteResult Output; -auto RecorderOwner = std::make_unique(Opts, [&]() { +auto RecorderOwner = std::make_unique(Opts, ForceLoadExternal, [&]() { assert(Recorder && "Recorder is not set"); CCContextKind = Recorder->CCContext.getKind(); IsUsingDeclaration = Recorder->CCContext.isUsingDeclaration(); @@ -1691,7 +1699,7 @@ class CodeCompleteFlow { Recorder = RecorderOwner.get(); -semaCodeComplete(std::move(RecorderOwner), Opts.getClangCompleteOpts(), +semaCodeComplete(std::move(RecorderOwner), Opts.getClangCompleteOpts(ForceLoadExternal), SemaCCInput, &Includes); logResults(Output, Tracer); return Output; @@ -2108,7 +2116,7 @@ class CodeCompleteFlow { } // namespace -clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const { +clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts(bool ForceLoadExternal) const { clang::CodeCompleteOptions Result; Result.IncludeCodePatterns = EnableSnippets; Result.IncludeMacros = true; @@ -2122,7 +2130,7 @@ clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const { // When an is used, Sema is responsible for completing the main file, // the index can provide results from the preamble. // Tell Sema not to deserialize the preamble to look for results. - Result.LoadExternal = !Index; + Result.LoadExternal = ForceLoadExternal || !Index; Result.IncludeFixIts = IncludeFixIts; return Result; diff --git a/clang-tools-extra/clangd/CodeComplete.h b/clang-tools-extra/clangd/CodeComplete.h index a7c1ae95dcbf49..336e84f0a7724c 100644 --- a/clang-tools-extra/clangd/CodeComplete.h +++ b/clang-tools-extra/clangd/CodeComplete.h @@ -41,7 +41,7 @@ struct CodeCompletion; struct CodeCompleteOptions { /// Re
[clang-tools-extra] [clangd] [C++20] [Modules] Support code complete for C++20 modules (PR #110083)
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 2b0a708f41dd6291ee744704d43febc975e3d026 e35e600159c99736de7d2bc735c738002f592988 --extensions h,cpp -- clang-tools-extra/clangd/CodeComplete.cpp clang-tools-extra/clangd/CodeComplete.h clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp `` View the diff from clang-format here. ``diff diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index f6f0d9a1be..96851ff901 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -891,8 +891,7 @@ static bool isExcludedMember(const NamedDecl &D) { // Generally the fields and methods of this object should only be used from // within the callback. struct CompletionRecorder : public CodeCompleteConsumer { - CompletionRecorder(const CodeCompleteOptions &Opts, - bool ForceLoadExternal, + CompletionRecorder(const CodeCompleteOptions &Opts, bool ForceLoadExternal, llvm::unique_function ResultsCallback) : CodeCompleteConsumer(Opts.getClangCompleteOpts(ForceLoadExternal)), CCContext(CodeCompletionContext::CCC_Other), Opts(Opts), @@ -1411,7 +1410,8 @@ bool semaCodeComplete(std::unique_ptr Consumer, Clang->setCodeCompletionConsumer(Consumer.release()); if (Input.Preamble.RequiredModules) - Input.Preamble.RequiredModules->adjustHeaderSearchOptions(Clang->getHeaderSearchOpts()); +Input.Preamble.RequiredModules->adjustHeaderSearchOptions( +Clang->getHeaderSearchOpts()); SyntaxOnlyAction Action; if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) { @@ -1633,15 +1633,16 @@ public: SpecFuzzyFind->Result = startAsyncFuzzyFind(*Opts.Index, *SpecReq); } -// FIXME: If we're using C++20 modules, force the lookup process to load external decls, -// since currently the index doesn't support C++20 modules. +// FIXME: If we're using C++20 modules, force the lookup process to load +// external decls, since currently the index doesn't support C++20 modules. bool ForceLoadExternal = (bool)SemaCCInput.Preamble.RequiredModules; // We run Sema code completion first. It builds an AST and calculates: // - completion results based on the AST. // - partial identifier and context. We need these for the index query. CodeCompleteResult Output; -auto RecorderOwner = std::make_unique(Opts, ForceLoadExternal, [&]() { +auto RecorderOwner = std::make_unique< +CompletionRecorder>(Opts, ForceLoadExternal, [&]() { assert(Recorder && "Recorder is not set"); CCContextKind = Recorder->CCContext.getKind(); IsUsingDeclaration = Recorder->CCContext.isUsingDeclaration(); @@ -1699,8 +1700,9 @@ public: Recorder = RecorderOwner.get(); -semaCodeComplete(std::move(RecorderOwner), Opts.getClangCompleteOpts(ForceLoadExternal), - SemaCCInput, &Includes); +semaCodeComplete(std::move(RecorderOwner), + Opts.getClangCompleteOpts(ForceLoadExternal), SemaCCInput, + &Includes); logResults(Output, Tracer); return Output; } @@ -2116,7 +2118,8 @@ private: } // namespace -clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts(bool ForceLoadExternal) const { +clang::CodeCompleteOptions +CodeCompleteOptions::getClangCompleteOpts(bool ForceLoadExternal) const { clang::CodeCompleteOptions Result; Result.IncludeCodePatterns = EnableSnippets; Result.IncludeMacros = true; diff --git a/clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp b/clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp index f1cdf9e899..d7f26f1020 100644 --- a/clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp +++ b/clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp @@ -435,7 +435,7 @@ void func() { /*Callback=*/nullptr); EXPECT_TRUE(Preamble); EXPECT_TRUE(Preamble->RequiredModules); - + auto Result = codeComplete(getFullPath("Use.cpp"), Test.point(), Preamble.get(), Use, {}); EXPECT_FALSE(Result.Completions.empty()); `` https://github.com/llvm/llvm-project/pull/110083 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add explicit visibility symbol macros (PR #108276)
https://github.com/fsfod updated https://github.com/llvm/llvm-project/pull/108276 >From c842394a368fa51ddad78f9c0a7efe2026425b52 Mon Sep 17 00:00:00 2001 From: Thomas Fransham Date: Tue, 10 Sep 2024 02:22:18 +0100 Subject: [PATCH 1/6] [Clang] Add explicit visibility symbol macros and update CMake to control them We need a different set of visibility macros to LLVM's since on windows you need a different attribute to import and export a symbol unlike other platforms and many translation units will be importing LLVM symbols and export some of Clangs. Updated Clang CMake to define a macro to enable the symbol visibility macros. --- clang/cmake/modules/AddClang.cmake | 4 ++ clang/include/clang/Support/Compiler.h | 69 ++ clang/tools/libclang/CMakeLists.txt| 2 +- 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 clang/include/clang/Support/Compiler.h diff --git a/clang/cmake/modules/AddClang.cmake b/clang/cmake/modules/AddClang.cmake index 5327b5d2f08928..dcdea378fb 100644 --- a/clang/cmake/modules/AddClang.cmake +++ b/clang/cmake/modules/AddClang.cmake @@ -108,6 +108,10 @@ macro(add_clang_library name) endif() llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs}) + if(NOT ARG_SHARED AND NOT ARG_STATIC) +target_compile_definitions("obj.${name}" PRIVATE CLANG_EXPORTS) + endif() + set(libs ${name}) if(ARG_SHARED AND ARG_STATIC) list(APPEND libs ${name}_static) diff --git a/clang/include/clang/Support/Compiler.h b/clang/include/clang/Support/Compiler.h new file mode 100644 index 00..4a584e190dc16e --- /dev/null +++ b/clang/include/clang/Support/Compiler.h @@ -0,0 +1,69 @@ +//===-- clang/Support/Compiler.h - Compiler abstraction support -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file defines explicit visibility macros used to export symbols from +// clang-cpp +// +//===--===// + +#ifndef CLANG_SUPPORT_COMPILER_H +#define CLANG_SUPPORT_COMPILER_H + +#include "llvm/Support/Compiler.h" + +/// CLANG_ABI is the main export/visibility macro to mark something as +/// explicitly exported when clang is built as a shared library with everything +/// else that is unannotated will have internal visibility. +/// +/// CLANG_EXPORT_TEMPLATE is used on explicit template instantiations in source +/// files that were declared extern in a header. This macro is only set as a +/// compiler export attribute on windows, on other platforms it does nothing. +/// +/// CLANG_TEMPLATE_ABI is for annotating extern template declarations in headers +/// for both functions and classes. On windows its turned in to dllimport for +/// library consumers, for other platforms its a default visibility attribute. +#ifndef CLANG_ABI_GENERATING_ANNOTATIONS +// Marker to add to classes or functions in public headers that should not have +// export macros added to them by the clang tool +#define CLANG_ABI_NOT_EXPORTED +#if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS) +// Some libraries like those for tablegen are linked in to tools that used +// in the build so can't depend on the llvm shared library. If export macros +// were left enabled when building these we would get duplicate or +// missing symbol linker errors on windows. +#if defined(CLANG_BUILD_STATIC) +#define CLANG_ABI +#define CLANG_TEMPLATE_ABI +#define CLANG_EXPORT_TEMPLATE +#elif defined(_WIN32) && !defined(__MINGW32__) +#if defined(CLANG_EXPORTS) +#define CLANG_ABI __declspec(dllexport) +#define CLANG_TEMPLATE_ABI +#define CLANG_EXPORT_TEMPLATE __declspec(dllexport) +#else +#define CLANG_ABI __declspec(dllimport) +#define CLANG_TEMPLATE_ABI __declspec(dllimport) +#define CLANG_EXPORT_TEMPLATE +#endif +#elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) +#define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT +#define CLANG_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT +#define CLANG_EXPORT_TEMPLATE +#elif defined(__MACH__) || defined(__WASM__) +#define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT +#define CLANG_TEMPLATE_ABI +#define CLANG_EXPORT_TEMPLATE +#endif +#else +#define CLANG_ABI +#define CLANG_TEMPLATE_ABI +#define CLANG_EXPORT_TEMPLATE +#endif +#endif + +#endif \ No newline at end of file diff --git a/clang/tools/libclang/CMakeLists.txt b/clang/tools/libclang/CMakeLists.txt index 968b46acb784cb..8c6a07f9e52a8c 100644 --- a/clang/tools/libclang/CMakeLists.txt +++ b/clang/tools/libclang/CMakeLists.txt @@ -166,7 +166,7 @@ if(ENABLE_SHARED) set_target_properties(libclang PROPERTIES VERSION ${LIBCLANG_LIBRARY_VERSION} - DEFINE_SYMBOL _CINDEX_LIB_) + DEFINE_SYMBO
[clang-tools-extra] [clangd] [C++20] [Modules] Support code complete for C++20 modules (PR #110083)
llvmbot wrote: @llvm/pr-subscribers-clangd Author: Chuanqi Xu (ChuanqiXu9) Changes According to https://github.com/ChuanqiXu9/clangd-for-modules/issues/9, I surprisingly found the support for C++20 modules doesn't support code completion well. After debugging, I found there are problems: (1) We forgot to call `adjustHeaderSearchOptions` in code complete. This may be an easy oversight. (2) In `CodeCompleteOptions::getClangCompleteOpts`, we may set `LoadExternal` as false when index is available. But we have support modules with index. So it is conflicting. Given modules are opt in now, I think it makes sense to to set LoadExternal as true when modules are enabled. This is a small fix and I wish it can land faster. --- Full diff: https://github.com/llvm/llvm-project/pull/110083.diff 3 Files Affected: - (modified) clang-tools-extra/clangd/CodeComplete.cpp (+13-5) - (modified) clang-tools-extra/clangd/CodeComplete.h (+1-1) - (modified) clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp (+40) ``diff diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index 89eee392837af4..f6f0d9a1be3c37 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -892,8 +892,9 @@ static bool isExcludedMember(const NamedDecl &D) { // within the callback. struct CompletionRecorder : public CodeCompleteConsumer { CompletionRecorder(const CodeCompleteOptions &Opts, + bool ForceLoadExternal, llvm::unique_function ResultsCallback) - : CodeCompleteConsumer(Opts.getClangCompleteOpts()), + : CodeCompleteConsumer(Opts.getClangCompleteOpts(ForceLoadExternal)), CCContext(CodeCompletionContext::CCC_Other), Opts(Opts), CCAllocator(std::make_shared()), CCTUInfo(CCAllocator), ResultsCallback(std::move(ResultsCallback)) { @@ -1409,6 +1410,9 @@ bool semaCodeComplete(std::unique_ptr Consumer, Clang->getPreprocessorOpts().SingleFileParseMode = CompletingInPreamble; Clang->setCodeCompletionConsumer(Consumer.release()); + if (Input.Preamble.RequiredModules) + Input.Preamble.RequiredModules->adjustHeaderSearchOptions(Clang->getHeaderSearchOpts()); + SyntaxOnlyAction Action; if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) { log("BeginSourceFile() failed when running codeComplete for {0}", @@ -1629,11 +1633,15 @@ class CodeCompleteFlow { SpecFuzzyFind->Result = startAsyncFuzzyFind(*Opts.Index, *SpecReq); } +// FIXME: If we're using C++20 modules, force the lookup process to load external decls, +// since currently the index doesn't support C++20 modules. +bool ForceLoadExternal = (bool)SemaCCInput.Preamble.RequiredModules; + // We run Sema code completion first. It builds an AST and calculates: // - completion results based on the AST. // - partial identifier and context. We need these for the index query. CodeCompleteResult Output; -auto RecorderOwner = std::make_unique(Opts, [&]() { +auto RecorderOwner = std::make_unique(Opts, ForceLoadExternal, [&]() { assert(Recorder && "Recorder is not set"); CCContextKind = Recorder->CCContext.getKind(); IsUsingDeclaration = Recorder->CCContext.isUsingDeclaration(); @@ -1691,7 +1699,7 @@ class CodeCompleteFlow { Recorder = RecorderOwner.get(); -semaCodeComplete(std::move(RecorderOwner), Opts.getClangCompleteOpts(), +semaCodeComplete(std::move(RecorderOwner), Opts.getClangCompleteOpts(ForceLoadExternal), SemaCCInput, &Includes); logResults(Output, Tracer); return Output; @@ -2108,7 +2116,7 @@ class CodeCompleteFlow { } // namespace -clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const { +clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts(bool ForceLoadExternal) const { clang::CodeCompleteOptions Result; Result.IncludeCodePatterns = EnableSnippets; Result.IncludeMacros = true; @@ -2122,7 +2130,7 @@ clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const { // When an is used, Sema is responsible for completing the main file, // the index can provide results from the preamble. // Tell Sema not to deserialize the preamble to look for results. - Result.LoadExternal = !Index; + Result.LoadExternal = ForceLoadExternal || !Index; Result.IncludeFixIts = IncludeFixIts; return Result; diff --git a/clang-tools-extra/clangd/CodeComplete.h b/clang-tools-extra/clangd/CodeComplete.h index a7c1ae95dcbf49..336e84f0a7724c 100644 --- a/clang-tools-extra/clangd/CodeComplete.h +++ b/clang-tools-extra/clangd/CodeComplete.h @@ -41,7 +41,7 @@ struct CodeCompletion; struct CodeCompleteOptions { /// Returns options that can be passed to clang's completion engine. - clang::CodeCompleteOptions getClangCompleteOpts() const; + clang::CodeComp
[clang] [llvm] [Clang][LLVM][AArch64] Add intrinsic for LUTI4 SME2 instruction (PR #97755)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-x86_64-debian-fast` running on `gribozavr4` while building `clang,llvm` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/56/builds/8336 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'Clang :: CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 2: /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/20/include -nostdsysteminc -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -O2 -Werror -Wall -emit-llvm -o - /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c | /b/1/clang-x86_64-debian-fast/llvm.obj/bin/FileCheck /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c + /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/20/include -nostdsysteminc -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -O2 -Werror -Wall -emit-llvm -o - /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c + /b/1/clang-x86_64-debian-fast/llvm.obj/bin/FileCheck /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c:12:17: error: CHECK-LABEL: expected string not found in input // CHECK-LABEL: define dso_local @test_luti4_zt_u8_x4( ^ :1:1: note: scanning from here ; ModuleID = '/b/1/clang-x86_64-debian-fast/llvm.src/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c' ^ :7:65: note: possible intended match here define dso_local { , , , } @test_luti4_zt_u8_x4( %op.coerce0, %op.coerce1) local_unnamed_addr #0 { ^ Input file: Check file: /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c -dump-input=help explains the following input dump. Input was: << 1: ; ModuleID = '/b/1/clang-x86_64-debian-fast/llvm.src/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c' label:12'0 X~ error: no match found 2: source_filename = "/b/1/clang-x86_64-debian-fast/llvm.src/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_zt.c" label:12'0 ~~~ 3: target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" label:12'0 ~~~ 4: target triple = "aarch64-none-linux-gnu" label:12'0 ~ 5: label:12'0 ~ 6: ; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn label:12'0 ~~~ 7: define dso_local { , , , } @test_luti4_zt_u8_x4( %op.coerce0, %op.coerce1) local_unnamed_addr #0 { label:12'0 ~ label:12'1 ? possible intended match 8: entry: label:12'0 ~~~ 9: %retval = alloca { , , , }, align 16 label:12'0 ~~~ 10: %0 = tail call { , , , } @llvm.aarch64.sme.luti4.zt.x4.nxv16i8(i32 0, %op.coerce0, %op.coerce1) label:12'0 11: %1 = extractvalue { , , , } %0, 0 label:12'0
[clang] [llvm] Deprecate the `-fbasic-block-sections=labels` option. (PR #107494)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `arc-builder` running on `arc-worker` while building `clang,llvm` at step 5 "build-unified-tree". Full details are available at: https://lab.llvm.org/buildbot/#/builders/3/builds/5248 Here is the relevant piece of the build log for the reference ``` Step 5 (build-unified-tree) failure: build (failure) ``` https://github.com/llvm/llvm-project/pull/107494 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Deprecate the `-fbasic-block-sections=labels` option. (PR #107494)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `sanitizer-aarch64-linux-fuzzer` running on `sanitizer-buildbot12` while building `clang,llvm` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/159/builds/6921 Here is the relevant piece of the build log for the reference ``` Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) ... [1117/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/LoongArch.cpp.o [1118/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/Sparc.cpp.o [1119/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/SPIR.cpp.o [1120/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/M68k.cpp.o [1121/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/TCE.cpp.o [1122/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/Mips.cpp.o [1123/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/SystemZ.cpp.o [1124/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/VE.cpp.o [1125/2117] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/InputChunks.cpp.o [1126/2117] Building CXX object tools/lld/ELF/CMakeFiles/lldELF.dir/LTO.cpp.o FAILED: tools/lld/ELF/CMakeFiles/lldELF.dir/LTO.cpp.o CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/clang++ -DGTEST_HAS_RTTI=0 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/b/sanitizer-aarch64-linux-fuzzer/build/llvm_build0/tools/lld/ELF -I/home/b/sanitizer-aarch64-linux-fuzzer/build/llvm-project/lld/ELF -I/home/b/sanitizer-aarch64-linux-fuzzer/build/llvm-project/lld/include -I/home/b/sanitizer-aarch64-linux-fuzzer/build/llvm_build0/tools/lld/include -I/home/b/sanitizer-aarch64-linux-fuzzer/build/llvm_build0/include -I/home/b/sanitizer-aarch64-linux-fuzzer/build/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17 -fno-exceptions -funwind-tables -fno-rtti -MD -MT tools/lld/ELF/CMakeFiles/lldELF.dir/LTO.cpp.o -MF tools/lld/ELF/CMakeFiles/lldELF.dir/LTO.cpp.o.d -o tools/lld/ELF/CMakeFiles/lldELF.dir/LTO.cpp.o -c /home/b/sanitizer-aarch64-linux-fuzzer/build/llvm-project/lld/ELF/LTO.cpp /home/b/sanitizer-aarch64-linux-fuzzer/build/llvm-project/lld/ELF/LTO.cpp:74:49: error: no member named 'Labels' in 'llvm::BasicBlockSection' 74 | c.Options.BBSections = BasicBlockSection::Labels; | ~~~^ 1 error generated. [1127/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/XCore.cpp.o [1128/2117] Building CXX object tools/llvm-lto/CMakeFiles/llvm-lto.dir/llvm-lto.cpp.o [1129/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/PPC.cpp.o [1130/2117] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/Relocations.cpp.o [1131/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/WebAssembly.cpp.o [1132/2117] Building CXX object tools/lld/MachO/CMakeFiles/lldMachO.dir/DriverUtils.cpp.o [1133/2117] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/OutputSegment.cpp.o [1134/2117] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/LTO.cpp.o [1135/2117] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/OutputSections.cpp.o [1136/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/RISCV.cpp.o [1137/2117] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/MarkLive.cpp.o [1138/2117] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/MapFile.cpp.o [1139/2117] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/Symbols.cpp.o [1140/2117] Building CXX object tools/lld/COFF/CMakeFiles/lldCOFF.dir/SymbolTable.cpp.o [1141/2117] Building CXX object tools/lld/COFF/CMakeFiles/lldCOFF.dir/LTO.cpp.o [1142/2117] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/Driver.cpp.o [1143/2117] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o [1144/2117] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/SymbolTable.cpp.o [1145/2117] Building CXX object tools/clang/lib/Lex/CMakeFiles/obj.clangLex.d
[clang] [llvm] Deprecate the `-fbasic-block-sections=labels` option. (PR #107494)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-sie-win` running on `sie-win-worker` while building `clang,llvm` at step 6 "build-unified-tree". Full details are available at: https://lab.llvm.org/buildbot/#/builders/46/builds/5534 Here is the relevant piece of the build log for the reference ``` Step 6 (build-unified-tree) failure: build (failure) ... [2786/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\DeclObjC.cpp.obj [2787/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\CXXInheritance.cpp.obj [2788/4713] Building CXX object tools\lld\wasm\CMakeFiles\lldWasm.dir\Writer.cpp.obj [2789/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ComputeDependence.cpp.obj [2790/4713] Building CXX object tools\lld\COFF\CMakeFiles\lldCOFF.dir\Driver.cpp.obj [2791/4713] Building CXX object tools\lld\MachO\CMakeFiles\lldMachO.dir\Driver.cpp.obj [2792/4713] Building CXX object tools\lld\wasm\CMakeFiles\lldWasm.dir\SymbolTable.cpp.obj [2793/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ByteCode\DynamicAllocator.cpp.obj [2794/4713] Building CXX object tools\lld\wasm\CMakeFiles\lldWasm.dir\Relocations.cpp.obj [2795/4713] Building CXX object tools\lld\ELF\CMakeFiles\lldELF.dir\LTO.cpp.obj FAILED: tools/lld/ELF/CMakeFiles/lldELF.dir/LTO.cpp.obj C:\bin\ccache.exe C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\HostX64\x64\cl.exe /nologo /TP -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\lld\ELF -IZ:\b\llvm-clang-x86_64-sie-win\llvm-project\lld\ELF -IZ:\b\llvm-clang-x86_64-sie-win\llvm-project\lld\include -Itools\lld\include -Iinclude -IZ:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\include /DWIN32 /D_WINDOWS /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2 -MD -wd4530 -wd4062 /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes /Fotools\lld\ELF\CMakeFiles\lldELF.dir\LTO.cpp.obj /Fdtools\lld\ELF\CMakeFiles\lldELF.dir\lldELF.pdb /FS -c Z:\b\llvm-clang-x86_64-sie-win\llvm-project\lld\ELF\LTO.cpp Z:\b\llvm-clang-x86_64-sie-win\llvm-project\lld\ELF\LTO.cpp(74): error C2838: 'Labels': illegal qualified name in member declaration Z:\b\llvm-clang-x86_64-sie-win\llvm-project\lld\ELF\LTO.cpp(74): error C2065: 'Labels': undeclared identifier [2796/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ByteCode\PrimType.cpp.obj [2797/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ExternalASTSource.cpp.obj [2798/4713] Building CXX object tools\lld\MachO\CMakeFiles\lldMachO.dir\LTO.cpp.obj [2799/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ByteCode\InterpBlock.cpp.obj [2800/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\DeclFriend.cpp.obj [2801/4713] Building CXX object tools\lld\wasm\CMakeFiles\lldWasm.dir\OutputSections.cpp.obj [2802/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ByteCode\MemberPointer.cpp.obj [2803/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ByteCode\InterpState.cpp.obj [2804/4713] Building CXX object tools\lld\wasm\CMakeFiles\lldWasm.dir\Symbols.cpp.obj [2805/4713] Building CXX object tools\lld\wasm\CMakeFiles\lldWasm.dir\OutputSegment.cpp.obj [2806/4713] Building CXX object tools\lld\wasm\CMakeFiles\lldWasm.dir\Driver.cpp.obj [2807/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ASTImporterLookupTable.cpp.obj [2808/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\Decl.cpp.obj [2809/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ExternalASTMerger.cpp.obj [2810/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\DeclBase.cpp.obj [2811/4713] Building CXX object tools\lld\wasm\CMakeFiles\lldWasm.dir\MapFile.cpp.obj [2812/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ByteCode\Source.cpp.obj [2813/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\AttrImpl.cpp.obj [2814/4713] Building CXX object tools\lld\MachO\CMakeFiles\lldMachO.dir\DriverUtils.cpp.obj [2815/4713] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\DeclCXX.cpp.obj [2816/4713] Building CXX object tools
[clang] [llvm] Deprecate the `-fbasic-block-sections=labels` option. (PR #107494)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `lldb-arm-ubuntu` running on `linaro-lldb-arm-ubuntu` while building `clang,llvm` at step 4 "build". Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/4463 Here is the relevant piece of the build log for the reference ``` Step 4 (build) failure: build (failure) ... 234.877 [2519/41/3753] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/ParsedAttrInfo.cpp.o 234.927 [2519/40/3754] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Sanitizers.cpp.o 234.928 [2519/39/3755] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Stack.cpp.o 234.933 [2514/43/3756] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/TargetID.cpp.o 234.938 [2514/42/3757] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/SourceMgrAdapter.cpp.o 234.940 [2514/41/3758] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/SourceLocation.cpp.o 234.941 [2514/40/3759] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/SourceManager.cpp.o 234.946 [2510/43/3760] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Sarif.cpp.o 234.975 [2509/43/3761] Building CXX object lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86TargetMachine.cpp.o 235.298 [2509/42/3762] Building CXX object tools/lld/ELF/CMakeFiles/lldELF.dir/LTO.cpp.o FAILED: tools/lld/ELF/CMakeFiles/lldELF.dir/LTO.cpp.o /usr/local/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_FILE_OFFSET_BITS=64 -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lld/ELF -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lld/ELF -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lld/include -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lld/include -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include -I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17 -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/lld/ELF/CMakeFiles/lldELF.dir/LTO.cpp.o -MF tools/lld/ELF/CMakeFiles/lldELF.dir/LTO.cpp.o.d -o tools/lld/ELF/CMakeFiles/lldELF.dir/LTO.cpp.o -c /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lld/ELF/LTO.cpp ../llvm-project/lld/ELF/LTO.cpp:74:49: error: no member named 'Labels' in 'llvm::BasicBlockSection' 74 | c.Options.BBSections = BasicBlockSection::Labels; | ~~~^ 1 error generated. 235.331 [2509/41/3763] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/DiagnosticIDs.cpp.o 235.628 [2509/40/3764] Building CXX object tools/llvm-lto/CMakeFiles/llvm-lto.dir/llvm-lto.cpp.o 235.988 [2509/39/3765] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/LTO.cpp.o 236.146 [2509/38/3766] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/Relocations.cpp.o 237.437 [2509/37/3767] Building CXX object tools/lld/wasm/CMakeFiles/lldWasm.dir/SymbolTable.cpp.o 237.710 [2509/36/3768] Building CXX object tools/lld/COFF/CMakeFiles/lldCOFF.dir/SymbolTable.cpp.o 238.303 [2509/35/3769] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/CodeGenOptions.cpp.o 238.792 [2509/34/3770] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/ProfileList.cpp.o 239.636 [2509/33/3771] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/MSP430.cpp.o 239.789 [2509/32/3772] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/DirectX.cpp.o 239.891 [2509/31/3773] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/BPF.cpp.o 240.442 [2509/30/3774] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/Lanai.cpp.o 240.583 [2509/29/3775] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/CSKY.cpp.o 240.751 [2509/28/3776] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Module.cpp.o 240.872 [2509/27/3777] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/ARC.cpp.o 240.894 [2509/26/3778] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Targets/AVR.cpp.o 241.109 [2509/25/3779] Bu
[clang] [Clang] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)
@@ -1,7 +1,28 @@ +// Verify ubsan doesn't emit checks for ignorelisted types +// RUN: echo "[{unsigned-integer-overflow,signed-integer-overflow}]" > %t-int.ignorelist +// RUN: echo "type:int" >> %t-int.ignorelist +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t-int.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=INT + +// RUN: echo "type:int" > %t-nosection.ignorelist +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t-nosection.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=INT + +// RUN: echo "type:int=allow" > %t-allow-same-as-no-category.ignorelist +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-ignorelist=%t-allow-same-as-no-category.ignorelist -emit-llvm %s -o - | FileCheck %s --check-prefix=INT + +// RUN: echo "[{unsigned-integer-overflow,signed-integer-overflow}]" > %t-myty.ignorelist +// RUN: echo "type:*" >> %t-myty.ignorelist +// RUN: echo "type:myty=skip" >> %t-myty.ignorelist JustinStitt wrote: OK, ce2a808 addresses Note1 but Note2 was not trivial to implement as my tests need both CHECKs and CHECK-NOTs. I find the tests easier to read using the `-NOT`s as the logic is not purely negatable -- at least for how I have it laid out right now. https://github.com/llvm/llvm-project/pull/107332 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
@@ -616,6 +626,62 @@ class LineJoiner { return 1; } + unsigned tryMergeNamespace(SmallVectorImpl::const_iterator I, + SmallVectorImpl::const_iterator E, + unsigned Limit) { +if (Limit == 0) + return 0; +if (I[1]->InPPDirective != (*I)->InPPDirective || +(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline)) { + return 0; +} +if (I + 2 == E || I[2]->Type == LT_Invalid) + return 0; + +Limit = limitConsideringMacros(I + 1, E, Limit); + +if (!nextTwoLinesFitInto(I, Limit)) + return 0; + +// Check if it's a namespace inside a namespace, and call recursively if so +// '3' is the sizes of the whitespace and closing brace for " _inner_ }". +if (I[1]->First->is(tok::kw_namespace)) { + if (I[1]->Last->is(TT_LineComment)) galenelias wrote: Yah, fair question. I think I could see it either way. I'm fine starting with not supporting trailing block comments either and then could relax it if there are explicit requests for that behavior. https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] eb48aac - [Clang] Automatically link the `compiler-rt` for GPUs if present (#109152)
Author: Joseph Huber Date: 2024-09-25T12:58:10-07:00 New Revision: eb48aac7d40ee9cd3072c466d7ab17facb58570f URL: https://github.com/llvm/llvm-project/commit/eb48aac7d40ee9cd3072c466d7ab17facb58570f DIFF: https://github.com/llvm/llvm-project/commit/eb48aac7d40ee9cd3072c466d7ab17facb58570f.diff LOG: [Clang] Automatically link the `compiler-rt` for GPUs if present (#109152) Summary: This automically links `copmiler-rt` for offloading languages if it exists in the resource directory. Added: Modified: clang/lib/Driver/ToolChains/Clang.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 0bab48caf1a5e2..a883ba2a25412e 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -9242,6 +9242,12 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString( "--device-linker=" + TC.getTripleString() + "=" + "-lm")); } + auto HasCompilerRT = getToolChain().getVFS().exists( + TC.getCompilerRT(Args, "builtins", ToolChain::FT_Static)); + if (HasCompilerRT) +CmdArgs.push_back( +Args.MakeArgString("--device-linker=" + TC.getTripleString() + "=" + + "-lclang_rt.builtins")); }); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Automatically link the `compiler-rt` for GPUs if present (PR #109152)
https://github.com/jhuber6 closed https://github.com/llvm/llvm-project/pull/109152 ___ 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)
https://github.com/rlavaee updated https://github.com/llvm/llvm-project/pull/110039 >From 52f633c5d3597c2ece53f821ee775aebce758efb Mon Sep 17 00:00:00 2001 From: Rahman Lavaee Date: Wed, 25 Sep 2024 20:12:07 + Subject: [PATCH 1/2] Reapply "Deprecate the `-fbasic-block-sections=labels` option. (#107494)" This reverts commit 639a0afa9955a8613902e46e168767bc05c46cdd. --- clang/docs/UsersManual.rst | 12 +++- clang/include/clang/Basic/CodeGenOptions.h | 9 ++--- clang/include/clang/Driver/Options.td| 4 ++-- clang/lib/CodeGen/BackendUtil.cpp| 1 - clang/lib/Driver/ToolChains/Clang.cpp| 10 +++--- clang/test/Driver/fbasic-block-sections.c| 3 ++- llvm/docs/CommandGuide/llvm-objdump.rst | 2 +- llvm/docs/Extensions.rst | 2 +- llvm/include/llvm/CodeGen/MachineFunction.h | 5 - llvm/include/llvm/Target/TargetOptions.h | 3 --- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 11 +-- llvm/lib/CodeGen/BasicBlockSections.cpp | 7 --- llvm/lib/CodeGen/CommandFlags.cpp| 2 -- llvm/lib/CodeGen/MIRParser/MIParser.cpp | 9 + llvm/lib/CodeGen/MIRParser/MIRParser.cpp | 4 +--- llvm/lib/CodeGen/MachineFunction.cpp | 8 +++- ...ock.ll => basic-block-address-map-empty-block.ll} | 2 +- ll => basic-block-address-map-empty-function.ll} | 4 ++-- .../X86/basic-block-address-map-function-sections.ll | 1 - ...rse.mir => basic-block-address-map-mir-parse.mir} | 4 ++-- ...es.ll => basic-block-address-map-pgo-features.ll} | 10 +- llvm/test/CodeGen/X86/basic-block-address-map.ll | 4 +--- .../CodeGen/X86/basic-block-sections-mir-print.ll| 10 +- 23 files changed, 48 insertions(+), 79 deletions(-) rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-block.ll => basic-block-address-map-empty-block.ll} (83%) rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-function.ll => basic-block-address-map-empty-function.ll} (68%) rename llvm/test/CodeGen/X86/{basic-block-labels-mir-parse.mir => basic-block-address-map-mir-parse.mir} (97%) rename llvm/test/CodeGen/X86/{basic-block-sections-labels-pgo-features.ll => basic-block-address-map-pgo-features.ll} (88%) diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index 57d78f867bab6e..4f03388bc87bd0 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -2369,14 +2369,16 @@ are listed below. $ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o -.. option:: -fbasic-block-sections=[labels, all, list=, none] +.. option:: -f[no]-basic-block-address-map: + Emits a ``SHT_LLVM_BB_ADDR_MAP`` section which includes address offsets for each + basic block in the program, relative to the parent function address. + + +.. option:: -fbasic-block-sections=[all, list=, none] Controls how Clang emits text sections for basic blocks. With values ``all`` and ``list=``, each basic block or a subset of basic blocks can be placed - in its own unique section. With the "labels" value, normal text sections are - emitted, but a ``.bb_addr_map`` section is emitted which includes address - offsets for each basic block in the program, relative to the parent function - address. + in its own unique section. With the ``list=`` option, a file containing the subset of basic blocks that need to placed in unique sections can be specified. The format of the diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index f2a707a8ba8d76..814d4d4c99e575 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -107,18 +107,13 @@ class CodeGenOptions : public CodeGenOptionsBase { // This field stores one of the allowed values for the option // -fbasic-block-sections=. The allowed values with this option are: - // {"labels", "all", "list=", "none"}. + // {"all", "list=", "none"}. // - // "labels": Only generate basic block symbols (labels) for all basic - //blocks, do not generate unique sections for basic blocks. - //Use the machine basic block id in the symbol name to - //associate profile info from virtual address to machine - //basic block. // "all" :Generate basic block sections for all basic blocks. // "list=": Generate basic block sections for a subset of basic blocks. //The functions and the machine basic block ids are specified //in the file. - // "none":Disable sections/labels for basic blocks. + // "none":Disable sections for basic blocks. std::string BBS
[clang] [alpha.webkit.UncountedCallArgsChecker] Use canonical type (PR #109393)
https://github.com/haoNoQ approved this pull request. Ah classic! LGTM! 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] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)
zygoloid wrote: I believe all the feedback has been addressed, and plan to merge in 24 hours if there are no further comments. 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] [alpha.webkit.UncountedCallArgsChecker] Use canonical type (PR #109393)
https://github.com/haoNoQ edited 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] [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(); haoNoQ wrote: `getTypePtrOrNull()` is unnecessary most of the time because you can do all the same operations on `QualType` directly, thanks to the overloaded `QualType::operator->()`. I think `isUncountedPtr()` should simply accept a `QualType` directly. 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] [clang-tools-extra] [NFC] Add implicit cast kinds for function pointer conversions (PR #110048)
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 4db0cc4c5582c73eb793572f8a8d5892b05fdfde 75cd73ecda039750270e8bde0523f51e4698c4ea --extensions cpp,h -- clang/test/AST/ast-dump-function-pointer-conversion.cpp clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp clang-tools-extra/clangd/Hover.cpp clang/include/clang/AST/IgnoreExpr.h clang/lib/ARCMigrate/TransBlockObjCVariable.cpp clang/lib/AST/ByteCode/Compiler.cpp clang/lib/AST/Expr.cpp clang/lib/AST/ExprCXX.cpp clang/lib/AST/ExprConstant.cpp clang/lib/Analysis/CFG.cpp clang/lib/Analysis/ExprMutationAnalyzer.cpp clang/lib/Analysis/FlowSensitive/Transfer.cpp clang/lib/Analysis/ThreadSafety.cpp clang/lib/Analysis/ThreadSafetyCommon.cpp clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGExprAgg.cpp clang/lib/CodeGen/CGExprComplex.cpp clang/lib/CodeGen/CGExprConstant.cpp clang/lib/CodeGen/CGExprScalar.cpp clang/lib/Edit/RewriteObjCFoundationAPI.cpp clang/lib/Sema/CheckExprLifetime.cpp clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaInit.cpp clang/lib/Sema/SemaOverload.cpp clang/lib/Sema/SemaStmt.cpp clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp clang/lib/StaticAnalyzer/Core/SValBuilder.cpp clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p4-ast.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index 49883e01f7..8c3396e2d9 100644 --- a/clang/lib/Analysis/ThreadSafety.cpp +++ b/clang/lib/Analysis/ThreadSafety.cpp @@ -2106,7 +2106,7 @@ static const Expr *UnpackConstruction(const Expr *E) { if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_FunctionPointerConversion || CE->getCastKind() == CK_MemberFunctionPointerConversion) -E = CE->getSubExpr()->IgnoreParens(); + E = CE->getSubExpr()->IgnoreParens(); if (auto *CE = dyn_cast(E)) if (CE->getCastKind() == CK_ConstructorConversion || CE->getCastKind() == CK_UserDefinedConversion) `` https://github.com/llvm/llvm-project/pull/110048 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [NFC] Add implicit cast kinds for function pointer conversions (PR #110048)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Akira Hatanaka (ahatanak) Changes The new cast kinds are needed to distinguish between no-op conversions and conversions from pointers to noexcept functions to pointers to functions without noexcept as the latter can cause function pointers to be re-signed on arm64e. See https://github.com/llvm/llvm-project/pull/109056 for background. --- Patch is 37.94 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/110048.diff 40 Files Affected: - (modified) clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp (+2) - (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp (+3-1) - (modified) clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp (+6-1) - (modified) clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp (+3-1) - (modified) clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp (+3-1) - (modified) clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp (+7-2) - (modified) clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp (+2) - (modified) clang-tools-extra/clangd/Hover.cpp (+2) - (modified) clang/include/clang/AST/IgnoreExpr.h (+3-1) - (modified) clang/include/clang/AST/OperationKinds.def (+8) - (modified) clang/lib/ARCMigrate/TransBlockObjCVariable.cpp (+4-2) - (modified) clang/lib/AST/ByteCode/Compiler.cpp (+4) - (modified) clang/lib/AST/Expr.cpp (+23-5) - (modified) clang/lib/AST/ExprCXX.cpp (+5-1) - (modified) clang/lib/AST/ExprConstant.cpp (+14-3) - (modified) clang/lib/Analysis/CFG.cpp (+2) - (modified) clang/lib/Analysis/ExprMutationAnalyzer.cpp (+7-5) - (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+6-2) - (modified) clang/lib/Analysis/ThreadSafety.cpp (+3-1) - (modified) clang/lib/Analysis/ThreadSafetyCommon.cpp (+2) - (modified) clang/lib/CodeGen/CGDecl.cpp (+2) - (modified) clang/lib/CodeGen/CGExpr.cpp (+5-1) - (modified) clang/lib/CodeGen/CGExprAgg.cpp (+4) - (modified) clang/lib/CodeGen/CGExprComplex.cpp (+2) - (modified) clang/lib/CodeGen/CGExprConstant.cpp (+2) - (modified) clang/lib/CodeGen/CGExprScalar.cpp (+3-1) - (modified) clang/lib/Edit/RewriteObjCFoundationAPI.cpp (+2) - (modified) clang/lib/Sema/CheckExprLifetime.cpp (+2) - (modified) clang/lib/Sema/SemaChecking.cpp (+4) - (modified) clang/lib/Sema/SemaDecl.cpp (+3-1) - (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3-1) - (modified) clang/lib/Sema/SemaExpr.cpp (+2) - (modified) clang/lib/Sema/SemaExprCXX.cpp (+5-1) - (modified) clang/lib/Sema/SemaInit.cpp (+2-2) - (modified) clang/lib/Sema/SemaOverload.cpp (+5-1) - (modified) clang/lib/Sema/SemaStmt.cpp (+2) - (modified) clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp (+2) - (modified) clang/lib/StaticAnalyzer/Core/SValBuilder.cpp (+2) - (added) clang/test/AST/ast-dump-function-pointer-conversion.cpp (+30) - (modified) clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p4-ast.cpp (+2-2) ``diff diff --git a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp index 8989444dde1300..acb7112fa2abed 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp @@ -27,6 +27,8 @@ void SwappedArgumentsCheck::registerMatchers(MatchFinder *Finder) { static const Expr *ignoreNoOpCasts(const Expr *E) { if (auto *Cast = dyn_cast(E)) if (Cast->getCastKind() == CK_LValueToRValue || +Cast->getCastKind() == CK_FunctionPointerConversion || +Cast->getCastKind() == CK_MemberFunctionPointerConversion || Cast->getCastKind() == CK_NoOp) return ignoreNoOpCasts(Cast->getSubExpr()); return E; diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp index 5e255dcaacd262..bab08496e90e86 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp @@ -90,7 +90,9 @@ void ProTypeCstyleCastCheck::check(const MatchFinder::MatchResult &Result) { return; } - if (MatchedCast->getCastKind() == CK_NoOp && + if ((MatchedCast->getCastKind() == CK_NoOp || + MatchedCast->getCastKind() == CK_FunctionPointerConversion || + MatchedCast->getCastKind() == CK_MemberFunctionPointerConversion) && needsConstCast(SourceType, MatchedCast->getType())) { diag(MatchedCast->getBeginLoc(), "do not use C-style cast to cast away constness"); diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp index 3109bbb3724c79..888f7b122b82c3 100644 --- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp +++ b/clang-tools-extra/clang-
[clang] [clang-tools-extra] [NFC] Add implicit cast kinds for function pointer conversions (PR #110048)
llvmbot wrote: @llvm/pr-subscribers-clangd Author: Akira Hatanaka (ahatanak) Changes The new cast kinds are needed to distinguish between no-op conversions and conversions from pointers to noexcept functions to pointers to functions without noexcept as the latter can cause function pointers to be re-signed on arm64e. See https://github.com/llvm/llvm-project/pull/109056 for background. --- Patch is 37.94 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/110048.diff 40 Files Affected: - (modified) clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp (+2) - (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp (+3-1) - (modified) clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp (+6-1) - (modified) clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp (+3-1) - (modified) clang-tools-extra/clang-tidy/performance/ImplicitConversionInLoopCheck.cpp (+3-1) - (modified) clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp (+7-2) - (modified) clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp (+2) - (modified) clang-tools-extra/clangd/Hover.cpp (+2) - (modified) clang/include/clang/AST/IgnoreExpr.h (+3-1) - (modified) clang/include/clang/AST/OperationKinds.def (+8) - (modified) clang/lib/ARCMigrate/TransBlockObjCVariable.cpp (+4-2) - (modified) clang/lib/AST/ByteCode/Compiler.cpp (+4) - (modified) clang/lib/AST/Expr.cpp (+23-5) - (modified) clang/lib/AST/ExprCXX.cpp (+5-1) - (modified) clang/lib/AST/ExprConstant.cpp (+14-3) - (modified) clang/lib/Analysis/CFG.cpp (+2) - (modified) clang/lib/Analysis/ExprMutationAnalyzer.cpp (+7-5) - (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+6-2) - (modified) clang/lib/Analysis/ThreadSafety.cpp (+3-1) - (modified) clang/lib/Analysis/ThreadSafetyCommon.cpp (+2) - (modified) clang/lib/CodeGen/CGDecl.cpp (+2) - (modified) clang/lib/CodeGen/CGExpr.cpp (+5-1) - (modified) clang/lib/CodeGen/CGExprAgg.cpp (+4) - (modified) clang/lib/CodeGen/CGExprComplex.cpp (+2) - (modified) clang/lib/CodeGen/CGExprConstant.cpp (+2) - (modified) clang/lib/CodeGen/CGExprScalar.cpp (+3-1) - (modified) clang/lib/Edit/RewriteObjCFoundationAPI.cpp (+2) - (modified) clang/lib/Sema/CheckExprLifetime.cpp (+2) - (modified) clang/lib/Sema/SemaChecking.cpp (+4) - (modified) clang/lib/Sema/SemaDecl.cpp (+3-1) - (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3-1) - (modified) clang/lib/Sema/SemaExpr.cpp (+2) - (modified) clang/lib/Sema/SemaExprCXX.cpp (+5-1) - (modified) clang/lib/Sema/SemaInit.cpp (+2-2) - (modified) clang/lib/Sema/SemaOverload.cpp (+5-1) - (modified) clang/lib/Sema/SemaStmt.cpp (+2) - (modified) clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp (+2) - (modified) clang/lib/StaticAnalyzer/Core/SValBuilder.cpp (+2) - (added) clang/test/AST/ast-dump-function-pointer-conversion.cpp (+30) - (modified) clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p4-ast.cpp (+2-2) ``diff diff --git a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp index 8989444dde1300..acb7112fa2abed 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SwappedArgumentsCheck.cpp @@ -27,6 +27,8 @@ void SwappedArgumentsCheck::registerMatchers(MatchFinder *Finder) { static const Expr *ignoreNoOpCasts(const Expr *E) { if (auto *Cast = dyn_cast(E)) if (Cast->getCastKind() == CK_LValueToRValue || +Cast->getCastKind() == CK_FunctionPointerConversion || +Cast->getCastKind() == CK_MemberFunctionPointerConversion || Cast->getCastKind() == CK_NoOp) return ignoreNoOpCasts(Cast->getSubExpr()); return E; diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp index 5e255dcaacd262..bab08496e90e86 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp @@ -90,7 +90,9 @@ void ProTypeCstyleCastCheck::check(const MatchFinder::MatchResult &Result) { return; } - if (MatchedCast->getCastKind() == CK_NoOp && + if ((MatchedCast->getCastKind() == CK_NoOp || + MatchedCast->getCastKind() == CK_FunctionPointerConversion || + MatchedCast->getCastKind() == CK_MemberFunctionPointerConversion) && needsConstCast(SourceType, MatchedCast->getType())) { diag(MatchedCast->getBeginLoc(), "do not use C-style cast to cast away constness"); diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp index 3109bbb3724c79..888f7b122b82c3 100644 --- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp +++ b/clang-tools-extra/clang
[clang] [clang-tools-extra] [NFC] Add implicit cast kinds for function pointer conversions (PR #110048)
https://github.com/ahatanak ready_for_review https://github.com/llvm/llvm-project/pull/110048 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Bugfixes and improved support for `AttributedType`s in lambdas (PR #85325)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-sie-ubuntu-fast` running on `sie-linux-worker` while building `clang` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/8001 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'Clang :: SemaCXX/lambda-attributes.cpp' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/20/include -nostdsysteminc -std=c++23 -fsyntax-only -verify /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/lambda-attributes.cpp + /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/20/include -nostdsysteminc -std=c++23 -fsyntax-only -verify /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/lambda-attributes.cpp error: 'expected-error' diagnostics seen but not expected: File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/lambda-attributes.cpp Line 18: 'preserve_most' calling convention is not supported for this target File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/lambda-attributes.cpp Line 29: 'preserve_most' calling convention is not supported for this target File /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/SemaCXX/lambda-attributes.cpp Line 40: 'preserve_most' calling convention is not supported for this target Line 45: 'preserve_most' calling convention is not supported for this target Line 48: 'preserve_most' calling convention is not supported for this target Line 53: 'preserve_most' calling convention is not supported for this target 6 errors generated. -- ``` https://github.com/llvm/llvm-project/pull/85325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Bugfixes and improved support for `AttributedType`s in lambdas (PR #85325)
Sirraide wrote: Forgot to set the target again it seems; will be fixing that in a moment https://github.com/llvm/llvm-project/pull/85325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Remove `__builtin_hlsl_create_handle` (PR #109910)
llvmbot wrote: @llvm/pr-subscribers-hlsl @llvm/pr-subscribers-clang Author: Helena Kotas (hekota) Changes The `__builtin_hlsl_create_handle` called from the constructor of resource buffer class was supposed to initialize the resource handle based on resource type and registry binding information. It is not possible to do though that because the registry binding information is not accessible from the constructor during codegen. Instead, the handle should be initialized to an empty or null handle with something like `__builtin_hlsl_create_null_handle`. This PR is removing `__builtin_hlsl_create_handle` first and the `__builtin_hlsl_create_null_handle` will be added to the constructor once the handle type changes to `__hlsl_resource_t` and HLSLAttributeResourceType is updated to be a canonical type, which will allow the initialization assignment. The actual handle initialization based on the registry binding will be implemented part 2/2 of llvm/llvm-project#105076 once the dependent tasks are completed. Part 1/2 of llvm/llvm-project#105076. --- Full diff: https://github.com/llvm/llvm-project/pull/109910.diff 11 Files Affected: - (modified) clang/include/clang/Basic/Builtins.td (-6) - (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+2-30) - (modified) clang/test/AST/HLSL/RWBuffer-AST.hlsl (+1-1) - (modified) clang/test/AST/HLSL/StructuredBuffer-AST.hlsl (+1-1) - (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl (+7-1) - (modified) clang/test/CodeGenHLSL/builtins/StructuredBuffer-constructor.hlsl (+7) - (removed) clang/test/CodeGenHLSL/builtins/create_handle.hlsl (-7) - (modified) clang/test/ParserHLSL/hlsl_resource_handle_attrs.hlsl (+2-2) - (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (-3) - (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (-2) - (modified) llvm/unittests/IR/IntrinsicsTest.cpp (-1) ``diff diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..33791270800c9d 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4703,12 +4703,6 @@ def HLSLClamp : LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } -def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> { - let Spellings = ["__builtin_hlsl_create_handle"]; - let Attributes = [NoThrow, Const]; - let Prototype = "void*(unsigned char)"; -} - def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_dot"]; let Attributes = [NoThrow, Const]; diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index d19f79b6ddefcd..ca521dc0bcd26b 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -193,36 +193,8 @@ struct BuiltinTypeDeclBuilder { ExplicitSpecifier(), false, true, false, ConstexprSpecKind::Unspecified); -DeclRefExpr *Fn = -lookupBuiltinFunction(AST, S, "__builtin_hlsl_create_handle"); -Expr *RCExpr = emitResourceClassExpr(AST, RC); -Expr *Call = CallExpr::Create(AST, Fn, {RCExpr}, AST.VoidPtrTy, VK_PRValue, - SourceLocation(), FPOptionsOverride()); - -CXXThisExpr *This = CXXThisExpr::Create( -AST, SourceLocation(), Constructor->getFunctionObjectParameterType(), -true); -Expr *Handle = MemberExpr::CreateImplicit(AST, This, false, Fields["h"], - Fields["h"]->getType(), VK_LValue, - OK_Ordinary); - -// If the handle isn't a void pointer, cast the builtin result to the -// correct type. -if (Handle->getType().getCanonicalType() != AST.VoidPtrTy) { - Call = CXXStaticCastExpr::Create( - AST, Handle->getType(), VK_PRValue, CK_Dependent, Call, nullptr, - AST.getTrivialTypeSourceInfo(Handle->getType(), SourceLocation()), - FPOptionsOverride(), SourceLocation(), SourceLocation(), - SourceRange()); -} - -BinaryOperator *Assign = BinaryOperator::Create( -AST, Handle, Call, BO_Assign, Handle->getType(), VK_LValue, OK_Ordinary, -SourceLocation(), FPOptionsOverride()); - -Constructor->setBody( -CompoundStmt::Create(AST, {Assign}, FPOptionsOverride(), - SourceLocation(), SourceLocation())); +Constructor->setBody(CompoundStmt::Create( +AST, {}, FPOptionsOverride(), SourceLocation(), SourceLocation())); Constructor->setAccess(AccessSpecifier::AS_public); Record->addDecl(Constructor); return *this; diff --git a/clang/test/AST/HLSL/RWBuffer-AST.hlsl b/clang/test/AST/HLSL/RWBuffer-AST.hlsl index c3ba520e0f68e4..a95be63da5dc17 100644 --- a/clang/test/AST/HLSL/RWBuffer-AST.hlsl +++ b/clang/test/AST/HLSL/RWBuffer-AST.hlsl @@ -66,7 +66,7 @@ RWBuffer Buffer; // CHECK: TemplateArgument type 'float' // CHECK-NEXT: BuiltinType 0
[clang] [Clang] Set target in test (PR #110068)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (Sirraide) Changes I forgot to set the target for a test that uses the `preserve_most` cc and it’s breaking the bots. --- Full diff: https://github.com/llvm/llvm-project/pull/110068.diff 1 Files Affected: - (modified) clang/test/SemaCXX/lambda-attributes.cpp (+4-4) ``diff diff --git a/clang/test/SemaCXX/lambda-attributes.cpp b/clang/test/SemaCXX/lambda-attributes.cpp index 799649719cf42b..97d23053b0f46a 100644 --- a/clang/test/SemaCXX/lambda-attributes.cpp +++ b/clang/test/SemaCXX/lambda-attributes.cpp @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s -// RUN: %clang_cc1 -std=c++23 -fsyntax-only -ast-dump %s | FileCheck %s -// RUN: %clang_cc1 -std=c++23 -triple x86_64-pc-linux -emit-pch -o %t %s -// RUN: %clang_cc1 -x c++ -std=c++23 -triple x86_64-pc-linux -include-pch %t -ast-dump-all /dev/null | FileCheck %s +// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-linux -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-linux -fsyntax-only -ast-dump %s | FileCheck %s +// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-linux -emit-pch -o %t %s +// RUN: %clang_cc1 -x c++ -std=c++23 -triple x86_64-unknown-linux -include-pch %t -ast-dump-all /dev/null | FileCheck %s // expected-no-diagnostics // Check that we both don't crash on transforming FunctionProtoType's `` https://github.com/llvm/llvm-project/pull/110068 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Set target in test (PR #110068)
https://github.com/Sirraide created https://github.com/llvm/llvm-project/pull/110068 I forgot to set the target for a test that uses the `preserve_most` cc and it’s breaking the bots. >From 1b1a9b7c03383bb7fc58f62a81272dfa0ee30b83 Mon Sep 17 00:00:00 2001 From: Sirraide Date: Thu, 26 Sep 2024 03:47:39 +0200 Subject: [PATCH] [Clang] Set target in test --- clang/test/SemaCXX/lambda-attributes.cpp | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/test/SemaCXX/lambda-attributes.cpp b/clang/test/SemaCXX/lambda-attributes.cpp index 799649719cf42b..97d23053b0f46a 100644 --- a/clang/test/SemaCXX/lambda-attributes.cpp +++ b/clang/test/SemaCXX/lambda-attributes.cpp @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s -// RUN: %clang_cc1 -std=c++23 -fsyntax-only -ast-dump %s | FileCheck %s -// RUN: %clang_cc1 -std=c++23 -triple x86_64-pc-linux -emit-pch -o %t %s -// RUN: %clang_cc1 -x c++ -std=c++23 -triple x86_64-pc-linux -include-pch %t -ast-dump-all /dev/null | FileCheck %s +// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-linux -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-linux -fsyntax-only -ast-dump %s | FileCheck %s +// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-linux -emit-pch -o %t %s +// RUN: %clang_cc1 -x c++ -std=c++23 -triple x86_64-unknown-linux -include-pch %t -ast-dump-all /dev/null | FileCheck %s // expected-no-diagnostics // Check that we both don't crash on transforming FunctionProtoType's ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Remove `__builtin_hlsl_create_handle` (PR #109910)
https://github.com/hekota ready_for_review https://github.com/llvm/llvm-project/pull/109910 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2b0a708 - [Clang] Set target in test (#110068)
Author: Sirraide Date: 2024-09-26T03:48:26+02:00 New Revision: 2b0a708f41dd6291ee744704d43febc975e3d026 URL: https://github.com/llvm/llvm-project/commit/2b0a708f41dd6291ee744704d43febc975e3d026 DIFF: https://github.com/llvm/llvm-project/commit/2b0a708f41dd6291ee744704d43febc975e3d026.diff LOG: [Clang] Set target in test (#110068) I forgot to set the target for a test that uses the `preserve_most` cc and it’s breaking the bots. Added: Modified: clang/test/SemaCXX/lambda-attributes.cpp Removed: diff --git a/clang/test/SemaCXX/lambda-attributes.cpp b/clang/test/SemaCXX/lambda-attributes.cpp index 799649719cf42b..97d23053b0f46a 100644 --- a/clang/test/SemaCXX/lambda-attributes.cpp +++ b/clang/test/SemaCXX/lambda-attributes.cpp @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s -// RUN: %clang_cc1 -std=c++23 -fsyntax-only -ast-dump %s | FileCheck %s -// RUN: %clang_cc1 -std=c++23 -triple x86_64-pc-linux -emit-pch -o %t %s -// RUN: %clang_cc1 -x c++ -std=c++23 -triple x86_64-pc-linux -include-pch %t -ast-dump-all /dev/null | FileCheck %s +// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-linux -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-linux -fsyntax-only -ast-dump %s | FileCheck %s +// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-linux -emit-pch -o %t %s +// RUN: %clang_cc1 -x c++ -std=c++23 -triple x86_64-unknown-linux -include-pch %t -ast-dump-all /dev/null | FileCheck %s // expected-no-diagnostics // Check that we both don't crash on transforming FunctionProtoType's ___ 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)
@@ -7326,11 +7326,13 @@ void ItaniumMangleContextImpl::mangleCXXCtorVTable(const CXXRecordDecl *RD, raw_ostream &Out) { // ::= TC _ CXXNameMangler Mangler(*this, Out); + QualType RDType = getASTContext().getRecordType(RD); + QualType TypeType = getASTContext().getRecordType(Type); Mangler.getStream() << "_ZTC"; - Mangler.mangleNameOrStandardSubstitution(RD); + Mangler.mangleType(RDType); tcwzxx wrote: > I can't find this production in the ItaniumABI docs, but if the comment is > right, I think performing this substitution is correct. I also can't find any Itanium ABI documentation, but I found that GCC follows the same process. So, I believe the comment is correct, and it is necessary to perform the substitution for RD. 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][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
@@ -224,6 +225,34 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts, else Builder.defineMacro("__riscv_32e"); } + + if (Opts.CFProtectionBranch) { +if (checkCFProtectionBranchSupported()) { + auto Scheme = Opts.getCFBranchLabelScheme(); + if (checkCFBranchLabelSchemeSupported(Scheme)) { +if (Scheme == CFBranchLabelSchemeKind::Default) + Scheme = getDefaultCFBranchLabelScheme(); + +Builder.defineMacro("__riscv_landing_pad", "1"); +switch (Scheme) { +case CFBranchLabelSchemeKind::Unlabeled: + Builder.defineMacro("__riscv_landing_pad_unlabeled", "1"); + break; +case CFBranchLabelSchemeKind::FuncSig: + Builder.defineMacro("__riscv_landing_pad_func_sig", "1"); + break; +case CFBranchLabelSchemeKind::Default: + llvm_unreachable("default cf-branch-label scheme should already be " + "transformed to other scheme"); +} + } else +Diags.Report(diag::err_opt_not_valid_on_target) +<< (Twine("-mcf-branch-label-scheme=") + +getCFBranchLabelSchemeFlagVal(Scheme)) + .str(); +} else + Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch"; mylai-mtk wrote: Yes, if it's `clang -c` or `clang -S`, I believe it would be diagnosed in `CodeGenModule`, but if it's `clang -E -dM`, it wouldn't be diagnosed, since code gen is not required. https://github.com/llvm/llvm-project/pull/109600 ___ 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)
@@ -7326,11 +7326,13 @@ void ItaniumMangleContextImpl::mangleCXXCtorVTable(const CXXRecordDecl *RD, raw_ostream &Out) { // ::= TC _ CXXNameMangler Mangler(*this, Out); + QualType RDType = getASTContext().getRecordType(RD); + QualType TypeType = getASTContext().getRecordType(Type); Mangler.getStream() << "_ZTC"; - Mangler.mangleNameOrStandardSubstitution(RD); + Mangler.mangleType(RDType); tcwzxx wrote: > I'd prefer we fix `mangleNameOrStandardSubstitution` itself. > We could rename it to `mangleCXXRecordDecl`, have it take a CXXRecordDecl*, > and handle the substitutions there. > This would avoid the same trap in a potential future user. After rechecking the code, I found that the users of the `mangleNameOrStandardSubstitution` function are `mangleCXXCtorVTable`, `mangleCXXVTable`, and `mangleCXXVTT`. In the Itanium ABI documentation, these situations are considered as 'Type'. So, maybe we can remove `mangleNameOrStandardSubstitution` and then use `mangleType`. 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][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
mylai-mtk wrote: > It is useful to protect a binary with an -mcpu that doesn't support Zicfilp. Generally I would agree that it's a good idea to protect a binary with an `-mcpu` that doesn't support Zicfilp, but to lift the check of Zicfilp would be misleading to naive compiler/RISC-V users who don't know that only with a system fully aware of Zicfilp, the protection of `-fcf-protection=branch` can be expected. I think from this perspective, compilers should at least warn the user if he asks for a feature that is known to be broken with his environment. @kito-cheng I need your input on this, since this would require a few updates on various PRs to the RISC-V specs. https://github.com/llvm/llvm-project/pull/109600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Allow resource type attributes only on __hlsl_resource_t (PR #110079)
https://github.com/hekota created https://github.com/llvm/llvm-project/pull/110079 Resource type attributes should only ever be used on the intangible type `__hlsl_resource_t`. This is a draft that also includes changes from PR llvm/llvm-project#109910. >From 970aab0a930e38dfd266c01065112602bb274a5e Mon Sep 17 00:00:00 2001 From: Helena Kotas Date: Wed, 25 Sep 2024 15:48:18 -0700 Subject: [PATCH 1/2] [HLSL] Allow resource type attributes only on __hlsl_resource_t --- clang/include/clang/AST/Type.h| 4 +- .../clang/Basic/DiagnosticSemaKinds.td| 1 + clang/include/clang/Sema/SemaHLSL.h | 2 +- clang/lib/AST/ASTContext.cpp | 4 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 72 +-- clang/lib/Sema/SemaHLSL.cpp | 10 ++- clang/lib/Sema/SemaType.cpp | 2 +- clang/test/AST/HLSL/RWBuffer-AST.hlsl | 22 ++ clang/test/AST/HLSL/StructuredBuffer-AST.hlsl | 22 ++ .../CodeGenHLSL/buffer-array-operator.hlsl| 3 + .../implicit-norecurse-attrib.hlsl| 2 +- .../hlsl_contained_type_attr_error.hlsl | 4 ++ .../ParserHLSL/hlsl_is_rov_attr_error.hlsl| 4 ++ .../hlsl_raw_buffer_attr_error.hlsl | 4 ++ .../hlsl_resource_class_attr_error.hlsl | 3 + .../hlsl_resource_handle_attrs.hlsl | 6 +- .../Types/Traits/IsIntangibleType.hlsl| 3 + 17 files changed, 85 insertions(+), 83 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index dc87b84153e74a..67e75652a16649 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -6191,7 +6191,9 @@ class HLSLAttributedResourceType : public Type, public llvm::FoldingSetNode { HLSLAttributedResourceType(QualType Canon, QualType Wrapped, QualType Contained, const Attributes &Attrs) - : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()), + : Type(HLSLAttributedResource, Canon, + Contained.isNull() ? TypeDependence::None +: Contained->getDependence()), WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {} public: diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index e4e04bff8b5120..a9b2042fcff4e3 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12394,6 +12394,7 @@ def err_hlsl_packoffset_alignment_mismatch : Error<"packoffset at 'y' not match def err_hlsl_pointers_unsupported : Error< "%select{pointers|references}0 are unsupported in HLSL">; def err_hlsl_missing_resource_class : Error<"HLSL resource needs to have [[hlsl::resource_class()]] attribute">; +def err_hlsl_attribute_needs_intangible_type: Error<"attribute %0 can be used only on HLSL intangible type %1">; def err_hlsl_operator_unsupported : Error< "the '%select{&|*|->}0' operator is unsupported in HLSL">; diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index e088254c566d3e..311cd58bbcac2c 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -70,7 +70,7 @@ class SemaHLSL : public SemaBase { void handleShaderAttr(Decl *D, const ParsedAttr &AL); void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL); void handleParamModifierAttr(Decl *D, const ParsedAttr &AL); - bool handleResourceTypeAttr(const ParsedAttr &AL); + bool handleResourceTypeAttr(QualType T, const ParsedAttr &AL); bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); QualType ProcessResourceTypeAttributes(QualType Wrapped); diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index fd8aa8de79b49f..ced18e1617e248 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2272,8 +2272,8 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { #include "clang/Basic/AMDGPUTypes.def" #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id: #include "clang/Basic/HLSLIntangibleTypes.def" - Width = 0; - Align = 8; + Width = Target->getPointerWidth(LangAS::Default); + Align = Target->getPointerAlign(LangAS::Default); break; } break; diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index d19f79b6ddefcd..e72da9a071fb71 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -117,33 +117,30 @@ struct BuiltinTypeDeclBuilder { if (Record->isCompleteDefinition()) return *this; +ASTContext &Ctx = S.getASTContext(); TypeSourceInfo *ElementTypeInfo = nullptr; -QualType Ty = Record->getASTContext().VoidPtrTy; +QualType ElemTy = Ctx.Char8Ty; if (Template) { if (const auto *TTD = dyn_cast(
[clang] [llvm] [HLSL] Allow resource type attributes only on __hlsl_resource_t (PR #110079)
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 e7d68c903be0d813be96954b274e65e58c42e5e4 71c4a9361f07a606c95eb5232be50dcdff31c422 --extensions cpp,h -- clang/include/clang/AST/Type.h clang/include/clang/Sema/SemaHLSL.h clang/lib/AST/ASTContext.cpp clang/lib/Sema/HLSLExternalSemaSource.cpp clang/lib/Sema/SemaHLSL.cpp clang/lib/Sema/SemaType.cpp llvm/unittests/IR/IntrinsicsTest.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index b6bd8e778a..e295fc9ef3 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -256,17 +256,21 @@ struct BuiltinTypeDeclBuilder { // FIXME: Placeholder to make sure we return the correct type - create // field of element_type and return reference to it. This field will go -// away once indexing into resources is properly implemented in +// away once indexing into resources is properly implemented in // llvm/llvm-project#95956. if (Fields.count("e") == 0) { addMemberVariable("e", ElemTy, {}); } FieldDecl *ElemFieldDecl = Fields["e"]; - -auto *This = CXXThisExpr::Create(AST, SourceLocation(), MethodDecl->getFunctionObjectParameterType(),true); -Expr *ElemField = MemberExpr::CreateImplicit(AST, This, false, ElemFieldDecl, - ElemFieldDecl->getType(), VK_LValue,OK_Ordinary); -auto *Return = ReturnStmt::Create(AST, SourceLocation(), ElemField, nullptr); + +auto *This = +CXXThisExpr::Create(AST, SourceLocation(), +MethodDecl->getFunctionObjectParameterType(), true); +Expr *ElemField = MemberExpr::CreateImplicit( +AST, This, false, ElemFieldDecl, ElemFieldDecl->getType(), VK_LValue, +OK_Ordinary); +auto *Return = +ReturnStmt::Create(AST, SourceLocation(), ElemField, nullptr); MethodDecl->setBody(CompoundStmt::Create(AST, {Return}, FPOptionsOverride(), SourceLocation(), `` https://github.com/llvm/llvm-project/pull/110079 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
kito-cheng wrote: > @kito-cheng I need your input on this, since this would require a few updates > on various PRs to the RISC-V specs. Yeah, I just chat with Craig, I think that right way to go, and actually the PR in riscv-toolchain-conventions I has implicitly allow that, I mean I only write `-fcf-protection=return` require `zimop`, and didn't say `-fcf-protection=branch` require `zicfilp`, so yeah, go ahead to drop the requirement of `zicfilp`, Craig and me will fix that on the back-end side :P [1] https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/54 https://github.com/llvm/llvm-project/pull/109600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Allow resource type attributes only on __hlsl_resource_t (PR #110079)
https://github.com/hekota updated https://github.com/llvm/llvm-project/pull/110079 >From 970aab0a930e38dfd266c01065112602bb274a5e Mon Sep 17 00:00:00 2001 From: Helena Kotas Date: Wed, 25 Sep 2024 15:48:18 -0700 Subject: [PATCH 1/3] [HLSL] Allow resource type attributes only on __hlsl_resource_t --- clang/include/clang/AST/Type.h| 4 +- .../clang/Basic/DiagnosticSemaKinds.td| 1 + clang/include/clang/Sema/SemaHLSL.h | 2 +- clang/lib/AST/ASTContext.cpp | 4 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 72 +-- clang/lib/Sema/SemaHLSL.cpp | 10 ++- clang/lib/Sema/SemaType.cpp | 2 +- clang/test/AST/HLSL/RWBuffer-AST.hlsl | 22 ++ clang/test/AST/HLSL/StructuredBuffer-AST.hlsl | 22 ++ .../CodeGenHLSL/buffer-array-operator.hlsl| 3 + .../implicit-norecurse-attrib.hlsl| 2 +- .../hlsl_contained_type_attr_error.hlsl | 4 ++ .../ParserHLSL/hlsl_is_rov_attr_error.hlsl| 4 ++ .../hlsl_raw_buffer_attr_error.hlsl | 4 ++ .../hlsl_resource_class_attr_error.hlsl | 3 + .../hlsl_resource_handle_attrs.hlsl | 6 +- .../Types/Traits/IsIntangibleType.hlsl| 3 + 17 files changed, 85 insertions(+), 83 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index dc87b84153e74a..67e75652a16649 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -6191,7 +6191,9 @@ class HLSLAttributedResourceType : public Type, public llvm::FoldingSetNode { HLSLAttributedResourceType(QualType Canon, QualType Wrapped, QualType Contained, const Attributes &Attrs) - : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()), + : Type(HLSLAttributedResource, Canon, + Contained.isNull() ? TypeDependence::None +: Contained->getDependence()), WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {} public: diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index e4e04bff8b5120..a9b2042fcff4e3 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12394,6 +12394,7 @@ def err_hlsl_packoffset_alignment_mismatch : Error<"packoffset at 'y' not match def err_hlsl_pointers_unsupported : Error< "%select{pointers|references}0 are unsupported in HLSL">; def err_hlsl_missing_resource_class : Error<"HLSL resource needs to have [[hlsl::resource_class()]] attribute">; +def err_hlsl_attribute_needs_intangible_type: Error<"attribute %0 can be used only on HLSL intangible type %1">; def err_hlsl_operator_unsupported : Error< "the '%select{&|*|->}0' operator is unsupported in HLSL">; diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index e088254c566d3e..311cd58bbcac2c 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -70,7 +70,7 @@ class SemaHLSL : public SemaBase { void handleShaderAttr(Decl *D, const ParsedAttr &AL); void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL); void handleParamModifierAttr(Decl *D, const ParsedAttr &AL); - bool handleResourceTypeAttr(const ParsedAttr &AL); + bool handleResourceTypeAttr(QualType T, const ParsedAttr &AL); bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); QualType ProcessResourceTypeAttributes(QualType Wrapped); diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index fd8aa8de79b49f..ced18e1617e248 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2272,8 +2272,8 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { #include "clang/Basic/AMDGPUTypes.def" #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id: #include "clang/Basic/HLSLIntangibleTypes.def" - Width = 0; - Align = 8; + Width = Target->getPointerWidth(LangAS::Default); + Align = Target->getPointerAlign(LangAS::Default); break; } break; diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index d19f79b6ddefcd..e72da9a071fb71 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -117,33 +117,30 @@ struct BuiltinTypeDeclBuilder { if (Record->isCompleteDefinition()) return *this; +ASTContext &Ctx = S.getASTContext(); TypeSourceInfo *ElementTypeInfo = nullptr; -QualType Ty = Record->getASTContext().VoidPtrTy; +QualType ElemTy = Ctx.Char8Ty; if (Template) { if (const auto *TTD = dyn_cast( Template->getTemplateParameters()->getParam(0))) { -Ty = Record->getASTContext().getPointerType( -QualType(TTD->getTypeForDecl(), 0)); -
[clang] [flang] [llvm] [flang][driver] rename flang-new to flang (PR #110023)
mjklemm wrote: I have seen some more matches for flang-new in the tree: ``` 1:.github/workflows/release-binaries.yml:331: ninja -C ${{ steps.setup-stage.outputs.build-prefix }}/build/tools/clang/stage2-bins/ -j2 flang-new bbc 2:openmp/CMakeLists.txt:72:set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang-new) 3:openmp/CMakeLists.txt:74:set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang-new.exe) ``` Since I'm travelling, I haven't dug any further at this point. 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] [Clang] [NFC] Introduce `DynamicRecursiveASTVisitor` (PR #105195)
Sirraide wrote: Closing this to split it up into multiple prs. https://github.com/llvm/llvm-project/pull/105195 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [NFC] Introduce `DynamicRecursiveASTVisitor` (PR #105195)
https://github.com/Sirraide closed https://github.com/llvm/llvm-project/pull/105195 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Make PCH's respect any VFS specified. (PR #106577)
sheredom wrote: > > If the goal is to put virtual paths in the PCH so that you can map them > > somewhere else in the consuming compiler's VFS, does > > the`RedirectingFileSystem` setting `'use-external-names': false` do what > > you need? The idea behind that setting is that we would use the virtual > > paths everywhere in the compiler instead of translating them to the > > external/on-disk path. I don't have a lot of experience with enabling that > > in modules/pch so maybe there's something that it doesn't handle. > > I'll have a look at that and get back to you! Ok we tested this and it doesn't work as expected - the generated PCH still has the original paths baked into it. https://github.com/llvm/llvm-project/pull/106577 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] adding clang codegen (PR #109331)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/109331 >From 50d21754119ac10c2ee2376ed8f79d12f73cd137 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Thu, 19 Sep 2024 00:13:51 + Subject: [PATCH 1/3] Codegen builtin --- clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 38 clang/lib/CodeGen/CGCall.cpp | 5 ++ clang/lib/CodeGen/CGExpr.cpp | 15 - clang/lib/CodeGen/CodeGenFunction.h | 10 +++- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 20 +++ clang/lib/Sema/SemaHLSL.cpp | 58 --- .../builtins/asuint-splitdouble.hlsl | 10 llvm/include/llvm/IR/IntrinsicsDirectX.td | 5 ++ llvm/lib/Target/DirectX/DXIL.td | 1 + .../Target/DirectX/DXILIntrinsicExpansion.cpp | 13 + 11 files changed, 167 insertions(+), 14 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/asuint-splitdouble.hlsl diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..b38957f6e3f15d 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4788,6 +4788,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLAsUintSplitDouble: LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_asuint_splitdouble"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + // Builtins for XRay. def XRayCustomEvent : Builtin { let Spellings = ["__xray_customevent"]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 249aead33ad73d..f7695b8693f3dc 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18843,6 +18843,44 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: { retType, CGM.getHLSLRuntime().getSignIntrinsic(), ArrayRef{Op0}, nullptr, "hlsl.sign"); } + // This should only be called when targeting DXIL + case Builtin::BI__builtin_hlsl_asuint_splitdouble: { + +assert((E->getArg(0)->getType()->hasFloatingRepresentation() && +E->getArg(1)->getType()->hasUnsignedIntegerRepresentation() && +E->getArg(2)->getType()->hasUnsignedIntegerRepresentation()) && + "asuint operands types mismatch"); + +Value *Op0 = EmitScalarExpr(E->getArg(0)); +const HLSLOutArgExpr *OutArg1 = dyn_cast(E->getArg(1)); +const HLSLOutArgExpr *OutArg2 = dyn_cast(E->getArg(2)); + +CallArgList Args; +LValue Op1TmpLValue = EmitHLSLOutArgExpr(OutArg1, Args, OutArg1->getType()); +LValue Op2TmpLValue = EmitHLSLOutArgExpr(OutArg2, Args, OutArg2->getType()); + +llvm::Type *retType = llvm::StructType::get(Int32Ty, Int32Ty); +if (Op0->getType()->isVectorTy()) { + auto *XVecTy = E->getArg(0)->getType()->getAs(); + + llvm::VectorType *i32VecTy = llvm::VectorType::get( + Int32Ty, ElementCount::getFixed(XVecTy->getNumElements())); + + retType = llvm::StructType::get(i32VecTy, i32VecTy); +} + +CallInst *CI = +Builder.CreateIntrinsic(retType, llvm::Intrinsic::dx_asuint_splitdouble, +{Op0}, nullptr, "hlsl.asuint"); + +Value *arg0 = Builder.CreateExtractValue(CI, 0); +Value *arg1 = Builder.CreateExtractValue(CI, 1); + +Builder.CreateStore(arg0, Op1TmpLValue.getAddress()); +auto *s = Builder.CreateStore(arg1, Op2TmpLValue.getAddress()); +EmitWritebacks(*this, Args); +return s; + } } return nullptr; } diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 4ae981e4013e9c..096bbafa4cc694 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -4681,6 +4681,11 @@ void CallArg::copyInto(CodeGenFunction &CGF, Address Addr) const { IsUsed = true; } +void CodeGenFunction::EmitWritebacks(CodeGenFunction &CGF, + const CallArgList &args) { + emitWritebacks(CGF, args); +} + void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E, QualType type) { DisableDebugLocationUpdates Dis(*this, E); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 9166db4c74128c..1c299c4a932ca0 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -19,6 +19,7 @@ #include "CGObjCRuntime.h" #include "CGOpenMPRuntime.h" #include "CGRecordLayout.h" +#include "CGValue.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "ConstantEmitter.h" @@ -28,6 +29,7 @@ #include "clang/AST/DeclObjC.h" #include "clang/AST/NSAPI.h" #include "clang/AST/StmtVisitor.h" +#include "clang/AST/Type.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/CodeGenOptions.h" #include "clang/Basic/SourceManager.h" @@ -5458,9 +5460,8 @@ LValue CodeGenFunction::EmitOpaqueValueLValu
[clang] 639a0af - Revert "Deprecate the `-fbasic-block-sections=labels` option. (#107494)"
Author: Kazu Hirata Date: 2024-09-25T12:34:43-07:00 New Revision: 639a0afa9955a8613902e46e168767bc05c46cdd URL: https://github.com/llvm/llvm-project/commit/639a0afa9955a8613902e46e168767bc05c46cdd DIFF: https://github.com/llvm/llvm-project/commit/639a0afa9955a8613902e46e168767bc05c46cdd.diff LOG: Revert "Deprecate the `-fbasic-block-sections=labels` option. (#107494)" This reverts commit 1911a50fae8a441b445eb835b98950710d28fc88. Several bots are failing: https://lab.llvm.org/buildbot/#/builders/190/builds/6519 https://lab.llvm.org/buildbot/#/builders/3/builds/5248 https://lab.llvm.org/buildbot/#/builders/18/builds/4463 Added: llvm/test/CodeGen/X86/basic-block-labels-mir-parse.mir llvm/test/CodeGen/X86/basic-block-sections-labels-empty-block.ll llvm/test/CodeGen/X86/basic-block-sections-labels-empty-function.ll llvm/test/CodeGen/X86/basic-block-sections-labels-pgo-features.ll Modified: clang/docs/UsersManual.rst clang/include/clang/Basic/CodeGenOptions.h clang/include/clang/Driver/Options.td clang/lib/CodeGen/BackendUtil.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/fbasic-block-sections.c llvm/docs/CommandGuide/llvm-objdump.rst llvm/docs/Extensions.rst llvm/include/llvm/CodeGen/MachineFunction.h llvm/include/llvm/Target/TargetOptions.h llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp llvm/lib/CodeGen/BasicBlockSections.cpp llvm/lib/CodeGen/CommandFlags.cpp llvm/lib/CodeGen/MIRParser/MIParser.cpp llvm/lib/CodeGen/MIRParser/MIRParser.cpp llvm/lib/CodeGen/MachineFunction.cpp llvm/test/CodeGen/X86/basic-block-address-map-function-sections.ll llvm/test/CodeGen/X86/basic-block-address-map.ll llvm/test/CodeGen/X86/basic-block-sections-mir-print.ll Removed: llvm/test/CodeGen/X86/basic-block-address-map-empty-block.ll llvm/test/CodeGen/X86/basic-block-address-map-empty-function.ll llvm/test/CodeGen/X86/basic-block-address-map-mir-parse.mir llvm/test/CodeGen/X86/basic-block-address-map-pgo-features.ll diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index 4f03388bc87bd0..57d78f867bab6e 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -2369,16 +2369,14 @@ are listed below. $ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o -.. option:: -f[no]-basic-block-address-map: - Emits a ``SHT_LLVM_BB_ADDR_MAP`` section which includes address offsets for each - basic block in the program, relative to the parent function address. - - -.. option:: -fbasic-block-sections=[all, list=, none] +.. option:: -fbasic-block-sections=[labels, all, list=, none] Controls how Clang emits text sections for basic blocks. With values ``all`` and ``list=``, each basic block or a subset of basic blocks can be placed - in its own unique section. + in its own unique section. With the "labels" value, normal text sections are + emitted, but a ``.bb_addr_map`` section is emitted which includes address + offsets for each basic block in the program, relative to the parent function + address. With the ``list=`` option, a file containing the subset of basic blocks that need to placed in unique sections can be specified. The format of the diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index 814d4d4c99e575..f2a707a8ba8d76 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -107,13 +107,18 @@ class CodeGenOptions : public CodeGenOptionsBase { // This field stores one of the allowed values for the option // -fbasic-block-sections=. The allowed values with this option are: - // {"all", "list=", "none"}. + // {"labels", "all", "list=", "none"}. // + // "labels": Only generate basic block symbols (labels) for all basic + //blocks, do not generate unique sections for basic blocks. + //Use the machine basic block id in the symbol name to + //associate profile info from virtual address to machine + //basic block. // "all" :Generate basic block sections for all basic blocks. // "list=": Generate basic block sections for a subset of basic blocks. //The functions and the machine basic block ids are specified //in the file. - // "none":Disable sections for basic blocks. + // "none":Disable sections/labels for basic blocks. std::string BBSections; // If set, override the default value of MCAsmInfo::BinutilsVersion. If diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index c22b07e9f8a6cb..23bd686a85f526 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/
[clang] [llvm] [alpha.webkit.NoUncheckedPtrMemberChecker] Introduce member variable checker for CheckedPtr/CheckedRef (PR #108352)
@@ -146,13 +149,67 @@ class NoUncountedMemberChecker BR->emitReport(std::move(Report)); haoNoQ wrote: `setDeclWithIssue()` goes into a different PR right? https://github.com/llvm/llvm-project/pull/108352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [alpha.webkit.NoUncheckedPtrMemberChecker] Introduce member variable checker for CheckedPtr/CheckedRef (PR #108352)
https://github.com/haoNoQ approved this pull request. LGTM!! I've got nitpicks but none of them are substantial enough to block. We've figured out the ObjC thing offline right? https://github.com/llvm/llvm-project/pull/108352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [alpha.webkit.NoUncheckedPtrMemberChecker] Introduce member variable checker for CheckedPtr/CheckedRef (PR #108352)
@@ -134,10 +137,10 @@ class NoUncountedMemberChecker Os << " in "; printQuotedQualifiedName(Os, ClassCXXRD); Os << " is a " - << (isa(MemberType) ? "raw pointer" : "reference") - << " to ref-countable type "; + << (isa(MemberType) ? "raw pointer" : "reference") << " to " + << typeName() << " "; printQuotedQualifiedName(Os, MemberCXXRD); haoNoQ wrote: Have you tried a simple `Os << MemberCXXRD` here? I think it even adds quotes automatically when you do that. But I don't remember if it works for arbitrary streams or only for clang warnings streams, so this might be completely misleading. https://github.com/llvm/llvm-project/pull/108352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [alpha.webkit.NoUncheckedPtrMemberChecker] Introduce member variable checker for CheckedPtr/CheckedRef (PR #108352)
@@ -146,13 +149,67 @@ class NoUncountedMemberChecker BR->emitReport(std::move(Report)); } }; + +class NoUncountedMemberChecker final : public RawPtrRefMemberChecker { haoNoQ wrote: Yes this is a perfectly valid way to reuse code here! https://github.com/llvm/llvm-project/pull/108352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [alpha.webkit.NoUncheckedPtrMemberChecker] Introduce member variable checker for CheckedPtr/CheckedRef (PR #108352)
https://github.com/haoNoQ edited https://github.com/llvm/llvm-project/pull/108352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [alpha.webkit.NoUncheckedPtrMemberChecker] Introduce member variable checker for CheckedPtr/CheckedRef (PR #108352)
@@ -53,48 +53,49 @@ hasPublicMethodInBase(const CXXBaseSpecifier *Base, const char *NameToMatch) { return hasPublicMethodInBaseClass(R, NameToMatch) ? R : nullptr; } -std::optional isRefCountable(const CXXRecordDecl* R) -{ +std::optional isSmartPtrCompatible(const CXXRecordDecl *R, + const char *IncMethodName, + const char *DecMethodName) { haoNoQ wrote: `StringRef`? Gotta start somewhere. Your static strings are implicitly convertible to that. https://github.com/llvm/llvm-project/pull/108352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [alpha.webkit.NoUncheckedPtrMemberChecker] Introduce member variable checker for CheckedPtr/CheckedRef (PR #108352)
@@ -0,0 +1,53 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.NoUncheckedPtrMemberChecker -verify %s + +#include "mock-types.h" +#include "mock-system-header.h" haoNoQ wrote: Do you need to include this one everywhere? Isn't it just a tiny test to confirm that some specific checker doesn't do something stupid in a system header? https://github.com/llvm/llvm-project/pull/108352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [alpha.webkit.NoUncheckedPtrMemberChecker] Introduce member variable checker for CheckedPtr/CheckedRef (PR #108352)
@@ -1771,6 +1771,10 @@ def UncountedLambdaCapturesChecker : Checker<"UncountedLambdaCapturesChecker">, let ParentPackage = WebKitAlpha in { +def NoUncheckedPtrMemberChecker : Checker<"NoUncheckedPtrMemberChecker">, + HelpText<"Check for no unchecked member variables.">, + Documentation; haoNoQ wrote: We can actually write a tiny bit of documentation that simply points the users to https://github.com/WebKit/WebKit/wiki/Safer-CPP-Guidelines (?) https://github.com/llvm/llvm-project/pull/108352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)
@@ -4719,8 +4719,9 @@ class FunctionEffect { NonBlocking = 1, Sirraide wrote: Something I only thought about just now: is `None` ever actually used? Otherwise, we should probably just remove it and start at 0 so we don’t have to do this `- 1` and `+ 1` dance below, because that seems like a recipe for disaster in terms of off-by-one errors. (Even if it is used, we should probably just use `std::optional` instead) https://github.com/llvm/llvm-project/pull/99656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)
@@ -0,0 +1,1572 @@ +//=== SemaFunctionEffects.cpp - Sema handling of function effects -===// +// +// 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 +// +//===--===// +// +// This file implements Sema handling of function effects. +// +//===--===// + +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/Type.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Sema/SemaInternal.h" + +#define DEBUG_TYPE "effectanalysis" + +using namespace clang; + +namespace { + +enum class ViolationID : uint8_t { + None = 0, // Sentinel for an empty Violation. + // These first few map to a %select{} in a diagnostic. + BaseDiagnosticIndex, + AllocatesMemory = BaseDiagnosticIndex, + ThrowsOrCatchesExceptions, + HasStaticLocalVariable, + AccessesThreadLocalVariable, + AccessesObjCMethodOrProperty, + + // These only apply to callees, where the analysis stops at the Decl. + DeclDisallowsInference, + + // These both apply to indirect calls. The difference is that sometimes + // we have an actual Decl (generally a variable) which is the function + // pointer being called, and sometimes, typically due to a cast, we only + // have an expression. + CallsDeclWithoutEffect, + CallsExprWithoutEffect, +}; + +// Information about the AST context in which a violation was found, so +// that diagnostics can point to the correct source. +class ViolationSite { +public: + enum class Kind : uint8_t { +Default = 0, // Function body. +MemberInitializer = 1, +DefaultArgExpr = 2 + }; + +private: + llvm::PointerIntPair Impl; + +public: + ViolationSite() = default; + + explicit ViolationSite(CXXDefaultArgExpr *E) + : Impl(E, Kind::DefaultArgExpr) {} + + Kind kind() const { return static_cast(Impl.getInt()); } + CXXDefaultArgExpr *defaultArgExpr() const { return Impl.getPointer(); } + + void setKind(Kind K) { Impl.setPointerAndInt(nullptr, K); } +}; + +// Represents a violation of the rules, potentially for the entire duration of +// the analysis phase, in order to refer to it when explaining why a caller has +// been made unsafe by a callee. Can be transformed into either a Diagnostic +// (warning or a note), depending on whether the violation pertains to a +// function failing to be verifed as holding an effect vs. a function failing to +// be inferred as holding that effect. +struct Violation { + FunctionEffect Effect; + FunctionEffect + CalleeEffectPreventingInference; // Only for certain IDs; can be None. + ViolationID ID = ViolationID::None; + ViolationSite Site; + SourceLocation Loc; + const Decl *Callee = nullptr; // Only valid for Calls*. + + Violation() = default; + + Violation(FunctionEffect Effect, ViolationID ID, ViolationSite VS, +SourceLocation Loc, const Decl *Callee = nullptr, +std::optional CalleeEffect = std::nullopt) + : Effect(Effect), CalleeEffectPreventingInference( +CalleeEffect.value_or(FunctionEffect())), +ID(ID), Site(VS), Loc(Loc), Callee(Callee) {} + + unsigned diagnosticSelectIndex() const { +return unsigned(ID) - unsigned(ViolationID::BaseDiagnosticIndex); + } +}; + +enum class SpecialFuncType : uint8_t { None, OperatorNew, OperatorDelete }; +enum class CallableType : uint8_t { + // Unknown: probably function pointer. + Unknown, + Function, + Virtual, + Block +}; + +// Return whether a function's effects CAN be verified. +// The question of whether it SHOULD be verified is independent. +static bool functionIsVerifiable(const FunctionDecl *FD) { + if (FD->isTrivial()) { +// Otherwise `struct x { int a; };` would have an unverifiable default +// constructor. +return true; + } + return FD->hasBody(); +} + +static bool isNoexcept(const FunctionDecl *FD) { + const auto *FPT = FD->getType()->castAs(); Sirraide wrote: Just checked and builtins are checked first before we do this, so that already covers `longjmp()`, but we should probably have a test for that (i.e. a C test with some builtin function that is `noreturn` and is correctly detected as `blocking`) https://github.com/llvm/llvm-project/pull/99656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits