[clang] 7e52ad3 - Fix a warning for #91455 [-Wc++20-extensions]
Author: NAKAMURA Takumi Date: 2024-05-10T16:00:16+09:00 New Revision: 7e52ad3b5b9509d0873965e8492ab01141342822 URL: https://github.com/llvm/llvm-project/commit/7e52ad3b5b9509d0873965e8492ab01141342822 DIFF: https://github.com/llvm/llvm-project/commit/7e52ad3b5b9509d0873965e8492ab01141342822.diff LOG: Fix a warning for #91455 [-Wc++20-extensions] Added: Modified: clang/unittests/Analysis/FlowSensitive/WatchedLiteralsSolverTest.cpp Removed: diff --git a/clang/unittests/Analysis/FlowSensitive/WatchedLiteralsSolverTest.cpp b/clang/unittests/Analysis/FlowSensitive/WatchedLiteralsSolverTest.cpp index 0a2514a2d7c12..d194742dbea7d 100644 --- a/clang/unittests/Analysis/FlowSensitive/WatchedLiteralsSolverTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/WatchedLiteralsSolverTest.cpp @@ -20,7 +20,7 @@ SolverTest::createSolverWithLowTimeout() { namespace { INSTANTIATE_TYPED_TEST_SUITE_P(WatchedLiteralsSolverTest, SolverTest, - WatchedLiteralsSolver); + WatchedLiteralsSolver, ); } // namespace } // namespace clang::dataflow::test ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2a61eeb - Cleanup asserts in BranchParameters and DecisionParameters
Author: NAKAMURA Takumi Date: 2024-05-10T16:00:16+09:00 New Revision: 2a61eebc66c0903cf3834a520b1f975ac3cdf92b URL: https://github.com/llvm/llvm-project/commit/2a61eebc66c0903cf3834a520b1f975ac3cdf92b DIFF: https://github.com/llvm/llvm-project/commit/2a61eebc66c0903cf3834a520b1f975ac3cdf92b.diff LOG: Cleanup asserts in BranchParameters and DecisionParameters Added: Modified: clang/lib/CodeGen/CoverageMappingGen.cpp llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h llvm/lib/ProfileData/Coverage/CoverageMapping.cpp llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp Removed: diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 733686d4946b3..ce2f39aeb0821 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -191,10 +191,7 @@ class SourceMappingRegion { bool isBranch() const { return FalseCount.has_value(); } bool isMCDCDecision() const { -const auto *DecisionParams = -std::get_if(&MCDCParams); -assert(!DecisionParams || DecisionParams->NumConditions > 0); -return DecisionParams; +return std::holds_alternative(MCDCParams); } const auto &getMCDCDecisionParams() const { diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h index 7a8b6639f2971..da03104045249 100644 --- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h +++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h @@ -462,10 +462,7 @@ struct MCDCRecord { CounterMappingRegion getDecisionRegion() const { return Region; } unsigned getNumConditions() const { -unsigned NumConditions = Region.getDecisionParams().NumConditions; -assert(NumConditions != 0 && - "In MC/DC, NumConditions should never be zero!"); -return NumConditions; +return Region.getDecisionParams().NumConditions; } unsigned getNumTestVectors() const { return TV.size(); } bool isCondFolded(unsigned Condition) const { return Folded[Condition]; } diff --git a/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h b/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h index 8c78bed4dec52..191e4ead95ea2 100644 --- a/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h +++ b/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h @@ -33,7 +33,9 @@ struct DecisionParameters { DecisionParameters() = delete; DecisionParameters(unsigned BitmapIdx, unsigned NumConditions) - : BitmapIdx(BitmapIdx), NumConditions(NumConditions) {} + : BitmapIdx(BitmapIdx), NumConditions(NumConditions) { +assert(NumConditions > 0); + } }; struct BranchParameters { @@ -44,7 +46,9 @@ struct BranchParameters { BranchParameters() = delete; BranchParameters(ConditionID ID, const ConditionIDs &Conds) - : ID(ID), Conds(Conds) {} + : ID(ID), Conds(Conds) { +assert(ID >= 0); + } }; /// The type of MC/DC-specific parameters. diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp index 6c77ce017c036..8c81bbe8e9c4e 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp @@ -338,7 +338,6 @@ class NextIDsBuilder { #endif for (const auto *Branch : Branches) { const auto &BranchParams = Branch->getBranchParams(); - assert(BranchParams.ID >= 0 && "CondID isn't set"); assert(SeenIDs.insert(BranchParams.ID).second && "Duplicate CondID"); NextIDs[BranchParams.ID] = BranchParams.Conds; } @@ -694,7 +693,6 @@ class MCDCDecisionRecorder { assert(Branch.Kind == CounterMappingRegion::MCDCBranchRegion); auto ConditionID = Branch.getBranchParams().ID; - assert(ConditionID >= 0 && "ConditionID should be positive"); if (ConditionIDs.contains(ConditionID) || ConditionID >= DecisionParams.NumConditions) diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp index 5036bde5aca72..adfd22804356e 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp @@ -256,7 +256,6 @@ void CoverageMappingWriter::write(raw_ostream &OS) { // They are written as internal values plus 1. const auto &BranchParams = I->getBranchParams(); ParamsShouldBeNull = false; -assert(BranchParams.ID >= 0); unsigned ID1 = BranchParams.ID + 1; unsigned TID1 = BranchParams.Conds[true] + 1; unsigned FID1 = BranchParams.Conds[false] + 1; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/lis
[clang] 6ce4c4c - [clang-format][NFC] Drop a redundant clang::format::
Author: Owen Pan Date: 2024-05-10T00:05:16-07:00 New Revision: 6ce4c4ca2bb846c2b8d64dc2b3d3496785c9edff URL: https://github.com/llvm/llvm-project/commit/6ce4c4ca2bb846c2b8d64dc2b3d3496785c9edff DIFF: https://github.com/llvm/llvm-project/commit/6ce4c4ca2bb846c2b8d64dc2b3d3496785c9edff.diff LOG: [clang-format][NFC] Drop a redundant clang::format:: Added: Modified: clang/lib/Format/UnwrappedLineParser.cpp Removed: diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 71557b127fb74..310b75485e089 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -3385,7 +3385,7 @@ void UnwrappedLineParser::parseAccessSpecifier() { /// \brief Parses a requires, decides if it is a clause or an expression. /// \pre The current token has to be the requires keyword. /// \returns true if it parsed a clause. -bool clang::format::UnwrappedLineParser::parseRequires() { +bool UnwrappedLineParser::parseRequires() { assert(FormatTok->is(tok::kw_requires) && "'requires' expected"); auto RequiresToken = FormatTok; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6aac30f - Update FEAT_PAuth_LR behaviour for AArch64 (#90614)
Author: Jack Styles Date: 2024-05-10T08:09:02+01:00 New Revision: 6aac30fa43f094ac25269bda163dc89a88cb8da7 URL: https://github.com/llvm/llvm-project/commit/6aac30fa43f094ac25269bda163dc89a88cb8da7 DIFF: https://github.com/llvm/llvm-project/commit/6aac30fa43f094ac25269bda163dc89a88cb8da7.diff LOG: Update FEAT_PAuth_LR behaviour for AArch64 (#90614) Currently, LLVM enables `-mbranch-protection=standard` as `bti+pac-ret`. To align LLVM with the behaviour in GNU, this has been updated to `bti+pac-ret+pc` when FEAT_PAuth_LR is enabled as an optional feature via the `-mcpu=` options. If this is not enabled, then this will revert to the existing behaviour. Added: Modified: clang/lib/Basic/Targets/AArch64.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/Preprocessor/aarch64-target-features.c llvm/docs/ReleaseNotes.rst llvm/include/llvm/TargetParser/AArch64TargetParser.h llvm/include/llvm/TargetParser/ARMTargetParserCommon.h llvm/lib/TargetParser/AArch64TargetParser.cpp llvm/lib/TargetParser/ARMTargetParserCommon.cpp Removed: diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 4b1545339f694..5db1ce78c657f 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -225,7 +225,7 @@ bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef, BranchProtectionInfo &BPI, StringRef &Err) const { llvm::ARM::ParsedBranchProtection PBP; - if (!llvm::ARM::parseBranchProtection(Spec, PBP, Err)) + if (!llvm::ARM::parseBranchProtection(Spec, PBP, Err, HasPAuthLR)) return false; BPI.SignReturnAddr = diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 449eb9b2a965a..f81c2024ae486 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -55,6 +55,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include "llvm/Support/YAMLParser.h" +#include "llvm/TargetParser/AArch64TargetParser.h" #include "llvm/TargetParser/ARMTargetParserCommon.h" #include "llvm/TargetParser/Host.h" #include "llvm/TargetParser/LoongArchTargetParser.h" @@ -1511,7 +1512,24 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, } else { StringRef DiagMsg; llvm::ARM::ParsedBranchProtection PBP; -if (!llvm::ARM::parseBranchProtection(A->getValue(), PBP, DiagMsg)) +bool EnablePAuthLR = false; + +// To know if we need to enable PAuth-LR As part of the standard branch +// protection option, it needs to be determined if the feature has been +// activated in the `march` argument. This information is stored within the +// CmdArgs variable and can be found using a search. +if (isAArch64) { + auto isPAuthLR = [](const char *member) { +llvm::AArch64::ExtensionInfo pauthlr_extension = +llvm::AArch64::getExtensionByID(llvm::AArch64::AEK_PAUTHLR); +return (pauthlr_extension.Feature.compare(member) == 0); + }; + + if (std::any_of(CmdArgs.begin(), CmdArgs.end(), isPAuthLR)) +EnablePAuthLR = true; +} +if (!llvm::ARM::parseBranchProtection(A->getValue(), PBP, DiagMsg, + EnablePAuthLR)) D.Diag(diag::err_drv_unsupported_option_argument) << A->getSpelling() << DiagMsg; if (!isAArch64 && PBP.Key == "b_key") diff --git a/clang/test/Preprocessor/aarch64-target-features.c b/clang/test/Preprocessor/aarch64-target-features.c index 4d10eeafa8847..82304a15a04a3 100644 --- a/clang/test/Preprocessor/aarch64-target-features.c +++ b/clang/test/Preprocessor/aarch64-target-features.c @@ -616,6 +616,9 @@ // == Check Armv9.5-A Pointer Authentication Enhancements(PAuth_LR). // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-LR-OFF %s // RUN: %clang -target arm64-none-linux-gnu -march=armv9.5-a -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-LR-OFF %s +// RUN: %clang -target arm64-none-linux-gnu -march=armv9.5-a -mbranch-protection=standard -x c -E -dM %s -o - | FileCheck -check-prefixes=CHECK-PAUTH-LR-OFF,CHECK-BRANCH-PROTECTION-NO-PC %s +// RUN: %clang -target arm64-none-linux-gnu -march=armv9.5-a+pauth-lr -mbranch-protection=standard -x c -E -dM %s -o - | FileCheck -check-prefixes=CHECK-PAUTH-LR,CHECK-BRANCH-PROTECTION-PC %s +// RUN: %clang -target arm64-none-linux-gnu -march=armv9.5-a+nopauth-lr -mbranch-protection=standard -x c -E -dM %s -o - | FileCheck -check-prefixes=CHECK-PAUTH-LR-OFF,CHECK-BRANCH-PROTECTION-NO-PC %s // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+pauth -mbranch-protection=none -x c -E -dM %s -o - | FileCheck -che
[clang] [llvm] Update FEAT_PAuth_LR behaviour for AArch64 (PR #90614)
https://github.com/Stylie777 closed https://github.com/llvm/llvm-project/pull/90614 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][driver] Accept -fallow-argument-mismatch with a warning instead of rejecting it (PR #91611)
banach-space wrote: Thank you for this contribution Paul! > Many autotools-utilizing projects (mpich among them) fail to complete the > configure step since it tries to invoke the (unknown to them) Fortran > compiler always with the -fallow-argument-mismatch flag. It sounds like an issue with the `mpich` build script rather than LLVM Flang. Why would `mpich` and other projects use this flag to begin with? Do other Fortran compilers support it? From GFrotran docs (https://gcc.gnu.org/onlinedocs/gfortran/Fortran-Dialect-Options.html): > Using this option is strongly discouraged. In general, I'm hesitant to allow such dummy flags that: * do nothing, * are there merely to prevent issues in build scripts. Are there no other ways around it? We obviously should make it possible for LLVM Flang to build all projects, but I really want to avoid Flang containing multiple dummy flags only to work around build scripts that assume a particular compiler is used. We might be missing some "gfortran compatibility mode" in Flang (on top of `FlangMode`). Such mode could allow unsupported GFortran flags and warn whenever those are used. `flang-new` would still "default" to `FlangMode` and just generate an error. In any case, it would be good to get more opinions on this. @kiranchandramohan , anyone else might be interested in this? https://github.com/llvm/llvm-project/pull/91611 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang] New -fdebug-unparse-with-modules option (PR #91660)
https://github.com/banach-space approved this pull request. LGTM, thanks! https://github.com/llvm/llvm-project/pull/91660 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Pass -fseparate-named-sections from the driver (PR #91567)
https://github.com/petrhosek updated https://github.com/llvm/llvm-project/pull/91567 >From ca2b9d52d31866a657e2eb19585cdcd11bcad7d3 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Thu, 9 May 2024 00:28:33 -0700 Subject: [PATCH 1/2] [Clang] Pass -fseparate-named-sections from the driver This is a follow up to #91028. --- clang/lib/Driver/ToolChains/Clang.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 0a2ea96de7382..ceb5eb835ddce 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6116,6 +6116,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.addOptOutFlag(CmdArgs, options::OPT_funique_section_names, options::OPT_fno_unique_section_names); + Args.addOptInFlag(CmdArgs, options::OPT_fseparate_named_sections, +options::OPT_fno_separate_named_sections); Args.addOptInFlag(CmdArgs, options::OPT_funique_internal_linkage_names, options::OPT_fno_unique_internal_linkage_names); Args.addOptInFlag(CmdArgs, options::OPT_funique_basic_block_section_names, >From 9a7a23e62fca9bb2c3257732d6dcc66a2240c042 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Fri, 10 May 2024 00:29:28 -0700 Subject: [PATCH 2/2] Add test --- clang/test/Driver/fseparate-named-sections.c | 4 1 file changed, 4 insertions(+) create mode 100644 clang/test/Driver/fseparate-named-sections.c diff --git a/clang/test/Driver/fseparate-named-sections.c b/clang/test/Driver/fseparate-named-sections.c new file mode 100644 index 0..6264b8fcf0d84 --- /dev/null +++ b/clang/test/Driver/fseparate-named-sections.c @@ -0,0 +1,4 @@ +// RUN: %clang -### -fseparate-named-sections %s -c 2>&1 | FileCheck -check-prefix=CHECK-OPT %s +// RUN: %clang -### -fseparate-named-sections -fno-separate-named-sections %s -c 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s +// CHECK-OPT: "-fseparate-named-sections" +// CHECK-NOOPT-NOT: "-fseparate-named-sections" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 5d24217 - [Clang] Pass -fseparate-named-sections from the driver (#91567)
Author: Petr Hosek Date: 2024-05-10T00:38:52-07:00 New Revision: 5d24217c2c1c06358168cae65d3ff8632b28cd7d URL: https://github.com/llvm/llvm-project/commit/5d24217c2c1c06358168cae65d3ff8632b28cd7d DIFF: https://github.com/llvm/llvm-project/commit/5d24217c2c1c06358168cae65d3ff8632b28cd7d.diff LOG: [Clang] Pass -fseparate-named-sections from the driver (#91567) This is a follow up to #91028. Added: clang/test/Driver/fseparate-named-sections.c Modified: clang/lib/Driver/ToolChains/Clang.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index f81c2024ae486..42feb1650574e 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6146,6 +6146,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.addOptOutFlag(CmdArgs, options::OPT_funique_section_names, options::OPT_fno_unique_section_names); + Args.addOptInFlag(CmdArgs, options::OPT_fseparate_named_sections, +options::OPT_fno_separate_named_sections); Args.addOptInFlag(CmdArgs, options::OPT_funique_internal_linkage_names, options::OPT_fno_unique_internal_linkage_names); Args.addOptInFlag(CmdArgs, options::OPT_funique_basic_block_section_names, diff --git a/clang/test/Driver/fseparate-named-sections.c b/clang/test/Driver/fseparate-named-sections.c new file mode 100644 index 0..6264b8fcf0d84 --- /dev/null +++ b/clang/test/Driver/fseparate-named-sections.c @@ -0,0 +1,4 @@ +// RUN: %clang -### -fseparate-named-sections %s -c 2>&1 | FileCheck -check-prefix=CHECK-OPT %s +// RUN: %clang -### -fseparate-named-sections -fno-separate-named-sections %s -c 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s +// CHECK-OPT: "-fseparate-named-sections" +// CHECK-NOOPT-NOT: "-fseparate-named-sections" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Pass -fseparate-named-sections from the driver (PR #91567)
https://github.com/petrhosek closed https://github.com/llvm/llvm-project/pull/91567 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Sema] Fix handling of fields with initializers in nested anonymous unions. (PR #91692)
https://github.com/Endilll approved this pull request. LGTM, but someone else should take a look as well. https://github.com/llvm/llvm-project/pull/91692 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #85564)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/85564 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Processing real directories added as virtual ones (PR #91645)
https://github.com/ivanmurashko edited https://github.com/llvm/llvm-project/pull/91645 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Processing real directories added as virtual ones (PR #91645)
https://github.com/ivanmurashko edited https://github.com/llvm/llvm-project/pull/91645 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/91712 Remove FormatToken::isSimpleTypeSpecifier() and call Token::isSimpleTypeSpecifier(LangOpts) instead. >From 3e0b10020d15c102e050ad3785622bef01d1c075 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Fri, 10 May 2024 01:00:16 -0700 Subject: [PATCH] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() Remove FormatToken::isSimpleTypeSpecifier() and call Token::isSimpleTypeSpecifier(LangOpts) instead. --- clang/lib/Format/Format.cpp | 3 +- clang/lib/Format/FormatToken.cpp | 46 + clang/lib/Format/FormatToken.h| 8 +- clang/lib/Format/FormatTokenLexer.cpp | 1 - clang/lib/Format/QualifierAlignmentFixer.cpp | 24 +++-- clang/lib/Format/QualifierAlignmentFixer.h| 5 +- clang/lib/Format/TokenAnalyzer.cpp| 4 +- clang/lib/Format/TokenAnalyzer.h | 1 + clang/lib/Format/TokenAnnotator.cpp | 43 + clang/lib/Format/TokenAnnotator.h | 6 +- clang/lib/Format/UnwrappedLineParser.cpp | 19 ++-- clang/lib/Format/UnwrappedLineParser.h| 1 + clang/unittests/Format/QualifierFixerTest.cpp | 94 +++ 13 files changed, 121 insertions(+), 134 deletions(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index c4eac1c99a663..c5c79dd0f883e 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -3858,8 +3858,7 @@ LangOptions getFormattingLangOpts(const FormatStyle &Style) { LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11; LangOpts.LineComment = 1; - bool AlternativeOperators = Style.isCpp(); - LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0; + LangOpts.CXXOperatorNames = Style.isCpp(); LangOpts.Bool = 1; LangOpts.ObjC = 1; LangOpts.MicrosoftExt = 1;// To get kw___try, kw___finally. diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index 4fb70ffac706d..85bec71ffbbc8 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -34,43 +34,6 @@ const char *getTokenTypeName(TokenType Type) { return nullptr; } -// FIXME: This is copy&pasted from Sema. Put it in a common place and remove -// duplication. -bool FormatToken::isSimpleTypeSpecifier() const { - switch (Tok.getKind()) { - case tok::kw_short: - case tok::kw_long: - case tok::kw___int64: - case tok::kw___int128: - case tok::kw_signed: - case tok::kw_unsigned: - case tok::kw_void: - case tok::kw_char: - case tok::kw_int: - case tok::kw_half: - case tok::kw_float: - case tok::kw_double: - case tok::kw___bf16: - case tok::kw__Float16: - case tok::kw___float128: - case tok::kw___ibm128: - case tok::kw_wchar_t: - case tok::kw_bool: -#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait: -#include "clang/Basic/TransformTypeTraits.def" - case tok::annot_typename: - case tok::kw_char8_t: - case tok::kw_char16_t: - case tok::kw_char32_t: - case tok::kw_typeof: - case tok::kw_decltype: - case tok::kw__Atomic: -return true; - default: -return false; - } -} - // Sorted common C++ non-keyword types. static SmallVector CppNonKeywordTypes = { "clock_t", "int16_t", "int32_t", "int64_t", "int8_t", @@ -78,15 +41,16 @@ static SmallVector CppNonKeywordTypes = { "uint32_t", "uint64_t", "uint8_t", "uintptr_t", }; -bool FormatToken::isTypeName(bool IsCpp) const { - return is(TT_TypeName) || isSimpleTypeSpecifier() || +bool FormatToken::isTypeName(const LangOptions &LangOpts) const { + const bool IsCpp = LangOpts.CXXOperatorNames; + return is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts) || (IsCpp && is(tok::identifier) && std::binary_search(CppNonKeywordTypes.begin(), CppNonKeywordTypes.end(), TokenText)); } -bool FormatToken::isTypeOrIdentifier(bool IsCpp) const { - return isTypeName(IsCpp) || isOneOf(tok::kw_auto, tok::identifier); +bool FormatToken::isTypeOrIdentifier(const LangOptions &LangOpts) const { + return isTypeName(LangOpts) || isOneOf(tok::kw_auto, tok::identifier); } bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const { diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 95f16fde5005f..8792f4c750748 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -684,12 +684,8 @@ struct FormatToken { isAttribute(); } - /// Determine whether the token is a simple-type-specifier. - [[nodiscard]] bool isSimpleTypeSpecifier() const; - - [[nodiscard]] bool isTypeName(bool IsCpp) const; - - [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const; + [[nodiscard]] bool isTypeName(const LangOptions &LangOpts) const; + [[nodiscard]] bool isTypeOrIdentifier(const LangOptions &LangOpts) const; bool isObjCAccessSpecifier() const { return is(tok::at) && Next && diff --gi
[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) Changes Remove FormatToken::isSimpleTypeSpecifier() and call Token::isSimpleTypeSpecifier(LangOpts) instead. --- Patch is 29.50 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/91712.diff 13 Files Affected: - (modified) clang/lib/Format/Format.cpp (+1-2) - (modified) clang/lib/Format/FormatToken.cpp (+5-41) - (modified) clang/lib/Format/FormatToken.h (+2-6) - (modified) clang/lib/Format/FormatTokenLexer.cpp (-1) - (modified) clang/lib/Format/QualifierAlignmentFixer.cpp (+11-13) - (modified) clang/lib/Format/QualifierAlignmentFixer.h (+3-2) - (modified) clang/lib/Format/TokenAnalyzer.cpp (+2-2) - (modified) clang/lib/Format/TokenAnalyzer.h (+1) - (modified) clang/lib/Format/TokenAnnotator.cpp (+25-18) - (modified) clang/lib/Format/TokenAnnotator.h (+5-1) - (modified) clang/lib/Format/UnwrappedLineParser.cpp (+11-8) - (modified) clang/lib/Format/UnwrappedLineParser.h (+1) - (modified) clang/unittests/Format/QualifierFixerTest.cpp (+54-40) ``diff diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index c4eac1c99a663..c5c79dd0f883e 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -3858,8 +3858,7 @@ LangOptions getFormattingLangOpts(const FormatStyle &Style) { LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11; LangOpts.LineComment = 1; - bool AlternativeOperators = Style.isCpp(); - LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0; + LangOpts.CXXOperatorNames = Style.isCpp(); LangOpts.Bool = 1; LangOpts.ObjC = 1; LangOpts.MicrosoftExt = 1;// To get kw___try, kw___finally. diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index 4fb70ffac706d..85bec71ffbbc8 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -34,43 +34,6 @@ const char *getTokenTypeName(TokenType Type) { return nullptr; } -// FIXME: This is copy&pasted from Sema. Put it in a common place and remove -// duplication. -bool FormatToken::isSimpleTypeSpecifier() const { - switch (Tok.getKind()) { - case tok::kw_short: - case tok::kw_long: - case tok::kw___int64: - case tok::kw___int128: - case tok::kw_signed: - case tok::kw_unsigned: - case tok::kw_void: - case tok::kw_char: - case tok::kw_int: - case tok::kw_half: - case tok::kw_float: - case tok::kw_double: - case tok::kw___bf16: - case tok::kw__Float16: - case tok::kw___float128: - case tok::kw___ibm128: - case tok::kw_wchar_t: - case tok::kw_bool: -#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait: -#include "clang/Basic/TransformTypeTraits.def" - case tok::annot_typename: - case tok::kw_char8_t: - case tok::kw_char16_t: - case tok::kw_char32_t: - case tok::kw_typeof: - case tok::kw_decltype: - case tok::kw__Atomic: -return true; - default: -return false; - } -} - // Sorted common C++ non-keyword types. static SmallVector CppNonKeywordTypes = { "clock_t", "int16_t", "int32_t", "int64_t", "int8_t", @@ -78,15 +41,16 @@ static SmallVector CppNonKeywordTypes = { "uint32_t", "uint64_t", "uint8_t", "uintptr_t", }; -bool FormatToken::isTypeName(bool IsCpp) const { - return is(TT_TypeName) || isSimpleTypeSpecifier() || +bool FormatToken::isTypeName(const LangOptions &LangOpts) const { + const bool IsCpp = LangOpts.CXXOperatorNames; + return is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts) || (IsCpp && is(tok::identifier) && std::binary_search(CppNonKeywordTypes.begin(), CppNonKeywordTypes.end(), TokenText)); } -bool FormatToken::isTypeOrIdentifier(bool IsCpp) const { - return isTypeName(IsCpp) || isOneOf(tok::kw_auto, tok::identifier); +bool FormatToken::isTypeOrIdentifier(const LangOptions &LangOpts) const { + return isTypeName(LangOpts) || isOneOf(tok::kw_auto, tok::identifier); } bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const { diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 95f16fde5005f..8792f4c750748 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -684,12 +684,8 @@ struct FormatToken { isAttribute(); } - /// Determine whether the token is a simple-type-specifier. - [[nodiscard]] bool isSimpleTypeSpecifier() const; - - [[nodiscard]] bool isTypeName(bool IsCpp) const; - - [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const; + [[nodiscard]] bool isTypeName(const LangOptions &LangOpts) const; + [[nodiscard]] bool isTypeOrIdentifier(const LangOptions &LangOpts) const; bool isObjCAccessSpecifier() const { return is(tok::at) && Next && diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp index f430d3764babe..e21b5a882b777 100644 --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/li
[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)
https://github.com/kadircet edited https://github.com/llvm/llvm-project/pull/87208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)
https://github.com/kadircet requested changes to this pull request. https://github.com/llvm/llvm-project/pull/87208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)
@@ -135,6 +135,21 @@ TEST(IncludeCleaner, GetUnusedHeaders) { Pointee(writtenInclusion("\"dir/unused.h\""; } +TEST(IncludeCleaner, SystemUnusedHeaders) { + auto TU = TestTU::withCode(R"cpp( +#include +#include +SystemClass x; + )cpp"); + TU.AdditionalFiles["system/system_header.h"] = guard("class SystemClass {};"); + TU.AdditionalFiles["system/system_unused.h"] = guard(""); + TU.ExtraArgs = {"-isystem", testPath("system")}; + auto AST = TU.build(); + IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST, true); kadircet wrote: can you also add a negative test? (i.e. when `AnalyzeSystemHeaders = false`, `UnusedIncludes` is empty) https://github.com/llvm/llvm-project/pull/87208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)
@@ -254,6 +254,10 @@ struct Fragment { /// unused or missing. These can match any suffix of the header file in /// question. std::vector> IgnoreHeader; + + /// If false (default), unused system headers will be ignored. + /// Standard library headers are analyzed regardless of this option. + std::optional> AnalyzeSystemHeaders; kadircet wrote: Same renaming suggestion here for `s/SystemHeaders/AngledIncludes` https://github.com/llvm/llvm-project/pull/87208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)
@@ -572,32 +572,43 @@ struct FragmentCompiler { #else static llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags; #endif -auto Filters = std::make_shared>(); -for (auto &HeaderPattern : F.IgnoreHeader) { - // Anchor on the right. - std::string AnchoredPattern = "(" + *HeaderPattern + ")$"; - llvm::Regex CompiledRegex(AnchoredPattern, Flags); - std::string RegexError; - if (!CompiledRegex.isValid(RegexError)) { -diag(Warning, - llvm::formatv("Invalid regular expression '{0}': {1}", - *HeaderPattern, RegexError) - .str(), - HeaderPattern.Range); -continue; +std::shared_ptr> Filters; +if (!F.IgnoreHeader.empty()) { kadircet wrote: nit: you can keep this part the same, and just replace `if (Filters->emtpy()) return;` with `Filters.reset();` https://github.com/llvm/llvm-project/pull/87208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)
@@ -114,6 +114,7 @@ struct Config { /// these regexes. struct { std::vector> IgnoreHeader; + bool AnalyzeSystemHeaders = false; kadircet wrote: can you move the comment about regexes near `IgnoreHeader`. Also I think `AnalyzeAngledIncludes` would be a more fitting name, WDYT? https://github.com/llvm/llvm-project/pull/87208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)
@@ -62,15 +64,6 @@ issueIncludeCleanerDiagnostics(ParsedAST &AST, llvm::StringRef Code, const ThreadsafeFS &TFS, HeaderFilter IgnoreHeader = {}); -/// Affects whether standard library includes should be considered for -/// removal. This is off by default for now due to implementation limitations: -/// - macros are not tracked -/// - symbol names without a unique associated header are not tracked -/// - references to std-namespaced C types are not properly tracked: -/// instead of std::size_t -> we see ::size_t -> -/// FIXME: remove this hack once the implementation is good enough. -void setIncludeCleanerAnalyzesStdlib(bool B); kadircet wrote: completely agreed, thanks for cleaning this up! https://github.com/llvm/llvm-project/pull/87208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)
@@ -572,32 +572,43 @@ struct FragmentCompiler { #else static llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags; #endif -auto Filters = std::make_shared>(); -for (auto &HeaderPattern : F.IgnoreHeader) { - // Anchor on the right. - std::string AnchoredPattern = "(" + *HeaderPattern + ")$"; - llvm::Regex CompiledRegex(AnchoredPattern, Flags); - std::string RegexError; - if (!CompiledRegex.isValid(RegexError)) { -diag(Warning, - llvm::formatv("Invalid regular expression '{0}': {1}", - *HeaderPattern, RegexError) - .str(), - HeaderPattern.Range); -continue; +std::shared_ptr> Filters; +if (!F.IgnoreHeader.empty()) { + Filters = std::make_shared>(); + for (auto &HeaderPattern : F.IgnoreHeader) { +// Anchor on the right. +std::string AnchoredPattern = "(" + *HeaderPattern + ")$"; +llvm::Regex CompiledRegex(AnchoredPattern, Flags); +std::string RegexError; +if (!CompiledRegex.isValid(RegexError)) { + diag(Warning, + llvm::formatv("Invalid regular expression '{0}': {1}", + *HeaderPattern, RegexError) + .str(), + HeaderPattern.Range); + continue; +} +Filters->push_back(std::move(CompiledRegex)); } - Filters->push_back(std::move(CompiledRegex)); } -if (Filters->empty()) +std::optional AnalyzeSystemHeaders; +if (F.AnalyzeSystemHeaders.has_value()) + AnalyzeSystemHeaders = **F.AnalyzeSystemHeaders; kadircet wrote: RHS here is no longer an optional https://github.com/llvm/llvm-project/pull/87208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)
@@ -135,6 +135,21 @@ TEST(IncludeCleaner, GetUnusedHeaders) { Pointee(writtenInclusion("\"dir/unused.h\""; } +TEST(IncludeCleaner, SystemUnusedHeaders) { + auto TU = TestTU::withCode(R"cpp( +#include +#include +SystemClass x; + )cpp"); + TU.AdditionalFiles["system/system_header.h"] = guard("class SystemClass {};"); + TU.AdditionalFiles["system/system_unused.h"] = guard(""); + TU.ExtraArgs = {"-isystem", testPath("system")}; kadircet wrote: using `-I` instead of `-isystem` might be better here. as in the implementation we don't really disambiguate between type of the inclusions, just how they're spelled. https://github.com/llvm/llvm-project/pull/87208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] use llvm::any_of refactor getAnalyzerCheckersAndPackages [NFC] (PR #91713)
https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/91713 None >From 035363d336a9b115d5584efe01733cb1b76792c4 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Fri, 10 May 2024 16:28:06 +0800 Subject: [PATCH] [clang-tidy] use llvm::any_of refactor getAnalyzerCheckersAndPackages [NFC] --- clang-tools-extra/clang-tidy/ClangTidy.cpp | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index b877ea06dc05c..1cd7cdd10bc25 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -373,11 +373,11 @@ static CheckersList getAnalyzerCheckersAndPackages(ClangTidyContext &Context, const auto &RegisteredCheckers = AnalyzerOptions::getRegisteredCheckers(IncludeExperimental); - bool AnalyzerChecksEnabled = false; - for (StringRef CheckName : RegisteredCheckers) { -std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str()); -AnalyzerChecksEnabled |= Context.isCheckEnabled(ClangTidyCheckName); - } + const bool AnalyzerChecksEnabled = + llvm::any_of(RegisteredCheckers, [&](StringRef CheckName) -> bool { +return Context.isCheckEnabled( +(AnalyzerCheckNamePrefix + CheckName).str()); + }); if (!AnalyzerChecksEnabled) return List; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] use llvm::any_of refactor getAnalyzerCheckersAndPackages [NFC] (PR #91713)
llvmbot wrote: @llvm/pr-subscribers-clang-tidy @llvm/pr-subscribers-clang-tools-extra Author: Congcong Cai (HerrCai0907) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/91713.diff 1 Files Affected: - (modified) clang-tools-extra/clang-tidy/ClangTidy.cpp (+5-5) ``diff diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index b877ea06dc05c..1cd7cdd10bc25 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -373,11 +373,11 @@ static CheckersList getAnalyzerCheckersAndPackages(ClangTidyContext &Context, const auto &RegisteredCheckers = AnalyzerOptions::getRegisteredCheckers(IncludeExperimental); - bool AnalyzerChecksEnabled = false; - for (StringRef CheckName : RegisteredCheckers) { -std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str()); -AnalyzerChecksEnabled |= Context.isCheckEnabled(ClangTidyCheckName); - } + const bool AnalyzerChecksEnabled = + llvm::any_of(RegisteredCheckers, [&](StringRef CheckName) -> bool { +return Context.isCheckEnabled( +(AnalyzerCheckNamePrefix + CheckName).str()); + }); if (!AnalyzerChecksEnabled) return List; `` https://github.com/llvm/llvm-project/pull/91713 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement __reference_converts_from_temporary (PR #91199)
cor3ntin wrote: This breaks the build, I'll push a fix shortly. https://github.com/llvm/llvm-project/pull/91199 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)
@@ -954,9 +954,18 @@ void readGnuProperty(const InputSection &sec, ObjFile &f) { continue; } -uint32_t featureAndType = config->emachine == EM_AARCH64 - ? GNU_PROPERTY_AARCH64_FEATURE_1_AND - : GNU_PROPERTY_X86_FEATURE_1_AND; +uint32_t featureAndType = 0; +switch (config->emachine) { +default: yetingk wrote: Is it better to add case `EM_CASE_X86` and set unreachable for default case? https://github.com/llvm/llvm-project/pull/77414 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)
@@ -7884,10 +7902,11 @@ template void LLVMELFDumper::printNotes() { W.printString("Type", "Unknown (" + to_string(format_hex(Type, 10)) + ")"); +uint16_t Target = this->Obj.getHeader().e_machine; yetingk wrote: Is it better to use `EMachine` for the naming? https://github.com/llvm/llvm-project/pull/77414 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)
@@ -7884,10 +7902,11 @@ template void LLVMELFDumper::printNotes() { W.printString("Type", "Unknown (" + to_string(format_hex(Type, 10)) + ")"); +uint16_t Target = this->Obj.getHeader().e_machine; yetingk wrote: Move this definition into `if (Name == "Gnu") {` scope. https://github.com/llvm/llvm-project/pull/77414 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add config option to allow detection of unused system headers (PR #87208)
kadircet wrote: thanks for the patch! this definitely LGTM at high level. as you folks also pointed out we don't want to surface analysis for angled includes in general, as include-cleaner doesn't have support for system headers yet (we wanted to have something similar to Stdlib includes, which maps certain include suffixes for known system libraries like posix, glibc to their umbrella headers, but never got to it). As a result, turning this on unconditionally would yield a ton of false negatives, which renders analysis useless. But doing that behind a flag, especially in conjunction with `IgnoreHeaders` is a solution that works nicely in practice. https://github.com/llvm/llvm-project/pull/87208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Set correct FPOptions if attribute 'optnone' presents (PR #85605)
SLTozer wrote: It looks like this is causing crashes when including precompiled headers that contain optnone functions; this can be reproduced with a very short header file and any source file, even a completely empty one. Reproducer follows: ``` $ cat header.h __attribute__((optnone)) void foo() {} $ cat src.cpp // Empty file $ ./build/bin/clang -x c++-header header.h -o header.pch $ ./build/bin/clang -c -include-pch header.pch src.cpp clang: /home/gbtozers/dev/upstream-llvm/clang/lib/Serialization/ASTReader.cpp:8316: void clang::ASTReader::UpdateSema(): Assertion `*FpPragmaCurrentValue == SemaObj->FpPragmaStack.DefaultValue && "Expected a default pragma float_control value"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: ./build/bin/clang -c -include-pch header.pch src.cpp 1. parser at end of file #0 0x55db95a49978 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./build/bin/clang+0x7aa2978) #1 0x55db95a474ce llvm::sys::RunSignalHandlers() (./build/bin/clang+0x7aa04ce) #2 0x55db959ae1a6 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0 #3 0x7f1c0f348520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x7f1c0f39c9fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76 #5 0x7f1c0f39c9fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10 #6 0x7f1c0f39c9fc pthread_kill ./nptl/pthread_kill.c:89:10 #7 0x7f1c0f348476 gsignal ./signal/../sysdeps/posix/raise.c:27:6 #8 0x7f1c0f32e7f3 abort ./stdlib/abort.c:81:7 #9 0x7f1c0f32e71b _nl_load_domain ./intl/loadmsgcat.c:1177:9 #10 0x7f1c0f33fe96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #11 0x55db967f68db clang::ASTReader::UpdateSema() (./build/bin/clang+0x884f8db) #12 0x55db980be50c clang::Sema::Initialize() (./build/bin/clang+0xa11750c) #13 0x55db97f7a4e3 clang::Parser::Initialize() (./build/bin/clang+0x9fd34e3) #14 0x55db97f75373 clang::ParseAST(clang::Sema&, bool, bool) (./build/bin/clang+0x9fce373) #15 0x55db966b20cf clang::FrontendAction::Execute() (./build/bin/clang+0x870b0cf) #16 0x55db966212cd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (./build/bin/clang+0x867a2cd) #17 0x55db9679971e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (./build/bin/clang+0x87f271e) #18 0x55db933468bc cc1_main(llvm::ArrayRef, char const*, void*) (./build/bin/clang+0x539f8bc) #19 0x55db9334325d ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&) driver.cpp:0:0 #20 0x55db96467159 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::$_0>(long) Job.cpp:0:0 #21 0x55db959adee6 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (./build/bin/clang+0x7a06ee6) #22 0x55db96466892 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (./build/bin/clang+0x84bf892) #23 0x55db9641e954 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (./build/bin/clang+0x8477954) #24 0x55db9641ee87 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (./build/bin/clang+0x8477e87) #25 0x55db9643fcb8 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (./build/bin/clang+0x8498cb8) #26 0x55db93342790 clang_main(int, char**, llvm::ToolContext const&) (./build/bin/clang+0x539b790) #27 0x55db93353047 main (./build/bin/clang+0x53ac047) #28 0x7f1c0f32fd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #29 0x7f1c0f32fe40 call_init ./csu/../csu/libc-start.c:128:20 #30 0x7f1c0f32fe40 __libc_start_main ./csu/../csu/libc-start.c:379:5 #31 0x55db93340c25 _start (./build/bin/clang+0x5399c25) clang: error: clang frontend command failed with exit code 134 (use -v to see invocation) clang version 19.0.0git (https://github.com/llvm/llvm-project.git a04624206ddf03dc54d5c372e7eac13575b4124b) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/gbtozers/dev/upstream-llvm/build/bin Build config: +assertions clang: note: diagnostic msg: PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang: note: diagnostic msg: /tmp/src-520bcb.cpp clang: note: diagnostic msg: /tmp/src-520bcb.sh clang: note: diagnostic msg: ``` https://github.com/llvm/llvm-project/pull/85605 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (PR #91628)
https://github.com/hokein commented: The fix looks good to me, and thanks for the comprehensive explanation in the description. https://github.com/llvm/llvm-project/pull/91628 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (PR #91628)
https://github.com/hokein edited https://github.com/llvm/llvm-project/pull/91628 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (PR #91628)
@@ -84,3 +84,17 @@ nested_init_list::concept_fail nil_invalid{1, ""}; // expected-note@#INIT_LIST_INNER_INVALID {{candidate template ignored: substitution failure [with F = const char *]: constraints not satisfied for class template 'concept_fail' [with F = const char *]}} // expected-note@#INIT_LIST_INNER_INVALID {{candidate function template not viable: requires 1 argument, but 2 were provided}} // expected-note@#INIT_LIST_INNER_INVALID {{candidate function template not viable: requires 0 arguments, but 2 were provided}} + +namespace PR88142 { hokein wrote: nit: PR => GH https://github.com/llvm/llvm-project/pull/91628 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (PR #91628)
@@ -2583,11 +2580,27 @@ struct ConvertConstructorToDeductionGuideTransform { //-- The types of the function parameters are those of the constructor. for (auto *OldParam : TL.getParams()) { - ParmVarDecl *NewParam = - transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs); - if (NestedPattern && NewParam) + ParmVarDecl *NewParam = OldParam; + // Given + // template struct C { + // template struct D { + // template D(U, V); + // }; + // }; + // First, transform all the references to template parameters that are + // defined outside of the surrounding class template. That is T in the + // above example. + if (NestedPattern) { NewParam = transformFunctionTypeParam(NewParam, OuterInstantiationArgs, MaterializedTypedefs); +if (!NewParam) + return QualType(); + } + // Then, transform all the references to template parameters that are + // defined at the class template and the constructor. In this example, + // they're U and V, respectively. + NewParam = + transformFunctionTypeParam(NewParam, Args, MaterializedTypedefs); hokein wrote: We have the same pattern on Line 2438-2452 in this file, where we perform a substitution of `OuterInstantiationArgs` on a new transformed parameter decl, I think we should probably fix it as well. https://github.com/llvm/llvm-project/pull/91628 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Processing real directories added as virtual ones (PR #91645)
https://github.com/ivanmurashko edited https://github.com/llvm/llvm-project/pull/91645 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)
@@ -188,6 +188,8 @@ struct Config { StringRef zBtiReport = "none"; StringRef zCetReport = "none"; StringRef zPauthReport = "none"; + llvm::StringRef zZicfilpReport = "none"; yetingk wrote: Use `StringRef` instead of `llvm::StringRef`. https://github.com/llvm/llvm-project/pull/77414 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] [RISCV] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)
yetingk wrote: I am sorry that I missed the commit for a long time. Very sorry about it. https://github.com/llvm/llvm-project/pull/77414 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e6d29be - [clang] fix FMV test for Win x Arm builds (#91490)
Author: Tomas Matheson Date: 2024-05-10T09:57:06+01:00 New Revision: e6d29be566d19a6558597ed1ede4783e85485749 URL: https://github.com/llvm/llvm-project/commit/e6d29be566d19a6558597ed1ede4783e85485749 DIFF: https://github.com/llvm/llvm-project/commit/e6d29be566d19a6558597ed1ede4783e85485749.diff LOG: [clang] fix FMV test for Win x Arm builds (#91490) Added: Modified: clang/test/Driver/aarch64-fmv.c Removed: diff --git a/clang/test/Driver/aarch64-fmv.c b/clang/test/Driver/aarch64-fmv.c index 873a88964e9b7..e7d01d1d5906a 100644 --- a/clang/test/Driver/aarch64-fmv.c +++ b/clang/test/Driver/aarch64-fmv.c @@ -11,8 +11,8 @@ // RUN: %clang --target=aarch64-linux-android23 --rtlib=compiler-rt -### -c %s 2>&1 | FileCheck -check-prefix=FMV-ENABLED %s // FMV is disabled without compiler-rt: -// RUN: %clang --target=aarch64 -### -c %s 2>&1 | FileCheck -check-prefix=FMV-DISABLED %s -// RUN: %clang --target=aarch64-linux-gnu -### -c %s 2>&1 | FileCheck -check-prefix=FMV-DISABLED %s +// RUN: %clang --rtlib=libgcc --target=aarch64 -### -c %s 2>&1 | FileCheck -check-prefix=FMV-DISABLED %s +// RUN: %clang --rtlib=libgcc --target=aarch64-linux-gnu -### -c %s 2>&1 | FileCheck -check-prefix=FMV-DISABLED %s // Disabled for older android versions: // RUN: %clang --rtlib=compiler-rt --target=aarch64-linux-android -### -c %s 2>&1 | FileCheck -check-prefix=FMV-DISABLED %s ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix Undefined Behavior introduced by #91199 (PR #91718)
https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/91718 We stacked allocated an OpaqueExpr that woukd be used after it was destroyed. >From fe25f0455d84ea3fd0d8dd988be6ae907f6661c2 Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Fri, 10 May 2024 10:55:20 +0200 Subject: [PATCH] [Clang] Fix Undefined Behavior introduced by #91199 We stacked allocated an OpaqueExpr that woukd be used after it was destroyed. --- clang/lib/Sema/SemaExprCXX.cpp | 17 + 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index ae844bc699143..1bd40a4b5db7e 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -5630,7 +5630,8 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, const TypeSourceInfo *Lhs, const TypeSourceInfo *Rhs, - SourceLocation KeyLoc) { + SourceLocation KeyLoc, + llvm::BumpPtrAllocator & OpaqueExprAllocator) { QualType LhsT = Lhs->getType(); QualType RhsT = Rhs->getType(); @@ -5675,9 +5676,9 @@ static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, // Build a fake source and destination for initialization. InitializedEntity To(InitializedEntity::InitializeTemporary(RhsT)); - OpaqueValueExpr From(KeyLoc, LhsT.getNonLValueExprType(Self.Context), + Expr* From = new (OpaqueExprAllocator.Allocate()) + OpaqueValueExpr(KeyLoc, LhsT.getNonLValueExprType(Self.Context), Expr::getValueKindForType(LhsT)); - Expr *FromPtr = &From; InitializationKind Kind = InitializationKind::CreateCopy(KeyLoc, SourceLocation()); @@ -5687,11 +5688,11 @@ static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, Self, Sema::ExpressionEvaluationContext::Unevaluated); Sema::SFINAETrap SFINAE(Self, /*AccessCheckingSFINAE=*/true); Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl()); - InitializationSequence Init(Self, To, Kind, FromPtr); + InitializationSequence Init(Self, To, Kind, From); if (Init.Failed()) return ExprError(); - ExprResult Result = Init.Perform(Self, To, Kind, FromPtr); + ExprResult Result = Init.Perform(Self, To, Kind, From); if (Result.isInvalid() || SFINAE.hasErrorOccurred()) return ExprError(); @@ -5819,7 +5820,7 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait Kind, S.Context.getPointerType(T.getNonReferenceType())); TypeSourceInfo *UPtr = S.Context.CreateTypeSourceInfo( S.Context.getPointerType(U.getNonReferenceType())); - return !CheckConvertibilityForTypeTraits(S, UPtr, TPtr, RParenLoc) + return !CheckConvertibilityForTypeTraits(S, UPtr, TPtr, RParenLoc, OpaqueExprAllocator) .isInvalid(); } @@ -6028,9 +6029,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI case BTT_IsNothrowConvertible: { if (RhsT->isVoidType()) return LhsT->isVoidType(); - +llvm::BumpPtrAllocator OpaqueExprAllocator; ExprResult Result = -CheckConvertibilityForTypeTraits(Self, Lhs, Rhs, KeyLoc); +CheckConvertibilityForTypeTraits(Self, Lhs, Rhs, KeyLoc, OpaqueExprAllocator); if (Result.isInvalid()) return false; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix Undefined Behavior introduced by #91199 (PR #91718)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/91718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix Undefined Behavior introduced by #91199 (PR #91718)
llvmbot wrote: @llvm/pr-subscribers-clang Author: cor3ntin (cor3ntin) Changes We stack allocated an OpaqueExpr that woukd be used after it was destroyed. --- Full diff: https://github.com/llvm/llvm-project/pull/91718.diff 1 Files Affected: - (modified) clang/lib/Sema/SemaExprCXX.cpp (+9-8) ``diff diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index ae844bc699143..1bd40a4b5db7e 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -5630,7 +5630,8 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, const TypeSourceInfo *Lhs, const TypeSourceInfo *Rhs, - SourceLocation KeyLoc) { + SourceLocation KeyLoc, + llvm::BumpPtrAllocator & OpaqueExprAllocator) { QualType LhsT = Lhs->getType(); QualType RhsT = Rhs->getType(); @@ -5675,9 +5676,9 @@ static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, // Build a fake source and destination for initialization. InitializedEntity To(InitializedEntity::InitializeTemporary(RhsT)); - OpaqueValueExpr From(KeyLoc, LhsT.getNonLValueExprType(Self.Context), + Expr* From = new (OpaqueExprAllocator.Allocate()) + OpaqueValueExpr(KeyLoc, LhsT.getNonLValueExprType(Self.Context), Expr::getValueKindForType(LhsT)); - Expr *FromPtr = &From; InitializationKind Kind = InitializationKind::CreateCopy(KeyLoc, SourceLocation()); @@ -5687,11 +5688,11 @@ static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, Self, Sema::ExpressionEvaluationContext::Unevaluated); Sema::SFINAETrap SFINAE(Self, /*AccessCheckingSFINAE=*/true); Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl()); - InitializationSequence Init(Self, To, Kind, FromPtr); + InitializationSequence Init(Self, To, Kind, From); if (Init.Failed()) return ExprError(); - ExprResult Result = Init.Perform(Self, To, Kind, FromPtr); + ExprResult Result = Init.Perform(Self, To, Kind, From); if (Result.isInvalid() || SFINAE.hasErrorOccurred()) return ExprError(); @@ -5819,7 +5820,7 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait Kind, S.Context.getPointerType(T.getNonReferenceType())); TypeSourceInfo *UPtr = S.Context.CreateTypeSourceInfo( S.Context.getPointerType(U.getNonReferenceType())); - return !CheckConvertibilityForTypeTraits(S, UPtr, TPtr, RParenLoc) + return !CheckConvertibilityForTypeTraits(S, UPtr, TPtr, RParenLoc, OpaqueExprAllocator) .isInvalid(); } @@ -6028,9 +6029,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI case BTT_IsNothrowConvertible: { if (RhsT->isVoidType()) return LhsT->isVoidType(); - +llvm::BumpPtrAllocator OpaqueExprAllocator; ExprResult Result = -CheckConvertibilityForTypeTraits(Self, Lhs, Rhs, KeyLoc); +CheckConvertibilityForTypeTraits(Self, Lhs, Rhs, KeyLoc, OpaqueExprAllocator); if (Result.isInvalid()) return false; `` https://github.com/llvm/llvm-project/pull/91718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix Undefined Behavior introduced by #91199 (PR #91718)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 5d24217c2c1c06358168cae65d3ff8632b28cd7d fe25f0455d84ea3fd0d8dd988be6ae907f6661c2 -- clang/lib/Sema/SemaExprCXX.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 1bd40a4b5d..c181092113 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -5627,11 +5627,9 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT, static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceInfo *Lhs, const TypeSourceInfo *Rhs, SourceLocation KeyLoc); -static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, - const TypeSourceInfo *Lhs, - const TypeSourceInfo *Rhs, - SourceLocation KeyLoc, - llvm::BumpPtrAllocator & OpaqueExprAllocator) { +static ExprResult CheckConvertibilityForTypeTraits( +Sema &Self, const TypeSourceInfo *Lhs, const TypeSourceInfo *Rhs, +SourceLocation KeyLoc, llvm::BumpPtrAllocator &OpaqueExprAllocator) { QualType LhsT = Lhs->getType(); QualType RhsT = Rhs->getType(); @@ -5676,9 +5674,9 @@ static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, // Build a fake source and destination for initialization. InitializedEntity To(InitializedEntity::InitializeTemporary(RhsT)); - Expr* From = new (OpaqueExprAllocator.Allocate()) - OpaqueValueExpr(KeyLoc, LhsT.getNonLValueExprType(Self.Context), - Expr::getValueKindForType(LhsT)); + Expr *From = new (OpaqueExprAllocator.Allocate()) + OpaqueValueExpr(KeyLoc, LhsT.getNonLValueExprType(Self.Context), + Expr::getValueKindForType(LhsT)); InitializationKind Kind = InitializationKind::CreateCopy(KeyLoc, SourceLocation()); @@ -5820,7 +5818,8 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait Kind, S.Context.getPointerType(T.getNonReferenceType())); TypeSourceInfo *UPtr = S.Context.CreateTypeSourceInfo( S.Context.getPointerType(U.getNonReferenceType())); - return !CheckConvertibilityForTypeTraits(S, UPtr, TPtr, RParenLoc, OpaqueExprAllocator) + return !CheckConvertibilityForTypeTraits(S, UPtr, TPtr, RParenLoc, + OpaqueExprAllocator) .isInvalid(); } @@ -6030,8 +6029,8 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI if (RhsT->isVoidType()) return LhsT->isVoidType(); llvm::BumpPtrAllocator OpaqueExprAllocator; -ExprResult Result = -CheckConvertibilityForTypeTraits(Self, Lhs, Rhs, KeyLoc, OpaqueExprAllocator); +ExprResult Result = CheckConvertibilityForTypeTraits(Self, Lhs, Rhs, KeyLoc, + OpaqueExprAllocator); if (Result.isInvalid()) return false; `` https://github.com/llvm/llvm-project/pull/91718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix Undefined Behavior introduced by #91199 (PR #91718)
https://github.com/Endilll approved this pull request. LGTM You should leave a link in the description to the buildbot failure you're addressing. https://github.com/llvm/llvm-project/pull/91718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix Undefined Behavior introduced by #91199 (PR #91718)
https://github.com/cor3ntin edited https://github.com/llvm/llvm-project/pull/91718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix Undefined Behavior introduced by #91199 (PR #91718)
https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/91718 >From fe25f0455d84ea3fd0d8dd988be6ae907f6661c2 Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Fri, 10 May 2024 10:55:20 +0200 Subject: [PATCH 1/2] [Clang] Fix Undefined Behavior introduced by #91199 We stacked allocated an OpaqueExpr that woukd be used after it was destroyed. --- clang/lib/Sema/SemaExprCXX.cpp | 17 + 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index ae844bc699143..1bd40a4b5db7e 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -5630,7 +5630,8 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, const TypeSourceInfo *Lhs, const TypeSourceInfo *Rhs, - SourceLocation KeyLoc) { + SourceLocation KeyLoc, + llvm::BumpPtrAllocator & OpaqueExprAllocator) { QualType LhsT = Lhs->getType(); QualType RhsT = Rhs->getType(); @@ -5675,9 +5676,9 @@ static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, // Build a fake source and destination for initialization. InitializedEntity To(InitializedEntity::InitializeTemporary(RhsT)); - OpaqueValueExpr From(KeyLoc, LhsT.getNonLValueExprType(Self.Context), + Expr* From = new (OpaqueExprAllocator.Allocate()) + OpaqueValueExpr(KeyLoc, LhsT.getNonLValueExprType(Self.Context), Expr::getValueKindForType(LhsT)); - Expr *FromPtr = &From; InitializationKind Kind = InitializationKind::CreateCopy(KeyLoc, SourceLocation()); @@ -5687,11 +5688,11 @@ static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, Self, Sema::ExpressionEvaluationContext::Unevaluated); Sema::SFINAETrap SFINAE(Self, /*AccessCheckingSFINAE=*/true); Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl()); - InitializationSequence Init(Self, To, Kind, FromPtr); + InitializationSequence Init(Self, To, Kind, From); if (Init.Failed()) return ExprError(); - ExprResult Result = Init.Perform(Self, To, Kind, FromPtr); + ExprResult Result = Init.Perform(Self, To, Kind, From); if (Result.isInvalid() || SFINAE.hasErrorOccurred()) return ExprError(); @@ -5819,7 +5820,7 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait Kind, S.Context.getPointerType(T.getNonReferenceType())); TypeSourceInfo *UPtr = S.Context.CreateTypeSourceInfo( S.Context.getPointerType(U.getNonReferenceType())); - return !CheckConvertibilityForTypeTraits(S, UPtr, TPtr, RParenLoc) + return !CheckConvertibilityForTypeTraits(S, UPtr, TPtr, RParenLoc, OpaqueExprAllocator) .isInvalid(); } @@ -6028,9 +6029,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI case BTT_IsNothrowConvertible: { if (RhsT->isVoidType()) return LhsT->isVoidType(); - +llvm::BumpPtrAllocator OpaqueExprAllocator; ExprResult Result = -CheckConvertibilityForTypeTraits(Self, Lhs, Rhs, KeyLoc); +CheckConvertibilityForTypeTraits(Self, Lhs, Rhs, KeyLoc, OpaqueExprAllocator); if (Result.isInvalid()) return false; >From 559084f20614cd8b4f716fab1f7b4a7ba58d3cde Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Fri, 10 May 2024 11:08:08 +0200 Subject: [PATCH 2/2] Format --- clang/lib/Sema/SemaExprCXX.cpp | 21 ++--- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 1bd40a4b5db7e..c181092113e1f 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -5627,11 +5627,9 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT, static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceInfo *Lhs, const TypeSourceInfo *Rhs, SourceLocation KeyLoc); -static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, - const TypeSourceInfo *Lhs, - const TypeSourceInfo *Rhs, - SourceLocation KeyLoc, - llvm::BumpPtrAllocator & OpaqueExprAllocator) { +static ExprResult CheckConvertibilityForTypeTraits( +Sema &Self, const TypeSourceInfo *Lhs, const TypeSourceInfo *Rhs, +SourceLocation KeyLoc, llvm::BumpPtrAllocator &OpaqueExprAllocator) { QualType LhsT = Lhs->getType(); QualType RhsT = Rhs->getType(); @@ -5676,9 +5674,9 @@ static ExprRes
[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder'. (PR #91445)
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/91445 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder'. (PR #91445)
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/91445 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix Undefined Behavior introduced by #91199 (PR #91718)
cor3ntin wrote: Merging that now to fix CI (hopefully) https://github.com/llvm/llvm-project/pull/91718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fc57f88 - [Clang] Fix Undefined Behavior introduced by #91199 (#91718)
Author: cor3ntin Date: 2024-05-10T11:15:26+02:00 New Revision: fc57f88f007497a4ead0ec8607ac66e1847b02d6 URL: https://github.com/llvm/llvm-project/commit/fc57f88f007497a4ead0ec8607ac66e1847b02d6 DIFF: https://github.com/llvm/llvm-project/commit/fc57f88f007497a4ead0ec8607ac66e1847b02d6.diff LOG: [Clang] Fix Undefined Behavior introduced by #91199 (#91718) We stack allocated an OpaqueExpr that would be used after it was destroyed. e.g https://lab.llvm.org/buildbot/#/builders/57/builds/34909 Added: Modified: clang/lib/Sema/SemaExprCXX.cpp Removed: diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index ae844bc699143..c181092113e1f 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -5627,10 +5627,9 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT, static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceInfo *Lhs, const TypeSourceInfo *Rhs, SourceLocation KeyLoc); -static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, - const TypeSourceInfo *Lhs, - const TypeSourceInfo *Rhs, - SourceLocation KeyLoc) { +static ExprResult CheckConvertibilityForTypeTraits( +Sema &Self, const TypeSourceInfo *Lhs, const TypeSourceInfo *Rhs, +SourceLocation KeyLoc, llvm::BumpPtrAllocator &OpaqueExprAllocator) { QualType LhsT = Lhs->getType(); QualType RhsT = Rhs->getType(); @@ -5675,9 +5674,9 @@ static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, // Build a fake source and destination for initialization. InitializedEntity To(InitializedEntity::InitializeTemporary(RhsT)); - OpaqueValueExpr From(KeyLoc, LhsT.getNonLValueExprType(Self.Context), - Expr::getValueKindForType(LhsT)); - Expr *FromPtr = &From; + Expr *From = new (OpaqueExprAllocator.Allocate()) + OpaqueValueExpr(KeyLoc, LhsT.getNonLValueExprType(Self.Context), + Expr::getValueKindForType(LhsT)); InitializationKind Kind = InitializationKind::CreateCopy(KeyLoc, SourceLocation()); @@ -5687,11 +5686,11 @@ static ExprResult CheckConvertibilityForTypeTraits(Sema &Self, Self, Sema::ExpressionEvaluationContext::Unevaluated); Sema::SFINAETrap SFINAE(Self, /*AccessCheckingSFINAE=*/true); Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl()); - InitializationSequence Init(Self, To, Kind, FromPtr); + InitializationSequence Init(Self, To, Kind, From); if (Init.Failed()) return ExprError(); - ExprResult Result = Init.Perform(Self, To, Kind, FromPtr); + ExprResult Result = Init.Perform(Self, To, Kind, From); if (Result.isInvalid() || SFINAE.hasErrorOccurred()) return ExprError(); @@ -5819,7 +5818,8 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait Kind, S.Context.getPointerType(T.getNonReferenceType())); TypeSourceInfo *UPtr = S.Context.CreateTypeSourceInfo( S.Context.getPointerType(U.getNonReferenceType())); - return !CheckConvertibilityForTypeTraits(S, UPtr, TPtr, RParenLoc) + return !CheckConvertibilityForTypeTraits(S, UPtr, TPtr, RParenLoc, + OpaqueExprAllocator) .isInvalid(); } @@ -6028,9 +6028,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI case BTT_IsNothrowConvertible: { if (RhsT->isVoidType()) return LhsT->isVoidType(); - -ExprResult Result = -CheckConvertibilityForTypeTraits(Self, Lhs, Rhs, KeyLoc); +llvm::BumpPtrAllocator OpaqueExprAllocator; +ExprResult Result = CheckConvertibilityForTypeTraits(Self, Lhs, Rhs, KeyLoc, + OpaqueExprAllocator); if (Result.isInvalid()) return false; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix Undefined Behavior introduced by #91199 (PR #91718)
https://github.com/cor3ntin closed https://github.com/llvm/llvm-project/pull/91718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder'. (PR #91445)
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/91445 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder'. (PR #91445)
@@ -0,0 +1,196 @@ +//===-- SetgidSetuidOrderChecker.cpp - check privilege revocation calls ---===// +// +// 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 a checker to detect possible reversed order of privilege +// revocations when 'setgid' and 'setuid' is used. +// +//===--===// + +#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" +#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" +#include "clang/StaticAnalyzer/Core/Checker.h" +#include "clang/StaticAnalyzer/Core/CheckerManager.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h" + +using namespace clang; +using namespace ento; + +namespace { + +class SetgidSetuidOrderChecker +: public Checker { + const BugType BT_WrongRevocationOrder{ + this, "Possible wrong order of privilege revocation"}; + + const CallDescription SetuidDesc{{"setuid"}, 1}; + const CallDescription SetgidDesc{{"setgid"}, 1}; NagyDonat wrote: ```suggestion const CallDescription SetuidDesc{CDM::CLibrary, {"setuid"}, 1}; const CallDescription SetgidDesc{CDM::CLibrary, {"setgid"}, 1}; ``` https://github.com/llvm/llvm-project/pull/91445 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder'. (PR #91445)
https://github.com/NagyDonat commented: You forgot to add `CDM::CLibrary` in the definition of `SetuidDesc` and `SetgidDesc` (see the new inline comment). There are also several inline comments from my previous review where I'm expecting an answer (not necessarily a code change -- in each case I can accept the current solution if you would prefer it). https://github.com/llvm/llvm-project/pull/91445 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add checker 'security.SetgidSetuidOrder'. (PR #91445)
@@ -0,0 +1,197 @@ +//===-- SetgidSetuidOrderChecker.cpp - check privilege revocation calls ---===// +// +// 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 a checker to detect possible reversed order of privilege +// revocations when 'setgid' and 'setuid' is used. +// +//===--===// + +#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" +#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" +#include "clang/StaticAnalyzer/Core/Checker.h" +#include "clang/StaticAnalyzer/Core/CheckerManager.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h" + +using namespace clang; +using namespace ento; + +namespace { + +class SetgidSetuidOrderChecker +: public Checker { + const BugType BT_WrongRevocationOrder{ + this, "Possible wrong order of privilege revocation"}; + + const CallDescription SetuidDesc{{"setuid"}, 1}; + const CallDescription SetgidDesc{{"setgid"}, 1}; + const CallDescription SeteuidDesc{{"seteuid"}, 1}; + const CallDescription SetegidDesc{{"setegid"}, 1}; + const CallDescription SetreuidDesc{{"setreuid"}, 2}; + const CallDescription SetregidDesc{{"setregid"}, 2}; + const CallDescription SetresuidDesc{{"setresuid"}, 3}; + const CallDescription SetresgidDesc{{"setresgid"}, 3}; + +public: + SetgidSetuidOrderChecker() {} + + void checkPostCall(const CallEvent &Call, CheckerContext &C) const; + void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const; + ProgramStateRef evalAssume(ProgramStateRef State, SVal Cond, + bool Assumption) const; + +private: + ProgramStateRef processSetuid(ProgramStateRef State, const CallEvent &Call, +CheckerContext &C) const; + ProgramStateRef processSetgid(ProgramStateRef State, const CallEvent &Call, +CheckerContext &C) const; + ProgramStateRef processOther(ProgramStateRef State, const CallEvent &Call, + CheckerContext &C) const; + /// Check if a function like \c getuid or \c getgid is called directly from + /// the first argument of function called from \a Call. + bool isFunctionCalledInArg(llvm::StringRef FnName, + const CallEvent &Call) const; + void emitReport(ProgramStateRef State, CheckerContext &C) const; +}; + +enum SetPrivilegeFunctionKind { Irrelevant, Setuid, Setgid }; + +} // end anonymous namespace + +/// Store if there was a call to 'setuid(getuid())' or 'setgid(getgid())' not +/// followed by other different privilege-change functions. +/// If the value \c Setuid is stored and a 'setgid(getgid())' call is found we +/// have found the bug to be reported. Value \c Setgid is used too to prevent +/// warnings at a setgid-setuid-setgid sequence. +REGISTER_TRAIT_WITH_PROGRAMSTATE(LastSetPrivilegeCall, SetPrivilegeFunctionKind) +/// Store the symbol value of the last 'setuid(getuid())' call. This is used to +/// detect if the result is compared to -1 and avoid warnings on that branch +/// (which is the failure branch of the call). +REGISTER_TRAIT_WITH_PROGRAMSTATE(LastSetuidCallSVal, SymbolRef) + +void SetgidSetuidOrderChecker::checkPostCall(const CallEvent &Call, + CheckerContext &C) const { + ProgramStateRef State = C.getState(); + if (SetuidDesc.matches(Call)) { +State = processSetuid(State, Call, C); + } else if (SetgidDesc.matches(Call)) { +State = processSetgid(State, Call, C); + } else if (matchesAny(Call, SeteuidDesc, SetegidDesc, SetreuidDesc, +SetregidDesc, SetresuidDesc, SetresgidDesc)) { +State = processOther(State, Call, C); + } + if (State) +C.addTransition(State); +} + +void SetgidSetuidOrderChecker::checkDeadSymbols(SymbolReaper &SymReaper, +CheckerContext &C) const { + ProgramStateRef State = C.getState(); + + SymbolRef LastSetuidSym = State->get(); + if (!LastSetuidSym) +return; + + if (!SymReaper.isDead(LastSetuidSym)) +return; + + State = State->set(SymbolRef{}); + C.addTransition(State, C.getPredecessor()); +} + +ProgramStateRef SetgidSetuidOrderChecker::evalAssume(ProgramStateRef State, + SVal Cond, + bool Assumption) const { NagyDonat
[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/91531 From 07dc4dd5c60c8a04637cce686b379e195deb5b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Wed, 8 May 2024 20:01:57 +0200 Subject: [PATCH 1/2] [analyzer] Refactor recognition of the errno getter functions There are many environments where `errno` is a macro that expands to something like `(*__errno())` (different standard library implementations use different names instead of "__errno"). In these environments the ErrnoModeling checker creates a symbolic region which will be used to represent the return value of this "get the location of errno" function. Previously this symbol was only created when the checker was able to find the declaration of the "get the location of errno" function; but this commit eliminates the complex logic that was responsible for this and always creates the symbolic region when `errno` is not available as a "regular" global variable. This significantly simplifies a code and only introduces a minimal performance reduction (one extra symbol) in the unlikely case when `errno` is not declared (neither as a variable nor as a function), but the `ErrnoModeling` checker is enabled. In addition to this simplification, this commit specifies that the `CallDescription`s for the "get the location of errno" functions are matched in `CDM::CLibrary` mode. (This was my original goal, but I was sidetracked by resolving a FIXME above the `CallDescriptionSet` in `ErrnoModeling.cpp`.) This change is very close to being NFC, but it fixes weird corner cases like the handling of a C++ method that happens to be named "__errno()" (previously it could've been recognized as an errno location getter function). --- .../StaticAnalyzer/Checkers/ErrnoChecker.cpp | 2 +- .../StaticAnalyzer/Checkers/ErrnoModeling.cpp | 127 ++ .../StaticAnalyzer/Checkers/ErrnoModeling.h | 9 +- clang/test/Analysis/memory-model.cpp | 18 +-- 4 files changed, 53 insertions(+), 103 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp index 18e718e085536..72fd6781a7561 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp @@ -205,7 +205,7 @@ void ErrnoChecker::checkPreCall(const CallEvent &Call, // Probably 'strerror'? if (CallF->isExternC() && CallF->isGlobal() && C.getSourceManager().isInSystemHeader(CallF->getLocation()) && - !isErrno(CallF)) { + !isErrnoLocationCall(Call)) { if (getErrnoState(C.getState()) == MustBeChecked) { std::optional ErrnoLoc = getErrnoLoc(C.getState()); assert(ErrnoLoc && "ErrnoLoc should exist if an errno state is set."); diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp index 1b34ea0e056e5..0612cd4c87248 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp @@ -39,10 +39,15 @@ namespace { // Name of the "errno" variable. // FIXME: Is there a system where it is not called "errno" but is a variable? const char *ErrnoVarName = "errno"; + // Names of functions that return a location of the "errno" value. // FIXME: Are there other similar function names? -const char *ErrnoLocationFuncNames[] = {"__errno_location", "___errno", -"__errno", "_errno", "__error"}; +CallDescriptionSet ErrnoLocationCalls{ +{CDM::SimpleFunc, {"__errno_location"}, 0, 0}, +{CDM::SimpleFunc, {"___errno"}, 0, 0}, +{CDM::SimpleFunc, {"__errno"}, 0, 0}, +{CDM::SimpleFunc, {"_errno"}, 0, 0}, +{CDM::SimpleFunc, {"__error"}, 0, 0}}; class ErrnoModeling : public Checker, check::BeginFunction, @@ -54,16 +59,10 @@ class ErrnoModeling void checkLiveSymbols(ProgramStateRef State, SymbolReaper &SR) const; bool evalCall(const CallEvent &Call, CheckerContext &C) const; - // The declaration of an "errno" variable or "errno location" function. - mutable const Decl *ErrnoDecl = nullptr; - private: - // FIXME: Names from `ErrnoLocationFuncNames` are used to build this set. - CallDescriptionSet ErrnoLocationCalls{{{"__errno_location"}, 0, 0}, -{{"___errno"}, 0, 0}, -{{"__errno"}, 0, 0}, -{{"_errno"}, 0, 0}, -{{"__error"}, 0, 0}}; + // The declaration of an "errno" variable on systems where errno is + // represented by a variable (and not a function that queries its location). + mutable const Decl *ErrnoDecl = nullptr; }; } // namespace @@ -74,9 +73,13 @@ REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoRegion, const MemRegion *) REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoState, errno_modeling::ErrnoCheckState) -/// Search for a variable called "errno
[clang] [llvm] [AArch64] Add intrinsics for bfloat16 min/max/minnm/maxnm (PR #90105)
https://github.com/momchil-velikov commented: LGTM, cheers! https://github.com/llvm/llvm-project/pull/90105 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)
@@ -39,10 +39,15 @@ namespace { // Name of the "errno" variable. // FIXME: Is there a system where it is not called "errno" but is a variable? const char *ErrnoVarName = "errno"; + // Names of functions that return a location of the "errno" value. // FIXME: Are there other similar function names? -const char *ErrnoLocationFuncNames[] = {"__errno_location", "___errno", -"__errno", "_errno", "__error"}; +CallDescriptionSet ErrnoLocationCalls{ +{CDM::SimpleFunc, {"__errno_location"}, 0, 0}, +{CDM::SimpleFunc, {"___errno"}, 0, 0}, +{CDM::SimpleFunc, {"__errno"}, 0, 0}, +{CDM::SimpleFunc, {"_errno"}, 0, 0}, +{CDM::SimpleFunc, {"__error"}, 0, 0}}; NagyDonat wrote: I updated them to `CLibrary` because it's slightly better for this usecase (it won't match functions within a user-defined C++ namespace). By the way, note that the `CLibrary` matching mode intentionally **doesn't check whether the function was declared within a system header**, because "being in a system header" is a very fragile property -- consider e.g. a case when somebody tries to submit a preprocessed source file for bug reproduction and the declaration becomes part of the (tweaked, minified) source file. I also suspect that there might be some unusual/internal functions (like these ones) whose declaration has no location, so it isn't in a system header... https://github.com/llvm/llvm-project/pull/91531 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)
@@ -54,16 +59,10 @@ class ErrnoModeling void checkLiveSymbols(ProgramStateRef State, SymbolReaper &SR) const; bool evalCall(const CallEvent &Call, CheckerContext &C) const; - // The declaration of an "errno" variable or "errno location" function. - mutable const Decl *ErrnoDecl = nullptr; - private: - // FIXME: Names from `ErrnoLocationFuncNames` are used to build this set. - CallDescriptionSet ErrnoLocationCalls{{{"__errno_location"}, 0, 0}, -{{"___errno"}, 0, 0}, -{{"__errno"}, 0, 0}, -{{"_errno"}, 0, 0}, -{{"__error"}, 0, 0}}; + // The declaration of an "errno" variable on systems where errno is + // represented by a variable (and not a function that queries its location). + mutable const Decl *ErrnoDecl = nullptr; NagyDonat wrote: Good point! https://github.com/llvm/llvm-project/pull/91531 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)
NagyDonat wrote: Thanks for the review, I updated my commit! https://github.com/llvm/llvm-project/pull/91531 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)
@@ -71,12 +71,9 @@ ProgramStateRef setErrnoState(ProgramStateRef State, ErrnoCheckState EState); /// Clear state of errno (make it irrelevant). ProgramStateRef clearErrnoState(ProgramStateRef State); -/// Determine if a `Decl` node related to 'errno'. -/// This is true if the declaration is the errno variable or a function -/// that returns a pointer to the 'errno' value (usually the 'errno' macro is -/// defined with this function). \p D is not required to be a canonical -/// declaration. -bool isErrno(const Decl *D); +/// Determine if `Call` is a call to a "magical" function that returns the +/// location of `errno` (in environments where errno is accessed this way). +bool isErrnoLocationCall(const CallEvent &Call); NagyDonat wrote: Yes, I see that `isErrno` was intended for a different behavior; but its variable declaration handling "side" became unused, so I deleted that and modified the remaining function-handling case to accept a call instead of a declaration. https://github.com/llvm/llvm-project/pull/91531 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add support for [[msvc::noinline]] attribute. (PR #91720)
https://github.com/simonzgx created https://github.com/llvm/llvm-project/pull/91720 None >From d0cde98f5e933c6f88703a55986f6cc508721fdc Mon Sep 17 00:00:00 2001 From: Xu Zhang Date: Fri, 10 May 2024 01:24:24 +0800 Subject: [PATCH 1/2] [Clang] Add support for [[msvc::noinline]] attribute. (#90941) --- clang/include/clang/Basic/Attr.td | 5 - clang/include/clang/Basic/AttrDocs.td | 2 ++ clang/test/CodeGen/attr-ms-noinline.cpp | 0 clang/test/Sema/attr-ms-noinline.cpp| 0 4 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGen/attr-ms-noinline.cpp create mode 100644 clang/test/Sema/attr-ms-noinline.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 0225598cbbe8a..2c7a238f61764 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1997,9 +1997,12 @@ def Convergent : InheritableAttr { def NoInline : DeclOrStmtAttr { let Spellings = [CustomKeyword<"__noinline__">, GCC<"noinline">, CXX11<"clang", "noinline">, C23<"clang", "noinline">, + CXX11<"msvc", "noinline">, C23<"msvc", "noinline">, Declspec<"noinline">]; let Accessors = [Accessor<"isClangNoInline", [CXX11<"clang", "noinline">, -C23<"clang", "noinline">]>]; +C23<"clang", "noinline">, +CXX11<"msvc", "noinline">, +C23<"msvc", "noinline">]>]; let Documentation = [NoInlineDocs]; let Subjects = SubjectList<[Function, Stmt], WarnDiag, "functions and statements">; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 8e6faabfae647..0ef636f716be5 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -597,6 +597,8 @@ spellings of the attribute are not supported on statements. If a statement is marked ``[[clang::noinline]]`` and contains calls, those calls inside the statement will not be inlined by the compiler. +``[[msvc::noinline]]`` + ``__noinline__`` can be used as a keyword in CUDA/HIP languages. This is to avoid diagnostics due to usage of ``__attribute__((__noinline__))`` with ``__noinline__`` defined as a macro as ``__attribute__((noinline))``. diff --git a/clang/test/CodeGen/attr-ms-noinline.cpp b/clang/test/CodeGen/attr-ms-noinline.cpp new file mode 100644 index 0..e69de29bb2d1d diff --git a/clang/test/Sema/attr-ms-noinline.cpp b/clang/test/Sema/attr-ms-noinline.cpp new file mode 100644 index 0..e69de29bb2d1d >From 1d7973be6024c2fef083960cb2602e95d91985d8 Mon Sep 17 00:00:00 2001 From: Xu Zhang Date: Fri, 10 May 2024 17:43:33 +0800 Subject: [PATCH 2/2] add unit test --- clang/include/clang/Basic/AttrDocs.td | 2 - clang/test/CodeGen/attr-ms-noinline.cpp | 53 clang/test/Sema/attr-ms-noinline.cpp| 66 + 3 files changed, 119 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 0ef636f716be5..8e6faabfae647 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -597,8 +597,6 @@ spellings of the attribute are not supported on statements. If a statement is marked ``[[clang::noinline]]`` and contains calls, those calls inside the statement will not be inlined by the compiler. -``[[msvc::noinline]]`` - ``__noinline__`` can be used as a keyword in CUDA/HIP languages. This is to avoid diagnostics due to usage of ``__attribute__((__noinline__))`` with ``__noinline__`` defined as a macro as ``__attribute__((noinline))``. diff --git a/clang/test/CodeGen/attr-ms-noinline.cpp b/clang/test/CodeGen/attr-ms-noinline.cpp index e69de29bb2d1d..99b0a05af715d 100644 --- a/clang/test/CodeGen/attr-ms-noinline.cpp +++ b/clang/test/CodeGen/attr-ms-noinline.cpp @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | FileCheck %s + +bool bar(); +void f(bool, bool); +void g(bool); + +static int baz(int x) { +return x * 10; +} + +[[msvc::noinline]] bool noi() { } + +void foo(int i) { + [[msvc::noinline]] bar(); +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR:[0-9]+]] + [[msvc::noinline]] i = baz(i); +// CHECK: call noundef i32 @_ZL3bazi({{.*}}) #[[NOINLINEATTR]] + [[msvc::noinline]] (i = 4, bar()); +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] + [[msvc::noinline]] (void)(bar()); +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] + [[msvc::noinline]] f(bar(), bar()); +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] +// CHECK: call void @_Z1fbb({{.*}}) #[[NOINLINEATTR]] + [[msvc::noinline]] [] { ba
[clang] [Clang] Add support for [[msvc::noinline]] attribute. (PR #91720)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Xu Zhang (simonzgx) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/91720.diff 3 Files Affected: - (modified) clang/include/clang/Basic/Attr.td (+4-1) - (added) clang/test/CodeGen/attr-ms-noinline.cpp (+53) - (added) clang/test/Sema/attr-ms-noinline.cpp (+66) ``diff diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 0225598cbbe8a..2c7a238f61764 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1997,9 +1997,12 @@ def Convergent : InheritableAttr { def NoInline : DeclOrStmtAttr { let Spellings = [CustomKeyword<"__noinline__">, GCC<"noinline">, CXX11<"clang", "noinline">, C23<"clang", "noinline">, + CXX11<"msvc", "noinline">, C23<"msvc", "noinline">, Declspec<"noinline">]; let Accessors = [Accessor<"isClangNoInline", [CXX11<"clang", "noinline">, -C23<"clang", "noinline">]>]; +C23<"clang", "noinline">, +CXX11<"msvc", "noinline">, +C23<"msvc", "noinline">]>]; let Documentation = [NoInlineDocs]; let Subjects = SubjectList<[Function, Stmt], WarnDiag, "functions and statements">; diff --git a/clang/test/CodeGen/attr-ms-noinline.cpp b/clang/test/CodeGen/attr-ms-noinline.cpp new file mode 100644 index 0..99b0a05af715d --- /dev/null +++ b/clang/test/CodeGen/attr-ms-noinline.cpp @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | FileCheck %s + +bool bar(); +void f(bool, bool); +void g(bool); + +static int baz(int x) { +return x * 10; +} + +[[msvc::noinline]] bool noi() { } + +void foo(int i) { + [[msvc::noinline]] bar(); +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR:[0-9]+]] + [[msvc::noinline]] i = baz(i); +// CHECK: call noundef i32 @_ZL3bazi({{.*}}) #[[NOINLINEATTR]] + [[msvc::noinline]] (i = 4, bar()); +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] + [[msvc::noinline]] (void)(bar()); +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] + [[msvc::noinline]] f(bar(), bar()); +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] +// CHECK: call void @_Z1fbb({{.*}}) #[[NOINLINEATTR]] + [[msvc::noinline]] [] { bar(); bar(); }(); // noinline only applies to the anonymous function call +// CHECK: call void @"_ZZ3fooiENK3$_0clEv"(ptr {{[^,]*}} %ref.tmp) #[[NOINLINEATTR]] + [[msvc::noinline]] for (bar(); bar(); bar()) {} +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] + bar(); +// CHECK: call noundef zeroext i1 @_Z3barv() + [[msvc::noinline]] noi(); +// CHECK: call noundef zeroext i1 @_Z3noiv() + noi(); +// CHECK: call noundef zeroext i1 @_Z3noiv() +} + +struct S { + friend bool operator==(const S &LHS, const S &RHS); +}; + +void func(const S &s1, const S &s2) { + [[msvc::noinline]]g(s1 == s2); +// CHECK: call noundef zeroext i1 @_ZeqRK1SS1_({{.*}}) #[[NOINLINEATTR]] +// CHECK: call void @_Z1gb({{.*}}) #[[NOINLINEATTR]] + bool b; + [[msvc::noinline]] b = s1 == s2; +// CHECK: call noundef zeroext i1 @_ZeqRK1SS1_({{.*}}) #[[NOINLINEATTR]] +} + +// CHECK: attributes #[[NOINLINEATTR]] = { noinline } diff --git a/clang/test/Sema/attr-ms-noinline.cpp b/clang/test/Sema/attr-ms-noinline.cpp new file mode 100644 index 0..292d34a41e411 --- /dev/null +++ b/clang/test/Sema/attr-ms-noinline.cpp @@ -0,0 +1,66 @@ +// RUN: %clang_cc1 -verify -fsyntax-only %s -Wno-c++17-extensions + +int bar(); + +void foo() { + [[msvc::noinline]] bar(); + [[msvc::noinline(0)]] bar(); // expected-error {{'noinline' attribute takes no arguments}} + int x; + [[msvc::noinline]] x = 0; // expected-warning {{'noinline' attribute is ignored because there exists no call expression inside the statement}} + [[msvc::noinline]] { asm("nop"); } // expected-warning {{'noinline' attribute is ignored because there exists no call expression inside the statement}} + [[msvc::noinline]] label: x = 1; // expected-warning {{'noinline' attribute only applies to functions and statements}} + + + [[msvc::noinline]] always_inline_fn(); // expected-warning {{statement attribute 'noinline' has higher precedence than function attribute 'always_inline'}} + [[msvc::noinline]] flatten_fn(); // expected-warning {{statement attribute 'noinline' has higher precedence than function attribute 'flatten'}} + [[msvc::noinline]] noinline_fn(); +} + +[[msvc::noinline]] static int i = bar(); // expected-warning {{'noinline' attribute only applies to functions and statements}} + +/
[clang] [Clang] Add support for [[msvc::noinline]] attribute. (PR #91720)
https://github.com/simonzgx converted_to_draft https://github.com/llvm/llvm-project/pull/91720 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add support for [[msvc::noinline]] attribute. (PR #91720)
https://github.com/simonzgx updated https://github.com/llvm/llvm-project/pull/91720 >From d0cde98f5e933c6f88703a55986f6cc508721fdc Mon Sep 17 00:00:00 2001 From: Xu Zhang Date: Fri, 10 May 2024 01:24:24 +0800 Subject: [PATCH 1/2] [Clang] Add support for [[msvc::noinline]] attribute. (#90941) --- clang/include/clang/Basic/Attr.td | 5 - clang/include/clang/Basic/AttrDocs.td | 2 ++ clang/test/CodeGen/attr-ms-noinline.cpp | 0 clang/test/Sema/attr-ms-noinline.cpp| 0 4 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGen/attr-ms-noinline.cpp create mode 100644 clang/test/Sema/attr-ms-noinline.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 0225598cbbe8a..2c7a238f61764 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1997,9 +1997,12 @@ def Convergent : InheritableAttr { def NoInline : DeclOrStmtAttr { let Spellings = [CustomKeyword<"__noinline__">, GCC<"noinline">, CXX11<"clang", "noinline">, C23<"clang", "noinline">, + CXX11<"msvc", "noinline">, C23<"msvc", "noinline">, Declspec<"noinline">]; let Accessors = [Accessor<"isClangNoInline", [CXX11<"clang", "noinline">, -C23<"clang", "noinline">]>]; +C23<"clang", "noinline">, +CXX11<"msvc", "noinline">, +C23<"msvc", "noinline">]>]; let Documentation = [NoInlineDocs]; let Subjects = SubjectList<[Function, Stmt], WarnDiag, "functions and statements">; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 8e6faabfae647..0ef636f716be5 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -597,6 +597,8 @@ spellings of the attribute are not supported on statements. If a statement is marked ``[[clang::noinline]]`` and contains calls, those calls inside the statement will not be inlined by the compiler. +``[[msvc::noinline]]`` + ``__noinline__`` can be used as a keyword in CUDA/HIP languages. This is to avoid diagnostics due to usage of ``__attribute__((__noinline__))`` with ``__noinline__`` defined as a macro as ``__attribute__((noinline))``. diff --git a/clang/test/CodeGen/attr-ms-noinline.cpp b/clang/test/CodeGen/attr-ms-noinline.cpp new file mode 100644 index 0..e69de29bb2d1d diff --git a/clang/test/Sema/attr-ms-noinline.cpp b/clang/test/Sema/attr-ms-noinline.cpp new file mode 100644 index 0..e69de29bb2d1d >From e17ba55102457f2d37bdea9adb49b47edddad115 Mon Sep 17 00:00:00 2001 From: Xu Zhang Date: Fri, 10 May 2024 17:46:40 +0800 Subject: [PATCH 2/2] add unit test --- clang/include/clang/Basic/AttrDocs.td | 2 - clang/test/CodeGen/attr-ms-noinline.cpp | 53 clang/test/Sema/attr-ms-noinline.cpp| 66 + 3 files changed, 119 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 0ef636f716be5..8e6faabfae647 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -597,8 +597,6 @@ spellings of the attribute are not supported on statements. If a statement is marked ``[[clang::noinline]]`` and contains calls, those calls inside the statement will not be inlined by the compiler. -``[[msvc::noinline]]`` - ``__noinline__`` can be used as a keyword in CUDA/HIP languages. This is to avoid diagnostics due to usage of ``__attribute__((__noinline__))`` with ``__noinline__`` defined as a macro as ``__attribute__((noinline))``. diff --git a/clang/test/CodeGen/attr-ms-noinline.cpp b/clang/test/CodeGen/attr-ms-noinline.cpp index e69de29bb2d1d..99b0a05af715d 100644 --- a/clang/test/CodeGen/attr-ms-noinline.cpp +++ b/clang/test/CodeGen/attr-ms-noinline.cpp @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | FileCheck %s + +bool bar(); +void f(bool, bool); +void g(bool); + +static int baz(int x) { +return x * 10; +} + +[[msvc::noinline]] bool noi() { } + +void foo(int i) { + [[msvc::noinline]] bar(); +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR:[0-9]+]] + [[msvc::noinline]] i = baz(i); +// CHECK: call noundef i32 @_ZL3bazi({{.*}}) #[[NOINLINEATTR]] + [[msvc::noinline]] (i = 4, bar()); +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] + [[msvc::noinline]] (void)(bar()); +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] + [[msvc::noinline]] f(bar(), bar()); +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] +// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]] +// CHECK: call void @_Z1fbb({{.*}}) #[[NOINLINEATTR]] + [[msvc::noinline]] [] { bar(); b
[clang] [llvm] [AArch64] Add intrinsics for 16-bit non-widening FMLA/FMLS (PR #88553)
https://github.com/momchil-velikov closed https://github.com/llvm/llvm-project/pull/88553 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)
https://github.com/mydeveloperday approved this pull request. I think this will stop people introducing extra arguments to function ...isCpp,isThis,isThat) LGTM https://github.com/llvm/llvm-project/pull/91712 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RemoveDIs] Print IR with debug records by default (PR #91724)
llvmbot wrote: @llvm/pr-subscribers-debuginfo Author: Stephen Tozer (SLTozer) Changes This patch makes the final major change of the RemoveDIs project, changing the default IR output from debug intrinsics to debug records. This is expected to break a large number of tests: every single one that tests for uses or declarations of debug intrinsics and does not explicitly disable writing records. There is also some collateral damage for tests that merely *contains* debug intrinsic declarations and test for attributes, as debug intrinsic declarations will now be deleted when writing debug records which may result in renumbering of other attributes. ### Review guidance This patch is divided into distinct sections, in the following order and comprising the following commits: 1. NFC manual test updates in preparation for the automated test updates. - Pre-script fixups 2. The functional change of the patch, which enables the printing of debug records by default. - Print debug records by default 3. The automated test updates, which comprise the vast majority of changes in this patch. - update_test_checks.py - update_cc_test_checks.py - substitute-checks.sh 4. Further manual test updates to fix up test errors that cannot be fixed by (or are caused by) the automated test updates. - Manual fixups post-update_test_checks My recommendation is to review individual commits rather than the patch as a whole, due to the extreme size of the automated updates. The manual changes made in this patch comprise a diff of size `+48, -45`, roughly 0.7% of the diff size of the complete patch. Instead of reviewing the automated test updates, I would instead recommend reviewing the "Update script details" section below, which explains the automated update process and gives exact steps to reproduce my results. ### Update script details For the most part, replacing debug intrinsics with debug records is trivial string substitution; replacing FileCheck CHECK lines for debug intrinsics is a slightly more complicated string substitution. For tests that use update_test_checks.py, updating the tests is entirely automatic, but for the many debug info tests that do not use update_test_checks.py I've used a less "smart" approach. The steps to produce the test updates are as follow: 1. Collect the list of failing lit tests into a single file, `failing-tests.txt`, separated by (and ending with) newlines. 2. Use the following line to split the failing tests into tests that use update_test_checks and tests that don't: ``` $ while IFS= read -r f; do grep -q "Assertions have been autogenerated by" "$f" && echo "$f" >> update-checks-tests.txt || echo "$f" >> manual-tests.txt; done < failing-tests.txt ``` 3. For the tests that use update_test_checks, run the appropriate update_test_checks script - for the updates run here, this was achieved with: ``` $ xargs ./llvm/utils/update_test_checks.py --opt-binary ./build/bin/opt < update-checks-tests.txt $ xargs ./llvm/utils/update_cc_test_checks.py --llvm-bin ./build/bin/ < update-checks-tests.txt ``` 4. For the manual tests, I used a pair of short scripts to perform the updates. The first script is used to fetch the check prefixes in each of the failing tests: ``` $ cat ./get-checks.sh #!/bin/bash # Always add CHECK, since it's more effort than it's worth to filter files where # every RUN line uses other check prefixes. # Then detect every instance of "check-prefix(es)=..." and add the # comma-separated arguments as extra checks. for filename in "$@" do echo "$filename,CHECK" allchecks=$(grep -Eo 'check-prefix(es)?[ =][A-Z0-9_,-]+' $filename | sed -E 's/.+[= ]([A-Z0-9_,-]+).*/\1/g; s/,/\n/g') for check in $allchecks; do echo "$filename,$check" done done ``` The second script performs the work of actually updating the check-lines in each of the failing tests, with a series of simple substitution patterns: ``` $ cat ./substitute-checks.sh #!/bin/bash file="$1" check="$2" # Any test that explicitly tests debug intrinsic output is not suitable to # update by this script. if grep -q "write-experimental-debuginfo=false" "$file"; then exit 0 fi sed -i -E -e " /(#|;|\/\/).*$check[A-Z0-9_\-]*:/!b /DIGlobalVariableExpression/b /!llvm.dbg./bpostcall s/((no|must)?tail )?call.*)?void )?@)?llvm.)?dbg\.([a-z]+)/#dbg_\7/ :postcall /declare #dbg_/d s/metadata //g s/metadata\{/{/g s/DIExpression\(([^)]*)\)\)(,( !dbg)?)?/DIExpression(\1),/ /#dbg_/!b s/((\))?(,) )?!dbg (![0-9]+)/\3\4\2/ s/((\))?(, ))?!dbg/\3/ " "$file" ``` Both of these scripts combined can be used on the list in `manual-tests.txt` as follows: ``` $ cat manual-tests.txt | xargs ./get-checks.sh | sort | uniq | awk -F ',' '{ system("./substitute-ch
[clang] 2371a64 - [AArch64] Add intrinsics for non-widening FMOPA/FMOPS (#88105)
Author: Momchil Velikov Date: 2024-05-10T11:57:08+01:00 New Revision: 2371a6410dd83e82862e1c4dce1f7411efbe6b1c URL: https://github.com/llvm/llvm-project/commit/2371a6410dd83e82862e1c4dce1f7411efbe6b1c DIFF: https://github.com/llvm/llvm-project/commit/2371a6410dd83e82862e1c4dce1f7411efbe6b1c.diff LOG: [AArch64] Add intrinsics for non-widening FMOPA/FMOPS (#88105) According to the specification in https://github.com/ARM-software/acle/pull/309 this adds the intrinsics void svmopa_za16[_f16]_m(uint64_t tile, svbool_t pn, svbool_t pm, svfloat16_t zn, svfloat16_t zm) __arm_streaming __arm_inout("za"); void svmops_za16[_f16]_m(uint64_t tile, svbool_t pn, svbool_t pm, svfloat16_t zn, svfloat16_t zm) __arm_streaming __arm_inout("za"); as well as the corresponding `bf16` variants. Added: clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c llvm/test/CodeGen/AArch64/sme2-intrinsics-mopa.ll Modified: clang/include/clang/Basic/arm_sme.td llvm/include/llvm/IR/IntrinsicsAArch64.td llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td llvm/lib/Target/AArch64/SMEInstrFormats.td Removed: diff --git a/clang/include/clang/Basic/arm_sme.td b/clang/include/clang/Basic/arm_sme.td index 77ea53fb83fac..7808ee559932e 100644 --- a/clang/include/clang/Basic/arm_sme.td +++ b/clang/include/clang/Basic/arm_sme.td @@ -708,3 +708,27 @@ let TargetGuard = "sme2" in { def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt_{d}_x2", "2.di[i", "cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>; def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", "cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>; } + + +// SME2p1 - FMOPA, FMOPS (non-widening) +let TargetGuard = "sme2,b16b16" in { + def SVMOPA_BF16_NW : SInst<"svmopa_za16[_bf16]_m", "viPPdd", "b", + MergeNone, "aarch64_sme_mopa", + [IsStreaming, IsInOutZA], + [ImmCheck<0, ImmCheck0_1>]>; + def SVMOPS_BF16_NW : SInst<"svmops_za16[_bf16]_m", "viPPdd", "b", + MergeNone, "aarch64_sme_mops", + [IsStreaming, IsInOutZA], + [ImmCheck<0, ImmCheck0_1>]>; +} + +let TargetGuard = "sme-f16f16" in { + def SVMOPA_F16_NW : SInst<"svmopa_za16[_f16]_m", "viPPdd", "h", +MergeNone, "aarch64_sme_mopa", +[IsStreaming, IsInOutZA], +[ImmCheck<0, ImmCheck0_1>]>; + def SVMOPS_F16_NW : SInst<"svmops_za16[_f16]_m", "viPPdd", "h", +MergeNone, "aarch64_sme_mops", +[IsStreaming, IsInOutZA], +[ImmCheck<0, ImmCheck0_1>]>; +} diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c new file mode 100644 index 0..626bb6d3cf6f7 --- /dev/null +++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c @@ -0,0 +1,97 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature +b16b16 -target-feature +sme-f16f16 -O2 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK +// RUN: %clang_cc1-x c++ -fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature +b16b16 -target-feature +sme-f16f16 -O2 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK-CXX +// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS-fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature +b16b16 -target-feature +sme-f16f16 -O2 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK +// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -x c++ -fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature +b16b16 -target-feature +sme-f16f16 -O2 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK-CXX + +// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -x c++ -fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sme2p1 -target-feature +b16b16 -target-feature +sme-f16f16 -S -O2 -Werror -o /dev/null %s + +// REQUIRES: aarch64-registered-target + +#include + +#ifdef SME_OVERLOADED_FORMS +#define SME_ACLE_FUNC(A1,A2_UNUSED,
[clang] [llvm] [AArch64] Add intrinsics for non-widening FMOPA/FMOPS (PR #88105)
https://github.com/momchil-velikov closed https://github.com/llvm/llvm-project/pull/88105 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)
@@ -74,9 +73,13 @@ REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoRegion, const MemRegion *) REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoState, errno_modeling::ErrnoCheckState) -/// Search for a variable called "errno" in the AST. -/// Return nullptr if not found. -static const VarDecl *getErrnoVar(ASTContext &ACtx) { +void ErrnoModeling::checkASTDecl(const TranslationUnitDecl *D, + AnalysisManager &Mgr, BugReporter &BR) const { + // Try to find the declaration of the external variable `int errno;`. + // There are also C library implementations, where the `errno` location is + // accessed via a function that returns its address; in those environments + // this callback does nothing. balazske wrote: ```suggestion // this callback has no effect. ``` https://github.com/llvm/llvm-project/pull/91531 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] support expect no diagnosis test (PR #91293)
@@ -226,6 +236,10 @@ def run_clang_tidy(self): print("--") return clang_tidy_output +def check_no_diagnosis(self, clang_tidy_output): +if clang_tidy_output != "": +sys.exit("No diagnostics were expected, but found the ones above") 5chmidti wrote: You may have accidentally not staged the hunk with the `print`. Either way, what I meant was: ```python if clang_tidy_output != "": print(clang_tidy_output) sys.exit("No diagnostics were expected, but found the ones above") ``` Because we already check if `clang_tidy_output` is empty to potentially terminate because errors were found when they shouldn't have, we can call print inside the if, so we don't print an empty string. (-> nit). https://github.com/llvm/llvm-project/pull/91293 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/91531 From 07dc4dd5c60c8a04637cce686b379e195deb5b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Wed, 8 May 2024 20:01:57 +0200 Subject: [PATCH 1/3] [analyzer] Refactor recognition of the errno getter functions There are many environments where `errno` is a macro that expands to something like `(*__errno())` (different standard library implementations use different names instead of "__errno"). In these environments the ErrnoModeling checker creates a symbolic region which will be used to represent the return value of this "get the location of errno" function. Previously this symbol was only created when the checker was able to find the declaration of the "get the location of errno" function; but this commit eliminates the complex logic that was responsible for this and always creates the symbolic region when `errno` is not available as a "regular" global variable. This significantly simplifies a code and only introduces a minimal performance reduction (one extra symbol) in the unlikely case when `errno` is not declared (neither as a variable nor as a function), but the `ErrnoModeling` checker is enabled. In addition to this simplification, this commit specifies that the `CallDescription`s for the "get the location of errno" functions are matched in `CDM::CLibrary` mode. (This was my original goal, but I was sidetracked by resolving a FIXME above the `CallDescriptionSet` in `ErrnoModeling.cpp`.) This change is very close to being NFC, but it fixes weird corner cases like the handling of a C++ method that happens to be named "__errno()" (previously it could've been recognized as an errno location getter function). --- .../StaticAnalyzer/Checkers/ErrnoChecker.cpp | 2 +- .../StaticAnalyzer/Checkers/ErrnoModeling.cpp | 127 ++ .../StaticAnalyzer/Checkers/ErrnoModeling.h | 9 +- clang/test/Analysis/memory-model.cpp | 18 +-- 4 files changed, 53 insertions(+), 103 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp index 18e718e085536..72fd6781a7561 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp @@ -205,7 +205,7 @@ void ErrnoChecker::checkPreCall(const CallEvent &Call, // Probably 'strerror'? if (CallF->isExternC() && CallF->isGlobal() && C.getSourceManager().isInSystemHeader(CallF->getLocation()) && - !isErrno(CallF)) { + !isErrnoLocationCall(Call)) { if (getErrnoState(C.getState()) == MustBeChecked) { std::optional ErrnoLoc = getErrnoLoc(C.getState()); assert(ErrnoLoc && "ErrnoLoc should exist if an errno state is set."); diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp index 1b34ea0e056e5..0612cd4c87248 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp @@ -39,10 +39,15 @@ namespace { // Name of the "errno" variable. // FIXME: Is there a system where it is not called "errno" but is a variable? const char *ErrnoVarName = "errno"; + // Names of functions that return a location of the "errno" value. // FIXME: Are there other similar function names? -const char *ErrnoLocationFuncNames[] = {"__errno_location", "___errno", -"__errno", "_errno", "__error"}; +CallDescriptionSet ErrnoLocationCalls{ +{CDM::SimpleFunc, {"__errno_location"}, 0, 0}, +{CDM::SimpleFunc, {"___errno"}, 0, 0}, +{CDM::SimpleFunc, {"__errno"}, 0, 0}, +{CDM::SimpleFunc, {"_errno"}, 0, 0}, +{CDM::SimpleFunc, {"__error"}, 0, 0}}; class ErrnoModeling : public Checker, check::BeginFunction, @@ -54,16 +59,10 @@ class ErrnoModeling void checkLiveSymbols(ProgramStateRef State, SymbolReaper &SR) const; bool evalCall(const CallEvent &Call, CheckerContext &C) const; - // The declaration of an "errno" variable or "errno location" function. - mutable const Decl *ErrnoDecl = nullptr; - private: - // FIXME: Names from `ErrnoLocationFuncNames` are used to build this set. - CallDescriptionSet ErrnoLocationCalls{{{"__errno_location"}, 0, 0}, -{{"___errno"}, 0, 0}, -{{"__errno"}, 0, 0}, -{{"_errno"}, 0, 0}, -{{"__error"}, 0, 0}}; + // The declaration of an "errno" variable on systems where errno is + // represented by a variable (and not a function that queries its location). + mutable const Decl *ErrnoDecl = nullptr; }; } // namespace @@ -74,9 +73,13 @@ REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoRegion, const MemRegion *) REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoState, errno_modeling::ErrnoCheckState) -/// Search for a variable called "errno
[clang-tools-extra] [clang-tidy] use llvm::any_of refactor getAnalyzerCheckersAndPackages [NFC] (PR #91713)
https://github.com/5chmidti approved this pull request. https://github.com/llvm/llvm-project/pull/91713 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)
@@ -136,53 +100,48 @@ void ErrnoModeling::checkBeginFunction(CheckerContext &C) const { ASTContext &ACtx = C.getASTContext(); ProgramStateRef State = C.getState(); - if (const auto *ErrnoVar = dyn_cast_or_null(ErrnoDecl)) { -// There is an external 'errno' variable. -// Use its memory region. -// The memory region for an 'errno'-like variable is allocated in system -// space by MemRegionManager. -const MemRegion *ErrnoR = -State->getRegion(ErrnoVar, C.getLocationContext()); + const MemRegion *ErrnoR; + + if (ErrnoDecl) { +// There is an external 'errno' variable, so we can simply use the memory +// region that's associated with it. +ErrnoR = State->getRegion(ErrnoDecl, C.getLocationContext()); assert(ErrnoR && "Memory region should exist for the 'errno' variable."); -State = State->set(ErrnoR); -State = -errno_modeling::setErrnoValue(State, C, 0, errno_modeling::Irrelevant); -C.addTransition(State); - } else if (ErrnoDecl) { -assert(isa(ErrnoDecl) && "Invalid errno location function."); -// There is a function that returns the location of 'errno'. -// We must create a memory region for it in system space. -// Currently a symbolic region is used with an artifical symbol. -// FIXME: It is better to have a custom (new) kind of MemRegion for such -// cases. + } else { +// The 'errno' location is accessed via an internal getter function, so +// create a new symbolic memory region that can be used as the return value +// of that function. balazske wrote: We should mention that this case happens even if there is no errno getter function at all https://github.com/llvm/llvm-project/pull/91531 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/91531 From 07dc4dd5c60c8a04637cce686b379e195deb5b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Wed, 8 May 2024 20:01:57 +0200 Subject: [PATCH 1/4] [analyzer] Refactor recognition of the errno getter functions There are many environments where `errno` is a macro that expands to something like `(*__errno())` (different standard library implementations use different names instead of "__errno"). In these environments the ErrnoModeling checker creates a symbolic region which will be used to represent the return value of this "get the location of errno" function. Previously this symbol was only created when the checker was able to find the declaration of the "get the location of errno" function; but this commit eliminates the complex logic that was responsible for this and always creates the symbolic region when `errno` is not available as a "regular" global variable. This significantly simplifies a code and only introduces a minimal performance reduction (one extra symbol) in the unlikely case when `errno` is not declared (neither as a variable nor as a function), but the `ErrnoModeling` checker is enabled. In addition to this simplification, this commit specifies that the `CallDescription`s for the "get the location of errno" functions are matched in `CDM::CLibrary` mode. (This was my original goal, but I was sidetracked by resolving a FIXME above the `CallDescriptionSet` in `ErrnoModeling.cpp`.) This change is very close to being NFC, but it fixes weird corner cases like the handling of a C++ method that happens to be named "__errno()" (previously it could've been recognized as an errno location getter function). --- .../StaticAnalyzer/Checkers/ErrnoChecker.cpp | 2 +- .../StaticAnalyzer/Checkers/ErrnoModeling.cpp | 127 ++ .../StaticAnalyzer/Checkers/ErrnoModeling.h | 9 +- clang/test/Analysis/memory-model.cpp | 18 +-- 4 files changed, 53 insertions(+), 103 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp index 18e718e085536..72fd6781a7561 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp @@ -205,7 +205,7 @@ void ErrnoChecker::checkPreCall(const CallEvent &Call, // Probably 'strerror'? if (CallF->isExternC() && CallF->isGlobal() && C.getSourceManager().isInSystemHeader(CallF->getLocation()) && - !isErrno(CallF)) { + !isErrnoLocationCall(Call)) { if (getErrnoState(C.getState()) == MustBeChecked) { std::optional ErrnoLoc = getErrnoLoc(C.getState()); assert(ErrnoLoc && "ErrnoLoc should exist if an errno state is set."); diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp index 1b34ea0e056e5..0612cd4c87248 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp @@ -39,10 +39,15 @@ namespace { // Name of the "errno" variable. // FIXME: Is there a system where it is not called "errno" but is a variable? const char *ErrnoVarName = "errno"; + // Names of functions that return a location of the "errno" value. // FIXME: Are there other similar function names? -const char *ErrnoLocationFuncNames[] = {"__errno_location", "___errno", -"__errno", "_errno", "__error"}; +CallDescriptionSet ErrnoLocationCalls{ +{CDM::SimpleFunc, {"__errno_location"}, 0, 0}, +{CDM::SimpleFunc, {"___errno"}, 0, 0}, +{CDM::SimpleFunc, {"__errno"}, 0, 0}, +{CDM::SimpleFunc, {"_errno"}, 0, 0}, +{CDM::SimpleFunc, {"__error"}, 0, 0}}; class ErrnoModeling : public Checker, check::BeginFunction, @@ -54,16 +59,10 @@ class ErrnoModeling void checkLiveSymbols(ProgramStateRef State, SymbolReaper &SR) const; bool evalCall(const CallEvent &Call, CheckerContext &C) const; - // The declaration of an "errno" variable or "errno location" function. - mutable const Decl *ErrnoDecl = nullptr; - private: - // FIXME: Names from `ErrnoLocationFuncNames` are used to build this set. - CallDescriptionSet ErrnoLocationCalls{{{"__errno_location"}, 0, 0}, -{{"___errno"}, 0, 0}, -{{"__errno"}, 0, 0}, -{{"_errno"}, 0, 0}, -{{"__error"}, 0, 0}}; + // The declaration of an "errno" variable on systems where errno is + // represented by a variable (and not a function that queries its location). + mutable const Decl *ErrnoDecl = nullptr; }; } // namespace @@ -74,9 +73,13 @@ REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoRegion, const MemRegion *) REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoState, errno_modeling::ErrnoCheckState) -/// Search for a variable called "errno
[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)
@@ -136,53 +100,48 @@ void ErrnoModeling::checkBeginFunction(CheckerContext &C) const { ASTContext &ACtx = C.getASTContext(); ProgramStateRef State = C.getState(); - if (const auto *ErrnoVar = dyn_cast_or_null(ErrnoDecl)) { -// There is an external 'errno' variable. -// Use its memory region. -// The memory region for an 'errno'-like variable is allocated in system -// space by MemRegionManager. -const MemRegion *ErrnoR = -State->getRegion(ErrnoVar, C.getLocationContext()); + const MemRegion *ErrnoR; + + if (ErrnoDecl) { +// There is an external 'errno' variable, so we can simply use the memory +// region that's associated with it. +ErrnoR = State->getRegion(ErrnoDecl, C.getLocationContext()); assert(ErrnoR && "Memory region should exist for the 'errno' variable."); -State = State->set(ErrnoR); -State = -errno_modeling::setErrnoValue(State, C, 0, errno_modeling::Irrelevant); -C.addTransition(State); - } else if (ErrnoDecl) { -assert(isa(ErrnoDecl) && "Invalid errno location function."); -// There is a function that returns the location of 'errno'. -// We must create a memory region for it in system space. -// Currently a symbolic region is used with an artifical symbol. -// FIXME: It is better to have a custom (new) kind of MemRegion for such -// cases. + } else { +// The 'errno' location is accessed via an internal getter function, so +// create a new symbolic memory region that can be used as the return value +// of that function. NagyDonat wrote: Good point, I fixed it. https://github.com/llvm/llvm-project/pull/91531 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)
@@ -520,6 +524,18 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo { RecomputeNeedsHandleIdentifier(); } + /// Determine whether this is the contextual keyword \c module. + bool isModulesDecl() const { return IsModulesDecl; } yronglin wrote: Agree! https://github.com/llvm/llvm-project/pull/90574 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)
@@ -1329,6 +1341,100 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) { return true; } +/// Lex a token following the 'module' contextual keyword. +/// +/// [cpp.module]/p2: +/// The pp-tokens, if any, of a pp-module shall be of the form: +/// pp-module-name pp-module-partition[opt] pp-tokens[opt] +/// +/// where the pp-tokens (if any) shall not begin with a ( preprocessing token +/// and the grammar non-terminals are defined as: +/// pp-module-name: +/// pp-module-name-qualifierp[opt] identifier +/// pp-module-partition: +/// : pp-module-name-qualifier[opt] identifier +/// pp-module-name-qualifier: +/// identifier . +/// pp-module-name-qualifier identifier . +/// No identifier in the pp-module-name or pp-module-partition shall currently +/// be defined as an object-like macro. +/// +/// [cpp.module]/p3: +/// Any preprocessing tokens after the module preprocessing token in the module +/// directive are processed just as in normal text. +bool Preprocessor::LexAfterModuleDecl(Token &Result) { + // Figure out what kind of lexer we actually have. + recomputeCurLexerKind(); + LexUnexpandedToken(Result); + + auto EnterTokens = [this](ArrayRef Toks, bool DisableMacroExpansion) { +auto ToksCopy = std::make_unique(Toks.size()); +std::copy(Toks.begin(), Toks.end(), ToksCopy.get()); +EnterTokenStream(std::move(ToksCopy), Toks.size(), DisableMacroExpansion, + /*IsReinject=*/false); + }; + + // If we don't expect an identifier but got an identifier, it's not a part of + // module name. + if (!ModuleDeclExpectsIdentifier && Result.is(tok::identifier)) { +EnterTokens(Result, /*DisableMacroExpansion=*/false); +return false; + } + + // The token sequence + // + // export[opt] module identifier (. identifier)* + // + // indicates a module directive. We already saw the 'module' + // contextual keyword, so now we're looking for the identifiers. + if (ModuleDeclExpectsIdentifier && Result.is(tok::identifier)) { +auto *MI = getMacroInfo(Result.getIdentifierInfo()); +if (MI && MI->isObjectLike()) { + Diag(Result, diag::err_module_decl_cannot_be_macros) + << Result.getLocation() << ModuleDeclLexingPartitionName + << Result.getIdentifierInfo(); +} +ModuleDeclExpectsIdentifier = false; +CurLexerCallback = CLK_LexAfterModuleDecl; +return true; + } + + // If we're expecting a '.', a ':' or a ';', and we got a '.', then wait until + // we see the next identifier. + if (!ModuleDeclExpectsIdentifier && Result.isOneOf(tok::period, tok::colon)) { +ModuleDeclExpectsIdentifier = true; +ModuleDeclLexingPartitionName = Result.is(tok::colon); +CurLexerCallback = CLK_LexAfterModuleDecl; +return true; + } + + // [cpp.module]/p2: where the pp-tokens (if any) shall not begin with a ( + // preprocessing token [...] + if (!ModuleDeclExpectsIdentifier && Result.is(tok::l_paren)) { +ModuleDeclExpectsIdentifier = false; +Diag(Result, diag::err_unxepected_paren_in_module_decl) +<< ModuleDeclLexingPartitionName; +Token Tok; +// We already have a '('. +unsigned NumParens = 1; +while (true) { + LexUnexpandedToken(Tok); + if (Tok.isOneOf(tok::eod, tok::eof, tok::semi, tok::period, tok::colon)) { +EnterTokens(Tok, /*DisableMacroExpansion=*/true); +break; + } + if (Tok.is(tok::l_paren)) +NumParens++; + else if (Tok.is(tok::r_paren) && --NumParens == 0) +break; +} +CurLexerCallback = CLK_LexAfterModuleDecl; +return false; + } + + return true; +} + yronglin wrote: > What is the motivation to put the logic in the preprocessor ? It does adds > quite a bit of complexity to the state machine. There are two reasons. The 1st is to be consistent with the way that `import` was processed. The 2nd reason is that some steps in Parser will look ahead of the token before ParseModuleDecl. In ParseModuleName, causing the first identifier was macro expanded token. So once we saw a `module` keyword, The next token and the token conforming to the form `identifier(.identifier)*` must be processed in `Preprocessor::LexAfterModuleDecl`. Introduce a new `cxx_module_name` also looks good to me, it's looks like the approach processing `#pragma`. https://github.com/llvm/llvm-project/pull/90574 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)
sam-mccall wrote: This commit did three things: A) changed the implementation, B) changed the flag default, and C) deprecated the flag. Since clang now crashes on widely-used, real-world code, can we at least revert C, and ideally B until the crashes are fixed? (It would also have been helpful to separate A and B, automated bisection can't tell the difference between the two, and generally we'd deal with crashes in default config by reverting the whole commit) https://github.com/llvm/llvm-project/pull/89807 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)
@@ -1329,6 +1341,100 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) { return true; } +/// Lex a token following the 'module' contextual keyword. +/// +/// [cpp.module]/p2: +/// The pp-tokens, if any, of a pp-module shall be of the form: +/// pp-module-name pp-module-partition[opt] pp-tokens[opt] +/// +/// where the pp-tokens (if any) shall not begin with a ( preprocessing token +/// and the grammar non-terminals are defined as: +/// pp-module-name: +/// pp-module-name-qualifierp[opt] identifier +/// pp-module-partition: +/// : pp-module-name-qualifier[opt] identifier +/// pp-module-name-qualifier: +/// identifier . +/// pp-module-name-qualifier identifier . +/// No identifier in the pp-module-name or pp-module-partition shall currently +/// be defined as an object-like macro. +/// +/// [cpp.module]/p3: +/// Any preprocessing tokens after the module preprocessing token in the module +/// directive are processed just as in normal text. +bool Preprocessor::LexAfterModuleDecl(Token &Result) { + // Figure out what kind of lexer we actually have. + recomputeCurLexerKind(); + LexUnexpandedToken(Result); + + auto EnterTokens = [this](ArrayRef Toks, bool DisableMacroExpansion) { +auto ToksCopy = std::make_unique(Toks.size()); +std::copy(Toks.begin(), Toks.end(), ToksCopy.get()); +EnterTokenStream(std::move(ToksCopy), Toks.size(), DisableMacroExpansion, + /*IsReinject=*/false); + }; + + // If we don't expect an identifier but got an identifier, it's not a part of + // module name. + if (!ModuleDeclExpectsIdentifier && Result.is(tok::identifier)) { +EnterTokens(Result, /*DisableMacroExpansion=*/false); +return false; + } + + // The token sequence + // + // export[opt] module identifier (. identifier)* + // + // indicates a module directive. We already saw the 'module' + // contextual keyword, so now we're looking for the identifiers. + if (ModuleDeclExpectsIdentifier && Result.is(tok::identifier)) { +auto *MI = getMacroInfo(Result.getIdentifierInfo()); +if (MI && MI->isObjectLike()) { + Diag(Result, diag::err_module_decl_cannot_be_macros) + << Result.getLocation() << ModuleDeclLexingPartitionName + << Result.getIdentifierInfo(); +} +ModuleDeclExpectsIdentifier = false; +CurLexerCallback = CLK_LexAfterModuleDecl; +return true; + } + + // If we're expecting a '.', a ':' or a ';', and we got a '.', then wait until + // we see the next identifier. + if (!ModuleDeclExpectsIdentifier && Result.isOneOf(tok::period, tok::colon)) { +ModuleDeclExpectsIdentifier = true; +ModuleDeclLexingPartitionName = Result.is(tok::colon); +CurLexerCallback = CLK_LexAfterModuleDecl; +return true; + } + + // [cpp.module]/p2: where the pp-tokens (if any) shall not begin with a ( + // preprocessing token [...] + if (!ModuleDeclExpectsIdentifier && Result.is(tok::l_paren)) { +ModuleDeclExpectsIdentifier = false; +Diag(Result, diag::err_unxepected_paren_in_module_decl) +<< ModuleDeclLexingPartitionName; +Token Tok; +// We already have a '('. +unsigned NumParens = 1; +while (true) { + LexUnexpandedToken(Tok); + if (Tok.isOneOf(tok::eod, tok::eof, tok::semi, tok::period, tok::colon)) { +EnterTokens(Tok, /*DisableMacroExpansion=*/true); +break; + } + if (Tok.is(tok::l_paren)) +NumParens++; + else if (Tok.is(tok::r_paren) && --NumParens == 0) +break; +} +CurLexerCallback = CLK_LexAfterModuleDecl; +return false; + } yronglin wrote: This recovery was used to handle cases like the following: ``` export module A.FUNC_LIKE(B c:C ATTRS export module A.FUNC_LIKE(B,). c:C ATTRS export module A.FUNC_LIKE(B,) c:C ATTRS ``` I want to recover from the error as much as possible, jumping to the next '.' or ':' when `(` occurs. https://github.com/llvm/llvm-project/pull/90574 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)
@@ -932,6 +932,12 @@ def warn_module_conflict : Warning< InGroup; // C++20 modules +def err_module_decl_cannot_be_macros : Error< + "the module name in a module%select{| partition}0 declaration cannot contain " + "an object-like macro %1, it's consists of one or more identifiers " + "separated by '.'">; yronglin wrote: Agree, I want to add a more help information into diagnostic to address @Bigcheese 's comments before. I don’t know if we need to add a link to clang’s documentation(or other helpful informations). I don’t know if there is any precedent before. > It would be nice in cases like this if we just linked to some documentation > saying what to do instead. https://github.com/llvm/llvm-project/pull/90574 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (PR #90574)
@@ -520,6 +524,18 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo { RecomputeNeedsHandleIdentifier(); } + /// Determine whether this is the contextual keyword \c module. + bool isModulesDecl() const { return IsModulesDecl; } + + /// Set whether this identifier is the contextual keyword \c module. + void setModulesDecl(bool I) { yronglin wrote: It seems that the setter methods of other flags in `IdentifierInfo` have a bool parameter, so I kept the same format. https://github.com/llvm/llvm-project/pull/90574 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 200f3bd - [Clang][Sema] access checking of friend declaration should not be delayed (#91430)
Author: Qizhi Hu Date: 2024-05-10T20:14:08+08:00 New Revision: 200f3bd39562f4d605f13567398025d30fa27d61 URL: https://github.com/llvm/llvm-project/commit/200f3bd39562f4d605f13567398025d30fa27d61 DIFF: https://github.com/llvm/llvm-project/commit/200f3bd39562f4d605f13567398025d30fa27d61.diff LOG: [Clang][Sema] access checking of friend declaration should not be delayed (#91430) attempt to fix https://github.com/llvm/llvm-project/issues/12361 Consider this example: ```cpp class D { class E{ class F{}; friend void foo(D::E::F& q); }; friend void foo(D::E::F& q); }; void foo(D::E::F& q) {} ``` The first friend declaration of foo is correct. After that, the second friend declaration delayed access checking and set its previous declaration to be the first one. When doing access checking of `F`(which is private filed of `E`), we put its canonical declaration(the first friend declaration) into `EffectiveContext.Functions`. Actually, we are still checking the first one. This is incorrect due to the delayed checking. Creating a new scope to indicate we are parsing a friend declaration and doing access checking in time. Added: clang/test/SemaCXX/PR12361.cpp Modified: clang/docs/ReleaseNotes.rst clang/include/clang/Sema/Scope.h clang/lib/Parse/ParseDecl.cpp clang/lib/Sema/Scope.cpp clang/lib/Sema/SemaAccess.cpp Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index eef627ff2e31f..7c5dcc59c7016 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -706,6 +706,7 @@ Bug Fixes to C++ Support within initializers for variables that are usable in constant expressions or are constant initialized, rather than evaluating them as a part of the larger manifestly constant evaluated expression. +- Fix a bug in access control checking due to dealyed checking of friend declaration. Fixes (#GH12361). Bug Fixes to AST Handling ^ diff --git a/clang/include/clang/Sema/Scope.h b/clang/include/clang/Sema/Scope.h index 1752a25111a77..084db73034219 100644 --- a/clang/include/clang/Sema/Scope.h +++ b/clang/include/clang/Sema/Scope.h @@ -159,6 +159,9 @@ class Scope { /// This is a scope of type alias declaration. TypeAliasScope = 0x2000, + +/// This is a scope of friend declaration. +FriendScope = 0x4000, }; private: @@ -586,6 +589,9 @@ class Scope { /// Determine whether this scope is a type alias scope. bool isTypeAliasScope() const { return getFlags() & Scope::TypeAliasScope; } + /// Determine whether this scope is a friend scope. + bool isFriendScope() const { return getFlags() & Scope::FriendScope; } + /// Returns if rhs has a higher scope depth than this. /// /// The caller is responsible for calling this only if one of the two scopes diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 2c11ae693c354..5b5fc02ad4023 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4331,9 +4331,12 @@ void Parser::ParseDeclarationSpecifiers( // friend case tok::kw_friend: - if (DSContext == DeclSpecContext::DSC_class) + if (DSContext == DeclSpecContext::DSC_class) { isInvalid = DS.SetFriendSpec(Loc, PrevSpec, DiagID); - else { +Scope *CurS = getCurScope(); +if (!isInvalid && CurS) + CurS->setFlags(CurS->getFlags() | Scope::FriendScope); + } else { PrevSpec = ""; // not actually used by the diagnostic DiagID = diag::err_friend_invalid_in_context; isInvalid = true; diff --git a/clang/lib/Sema/Scope.cpp b/clang/lib/Sema/Scope.cpp index 11a41753a1bda..c08073e80ff3d 100644 --- a/clang/lib/Sema/Scope.cpp +++ b/clang/lib/Sema/Scope.cpp @@ -229,6 +229,7 @@ void Scope::dumpImpl(raw_ostream &OS) const { {ClassInheritanceScope, "ClassInheritanceScope"}, {CatchScope, "CatchScope"}, {OpenACCComputeConstructScope, "OpenACCComputeConstructScope"}, + {FriendScope, "FriendScope"}, }; for (auto Info : FlagInfo) { diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index 6a707eeb66d01..979a64b065f3d 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -1473,12 +1473,32 @@ static Sema::AccessResult CheckAccess(Sema &S, SourceLocation Loc, // specifier, like this: // A::private_type A::foo() { ... } // - // Or we might be parsing something that will turn out to be a friend: - // void foo(A::private_type); - // void B::foo(A::private_type); + // friend declaration should not be delayed because it may lead to incorrect + // redeclaration chain, such as: + // class D { + //class E{ + // class F{}; + // friend void foo(D::E::F& q); + //}; + //friend void foo(D::E::F& q); + // };
[clang] [Clang][Sema] access checking of friend declaration should not be delayed (PR #91430)
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/91430 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)
cor3ntin wrote: I don't think there is motivation to revert anything at this point (we should avoid churn), however I do agree this is a regression that we should fix quickly @mizvekov. (Even if it's not a new bug, it is a newly exposed bug, the pain for users is the same) If the fix takes a long time to manifest then we should consider more aggressive mitigations. https://github.com/llvm/llvm-project/pull/89807 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] No longer require complete types with __builtin_launder (PR #91070)
erichkeane wrote: This patch doesn't really make sense to me. Why would we want `__builtin_launder` to work on incomplete types? https://github.com/llvm/llvm-project/pull/91070 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Add intrinsics for multi-vector to ZA array vector accumulators (PR #91606)
https://github.com/momchil-velikov updated https://github.com/llvm/llvm-project/pull/91606 >From d3e381ac645d08b6f3b01283d47344556a163605 Mon Sep 17 00:00:00 2001 From: Momchil Velikov Date: Thu, 9 May 2024 15:56:31 +0100 Subject: [PATCH] [AArch64] Add intrinsics for multi-vector to ZA array vector accumulators (#88266) According to the specification in https://github.com/ARM-software/acle/pull/309 this adds the intrinsics void_svadd_za16_vg1x2_f16(uint32_t slice, svfloat16x2_t zn) __arm_streaming __arm_inout("za"); void_svadd_za16_vg1x4_f16(uint32_t slice, svfloat16x4_t zn) __arm_streaming __arm_inout("za"); void_svsub_za16_vg1x2_f16(uint32_t slice, svfloat16x2_t zn) __arm_streaming __arm_inout("za"); void_svsub_za16_vg1x4_f16(uint32_t slice, svfloat16x4_t zn) __arm_streaming __arm_inout("za"); as well as the corresponding `bf16` variants. --- clang/include/clang/Basic/arm_sme.td | 10 + .../acle_sme2_add_sub_za16.c | 193 ++ .../acle_sme2_add_sub_za16.c | 29 +++ llvm/include/llvm/IR/IntrinsicsAArch64.td | 2 +- .../lib/Target/AArch64/AArch64SMEInstrInfo.td | 16 +- .../AArch64/sme2-intrinsics-add-sub-za16.ll | 148 ++ 6 files changed, 389 insertions(+), 9 deletions(-) create mode 100644 clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c create mode 100644 clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-add-sub-za16.ll diff --git a/clang/include/clang/Basic/arm_sme.td b/clang/include/clang/Basic/arm_sme.td index 7808ee559932e..80e635e4a57ec 100644 --- a/clang/include/clang/Basic/arm_sme.td +++ b/clang/include/clang/Basic/arm_sme.td @@ -298,6 +298,16 @@ multiclass ZAAddSub { def NAME # _ZA64_VG1X2_F64 : Inst<"sv" # n_suffix # "_za64[_{d}]_vg1x2", "vm2", "d", MergeNone, "aarch64_sme_" # n_suffix # "_za64_vg1x2", [IsStreaming, IsInOutZA], []>; def NAME # _ZA64_VG1X4_F64 : Inst<"sv" # n_suffix # "_za64[_{d}]_vg1x4", "vm4", "d", MergeNone, "aarch64_sme_" # n_suffix # "_za64_vg1x4", [IsStreaming, IsInOutZA], []>; } + + let TargetGuard = "sme-f16f16|sme-f8f16" in { +def NAME # _ZA16_VG1X2_F16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x2", "vm2", "h", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x2", [IsStreaming, IsInOutZA], []>; +def NAME # _ZA16_VG1X4_F16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x4", "vm4", "h", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x4", [IsStreaming, IsInOutZA], []>; + } + + let TargetGuard = "sme2,b16b16" in { +def NAME # _ZA16_VG1X2_BF16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x2", "vm2", "b", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x2", [IsStreaming, IsInOutZA], []>; +def NAME # _ZA16_VG1X4_BF16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x4", "vm4", "b", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x4", [IsStreaming, IsInOutZA], []>; + } } defm SVADD : ZAAddSub<"add">; diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c new file mode 100644 index 0..9a8aa448d3780 --- /dev/null +++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c @@ -0,0 +1,193 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sme2 -target-feature +sme-f16f16 -target-feature +b16b16 -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1-x c++ -fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sme2 -target-feature +sme-f8f16 -target-feature +b16b16 -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK-CXX +// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS-fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sme2 -target-feature +sme-f8f16 -target-feature +b16b16 -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -x c++ -fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sme2 -target-feature +sme-f16f16 -target-feature +b16b16 -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK-CXX + +// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu -target-feature +sme2 -target-feature +sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -o /dev/null + +// REQUIRES: aarch64-registered-target + +#include + +#ifdef SVE_OVERLOADED_FORMS +#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3 +#else +#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3 +#endif + +// CHECK-LABEL: define dso_local void @test_svadd_za16_vg1x2_f16( +// CHECK-SAME: i32 noundef [[SLICE:%.*]], [[ZN:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-
[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)
Endilll wrote: It'd also be nice if someone can share a reproducer that crashes on trunk but not on 18.1.0 without names reduced to 1-2 letters. Definitely would speed up the work towards the fix. https://github.com/llvm/llvm-project/pull/89807 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)
cor3ntin wrote: Having a clean reduction to decide whether the code is supposed to compile or not is indeed a good first step. Clang 18 was not conforming and people might have relied on it. There is a -fno-relaxed-template-template-args that can be used as a workaround for now https://github.com/llvm/llvm-project/pull/89807 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)
erichkeane wrote: I agree with @sam-mccall : I think "crashes on some widely-used real-world code" means we should revert `B` until we can make that case work. Yes, it is a pre-existing issue, however it means that we aren't "ready" to change the flag default. However, we DEFINITELY need a useful reproducer, and I'm OK holding off on a revert if we can get a fix in 'the next few days' timeframe. https://github.com/llvm/llvm-project/pull/89807 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (PR #91628)
https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/91628 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)
erichkeane wrote: > If you're using `creduce`, this set of arguments disables all renaming > passes: `--remove-pass pass_clang rename-fun --remove-pass pass_clang > rename-param --remove-pass pass_clang rename-var --remove-pass pass_clang > rename-class --remove-pass pass_clang rename-cxx-method --remove-pass > pass_clex rename-toks` This 100% needs to happen ASAP. @sam-mccall or @bgra8 : Is this something you can provide? https://github.com/llvm/llvm-project/pull/89807 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] No longer require complete types with __builtin_launder (PR #91070)
cor3ntin wrote: The committee says so Because launder is just adding a fence on a pointer to T, we need not know what T is. I don't know whether there are scenarios where calling launder on an incomplete type would be useful (as presumably you would new an object right before which would require completeness) but it's also harmless. https://github.com/llvm/llvm-project/pull/91070 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][HIP] Warn when __AMDGCN_WAVEFRONT_SIZE is used in host code (PR #91478)
@@ -0,0 +1,55 @@ +/*=== __clang_hip_device_macro_guards.h - guards for HIP device macros -=== + * + * 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 + * + *===---=== + */ + +/* + * WARNING: This header is intended to be directly -include'd by + * the compiler and is not supposed to be included by users. + * + */ + +#ifndef __CLANG_HIP_DEVICE_MACRO_GUARDS_H__ +#define __CLANG_HIP_DEVICE_MACRO_GUARDS_H__ + +#if __HIP__ +#if !defined(__HIP_DEVICE_COMPILE__) +// The __AMDGCN_WAVEFRONT_SIZE macros cannot hold meaningful values during host +// compilation as devices are not initialized when the macros are defined and +// there may indeed be devices with differing wavefront sizes in the same +// system. This code issues diagnostics when the macros are used in host code. + +#undef __AMDGCN_WAVEFRONT_SIZE +#undef __AMDGCN_WAVEFRONT_SIZE__ + +// Reference __hip_device_macro_guard in a way that is legal in preprocessor +// directives and does not affect the value so that appropriate diagnostics are +// issued. Function calls, casts, or the comma operator would make the macro +// illegal for use in preprocessor directives. +#define __AMDGCN_WAVEFRONT_SIZE (!__hip_device_macro_guard ? 64 : 64) +#define __AMDGCN_WAVEFRONT_SIZE__ (!__hip_device_macro_guard ? 64 : 64) + +// This function is referenced by the macro in device functions during host +// compilation, it SHOULD NOT cause a diagnostic. +__attribute__((device)) static constexpr int __hip_device_macro_guard(void) { + return -1; +} + +// This function is referenced by the macro in host functions during host +// compilation, it SHOULD cause a diagnostic. +__attribute__(( +host, deprecated("The __AMDGCN_WAVEFRONT_SIZE macros do not correspond " + "to the device(s) when used in host code and may only " + "be used in device code."))) static constexpr int ritter-x2a wrote: re pre-C++11 HIP: I think we can just drop the `constexpr` from both variants of the guard function; since the guard function is only referenced and never called, the macros would still work as constant expressions. re OpenMP: As far as I can see in experiments, the macros are not defined during OpenMP's host compilation. This is therefore not an issue for OpenMP. https://github.com/llvm/llvm-project/pull/91478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] No longer require complete types with __builtin_launder (PR #91070)
erichkeane wrote: > The committee says so > > Because launder is just adding a fence on a pointer to T, we need not know > what T is. > > I don't know whether there are scenarios where calling launder on an > incomplete type would be useful (as presumably you would new an object right > before which would require completeness) but it's also harmless. Thanks! That wasn't clear to me from the bug report/commit message. https://github.com/llvm/llvm-project/pull/91070 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] No longer require complete types with __builtin_launder (PR #91070)
erichkeane wrote: > Should we try to force an instantiation in codegen for > complete-but-not-yet-instantiated classes? I think we have to here. I believe we can do this by changing the `RequireCompleteType` to pass a null `diagnoser`. See this overload: https://clang.llvm.org/doxygen/classclang_1_1Sema.html#ac457a5af05f2ffc2cf6286f398d9201d (RequireCompleteType() [1/5]) https://github.com/llvm/llvm-project/pull/91070 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Revise the transformation of CTAD parameters of nested class templates (PR #91628)
@@ -2583,11 +2580,27 @@ struct ConvertConstructorToDeductionGuideTransform { //-- The types of the function parameters are those of the constructor. for (auto *OldParam : TL.getParams()) { - ParmVarDecl *NewParam = - transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs); - if (NestedPattern && NewParam) + ParmVarDecl *NewParam = OldParam; + // Given + // template struct C { + // template struct D { + // template D(U, V); + // }; + // }; + // First, transform all the references to template parameters that are + // defined outside of the surrounding class template. That is T in the + // above example. + if (NestedPattern) { NewParam = transformFunctionTypeParam(NewParam, OuterInstantiationArgs, MaterializedTypedefs); +if (!NewParam) + return QualType(); + } + // Then, transform all the references to template parameters that are + // defined at the class template and the constructor. In this example, + // they're U and V, respectively. + NewParam = + transformFunctionTypeParam(NewParam, Args, MaterializedTypedefs); zyn0217 wrote: I think that's just fine, although it looks weird: those lines are merely "creating" new template parameters rather than doing type substitution. (it's applying a `TemplateDeclInstantiator` with the instantiating arguments - the only valuable part from these arguments is the depth we're supposed to deduct, and the type isn't something we're concerned about at that time.) Frankly, I have to say I didn't fully understand why we have such discrepancies (use the `transformTemplateParameter` first and then a `TemplateDeclInstantiator` for nested cases). I was expecting that perhaps we could unify them in one call. I think it warrants a separate refactoring PR, then. https://github.com/llvm/llvm-project/pull/91628 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits