[clang] [llvm] adding clang codegen (PR #109331)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/109331 >From 7bdad6254a6a5bc763ebcbb120f7ad73f598cb7d Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Thu, 19 Sep 2024 00:13:51 + Subject: [PATCH] adding clang codegen --- clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 40 + clang/lib/CodeGen/CGCall.cpp | 6 ++ 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 | 56 --- .../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, 169 insertions(+), 13 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 e2711f1ba70239..a39c34cae016b5 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18824,6 +18824,46 @@ 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()->isDoubleType() && +E->getArg(1)->getType()->isUnsignedIntegerType() && +E->getArg(2)->getType()->isUnsignedIntegerType()) && + "asuint operands types mismatch"); + +Value *Op0 = EmitScalarExpr(E->getArg(0)); +auto *OutArg1 = dyn_cast(E->getArg(1)); +auto *OutArg2 = dyn_cast(E->getArg(2)); + +CallArgList Args; +auto [Op1BaseLValue, Op1TmpLValue] = +EmitHLSLOutArgExpr(OutArg1, Args, OutArg1->getType()); +auto [Op2BaseLValue, 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..4581d06c7c12e5 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); @@ -4696,6 +4701,7 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E, // Add writeback for HLSLOutParamExpr. if (const HLSLOutArgExpr *OE = dyn_cast(E)) { EmitHLSLOutArgExpr(OE, args, type); +emitWritebacks(*this, args); return; } diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 35b5daaf6d4b55..abbf227e342b77 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -28,6 +28,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 +5459,8 @@ L
[clang] [clang-offload-bundler] Avoid repeated hash lookups (NFC) (PR #109507)
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/109507 None >From a08161a8308d724e7cf41ee0f603321ee6a121d4 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Fri, 20 Sep 2024 13:32:54 -0700 Subject: [PATCH] [clang-offload-bundler] Avoid repeated hash lookups (NFC) --- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp index e336417586f70b..0189fe5d56ab2a 100644 --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -349,11 +349,10 @@ int main(int argc, const char **argv) { // Standardize target names to include env field std::vector StandardizedTargetNames; for (StringRef Target : TargetNames) { -if (ParsedTargets.contains(Target)) { +if (!ParsedTargets.insert(Target).second) { reportError(createStringError(errc::invalid_argument, "Duplicate targets are not allowed")); } -ParsedTargets.insert(Target); auto OffloadInfo = OffloadTargetInfo(Target, BundlerConfig); bool KindIsValid = OffloadInfo.isOffloadKindValid(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Collect comments from function definitions into the index (PR #67802)
https://github.com/HighCommander4 approved this pull request. Thanks! The patch looks good to me. And the index size measurements reported in [this comment](https://github.com/llvm/llvm-project/pull/67802#issuecomment-1923778262) look good as well, thank you for taking them. https://github.com/llvm/llvm-project/pull/67802 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Collect comments from function definitions into the index (PR #67802)
https://github.com/HighCommander4 closed https://github.com/llvm/llvm-project/pull/67802 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Diagnose weak reads in final load (PR #109515)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/109515 They aren't allowed here either. >From bc5bbba9c0ab2aa19172d45b2fad628ec531bb8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 21 Sep 2024 08:28:52 +0200 Subject: [PATCH] [clang][bytecode] Diagnose weak reads in final load They aren't allowed here either. --- clang/lib/AST/ByteCode/Interp.cpp | 2 ++ clang/test/CodeGenCXX/weak-init.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 17cf3ccdeb6a94..65b4c0a9cb7660 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -620,6 +620,8 @@ bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { return false; if (!CheckTemporary(S, OpPC, Ptr, AK_Read)) return false; + if (!CheckWeak(S, OpPC, Ptr)) +return false; if (!CheckMutable(S, OpPC, Ptr)) return false; return true; diff --git a/clang/test/CodeGenCXX/weak-init.cpp b/clang/test/CodeGenCXX/weak-init.cpp index 634021f38f854c..d9b17d9ca74f87 100644 --- a/clang/test/CodeGenCXX/weak-init.cpp +++ b/clang/test/CodeGenCXX/weak-init.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s extern const int W __attribute__((weak)) = 99; const int S = 77; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Diagnose weak reads in final load (PR #109515)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes They aren't allowed here either. --- Full diff: https://github.com/llvm/llvm-project/pull/109515.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Interp.cpp (+2) - (modified) clang/test/CodeGenCXX/weak-init.cpp (+1) ``diff diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 17cf3ccdeb6a94..65b4c0a9cb7660 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -620,6 +620,8 @@ bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { return false; if (!CheckTemporary(S, OpPC, Ptr, AK_Read)) return false; + if (!CheckWeak(S, OpPC, Ptr)) +return false; if (!CheckMutable(S, OpPC, Ptr)) return false; return true; diff --git a/clang/test/CodeGenCXX/weak-init.cpp b/clang/test/CodeGenCXX/weak-init.cpp index 634021f38f854c..d9b17d9ca74f87 100644 --- a/clang/test/CodeGenCXX/weak-init.cpp +++ b/clang/test/CodeGenCXX/weak-init.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s extern const int W __attribute__((weak)) = 99; const int S = 77; `` https://github.com/llvm/llvm-project/pull/109515 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/109496 >From e7f7f82b25eaae86623ac8f47731892b3b629d7d Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Fri, 20 Sep 2024 16:27:09 -0700 Subject: [PATCH 1/3] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files - Fix a bug in UnsafeBufferUsage.cpp related to casting to PointerType - Suppress -Wunsafe-buffer-usage-in-libc-call for C files (rdar://117182250) --- clang/lib/Analysis/UnsafeBufferUsage.cpp | 8 +--- clang/lib/Sema/AnalysisBasedWarnings.cpp | 4 +++- .../warn-unsafe-buffer-usage-no-libc-functions-in-c.c| 9 + 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 clang/test/SemaCXX/warn-unsafe-buffer-usage-no-libc-functions-in-c.c diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp index a16762244b1766..110a121e71a7d2 100644 --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -250,7 +250,9 @@ AST_MATCHER_P(Stmt, ignoreUnsafeBufferInContainer, AST_MATCHER_P(Stmt, ignoreUnsafeLibcCall, const UnsafeBufferUsageHandler *, Handler) { - return Handler->ignoreUnsafeBufferInLibcCall(Node.getBeginLoc()); + if (Finder->getASTContext().getLangOpts().CPlusPlus) +return Handler->ignoreUnsafeBufferInLibcCall(Node.getBeginLoc()); + return true; /* Only warn about libc calls for C++ */ } AST_MATCHER_P(CastExpr, castSubExpr, internal::Matcher, innerMatcher) { @@ -789,7 +791,7 @@ AST_MATCHER_P(CallExpr, hasUnsafePrintfStringArg, if (!FristParmTy->isPointerType()) return false; // possibly some user-defined printf function - QualType FirstPteTy = (cast(FristParmTy))->getPointeeType(); + QualType FirstPteTy = FristParmTy->getAs()->getPointeeType(); if (!Ctx.getFILEType() .isNull() && //`FILE *` must be in the context if it is fprintf @@ -865,7 +867,7 @@ AST_MATCHER(CallExpr, hasUnsafeSnprintfBuffer) { if (!FirstParmTy->isPointerType()) return false; // Not an snprint - QualType FirstPteTy = cast(FirstParmTy)->getPointeeType(); + QualType FirstPteTy = FirstParmTy->getAs()->getPointeeType(); const Expr *Buf = Node.getArg(0), *Size = Node.getArg(1); if (FirstPteTy.isConstQualified() || !Buf->getType()->isPointerType() || diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index 117b2c8bc57935..7e0b929abea683 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -2549,6 +2549,7 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings( DiagnosticOptions &DiagOpts = Diags.getDiagnosticOptions(); // UnsafeBufferUsage analysis settings. + bool IsCXXLang = S.getLangOpts().CPlusPlus; bool UnsafeBufferUsageCanEmitSuggestions = S.getLangOpts().CPlusPlus20; bool UnsafeBufferUsageShouldEmitSuggestions = // Should != Can. UnsafeBufferUsageCanEmitSuggestions && @@ -2581,7 +2582,8 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings( !Diags.isIgnored(diag::warn_unsafe_buffer_variable, SourceLocation()) || !Diags.isIgnored(diag::warn_unsafe_buffer_usage_in_container, SourceLocation()) || - !Diags.isIgnored(diag::warn_unsafe_buffer_libc_call, SourceLocation())) { + (!Diags.isIgnored(diag::warn_unsafe_buffer_libc_call, SourceLocation()) && + IsCXXLang)) { CallableVisitor(CallAnalyzers).TraverseTranslationUnitDecl(TU); } } diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-no-libc-functions-in-c.c b/clang/test/SemaCXX/warn-unsafe-buffer-usage-no-libc-functions-in-c.c new file mode 100644 index 00..e305c3e140dff9 --- /dev/null +++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-no-libc-functions-in-c.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -Wunsafe-buffer-usage %s -verify %s + +void* memcpy(void *dst,const void *src, unsigned long size); + +void f(int *p, int *q) { + + memcpy(p, q, 10); // no libc warn in C + ++p[5]; // expected-warning{{unsafe buffer access}} +} >From 42664f03f16a99aa17bb33f473a01db73af796f5 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Fri, 20 Sep 2024 18:53:28 -0700 Subject: [PATCH 2/3] Add tests and fix a typo --- clang/lib/Analysis/UnsafeBufferUsage.cpp | 6 +++--- .../warn-unsafe-buffer-usage-libc-functions.cpp| 10 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp index 110a121e71a7d2..6c1979179711b9 100644 --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -786,12 +786,12 @@ AST_MATCHER_P(CallExpr, hasUnsafePrintfStringArg, return false; // possibly some user-defined printf function ASTContext &Ctx = Finder->getASTContext(); - QualType FristParmTy = FD->getParamDecl(0)->getT
[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)
@@ -784,12 +786,12 @@ AST_MATCHER_P(CallExpr, hasUnsafePrintfStringArg, return false; // possibly some user-defined printf function ASTContext &Ctx = Finder->getASTContext(); - QualType FristParmTy = FD->getParamDecl(0)->getType(); + QualType FirstParmTy = FD->getParamDecl(0)->getType(); - if (!FristParmTy->isPointerType()) + if (!FirstParmTy->isPointerType()) return false; // possibly some user-defined printf function - QualType FirstPteTy = (cast(FristParmTy))->getPointeeType(); + QualType FirstPteTy = FirstParmTy->getAs()->getPointeeType(); ziqingluo-90 wrote: The difference between `castAs` and `getAs` is that `castAs` asserts the canonical type is `PointerType` while `getAs` returns null if not. I think `castAs` is more suitable for our case. https://github.com/llvm/llvm-project/pull/109496 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)
https://github.com/haoNoQ approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/109496 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)
@@ -784,12 +786,12 @@ AST_MATCHER_P(CallExpr, hasUnsafePrintfStringArg, return false; // possibly some user-defined printf function ASTContext &Ctx = Finder->getASTContext(); - QualType FristParmTy = FD->getParamDecl(0)->getType(); + QualType FirstParmTy = FD->getParamDecl(0)->getType(); - if (!FristParmTy->isPointerType()) + if (!FirstParmTy->isPointerType()) return false; // possibly some user-defined printf function - QualType FirstPteTy = (cast(FristParmTy))->getPointeeType(); + QualType FirstPteTy = FirstParmTy->getAs()->getPointeeType(); haoNoQ wrote: `castAs`? https://github.com/llvm/llvm-project/pull/109496 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Loads] Check context instruction for context-sensitive derefability (PR #109277)
https://github.com/dtcxzyw approved this pull request. Nice catch! https://github.com/llvm/llvm-project/pull/109277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)
https://github.com/haoNoQ edited https://github.com/llvm/llvm-project/pull/109496 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [modularize] Avoid repeated hash lookups (NFC) (PR #109508)
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/109508 None >From d50b829fd1277736b7e65886879fcfe9a45714f2 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Fri, 20 Sep 2024 13:31:12 -0700 Subject: [PATCH] [modularize] Avoid repeated hash lookups (NFC) --- clang-tools-extra/modularize/Modularize.cpp | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/modularize/Modularize.cpp b/clang-tools-extra/modularize/Modularize.cpp index f3e7dfc20b027d..92e4792526d6f3 100644 --- a/clang-tools-extra/modularize/Modularize.cpp +++ b/clang-tools-extra/modularize/Modularize.cpp @@ -508,13 +508,11 @@ class EntityMap : public std::map> { // Sort contents. llvm::sort(H->second); - // Check whether we've seen this header before. - auto KnownH = AllHeaderContents.find(H->first); - if (KnownH == AllHeaderContents.end()) { -// We haven't seen this header before; record its contents. -AllHeaderContents.insert(*H); + // Record this header and its contents if we haven't seen it before. + auto [KnownH, Inserted] = + AllHeaderContents.try_emplace(H->first, H->second); + if (Inserted) continue; - } // If the header contents are the same, we're done. if (H->second == KnownH->second) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [modularize] Avoid repeated hash lookups (NFC) (PR #109508)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Kazu Hirata (kazutakahirata) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/109508.diff 1 Files Affected: - (modified) clang-tools-extra/modularize/Modularize.cpp (+4-6) ``diff diff --git a/clang-tools-extra/modularize/Modularize.cpp b/clang-tools-extra/modularize/Modularize.cpp index f3e7dfc20b027d..92e4792526d6f3 100644 --- a/clang-tools-extra/modularize/Modularize.cpp +++ b/clang-tools-extra/modularize/Modularize.cpp @@ -508,13 +508,11 @@ class EntityMap : public std::map> { // Sort contents. llvm::sort(H->second); - // Check whether we've seen this header before. - auto KnownH = AllHeaderContents.find(H->first); - if (KnownH == AllHeaderContents.end()) { -// We haven't seen this header before; record its contents. -AllHeaderContents.insert(*H); + // Record this header and its contents if we haven't seen it before. + auto [KnownH, Inserted] = + AllHeaderContents.try_emplace(H->first, H->second); + if (Inserted) continue; - } // If the header contents are the same, we're done. if (H->second == KnownH->second) `` https://github.com/llvm/llvm-project/pull/109508 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-offload-bundler] Avoid repeated hash lookups (NFC) (PR #109507)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/109507.diff 1 Files Affected: - (modified) clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp (+1-2) ``diff diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp index e336417586f70b..0189fe5d56ab2a 100644 --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -349,11 +349,10 @@ int main(int argc, const char **argv) { // Standardize target names to include env field std::vector StandardizedTargetNames; for (StringRef Target : TargetNames) { -if (ParsedTargets.contains(Target)) { +if (!ParsedTargets.insert(Target).second) { reportError(createStringError(errc::invalid_argument, "Duplicate targets are not allowed")); } -ParsedTargets.insert(Target); auto OffloadInfo = OffloadTargetInfo(Target, BundlerConfig); bool KindIsValid = OffloadInfo.isOffloadKindValid(); `` https://github.com/llvm/llvm-project/pull/109507 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] Remove clang-pseudo (PR #109154)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-s390x-linux-lnt` running on `systemz-1` while building `clang-tools-extra,clang` at step 7 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/136/builds/972 Here is the relevant piece of the build log for the reference ``` Step 7 (ninja check 1) failure: stage 1 checked (failure) TEST 'libFuzzer-s390x-default-Linux :: fuzzer-timeout.test' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest + /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest RUN: at line 2: /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest + /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/lib/fuzzer /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/TimeoutEmptyTest.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutEmptyTest RUN: at line 3: not /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 2>&1 | FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=TimeoutTest + not /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 + FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=TimeoutTest RUN: at line 12: not /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/hi.txt 2>&1 | FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=SingleInputTimeoutTest + not /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/hi.txt + FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/llvm/compiler-rt/test/fuzzer/fuzzer-timeout.test --check-prefix=SingleInputTimeoutTest RUN: at line 16: /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 -timeout_exitcode=0 + /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/stage1/runtimes/runtimes-bins/compiler-rt/test/fuzzer/S390XDefaultLinuxConfig/Output/fuzzer-timeout.test.tmp-TimeoutTest -timeout=1 -timeout_exitcode=0 INFO: Running with entropic power schedule (0xFF, 100). IN
[clang] [clang] fix the unexpected control flow in ParseTentative.cpp (PR #109298)
c8ef wrote: > But that function _does_ have a return statement after the loop? I assumed that the entire function body was enclosed within the `while(true)` loop? https://github.com/llvm/llvm-project/pull/109298 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Implement arithmetic, bitwise and compound assignment operator (PR #108949)
@@ -10,11 +10,229 @@ using FourI128VecSize __attribute__((vector_size(64))) = __int128; using FourCharsExtVec __attribute__((ext_vector_type(4))) = char; using FourIntsExtVec __attribute__((ext_vector_type(4))) = int; +using FourLongLongsExtVec __attribute__((ext_vector_type(4))) = long long; +using FourFloatsExtVec __attribute__((ext_vector_type(4))) = float; +using FourDoublesExtVec __attribute__((ext_vector_type(4))) = double; using FourI128ExtVec __attribute__((ext_vector_type(4))) = __int128; + +// Next a series of tests to make sure these operations are usable in +// constexpr functions. Template instantiations don't emit Winvalid-constexpr, +// so we have to do these as macros. +#define MathShiftOps(Type)\ + constexpr auto MathShiftOps##Type(Type a, Type b) { \ +a = a + b;\ +a = a - b;\ +a = a * b;\ +a = a / b;\ +b = a + 1;\ +b = a - 1;\ +b = a * 1;\ +b = a / 1;\ +a += a; \ +a -= a; \ +a *= a; \ +a /= a; \ +b += a; \ +b -= a; \ +b *= a; \ +b /= a; \ +b = (a += a); \ +b = (a -= a); \ +b = (a *= a); \ +b = (a /= a); \ +b = (b += a); \ +b = (b -= a); \ +b = (b *= a); \ +b = (b /= a); \ +a < b;\ +a > b;\ +a <= b; \ +a >= b; \ +a == b; \ +a != b; \ +a &&b;\ +a || b; \ +auto c = (a, b); \ +return c; \ + } + +// Ops specific to Integers. +#define MathShiftOpsInts(Type)\ + constexpr auto MathShiftopsInts##Type(Type a, Type b) { \ +a = a << b; \ +a = a >> b; \ +a = a << 3; \ +a = a >> 3; \ +a = 3 << b; \ +a = 3 >> b; \ +a <<= b; \ +a >>= b; \ +a <<= 3; \ +a >>= 3; \ +b = (a <<= b);\ +b = (a >>= b);\ +b = (a <<= 3);\ +b = (a >>= 3);\ +a = a % b;\ +a &b; \ +a | b;\ +a ^ b;\ +return a; \ + } + +MathShiftOps(FourCharsVecSize); +MathShiftOps(FourIntsVecSize); +MathShiftOps(FourLongLongsVecSize); +MathShiftOps(FourFloatsVecSize); +MathShiftOps(FourDoublesVecSize); +MathShiftOps(FourCharsExtVec); +MathShiftOps(FourIntsExtVec); +MathShiftOps(FourLongLongsExtVec); +MathShiftOps(FourFloatsExtVec); +MathShiftOps(FourDoublesExtVec); + +MathShiftOpsInts(FourCharsVecSize); +MathShiftOpsInts(FourIntsVecSize); +MathShiftOpsInts(FourLongLongsVecSize); +MathShiftOpsInts(FourCharsExtVec); +MathShiftOpsInts(FourIntsExtVec); +MathShiftOpsInts(FourLongLongsExtVec); tbaederr wrote: Can you add tests for with `FourI128ExtVec` as well here? I think that might be broken. https://github.com/llvm/llvm-project/pull/108949 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Annotate the l_paren of function pointer types (PR #109229)
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/109229 >From 84c166dfabc3f314cd922baa3933b3d0ea11e08e Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Wed, 18 Sep 2024 21:03:24 -0700 Subject: [PATCH] [clang-format] Annotate the l_paren of function pointer types Fixes #109146. --- clang/lib/Format/TokenAnnotator.cpp | 14 -- clang/unittests/Format/TokenAnnotatorTest.cpp | 6 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 6f09835bad3a83..9e5f5588592199 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -486,16 +486,18 @@ class AnnotatingParser { } } - if (CurrentToken->Previous->is(TT_PointerOrReference) && - CurrentToken->Previous->Previous->isOneOf(tok::l_paren, -tok::coloncolon)) { + const auto &Prev = *CurrentToken->Previous; + if (Prev.is(TT_PointerOrReference) && + Prev.Previous->isOneOf(tok::l_paren, tok::coloncolon)) { ProbablyFunctionType = true; } if (CurrentToken->is(tok::comma)) MightBeFunctionType = false; - if (CurrentToken->Previous->is(TT_BinaryOperator)) + if (Prev.is(TT_BinaryOperator)) Contexts.back().IsExpression = true; if (CurrentToken->is(tok::r_paren)) { +if (Prev.is(TT_PointerOrReference) && Prev.Previous == &OpeningParen) + MightBeFunctionType = true; if (OpeningParen.isNot(TT_CppCastLParen) && MightBeFunctionType && ProbablyFunctionType && CurrentToken->Next && (CurrentToken->Next->is(tok::l_paren) || @@ -568,8 +570,8 @@ class AnnotatingParser { bool ProbablyFunctionTypeLParen = (CurrentToken->is(tok::l_paren) && CurrentToken->Next && CurrentToken->Next->isOneOf(tok::star, tok::amp, tok::caret)); - if ((CurrentToken->Previous->isOneOf(tok::kw_const, tok::kw_auto) || - CurrentToken->Previous->isTypeName(LangOpts)) && + if ((Prev.isOneOf(tok::kw_const, tok::kw_auto) || + Prev.isTypeName(LangOpts)) && !(CurrentToken->is(tok::l_brace) || (CurrentToken->is(tok::l_paren) && !ProbablyFunctionTypeLParen))) { Contexts.back().IsExpression = false; diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 34c03d668a9a0a..b5f03d4f851e6e 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -789,6 +789,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsCasts) { ASSERT_EQ(Tokens.size(), 13u) << Tokens; EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_CastRParen); + Tokens = annotate("return (Foo (*)(void *, Bar, ...))&foo;"); + ASSERT_EQ(Tokens.size(), 19u) << Tokens; + EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_FunctionTypeLParen); + EXPECT_TOKEN(Tokens[14], tok::r_paren, TT_CastRParen); + EXPECT_TOKEN(Tokens[15], tok::amp, TT_UnaryOperator); + auto Style = getLLVMStyle(); Style.TypeNames.push_back("Foo"); Tokens = annotate("#define FOO(bar) foo((Foo)&bar)", Style); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20][Modules] Restore inliness of constexpr/consteval functions defined in-class (PR #109470)
https://github.com/tomasz-kaminski-sonarsource updated https://github.com/llvm/llvm-project/pull/109470 >From 6ff9964b7180cc9279c2742b14f69cc966a027a1 Mon Sep 17 00:00:00 2001 From: Tomasz Kaminski Date: Fri, 20 Sep 2024 17:21:33 +0200 Subject: [PATCH] [C++20][Modules] Restore inliness of constexpr/consteval functions defined in-class This correct issue, when the functions declared as `constexpr` are `consteval`, are not considered to be inline (`isInlined()` is false) when defined inside class attached to named module: ```c++ export module mod; struct Clazz { constexpr void f1() { } // non-inline constexpr void f2(); friend constexpr void f3() {} // non-inline }; constexpr void Clazz::f3() {} // inline ``` This conflicts with [decl.constexpr] p1: > A function or static data member declared with the constexpr or consteval specifier on its first declaration is implicitly an inline function or variable ([dcl.inline]). If any declaration of a function or function template has a constexpr or consteval specifier, then all its declarations shall contain the same specifier/) This regression was introduced by https://github.com/llvm/llvm-project/commit/97af17c5, where the inline of such function was accidentally removed The corresponding wording in [class.friend] and p6 [class.mfct] p1 uses "if" and not "if and only if", thus does not imply that these are only cases where such functions are inline. --- clang/lib/Sema/SemaDecl.cpp | 14 +++ .../test/CXX/class/class.friend/p7-cxx20.cpp | 38 --- clang/test/CXX/class/class.mfct/p1-cxx20.cpp | 30 +-- 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index de8805e15bc750..0ea99c43037e5e 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9760,8 +9760,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, if (getLangOpts().CPlusPlus) { // The rules for implicit inlines changed in C++20 for methods and friends // with an in-class definition (when such a definition is not attached to -// the global module). User-specified 'inline' overrides this (set when -// the function decl is created above). +// the global module). This does not affect declarations, that are already +// inline, for example due being declared `inline` or `consteval` // FIXME: We need a better way to separate C++ standard and clang modules. bool ImplicitInlineCXX20 = !getLangOpts().CPlusPlusModules || NewFD->isConstexpr() || NewFD->isConsteval() || @@ -9772,14 +9772,14 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, bool isVirtual = D.getDeclSpec().isVirtualSpecified(); bool hasExplicit = D.getDeclSpec().hasExplicitSpecifier(); isFriend = D.getDeclSpec().isFriendSpecified(); -if (isFriend && !isInline && D.isFunctionDefinition()) { +if (ImplicitInlineCXX20 && isFriend && D.isFunctionDefinition()) { // Pre-C++20 [class.friend]p5 // A function can be defined in a friend declaration of a // class . . . . Such a function is implicitly inline. // Post C++20 [class.friend]p7 // Such a function is implicitly an inline function if it is attached // to the global module. - NewFD->setImplicitlyInline(ImplicitInlineCXX20); + NewFD->setImplicitlyInline(); } // If this is a method defined in an __interface, and is not a constructor @@ -10083,15 +10083,15 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, break; } -if (isa(NewFD) && DC == CurContext && -D.isFunctionDefinition() && !isInline) { +if (ImplicitInlineCXX20 && isa(NewFD) && DC == CurContext && +D.isFunctionDefinition()) { // Pre C++20 [class.mfct]p2: // A member function may be defined (8.4) in its class definition, in // which case it is an inline member function (7.1.2) // Post C++20 [class.mfct]p1: // If a member function is attached to the global module and is defined // in its class definition, it is inline. - NewFD->setImplicitlyInline(ImplicitInlineCXX20); + NewFD->setImplicitlyInline(); } if (!isFriend && SC != SC_None) { diff --git a/clang/test/CXX/class/class.friend/p7-cxx20.cpp b/clang/test/CXX/class/class.friend/p7-cxx20.cpp index 8843d55910ea2d..0ce77b353c2499 100644 --- a/clang/test/CXX/class/class.friend/p7-cxx20.cpp +++ b/clang/test/CXX/class/class.friend/p7-cxx20.cpp @@ -46,14 +46,42 @@ module; export module M; class Z { - friend void z(){}; + friend void z1(){}; }; + +class Inline { + friend inline void z2(){}; +}; + +class Constexpr { + friend constexpr void z3(){}; +}; + +class Consteval { + friend consteval void z4(){}; +}; + // CHECK-MOD: |-CXXRecordDecl {{.*}} <.{{/|?}}header.h:2:1, line:4:1>
[clang] [C++20][Modules] Restore inliness of constexpr/consteval functions defined in-class (PR #109470)
https://github.com/tomasz-kaminski-sonarsource edited https://github.com/llvm/llvm-project/pull/109470 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Correctly annotate */& in if condition with braced init (PR #109505)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/109505 Fixes #109371. >From 192deb4adc9f7e77167a02c060eef8c91932b912 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Fri, 20 Sep 2024 20:28:31 -0700 Subject: [PATCH] [clang-format] Correctly annotate */& in if condition with braced init Fixes #109371. --- clang/lib/Format/TokenAnnotator.cpp | 25 --- clang/unittests/Format/TokenAnnotatorTest.cpp | 5 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index f665ce2ad81eb0..f5acfaaee900a2 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1165,19 +1165,26 @@ class AnnotatingParser { ScopedContextCreator ContextCreator(*this, tok::l_brace, 1); Contexts.back().ColonIsDictLiteral = true; -if (OpeningBrace.is(BK_BracedInit)) + +const auto *Prev = OpeningBrace.getPreviousNonComment(); + +if (OpeningBrace.is(BK_BracedInit)) { Contexts.back().IsExpression = true; -if (Style.isJavaScript() && OpeningBrace.Previous && -OpeningBrace.Previous->is(TT_JsTypeColon)) { - Contexts.back().IsExpression = false; -} -if (Style.isVerilog() && -(!OpeningBrace.getPreviousNonComment() || - OpeningBrace.getPreviousNonComment()->isNot(Keywords.kw_apostrophe))) { - Contexts.back().VerilogMayBeConcatenation = true; + if (Prev) { +for (auto *Tok = Prev->Previous; Tok && Tok->isPointerOrReference(); + Tok = Tok->Previous) { + Tok->setFinalizedType(TT_PointerOrReference); +} + } } + +if (Style.isJavaScript() && Prev && Prev->is(TT_JsTypeColon)) + Contexts.back().IsExpression = false; + if (Style.isTableGen()) Contexts.back().ColonIsDictLiteral = false; +else if (Style.isVerilog() && !(Prev && Prev->is(Keywords.kw_apostrophe))) + Contexts.back().VerilogMayBeConcatenation = true; unsigned CommaCount = 0; while (CurrentToken) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 1884d41a5f23f5..e2c9ba01794caf 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -308,6 +308,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) { EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference); EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference); + Tokens = annotate("if (Foo *&foo{a})"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference); + EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference); + FormatStyle Style = getLLVMStyle(); Style.TypeNames.push_back("MYI"); Tokens = annotate("if (MYI *p{nullptr})", Style); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Correctly annotate */& in if condition with braced init (PR #109505)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) Changes Fixes #109371. --- Full diff: https://github.com/llvm/llvm-project/pull/109505.diff 2 Files Affected: - (modified) clang/lib/Format/TokenAnnotator.cpp (+16-9) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+5) ``diff diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index f665ce2ad81eb0..f5acfaaee900a2 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1165,19 +1165,26 @@ class AnnotatingParser { ScopedContextCreator ContextCreator(*this, tok::l_brace, 1); Contexts.back().ColonIsDictLiteral = true; -if (OpeningBrace.is(BK_BracedInit)) + +const auto *Prev = OpeningBrace.getPreviousNonComment(); + +if (OpeningBrace.is(BK_BracedInit)) { Contexts.back().IsExpression = true; -if (Style.isJavaScript() && OpeningBrace.Previous && -OpeningBrace.Previous->is(TT_JsTypeColon)) { - Contexts.back().IsExpression = false; -} -if (Style.isVerilog() && -(!OpeningBrace.getPreviousNonComment() || - OpeningBrace.getPreviousNonComment()->isNot(Keywords.kw_apostrophe))) { - Contexts.back().VerilogMayBeConcatenation = true; + if (Prev) { +for (auto *Tok = Prev->Previous; Tok && Tok->isPointerOrReference(); + Tok = Tok->Previous) { + Tok->setFinalizedType(TT_PointerOrReference); +} + } } + +if (Style.isJavaScript() && Prev && Prev->is(TT_JsTypeColon)) + Contexts.back().IsExpression = false; + if (Style.isTableGen()) Contexts.back().ColonIsDictLiteral = false; +else if (Style.isVerilog() && !(Prev && Prev->is(Keywords.kw_apostrophe))) + Contexts.back().VerilogMayBeConcatenation = true; unsigned CommaCount = 0; while (CurrentToken) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 1884d41a5f23f5..e2c9ba01794caf 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -308,6 +308,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) { EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference); EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference); + Tokens = annotate("if (Foo *&foo{a})"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference); + EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference); + FormatStyle Style = getLLVMStyle(); Style.TypeNames.push_back("MYI"); Tokens = annotate("if (MYI *p{nullptr})", Style); `` https://github.com/llvm/llvm-project/pull/109505 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files (PR #109496)
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/109496 >From e7f7f82b25eaae86623ac8f47731892b3b629d7d Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Fri, 20 Sep 2024 16:27:09 -0700 Subject: [PATCH 1/4] [-Wunsafe-buffer-usage] Fix a bug and suppress libc warnings for C files - Fix a bug in UnsafeBufferUsage.cpp related to casting to PointerType - Suppress -Wunsafe-buffer-usage-in-libc-call for C files (rdar://117182250) --- clang/lib/Analysis/UnsafeBufferUsage.cpp | 8 +--- clang/lib/Sema/AnalysisBasedWarnings.cpp | 4 +++- .../warn-unsafe-buffer-usage-no-libc-functions-in-c.c| 9 + 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 clang/test/SemaCXX/warn-unsafe-buffer-usage-no-libc-functions-in-c.c diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp index a16762244b1766..110a121e71a7d2 100644 --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -250,7 +250,9 @@ AST_MATCHER_P(Stmt, ignoreUnsafeBufferInContainer, AST_MATCHER_P(Stmt, ignoreUnsafeLibcCall, const UnsafeBufferUsageHandler *, Handler) { - return Handler->ignoreUnsafeBufferInLibcCall(Node.getBeginLoc()); + if (Finder->getASTContext().getLangOpts().CPlusPlus) +return Handler->ignoreUnsafeBufferInLibcCall(Node.getBeginLoc()); + return true; /* Only warn about libc calls for C++ */ } AST_MATCHER_P(CastExpr, castSubExpr, internal::Matcher, innerMatcher) { @@ -789,7 +791,7 @@ AST_MATCHER_P(CallExpr, hasUnsafePrintfStringArg, if (!FristParmTy->isPointerType()) return false; // possibly some user-defined printf function - QualType FirstPteTy = (cast(FristParmTy))->getPointeeType(); + QualType FirstPteTy = FristParmTy->getAs()->getPointeeType(); if (!Ctx.getFILEType() .isNull() && //`FILE *` must be in the context if it is fprintf @@ -865,7 +867,7 @@ AST_MATCHER(CallExpr, hasUnsafeSnprintfBuffer) { if (!FirstParmTy->isPointerType()) return false; // Not an snprint - QualType FirstPteTy = cast(FirstParmTy)->getPointeeType(); + QualType FirstPteTy = FirstParmTy->getAs()->getPointeeType(); const Expr *Buf = Node.getArg(0), *Size = Node.getArg(1); if (FirstPteTy.isConstQualified() || !Buf->getType()->isPointerType() || diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index 117b2c8bc57935..7e0b929abea683 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -2549,6 +2549,7 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings( DiagnosticOptions &DiagOpts = Diags.getDiagnosticOptions(); // UnsafeBufferUsage analysis settings. + bool IsCXXLang = S.getLangOpts().CPlusPlus; bool UnsafeBufferUsageCanEmitSuggestions = S.getLangOpts().CPlusPlus20; bool UnsafeBufferUsageShouldEmitSuggestions = // Should != Can. UnsafeBufferUsageCanEmitSuggestions && @@ -2581,7 +2582,8 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings( !Diags.isIgnored(diag::warn_unsafe_buffer_variable, SourceLocation()) || !Diags.isIgnored(diag::warn_unsafe_buffer_usage_in_container, SourceLocation()) || - !Diags.isIgnored(diag::warn_unsafe_buffer_libc_call, SourceLocation())) { + (!Diags.isIgnored(diag::warn_unsafe_buffer_libc_call, SourceLocation()) && + IsCXXLang)) { CallableVisitor(CallAnalyzers).TraverseTranslationUnitDecl(TU); } } diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-no-libc-functions-in-c.c b/clang/test/SemaCXX/warn-unsafe-buffer-usage-no-libc-functions-in-c.c new file mode 100644 index 00..e305c3e140dff9 --- /dev/null +++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-no-libc-functions-in-c.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -Wunsafe-buffer-usage %s -verify %s + +void* memcpy(void *dst,const void *src, unsigned long size); + +void f(int *p, int *q) { + + memcpy(p, q, 10); // no libc warn in C + ++p[5]; // expected-warning{{unsafe buffer access}} +} >From 42664f03f16a99aa17bb33f473a01db73af796f5 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Fri, 20 Sep 2024 18:53:28 -0700 Subject: [PATCH 2/4] Add tests and fix a typo --- clang/lib/Analysis/UnsafeBufferUsage.cpp | 6 +++--- .../warn-unsafe-buffer-usage-libc-functions.cpp| 10 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp index 110a121e71a7d2..6c1979179711b9 100644 --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -786,12 +786,12 @@ AST_MATCHER_P(CallExpr, hasUnsafePrintfStringArg, return false; // possibly some user-defined printf function ASTContext &Ctx = Finder->getASTContext(); - QualType FristParmTy = FD->getParamDecl(0)->getT
[clang-tools-extra] 0659fd9 - [clangd] Collect comments from function definitions into the index (#67802)
Author: Christian Kandeler Date: 2024-09-20T23:54:20-04:00 New Revision: 0659fd996784cbc2b11379380a03633fa80f7816 URL: https://github.com/llvm/llvm-project/commit/0659fd996784cbc2b11379380a03633fa80f7816 DIFF: https://github.com/llvm/llvm-project/commit/0659fd996784cbc2b11379380a03633fa80f7816.diff LOG: [clangd] Collect comments from function definitions into the index (#67802) This is useful with projects that put their (doxygen) comments at the implementation site, rather than the header. Added: Modified: clang-tools-extra/clangd/index/Symbol.h clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/index/SymbolCollector.h clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp Removed: diff --git a/clang-tools-extra/clangd/index/Symbol.h b/clang-tools-extra/clangd/index/Symbol.h index 1aa5265299231b..62c47ddfc5758d 100644 --- a/clang-tools-extra/clangd/index/Symbol.h +++ b/clang-tools-extra/clangd/index/Symbol.h @@ -145,9 +145,11 @@ struct Symbol { ImplementationDetail = 1 << 2, /// Symbol is visible to other files (not e.g. a static helper function). VisibleOutsideFile = 1 << 3, +/// Symbol has an attached documentation comment. +HasDocComment = 1 << 4 }; - SymbolFlag Flags = SymbolFlag::None; + /// FIXME: also add deprecation message and fixit? }; diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index 5c4e2150cf3123..a76894cf0855f3 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -635,17 +635,21 @@ bool SymbolCollector::handleDeclOccurrence( return true; const Symbol *BasicSymbol = Symbols.find(ID); - if (isPreferredDeclaration(*OriginalDecl, Roles)) + bool SkipDocCheckInDef = false; + if (isPreferredDeclaration(*OriginalDecl, Roles)) { // If OriginalDecl is preferred, replace/create the existing canonical // declaration (e.g. a class forward declaration). There should be at most // one duplicate as we expect to see only one preferred declaration per // TU, because in practice they are definitions. BasicSymbol = addDeclaration(*OriginalDecl, std::move(ID), IsMainFileOnly); - else if (!BasicSymbol || DeclIsCanonical) +SkipDocCheckInDef = true; + } else if (!BasicSymbol || DeclIsCanonical) { BasicSymbol = addDeclaration(*ND, std::move(ID), IsMainFileOnly); +SkipDocCheckInDef = true; + } if (Roles & static_cast(index::SymbolRole::Definition)) -addDefinition(*OriginalDecl, *BasicSymbol); +addDefinition(*OriginalDecl, *BasicSymbol, SkipDocCheckInDef); return true; } @@ -1025,16 +1029,28 @@ const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, SymbolID ID, *ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator, *CompletionTUInfo, /*IncludeBriefComments*/ false); - std::string Documentation = - formatDocumentation(*CCS, getDocComment(Ctx, SymbolCompletion, - /*CommentsFromHeaders=*/true)); + std::string DocComment; + std::string Documentation; + bool AlreadyHasDoc = S.Flags & Symbol::HasDocComment; + if (!AlreadyHasDoc) { +DocComment = getDocComment(Ctx, SymbolCompletion, + /*CommentsFromHeaders=*/true); +Documentation = formatDocumentation(*CCS, DocComment); + } + const auto UpdateDoc = [&] { +if (!AlreadyHasDoc) { + if (!DocComment.empty()) +S.Flags |= Symbol::HasDocComment; + S.Documentation = Documentation; +} + }; if (!(S.Flags & Symbol::IndexedForCodeCompletion)) { if (Opts.StoreAllDocumentation) - S.Documentation = Documentation; + UpdateDoc(); Symbols.insert(S); return Symbols.find(S.ID); } - S.Documentation = Documentation; + UpdateDoc(); std::string Signature; std::string SnippetSuffix; getSignature(*CCS, &Signature, &SnippetSuffix, SymbolCompletion.Kind, @@ -1058,8 +1074,8 @@ const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, SymbolID ID, return Symbols.find(S.ID); } -void SymbolCollector::addDefinition(const NamedDecl &ND, -const Symbol &DeclSym) { +void SymbolCollector::addDefinition(const NamedDecl &ND, const Symbol &DeclSym, +bool SkipDocCheck) { if (DeclSym.Definition) return; const auto &SM = ND.getASTContext().getSourceManager(); @@ -1074,6 +1090,27 @@ void SymbolCollector::addDefinition(const NamedDecl &ND, Symbol S = DeclSym; // FIXME: use the result to filter out symbols. S.Definition = *DefLoc; + + std::string DocComment; + std::string Documentation; + if (!SkipDocCheck && !(S.Flags & Symbol::HasDocComment) && + (llvm::isa(ND) || llvm::isa(ND))) { +CodeComple
[clang] [llvm] [Support] Add scaling support in `indent` (PR #109478)
llvmbot wrote: @llvm/pr-subscribers-llvm-support Author: Rahul Joshi (jurahul) Changes Scaled indent is useful when indentation is always in steps of a fixed number (the Scale) and still allow using the +/- operators to adjust indentation. --- Full diff: https://github.com/llvm/llvm-project/pull/109478.diff 3 Files Affected: - (modified) clang/unittests/Format/FormatTest.cpp (+1-1) - (modified) llvm/include/llvm/Support/raw_ostream.h (+17-8) - (modified) llvm/unittests/Support/raw_ostream_test.cpp (+10) ``diff diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 53aa93a7a4fb01..1c9f568d24fd98 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -25137,7 +25137,7 @@ TEST_F(FormatTest, SkipMacroDefinitionBody) { "a", Style); - // Adjust indendations but don't change the definition. + // Adjust indentations but don't change the definition. Style.IndentPPDirectives = FormatStyle::PPDIS_None; verifyNoChange("#if A\n" "#define A a\n" diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h index 34f91cbe9551f4..3be9f9d18a1717 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -774,18 +774,27 @@ class buffer_unique_ostream : public raw_svector_ostream { // you can use // OS << indent(6) << "more stuff"; // which has better ergonomics (and clang-formats better as well). +// +// If indentation is always in increments of a fixed value, you can use Scale +// to set that value once. So indent(1, 2) will add 2 spaces and +// indent(1,2) + 1 will add 4 spaces. struct indent { - unsigned NumSpaces; - - explicit indent(unsigned NumSpaces) : NumSpaces(NumSpaces) {} - void operator+=(unsigned N) { NumSpaces += N; } - void operator-=(unsigned N) { NumSpaces -= N; } - indent operator+(unsigned N) const { return indent(NumSpaces + N); } - indent operator-(unsigned N) const { return indent(NumSpaces - N); } + // Indentation is represented as `NumIndents` steps of size `Scale` each. + unsigned NumIndents; + unsigned Scale; + + explicit indent(unsigned NumIndents, unsigned Scale = 1) + : NumIndents(NumIndents), Scale(Scale) {} + + // These arithmeric operators preserve scale. + void operator+=(unsigned N) { NumIndents += N; } + void operator-=(unsigned N) { NumIndents -= N; } + indent operator+(unsigned N) const { return indent(NumIndents + N, Scale); } + indent operator-(unsigned N) const { return indent(NumIndents - N, Scale); } }; inline raw_ostream &operator<<(raw_ostream &OS, const indent &Indent) { - return OS.indent(Indent.NumSpaces); + return OS.indent(Indent.NumIndents * Indent.Scale); } class Error; diff --git a/llvm/unittests/Support/raw_ostream_test.cpp b/llvm/unittests/Support/raw_ostream_test.cpp index 99aa350adad71d..a35edd61685296 100644 --- a/llvm/unittests/Support/raw_ostream_test.cpp +++ b/llvm/unittests/Support/raw_ostream_test.cpp @@ -188,6 +188,16 @@ TEST(raw_ostreamTest, Indent) { EXPECT_EQ(Spaces(5), printToString(Indent)); Indent -= 1; EXPECT_EQ(Spaces(4), printToString(Indent)); + + // Scaled indent. + indent Scaled(4, 2); + EXPECT_EQ(Spaces(8), printToString(Scaled)); + EXPECT_EQ(Spaces(10), printToString(Scaled + 1)); + EXPECT_EQ(Spaces(6), printToString(Scaled - 1)); + Scaled += 1; + EXPECT_EQ(Spaces(10), printToString(Scaled)); + Scaled -= 1; + EXPECT_EQ(Spaces(8), printToString(Scaled)); } TEST(raw_ostreamTest, FormatHex) { `` https://github.com/llvm/llvm-project/pull/109478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20][Modules] Restore inliness of constexpr/consteval functions defined in-class (PR #109470)
tomasz-kaminski-sonarsource wrote: The correct link is https://github.com/llvm/llvm-project/commit/97af17c5. The commit id remains the same. https://github.com/llvm/llvm-project/pull/109470 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Support] Add scaling support in `indent` (PR #109478)
https://github.com/jurahul ready_for_review https://github.com/llvm/llvm-project/pull/109478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix the unexpected control flow in ParseTentative.cpp (PR #109298)
tbaederr wrote: Yeah the behavior is not the same. The original code only parsed `ident[,]` in the loop, since the `continue` ended the loop anyway. The comment above the function reads: ``` /// [ObjC] protocol-qualifiers: '<' identifier-list '>' ``` So the assumption is that this should parse multiple identifiers, and not just one. I think the new code does that. I'm only worried about the missing return at the end of the function - maybe there should be a `llvm_unreachable` here to silence compilers, even if that control flow is not possible. https://github.com/llvm/llvm-project/pull/109298 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Support] Add scaling support in `indent` (PR #109478)
@@ -774,18 +774,27 @@ class buffer_unique_ostream : public raw_svector_ostream { // you can use // OS << indent(6) << "more stuff"; // which has better ergonomics (and clang-formats better as well). +// +// If indentation is always in increments of a fixed value, you can use Scale +// to set that value once. So indent(1, 2) will add 2 spaces and +// indent(1,2) + 1 will add 4 spaces. struct indent { - unsigned NumSpaces; - - explicit indent(unsigned NumSpaces) : NumSpaces(NumSpaces) {} - void operator+=(unsigned N) { NumSpaces += N; } - void operator-=(unsigned N) { NumSpaces -= N; } - indent operator+(unsigned N) const { return indent(NumSpaces + N); } - indent operator-(unsigned N) const { return indent(NumSpaces - N); } + // Indentation is represented as `NumIndents` steps of size `Scale` each. + unsigned NumIndents; + unsigned Scale; + + explicit indent(unsigned NumIndents, unsigned Scale = 1) + : NumIndents(NumIndents), Scale(Scale) {} + + // These arithmeric operators preserve scale. + void operator+=(unsigned N) { NumIndents += N; } + void operator-=(unsigned N) { NumIndents -= N; } + indent operator+(unsigned N) const { return indent(NumIndents + N, Scale); } + indent operator-(unsigned N) const { return indent(NumIndents - N, Scale); } arsenm wrote: I'm surprised there's no guard against underflow here https://github.com/llvm/llvm-project/pull/109478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Support] Add scaling support in `indent` (PR #109478)
https://github.com/arsenm approved this pull request. https://github.com/llvm/llvm-project/pull/109478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SPIR-V] Add SPIR-V structurizer (PR #107408)
Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= , Nathan =?utf-8?q?Gauër?= Message-ID: In-Reply-To: llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `lld-x86_64-win` running on `as-worker-93` while building `clang,llvm` at step 7 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/146/builds/1200 Here is the relevant piece of the build log for the reference ``` Step 7 (test-build-unified-tree-check-all) failure: test (failure) TEST 'LLVM-Unit :: Support/./SupportTests.exe/36/87' FAILED Script(shard): -- GTEST_OUTPUT=json:C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe-LLVM-Unit-13812-36-87.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=87 GTEST_SHARD_INDEX=36 C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe -- Script: -- C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe --gtest_filter=ProgramEnvTest.CreateProcessLongPath -- C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(160): error: Expected equality of these values: 0 RC Which is: -2 C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(163): error: fs::remove(Twine(LongPath)): did not return errc::success. error number: 13 error message: permission denied C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:160 Expected equality of these values: 0 RC Which is: -2 C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:163 fs::remove(Twine(LongPath)): did not return errc::success. error number: 13 error message: permission denied ``` https://github.com/llvm/llvm-project/pull/107408 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix the unexpected control flow in ParseTentative.cpp (PR #109298)
c8ef wrote: > I'm only worried about the missing return at the end of the function - maybe > there should be a `llvm_unreachable` here to silence compilers, even if that > control flow is not possible. https://github.com/llvm/llvm-project/blob/21594f2793da5d2e1d1cd6714bfa10e742f2e526/clang/lib/Parse/ParseTentative.cpp#L914-L937 I believe we can conclude from the code snippet above that we don't actually need the `llvm_unreachable`? @tbaederr https://github.com/llvm/llvm-project/pull/109298 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix the unexpected control flow in ParseTentative.cpp (PR #109298)
tbaederr wrote: But that function _does_ have a return statement after the loop? https://github.com/llvm/llvm-project/pull/109298 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)
peilin-ye wrote: @eddyz87, Thanks! I didn't know about `XXXISelLowering.cpp`. > But there should be a way to tweak existing `fail` function to stop after > errors are reported. Can we `exit(1)` ? :-) `fail()` calls `LLVMContext::diagnose()`, which already `exit(1)` when there's no "report handler", if "severity" is `DS_Error` : ```cpp if (DI.getSeverity() == DS_Error) exit(1); } ``` `fail()` uses `DiagnosticInfoUnsupported`, whose "severity" \_is\_ `DS_Error`, but our "report handler" (`pImpl->DiagHandler->handleDiagnostics()`) doesn't call `exit()` ... - - - I tried, based on your diff (`__ATOMIC_ACQ_REL` is illegal for `__atomic_{load,store}{,_n}()`, so we only need to handle `AtomicOrdering::SequentiallyConsistent`) : ```diff --- a/llvm/lib/Target/BPF/BPFISelLowering.cpp +++ b/llvm/lib/Target/BPF/BPFISelLowering.cpp @@ -93,6 +93,9 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM, setOperationAction(ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS, VT, Custom); } + for (auto VT : {MVT::i8, MVT::i16, MVT::i32, MVT::i64}) +setOperationAction(ISD::ATOMIC_LOAD, VT, Custom); + for (auto VT : { MVT::i32, MVT::i64 }) { if (VT == MVT::i32 && !STI.getHasAlu32()) continue; @@ -291,6 +294,8 @@ void BPFTargetLowering::ReplaceNodeResults( else Msg = "unsupported atomic operation, please use 64 bit version"; break; + case ISD::ATOMIC_LOAD: +return; } SDLoc DL(N); @@ -316,6 +321,8 @@ SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { return LowerSDIVSREM(Op, DAG); case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); + case ISD::ATOMIC_LOAD: +return LowerATOMIC_LOAD(Op, DAG); } } @@ -703,6 +710,22 @@ SDValue BPFTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { return DAG.getNode(BPFISD::SELECT_CC, DL, VTs, Ops); } +SDValue BPFTargetLowering::LowerATOMIC_LOAD(SDValue Op, +SelectionDAG &DAG) const { + const char *Msg = + "sequentially consistent (seq_cst) atomic load is not supported"; + SDNode *N = Op.getNode(); + SDLoc DL(N); + + if (cast(N)->getMergedOrdering() == + AtomicOrdering::SequentiallyConsistent) { +fail(DL, DAG, Msg); +exit(1); + } + + return Op; +} + const char *BPFTargetLowering::getTargetNodeName(unsigned Opcode) const { switch ((BPFISD::NodeType)Opcode) { case BPFISD::FIRST_NUMBER: ``` ```diff --- a/llvm/lib/Target/BPF/BPFISelLowering.h +++ b/llvm/lib/Target/BPF/BPFISelLowering.h @@ -77,7 +77,7 @@ private: SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const; SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const; SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const; - + SDValue LowerATOMIC_LOAD(SDValue Op, SelectionDAG &DAG) const; SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const; SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const; ``` which seems to work nicely: ``` $ cat bar.c char foo(char *ptr) { return __atomic_load_n(ptr, __ATOMIC_SEQ_CST); } $ $ clang --target=bpf -mcpu=v5 -g bar.c > /dev/null bar.c:1:6: error: sequentially consistent (seq_cst) atomic load is not supported 1 | char foo(char *ptr) { return __atomic_load_n(ptr, __ATOMIC_SEQ_CST); } | ^ $ ``` https://github.com/llvm/llvm-project/pull/108636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix the unexpected control flow in ParseTentative.cpp (PR #109298)
c8ef wrote: Or we can simply return `TPResult::Ambiguous`, as many functions in this file do. https://github.com/llvm/llvm-project/pull/109298 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 68849a8 - [TableGen] Use StringSet instead of StringMap (NFC) (#109469)
Author: Kazu Hirata Date: 2024-09-20T20:32:23-07:00 New Revision: 68849a878858f981e19c5a664310e0ff059f27e7 URL: https://github.com/llvm/llvm-project/commit/68849a878858f981e19c5a664310e0ff059f27e7 DIFF: https://github.com/llvm/llvm-project/commit/68849a878858f981e19c5a664310e0ff059f27e7.diff LOG: [TableGen] Use StringSet instead of StringMap (NFC) (#109469) Added: Modified: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp Removed: diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp index 2a369271cfc3f2..80cb2ee28e256a 100644 --- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp +++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp @@ -20,7 +20,6 @@ #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/StringSwitch.h" @@ -114,9 +113,8 @@ class BuiltinNameEmitter { // \param Output (out) String containing the enums to emit in the output file. // \param List (out) List containing the extracted Types, except the Types in //TypesSeen. - void ExtractEnumTypes(ArrayRef Types, -StringMap &TypesSeen, std::string &Output, -std::vector &List); + void ExtractEnumTypes(ArrayRef Types, StringSet<> &TypesSeen, +std::string &Output, std::vector &List); // Emit the enum or struct used in the generated file. // Populate the TypeList at the same time. @@ -364,7 +362,7 @@ void BuiltinNameEmitter::Emit() { } void BuiltinNameEmitter::ExtractEnumTypes(ArrayRef Types, - StringMap &TypesSeen, + StringSet<> &TypesSeen, std::string &Output, std::vector &List) { raw_string_ostream SS(Output); @@ -376,7 +374,7 @@ void BuiltinNameEmitter::ExtractEnumTypes(ArrayRef Types, // the Record can be a VectorType or something else, only the name is // important. List.push_back(T); - TypesSeen.insert(std::make_pair(T->getValueAsString("Name"), true)); + TypesSeen.insert(T->getValueAsString("Name")); } } } @@ -385,7 +383,7 @@ void BuiltinNameEmitter::EmitDeclarations() { // Enum of scalar type names (float, int, ...) and generic type sets. OS << "enum OpenCLTypeID {\n"; - StringMap TypesSeen; + StringSet<> TypesSeen; std::string GenTypeEnums; std::string TypeEnums; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TableGen] Use StringSet instead of StringMap (NFC) (PR #109469)
https://github.com/kazutakahirata closed https://github.com/llvm/llvm-project/pull/109469 ___ 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 6d40fb810312b41d4ec4e10dba2f55e7e0625953 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Thu, 19 Sep 2024 00:13:51 + Subject: [PATCH] adding clang codegen --- clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 40 + 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 | 56 --- .../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, 168 insertions(+), 13 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 e2711f1ba70239..a39c34cae016b5 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18824,6 +18824,46 @@ 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()->isDoubleType() && +E->getArg(1)->getType()->isUnsignedIntegerType() && +E->getArg(2)->getType()->isUnsignedIntegerType()) && + "asuint operands types mismatch"); + +Value *Op0 = EmitScalarExpr(E->getArg(0)); +auto *OutArg1 = dyn_cast(E->getArg(1)); +auto *OutArg2 = dyn_cast(E->getArg(2)); + +CallArgList Args; +auto [Op1BaseLValue, Op1TmpLValue] = +EmitHLSLOutArgExpr(OutArg1, Args, OutArg1->getType()); +auto [Op2BaseLValue, 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 35b5daaf6d4b55..abbf227e342b77 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -28,6 +28,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 +5459,8 @@ LValue CodeGenFunction::EmitOpaqueValueLValue(const OpaqueValueExpr *e) { return getOrCreateOpaqueLValueMapping(e); } -void CodeGenFunction::EmitHLSLOutArgExpr(const HLSLOutArgExpr *E, - CallArgList &Args, QualType Ty) { - +std::pa
[clang] [clang] Use {} instead of std::nullopt to initialize empty ArrayRef (PR #109399)
https://github.com/NagyDonat commented: StaticAnalyzer changes LGTM. https://github.com/llvm/llvm-project/pull/109399 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tools-extra] Use {} instead of std::nullopt to initialize empty ArrayRef (PR #109400)
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/109400 Follow up to #109133. >From ebffad800626acbdb06c74633c0950e24df755c8 Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Fri, 20 Sep 2024 11:16:23 +0100 Subject: [PATCH] [clang-tools-extra] Use {} instead of std::nullopt to initialize empty ArrayRef Follow up to #109133. --- clang-tools-extra/clang-query/Query.cpp | 2 +- .../unittests/clang-tidy/ClangTidyTest.h | 2 +- .../clang-tidy/IncludeCleanerTest.cpp | 22 +-- .../clang-tidy/IncludeInserterTest.cpp| 2 +- .../clang-tidy/NamespaceAliaserTest.cpp | 2 +- .../clang-tidy/ReadabilityModuleTest.cpp | 6 ++--- .../TransformerClangTidyCheckTest.cpp | 20 - .../clang-tidy/UsingInserterTest.cpp | 2 +- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/clang-tools-extra/clang-query/Query.cpp b/clang-tools-extra/clang-query/Query.cpp index 93f4104d39db8c..282d136aff721a 100644 --- a/clang-tools-extra/clang-query/Query.cpp +++ b/clang-tools-extra/clang-query/Query.cpp @@ -146,7 +146,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const { TD.emitDiagnostic( FullSourceLoc(R.getBegin(), AST->getSourceManager()), DiagnosticsEngine::Note, "\"" + BI->first + "\" binds here", -CharSourceRange::getTokenRange(R), std::nullopt); +CharSourceRange::getTokenRange(R), {}); } } if (QS.PrintOutput) { diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h index 078054c5194c54..e511eb6e49e8df 100644 --- a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h +++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h @@ -86,7 +86,7 @@ template std::string runCheckOnCode(StringRef Code, std::vector *Errors = nullptr, const Twine &Filename = "input.cc", - ArrayRef ExtraArgs = std::nullopt, + ArrayRef ExtraArgs = {}, const ClangTidyOptions &ExtraOptions = ClangTidyOptions(), std::map PathsToContent = std::map()) { diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp index 8da1051a860a8c..7344c73aa47dab 100644 --- a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp +++ b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp @@ -49,7 +49,7 @@ TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) { std::vector Errors; EXPECT_EQ(PostCode, runCheckOnCode( -PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(), +PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(), {{"bar.h", "#pragma once"}, {"vector", "#pragma once"}})); } @@ -78,7 +78,7 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) { EXPECT_EQ( PostCode, runCheckOnCode( - PreCode, &Errors, "file.cpp", std::nullopt, Opts, + PreCode, &Errors, "file.cpp", {}, Opts, {{"bar.h", "#pragma once"}, {"vector", "#pragma once"}, {"list", "#pragma once"}, @@ -105,7 +105,7 @@ int BazResult = baz(); std::vector Errors; EXPECT_EQ(PostCode, runCheckOnCode( -PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(), +PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(), {{"bar.h", R"(#pragma once #include "baz.h" int bar(); @@ -125,7 +125,7 @@ int BarResult2 = $diag2^bar();)"); { std::vector Errors; runCheckOnCode(Code.code(), &Errors, "file.cpp", -std::nullopt, ClangTidyOptions(), +{}, ClangTidyOptions(), {{"baz.h", R"(#pragma once #include "bar.h" )"}, @@ -142,7 +142,7 @@ int BarResult2 = $diag2^bar();)"); ClangTidyOptions Opts; Opts.CheckOptions.insert({"DeduplicateFindings", "false"}); runCheckOnCode(Code.code(), &Errors, "file.cpp", -std::nullopt, Opts, +{}, Opts, {{"baz.h", R"(#pragma once #include "bar.h" )"}, @@ -176,7 +176,7 @@ std::vector x; llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"}))}; std::vector Errors; EXPECT_EQ(PreCode, runCheckOnCode( - PreCode, &Errors, "file.cpp", std::nullopt, Opts, + PreCode, &Errors, "file.cpp", {}, Opts, {{"bar.h", R"(#pragma once
[clang-tools-extra] [clang-tools-extra] Use {} instead of std::nullopt to initialize empty ArrayRef (PR #109400)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Jay Foad (jayfoad) Changes Follow up to #109133. --- Full diff: https://github.com/llvm/llvm-project/pull/109400.diff 8 Files Affected: - (modified) clang-tools-extra/clang-query/Query.cpp (+1-1) - (modified) clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h (+1-1) - (modified) clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp (+31-37) - (modified) clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp (+1-1) - (modified) clang-tools-extra/unittests/clang-tidy/NamespaceAliaserTest.cpp (+2-3) - (modified) clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp (+3-4) - (modified) clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp (+26-26) - (modified) clang-tools-extra/unittests/clang-tidy/UsingInserterTest.cpp (+2-3) ``diff diff --git a/clang-tools-extra/clang-query/Query.cpp b/clang-tools-extra/clang-query/Query.cpp index 93f4104d39db8c..282d136aff721a 100644 --- a/clang-tools-extra/clang-query/Query.cpp +++ b/clang-tools-extra/clang-query/Query.cpp @@ -146,7 +146,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const { TD.emitDiagnostic( FullSourceLoc(R.getBegin(), AST->getSourceManager()), DiagnosticsEngine::Note, "\"" + BI->first + "\" binds here", -CharSourceRange::getTokenRange(R), std::nullopt); +CharSourceRange::getTokenRange(R), {}); } } if (QS.PrintOutput) { diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h index 078054c5194c54..e511eb6e49e8df 100644 --- a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h +++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h @@ -86,7 +86,7 @@ template std::string runCheckOnCode(StringRef Code, std::vector *Errors = nullptr, const Twine &Filename = "input.cc", - ArrayRef ExtraArgs = std::nullopt, + ArrayRef ExtraArgs = {}, const ClangTidyOptions &ExtraOptions = ClangTidyOptions(), std::map PathsToContent = std::map()) { diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp index 8da1051a860a8c..d400cf6fe2d576 100644 --- a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp +++ b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp @@ -49,7 +49,7 @@ TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) { std::vector Errors; EXPECT_EQ(PostCode, runCheckOnCode( -PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(), +PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(), {{"bar.h", "#pragma once"}, {"vector", "#pragma once"}})); } @@ -78,7 +78,7 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) { EXPECT_EQ( PostCode, runCheckOnCode( - PreCode, &Errors, "file.cpp", std::nullopt, Opts, + PreCode, &Errors, "file.cpp", {}, Opts, {{"bar.h", "#pragma once"}, {"vector", "#pragma once"}, {"list", "#pragma once"}, @@ -103,14 +103,13 @@ int BazResult = baz(); )"; std::vector Errors; - EXPECT_EQ(PostCode, -runCheckOnCode( -PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(), -{{"bar.h", R"(#pragma once + EXPECT_EQ(PostCode, runCheckOnCode( + PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(), + {{"bar.h", R"(#pragma once #include "baz.h" int bar(); )"}, - {"baz.h", R"(#pragma once + {"baz.h", R"(#pragma once int baz(); )"}})); } @@ -124,8 +123,8 @@ int BarResult2 = $diag2^bar();)"); { std::vector Errors; -runCheckOnCode(Code.code(), &Errors, "file.cpp", -std::nullopt, ClangTidyOptions(), +runCheckOnCode(Code.code(), &Errors, "file.cpp", {}, +ClangTidyOptions(), {{"baz.h", R"(#pragma once #include "bar.h" )"}, @@ -141,8 +140,8 @@ int BarResult2 = $diag2^bar();)"); std::vector Errors; ClangTidyOptions Opts; Opts.CheckOptions.insert({"DeduplicateFindings", "false"}); -runCheckOnCode(Code.code(), &Errors, "file.cpp", -std::nullopt, Opts, +runCheckOnCode(Code.code(), &Errors, "file.cpp", {}, +Opts, {{"baz.h", R"(#pragma once
[clang] [llvm] [CVP] Infer range return attribute (PR #99620)
nikic wrote: > Missing fold: https://alive2.llvm.org/ce/z/2rmc3h See > [dtcxzyw/llvm-opt-benchmark#1342 > (comment)](https://github.com/dtcxzyw/llvm-opt-benchmark/pull/1342#discussion_r1767033125) In principle, I think this could be supported by making decomposeBitTestICmp detect that `ugt 255` means `& 256 == 1` together with information from computeConstantRange(). Not sure if it's worth it... https://github.com/llvm/llvm-project/pull/99620 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tools-extra] Use {} instead of std::nullopt to initialize empty ArrayRef (PR #109400)
https://github.com/jayfoad updated https://github.com/llvm/llvm-project/pull/109400 >From ebffad800626acbdb06c74633c0950e24df755c8 Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Fri, 20 Sep 2024 11:16:23 +0100 Subject: [PATCH 1/2] [clang-tools-extra] Use {} instead of std::nullopt to initialize empty ArrayRef Follow up to #109133. --- clang-tools-extra/clang-query/Query.cpp | 2 +- .../unittests/clang-tidy/ClangTidyTest.h | 2 +- .../clang-tidy/IncludeCleanerTest.cpp | 22 +-- .../clang-tidy/IncludeInserterTest.cpp| 2 +- .../clang-tidy/NamespaceAliaserTest.cpp | 2 +- .../clang-tidy/ReadabilityModuleTest.cpp | 6 ++--- .../TransformerClangTidyCheckTest.cpp | 20 - .../clang-tidy/UsingInserterTest.cpp | 2 +- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/clang-tools-extra/clang-query/Query.cpp b/clang-tools-extra/clang-query/Query.cpp index 93f4104d39db8c..282d136aff721a 100644 --- a/clang-tools-extra/clang-query/Query.cpp +++ b/clang-tools-extra/clang-query/Query.cpp @@ -146,7 +146,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const { TD.emitDiagnostic( FullSourceLoc(R.getBegin(), AST->getSourceManager()), DiagnosticsEngine::Note, "\"" + BI->first + "\" binds here", -CharSourceRange::getTokenRange(R), std::nullopt); +CharSourceRange::getTokenRange(R), {}); } } if (QS.PrintOutput) { diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h index 078054c5194c54..e511eb6e49e8df 100644 --- a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h +++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h @@ -86,7 +86,7 @@ template std::string runCheckOnCode(StringRef Code, std::vector *Errors = nullptr, const Twine &Filename = "input.cc", - ArrayRef ExtraArgs = std::nullopt, + ArrayRef ExtraArgs = {}, const ClangTidyOptions &ExtraOptions = ClangTidyOptions(), std::map PathsToContent = std::map()) { diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp index 8da1051a860a8c..7344c73aa47dab 100644 --- a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp +++ b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp @@ -49,7 +49,7 @@ TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) { std::vector Errors; EXPECT_EQ(PostCode, runCheckOnCode( -PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(), +PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(), {{"bar.h", "#pragma once"}, {"vector", "#pragma once"}})); } @@ -78,7 +78,7 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) { EXPECT_EQ( PostCode, runCheckOnCode( - PreCode, &Errors, "file.cpp", std::nullopt, Opts, + PreCode, &Errors, "file.cpp", {}, Opts, {{"bar.h", "#pragma once"}, {"vector", "#pragma once"}, {"list", "#pragma once"}, @@ -105,7 +105,7 @@ int BazResult = baz(); std::vector Errors; EXPECT_EQ(PostCode, runCheckOnCode( -PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(), +PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(), {{"bar.h", R"(#pragma once #include "baz.h" int bar(); @@ -125,7 +125,7 @@ int BarResult2 = $diag2^bar();)"); { std::vector Errors; runCheckOnCode(Code.code(), &Errors, "file.cpp", -std::nullopt, ClangTidyOptions(), +{}, ClangTidyOptions(), {{"baz.h", R"(#pragma once #include "bar.h" )"}, @@ -142,7 +142,7 @@ int BarResult2 = $diag2^bar();)"); ClangTidyOptions Opts; Opts.CheckOptions.insert({"DeduplicateFindings", "false"}); runCheckOnCode(Code.code(), &Errors, "file.cpp", -std::nullopt, Opts, +{}, Opts, {{"baz.h", R"(#pragma once #include "bar.h" )"}, @@ -176,7 +176,7 @@ std::vector x; llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"}))}; std::vector Errors; EXPECT_EQ(PreCode, runCheckOnCode( - PreCode, &Errors, "file.cpp", std::nullopt, Opts, + PreCode, &Errors, "file.cpp", {}, Opts, {{"bar.h", R"(#pragma once #i
[clang] [lldb] [llvm] [mlir] [APInt] Assert correct values in APInt constructor (PR #80309)
https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/80309 >From 7467ecf67c706ffdfa79eaebdc9528002b74c5af Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 19 Sep 2024 17:27:13 +0200 Subject: [PATCH] apint only --- clang/lib/AST/ByteCode/IntegralAP.h | 6 ++-- clang/lib/CodeGen/CGVTT.cpp | 5 +-- clang/lib/CodeGen/ItaniumCXXABI.cpp | 5 +-- clang/lib/Parse/ParseInit.cpp | 4 ++- clang/lib/Sema/SemaExpr.cpp | 7 ++-- clang/lib/Sema/SemaOpenMP.cpp | 4 ++- lldb/source/Expression/DWARFExpression.cpp| 7 ++-- llvm/include/llvm/ADT/APFixedPoint.h | 4 ++- llvm/lib/Analysis/ConstantFolding.cpp | 3 +- llvm/lib/Analysis/Loads.cpp | 6 ++-- llvm/lib/Analysis/MemoryBuiltins.cpp | 2 ++ llvm/lib/Analysis/ScalarEvolution.cpp | 2 +- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 3 +- .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 5 ++- .../SelectionDAG/SelectionDAGBuilder.cpp | 3 +- .../CodeGen/SelectionDAG/SelectionDAGISel.cpp | 8 +++-- .../CodeGen/SelectionDAG/TargetLowering.cpp | 8 +++-- llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp | 2 +- llvm/lib/IR/Constants.cpp | 4 ++- .../Target/AArch64/AArch64ISelLowering.cpp| 32 +-- llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp | 2 +- .../AMDGPU/AMDGPUInstructionSelector.cpp | 2 +- .../Disassembler/AMDGPUDisassembler.cpp | 2 +- .../MCTargetDesc/AMDGPUMCTargetDesc.cpp | 2 +- llvm/lib/Target/AMDGPU/SIInstrInfo.cpp| 17 +++--- .../Target/AMDGPU/SIShrinkInstructions.cpp| 4 +-- .../lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 4 ++- .../Hexagon/HexagonConstPropagation.cpp | 3 +- llvm/lib/Target/Hexagon/HexagonGenExtract.cpp | 2 +- llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 4 ++- llvm/lib/Target/X86/X86ISelLowering.cpp | 6 ++-- llvm/lib/Transforms/IPO/ArgumentPromotion.cpp | 3 +- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 2 +- llvm/unittests/ADT/APFixedPointTest.cpp | 9 +++--- mlir/include/mlir/IR/BuiltinAttributes.td | 4 ++- mlir/include/mlir/IR/OpImplementation.h | 3 +- .../Conversion/TosaToArith/TosaToArith.cpp| 2 +- .../Dialect/ControlFlow/IR/ControlFlowOps.cpp | 2 +- mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp| 2 +- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 2 +- mlir/lib/IR/Builders.cpp | 16 +++--- .../SPIRV/Deserialization/Deserializer.cpp| 6 ++-- .../Dialect/SPIRV/SerializationTest.cpp | 2 +- 43 files changed, 139 insertions(+), 82 deletions(-) diff --git a/clang/lib/AST/ByteCode/IntegralAP.h b/clang/lib/AST/ByteCode/IntegralAP.h index a4d656433344b7..6ab3d09ec85d5b 100644 --- a/clang/lib/AST/ByteCode/IntegralAP.h +++ b/clang/lib/AST/ByteCode/IntegralAP.h @@ -61,7 +61,7 @@ template class IntegralAP final { IntegralAP(APInt V) : V(V) {} /// Arbitrary value for uninitialized variables. - IntegralAP() : IntegralAP(-1, 3) {} + IntegralAP() : IntegralAP(Signed ? -1 : 7, 3) {} IntegralAP operator-() const { return IntegralAP(-V); } IntegralAP operator-(const IntegralAP &Other) const { @@ -112,7 +112,9 @@ template class IntegralAP final { template static IntegralAP from(Integral I, unsigned BitWidth) { -APInt Copy = APInt(BitWidth, static_cast(I), InputSigned); +// TODO: Avoid implicit trunc? +APInt Copy = APInt(BitWidth, static_cast(I), InputSigned, + /*implicitTrunc=*/true); return IntegralAP(Copy); } diff --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp index 20bd2c2fc2c642..989a07d09d50ee 100644 --- a/clang/lib/CodeGen/CGVTT.cpp +++ b/clang/lib/CodeGen/CGVTT.cpp @@ -85,8 +85,9 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT, cast(VTable->getValueType()) ->getElementType(AddressPoint.VTableIndex)); unsigned Offset = ComponentSize * AddressPoint.AddressPointIndex; - llvm::ConstantRange InRange(llvm::APInt(32, -Offset, true), - llvm::APInt(32, VTableSize - Offset, true)); + llvm::ConstantRange InRange( + llvm::APInt(32, (int)-Offset, true), + llvm::APInt(32, (int)(VTableSize - Offset), true)); llvm::Constant *Init = llvm::ConstantExpr::getGetElementPtr( VTable->getValueType(), VTable, Idxs, /*InBounds=*/true, InRange); diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index dcc35d5689831e..ff018fa22db866 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -2099,8 +2099,9 @@ ItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base, unsigned VTableSize = ComponentSize * Layout.getVTableSize(AddressPoint.VTableIndex); unsigned Offset = ComponentSize * AddressPoint.AddressPointInde
[clang] [lldb] [llvm] [mlir] [APInt] Fix APInt constructions where value does not fix bitwidth (PR #80309)
https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/80309 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e5717fb - [clang][wasm] Replace the target iminmax intrinsics with the equivalent generic `__builtin_elementwise_min/max` intrinsics (#109259)
Author: Simon Pilgrim Date: 2024-09-20T11:48:57+01:00 New Revision: e5717fb61d844895d4ca88659646d04ac749bc82 URL: https://github.com/llvm/llvm-project/commit/e5717fb61d844895d4ca88659646d04ac749bc82 DIFF: https://github.com/llvm/llvm-project/commit/e5717fb61d844895d4ca88659646d04ac749bc82.diff LOG: [clang][wasm] Replace the target iminmax intrinsics with the equivalent generic `__builtin_elementwise_min/max` intrinsics (#109259) Noticed while working on #109160 Added: Modified: clang/include/clang/Basic/BuiltinsWebAssembly.def clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Headers/wasm_simd128.h clang/test/CodeGen/builtins-wasm.c Removed: diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def b/clang/include/clang/Basic/BuiltinsWebAssembly.def index be9ba7599fe5af..6a24c9704eb876 100644 --- a/clang/include/clang/Basic/BuiltinsWebAssembly.def +++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def @@ -83,19 +83,6 @@ TARGET_BUILTIN(__builtin_wasm_abs_i16x8, "V8sV8s", "nc", "simd128") TARGET_BUILTIN(__builtin_wasm_abs_i32x4, "V4iV4i", "nc", "simd128") TARGET_BUILTIN(__builtin_wasm_abs_i64x2, "V2LLiV2LLi", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_min_s_i8x16, "V16ScV16ScV16Sc", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_min_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_max_s_i8x16, "V16ScV16ScV16Sc", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_max_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_min_s_i16x8, "V8sV8sV8s", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_min_u_i16x8, "V8UsV8UsV8Us", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_max_s_i16x8, "V8sV8sV8s", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_max_u_i16x8, "V8UsV8UsV8Us", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_min_s_i32x4, "V4iV4iV4i", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_min_u_i32x4, "V4UiV4UiV4Ui", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_max_s_i32x4, "V4iV4iV4i", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_max_u_i32x4, "V4UiV4UiV4Ui", "nc", "simd128") - TARGET_BUILTIN(__builtin_wasm_avgr_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128") TARGET_BUILTIN(__builtin_wasm_avgr_u_i16x8, "V8UsV8UsV8Us", "nc", "simd128") diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index e2711f1ba70239..2c4e872b9d7e97 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -21487,47 +21487,6 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, Value *ICmp = Builder.CreateICmpSLT(Vec, Zero, "abscond"); return Builder.CreateSelect(ICmp, Neg, Vec, "abs"); } - case WebAssembly::BI__builtin_wasm_min_s_i8x16: - case WebAssembly::BI__builtin_wasm_min_u_i8x16: - case WebAssembly::BI__builtin_wasm_max_s_i8x16: - case WebAssembly::BI__builtin_wasm_max_u_i8x16: - case WebAssembly::BI__builtin_wasm_min_s_i16x8: - case WebAssembly::BI__builtin_wasm_min_u_i16x8: - case WebAssembly::BI__builtin_wasm_max_s_i16x8: - case WebAssembly::BI__builtin_wasm_max_u_i16x8: - case WebAssembly::BI__builtin_wasm_min_s_i32x4: - case WebAssembly::BI__builtin_wasm_min_u_i32x4: - case WebAssembly::BI__builtin_wasm_max_s_i32x4: - case WebAssembly::BI__builtin_wasm_max_u_i32x4: { -Value *LHS = EmitScalarExpr(E->getArg(0)); -Value *RHS = EmitScalarExpr(E->getArg(1)); -Value *ICmp; -switch (BuiltinID) { -case WebAssembly::BI__builtin_wasm_min_s_i8x16: -case WebAssembly::BI__builtin_wasm_min_s_i16x8: -case WebAssembly::BI__builtin_wasm_min_s_i32x4: - ICmp = Builder.CreateICmpSLT(LHS, RHS); - break; -case WebAssembly::BI__builtin_wasm_min_u_i8x16: -case WebAssembly::BI__builtin_wasm_min_u_i16x8: -case WebAssembly::BI__builtin_wasm_min_u_i32x4: - ICmp = Builder.CreateICmpULT(LHS, RHS); - break; -case WebAssembly::BI__builtin_wasm_max_s_i8x16: -case WebAssembly::BI__builtin_wasm_max_s_i16x8: -case WebAssembly::BI__builtin_wasm_max_s_i32x4: - ICmp = Builder.CreateICmpSGT(LHS, RHS); - break; -case WebAssembly::BI__builtin_wasm_max_u_i8x16: -case WebAssembly::BI__builtin_wasm_max_u_i16x8: -case WebAssembly::BI__builtin_wasm_max_u_i32x4: - ICmp = Builder.CreateICmpUGT(LHS, RHS); - break; -default: - llvm_unreachable("unexpected builtin ID"); -} -return Builder.CreateSelect(ICmp, LHS, RHS); - } case WebAssembly::BI__builtin_wasm_avgr_u_i8x16: case WebAssembly::BI__builtin_wasm_avgr_u_i16x8: { Value *LHS = EmitScalarExpr(E->getArg(0)); diff --git a/clang/lib/Headers/wasm_simd128.h b/clang/lib/Headers/wasm_simd128.h index 22f0e27ccf756e..bd160bcc9b6964 100644 --- a/clang/lib/Headers/wasm_simd128.h +++ b/clang/lib/Headers/wasm_simd128.h @@ -1007,22 +1007,22 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_sub_sat(v128_t __a,
[clang] 2c90eb9 - [clang][wasm] Replace the target integer add saturate intrinsics with the equivalent generic `__builtin_elementwise_add_sat` intrinsics (#109269)
Author: Simon Pilgrim Date: 2024-09-20T11:49:31+01:00 New Revision: 2c90eb990af176f2b57baecd2920481243845bb9 URL: https://github.com/llvm/llvm-project/commit/2c90eb990af176f2b57baecd2920481243845bb9 DIFF: https://github.com/llvm/llvm-project/commit/2c90eb990af176f2b57baecd2920481243845bb9.diff LOG: [clang][wasm] Replace the target integer add saturate intrinsics with the equivalent generic `__builtin_elementwise_add_sat` intrinsics (#109269) Noticed while working on #109160 I've left out the sub_sat intrinsics for now - not sure about the history behind them using Intrinsic::wasm_sub_sat_* instead of Intrinsic::*sub_sat Added: Modified: clang/include/clang/Basic/BuiltinsWebAssembly.def clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Headers/wasm_simd128.h clang/test/CodeGen/builtins-wasm.c Removed: diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def b/clang/include/clang/Basic/BuiltinsWebAssembly.def index 6a24c9704eb876..90441a5d500120 100644 --- a/clang/include/clang/Basic/BuiltinsWebAssembly.def +++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def @@ -68,11 +68,6 @@ TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f64, "LLid", "nc", "nontrappi // SIMD builtins TARGET_BUILTIN(__builtin_wasm_swizzle_i8x16, "V16ScV16ScV16Sc", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_add_sat_s_i8x16, "V16ScV16ScV16Sc", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_add_sat_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_add_sat_s_i16x8, "V8sV8sV8s", "nc", "simd128") -TARGET_BUILTIN(__builtin_wasm_add_sat_u_i16x8, "V8UsV8UsV8Us", "nc", "simd128") - TARGET_BUILTIN(__builtin_wasm_sub_sat_s_i8x16, "V16ScV16ScV16Sc", "nc", "simd128") TARGET_BUILTIN(__builtin_wasm_sub_sat_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128") TARGET_BUILTIN(__builtin_wasm_sub_sat_s_i16x8, "V8sV8sV8s", "nc", "simd128") diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 2c4e872b9d7e97..3d1138b7773853 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -21443,24 +21443,12 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_swizzle); return Builder.CreateCall(Callee, {Src, Indices}); } - case WebAssembly::BI__builtin_wasm_add_sat_s_i8x16: - case WebAssembly::BI__builtin_wasm_add_sat_u_i8x16: - case WebAssembly::BI__builtin_wasm_add_sat_s_i16x8: - case WebAssembly::BI__builtin_wasm_add_sat_u_i16x8: case WebAssembly::BI__builtin_wasm_sub_sat_s_i8x16: case WebAssembly::BI__builtin_wasm_sub_sat_u_i8x16: case WebAssembly::BI__builtin_wasm_sub_sat_s_i16x8: case WebAssembly::BI__builtin_wasm_sub_sat_u_i16x8: { unsigned IntNo; switch (BuiltinID) { -case WebAssembly::BI__builtin_wasm_add_sat_s_i8x16: -case WebAssembly::BI__builtin_wasm_add_sat_s_i16x8: - IntNo = Intrinsic::sadd_sat; - break; -case WebAssembly::BI__builtin_wasm_add_sat_u_i8x16: -case WebAssembly::BI__builtin_wasm_add_sat_u_i16x8: - IntNo = Intrinsic::uadd_sat; - break; case WebAssembly::BI__builtin_wasm_sub_sat_s_i8x16: case WebAssembly::BI__builtin_wasm_sub_sat_s_i16x8: IntNo = Intrinsic::wasm_sub_sat_signed; diff --git a/clang/lib/Headers/wasm_simd128.h b/clang/lib/Headers/wasm_simd128.h index bd160bcc9b6964..b1bef7097800b9 100644 --- a/clang/lib/Headers/wasm_simd128.h +++ b/clang/lib/Headers/wasm_simd128.h @@ -982,12 +982,12 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_add(v128_t __a, static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_add_sat(v128_t __a, v128_t __b) { - return (v128_t)__builtin_wasm_add_sat_s_i8x16((__i8x16)__a, (__i8x16)__b); + return (v128_t)__builtin_elementwise_add_sat((__i8x16)__a, (__i8x16)__b); } static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_add_sat(v128_t __a, v128_t __b) { - return (v128_t)__builtin_wasm_add_sat_u_i8x16((__u8x16)__a, (__u8x16)__b); + return (v128_t)__builtin_elementwise_add_sat((__u8x16)__a, (__u8x16)__b); } static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_sub(v128_t __a, @@ -1068,12 +1068,12 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_add(v128_t __a, static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_add_sat(v128_t __a, v128_t __b) { - return (v128_t)__builtin_wasm_add_sat_s_i16x8((__i16x8)__a, (__i16x8)__b); + return (v128_t)__builtin_elementwise_add_sat((__i16x8)__a, (__i16x8)__b); } static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u16x8_add_sat(v128_t __a, v128_t __b) { - return (v128_t)__builtin_wasm_add_sat_u
[clang] [lldb] [llvm] [mlir] [APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) (PR #80309)
nikic wrote: I think this is ready for review now. I've landed many parts of this PR separately already, and am happy to land this in parts (or split as needed). https://github.com/llvm/llvm-project/pull/80309 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][wasm] Replace the target integer add saturate intrinsics with the equivalent generic `__builtin_elementwise_add_sat` intrinsics (PR #109269)
https://github.com/RKSimon closed https://github.com/llvm/llvm-project/pull/109269 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][wasm] Replace the target iminmax intrinsics with the equivalent generic `__builtin_elementwise_min/max` intrinsics (PR #109259)
https://github.com/RKSimon closed https://github.com/llvm/llvm-project/pull/109259 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] [llvm] [mlir] [APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) (PR #80309)
@@ -4377,7 +4377,7 @@ AMDGPUInstructionSelector::selectGlobalSAddr(MachineOperand &Root) const { // instructions to perform VALU adds with immediates or inline literals. unsigned NumLiterals = !TII.isInlineConstant(APInt(32, ConstOffset & 0x)) + -!TII.isInlineConstant(APInt(32, ConstOffset >> 32)); +!TII.isInlineConstant(APInt(32, uint64_t(ConstOffset) >> 32)); arsenm wrote: These should probably just use Lo_32/Hi_32 https://github.com/llvm/llvm-project/pull/80309 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] [llvm] [mlir] [APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) (PR #80309)
@@ -1806,7 +1806,7 @@ bool AMDGPUDAGToDAGISel::SelectGlobalSAddr(SDNode *N, // instructions to perform VALU adds with immediates or inline literals. unsigned NumLiterals = !TII->isInlineConstant(APInt(32, COffsetVal & 0x)) + - !TII->isInlineConstant(APInt(32, COffsetVal >> 32)); + !TII->isInlineConstant(APInt(32, uint64_t(COffsetVal) >> 32)); arsenm wrote: These should probably just use Lo_32/Hi_32 https://github.com/llvm/llvm-project/pull/80309 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][TableGen] Support specifying address space in clang builtin prototypes (PR #108497)
vikramRH wrote: > > > > Gentle ping @AaronBallman , @philnik777 , @fpetrogalli :) > > > > > > > > > Ah, sorry -- because the PR is marked as a Draft, I figured it wasn't > > > ready for review yet. > > > I think I'd rather this was expressed differently; we already don't put > > > attribute information in the prototype anyway (`noexcept` as an example), > > > so I'd prefer to continue down that road and put the address space > > > information into the `Attributes` field. e.g., > > > ``` > > > def BuiltinCPUIs : Builtin { > > > let Spellings = ["__builtin_cpu_is"]; > > > let Attributes = [NoThrow, Const, AddressSpace<2>]; > > > let Prototype = "bool(char const*)"; > > > } > > > ``` > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I think that makes it more clean in terms of specifying the attribute, > > > and it also means we can name the address spaces in `BuiltinsBase.td` if > > > we would like, which is even easier for folks to understand when reading > > > `Builtins.td` > > > WDYT? > > > > > > Thanks for the reply @AaronBallman . The reason this is still a draft is > > that I wanted it to be an initial proposal to get some inputs and a > > consensus on the final design. and about it being part of the "Attributes" > > field, one major issue is that the address space information should be per > > argument including the return type. "Attributes" field currently expresses > > attributes to the function. If attribute in the prototype is not desired, > > probably a new field that lets us specify per argument attributes makes > > sense ? > > Oh! I hadn't realized this was needed on a per-parameter basis. Oof that > makes this more awkward. I'd still love to avoid writing this as part of the > signature; I think we could use the existing `IndexedAttribute` to specify > which argument the attribute applies to. e.g., > > ``` > class AddressSpace : IndexedAttribute<"something", > Idx> { > int SpaceNum = AddrSpaceNum; > } > ``` Makes sense, I will give this a try and update the PR https://github.com/llvm/llvm-project/pull/108497 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Use {} instead of std::nullopt to initialize empty ArrayRef (PR #109399)
cc-ww wrote: LGTM. https://github.com/llvm/llvm-project/pull/109399 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RISCV] Fix incorrect check prefix in riscv32-toolchain.c and riscv64-toolchain.c. NFC. (PR #109390)
https://github.com/wangpc-pp approved this pull request. https://github.com/llvm/llvm-project/pull/109390 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Fix checkArmStreamingBuiltin for 'sve-b16b16' (PR #109420)
https://github.com/sdesmalen-arm created https://github.com/llvm/llvm-project/pull/109420 The implementation made the assumption that any feature starting with "sve" meant that this was an SVE feature. This is not the case for "sve-b16b16", as this is a feature that applies to both SVE and SME. This meant that: ``` __attribute__((target("+sme2,+sve2,+sve-b16b16"))) svbfloat16_t foo(svbfloat16_t a, svbfloat16_t b, svbfloat16_t c) __arm_streaming { return svclamp_bf16(a, b, c); } ``` would result in an incorrect diagnostic saying that `svclamp_bf16` could only be used in non-streaming functions. >From af4cd0b3643e682fcb34042d209df03037743eb0 Mon Sep 17 00:00:00 2001 From: Sander de Smalen Date: Fri, 20 Sep 2024 14:16:23 +0100 Subject: [PATCH] [Clang][AArch64] Fix checkArmStreamingBuiltin for 'sve-b16b16' The implementation made the assumption that any feature starting with "sve" meant that this was an SVE feature. This is not the case for "sve-b16b16", as this is a feature that applies to both SVE and SME. This meant that: __attribute__((target("+sme2,+sve2,+sve-b16b16"))) svbfloat16_t foo(svbfloat16_t a, svbfloat16_t b, svbfloat16_t c) __arm_streaming { return svclamp_bf16(a, b, c); } would result in an incorrect diagnostic saying that `svclamp_bf16` could only be used in non-streaming functions. --- clang/lib/Sema/SemaARM.cpp| 21 --- ...reaming-sme-or-nonstreaming-sve-builtins.c | 6 ++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp index efde354860de43..fba1453e5d38fc 100644 --- a/clang/lib/Sema/SemaARM.cpp +++ b/clang/lib/Sema/SemaARM.cpp @@ -567,15 +567,18 @@ static bool checkArmStreamingBuiltin(Sema &S, CallExpr *TheCall, // * When compiling for SVE only, the caller must be in non-streaming mode. // * When compiling for both SVE and SME, the caller can be in either mode. if (BuiltinType == SemaARM::VerifyRuntimeMode) { -auto DisableFeatures = [](llvm::StringMap &Map, StringRef S) { - for (StringRef K : Map.keys()) -if (K.starts_with(S)) - Map[K] = false; -}; - llvm::StringMap CallerFeatureMapWithoutSVE; S.Context.getFunctionFeatureMap(CallerFeatureMapWithoutSVE, FD); -DisableFeatures(CallerFeatureMapWithoutSVE, "sve"); +CallerFeatureMapWithoutSVE["sve"] = false; +CallerFeatureMapWithoutSVE["sve2"] = false; +CallerFeatureMapWithoutSVE["sve2p1"] = false; +// FIXME: This list must be updated with future extensions, because when +// an intrinsic is enabled by (sve2p1|sme2p1), disabling just "sve" is +// not sufficient, as the feature dependences are not resolved. +// At the moment, it should be sufficient to test the 'base' architectural +// support for SVE and SME, which must always be provided in the +// target guard. e.g. TargetGuard = "sve-b16b16" without "sme" or "sve" +// is not sufficient. // Avoid emitting diagnostics for a function that can never compile. if (FnType == SemaARM::ArmStreaming && !CallerFeatureMapWithoutSVE["sme"]) @@ -583,7 +586,9 @@ static bool checkArmStreamingBuiltin(Sema &S, CallExpr *TheCall, llvm::StringMap CallerFeatureMapWithoutSME; S.Context.getFunctionFeatureMap(CallerFeatureMapWithoutSME, FD); -DisableFeatures(CallerFeatureMapWithoutSME, "sme"); +CallerFeatureMapWithoutSME["sme"] = false; +CallerFeatureMapWithoutSME["sme2"] = false; +CallerFeatureMapWithoutSME["sme2p1"] = false; // We know the builtin requires either some combination of SVE flags, or // some combination of SME flags, but we need to figure out which part diff --git a/clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c b/clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c index 45776eb13e4fbc..792d79ee3e600d 100644 --- a/clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c +++ b/clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c @@ -38,6 +38,12 @@ svfloat32_t good6(svfloat32_t a, svfloat32_t b, svfloat32_t c) __arm_streaming_c return svclamp(a, b, c); } +// Test that the +sve-b16b16 is not considered an SVE flag (it applies to both) +__attribute__((target("+sme2,+sve2,+sve-b16b16"))) +svbfloat16_t good7(svbfloat16_t a, svbfloat16_t b, svbfloat16_t c) __arm_streaming { +return svclamp_bf16(a, b, c); +} + // Without '+sme2', the builtin is only valid in non-streaming mode. __attribute__((target("+sve2p1,+sme"))) svfloat32_t bad1(svfloat32_t a, svfloat32_t b, svfloat32_t c) __arm_streaming { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Improve robustness when clang-tidy check names contain leading spaces. (PR #109421)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clangd Author: Haojian Wu (hokein) Changes The current logic assumes that check names do not have leading spaces. In cases like "-*, clang-diagnostic*", when processing the second check " clang-diagnostics-*" (with a leading space), the check fails on `CDPrefix.starts_with(Check)`, resulting in all diagnostics remaining disabled. --- Full diff: https://github.com/llvm/llvm-project/pull/109421.diff 2 Files Affected: - (modified) clang-tools-extra/clangd/ParsedAST.cpp (+2) - (modified) clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp (+4) ``diff diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp index 4491be9aa0362b..5cf1691ce39617 100644 --- a/clang-tools-extra/clangd/ParsedAST.cpp +++ b/clang-tools-extra/clangd/ParsedAST.cpp @@ -280,6 +280,8 @@ class TidyDiagnosticGroups { llvm::StringRef Check; while (!Checks.empty()) { std::tie(Check, Checks) = Checks.split(','); + Check = Check.trim(); + if (Check.empty()) continue; diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp index 096f77e414f5a5..efb2e5ed2fbe1d 100644 --- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp @@ -748,6 +748,10 @@ TEST(DiagnosticTest, ClangTidyEnablesClangWarning) { TU.ExtraArgs = {"-Wunused"}; TU.ClangTidyProvider = addClangArgs({"-Wno-unused"}, {}); EXPECT_THAT(TU.build().getDiagnostics(), IsEmpty()); + + TU.ExtraArgs = {"-Wno-unused"}; + TU.ClangTidyProvider = addClangArgs({"-Wunused"}, {"-*, clang-diagnostic-*"}); + EXPECT_THAT(TU.build().getDiagnostics(), SizeIs(1)); } TEST(DiagnosticTest, LongFixMessages) { `` https://github.com/llvm/llvm-project/pull/109421 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Fix checkArmStreamingBuiltin for 'sve-b16b16' (PR #109420)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Sander de Smalen (sdesmalen-arm) Changes The implementation made the assumption that any feature starting with "sve" meant that this was an SVE feature. This is not the case for "sve-b16b16", as this is a feature that applies to both SVE and SME. This meant that: ``` __attribute__((target("+sme2,+sve2,+sve-b16b16"))) svbfloat16_t foo(svbfloat16_t a, svbfloat16_t b, svbfloat16_t c) __arm_streaming { return svclamp_bf16(a, b, c); } ``` would result in an incorrect diagnostic saying that `svclamp_bf16` could only be used in non-streaming functions. --- Full diff: https://github.com/llvm/llvm-project/pull/109420.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaARM.cpp (+13-8) - (modified) clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c (+6) ``diff diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp index efde354860de43..fba1453e5d38fc 100644 --- a/clang/lib/Sema/SemaARM.cpp +++ b/clang/lib/Sema/SemaARM.cpp @@ -567,15 +567,18 @@ static bool checkArmStreamingBuiltin(Sema &S, CallExpr *TheCall, // * When compiling for SVE only, the caller must be in non-streaming mode. // * When compiling for both SVE and SME, the caller can be in either mode. if (BuiltinType == SemaARM::VerifyRuntimeMode) { -auto DisableFeatures = [](llvm::StringMap &Map, StringRef S) { - for (StringRef K : Map.keys()) -if (K.starts_with(S)) - Map[K] = false; -}; - llvm::StringMap CallerFeatureMapWithoutSVE; S.Context.getFunctionFeatureMap(CallerFeatureMapWithoutSVE, FD); -DisableFeatures(CallerFeatureMapWithoutSVE, "sve"); +CallerFeatureMapWithoutSVE["sve"] = false; +CallerFeatureMapWithoutSVE["sve2"] = false; +CallerFeatureMapWithoutSVE["sve2p1"] = false; +// FIXME: This list must be updated with future extensions, because when +// an intrinsic is enabled by (sve2p1|sme2p1), disabling just "sve" is +// not sufficient, as the feature dependences are not resolved. +// At the moment, it should be sufficient to test the 'base' architectural +// support for SVE and SME, which must always be provided in the +// target guard. e.g. TargetGuard = "sve-b16b16" without "sme" or "sve" +// is not sufficient. // Avoid emitting diagnostics for a function that can never compile. if (FnType == SemaARM::ArmStreaming && !CallerFeatureMapWithoutSVE["sme"]) @@ -583,7 +586,9 @@ static bool checkArmStreamingBuiltin(Sema &S, CallExpr *TheCall, llvm::StringMap CallerFeatureMapWithoutSME; S.Context.getFunctionFeatureMap(CallerFeatureMapWithoutSME, FD); -DisableFeatures(CallerFeatureMapWithoutSME, "sme"); +CallerFeatureMapWithoutSME["sme"] = false; +CallerFeatureMapWithoutSME["sme2"] = false; +CallerFeatureMapWithoutSME["sme2p1"] = false; // We know the builtin requires either some combination of SVE flags, or // some combination of SME flags, but we need to figure out which part diff --git a/clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c b/clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c index 45776eb13e4fbc..792d79ee3e600d 100644 --- a/clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c +++ b/clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c @@ -38,6 +38,12 @@ svfloat32_t good6(svfloat32_t a, svfloat32_t b, svfloat32_t c) __arm_streaming_c return svclamp(a, b, c); } +// Test that the +sve-b16b16 is not considered an SVE flag (it applies to both) +__attribute__((target("+sme2,+sve2,+sve-b16b16"))) +svbfloat16_t good7(svbfloat16_t a, svbfloat16_t b, svbfloat16_t c) __arm_streaming { +return svclamp_bf16(a, b, c); +} + // Without '+sme2', the builtin is only valid in non-streaming mode. __attribute__((target("+sve2p1,+sme"))) svfloat32_t bad1(svfloat32_t a, svfloat32_t b, svfloat32_t c) __arm_streaming { `` https://github.com/llvm/llvm-project/pull/109420 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Improve robustness when clang-tidy check names contain leading spaces. (PR #109421)
https://github.com/hokein created https://github.com/llvm/llvm-project/pull/109421 The current logic assumes that check names do not have leading spaces. In cases like "-*, clang-diagnostic*", when processing the second check " clang-diagnostics-*" (with a leading space), the check fails on `CDPrefix.starts_with(Check)`, resulting in all diagnostics remaining disabled. >From 8542638d3460aa659b34107260788e2126371c44 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 20 Sep 2024 15:19:12 +0200 Subject: [PATCH] [clangd] Improve robustness when clang-tidy check names contain leading spaces. The current logic assumes that check names do not have leading spaces. In cases like "-*, clang-diagnostic*", when processing the second check " clang-diagnostics-*" (with a leading space), the check fails on `CDPrefix.starts_with(Check)`, resulting in all diagnostics remaining disabled. --- clang-tools-extra/clangd/ParsedAST.cpp | 2 ++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp | 4 2 files changed, 6 insertions(+) diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp index 4491be9aa0362b..5cf1691ce39617 100644 --- a/clang-tools-extra/clangd/ParsedAST.cpp +++ b/clang-tools-extra/clangd/ParsedAST.cpp @@ -280,6 +280,8 @@ class TidyDiagnosticGroups { llvm::StringRef Check; while (!Checks.empty()) { std::tie(Check, Checks) = Checks.split(','); + Check = Check.trim(); + if (Check.empty()) continue; diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp index 096f77e414f5a5..efb2e5ed2fbe1d 100644 --- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp @@ -748,6 +748,10 @@ TEST(DiagnosticTest, ClangTidyEnablesClangWarning) { TU.ExtraArgs = {"-Wunused"}; TU.ClangTidyProvider = addClangArgs({"-Wno-unused"}, {}); EXPECT_THAT(TU.build().getDiagnostics(), IsEmpty()); + + TU.ExtraArgs = {"-Wno-unused"}; + TU.ClangTidyProvider = addClangArgs({"-Wunused"}, {"-*, clang-diagnostic-*"}); + EXPECT_THAT(TU.build().getDiagnostics(), SizeIs(1)); } TEST(DiagnosticTest, LongFixMessages) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ADT] Simplify SmallSet (PR #109412)
https://github.com/kuhar approved this pull request. LGTM. Could you also add [NFC] to the PR title? https://github.com/llvm/llvm-project/pull/109412 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)
@@ -77,42 +78,46 @@ class IncrementalCompilerBuilder { llvm::StringRef CudaSDKPath; }; -/// Generate glue code between the Interpreter's built-in runtime and user code. -class RuntimeInterfaceBuilder { -public: - virtual ~RuntimeInterfaceBuilder() = default; - - using TransformExprFunction = ExprResult(RuntimeInterfaceBuilder *Builder, - Expr *, ArrayRef); - virtual TransformExprFunction *getPrintValueTransformer() = 0; -}; +class IncrementalAction; +class InProcessPrintingASTConsumer; /// Provides top-level interfaces for incremental compilation and execution. class Interpreter { + friend class Value; + friend InProcessPrintingASTConsumer; + std::unique_ptr TSCtx; + /// Long-lived, incremental parsing action. + std::unique_ptr Act; std::unique_ptr IncrParser; std::unique_ptr IncrExecutor; - std::unique_ptr RuntimeIB; // An optional parser for CUDA offloading std::unique_ptr DeviceParser; + /// List containing every information about every incrementally parsed piece AaronBallman wrote: ```suggestion /// List containing information about every incrementally parsed piece ``` https://github.com/llvm/llvm-project/pull/107737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)
https://github.com/AaronBallman approved this pull request. In general, I like the direction this is heading! I found a few nits, but nothing significant jumped out at me. Approving because I'm going to be out the next few weeks and I didn't want you to feel held up on my sign-off. https://github.com/llvm/llvm-project/pull/107737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)
@@ -241,28 +244,180 @@ IncrementalCompilerBuilder::CreateCudaHost() { return IncrementalCompilerBuilder::createCuda(false); } -Interpreter::Interpreter(std::unique_ptr CI, +class InProcessPrintingASTConsumer final : public MultiplexConsumer { + Interpreter &Interp; + +public: + InProcessPrintingASTConsumer(std::unique_ptr C, Interpreter &I) + : MultiplexConsumer(std::move(C)), Interp(I) {} + bool HandleTopLevelDecl(DeclGroupRef DGR) override final { +if (DGR.isNull()) + return true; + +for (Decl *D : DGR) + if (auto *TLSD = llvm::dyn_cast(D)) +if (TLSD && TLSD->isSemiMissing()) { + auto ExprOrErr = + Interp.ExtractValueFromExpr(cast(TLSD->getStmt())); + if (llvm::Error E = ExprOrErr.takeError()) { +llvm::logAllUnhandledErrors(std::move(E), llvm::errs(), +"Value printing failed: "); +return false; // abort parsing + } + TLSD->setStmt(*ExprOrErr); +} + +return MultiplexConsumer::HandleTopLevelDecl(DGR); + } +}; + +/// A custom action enabling the incremental processing functionality. +/// +/// The usual \p FrontendAction expects one call to ExecuteAction and once it +/// sees a call to \p EndSourceFile it deletes some of the important objects +/// such as \p Preprocessor and \p Sema assuming no further input will come. +/// +/// \p IncrementalAction ensures it keep its underlying action's objects alive +/// as long as the \p IncrementalParser needs them. +/// +class IncrementalAction : public WrapperFrontendAction { +private: + bool IsTerminating = false; + Interpreter &Interp; + std::unique_ptr Consumer; + +public: + IncrementalAction(CompilerInstance &CI, llvm::LLVMContext &LLVMCtx, +llvm::Error &Err, Interpreter &I, +std::unique_ptr Consumer = nullptr) + : WrapperFrontendAction([&]() { + llvm::ErrorAsOutParameter EAO(&Err); + std::unique_ptr Act; + switch (CI.getFrontendOpts().ProgramAction) { + default: +Err = llvm::createStringError( +std::errc::state_not_recoverable, +"Driver initialization failed. " +"Incremental mode for action %d is not supported", +CI.getFrontendOpts().ProgramAction); +return Act; + case frontend::ASTDump: +[[fallthrough]]; + case frontend::ASTPrint: +[[fallthrough]]; + case frontend::ParseSyntaxOnly: +Act = CreateFrontendAction(CI); +break; + case frontend::PluginAction: +[[fallthrough]]; + case frontend::EmitAssembly: +[[fallthrough]]; + case frontend::EmitBC: +[[fallthrough]]; + case frontend::EmitObj: +[[fallthrough]]; + case frontend::PrintPreprocessedInput: +[[fallthrough]]; AaronBallman wrote: ```suggestion case frontend::PluginAction: case frontend::EmitAssembly: case frontend::EmitBC: case frontend::EmitObj: case frontend::PrintPreprocessedInput: ``` You only need the `fallthrough` attribute when the cases are not immediately adjacent to one another (basically, one of the cases has to do something, otherwise fallthrough is very much expected). https://github.com/llvm/llvm-project/pull/107737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)
@@ -241,28 +244,180 @@ IncrementalCompilerBuilder::CreateCudaHost() { return IncrementalCompilerBuilder::createCuda(false); } -Interpreter::Interpreter(std::unique_ptr CI, +class InProcessPrintingASTConsumer final : public MultiplexConsumer { + Interpreter &Interp; + +public: + InProcessPrintingASTConsumer(std::unique_ptr C, Interpreter &I) + : MultiplexConsumer(std::move(C)), Interp(I) {} + bool HandleTopLevelDecl(DeclGroupRef DGR) override final { +if (DGR.isNull()) + return true; + +for (Decl *D : DGR) + if (auto *TLSD = llvm::dyn_cast(D)) +if (TLSD && TLSD->isSemiMissing()) { + auto ExprOrErr = + Interp.ExtractValueFromExpr(cast(TLSD->getStmt())); + if (llvm::Error E = ExprOrErr.takeError()) { +llvm::logAllUnhandledErrors(std::move(E), llvm::errs(), +"Value printing failed: "); +return false; // abort parsing + } + TLSD->setStmt(*ExprOrErr); +} + +return MultiplexConsumer::HandleTopLevelDecl(DGR); + } +}; + +/// A custom action enabling the incremental processing functionality. +/// +/// The usual \p FrontendAction expects one call to ExecuteAction and once it +/// sees a call to \p EndSourceFile it deletes some of the important objects +/// such as \p Preprocessor and \p Sema assuming no further input will come. +/// +/// \p IncrementalAction ensures it keep its underlying action's objects alive +/// as long as the \p IncrementalParser needs them. +/// +class IncrementalAction : public WrapperFrontendAction { +private: + bool IsTerminating = false; + Interpreter &Interp; + std::unique_ptr Consumer; + +public: + IncrementalAction(CompilerInstance &CI, llvm::LLVMContext &LLVMCtx, +llvm::Error &Err, Interpreter &I, +std::unique_ptr Consumer = nullptr) + : WrapperFrontendAction([&]() { + llvm::ErrorAsOutParameter EAO(&Err); + std::unique_ptr Act; + switch (CI.getFrontendOpts().ProgramAction) { + default: +Err = llvm::createStringError( +std::errc::state_not_recoverable, +"Driver initialization failed. " +"Incremental mode for action %d is not supported", +CI.getFrontendOpts().ProgramAction); +return Act; + case frontend::ASTDump: +[[fallthrough]]; + case frontend::ASTPrint: +[[fallthrough]]; AaronBallman wrote: ```suggestion case frontend::ASTDump: case frontend::ASTPrint: ``` https://github.com/llvm/llvm-project/pull/107737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)
@@ -53,6 +53,7 @@ class MultiplexConsumer : public SemaConsumer { public: // Takes ownership of the pointers in C. MultiplexConsumer(std::vector> C); + MultiplexConsumer(std::unique_ptr C); AaronBallman wrote: This feels unnecessary because you should be able to do `MultiplexConsumer M({std::move(ptr)});` right? https://github.com/llvm/llvm-project/pull/107737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Simplify the value printing logic to enable out-of-process. (PR #107737)
@@ -39,11 +44,13 @@ class IncrementalCUDADeviceParser : public IncrementalParser { ~IncrementalCUDADeviceParser(); protected: - IncrementalParser &HostParser; + std::unique_ptr DeviceCI; int SMVersion; llvm::SmallString<1024> PTXCode; llvm::SmallVector FatbinContent; llvm::IntrusiveRefCntPtr VFS; + CodeGenOptions &CodeGenOpts; // intentionally a reference. AaronBallman wrote: ```suggestion CodeGenOptions &CodeGenOpts; // Intentionally a reference. ``` Not certain the comment adds much -- we usually don't add reference members accidentally. https://github.com/llvm/llvm-project/pull/107737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] modernize-use-nullptr matches "NULL" in templates (PR #109169)
EugeneZelenko wrote: I mostly check documentation and minor code issues. Please wait for at least one of active developers whom I added to reviewers list. https://github.com/llvm/llvm-project/pull/109169 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Improve robustness when clang-tidy check names contain leading spaces. (PR #109421)
https://github.com/kadircet approved this pull request. thanks! https://github.com/llvm/llvm-project/pull/109421 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Loads] Check context instruction for context-sensitive derefability (PR #109277)
https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/109277 >From edbdc039ee955cc9d5f0f7d4cb4be287c55e25bb Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 17 Sep 2024 15:48:42 +0200 Subject: [PATCH 1/2] [Loads] Check context instruction for context-sensitive derefability If a dereferenceability fact is provided through `!dereferenceable`, it may only hold on the given control flow path. When we use `isSafeToSpeculativelyExecute()` to check multiple instructions, we might make use of `!dereferenceable` information that does not hold at the speculation target. This doesn't happen when speculating instructions one by one, because `!dereferenceable` will be dropped while speculating. Fix this by checking whether the instruction with `!dereferenceable` dominates the context instruction. If this is not the case, it means we are speculating, and cannot guarantee that it holds at the speculation target. Fixes https://github.com/llvm/llvm-project/issues/108854. --- clang/test/CodeGenOpenCL/builtins-amdgcn.cl | 6 +- llvm/lib/Analysis/Loads.cpp | 11 +++ llvm/lib/Analysis/MemDerefPrinter.cpp | 4 ++-- llvm/lib/CodeGen/MachineOperand.cpp | 3 ++- .../SimplifyCFG/speculate-derefable-load.ll | 11 +++ 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl index 6a6d5b1dfed3df..9274c80abd8c04 100644 --- a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl +++ b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl @@ -638,11 +638,7 @@ void test_get_workgroup_size(int d, global int *out) // CHECK-LABEL: @test_get_grid_size( // CHECK: {{.*}}call align 4 dereferenceable(64){{.*}} ptr addrspace(4) @llvm.amdgcn.dispatch.ptr() -// CHECK: getelementptr inbounds i8, ptr addrspace(4) %{{.*}}, i64 12 -// CHECK: load i32, ptr addrspace(4) %{{.*}}, align 4, !invariant.load -// CHECK: getelementptr inbounds i8, ptr addrspace(4) %{{.*}}, i64 16 -// CHECK: load i32, ptr addrspace(4) %{{.*}}, align 4, !invariant.load -// CHECK: getelementptr inbounds i8, ptr addrspace(4) %{{.*}}, i64 20 +// CHECK: getelementptr inbounds i8, ptr addrspace(4) %{{.*}}, i64 %.sink // CHECK: load i32, ptr addrspace(4) %{{.*}}, align 4, !invariant.load void test_get_grid_size(int d, global int *out) { diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp index 957ac883490c45..11f3807ffacf6e 100644 --- a/llvm/lib/Analysis/Loads.cpp +++ b/llvm/lib/Analysis/Loads.cpp @@ -104,6 +104,17 @@ static bool isDereferenceableAndAlignedPointer( if (CheckForNonNull && !isKnownNonZero(V, SimplifyQuery(DL, DT, AC, CtxI))) return false; +// When using something like !dereferenceable on a load, the +// dereferenceability may only be valid on a specific control-flow path. +// If the instruction doesn't dominate the context instruction, we're +// asking about dereferenceability under the assumption that the +// instruction has been speculated to the point of the context instruction, +// in which case we don't know if the dereferenceability info still holds. +// We don't bother handling allocas here, as they aren't speculatable +// anyway. +auto *I = dyn_cast(V); +if (I && !isa(I)) + return CtxI && isValidAssumeForContext(I, CtxI, DT); return true; }; if (IsKnownDeref()) { diff --git a/llvm/lib/Analysis/MemDerefPrinter.cpp b/llvm/lib/Analysis/MemDerefPrinter.cpp index e858d941435441..68cb8859488f70 100644 --- a/llvm/lib/Analysis/MemDerefPrinter.cpp +++ b/llvm/lib/Analysis/MemDerefPrinter.cpp @@ -30,10 +30,10 @@ PreservedAnalyses MemDerefPrinterPass::run(Function &F, for (auto &I : instructions(F)) { if (LoadInst *LI = dyn_cast(&I)) { Value *PO = LI->getPointerOperand(); - if (isDereferenceablePointer(PO, LI->getType(), DL)) + if (isDereferenceablePointer(PO, LI->getType(), DL, LI)) Deref.push_back(PO); if (isDereferenceableAndAlignedPointer(PO, LI->getType(), LI->getAlign(), - DL)) + DL, LI)) DerefAndAligned.insert(PO); } } diff --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp index 6ee47624f31c54..89d32c3f005e00 100644 --- a/llvm/lib/CodeGen/MachineOperand.cpp +++ b/llvm/lib/CodeGen/MachineOperand.cpp @@ -1047,7 +1047,8 @@ bool MachinePointerInfo::isDereferenceable(unsigned Size, LLVMContext &C, return false; return isDereferenceableAndAlignedPointer( - BasePtr, Align(1), APInt(DL.getPointerSizeInBits(), Offset + Size), DL); + BasePtr, Align(1), APInt(DL.getPointerSizeInBits(), Offset + Size), DL, + dyn_cast(BasePtr)); } /// getConstantPool - Return a MachinePointerInfo record that refers to the diff --git a/llvm/test/Transforms/SimplifyCFG/speculate
[clang] [llvm] [Loads] Check context instruction for context-sensitive derefability (PR #109277)
nikic wrote: I added some wording to isSafeToSpeculativelyExecute(), but not sure if this is what you had in mind. https://github.com/llvm/llvm-project/pull/109277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #109375)
https://github.com/nikic commented: Hm, why does this wrapper exist at all? It looks like a trivial wrapper that doesn't add or change any DenseMap functionality. https://github.com/llvm/llvm-project/pull/109375 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 96ae7c4 - [clang-repl] Implement continuation for preprocessor directives. (#107552)
Author: Vassil Vassilev Date: 2024-09-20T10:07:46+03:00 New Revision: 96ae7c4f1aa02cb10455dda22abbb0b3b2ceaa6b URL: https://github.com/llvm/llvm-project/commit/96ae7c4f1aa02cb10455dda22abbb0b3b2ceaa6b DIFF: https://github.com/llvm/llvm-project/commit/96ae7c4f1aa02cb10455dda22abbb0b3b2ceaa6b.diff LOG: [clang-repl] Implement continuation for preprocessor directives. (#107552) Added: Modified: clang/test/Interpreter/multiline.cpp clang/tools/clang-repl/ClangRepl.cpp Removed: diff --git a/clang/test/Interpreter/multiline.cpp b/clang/test/Interpreter/multiline.cpp index 054e61a7e3d62e..0f5ef48417f133 100644 --- a/clang/test/Interpreter/multiline.cpp +++ b/clang/test/Interpreter/multiline.cpp @@ -1,6 +1,8 @@ // REQUIRES: host-supports-jit // UNSUPPORTED: system-aix -// RUN: cat %s | clang-repl | FileCheck %s +// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc -verify | FileCheck %s + +// expected-no-diagnostics extern "C" int printf(const char*,...); int i = \ @@ -17,8 +19,7 @@ void f(int x) \ f(i); // CHECK: x=12 -// FIXME: Support preprocessor directives. -// #if 0 \ -// #error "Can't be!" \ -// #endif +#if 0 \ + #error "Can't be!"\ +#endif diff --git a/clang/tools/clang-repl/ClangRepl.cpp b/clang/tools/clang-repl/ClangRepl.cpp index 9cfc70462893dd..08c54e6cafa901 100644 --- a/clang/tools/clang-repl/ClangRepl.cpp +++ b/clang/tools/clang-repl/ClangRepl.cpp @@ -232,8 +232,10 @@ int main(int argc, const char **argv) { llvm::StringRef L = *Line; L = L.trim(); if (L.ends_with("\\")) { -// FIXME: Support #ifdef X \ ... Input += L.drop_back(1); +// If it is a preprocessor directive, new lines matter. +if (L.starts_with('#')) + Input += "\n"; LE.setPrompt("clang-repl... "); continue; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Fix a problem with array size limits (PR #109383)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes Descriptor::MaxArrayElemBytes is an unsigned value, which might overflow the SizeT we have in CheckArraySize. --- Full diff: https://github.com/llvm/llvm-project/pull/109383.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Interp.h (+7) - (modified) clang/test/AST/ByteCode/new-delete.cpp (+15) ``diff diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 52ccefee88642a..92bed32d56f4d5 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -241,11 +241,18 @@ bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT *NumElements, // FIXME: Both the SizeT::from() as well as the // NumElements.toAPSInt() in this function are rather expensive. + // Can't be too many elements if the bitwidth of NumElements is lower than + // that of Descriptor::MaxArrayElemBytes. + if ((NumElements->bitWidth() - NumElements->isSigned()) < + (sizeof(Descriptor::MaxArrayElemBytes) * 8)) +return true; + // FIXME: GH63562 // APValue stores array extents as unsigned, // so anything that is greater that unsigned would overflow when // constructing the array, we catch this here. SizeT MaxElements = SizeT::from(Descriptor::MaxArrayElemBytes / ElemSize); + assert(MaxElements.isPositive()); if (NumElements->toAPSInt().getActiveBits() > ConstantArrayType::getMaxSizeBits(S.getASTContext()) || *NumElements > MaxElements) { diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp index 76858aa94bb37d..2ba1286b250dc6 100644 --- a/clang/test/AST/ByteCode/new-delete.cpp +++ b/clang/test/AST/ByteCode/new-delete.cpp @@ -718,6 +718,21 @@ namespace OperatorNewDelete { static_assert((std::allocator().deallocate(std::allocator().allocate(10)), 1) == 1); } +namespace Limits { + template + constexpr T dynarray(int elems, int i) { +T *p; +if constexpr (sizeof(T) == 1) + p = new T[elems]{"fox"}; +else + p = new T[elems]{1, 2, 3}; +T n = p[i]; +delete [] p; +return n; + } + static_assert(dynarray(5, 0) == 'f'); +} + #else /// Make sure we reject this prior to C++20 constexpr int a() { // both-error {{never produces a constant expression}} `` https://github.com/llvm/llvm-project/pull/109383 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Implement continuation for preprocessor directives. (PR #107552)
https://github.com/vgvassilev closed https://github.com/llvm/llvm-project/pull/107552 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Fix a problem with array size limits (PR #109383)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/109383 Descriptor::MaxArrayElemBytes is an unsigned value, which might overflow the SizeT we have in CheckArraySize. >From 091ba215597e2fc41b3860182ae2136bcac7f5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Fri, 20 Sep 2024 08:33:48 +0200 Subject: [PATCH] [clang][bytecode] Fix a problem with array size limits Descriptor::MaxArrayElemBytes is an unsigned value, which might overflow the SizeT we have in CheckArraySize. --- clang/lib/AST/ByteCode/Interp.h| 7 +++ clang/test/AST/ByteCode/new-delete.cpp | 15 +++ 2 files changed, 22 insertions(+) diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 52ccefee88642a..92bed32d56f4d5 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -241,11 +241,18 @@ bool CheckArraySize(InterpState &S, CodePtr OpPC, SizeT *NumElements, // FIXME: Both the SizeT::from() as well as the // NumElements.toAPSInt() in this function are rather expensive. + // Can't be too many elements if the bitwidth of NumElements is lower than + // that of Descriptor::MaxArrayElemBytes. + if ((NumElements->bitWidth() - NumElements->isSigned()) < + (sizeof(Descriptor::MaxArrayElemBytes) * 8)) +return true; + // FIXME: GH63562 // APValue stores array extents as unsigned, // so anything that is greater that unsigned would overflow when // constructing the array, we catch this here. SizeT MaxElements = SizeT::from(Descriptor::MaxArrayElemBytes / ElemSize); + assert(MaxElements.isPositive()); if (NumElements->toAPSInt().getActiveBits() > ConstantArrayType::getMaxSizeBits(S.getASTContext()) || *NumElements > MaxElements) { diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp index 76858aa94bb37d..2ba1286b250dc6 100644 --- a/clang/test/AST/ByteCode/new-delete.cpp +++ b/clang/test/AST/ByteCode/new-delete.cpp @@ -718,6 +718,21 @@ namespace OperatorNewDelete { static_assert((std::allocator().deallocate(std::allocator().allocate(10)), 1) == 1); } +namespace Limits { + template + constexpr T dynarray(int elems, int i) { +T *p; +if constexpr (sizeof(T) == 1) + p = new T[elems]{"fox"}; +else + p = new T[elems]{1, 2, 3}; +T n = p[i]; +delete [] p; +return n; + } + static_assert(dynarray(5, 0) == 'f'); +} + #else /// Make sure we reject this prior to C++20 constexpr int a() { // both-error {{never produces a constant expression}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver][Sparc] Default to -mcpu=v9 for 32-bit Linux/sparc64 (PR #109278)
rorth wrote: > We try to restrict distribution differences to things like default linker > options and library paths. Affecting `-mcpu=` seems very unintuitive. There > are many Debian derivatives. It's weird that Debian uses -mcpu=v9 while > others use -mcpu=v8. We should not increase `IsDebian` or `IsGentoo` use. Ah, thanks. That simplifies things a lot. > If -mcpu=v9 seems the right thing for the majority of configurations, we can > bump -mcpu=v9 for all Linux and ask other, older systems to use > https://clang.llvm.org/docs/UsersManual.html#configuration-files to specify > `-mcpu=v8`. I'd been operating under the assumption that `clang` should work out of the box on either kind of distro. I'll update the patch accordingly and add a release notes entry about the change. https://github.com/llvm/llvm-project/pull/109278 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add new check bugprone-tagged-union-member-count (PR #89925)
=?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= , =?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= , =?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= , =?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= , =?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= , =?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= , =?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= , =?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= , =?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= , =?utf-8?b?R8OhYm9yIFTDs3RodsOhcmk=?= Message-ID: In-Reply-To: https://github.com/whisperity approved this pull request. https://github.com/llvm/llvm-project/pull/89925 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Lifetime of locals must end before musttail call (PR #109255)
@@ -637,6 +637,11 @@ return value must be trivially destructible. The calling convention of the caller and callee must match, and they must not be variadic functions or have old style K&R C function declarations. +The lifetimes of all local variables and function parameters end immediately +before the call to the function. This means that it is undefined behaviour to +pass a pointer or reference to a local variable to the called function, which +is not the case without the attribute. hokein wrote: nit: maybe mention that clang will give a diagnostic on this case. https://github.com/llvm/llvm-project/pull/109255 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Lifetime of locals must end before musttail call (PR #109255)
https://github.com/hokein approved this pull request. Thanks, it looks good, just a few nits. https://github.com/llvm/llvm-project/pull/109255 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] WebKit Checkers should set DeclWithIssue. (PR #109389)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) Changes Set DeclWithIssue in alpha.webkit.UncountedCallArgsChecker and alpha.webkit.UncountedLocalVarsChecker. --- Full diff: https://github.com/llvm/llvm-project/pull/109389.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp (+21-8) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp (+16-5) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp index 81c2434ce64775..410e78c5418ee3 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp @@ -18,6 +18,8 @@ #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" #include "clang/StaticAnalyzer/Core/Checker.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/Support/SaveAndRestore.h" #include using namespace clang; @@ -44,7 +46,11 @@ class UncountedCallArgsChecker // visit template instantiations or lambda classes. We // want to visit those, so we make our own RecursiveASTVisitor. struct LocalVisitor : public RecursiveASTVisitor { + using Base = RecursiveASTVisitor; + const UncountedCallArgsChecker *Checker; + Decl *DeclWithIssue { nullptr }; + explicit LocalVisitor(const UncountedCallArgsChecker *Checker) : Checker(Checker) { assert(Checker); @@ -56,12 +62,16 @@ class UncountedCallArgsChecker bool TraverseClassTemplateDecl(ClassTemplateDecl *Decl) { if (isRefType(safeGetName(Decl))) return true; -return RecursiveASTVisitor::TraverseClassTemplateDecl( -Decl); +return Base::TraverseClassTemplateDecl(Decl); + } + + bool TraverseDecl(Decl *D) { +llvm::SaveAndRestore SavedDecl(DeclWithIssue, D); +return Base::TraverseDecl(D); } bool VisitCallExpr(const CallExpr *CE) { -Checker->visitCallExpr(CE); +Checker->visitCallExpr(CE, DeclWithIssue); return true; } }; @@ -70,7 +80,7 @@ class UncountedCallArgsChecker visitor.TraverseDecl(const_cast(TUD)); } - void visitCallExpr(const CallExpr *CE) const { + void visitCallExpr(const CallExpr *CE, const Decl *D) const { if (shouldSkipCall(CE)) return; @@ -89,7 +99,7 @@ class UncountedCallArgsChecker QualType ArgType = MemberCallExpr->getObjectType(); std::optional IsUncounted = isUncounted(ArgType); if (IsUncounted && *IsUncounted && !isPtrOriginSafe(E)) - reportBugOnThis(E); + reportBugOnThis(E, D); } for (auto P = F->param_begin(); @@ -119,7 +129,7 @@ class UncountedCallArgsChecker if (isPtrOriginSafe(Arg)) continue; -reportBug(Arg, *P); +reportBug(Arg, *P, D); } } } @@ -240,7 +250,8 @@ class UncountedCallArgsChecker ClsName.ends_with("String")); } - void reportBug(const Expr *CallArg, const ParmVarDecl *Param) const { + void reportBug(const Expr *CallArg, const ParmVarDecl *Param, + const Decl *DeclWithIssue) const { assert(CallArg); SmallString<100> Buf; @@ -261,10 +272,11 @@ class UncountedCallArgsChecker PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager()); auto Report = std::make_unique(Bug, Os.str(), BSLoc); Report->addRange(CallArg->getSourceRange()); +Report->setDeclWithIssue(DeclWithIssue); BR->emitReport(std::move(Report)); } - void reportBugOnThis(const Expr *CallArg) const { + void reportBugOnThis(const Expr *CallArg, const Decl *DeclWithIssue) const { assert(CallArg); const SourceLocation SrcLocToReport = CallArg->getSourceRange().getBegin(); @@ -274,6 +286,7 @@ class UncountedCallArgsChecker Bug, "Call argument for 'this' parameter is uncounted and unsafe.", BSLoc); Report->addRange(CallArg->getSourceRange()); +Report->setDeclWithIssue(DeclWithIssue); BR->emitReport(std::move(Report)); } }; diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp index 274da0baf2ce5c..30f10d7e9f91e7 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp @@ -121,6 +121,7 @@ class UncountedLocalVarsChecker // want to visit those, so we make our own RecursiveASTVisitor. struct LocalVisitor : public RecursiveASTVisitor { const UncountedLocalVarsChecker *Checker; + Decl *DeclWithIssue { nullptr }; TrivialFunctionAnalysis TFA; @@ -134,10 +135,17 @@ class UncountedLocalV
[clang] [llvm] Update llvm::Registry to work for LLVM shared library builds on windows (PR #109024)
https://github.com/AaronBallman edited https://github.com/llvm/llvm-project/pull/109024 ___ 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)
https://github.com/rlavaee updated https://github.com/llvm/llvm-project/pull/107494 >From 57989794675a67b955aaf0e06fb4dbdc3ad48c9b Mon Sep 17 00:00:00 2001 From: Rahman Lavaee Date: Thu, 5 Sep 2024 19:14:11 + Subject: [PATCH] Deprecate the `-fbasic-block-sections=labels` option. This feature is supported via the newer option `-fbasic-block-address-map`. Using the old option still works by delegating to the newer option, while a warning is generated to show deprecation. --- 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 | 4 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, 47 insertions(+), 75 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 sectio
[clang] [llvm] Update llvm::Registry to work for LLVM shared library builds on windows (PR #109024)
https://github.com/AaronBallman commented: Thank you for working on this, I'm super excited for the ability to write plugins that work on Windows! https://github.com/llvm/llvm-project/pull/109024 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Update llvm::Registry to work for LLVM shared library builds on windows (PR #109024)
@@ -189,19 +190,23 @@ #define LLVM_TEMPLATE_ABI __declspec(dllimport) #define LLVM_EXPORT_TEMPLATE #endif +#define LLVM_ABI_EXPORT __declspec(dllexport) AaronBallman wrote: I think this is subtle enough that we may need some documentation comments explaining when and how someone should use this. (Most reviewers aren't going to be well-versed in how shared libraries work on Windows.) https://github.com/llvm/llvm-project/pull/109024 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [lldb] [llvm] [SystemZ][z/OS] Propagate IsText parameter to open text files as text (PR #107906)
@@ -323,10 +325,11 @@ ErrorOr RealFileSystem::status(const Twine &Path) { } ErrorOr> -RealFileSystem::openFileForRead(const Twine &Name) { +RealFileSystem::openFileForRead(const Twine &Name, bool IsText) { SmallString<256> RealName, Storage; Expected FDOrErr = sys::fs::openNativeFileForRead( - adjustPath(Name, Storage), sys::fs::OF_None, &RealName); + adjustPath(Name, Storage), IsText ? sys::fs::OF_Text : sys::fs::OF_None, abhina-sree wrote: I will look into this and see if I hit any issues. I think if the file already exists, we can deduce it here, but in the case the file does not exist, we do not know whether the file is supposed to be text or binary without additional context https://github.com/llvm/llvm-project/pull/107906 ___ 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/AaronBallman edited https://github.com/llvm/llvm-project/pull/108276 ___ 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/AaronBallman commented: One thing I don't understand about this PR is why we need Compiler.h in Clang -- wouldn't the LLVM definitions in their Compiler.h work for Clang as well? (This would probably be worth explaining in the patch summary.) https://github.com/llvm/llvm-project/pull/108276 ___ 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)
@@ -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 AaronBallman wrote: Please add a newline to the end of the file. https://github.com/llvm/llvm-project/pull/108276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ADT] Simplify SmallSet (PR #109412)
https://github.com/vhscampos edited https://github.com/llvm/llvm-project/pull/109412 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] da36603 - [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (#108657)
Author: Oleksandr T. Date: 2024-09-20T09:14:26-04:00 New Revision: da36603148baf37d3625aa030b4c05bf5785cae2 URL: https://github.com/llvm/llvm-project/commit/da36603148baf37d3625aa030b4c05bf5785cae2 DIFF: https://github.com/llvm/llvm-project/commit/da36603148baf37d3625aa030b4c05bf5785cae2.diff LOG: [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (#108657) Fixes #108326 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaExpr.cpp clang/test/Sema/ext_vector_casts.c Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3f146cb9247a78..0a1d0fd85e7ae0 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -403,6 +403,7 @@ Bug Fixes to C++ Support - Avoided a redundant friend declaration instantiation under a certain ``consteval`` context. (#GH107175) - Fixed an assertion failure in debug mode, and potential crashes in release mode, when diagnosing a failed cast caused indirectly by a failed implicit conversion to the type of the constructor parameter. +- Fixed an assertion failure by adjusting integral to boolean vector conversions (#GH108326) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 2f7e9c754ce095..66df9c969256a2 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -9868,7 +9868,9 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar, // if necessary. CastKind scalarCast = CK_NoOp; - if (vectorEltTy->isIntegralType(S.Context)) { + if (vectorEltTy->isBooleanType() && scalarTy->isIntegralType(S.Context)) { +scalarCast = CK_IntegralToBoolean; + } else if (vectorEltTy->isIntegralType(S.Context)) { if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() || (scalarTy->isIntegerType() && S.Context.getIntegerTypeOrder(vectorEltTy, scalarTy) < 0))) { diff --git a/clang/test/Sema/ext_vector_casts.c b/clang/test/Sema/ext_vector_casts.c index 48440735d88ea9..8bf2737e0bfab1 100644 --- a/clang/test/Sema/ext_vector_casts.c +++ b/clang/test/Sema/ext_vector_casts.c @@ -11,6 +11,7 @@ typedef float t3 __attribute__ ((vector_size (16))); typedef __typeof__(sizeof(int)) size_t; typedef unsigned long ulong2 __attribute__ ((ext_vector_type(2))); typedef size_t stride4 __attribute__((ext_vector_type(4))); +typedef _Bool bool4 __attribute__(( ext_vector_type(4) )); static void test(void) { float2 vec2; @@ -19,6 +20,7 @@ static void test(void) { int4 ivec4; short8 ish8; t3 vec4_3; +bool4 bvec4 = 0; int *ptr; int i; @@ -51,6 +53,9 @@ static void test(void) { ivec4 -= ivec4; ivec4 |= ivec4; ivec4 += ptr; // expected-error {{cannot convert between vector and non-scalar values ('int4' (vector of 4 'int' values) and 'int *')}} + +bvec4 != 0; // expected-warning {{inequality comparison result unused}} \ +// expected-note {{use '|=' to turn this inequality comparison into an or-assignment}} } typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // expected-error{{invalid vector element type 'float2' (vector of 2 'float' values)}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (PR #108657)
https://github.com/AaronBallman approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/108657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (PR #108657)
https://github.com/AaronBallman closed https://github.com/llvm/llvm-project/pull/108657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Fix templated array size calculation. (PR #96464)
https://github.com/erichkeane approved this pull request. LGTM, feel free to merge. https://github.com/llvm/llvm-project/pull/96464 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SPIRV][RFC] Rework / extend support for memory scopes (PR #106429)
@@ -1,7 +1,7 @@ ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV ; CHECK-SPIRV: %[[#Int:]] = OpTypeInt 32 0 -; CHECK-SPIRV-DAG: %[[#MemScope_Device:]] = OpConstant %[[#Int]] 1 +; CHECK-SPIRV-DAG: %[[#MemScope_AllSvmDevices:]] = OpConstant %[[#Int]] 0 VyacheslavLevytskyy wrote: I think it's better to be consistent in terminology of tests vs. source code, and to use here and in other tests CrossDevice instead of AllSvmDevices. https://github.com/llvm/llvm-project/pull/106429 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Lifetime of locals must end before musttail call (PR #109255)
https://github.com/ostannard updated https://github.com/llvm/llvm-project/pull/109255 >From 85ac319257785f88fd27a533fffde7aab20c8d8d Mon Sep 17 00:00:00 2001 From: Oliver Stannard Date: Wed, 18 Sep 2024 16:22:41 +0100 Subject: [PATCH 1/5] [clang] Lifetime of locals must end before musttail call The lifetimes of local variables and function parameters must end before the call to a [[clang::musttail]] function, instead of before the return, because we will not have a stack frame to hold them when doing the call. This documents this limitation, and adds diagnostics to warn about some code which is invalid because of it. --- clang/include/clang/Basic/AttrDocs.td | 5 .../clang/Basic/DiagnosticSemaKinds.td| 3 ++- clang/lib/Sema/CheckExprLifetime.cpp | 16 +-- clang/lib/Sema/CheckExprLifetime.h| 6 + clang/lib/Sema/SemaStmt.cpp | 10 +++ clang/test/SemaCXX/attr-musttail.cpp | 27 +++ 6 files changed, 64 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 8ef151b3f2fddb..7226871074ee7e 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -637,6 +637,11 @@ return value must be trivially destructible. The calling convention of the caller and callee must match, and they must not be variadic functions or have old style K&R C function declarations. +The lifetimes of all local variables and function parameters end immediately +before the call to the function. This means that it is undefined behaviour to +pass a pointer or reference to a local variable to the called function, which +is not the case without the attribute. + ``clang::musttail`` provides assurances that the tail call can be optimized on all targets, not just one. }]; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index ba813af960af6f..75c7f9e0eb7de0 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10101,7 +10101,8 @@ def err_lifetimebound_ctor_dtor : Error< // CHECK: returning address/reference of stack memory def warn_ret_stack_addr_ref : Warning< "%select{address of|reference to}0 stack memory associated with " - "%select{local variable|parameter|compound literal}2 %1 returned">, + "%select{local variable|parameter|compound literal}2 %1 " + "%select{returned|passed to musttail function}3">, InGroup; def warn_ret_local_temp_addr_ref : Warning< "returning %select{address of|reference to}0 local temporary object">, diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp index c98fbca849faba..211c1cc7bc81f9 100644 --- a/clang/lib/Sema/CheckExprLifetime.cpp +++ b/clang/lib/Sema/CheckExprLifetime.cpp @@ -33,6 +33,10 @@ enum LifetimeKind { /// the entity is a return object. LK_Return, + /// The lifetime of a temporary bound to this entity ends too soon, because + /// the entity passed to a musttail function call. + LK_MustTail, + /// The lifetime of a temporary bound to this entity ends too soon, because /// the entity is the result of a statement expression. LK_StmtExprResult, @@ -1150,6 +1154,7 @@ static void checkExprLifetimeImpl(Sema &SemaRef, break; case LK_Return: +case LK_MustTail: case LK_StmtExprResult: if (auto *DRE = dyn_cast(L)) { // We can't determine if the local variable outlives the statement @@ -1158,7 +1163,8 @@ static void checkExprLifetimeImpl(Sema &SemaRef, return false; SemaRef.Diag(DiagLoc, diag::warn_ret_stack_addr_ref) << InitEntity->getType()->isReferenceType() << DRE->getDecl() -<< isa(DRE->getDecl()) << DiagRange; +<< isa(DRE->getDecl()) << (LK == LK_MustTail) +<< DiagRange; } else if (isa(L)) { SemaRef.Diag(DiagLoc, diag::err_ret_local_block) << DiagRange; } else if (isa(L)) { @@ -1170,7 +1176,7 @@ static void checkExprLifetimeImpl(Sema &SemaRef, } else if (auto *CLE = dyn_cast(L)) { SemaRef.Diag(DiagLoc, diag::warn_ret_stack_addr_ref) << InitEntity->getType()->isReferenceType() << CLE->getInitializer() -<< 2 << DiagRange; +<< 2 << (LK == LK_MustTail) << DiagRange; } else { // P2748R5: Disallow Binding a Returned Glvalue to a Temporary. // [stmt.return]/p6: In a function whose return type is a reference, @@ -1265,6 +1271,12 @@ void checkExprLifetime(Sema &SemaRef, const InitializedEntity &Entity, /*AEntity*/ nullptr, Init); } +void checkExprLifetimeMustTailArg(Sema &SemaRef, const InitializedEntity &Entity, + Expr *Init) { + checkExprLifetimeImpl(SemaRef, &Entity, nullptr, LK_MustTail, +/*AEntity*/ nullptr,
[clang] [llvm] [SPIRV][RFC] Rework / extend support for memory scopes (PR #106429)
@@ -5,8 +5,8 @@ ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %} ; CHECK: %[[#Int:]] = OpTypeInt 32 0 -; CHECK-DAG: %[[#Scope_Device:]] = OpConstant %[[#Int]] 1{{$}} -; CHECK-DAG: %[[#MemSem_Relaxed:]] = OpConstant %[[#Int]] 0 +; CHECK-DAG: %[[#Scope_AllSvmDevices:]] = OpConstant %[[#Int]] 0{{$}} VyacheslavLevytskyy wrote: I'm not 100% sure, just as an idea -- maybe a choice of Const0 or ConstZero would be a better way than slightly misleading use of Scope_AllSvmDevices in the place of MemSem_Relaxed. Motivation for the idea is that `OpAtomicSMax %[[#Int]] %[[#Pointer]] %[[#Scope_AllSvmDevices]] %[[#Scope_AllSvmDevices]] %[[#Value]]` looks just wrong and I'm not sure that even the comment below will help to avoid confusions. https://github.com/llvm/llvm-project/pull/106429 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SPIRV][RFC] Rework / extend support for memory scopes (PR #106429)
https://github.com/VyacheslavLevytskyy edited https://github.com/llvm/llvm-project/pull/106429 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Lifetime of locals must end before musttail call (PR #109255)
@@ -267,3 +267,30 @@ namespace ns {} void TestCallNonValue() { [[clang::musttail]] return ns; // expected-error {{unexpected namespace name 'ns': expected expression}} } + +// Test diagnostics for lifetimes of local variables, which end earlier for a +// musttail call than for a nowmal one. + +void TakesIntAndPtr(int, int *); +void PassAddressOfLocal(int a, int *b) { + int c; + [[clang::musttail]] return TakesIntAndPtr(0, &c); // expected-warning {{address of stack memory associated with local variable 'c' passed to musttail function}} ostannard wrote: Done, and there was a different diagnostic message used for temporaries, so added a better wording for that. https://github.com/llvm/llvm-project/pull/109255 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Lifetime of locals must end before musttail call (PR #109255)
@@ -637,6 +637,11 @@ return value must be trivially destructible. The calling convention of the caller and callee must match, and they must not be variadic functions or have old style K&R C function declarations. +The lifetimes of all local variables and function parameters end immediately +before the call to the function. This means that it is undefined behaviour to +pass a pointer or reference to a local variable to the called function, which +is not the case without the attribute. ostannard wrote: Done. https://github.com/llvm/llvm-project/pull/109255 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits