[llvm-branch-commits] [llvm] bd5722b - [X86] Remove AVX512VP2INTERSECT from Sapphire Rapids.
Author: Freddy Ye Date: 2022-10-10T08:49:16+02:00 New Revision: bd5722b87b5aa1b8286762af7f29b6aae669dee1 URL: https://github.com/llvm/llvm-project/commit/bd5722b87b5aa1b8286762af7f29b6aae669dee1 DIFF: https://github.com/llvm/llvm-project/commit/bd5722b87b5aa1b8286762af7f29b6aae669dee1.diff LOG: [X86] Remove AVX512VP2INTERSECT from Sapphire Rapids. For more details, please refer to the latest ISE document: https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D135509 (cherry picked from commit 566c277c64f8f76d8911aa5fd931903a357ed7be) Added: Modified: llvm/lib/Support/X86TargetParser.cpp llvm/lib/Target/X86/X86.td Removed: diff --git a/llvm/lib/Support/X86TargetParser.cpp b/llvm/lib/Support/X86TargetParser.cpp index 2567f3ed8034b..0daaa6d815bf0 100644 --- a/llvm/lib/Support/X86TargetParser.cpp +++ b/llvm/lib/Support/X86TargetParser.cpp @@ -203,10 +203,10 @@ constexpr FeatureBitset FeaturesTigerlake = FeatureCLWB | FeatureMOVDIRI | FeatureSHSTK | FeatureKL | FeatureWIDEKL; constexpr FeatureBitset FeaturesSapphireRapids = FeaturesICLServer | FeatureAMX_BF16 | FeatureAMX_INT8 | FeatureAMX_TILE | -FeatureAVX512BF16 | FeatureAVX512FP16 | FeatureAVX512VP2INTERSECT | -FeatureAVXVNNI | FeatureCLDEMOTE | FeatureENQCMD | FeatureMOVDIR64B | -FeatureMOVDIRI | FeaturePTWRITE | FeatureSERIALIZE | FeatureSHSTK | -FeatureTSXLDTRK | FeatureUINTR | FeatureWAITPKG; +FeatureAVX512BF16 | FeatureAVX512FP16 | FeatureAVXVNNI | FeatureCLDEMOTE | +FeatureENQCMD | FeatureMOVDIR64B | FeatureMOVDIRI | FeaturePTWRITE | +FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureUINTR | +FeatureWAITPKG; // Intel Atom processors. // Bonnell has feature parity with Core2 and adds MOVBE. @@ -367,7 +367,7 @@ constexpr ProcInfo Processors[] = { // Tigerlake microarchitecture based processors. { {"tigerlake"}, CK_Tigerlake, FEATURE_AVX512VP2INTERSECT, FeaturesTigerlake }, // Sapphire Rapids microarchitecture based processors. - { {"sapphirerapids"}, CK_SapphireRapids, FEATURE_AVX512VP2INTERSECT, FeaturesSapphireRapids }, + { {"sapphirerapids"}, CK_SapphireRapids, FEATURE_AVX512BF16, FeaturesSapphireRapids }, // Alderlake microarchitecture based processors. { {"alderlake"}, CK_Alderlake, FEATURE_AVX2, FeaturesAlderlake }, // Knights Landing processor. diff --git a/llvm/lib/Target/X86/X86.td b/llvm/lib/Target/X86/X86.td index fa0a6bd415dc0..f98916e81cee9 100644 --- a/llvm/lib/Target/X86/X86.td +++ b/llvm/lib/Target/X86/X86.td @@ -909,7 +909,6 @@ def ProcessorFeatures { FeatureTSXLDTRK, FeatureENQCMD, FeatureSHSTK, - FeatureVP2INTERSECT, FeatureMOVDIRI, FeatureMOVDIR64B, FeatureUINTR]; ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 61fa709 - [LoopVersioning] Invalidate SCEV for phi if new values are added.
Author: Florian Hahn Date: 2022-10-10T08:49:03+02:00 New Revision: 61fa70903191f2350dc20dee2c9f45a8fbdf28af URL: https://github.com/llvm/llvm-project/commit/61fa70903191f2350dc20dee2c9f45a8fbdf28af DIFF: https://github.com/llvm/llvm-project/commit/61fa70903191f2350dc20dee2c9f45a8fbdf28af.diff LOG: [LoopVersioning] Invalidate SCEV for phi if new values are added. After 20d798bd47ec5191d, SCEV looks through PHIs with a single incoming value. This means adding a new incoming value may change the SCEV for a phi. Add missing invalidation when an existing PHI is reused during LoopVersioning. New incoming values will be added later from the versioned loop. Similar issues have been fixed by also adding missing invalidation. Fixes #57825. Note that the test case unfortunately requires running loop-vectorize followed by loop-load-elimination, which does the actual versioning. I don't think it is possible to reproduce the failure without that combination. (cherry picked from commit 623c4a7a55f716b96070a5c2f83fe0096cb38d38) Added: llvm/test/Transforms/LoopLoadElim/versioning-scev-invalidation.ll Modified: llvm/lib/Transforms/Utils/LoopVersioning.cpp Removed: diff --git a/llvm/lib/Transforms/Utils/LoopVersioning.cpp b/llvm/lib/Transforms/Utils/LoopVersioning.cpp index 97f29527bb95c..6309eed7963d1 100644 --- a/llvm/lib/Transforms/Utils/LoopVersioning.cpp +++ b/llvm/lib/Transforms/Utils/LoopVersioning.cpp @@ -137,8 +137,10 @@ void LoopVersioning::addPHINodes( // See if we have a single-operand PHI with the value defined by the // original loop. for (auto I = PHIBlock->begin(); (PN = dyn_cast(I)); ++I) { - if (PN->getIncomingValue(0) == Inst) + if (PN->getIncomingValue(0) == Inst) { +SE->forgetValue(PN); break; + } } // If not create it. if (!PN) { diff --git a/llvm/test/Transforms/LoopLoadElim/versioning-scev-invalidation.ll b/llvm/test/Transforms/LoopLoadElim/versioning-scev-invalidation.ll new file mode 100644 index 0..4b0bc908eddfa --- /dev/null +++ b/llvm/test/Transforms/LoopLoadElim/versioning-scev-invalidation.ll @@ -0,0 +1,125 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -force-vector-width=4 -force-vector-interleave=1 -passes='loop-vectorize,loop-load-elim' -S %s | FileCheck %s + +@glob.1 = external global [100 x double] +@glob.2 = external global [100 x double] + +define void @g(ptr %dst.1, ptr %start, i64 %N) { +; CHECK-LABEL: @g( +; CHECK-NEXT: loop.1.lver.check: +; CHECK-NEXT:[[TMP0:%.*]] = shl i64 [[N:%.*]], 3 +; CHECK-NEXT:[[TMP1:%.*]] = add i64 [[TMP0]], 16 +; CHECK-NEXT:[[UGLYGEP:%.*]] = getelementptr i8, ptr @glob.2, i64 [[TMP1]] +; CHECK-NEXT:[[UGLYGEP2:%.*]] = getelementptr i8, ptr [[DST_1:%.*]], i64 8 +; CHECK-NEXT:[[BOUND0:%.*]] = icmp ult ptr @glob.2, [[UGLYGEP2]] +; CHECK-NEXT:[[BOUND1:%.*]] = icmp ult ptr [[DST_1]], [[UGLYGEP]] +; CHECK-NEXT:[[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]] +; CHECK-NEXT:br i1 [[FOUND_CONFLICT]], label [[LOOP_1_PH_LVER_ORIG:%.*]], label [[LOOP_1_PH:%.*]] +; CHECK: loop.1.ph.lver.orig: +; CHECK-NEXT:br label [[LOOP_1_LVER_ORIG:%.*]] +; CHECK: loop.1.lver.orig: +; CHECK-NEXT:[[IV_LVER_ORIG:%.*]] = phi i64 [ 0, [[LOOP_1_PH_LVER_ORIG]] ], [ [[IV_NEXT_LVER_ORIG:%.*]], [[LOOP_1_LVER_ORIG]] ] +; CHECK-NEXT:[[PTR_IV_1_LVER_ORIG:%.*]] = phi ptr [ @glob.1, [[LOOP_1_PH_LVER_ORIG]] ], [ [[PTR_IV_1_NEXT_LVER_ORIG:%.*]], [[LOOP_1_LVER_ORIG]] ] +; CHECK-NEXT:[[GEP_IV_LVER_ORIG:%.*]] = getelementptr inbounds double, ptr @glob.2, i64 [[IV_LVER_ORIG]] +; CHECK-NEXT:[[L_1_LVER_ORIG:%.*]] = load double, ptr [[GEP_IV_LVER_ORIG]], align 8 +; CHECK-NEXT:[[GEP_IV_1_LVER_ORIG:%.*]] = getelementptr inbounds double, ptr getelementptr inbounds (double, ptr @glob.2, i64 1), i64 [[IV_LVER_ORIG]] +; CHECK-NEXT:store double 0.00e+00, ptr [[GEP_IV_1_LVER_ORIG]], align 8 +; CHECK-NEXT:store double 0.00e+00, ptr [[DST_1]], align 8 +; CHECK-NEXT:[[PTR_IV_1_NEXT_LVER_ORIG]] = getelementptr inbounds double, ptr [[PTR_IV_1_LVER_ORIG]], i64 1 +; CHECK-NEXT:[[IV_NEXT_LVER_ORIG]] = add nuw nsw i64 [[IV_LVER_ORIG]], 1 +; CHECK-NEXT:[[EXITCOND_NOT_LVER_ORIG:%.*]] = icmp eq i64 [[IV_LVER_ORIG]], [[N]] +; CHECK-NEXT:br i1 [[EXITCOND_NOT_LVER_ORIG]], label [[LOOP_2_PH_LOOPEXIT:%.*]], label [[LOOP_1_LVER_ORIG]] +; CHECK: loop.1.ph: +; CHECK-NEXT:[[LOAD_INITIAL:%.*]] = load double, ptr @glob.2, align 8 +; CHECK-NEXT:br label [[LOOP_1:%.*]] +; CHECK: loop.1: +; CHECK-NEXT:[[STORE_FORWARDED:%.*]] = phi double [ [[LOAD_INITIAL]], [[LOOP_1_PH]] ], [ 0.00e+00, [[LOOP_1]] ] +; CHECK-NEXT:[[IV:%.*]] = phi i64 [ 0, [[LOOP_1_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP_1]] ] +; CHECK-NEXT:[[PTR_IV_1:%.*]] = phi ptr [ @glob.1, [[LOOP_1_PH]] ], [ [[
[llvm-branch-commits] [clang-tools-extra] 359ef0c - [clangd] Improve inlay hints of things expanded from macros
Author: Sam McCall Date: 2022-10-10T08:49:22+02:00 New Revision: 359ef0c932404d31347ce25895fdcadee1004381 URL: https://github.com/llvm/llvm-project/commit/359ef0c932404d31347ce25895fdcadee1004381 DIFF: https://github.com/llvm/llvm-project/commit/359ef0c932404d31347ce25895fdcadee1004381.diff LOG: [clangd] Improve inlay hints of things expanded from macros When we aim a hint at some expanded tokens, we're only willing to attach it to spelled tokens that exactly corresponde. e.g. int zoom(int x, int y, int z); int dummy = zoom(NUMBERS); Here we want to place a hint "x:" on the expanded "1", but we shouldn't be willing to place it on NUMBERS, because it doesn't *exactly* correspond (it has more tokens). Fortunately we don't even have to implement this algorithm from scratch, TokenBuffer has it. Fixes https://github.com/clangd/clangd/issues/1289 Fixes https://github.com/clangd/clangd/issues/1118 Fixes https://github.com/clangd/clangd/issues/1018 Differential Revision: https://reviews.llvm.org/D133982 (cherry picked from commit 924974a3a13b03090d04860f209ce11b3d9d00a6) Added: Modified: clang-tools-extra/clangd/InlayHints.cpp clang-tools-extra/clangd/unittests/InlayHintTests.cpp Removed: diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp index 7be05fbc3b34..16c6b1cecc03 100644 --- a/clang-tools-extra/clangd/InlayHints.cpp +++ b/clang-tools-extra/clangd/InlayHints.cpp @@ -10,6 +10,7 @@ #include "Config.h" #include "HeuristicResolver.h" #include "ParsedAST.h" +#include "SourceCode.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/ExprCXX.h" @@ -192,8 +193,8 @@ class InlayHintVisitor : public RecursiveASTVisitor { public: InlayHintVisitor(std::vector &Results, ParsedAST &AST, const Config &Cfg, llvm::Optional RestrictRange) - : Results(Results), AST(AST.getASTContext()), Cfg(Cfg), -RestrictRange(std::move(RestrictRange)), + : Results(Results), AST(AST.getASTContext()), Tokens(AST.getTokens()), +Cfg(Cfg), RestrictRange(std::move(RestrictRange)), MainFileID(AST.getSourceManager().getMainFileID()), Resolver(AST.getHeuristicResolver()), TypeHintPolicy(this->AST.getPrintingPolicy()), @@ -227,8 +228,7 @@ class InlayHintVisitor : public RecursiveASTVisitor { return true; } -processCall(E->getParenOrBraceRange().getBegin(), E->getConstructor(), -{E->getArgs(), E->getNumArgs()}); +processCall(E->getConstructor(), {E->getArgs(), E->getNumArgs()}); return true; } @@ -254,7 +254,7 @@ class InlayHintVisitor : public RecursiveASTVisitor { if (!Callee) return true; -processCall(E->getRParenLoc(), Callee, {E->getArgs(), E->getNumArgs()}); +processCall(Callee, {E->getArgs(), E->getNumArgs()}); return true; } @@ -278,11 +278,11 @@ class InlayHintVisitor : public RecursiveASTVisitor { return true; } - void addReturnTypeHint(FunctionDecl *D, SourceLocation Loc) { + void addReturnTypeHint(FunctionDecl *D, SourceRange Range) { auto *AT = D->getReturnType()->getContainedAutoType(); if (!AT || AT->getDeducedType().isNull()) return; -addTypeHint(Loc, D->getReturnType(), /*Prefix=*/"-> "); +addTypeHint(Range, D->getReturnType(), /*Prefix=*/"-> "); } bool VisitVarDecl(VarDecl *D) { @@ -375,21 +375,11 @@ class InlayHintVisitor : public RecursiveASTVisitor { private: using NameVec = SmallVector; - // The purpose of Anchor is to deal with macros. It should be the call's - // opening or closing parenthesis or brace. (Always using the opening would - // make more sense but CallExpr only exposes the closing.) We heuristically - // assume that if this location does not come from a macro definition, then - // the entire argument list likely appears in the main file and can be hinted. - void processCall(SourceLocation Anchor, const FunctionDecl *Callee, + void processCall(const FunctionDecl *Callee, llvm::ArrayRef Args) { if (!Cfg.InlayHints.Parameters || Args.size() == 0 || !Callee) return; -// If the anchor location comes from a macro defintion, there's nowhere to -// put hints. -if (!AST.getSourceManager().getTopMacroCallerLoc(Anchor).isFileID()) - return; - // The parameter name of a move or copy constructor is not very interesting. if (auto *Ctor = dyn_cast(Callee)) if (Ctor->isCopyOrMoveConstructor()) @@ -637,25 +627,33 @@ class InlayHintVisitor : public RecursiveASTVisitor { #undef CHECK_KIND } -auto FileRange = -toHalfOpenFileRange(AST.getSourceManager(), AST.getLangOpts(), R); -if (!FileRange) +auto LSPRange = getHintRange(R); +if (!LSPRange) return; -Range LSPRange{ -sourceLocToPosition(AST.getSourc
[llvm-branch-commits] [clang-tools-extra] c0748fe - [clang-tools-extra] [clangd] Respect llvm_shlib_dir in tests
Author: Michał Górny Date: 2022-10-10T08:48:56+02:00 New Revision: c0748fe6dec5927bb343c2bb25741fc5d0d280a2 URL: https://github.com/llvm/llvm-project/commit/c0748fe6dec5927bb343c2bb25741fc5d0d280a2 DIFF: https://github.com/llvm/llvm-project/commit/c0748fe6dec5927bb343c2bb25741fc5d0d280a2.diff LOG: [clang-tools-extra] [clangd] Respect llvm_shlib_dir in tests Add llvm_shlib_dir to variables used in clangd test suite, consistently to how it is used in the test suites of clang, clang-tools-extra and a few other components. This is necessary to ensure that the correct shared libraries are used when building clang standalone -- otherwise, use_clang() sets LD_LIBRARY_PATH to the directory containing the earlier system installation of clang rather than the just-built library. Differential Revision: https://reviews.llvm.org/D135062 (cherry picked from commit 77945a344c3dee3f9735744c8d4151ef2cec6a8d) Added: Modified: clang-tools-extra/clangd/test/lit.site.cfg.py.in Removed: diff --git a/clang-tools-extra/clangd/test/lit.site.cfg.py.in b/clang-tools-extra/clangd/test/lit.site.cfg.py.in index 20caa72af3da1..1fe7c8d0f3244 100644 --- a/clang-tools-extra/clangd/test/lit.site.cfg.py.in +++ b/clang-tools-extra/clangd/test/lit.site.cfg.py.in @@ -10,6 +10,7 @@ config.python_executable = "@Python3_EXECUTABLE@" config.clang_tools_dir = lit_config.substitute("@CURRENT_TOOLS_DIR@") config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@") config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@") +config.llvm_shlib_dir = "@SHLIBDIR@" config.clangd_source_dir = "@CMAKE_CURRENT_SOURCE_DIR@/.." config.clangd_binary_dir = "@CMAKE_CURRENT_BINARY_DIR@/.." ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] 73ea64f - [clangd] Avoid scanning up to end of file on each comment!
Author: Sam McCall Date: 2022-10-10T08:49:11+02:00 New Revision: 73ea64f30411bcb9a2f32649a49d4c23780ee045 URL: https://github.com/llvm/llvm-project/commit/73ea64f30411bcb9a2f32649a49d4c23780ee045 DIFF: https://github.com/llvm/llvm-project/commit/73ea64f30411bcb9a2f32649a49d4c23780ee045.diff LOG: [clangd] Avoid scanning up to end of file on each comment! Assigning char* (pointing at comment start) to StringRef was causing us to scan the rest of the source file looking for the null terminator. This seems to be eating about 8% of our *total* CPU! While fixing this, factor out the common bits from the two places we're parsing IWYU pragmas. Differential Revision: https://reviews.llvm.org/D135314 (cherry picked from commit 5d2d527c32da2081b814ef8b446bc3e037f74b0a) Added: Modified: clang-tools-extra/clangd/Headers.cpp clang-tools-extra/clangd/Headers.h clang-tools-extra/clangd/index/CanonicalIncludes.cpp clang-tools-extra/clangd/unittests/HeadersTests.cpp Removed: diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp index cb7abac3e9f9e..af22a446b03ce 100644 --- a/clang-tools-extra/clangd/Headers.cpp +++ b/clang-tools-extra/clangd/Headers.cpp @@ -22,9 +22,17 @@ namespace clang { namespace clangd { -const char IWYUPragmaKeep[] = "// IWYU pragma: keep"; -const char IWYUPragmaExport[] = "// IWYU pragma: export"; -const char IWYUPragmaBeginExports[] = "// IWYU pragma: begin_exports"; +llvm::Optional parseIWYUPragma(const char *Text) { + // This gets called for every comment seen in the preamble, so it's quite hot. + constexpr llvm::StringLiteral IWYUPragma = "// IWYU pragma: "; + if (strncmp(Text, IWYUPragma.data(), IWYUPragma.size())) +return llvm::None; + Text += IWYUPragma.size(); + const char *End = Text; + while (*End != 0 && *End != '\n') +++End; + return StringRef(Text, End - Text); +} class IncludeStructure::RecordHeaders : public PPCallbacks, public CommentHandler { @@ -129,10 +137,10 @@ class IncludeStructure::RecordHeaders : public PPCallbacks, } bool HandleComment(Preprocessor &PP, SourceRange Range) override { -bool Err = false; -llvm::StringRef Text = SM.getCharacterData(Range.getBegin(), &Err); -if (Err) +auto Pragma = parseIWYUPragma(SM.getCharacterData(Range.getBegin())); +if (!Pragma) return false; + if (inMainFile()) { // Given: // @@ -150,8 +158,7 @@ class IncludeStructure::RecordHeaders : public PPCallbacks, // will know that the next inclusion is behind the IWYU pragma. // FIXME: Support "IWYU pragma: begin_exports" and "IWYU pragma: // end_exports". - if (!Text.startswith(IWYUPragmaExport) && - !Text.startswith(IWYUPragmaKeep)) + if (!Pragma->startswith("export") && !Pragma->startswith("keep")) return false; unsigned Offset = SM.getFileOffset(Range.getBegin()); LastPragmaKeepInMainFileLine = @@ -161,8 +168,7 @@ class IncludeStructure::RecordHeaders : public PPCallbacks, // does not support them properly yet, so they will be not marked as // unused. // FIXME: Once IncludeCleaner supports export pragmas, remove this. - if (!Text.startswith(IWYUPragmaExport) && - !Text.startswith(IWYUPragmaBeginExports)) + if (!Pragma->startswith("export") && !Pragma->startswith("begin_exports")) return false; Out->HasIWYUExport.insert( *Out->getID(SM.getFileEntryForID(SM.getFileID(Range.getBegin(); diff --git a/clang-tools-extra/clangd/Headers.h b/clang-tools-extra/clangd/Headers.h index ff3f063168325..ba72ad397bf8f 100644 --- a/clang-tools-extra/clangd/Headers.h +++ b/clang-tools-extra/clangd/Headers.h @@ -35,6 +35,12 @@ namespace clangd { /// Returns true if \p Include is literal include like "path" or . bool isLiteralInclude(llvm::StringRef Include); +/// If Text begins an Include-What-You-Use directive, returns it. +/// Given "// IWYU pragma: keep", returns "keep". +/// Input is a null-terminated char* as provided by SM.getCharacterData(). +/// (This should not be StringRef as we do *not* want to scan for its length). +llvm::Optional parseIWYUPragma(const char *Text); + /// Represents a header file to be #include'd. struct HeaderFile { std::string File; diff --git a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp index 145d98d57ca83..bbc80e7e0d139 100644 --- a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp +++ b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp @@ -17,8 +17,6 @@ namespace clang { namespace clangd { namespace { -const char IWYUPragma[] = "// IWYU pragma: private, include "; - const std::pair IncludeMappings[] = { {"include/__stddef_max_align_t.h", ""}, {"include/__wmmintrin_aes.h", ""}, @@
[llvm-branch-commits] [clang] 27e075f - [Syntax] Fix macro-arg handling in TokenBuffer::spelledForExpanded
Author: Sam McCall Date: 2022-10-10T08:49:22+02:00 New Revision: 27e075fcfad137b43367734052c63abe12555403 URL: https://github.com/llvm/llvm-project/commit/27e075fcfad137b43367734052c63abe12555403 DIFF: https://github.com/llvm/llvm-project/commit/27e075fcfad137b43367734052c63abe12555403.diff LOG: [Syntax] Fix macro-arg handling in TokenBuffer::spelledForExpanded A few cases were not handled correctly. Notably: #define ID(X) X #define HIDE a ID(b) HIDE spelledForExpanded() would claim HIDE is an equivalent range of the 'b' it contains, despite the fact that HIDE also covers 'a'. While trying to fix this bug, I found findCommonRangeForMacroArgs hard to understand (both the implementation and how it's used in spelledForExpanded). It relies on details of the SourceLocation graph that are IMO fairly obscure. So I've added/revised quite a lot of comments and made some naming tweaks. Fixes https://github.com/clangd/clangd/issues/1289 Differential Revision: https://reviews.llvm.org/D134618 (cherry picked from commit 67268ee11c220b1dfdf84afb10a12371c5ae6400) Added: Modified: clang/lib/Tooling/Syntax/Tokens.cpp clang/unittests/Tooling/Syntax/TokensTest.cpp Removed: diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp b/clang/lib/Tooling/Syntax/Tokens.cpp index e2014f965c900..9a30e3692ee54 100644 --- a/clang/lib/Tooling/Syntax/Tokens.cpp +++ b/clang/lib/Tooling/Syntax/Tokens.cpp @@ -55,45 +55,140 @@ getTokensCovering(llvm::ArrayRef Toks, SourceRange R, return {Begin, End}; } -// Finds the smallest expansion range that contains expanded tokens First and -// Last, e.g.: +// Finds the range within FID corresponding to expanded tokens [First, Last]. +// Prev precedes First and Next follows Last, these must *not* be included. +// If no range satisfies the criteria, returns an invalid range. +// // #define ID(x) x // ID(ID(ID(a1) a2)) // ~~ -> a1 // ~~ -> a2 // ~ -> a1 a2 -SourceRange findCommonRangeForMacroArgs(const syntax::Token &First, -const syntax::Token &Last, -const SourceManager &SM) { - SourceRange Res; - auto FirstLoc = First.location(), LastLoc = Last.location(); - // Keep traversing up the spelling chain as longs as tokens are part of the - // same expansion. - while (!FirstLoc.isFileID() && !LastLoc.isFileID()) { -auto ExpInfoFirst = SM.getSLocEntry(SM.getFileID(FirstLoc)).getExpansion(); -auto ExpInfoLast = SM.getSLocEntry(SM.getFileID(LastLoc)).getExpansion(); -// Stop if expansions have diverged. -if (ExpInfoFirst.getExpansionLocStart() != -ExpInfoLast.getExpansionLocStart()) +SourceRange spelledForExpandedSlow(SourceLocation First, SourceLocation Last, + SourceLocation Prev, SourceLocation Next, + FileID TargetFile, + const SourceManager &SM) { + // There are two main parts to this algorithm: + // - identifying which spelled range covers the expanded tokens + // - validating that this range doesn't cover any extra tokens (First/Last) + // + // We do these in order. However as we transform the expanded range into the + // spelled one, we adjust First/Last so the validation remains simple. + + assert(SM.getSLocEntry(TargetFile).isFile()); + // In most cases, to select First and Last we must return their expansion + // range, i.e. the whole of any macros they are included in. + // + // When First and Last are part of the *same macro arg* of a macro written + // in TargetFile, we that slice of the arg, i.e. their spelling range. + // + // Unwrap such macro calls. If the target file has A(B(C)), the + // SourceLocation stack of a token inside C shows us the expansion of A first, + // then B, then any macros inside C's body, then C itself. + // (This is the reverse of the order the PP applies the expansions in). + while (First.isMacroID() && Last.isMacroID()) { +auto DecFirst = SM.getDecomposedLoc(First); +auto DecLast = SM.getDecomposedLoc(Last); +auto &ExpFirst = SM.getSLocEntry(DecFirst.first).getExpansion(); +auto &ExpLast = SM.getSLocEntry(DecLast.first).getExpansion(); + +if (!ExpFirst.isMacroArgExpansion() || !ExpLast.isMacroArgExpansion()) + break; +// Locations are in the same macro arg if they expand to the same place. +// (They may still have diff erent FileIDs - an arg can have >1 chunks!) +if (ExpFirst.getExpansionLocStart() != ExpLast.getExpansionLocStart()) break; -// Do not continue into macro bodies. -if (!ExpInfoFirst.isMacroArgExpansion() || -!ExpInfoLast.isMacroArgExpansion()) +// Careful, given: +// #define HIDE ID(ID(a)) +// ID(ID(HIDE)) +// The token `a` is wrapped in 4 arg-expansions, we only want to unwra
[llvm-branch-commits] [libcxx] fc47af8 - Bump version to 15.0.3
Author: Tobias Hieta Date: 2022-10-10T08:53:34+02:00 New Revision: fc47af8c914012789db554ecb24e8344a4709ebf URL: https://github.com/llvm/llvm-project/commit/fc47af8c914012789db554ecb24e8344a4709ebf DIFF: https://github.com/llvm/llvm-project/commit/fc47af8c914012789db554ecb24e8344a4709ebf.diff LOG: Bump version to 15.0.3 Added: Modified: libcxx/include/__config llvm/CMakeLists.txt llvm/utils/gn/secondary/llvm/version.gni llvm/utils/lit/lit/__init__.py utils/bazel/llvm-project-overlay/clang/BUILD.bazel utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h utils/bazel/llvm-project-overlay/lld/BUILD.bazel utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h Removed: diff --git a/libcxx/include/__config b/libcxx/include/__config index 01377a9617ea4..589b5c3b2241e 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -36,7 +36,7 @@ #ifdef __cplusplus -# define _LIBCPP_VERSION 15002 +# define _LIBCPP_VERSION 15003 # define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y # define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index fddb8ffd0c169..1a45f2eff0130 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -22,7 +22,7 @@ if(NOT DEFINED LLVM_VERSION_MINOR) set(LLVM_VERSION_MINOR 0) endif() if(NOT DEFINED LLVM_VERSION_PATCH) - set(LLVM_VERSION_PATCH 2) + set(LLVM_VERSION_PATCH 3) endif() if(NOT DEFINED LLVM_VERSION_SUFFIX) set(LLVM_VERSION_SUFFIX) diff --git a/llvm/utils/gn/secondary/llvm/version.gni b/llvm/utils/gn/secondary/llvm/version.gni index ac79ba5bbc774..6d64da0180dff 100644 --- a/llvm/utils/gn/secondary/llvm/version.gni +++ b/llvm/utils/gn/secondary/llvm/version.gni @@ -1,4 +1,4 @@ llvm_version_major = 15 llvm_version_minor = 0 -llvm_version_patch = 2 +llvm_version_patch = 3 llvm_version = "$llvm_version_major.$llvm_version_minor.$llvm_version_patch" diff --git a/llvm/utils/lit/lit/__init__.py b/llvm/utils/lit/lit/__init__.py index 2ee97f578f04a..5cb7ccdc67dab 100644 --- a/llvm/utils/lit/lit/__init__.py +++ b/llvm/utils/lit/lit/__init__.py @@ -2,7 +2,7 @@ __author__ = 'Daniel Dunbar' __email__ = 'dan...@minormatter.com' -__versioninfo__ = (15, 0, 2) +__versioninfo__ = (15, 0, 3) __version__ = '.'.join(str(v) for v in __versioninfo__) + 'dev' __all__ = [] diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel index fe5223d3195a0..6cb8889bf50ff 100644 --- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel @@ -358,11 +358,11 @@ genrule( name = "basic_version_gen", outs = ["include/clang/Basic/Version.inc"], cmd = ( -"echo '#define CLANG_VERSION 15.0.2' >> $@\n" + +"echo '#define CLANG_VERSION 15.0.3' >> $@\n" + "echo '#define CLANG_VERSION_MAJOR 15' >> $@\n" + "echo '#define CLANG_VERSION_MINOR 0' >> $@\n" + -"echo '#define CLANG_VERSION_PATCHLEVEL 2' >> $@\n" + -"echo '#define CLANG_VERSION_STRING \"15.0.2\"' >> $@\n" +"echo '#define CLANG_VERSION_PATCHLEVEL 3' >> $@\n" + +"echo '#define CLANG_VERSION_STRING \"15.0.3\"' >> $@\n" ), ) diff --git a/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h b/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h index a3fefb8fb2bc5..cedeb0a2c9511 100644 --- a/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h +++ b/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h @@ -93,7 +93,7 @@ /* CLANG_HAVE_RLIMITS defined conditionally below */ /* The LLVM product name and version */ -#define BACKEND_PACKAGE_STRING "LLVM 15.0.2" +#define BACKEND_PACKAGE_STRING "LLVM 15.0.3" /* Linker version detected at compile time. */ /* #undef HOST_LINK_VERSION */ diff --git a/utils/bazel/llvm-project-overlay/lld/BUILD.bazel b/utils/bazel/llvm-project-overlay/lld/BUILD.bazel index db46efe289e28..139298d1533f3 100644 --- a/utils/bazel/llvm-project-overlay/lld/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/lld/BUILD.bazel @@ -13,7 +13,7 @@ package( genrule( name = "config_version_gen", outs = ["include/lld/Common/Version.inc"], -cmd = "echo '#define LLD_VERSION_STRING \"15.0.2\"' > $@", +cmd = "echo '#define LLD_VERSION_STRING \"15.0.3\"' > $@", ) genrule( diff --git a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h index 66f8eecc5ff04..37bb4cf22a890 100644 --- a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h +++ b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h @@ -80,10 +80,10 @@ #define LLVM_VERSION_MINOR 0 /* Patch version of the LLVM