[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -8925,6 +8925,97 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { NoBinPacking); } +TEST_F(FormatTest, FormatsDeclarationBreakAlways) { + FormatStyle BreakAlways = getGoogleStyle(); + BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine; + verifyFormat("void f(int a,\n" + " int b);", + BreakAlways); + verifyFormat("void f(int aa,\n" + " int b,\n" + " int );", + BreakAlways); + + // Ensure AlignAFterOpenBracket interacts correctly with + // PackParameters set to BreakAlways. + BreakAlways.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak; + verifyFormat( + "void someLongFunctionName(\n" + "int a,\n" + "int b);", + BreakAlways); + BreakAlways.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent; + verifyFormat( + "void someLongFunctionName(\n" + "int a,\n" + "int b\n" + ");", + BreakAlways); +} + +TEST_F(FormatTest, FormatsDefinitionBreakAlways) { + FormatStyle BreakAlways = getGoogleStyle(); + BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine; + verifyFormat("void f(int a,\n" + " int b) {\n" + " f(a, b);\n" + "}", + BreakAlways); + + // Ensure BinPackArguments interact correctly when BinPackParameters is set to + // BreakAlways. owenca wrote: ```suggestion // BPPS_Never. ``` https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -5475,6 +5475,14 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, return true; } + // Ignores the first parameter as this will be handled separately by + // BreakFunctionDefinitionParameters or AlignAfterOpenBracket. + if (FormatStyle::BPPS_OnePerLine == Style.BinPackParameters && owenca wrote: ```suggestion if (Style.BinPackParameters == FormatStyle::BPPS_Never && ``` https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -1192,20 +1192,36 @@ struct FormatStyle { /// \version 3.7 bool BinPackArguments; - /// If ``false``, a function declaration's or function definition's - /// parameters will either all be on the same line or will have one line each. - /// \code - /// true: - /// void f(int , int , - /// int aaa) {} - /// - /// false: - /// void f(int , - /// int , - /// int aaa) {} - /// \endcode + /// Different way to try to fit all parameters on a line. + enum BinPackParametersStyle : int8_t { +/// Put all parameters on the current line if they fit. +/// Otherwise, put each one on its own line. +/// \code +///void f(int a, int b, int c); +/// +///void f(int a, +/// int b, +/// int c); +/// \endcode +BPPS_Never, owenca wrote: IMO we should swap `BPPS_Never` and `BPPS_OnePerLine` to be consistent with `BreakBinaryOperations`, i.e.: - `true` becomes `BPPS_Always`. - `false` becomes `BPPS_OnePerLine`. - `BPPS_Never` is new and means _always_ one per line. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -8925,6 +8925,97 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { NoBinPacking); } +TEST_F(FormatTest, FormatsDeclarationBreakAlways) { + FormatStyle BreakAlways = getGoogleStyle(); + BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine; owenca wrote: ```suggestion BreakAlways.BinPackParameters = FormatStyle::BPPS_Never; ``` https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -128,25 +128,6 @@ static bool startsSegmentOfBuilderTypeCall(const FormatToken &Tok) { return Tok.isMemberAccess() && Tok.Previous && Tok.Previous->closesScope(); } -// Returns \c true if \c Current starts a new parameter. -static bool startsNextParameter(const FormatToken &Current, -const FormatStyle &Style) { - assert(Current.Previous); - const auto &Previous = *Current.Previous; - if (Current.is(TT_CtorInitializerComma) && - Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma) { -return true; - } - if (Style.Language == FormatStyle::LK_Proto && Current.is(TT_SelectorName)) -return true; - return Previous.is(tok::comma) && !Current.isTrailingComment() && - ((Previous.isNot(TT_CtorInitializerComma) || - Style.BreakConstructorInitializers != - FormatStyle::BCIS_BeforeComma) && - (Previous.isNot(TT_InheritanceComma) || - Style.BreakInheritanceList != FormatStyle::BILS_BeforeComma)); -} - owenca wrote: There's no need to move it to `FormatToken.h`. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -8244,7 +8244,7 @@ TEST_F(FormatTest, BreakConstructorInitializersAfterColon) { "a(aa, aa,\n" " aa) {}", OnePerLine); - OnePerLine.BinPackParameters = false; + OnePerLine.BinPackParameters = FormatStyle::BPPS_Never; owenca wrote: Ditto. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -8925,6 +8925,97 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { NoBinPacking); } +TEST_F(FormatTest, FormatsDeclarationBreakAlways) { + FormatStyle BreakAlways = getGoogleStyle(); + BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine; + verifyFormat("void f(int a,\n" + " int b);", + BreakAlways); + verifyFormat("void f(int aa,\n" + " int b,\n" + " int );", + BreakAlways); + + // Ensure AlignAFterOpenBracket interacts correctly with + // PackParameters set to BreakAlways. owenca wrote: ```suggestion // Ensure AlignAfterOpenBracket interacts correctly with BinPackParameters set // to BPPS_Never. ``` https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -8925,6 +8925,97 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { NoBinPacking); } +TEST_F(FormatTest, FormatsDeclarationBreakAlways) { + FormatStyle BreakAlways = getGoogleStyle(); + BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine; + verifyFormat("void f(int a,\n" + " int b);", + BreakAlways); + verifyFormat("void f(int aa,\n" + " int b,\n" + " int );", + BreakAlways); + + // Ensure AlignAFterOpenBracket interacts correctly with + // PackParameters set to BreakAlways. + BreakAlways.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak; + verifyFormat( + "void someLongFunctionName(\n" + "int a,\n" + "int b);", + BreakAlways); + BreakAlways.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent; + verifyFormat( + "void someLongFunctionName(\n" + "int a,\n" + "int b\n" + ");", + BreakAlways); +} + +TEST_F(FormatTest, FormatsDefinitionBreakAlways) { + FormatStyle BreakAlways = getGoogleStyle(); + BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine; owenca wrote: ```suggestion BreakAlways.BinPackParameters = FormatStyle::BPPS_Never; ``` https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -1850,7 +1863,7 @@ FormatStyle getMozillaStyle() { MozillaStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_TopLevel; MozillaStyle.BinPackArguments = false; - MozillaStyle.BinPackParameters = false; + MozillaStyle.BinPackParameters = FormatStyle::BPPS_Never; owenca wrote: Ditto. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -8925,6 +8925,97 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { NoBinPacking); } +TEST_F(FormatTest, FormatsDeclarationBreakAlways) { + FormatStyle BreakAlways = getGoogleStyle(); + BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine; + verifyFormat("void f(int a,\n" + " int b);", + BreakAlways); + verifyFormat("void f(int aa,\n" + " int b,\n" + " int );", + BreakAlways); + + // Ensure AlignAFterOpenBracket interacts correctly with + // PackParameters set to BreakAlways. + BreakAlways.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak; + verifyFormat( + "void someLongFunctionName(\n" + "int a,\n" + "int b);", + BreakAlways); + BreakAlways.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent; + verifyFormat( + "void someLongFunctionName(\n" + "int a,\n" + "int b\n" + ");", + BreakAlways); +} + +TEST_F(FormatTest, FormatsDefinitionBreakAlways) { + FormatStyle BreakAlways = getGoogleStyle(); + BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine; + verifyFormat("void f(int a,\n" + " int b) {\n" + " f(a, b);\n" + "}", + BreakAlways); + + // Ensure BinPackArguments interact correctly when BinPackParameters is set to + // BreakAlways. + verifyFormat("void f(int aa,\n" + " int b,\n" + " int ) {\n" + " f(aa, b,\n" + ");\n" + "}", + BreakAlways); + BreakAlways.BinPackArguments = false; + verifyFormat("void f(int aa,\n" + " int b,\n" + " int ) {\n" + " f(aa,\n" + "b,\n" + ");\n" + "}", + BreakAlways); + + // Ensure BreakFunctionDefinitionParameters interacts correctly when + // BinPackParameters is set to BreakAlways + BreakAlways.BreakFunctionDefinitionParameters = true; + verifyFormat("void f(\n" + "int a,\n" + "int b) {\n" + " f(a, b);\n" + "}", + BreakAlways); + BreakAlways.BreakFunctionDefinitionParameters = false; + + // Ensure AlignAFterOpenBracket interacts correctly with + // BinPackParameters set to BreakAlways. owenca wrote: ```suggestion // Ensure AlignAfterOpenBracket interacts correctly with BinPackParameters set // to BPPS_Never. ``` https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -7954,7 +7954,7 @@ TEST_F(FormatTest, AllowAllArgumentsOnNextLine) { } // This parameter should not affect declarations. - Style.BinPackParameters = false; + Style.BinPackParameters = FormatStyle::BPPS_Never; owenca wrote: Ditto. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -8925,6 +8925,97 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { NoBinPacking); } +TEST_F(FormatTest, FormatsDeclarationBreakAlways) { + FormatStyle BreakAlways = getGoogleStyle(); + BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine; + verifyFormat("void f(int a,\n" + " int b);", + BreakAlways); + verifyFormat("void f(int aa,\n" + " int b,\n" + " int );", + BreakAlways); + + // Ensure AlignAFterOpenBracket interacts correctly with + // PackParameters set to BreakAlways. + BreakAlways.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak; + verifyFormat( + "void someLongFunctionName(\n" + "int a,\n" + "int b);", + BreakAlways); + BreakAlways.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent; + verifyFormat( + "void someLongFunctionName(\n" + "int a,\n" + "int b\n" + ");", + BreakAlways); +} + +TEST_F(FormatTest, FormatsDefinitionBreakAlways) { + FormatStyle BreakAlways = getGoogleStyle(); + BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine; + verifyFormat("void f(int a,\n" + " int b) {\n" + " f(a, b);\n" + "}", + BreakAlways); + + // Ensure BinPackArguments interact correctly when BinPackParameters is set to + // BreakAlways. + verifyFormat("void f(int aa,\n" + " int b,\n" + " int ) {\n" + " f(aa, b,\n" + ");\n" + "}", + BreakAlways); + BreakAlways.BinPackArguments = false; + verifyFormat("void f(int aa,\n" + " int b,\n" + " int ) {\n" + " f(aa,\n" + "b,\n" + ");\n" + "}", + BreakAlways); + + // Ensure BreakFunctionDefinitionParameters interacts correctly when + // BinPackParameters is set to BreakAlways owenca wrote: ```suggestion // BinPackParameters is set to BPPS_Never. ``` https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -7694,7 +7694,7 @@ TEST_F(FormatTest, ConstructorInitializers) { ": a(aa, aa,\n" "aa) {}", OnePerLine); - OnePerLine.BinPackParameters = false; + OnePerLine.BinPackParameters = FormatStyle::BPPS_Never; owenca wrote: Ditto. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -2338,7 +2338,7 @@ TEST_F(FormatTest, FormatsForLoop) { "for (const Foo &baz = in.value(); !baz.at_end(); ++baz) {\n}"); FormatStyle NoBinPacking = getLLVMStyle(); - NoBinPacking.BinPackParameters = false; + NoBinPacking.BinPackParameters = FormatStyle::BPPS_Never; owenca wrote: Ditto. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -362,6 +362,26 @@ TEST_F(FormatTestComments, KeepsParameterWithTrailingCommentsOnTheirOwnLine) { format("aa((,\n" "), //\n" ", b);")); + + FormatStyle BreakAlways = getLLVMStyle(); + BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine; + EXPECT_EQ("SomeFunction(a,\n" +" b, // comment\n" +" c,\n" +" d);", +format("SomeFunction(a,\n" + " b, // comment\n" + " c, d);", + BreakAlways)); + EXPECT_EQ("SomeFunction(a,\n" +" b,\n" +" // comment\n" +" c);", +format("SomeFunction(a,\n" + " b,\n" + " // comment\n" + " c);", + BreakAlways)); owenca wrote: Please use `verifyFormat()` instead. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -7165,7 +7165,7 @@ TEST_F(FormatTest, LineBreakingInBinaryExpressions) { "}"); FormatStyle OnePerLine = getLLVMStyle(); - OnePerLine.BinPackParameters = false; + OnePerLine.BinPackParameters = FormatStyle::BPPS_Never; owenca wrote: Ditto. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
owenca wrote: > > Whilst I can understand BinPackParameters being deprecated, as its one of > > the original options I do worry a little about just how much impact such a > > deprecation might have... it needs to be completely seemless because there > > is ALOT of documentation references to its use on say stackoverflow. etc... > > One reason I suggested making the change without renaming the option was > > the level of flux the name change was having. > > I had never reviewed a similar PR (until #96804) let alone having worked on > one. Now I understand it's better to keep the option name even if it's > confusing. Actually, we renamed boolean options before when extending them to `enum`s, e.g. [`AlwaysBreakTemplateDeclarations`](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#alwaysbreaktemplatedeclarations). So I guess it depends on whether or not the old name would be confusing enough. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Split invalid-cpu-note tests (PR #104601)
@@ -0,0 +1,90 @@ +// Use --implicit-check-not to ensure no additional CPUs are in this list + +// RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --implicit-check-not={{[a-zA-Z0-9]}} +// RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --implicit-check-not={{[a-zA-Z0-9]}} + +// CHECK: error: unknown target CPU 'not-a-cpu' +// CHECK-NEXT: note: valid target CPU values are: +// CHECK-SAME: a64fx, lenary wrote: I can use the caret pattern, but i'm keen to leave each CPU on one line to make diffs easier and clearer (so there's no rewrapping diffs) https://github.com/llvm/llvm-project/pull/104601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)
@@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -fsyntax-only %s + +auto f() { return 43273096 / 65536j; } cor3ntin wrote: can you move that to , for example `clang/test/SemaCXX/constant-expression-cxx11.cpp` and make sure that actually always get evaluated? maybe `constexpr auto a = `43273096 / 65536j;` https://github.com/llvm/llvm-project/pull/104666 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)
cor3ntin wrote: This change needs a release note. Please add an entry to `clang/docs/ReleaseNotes.rst` in the section the most adapted to the change, and referencing any Github issue this change fixes. Thanks! The fix itself looks good https://github.com/llvm/llvm-project/pull/104666 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -128,25 +128,6 @@ static bool startsSegmentOfBuilderTypeCall(const FormatToken &Tok) { return Tok.isMemberAccess() && Tok.Previous && Tok.Previous->closesScope(); } -// Returns \c true if \c Current starts a new parameter. -static bool startsNextParameter(const FormatToken &Current, -const FormatStyle &Style) { - assert(Current.Previous); - const auto &Previous = *Current.Previous; - if (Current.is(TT_CtorInitializerComma) && - Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma) { -return true; - } - if (Style.Language == FormatStyle::LK_Proto && Current.is(TT_SelectorName)) -return true; - return Previous.is(tok::comma) && !Current.isTrailingComment() && - ((Previous.isNot(TT_CtorInitializerComma) || - Style.BreakConstructorInitializers != - FormatStyle::BCIS_BeforeComma) && - (Previous.isNot(TT_InheritanceComma) || - Style.BreakInheritanceList != FormatStyle::BILS_BeforeComma)); -} - VolatileAcorn wrote: I'm not sure what the alternative is here? I moved it so that it could be used in TokenAnnotator.cpp for the always break behavior. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Add a check for invalid default features (PR #104435)
https://github.com/tmatheson-arm updated https://github.com/llvm/llvm-project/pull/104435 >From f79eb28441491f1625691886cc92bd05d3b3cb6a Mon Sep 17 00:00:00 2001 From: Tomas Matheson Date: Thu, 15 Aug 2024 13:41:31 +0100 Subject: [PATCH 01/18] [AArch64] Add a check for invalid default features This adds a check that all ExtensionWithMArch which are marked as implied features for an architecture are also present in the list of default features. It doesn't make sense to have something mandatory but not on by default. There were a number of existing cases that violated this rule, and some changes to which features are mandatory (indicated by the Implies field): > FEAT_SPECRES is mandatory from Armv8.5. FeaturePredRes is added to the HasV8_5aOps.DefaultExts. > FEAT_DIT is mandatory from Armv8.4. FeatureDIT is added to the HasV8_4aOps.DefaultExts. FEAT_SSBS is not mandatory for any architecture. https://reviews.llvm.org/D54629 says it is mandatory for 8.5-a but I can't see that in the Arm ARM. FeatureSSBS is removed from Implied and added to HasV8_5aOps.DefaultExts. Cortex-A710 does not appear to have SSBS https://developer.arm.com/documentation/101800/0201/The-Cortex-A710--core/Cortex-A710--core-features?lang=en Removed from the Cortex-A710 and Oryon print-supported-extensions tests. https://developer.apple.com/download/apple-silicon-cpu-optimization-guide/ Added to Apple A15/A16/A17 and (presumably?) M4 processor features. > FEAT_BTI is mandatory from Armv8.5. FeatureBranchTargetId is added to the DefaultExts > FEAT_FlagM is mandatory from Armv8.4. FeatureFlagM is added to the DefaultExts > In an Armv8.4 implementation, if FEAT_AdvSIMD is implemented, FEAT_DotProd is > implemented. FeatureDotProd is added to the HasV8_4aOps.DefaultExts. FIXME what about nofp here? > FEAT_SB is mandatory from Armv8.5. FeatureSB is added to HasV8_5aOps.DefaultExts. Therefore it appears on the `-cc1` command line for `-march=armv8.5a+nosb`. > FEAT_WFxT is mandatory from Armv8.7. FeatureWFxT is added to HasV8_7aOps.DefaultExts and HasV9_2aOps.DefaultExts. > FEAT_CCIDX is OPTIONAL from Armv8.2. Removed from Implies and added to HasV8_3aOps.DefaultExts and HasV8_0rOps.DefaultExts. For v8-R, FEAT_CCIDX is not mandatory, removed. - Not implemented by cortex-r82, removed: https://developer.arm.com/documentation/102670/0300/?lang=en - Ditto cortex-r82ae --- clang/test/CodeGen/aarch64-targetattr.c | 12 +++ clang/test/Driver/arm-sb.c| 2 +- .../aarch64-cortex-a710.c | 1 - .../aarch64-cortex-r82.c | 1 - .../aarch64-cortex-r82ae.c| 1 - .../aarch64-oryon-1.c | 1 - .../Preprocessor/aarch64-target-features.c| 4 +-- llvm/lib/Target/AArch64/AArch64Features.td| 16 +- llvm/lib/Target/AArch64/AArch64Processors.td | 11 --- llvm/test/MC/AArch64/armv8.5a-ssbs-error.s| 2 +- llvm/test/MC/AArch64/armv8.5a-ssbs.s | 2 +- .../MC/Disassembler/AArch64/armv8.5a-ssbs.txt | 2 +- .../TargetParser/TargetParserTest.cpp | 21 ++-- llvm/utils/TableGen/ARMTargetDefEmitter.cpp | 32 +-- 14 files changed, 67 insertions(+), 41 deletions(-) diff --git a/clang/test/CodeGen/aarch64-targetattr.c b/clang/test/CodeGen/aarch64-targetattr.c index 4f891f938b6186..d6227be2ebef83 100644 --- a/clang/test/CodeGen/aarch64-targetattr.c +++ b/clang/test/CodeGen/aarch64-targetattr.c @@ -195,19 +195,19 @@ void minusarch() {} // CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" } // CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a" } // CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a" } -// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a" } -// CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="cortex-a710" "target-features"="+bf16,+complxnum,+crc,+dotprod,+ete,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+mte,+neon,+pauth,+perfmon,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm,+trbe,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8a,+v9a" } +// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-siz
[clang] [clang][NFC] Split invalid-cpu-note tests (PR #104601)
@@ -0,0 +1,90 @@ +// Use --implicit-check-not to ensure no additional CPUs are in this list + +// RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --implicit-check-not={{[a-zA-Z0-9]}} +// RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --implicit-check-not={{[a-zA-Z0-9]}} + +// CHECK: error: unknown target CPU 'not-a-cpu' +// CHECK-NEXT: note: valid target CPU values are: +// CHECK-SAME: a64fx, tmatheson-arm wrote: Tbh, the `--implicit-check-not` method looks cleaner to me than having `{{^}}` on every line. But it only works because there is so little output for this test to it can all be checked. There might be a case for adding (not in this PR) something like `CHECK-SAME-NEXT:` which would be useful across a large class of tests. The `-target-feature` tests could benefit from this too. https://github.com/llvm/llvm-project/pull/104601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -1978,6 +1978,25 @@ inline bool continuesLineComment(const FormatToken &FormatTok, FormatTok.OriginalColumn >= MinContinueColumn; } +// Returns \c true if \c Current starts a new parameter. +static bool startsNextParameter(const FormatToken &Current, owenca wrote: ```suggestion bool startsNextParameter(const FormatToken &Current, ``` https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -128,25 +128,6 @@ static bool startsSegmentOfBuilderTypeCall(const FormatToken &Tok) { return Tok.isMemberAccess() && Tok.Previous && Tok.Previous->closesScope(); } -// Returns \c true if \c Current starts a new parameter. -static bool startsNextParameter(const FormatToken &Current, -const FormatStyle &Style) { - assert(Current.Previous); - const auto &Previous = *Current.Previous; - if (Current.is(TT_CtorInitializerComma) && - Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma) { -return true; - } - if (Style.Language == FormatStyle::LK_Proto && Current.is(TT_SelectorName)) -return true; - return Previous.is(tok::comma) && !Current.isTrailingComment() && - ((Previous.isNot(TT_CtorInitializerComma) || - Style.BreakConstructorInitializers != - FormatStyle::BCIS_BeforeComma) && - (Previous.isNot(TT_InheritanceComma) || - Style.BreakInheritanceList != FormatStyle::BILS_BeforeComma)); -} - owenca wrote: Oops! For some reason I missed that. Then just drop the `static` after the move. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -1192,20 +1192,36 @@ struct FormatStyle { /// \version 3.7 bool BinPackArguments; - /// If ``false``, a function declaration's or function definition's - /// parameters will either all be on the same line or will have one line each. - /// \code - /// true: - /// void f(int , int , - /// int aaa) {} - /// - /// false: - /// void f(int , - /// int , - /// int aaa) {} - /// \endcode + /// Different way to try to fit all parameters on a line. + enum BinPackParametersStyle : int8_t { +/// Put all parameters on the current line if they fit. +/// Otherwise, put each one on its own line. +/// \code +///void f(int a, int b, int c); +/// +///void f(int a, +/// int b, +/// int c); +/// \endcode +BPPS_Never, VolatileAcorn wrote: What do you think about making it consistent with `PackConstructorInitializers`? I think the `CurrentLine` name removes ambiguity, `OnePerLine` could mean 2 different things. If we followed `PackConstructorInitializers` it would become like this: - `true` becomes `BPPS_BinPack` - `false` becomes `BPPS_CurrentLine` - `BPPS_Never` is new and means always one per line https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)
https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/104666 >From b58b9c3ad5fb2b37715ba9f52c905b6961159f0c Mon Sep 17 00:00:00 2001 From: c8ef Date: Sat, 17 Aug 2024 05:42:39 + Subject: [PATCH 1/2] [clang] fix divide by zero in ComplexExprEvaluator --- clang/lib/AST/ExprConstant.cpp | 7 --- clang/test/SemaCXX/complex-div.cpp | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 clang/test/SemaCXX/complex-div.cpp diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7bfc63ffd81e28..aa902280f1861e 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15567,12 +15567,13 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { HandleComplexComplexDiv(A, B, C, D, ResR, ResI); } } else { - if (RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0) -return Error(E, diag::note_expr_divide_by_zero); - ComplexValue LHS = Result; APSInt Den = RHS.getComplexIntReal() * RHS.getComplexIntReal() + RHS.getComplexIntImag() * RHS.getComplexIntImag(); + if ((RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0) || + Den.isZero()) +return Error(E, diag::note_expr_divide_by_zero); + Result.getComplexIntReal() = (LHS.getComplexIntReal() * RHS.getComplexIntReal() + LHS.getComplexIntImag() * RHS.getComplexIntImag()) / Den; diff --git a/clang/test/SemaCXX/complex-div.cpp b/clang/test/SemaCXX/complex-div.cpp new file mode 100644 index 00..a5f9a79b8ebde0 --- /dev/null +++ b/clang/test/SemaCXX/complex-div.cpp @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -fsyntax-only %s + +auto f() { return 43273096 / 65536j; } >From 8a0be6659ac649e45b7a04458c3266f9ba5d6315 Mon Sep 17 00:00:00 2001 From: c8ef Date: Sat, 17 Aug 2024 09:37:18 + Subject: [PATCH 2/2] address CR comment --- clang/docs/ReleaseNotes.rst | 1 + clang/test/SemaCXX/complex-div.cpp | 3 --- clang/test/SemaCXX/constant-expression-cxx11.cpp | 3 +++ 3 files changed, 4 insertions(+), 3 deletions(-) delete mode 100644 clang/test/SemaCXX/complex-div.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ffdd063ec99037..71a7abc8db166a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -264,6 +264,7 @@ Bug Fixes to C++ Support - Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter. - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). +- Fixed a crash that occurred when dividing by zero in complex integer division. (#GH55390). Bug Fixes to AST Handling ^ diff --git a/clang/test/SemaCXX/complex-div.cpp b/clang/test/SemaCXX/complex-div.cpp deleted file mode 100644 index a5f9a79b8ebde0..00 --- a/clang/test/SemaCXX/complex-div.cpp +++ /dev/null @@ -1,3 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only %s - -auto f() { return 43273096 / 65536j; } diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index d87bd8c6f3..44ef540f41fa8c 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -1268,6 +1268,9 @@ constexpr complex_wrap makeComplexWrap(int re, int im) { static_assert(makeComplexWrap(1,0) == complex(1), ""); static_assert(makeComplexWrap(1,0) != complex(0, 1), ""); +constexpr auto GH55390 = 1 / 65536j; // expected-note {{division by zero}} \ + // expected-error {{constexpr variable 'GH55390' must be initialized by a constant expression}} \ + // expected-warning {{imaginary constants are a GNU extension}} } namespace PR11595 { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)
@@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -fsyntax-only %s + +auto f() { return 43273096 / 65536j; } c8ef wrote: Thank you for your suggestion! I have relocated the test case and included the relevant release note. https://github.com/llvm/llvm-project/pull/104666 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -1192,20 +1192,36 @@ struct FormatStyle { /// \version 3.7 bool BinPackArguments; - /// If ``false``, a function declaration's or function definition's - /// parameters will either all be on the same line or will have one line each. - /// \code - /// true: - /// void f(int , int , - /// int aaa) {} - /// - /// false: - /// void f(int , - /// int , - /// int aaa) {} - /// \endcode + /// Different way to try to fit all parameters on a line. + enum BinPackParametersStyle : int8_t { +/// Put all parameters on the current line if they fit. +/// Otherwise, put each one on its own line. +/// \code +///void f(int a, int b, int c); +/// +///void f(int a, +/// int b, +/// int c); +/// \endcode +BPPS_Never, owenca wrote: I reviewed what I did with `PackConstructorInitializers` but didn't suggest `CurrentLine` over `OnePerLine` even though the latter was also confusing. (That's why I also suggested changing the option name to `PackParameters`.) I'll leave it to you as long as other reviewers have no objections. https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)
https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/104666 >From b58b9c3ad5fb2b37715ba9f52c905b6961159f0c Mon Sep 17 00:00:00 2001 From: c8ef Date: Sat, 17 Aug 2024 05:42:39 + Subject: [PATCH 1/3] [clang] fix divide by zero in ComplexExprEvaluator --- clang/lib/AST/ExprConstant.cpp | 7 --- clang/test/SemaCXX/complex-div.cpp | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 clang/test/SemaCXX/complex-div.cpp diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7bfc63ffd81e28..aa902280f1861e 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -15567,12 +15567,13 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { HandleComplexComplexDiv(A, B, C, D, ResR, ResI); } } else { - if (RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0) -return Error(E, diag::note_expr_divide_by_zero); - ComplexValue LHS = Result; APSInt Den = RHS.getComplexIntReal() * RHS.getComplexIntReal() + RHS.getComplexIntImag() * RHS.getComplexIntImag(); + if ((RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0) || + Den.isZero()) +return Error(E, diag::note_expr_divide_by_zero); + Result.getComplexIntReal() = (LHS.getComplexIntReal() * RHS.getComplexIntReal() + LHS.getComplexIntImag() * RHS.getComplexIntImag()) / Den; diff --git a/clang/test/SemaCXX/complex-div.cpp b/clang/test/SemaCXX/complex-div.cpp new file mode 100644 index 00..a5f9a79b8ebde0 --- /dev/null +++ b/clang/test/SemaCXX/complex-div.cpp @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -fsyntax-only %s + +auto f() { return 43273096 / 65536j; } >From 8a0be6659ac649e45b7a04458c3266f9ba5d6315 Mon Sep 17 00:00:00 2001 From: c8ef Date: Sat, 17 Aug 2024 09:37:18 + Subject: [PATCH 2/3] address CR comment --- clang/docs/ReleaseNotes.rst | 1 + clang/test/SemaCXX/complex-div.cpp | 3 --- clang/test/SemaCXX/constant-expression-cxx11.cpp | 3 +++ 3 files changed, 4 insertions(+), 3 deletions(-) delete mode 100644 clang/test/SemaCXX/complex-div.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ffdd063ec99037..71a7abc8db166a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -264,6 +264,7 @@ Bug Fixes to C++ Support - Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter. - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). +- Fixed a crash that occurred when dividing by zero in complex integer division. (#GH55390). Bug Fixes to AST Handling ^ diff --git a/clang/test/SemaCXX/complex-div.cpp b/clang/test/SemaCXX/complex-div.cpp deleted file mode 100644 index a5f9a79b8ebde0..00 --- a/clang/test/SemaCXX/complex-div.cpp +++ /dev/null @@ -1,3 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only %s - -auto f() { return 43273096 / 65536j; } diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index d87bd8c6f3..44ef540f41fa8c 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -1268,6 +1268,9 @@ constexpr complex_wrap makeComplexWrap(int re, int im) { static_assert(makeComplexWrap(1,0) == complex(1), ""); static_assert(makeComplexWrap(1,0) != complex(0, 1), ""); +constexpr auto GH55390 = 1 / 65536j; // expected-note {{division by zero}} \ + // expected-error {{constexpr variable 'GH55390' must be initialized by a constant expression}} \ + // expected-warning {{imaginary constants are a GNU extension}} } namespace PR11595 { >From 73a9f7bb42d10ec2df2f2f1f2d5fc9ae939d266b Mon Sep 17 00:00:00 2001 From: c8ef Date: Sat, 17 Aug 2024 09:43:40 + Subject: [PATCH 3/3] relocate note --- clang/docs/ReleaseNotes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 71a7abc8db166a..c28fbd881eda86 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -264,11 +264,12 @@ Bug Fixes to C++ Support - Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter. - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). -- Fixed a crash that occurred when dividing by zero in complex integer division. (#GH55390). Bug Fixes to AST Handling ^ +- Fixed a crash that occurred when
[clang] [clang-format] Change GNU style language standard to LS_Latest (PR #104669)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/104669 Fixes #104655. >From d7c7c0da69864067999ecd9b1621fdbb85d4d365 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sat, 17 Aug 2024 02:32:19 -0700 Subject: [PATCH] [clang-format] Change GNU style language standard to LS_Latest Fixes #104655. --- clang/lib/Format/Format.cpp | 1 - clang/unittests/Format/TokenAnnotatorTest.cpp | 8 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 5358b35c19de25..e8fe17ecee1837 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1904,7 +1904,6 @@ FormatStyle getGNUStyle() { Style.Cpp11BracedListStyle = false; Style.FixNamespaceComments = false; Style.SpaceBeforeParens = FormatStyle::SBPO_Always; - Style.Standard = FormatStyle::LS_Cpp03; return Style; } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 256bbd49c424fa..c40df0794ab9ae 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -3360,6 +3360,14 @@ TEST_F(TokenAnnotatorTest, TypenameMacro) { EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_Unknown); } +TEST_F(TokenAnnotatorTest, GNULanguageStandard) { + auto Style = getGNUStyle(); + EXPECT_EQ(Style.Standard, FormatStyle::LS_Latest); + + auto Tokens = annotate("return 1 <=> 2;", Style); + EXPECT_TOKEN(Tokens[2], tok::spaceship, TT_BinaryOperator); +} + } // namespace } // namespace format } // namespace clang ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change GNU style language standard to LS_Latest (PR #104669)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) Changes Fixes #104655. --- Full diff: https://github.com/llvm/llvm-project/pull/104669.diff 2 Files Affected: - (modified) clang/lib/Format/Format.cpp (-1) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+8) ``diff diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 5358b35c19de25..e8fe17ecee1837 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1904,7 +1904,6 @@ FormatStyle getGNUStyle() { Style.Cpp11BracedListStyle = false; Style.FixNamespaceComments = false; Style.SpaceBeforeParens = FormatStyle::SBPO_Always; - Style.Standard = FormatStyle::LS_Cpp03; return Style; } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 256bbd49c424fa..c40df0794ab9ae 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -3360,6 +3360,14 @@ TEST_F(TokenAnnotatorTest, TypenameMacro) { EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_Unknown); } +TEST_F(TokenAnnotatorTest, GNULanguageStandard) { + auto Style = getGNUStyle(); + EXPECT_EQ(Style.Standard, FormatStyle::LS_Latest); + + auto Tokens = annotate("return 1 <=> 2;", Style); + EXPECT_TOKEN(Tokens[2], tok::spaceship, TT_BinaryOperator); +} + } // namespace } // namespace format } // namespace clang `` https://github.com/llvm/llvm-project/pull/104669 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -1192,20 +1192,36 @@ struct FormatStyle { /// \version 3.7 bool BinPackArguments; - /// If ``false``, a function declaration's or function definition's - /// parameters will either all be on the same line or will have one line each. - /// \code - /// true: - /// void f(int , int , - /// int aaa) {} - /// - /// false: - /// void f(int , - /// int , - /// int aaa) {} - /// \endcode + /// Different way to try to fit all parameters on a line. + enum BinPackParametersStyle : int8_t { +/// Put all parameters on the current line if they fit. +/// Otherwise, put each one on its own line. +/// \code +///void f(int a, int b, int c); +/// +///void f(int a, +/// int b, +/// int c); +/// \endcode +BPPS_Never, VolatileAcorn wrote: @mydeveloperday @HazardyKnusperkeks Which names for the values do you prefer? https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change GNU style language standard to LS_Latest (PR #104669)
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/104669 >From d7c7c0da69864067999ecd9b1621fdbb85d4d365 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sat, 17 Aug 2024 02:32:19 -0700 Subject: [PATCH 1/2] [clang-format] Change GNU style language standard to LS_Latest Fixes #104655. --- clang/lib/Format/Format.cpp | 1 - clang/unittests/Format/TokenAnnotatorTest.cpp | 8 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 5358b35c19de25..e8fe17ecee1837 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1904,7 +1904,6 @@ FormatStyle getGNUStyle() { Style.Cpp11BracedListStyle = false; Style.FixNamespaceComments = false; Style.SpaceBeforeParens = FormatStyle::SBPO_Always; - Style.Standard = FormatStyle::LS_Cpp03; return Style; } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 256bbd49c424fa..c40df0794ab9ae 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -3360,6 +3360,14 @@ TEST_F(TokenAnnotatorTest, TypenameMacro) { EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_Unknown); } +TEST_F(TokenAnnotatorTest, GNULanguageStandard) { + auto Style = getGNUStyle(); + EXPECT_EQ(Style.Standard, FormatStyle::LS_Latest); + + auto Tokens = annotate("return 1 <=> 2;", Style); + EXPECT_TOKEN(Tokens[2], tok::spaceship, TT_BinaryOperator); +} + } // namespace } // namespace format } // namespace clang >From 9a5913fd3bf4bb682d4647ad8bf77689a1b9d6ee Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sat, 17 Aug 2024 03:30:21 -0700 Subject: [PATCH 2/2] Update TokenAnnotatorTest.cpp --- clang/unittests/Format/TokenAnnotatorTest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index c40df0794ab9ae..99798de43e70ff 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -3365,6 +3365,7 @@ TEST_F(TokenAnnotatorTest, GNULanguageStandard) { EXPECT_EQ(Style.Standard, FormatStyle::LS_Latest); auto Tokens = annotate("return 1 <=> 2;", Style); + ASSERT_EQ(Tokens.size(), 6u); EXPECT_TOKEN(Tokens[2], tok::spaceship, TT_BinaryOperator); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
@@ -1192,20 +1192,36 @@ struct FormatStyle { /// \version 3.7 bool BinPackArguments; - /// If ``false``, a function declaration's or function definition's - /// parameters will either all be on the same line or will have one line each. - /// \code - /// true: - /// void f(int , int , - /// int aaa) {} - /// - /// false: - /// void f(int , - /// int , - /// int aaa) {} - /// \endcode + /// Different way to try to fit all parameters on a line. + enum BinPackParametersStyle : int8_t { +/// Put all parameters on the current line if they fit. +/// Otherwise, put each one on its own line. +/// \code +///void f(int a, int b, int c); +/// +///void f(int a, +/// int b, +/// int c); +/// \endcode +BPPS_Never, owenca wrote: How about `BinPack` (previously `true`), `OnePerLine` (previously `false`), and `AlwaysOnePerLine`? https://github.com/llvm/llvm-project/pull/101882 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 27d37ee - [clang][NFC] Clean up `Sema` headers
Author: Vlad Serebrennikov Date: 2024-08-17T14:57:59+03:00 New Revision: 27d37ee4d067f42e9a46a0871d3cb961323e5c85 URL: https://github.com/llvm/llvm-project/commit/27d37ee4d067f42e9a46a0871d3cb961323e5c85 DIFF: https://github.com/llvm/llvm-project/commit/27d37ee4d067f42e9a46a0871d3cb961323e5c85.diff LOG: [clang][NFC] Clean up `Sema` headers When various `Sema*.h` and `Sema*.cpp` files were created, cleanup of `Sema.h` includes and forward declarations was left for the later. Now's the time. This commit touches `Sema.h` and Sema components: 1. Unused includes are removed. 2. Unused forward declarations are removed. 3. Missing includes are added (those files are largely IWYU-clean now). 4. Includes were converted into forward declarations where possible. As this commit focuses on headers, all changes to `.cpp` files were minimal, and were aiming at keeping everything buildable. Added: Modified: clang/include/clang/AST/Attr.h clang/include/clang/Sema/Sema.h clang/include/clang/Sema/SemaAMDGPU.h clang/include/clang/Sema/SemaARM.h clang/include/clang/Sema/SemaAVR.h clang/include/clang/Sema/SemaBPF.h clang/include/clang/Sema/SemaCUDA.h clang/include/clang/Sema/SemaCodeCompletion.h clang/include/clang/Sema/SemaHLSL.h clang/include/clang/Sema/SemaHexagon.h clang/include/clang/Sema/SemaLoongArch.h clang/include/clang/Sema/SemaM68k.h clang/include/clang/Sema/SemaMIPS.h clang/include/clang/Sema/SemaMSP430.h clang/include/clang/Sema/SemaNVPTX.h clang/include/clang/Sema/SemaObjC.h clang/include/clang/Sema/SemaOpenACC.h clang/include/clang/Sema/SemaOpenCL.h clang/include/clang/Sema/SemaOpenMP.h clang/include/clang/Sema/SemaPPC.h clang/include/clang/Sema/SemaPseudoObject.h clang/include/clang/Sema/SemaRISCV.h clang/include/clang/Sema/SemaSYCL.h clang/include/clang/Sema/SemaSwift.h clang/include/clang/Sema/SemaSystemZ.h clang/include/clang/Sema/SemaWasm.h clang/include/clang/Sema/SemaX86.h clang/lib/Parse/ParseExpr.cpp clang/lib/Parse/ParseObjc.cpp clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaARM.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprObjC.cpp clang/lib/Sema/SemaLambda.cpp clang/lib/Sema/SemaMIPS.cpp clang/lib/Sema/SemaObjC.cpp clang/lib/Sema/SemaPPC.cpp clang/lib/Sema/SemaSYCL.cpp clang/lib/Sema/SemaTemplateDeduction.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/lib/Sema/SemaType.cpp clang/lib/Sema/SemaX86.cpp Removed: diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h index 8e9b7ad8b46826..bd1851a26ce2e1 100644 --- a/clang/include/clang/AST/Attr.h +++ b/clang/include/clang/AST/Attr.h @@ -372,7 +372,7 @@ class ParamIdx { static_assert(sizeof(ParamIdx) == sizeof(ParamIdx::SerialType), "ParamIdx does not fit its serialization type"); -#include "clang/AST/Attrs.inc" +#include "clang/AST/Attrs.inc" // IWYU pragma: export inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, const Attr *At) { diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index ea297783846641..299a916b9abf8d 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -15,36 +15,42 @@ #define LLVM_CLANG_SEMA_SEMA_H #include "clang/APINotes/APINotesManager.h" -#include "clang/AST/ASTConcept.h" #include "clang/AST/ASTFwd.h" #include "clang/AST/Attr.h" -#include "clang/AST/Availability.h" -#include "clang/AST/ComparisonCategories.h" +#include "clang/AST/AttrIterator.h" +#include "clang/AST/CharUnits.h" +#include "clang/AST/DeclBase.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprConcepts.h" -#include "clang/AST/ExprObjC.h" #include "clang/AST/ExternalASTSource.h" -#include "clang/AST/LocInfoType.h" -#include "clang/AST/MangleNumberingContext.h" -#include "clang/AST/NSAPI.h" -#include "clang/AST/PrettyPrinter.h" +#include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/OperationKinds.h" #include "clang/AST/StmtCXX.h" +#include "clang/AST/Type.h" #include "clang/AST/TypeLoc.h" -#include "clang/AST/TypeOrdering.h" -#include "clang/Basic/BitmaskEnum.h" +#include "clang/Basic/AttrSubjectMatchRules.h" #include "clang/Basic/Builtins.h" +#include "clang/Basic/CapturedStmt.h" #include "clang/Basic/Cuda.h" -#include "clang/Basic/DarwinSDKInfo.h" +#include "clang/Basic/DiagnosticSema.h" +#include "clang/Basic/ExceptionSpecificationType.h" #include "clang/Basic/ExpressionTraits.h" -#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/Lambda.h" +#include "clang/Basic/LangO
[clang] 362142c - [AArch64] Add a check for invalid default features (#104435)
Author: Tomas Matheson Date: 2024-08-17T13:36:40+01:00 New Revision: 362142c4bb5cc657151f592e507f552d5b9f7dde URL: https://github.com/llvm/llvm-project/commit/362142c4bb5cc657151f592e507f552d5b9f7dde DIFF: https://github.com/llvm/llvm-project/commit/362142c4bb5cc657151f592e507f552d5b9f7dde.diff LOG: [AArch64] Add a check for invalid default features (#104435) This adds a check that all ExtensionWithMArch which are marked as implied features for an architecture are also present in the list of default features. It doesn't make sense to have something mandatory but not on by default. There were a number of existing cases that violated this rule, and some changes to which features are mandatory (indicated by the Implies field). This resulted in a bug where if a feature was marked as `Implies` but was not added to `DefaultExt`, then for `-march=base_arch+nofeat` the Driver would consider `feat` to have never been added and therefore would do nothing to disable it (no `-target-feature -feat` would be added, but the backend would enable the feature by default because of `Implies`). See clang/test/Driver/aarch64-negative-modifiers-for-default-features.c. Note that the processor definitions do not respect the architecture DefaultExts. These apply only when specifying `-march=`. So when a feature is moved from `Implies` to `DefaultExts` on the Architecture definition, the feature needs to be added to all processor definitions (that are based on that architecture) in order to preserve the existing behaviour. I have checked the TRMs for many cases (see specific commit messages) but in other cases I have just kept the current behaviour and not tried to fix it. Added: clang/test/Driver/aarch64-negative-modifiers-for-default-features.c Modified: clang/test/CodeGen/aarch64-targetattr.c clang/test/Driver/arm-sb.c clang/test/Driver/print-enabled-extensions/aarch64-apple-a12.c clang/test/Driver/print-enabled-extensions/aarch64-apple-a13.c clang/test/Driver/print-enabled-extensions/aarch64-apple-a14.c clang/test/Driver/print-enabled-extensions/aarch64-apple-a15.c clang/test/Driver/print-enabled-extensions/aarch64-apple-a16.c clang/test/Driver/print-enabled-extensions/aarch64-apple-a17.c clang/test/Driver/print-enabled-extensions/aarch64-apple-m4.c clang/test/Driver/print-enabled-extensions/aarch64-cortex-r82.c clang/test/Driver/print-enabled-extensions/aarch64-cortex-r82ae.c llvm/lib/Target/AArch64/AArch64Features.td llvm/lib/Target/AArch64/AArch64Processors.td llvm/test/MC/AArch64/arm64-system-encoding.s llvm/test/MC/AArch64/armv8.5a-ssbs-error.s llvm/test/MC/AArch64/armv8.5a-ssbs.s llvm/test/MC/Disassembler/AArch64/armv8.5a-ssbs.txt llvm/test/MC/Disassembler/AArch64/basic-a64-instructions.txt llvm/unittests/TargetParser/TargetParserTest.cpp llvm/utils/TableGen/ARMTargetDefEmitter.cpp Removed: diff --git a/clang/test/CodeGen/aarch64-targetattr.c b/clang/test/CodeGen/aarch64-targetattr.c index 4f891f938b6186..d6227be2ebef83 100644 --- a/clang/test/CodeGen/aarch64-targetattr.c +++ b/clang/test/CodeGen/aarch64-targetattr.c @@ -195,19 +195,19 @@ void minusarch() {} // CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" } // CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a" } // CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a" } -// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a" } -// CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="cortex-a710" "target-features"="+bf16,+complxnum,+crc,+dotprod,+ete,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+mte,+neon,+pauth,+perfmon,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm,+trbe,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8a,+v9a" } +// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+bti,+ccidx,+complxnum,+crc,+dit,+dotprod,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+predres,+ras,+rcpc,+rdm,+sb,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a" } +// CH
[clang] [llvm] [AArch64] Add a check for invalid default features (PR #104435)
https://github.com/tmatheson-arm closed https://github.com/llvm/llvm-project/pull/104435 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/102857 >From 1119f0a8d180e482bff45c999d488827ac5ae49e Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Mon, 12 Aug 2024 23:32:34 +0800 Subject: [PATCH 1/5] [Clang][NFCI] Slightly refactor getTemplateInstantiationArgs() --- clang/include/clang/Sema/Sema.h| 12 +--- clang/lib/Sema/SemaConcept.cpp | 2 +- clang/lib/Sema/SemaTemplate.cpp| 2 +- clang/lib/Sema/SemaTemplateInstantiate.cpp | 15 +++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 2ec6367eccea01..352b26b0739ffb 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -13033,11 +13033,14 @@ class Sema final : public SemaBase { /// instantiation arguments. /// /// \param DC In the event we don't HAVE a declaration yet, we instead provide - /// the decl context where it will be created. In this case, the `Innermost` - /// should likely be provided. If ND is non-null, this is ignored. + /// the decl context where it will be created. In this case, the \p + /// Innermost should likely be provided. If \p ND is non-null and \p + /// Innermost is NULL, this is ignored. /// /// \param Innermost if non-NULL, specifies a template argument list for the - /// template declaration passed as ND. + /// template declaration passed as \p ND. The next declaration context would + /// be switched to \p DC if present; otherwise, it would be the semantic + /// declaration context of \p ND. /// /// \param RelativeToPrimary true if we should get the template /// arguments relative to the primary template, even when we're @@ -13053,6 +13056,9 @@ class Sema final : public SemaBase { /// ForConstraintInstantiation indicates we should continue looking when /// encountering a lambda generic call operator, and continue looking for /// arguments on an enclosing class template. + /// + /// \param SkipForSpecialization when specified, any template specializations + /// in a traversal would be ignored. MultiLevelTemplateArgumentList getTemplateInstantiationArgs( const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, std::optional> Innermost = std::nullopt, diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index d4c9d044985e34..929555e94dc35d 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -1482,7 +1482,7 @@ substituteParameterMappings(Sema &S, NormalizedConstraint &N, static bool substituteParameterMappings(Sema &S, NormalizedConstraint &N, const ConceptSpecializationExpr *CSE) { MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs( - CSE->getNamedConcept(), CSE->getNamedConcept()->getLexicalDeclContext(), + CSE->getNamedConcept(), CSE->getNamedConcept()->getDeclContext(), /*Final=*/true, CSE->getTemplateArguments(), /*RelativeToPrimary=*/true, /*Pattern=*/nullptr, diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 1346a4a3f0012a..e6191c8c1397bd 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -5582,7 +5582,7 @@ bool Sema::CheckTemplateArgumentList( CXXThisScopeRAII(*this, RD, ThisQuals, RD != nullptr); MultiLevelTemplateArgumentList MLTAL = getTemplateInstantiationArgs( -Template, NewContext, /*Final=*/true, SugaredConverted, +Template, Template->getDeclContext(), /*Final=*/true, SugaredConverted, /*RelativeToPrimary=*/true, /*Pattern=*/nullptr, /*ForConceptInstantiation=*/true); diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index de470739ab78e7..6cc9fb0ef04b65 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -491,7 +491,8 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs( // has a depth of 0. if (const auto *TTP = dyn_cast(CurDecl)) HandleDefaultTempArgIntoTempTempParam(TTP, Result); -CurDecl = Response::UseNextDecl(CurDecl).NextDecl; +CurDecl = DC ? Decl::castFromDeclContext(DC) + : Response::UseNextDecl(CurDecl).NextDecl; } while (!CurDecl->isFileContextDecl()) { @@ -3242,15 +3243,13 @@ bool Sema::SubstDefaultArgument( /*ForDefinition*/ false); if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs)) return true; - const FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate(); - if (PrimaryTemplate && PrimaryTemplate->isOutOfLine()) { -TemplateArgumentList *CurrentTemplateArgumentList = -TemplateArgumentList::CreateCopy(getASTContext(), - TemplateArgs.
[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/102857 >From 1119f0a8d180e482bff45c999d488827ac5ae49e Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Mon, 12 Aug 2024 23:32:34 +0800 Subject: [PATCH 1/6] [Clang][NFCI] Slightly refactor getTemplateInstantiationArgs() --- clang/include/clang/Sema/Sema.h| 12 +--- clang/lib/Sema/SemaConcept.cpp | 2 +- clang/lib/Sema/SemaTemplate.cpp| 2 +- clang/lib/Sema/SemaTemplateInstantiate.cpp | 15 +++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 2ec6367eccea01..352b26b0739ffb 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -13033,11 +13033,14 @@ class Sema final : public SemaBase { /// instantiation arguments. /// /// \param DC In the event we don't HAVE a declaration yet, we instead provide - /// the decl context where it will be created. In this case, the `Innermost` - /// should likely be provided. If ND is non-null, this is ignored. + /// the decl context where it will be created. In this case, the \p + /// Innermost should likely be provided. If \p ND is non-null and \p + /// Innermost is NULL, this is ignored. /// /// \param Innermost if non-NULL, specifies a template argument list for the - /// template declaration passed as ND. + /// template declaration passed as \p ND. The next declaration context would + /// be switched to \p DC if present; otherwise, it would be the semantic + /// declaration context of \p ND. /// /// \param RelativeToPrimary true if we should get the template /// arguments relative to the primary template, even when we're @@ -13053,6 +13056,9 @@ class Sema final : public SemaBase { /// ForConstraintInstantiation indicates we should continue looking when /// encountering a lambda generic call operator, and continue looking for /// arguments on an enclosing class template. + /// + /// \param SkipForSpecialization when specified, any template specializations + /// in a traversal would be ignored. MultiLevelTemplateArgumentList getTemplateInstantiationArgs( const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, std::optional> Innermost = std::nullopt, diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index d4c9d044985e34..929555e94dc35d 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -1482,7 +1482,7 @@ substituteParameterMappings(Sema &S, NormalizedConstraint &N, static bool substituteParameterMappings(Sema &S, NormalizedConstraint &N, const ConceptSpecializationExpr *CSE) { MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs( - CSE->getNamedConcept(), CSE->getNamedConcept()->getLexicalDeclContext(), + CSE->getNamedConcept(), CSE->getNamedConcept()->getDeclContext(), /*Final=*/true, CSE->getTemplateArguments(), /*RelativeToPrimary=*/true, /*Pattern=*/nullptr, diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 1346a4a3f0012a..e6191c8c1397bd 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -5582,7 +5582,7 @@ bool Sema::CheckTemplateArgumentList( CXXThisScopeRAII(*this, RD, ThisQuals, RD != nullptr); MultiLevelTemplateArgumentList MLTAL = getTemplateInstantiationArgs( -Template, NewContext, /*Final=*/true, SugaredConverted, +Template, Template->getDeclContext(), /*Final=*/true, SugaredConverted, /*RelativeToPrimary=*/true, /*Pattern=*/nullptr, /*ForConceptInstantiation=*/true); diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index de470739ab78e7..6cc9fb0ef04b65 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -491,7 +491,8 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs( // has a depth of 0. if (const auto *TTP = dyn_cast(CurDecl)) HandleDefaultTempArgIntoTempTempParam(TTP, Result); -CurDecl = Response::UseNextDecl(CurDecl).NextDecl; +CurDecl = DC ? Decl::castFromDeclContext(DC) + : Response::UseNextDecl(CurDecl).NextDecl; } while (!CurDecl->isFileContextDecl()) { @@ -3242,15 +3243,13 @@ bool Sema::SubstDefaultArgument( /*ForDefinition*/ false); if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs)) return true; - const FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate(); - if (PrimaryTemplate && PrimaryTemplate->isOutOfLine()) { -TemplateArgumentList *CurrentTemplateArgumentList = -TemplateArgumentList::CreateCopy(getASTContext(), - TemplateArgs.
[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/102857 >From 1119f0a8d180e482bff45c999d488827ac5ae49e Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Mon, 12 Aug 2024 23:32:34 +0800 Subject: [PATCH 1/7] [Clang][NFCI] Slightly refactor getTemplateInstantiationArgs() --- clang/include/clang/Sema/Sema.h| 12 +--- clang/lib/Sema/SemaConcept.cpp | 2 +- clang/lib/Sema/SemaTemplate.cpp| 2 +- clang/lib/Sema/SemaTemplateInstantiate.cpp | 15 +++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 2ec6367eccea01..352b26b0739ffb 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -13033,11 +13033,14 @@ class Sema final : public SemaBase { /// instantiation arguments. /// /// \param DC In the event we don't HAVE a declaration yet, we instead provide - /// the decl context where it will be created. In this case, the `Innermost` - /// should likely be provided. If ND is non-null, this is ignored. + /// the decl context where it will be created. In this case, the \p + /// Innermost should likely be provided. If \p ND is non-null and \p + /// Innermost is NULL, this is ignored. /// /// \param Innermost if non-NULL, specifies a template argument list for the - /// template declaration passed as ND. + /// template declaration passed as \p ND. The next declaration context would + /// be switched to \p DC if present; otherwise, it would be the semantic + /// declaration context of \p ND. /// /// \param RelativeToPrimary true if we should get the template /// arguments relative to the primary template, even when we're @@ -13053,6 +13056,9 @@ class Sema final : public SemaBase { /// ForConstraintInstantiation indicates we should continue looking when /// encountering a lambda generic call operator, and continue looking for /// arguments on an enclosing class template. + /// + /// \param SkipForSpecialization when specified, any template specializations + /// in a traversal would be ignored. MultiLevelTemplateArgumentList getTemplateInstantiationArgs( const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, std::optional> Innermost = std::nullopt, diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index d4c9d044985e34..929555e94dc35d 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -1482,7 +1482,7 @@ substituteParameterMappings(Sema &S, NormalizedConstraint &N, static bool substituteParameterMappings(Sema &S, NormalizedConstraint &N, const ConceptSpecializationExpr *CSE) { MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs( - CSE->getNamedConcept(), CSE->getNamedConcept()->getLexicalDeclContext(), + CSE->getNamedConcept(), CSE->getNamedConcept()->getDeclContext(), /*Final=*/true, CSE->getTemplateArguments(), /*RelativeToPrimary=*/true, /*Pattern=*/nullptr, diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 1346a4a3f0012a..e6191c8c1397bd 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -5582,7 +5582,7 @@ bool Sema::CheckTemplateArgumentList( CXXThisScopeRAII(*this, RD, ThisQuals, RD != nullptr); MultiLevelTemplateArgumentList MLTAL = getTemplateInstantiationArgs( -Template, NewContext, /*Final=*/true, SugaredConverted, +Template, Template->getDeclContext(), /*Final=*/true, SugaredConverted, /*RelativeToPrimary=*/true, /*Pattern=*/nullptr, /*ForConceptInstantiation=*/true); diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index de470739ab78e7..6cc9fb0ef04b65 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -491,7 +491,8 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs( // has a depth of 0. if (const auto *TTP = dyn_cast(CurDecl)) HandleDefaultTempArgIntoTempTempParam(TTP, Result); -CurDecl = Response::UseNextDecl(CurDecl).NextDecl; +CurDecl = DC ? Decl::castFromDeclContext(DC) + : Response::UseNextDecl(CurDecl).NextDecl; } while (!CurDecl->isFileContextDecl()) { @@ -3242,15 +3243,13 @@ bool Sema::SubstDefaultArgument( /*ForDefinition*/ false); if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs)) return true; - const FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate(); - if (PrimaryTemplate && PrimaryTemplate->isOutOfLine()) { -TemplateArgumentList *CurrentTemplateArgumentList = -TemplateArgumentList::CreateCopy(getASTContext(), - TemplateArgs.
[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)
https://github.com/zyn0217 edited https://github.com/llvm/llvm-project/pull/102857 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/102857 >From 1119f0a8d180e482bff45c999d488827ac5ae49e Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Mon, 12 Aug 2024 23:32:34 +0800 Subject: [PATCH 1/8] [Clang][NFCI] Slightly refactor getTemplateInstantiationArgs() --- clang/include/clang/Sema/Sema.h| 12 +--- clang/lib/Sema/SemaConcept.cpp | 2 +- clang/lib/Sema/SemaTemplate.cpp| 2 +- clang/lib/Sema/SemaTemplateInstantiate.cpp | 15 +++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 2ec6367eccea01..352b26b0739ffb 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -13033,11 +13033,14 @@ class Sema final : public SemaBase { /// instantiation arguments. /// /// \param DC In the event we don't HAVE a declaration yet, we instead provide - /// the decl context where it will be created. In this case, the `Innermost` - /// should likely be provided. If ND is non-null, this is ignored. + /// the decl context where it will be created. In this case, the \p + /// Innermost should likely be provided. If \p ND is non-null and \p + /// Innermost is NULL, this is ignored. /// /// \param Innermost if non-NULL, specifies a template argument list for the - /// template declaration passed as ND. + /// template declaration passed as \p ND. The next declaration context would + /// be switched to \p DC if present; otherwise, it would be the semantic + /// declaration context of \p ND. /// /// \param RelativeToPrimary true if we should get the template /// arguments relative to the primary template, even when we're @@ -13053,6 +13056,9 @@ class Sema final : public SemaBase { /// ForConstraintInstantiation indicates we should continue looking when /// encountering a lambda generic call operator, and continue looking for /// arguments on an enclosing class template. + /// + /// \param SkipForSpecialization when specified, any template specializations + /// in a traversal would be ignored. MultiLevelTemplateArgumentList getTemplateInstantiationArgs( const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, std::optional> Innermost = std::nullopt, diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index d4c9d044985e34..929555e94dc35d 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -1482,7 +1482,7 @@ substituteParameterMappings(Sema &S, NormalizedConstraint &N, static bool substituteParameterMappings(Sema &S, NormalizedConstraint &N, const ConceptSpecializationExpr *CSE) { MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs( - CSE->getNamedConcept(), CSE->getNamedConcept()->getLexicalDeclContext(), + CSE->getNamedConcept(), CSE->getNamedConcept()->getDeclContext(), /*Final=*/true, CSE->getTemplateArguments(), /*RelativeToPrimary=*/true, /*Pattern=*/nullptr, diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 1346a4a3f0012a..e6191c8c1397bd 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -5582,7 +5582,7 @@ bool Sema::CheckTemplateArgumentList( CXXThisScopeRAII(*this, RD, ThisQuals, RD != nullptr); MultiLevelTemplateArgumentList MLTAL = getTemplateInstantiationArgs( -Template, NewContext, /*Final=*/true, SugaredConverted, +Template, Template->getDeclContext(), /*Final=*/true, SugaredConverted, /*RelativeToPrimary=*/true, /*Pattern=*/nullptr, /*ForConceptInstantiation=*/true); diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index de470739ab78e7..6cc9fb0ef04b65 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -491,7 +491,8 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs( // has a depth of 0. if (const auto *TTP = dyn_cast(CurDecl)) HandleDefaultTempArgIntoTempTempParam(TTP, Result); -CurDecl = Response::UseNextDecl(CurDecl).NextDecl; +CurDecl = DC ? Decl::castFromDeclContext(DC) + : Response::UseNextDecl(CurDecl).NextDecl; } while (!CurDecl->isFileContextDecl()) { @@ -3242,15 +3243,13 @@ bool Sema::SubstDefaultArgument( /*ForDefinition*/ false); if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs)) return true; - const FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate(); - if (PrimaryTemplate && PrimaryTemplate->isOutOfLine()) { -TemplateArgumentList *CurrentTemplateArgumentList = -TemplateArgumentList::CreateCopy(getASTContext(), - TemplateArgs.
[clang-tools-extra] [clang-tidy] Correct typo in ReleaseNotes.rst (PR #104674)
https://github.com/mikecrowe created https://github.com/llvm/llvm-project/pull/104674 None >From b96dfbca33c5beb5ca3c984bc9388d11f0d7f707 Mon Sep 17 00:00:00 2001 From: Mike Crowe Date: Sat, 17 Aug 2024 17:04:06 +0100 Subject: [PATCH] [clang-tidy] Correct typo in ReleaseNotes.rst --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b72d109b3d3938..0f6b34cf400521 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -106,7 +106,7 @@ Changes in existing checks - Improved :doc:`readability-redundant-smartptr-get ` check to - remove `->`, when reduntant `get()` is removed. + remove `->`, when redundant `get()` is removed. Removed checks ^^ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Correct typo in ReleaseNotes.rst (PR #104674)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Mike Crowe (mikecrowe) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/104674.diff 1 Files Affected: - (modified) clang-tools-extra/docs/ReleaseNotes.rst (+1-1) ``diff diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b72d109b3d3938..0f6b34cf400521 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -106,7 +106,7 @@ Changes in existing checks - Improved :doc:`readability-redundant-smartptr-get ` check to - remove `->`, when reduntant `get()` is removed. + remove `->`, when redundant `get()` is removed. Removed checks ^^ `` https://github.com/llvm/llvm-project/pull/104674 ___ 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 member functions with modernize-use-std-print/format (PR #104675)
https://github.com/mikecrowe created https://github.com/llvm/llvm-project/pull/104675 These checks can be made to work on member functions quite easily and it's not unknown to have at least printf-style functions as members. Let's remove the restriction. >From afdd6c2a12735e1da69a46c6ff78b5d4e0dcdb6e Mon Sep 17 00:00:00 2001 From: Mike Crowe Date: Sun, 21 Jul 2024 20:37:02 +0100 Subject: [PATCH] [clang-tidy] Support member functions with modernize-use-std-print/format These checks can be made to work on member functions quite easily and it's not unknown to have at least printf-style functions as members. Let's remove the restriction. --- .../modernize/UseStdFormatCheck.cpp | 6 +- .../clang-tidy/modernize/UseStdPrintCheck.cpp | 8 +-- clang-tools-extra/docs/ReleaseNotes.rst | 6 ++ .../checks/modernize/use-std-format.rst | 5 +- .../checks/modernize/use-std-print.rst| 15 ++-- .../modernize/use-std-format-member.cpp | 44 .../modernize/use-std-print-member.cpp| 70 +++ 7 files changed, 138 insertions(+), 16 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-member.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-member.cpp diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp index 6cef21f1318a2a..cdb34aef1b0e61 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp @@ -50,8 +50,7 @@ void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( callExpr(argumentCountAtLeast(1), hasArgument(0, stringLiteral(isOrdinary())), - callee(functionDecl(unless(cxxMethodDecl()), - matchers::matchesAnyListedName( + callee(functionDecl(matchers::matchesAnyListedName( StrFormatLikeFunctions)) .bind("func_decl"))) .bind("strformat"), @@ -93,7 +92,8 @@ void UseStdFormatCheck::check(const MatchFinder::MatchResult &Result) { diag(StrFormatCall->getBeginLoc(), "use '%0' instead of %1") << ReplacementFormatFunction << OldFunction->getIdentifier(); Diag << FixItHint::CreateReplacement( - CharSourceRange::getTokenRange(StrFormatCall->getSourceRange()), + CharSourceRange::getTokenRange(StrFormatCall->getExprLoc(), + StrFormatCall->getEndLoc()), ReplacementFormatFunction); Converter.applyFixes(Diag, *Result.SourceManager); diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp index ff990feadc0c1d..16f2f4b3e7d1af 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp @@ -100,8 +100,7 @@ void UseStdPrintCheck::registerMatchers(MatchFinder *Finder) { unusedReturnValue( callExpr(argumentCountAtLeast(1), hasArgument(0, stringLiteral(isOrdinary())), - callee(functionDecl(unless(cxxMethodDecl()), - matchers::matchesAnyListedName( + callee(functionDecl(matchers::matchesAnyListedName( PrintfLikeFunctions)) .bind("func_decl"))) .bind("printf")), @@ -112,8 +111,7 @@ void UseStdPrintCheck::registerMatchers(MatchFinder *Finder) { unusedReturnValue( callExpr(argumentCountAtLeast(2), hasArgument(1, stringLiteral(isOrdinary())), - callee(functionDecl(unless(cxxMethodDecl()), - matchers::matchesAnyListedName( + callee(functionDecl(matchers::matchesAnyListedName( FprintfLikeFunctions)) .bind("func_decl"))) .bind("fprintf")), @@ -152,7 +150,7 @@ void UseStdPrintCheck::check(const MatchFinder::MatchResult &Result) { << ReplacementFunction << OldFunction->getIdentifier(); Diag << FixItHint::CreateReplacement( - CharSourceRange::getTokenRange(PrintfCall->getBeginLoc(), + CharSourceRange::getTokenRange(PrintfCall->getExprLoc(), PrintfCall->getEndLoc()), ReplacementFunction); Converter.applyFixes(Diag, *Result.SourceManager); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b72d109b3d3938..d542ec4e3e1721 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -104,6 +104,12 @@ New chec
[clang-tools-extra] [clang-tidy] Support member functions with modernize-use-std-print/format (PR #104675)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Mike Crowe (mikecrowe) Changes These checks can be made to work on member functions quite easily and it's not unknown to have at least printf-style functions as members. Let's remove the restriction. --- Full diff: https://github.com/llvm/llvm-project/pull/104675.diff 7 Files Affected: - (modified) clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp (+3-3) - (modified) clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp (+3-5) - (modified) clang-tools-extra/docs/ReleaseNotes.rst (+6) - (modified) clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst (+3-2) - (modified) clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst (+9-6) - (added) clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-member.cpp (+44) - (added) clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-member.cpp (+70) ``diff diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp index 6cef21f1318a2a..cdb34aef1b0e61 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp @@ -50,8 +50,7 @@ void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( callExpr(argumentCountAtLeast(1), hasArgument(0, stringLiteral(isOrdinary())), - callee(functionDecl(unless(cxxMethodDecl()), - matchers::matchesAnyListedName( + callee(functionDecl(matchers::matchesAnyListedName( StrFormatLikeFunctions)) .bind("func_decl"))) .bind("strformat"), @@ -93,7 +92,8 @@ void UseStdFormatCheck::check(const MatchFinder::MatchResult &Result) { diag(StrFormatCall->getBeginLoc(), "use '%0' instead of %1") << ReplacementFormatFunction << OldFunction->getIdentifier(); Diag << FixItHint::CreateReplacement( - CharSourceRange::getTokenRange(StrFormatCall->getSourceRange()), + CharSourceRange::getTokenRange(StrFormatCall->getExprLoc(), + StrFormatCall->getEndLoc()), ReplacementFormatFunction); Converter.applyFixes(Diag, *Result.SourceManager); diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp index ff990feadc0c1d..16f2f4b3e7d1af 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp @@ -100,8 +100,7 @@ void UseStdPrintCheck::registerMatchers(MatchFinder *Finder) { unusedReturnValue( callExpr(argumentCountAtLeast(1), hasArgument(0, stringLiteral(isOrdinary())), - callee(functionDecl(unless(cxxMethodDecl()), - matchers::matchesAnyListedName( + callee(functionDecl(matchers::matchesAnyListedName( PrintfLikeFunctions)) .bind("func_decl"))) .bind("printf")), @@ -112,8 +111,7 @@ void UseStdPrintCheck::registerMatchers(MatchFinder *Finder) { unusedReturnValue( callExpr(argumentCountAtLeast(2), hasArgument(1, stringLiteral(isOrdinary())), - callee(functionDecl(unless(cxxMethodDecl()), - matchers::matchesAnyListedName( + callee(functionDecl(matchers::matchesAnyListedName( FprintfLikeFunctions)) .bind("func_decl"))) .bind("fprintf")), @@ -152,7 +150,7 @@ void UseStdPrintCheck::check(const MatchFinder::MatchResult &Result) { << ReplacementFunction << OldFunction->getIdentifier(); Diag << FixItHint::CreateReplacement( - CharSourceRange::getTokenRange(PrintfCall->getBeginLoc(), + CharSourceRange::getTokenRange(PrintfCall->getExprLoc(), PrintfCall->getEndLoc()), ReplacementFunction); Converter.applyFixes(Diag, *Result.SourceManager); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b72d109b3d3938..d542ec4e3e1721 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -104,6 +104,12 @@ New check aliases Changes in existing checks ^^ +- Improved :doc:`modernize-use-std-print + ` and + :doc:`modernize-use-std-print + ` checks to support replacing + member function calls too. + - Improved :doc:`readability-redundant-smartptr-get ` check to remove `->`, when reduntant `get()` is removed. diff -
[clang] [clang][NFC] Split invalid-cpu-note tests (PR #104601)
@@ -0,0 +1,90 @@ +// Use --implicit-check-not to ensure no additional CPUs are in this list + +// RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --implicit-check-not={{[a-zA-Z0-9]}} +// RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --implicit-check-not={{[a-zA-Z0-9]}} + +// CHECK: error: unknown target CPU 'not-a-cpu' +// CHECK-NEXT: note: valid target CPU values are: +// CHECK-SAME: a64fx, MaskRay wrote: Instead of having every CPU one the same line, you can group them by families like: ``` {{^}}, ampere1, ampere1a, ampere1b {{^}}, fooX, fooY, fooZ ``` which still looks quite good. Word diff tools are quite robust, so I think strictly avoiding packing is not necessary. https://github.com/llvm/llvm-project/pull/104601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/102857 >From 1119f0a8d180e482bff45c999d488827ac5ae49e Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Mon, 12 Aug 2024 23:32:34 +0800 Subject: [PATCH 1/9] [Clang][NFCI] Slightly refactor getTemplateInstantiationArgs() --- clang/include/clang/Sema/Sema.h| 12 +--- clang/lib/Sema/SemaConcept.cpp | 2 +- clang/lib/Sema/SemaTemplate.cpp| 2 +- clang/lib/Sema/SemaTemplateInstantiate.cpp | 15 +++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 2ec6367eccea01..352b26b0739ffb 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -13033,11 +13033,14 @@ class Sema final : public SemaBase { /// instantiation arguments. /// /// \param DC In the event we don't HAVE a declaration yet, we instead provide - /// the decl context where it will be created. In this case, the `Innermost` - /// should likely be provided. If ND is non-null, this is ignored. + /// the decl context where it will be created. In this case, the \p + /// Innermost should likely be provided. If \p ND is non-null and \p + /// Innermost is NULL, this is ignored. /// /// \param Innermost if non-NULL, specifies a template argument list for the - /// template declaration passed as ND. + /// template declaration passed as \p ND. The next declaration context would + /// be switched to \p DC if present; otherwise, it would be the semantic + /// declaration context of \p ND. /// /// \param RelativeToPrimary true if we should get the template /// arguments relative to the primary template, even when we're @@ -13053,6 +13056,9 @@ class Sema final : public SemaBase { /// ForConstraintInstantiation indicates we should continue looking when /// encountering a lambda generic call operator, and continue looking for /// arguments on an enclosing class template. + /// + /// \param SkipForSpecialization when specified, any template specializations + /// in a traversal would be ignored. MultiLevelTemplateArgumentList getTemplateInstantiationArgs( const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, std::optional> Innermost = std::nullopt, diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index d4c9d044985e34..929555e94dc35d 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -1482,7 +1482,7 @@ substituteParameterMappings(Sema &S, NormalizedConstraint &N, static bool substituteParameterMappings(Sema &S, NormalizedConstraint &N, const ConceptSpecializationExpr *CSE) { MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs( - CSE->getNamedConcept(), CSE->getNamedConcept()->getLexicalDeclContext(), + CSE->getNamedConcept(), CSE->getNamedConcept()->getDeclContext(), /*Final=*/true, CSE->getTemplateArguments(), /*RelativeToPrimary=*/true, /*Pattern=*/nullptr, diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 1346a4a3f0012a..e6191c8c1397bd 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -5582,7 +5582,7 @@ bool Sema::CheckTemplateArgumentList( CXXThisScopeRAII(*this, RD, ThisQuals, RD != nullptr); MultiLevelTemplateArgumentList MLTAL = getTemplateInstantiationArgs( -Template, NewContext, /*Final=*/true, SugaredConverted, +Template, Template->getDeclContext(), /*Final=*/true, SugaredConverted, /*RelativeToPrimary=*/true, /*Pattern=*/nullptr, /*ForConceptInstantiation=*/true); diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index de470739ab78e7..6cc9fb0ef04b65 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -491,7 +491,8 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs( // has a depth of 0. if (const auto *TTP = dyn_cast(CurDecl)) HandleDefaultTempArgIntoTempTempParam(TTP, Result); -CurDecl = Response::UseNextDecl(CurDecl).NextDecl; +CurDecl = DC ? Decl::castFromDeclContext(DC) + : Response::UseNextDecl(CurDecl).NextDecl; } while (!CurDecl->isFileContextDecl()) { @@ -3242,15 +3243,13 @@ bool Sema::SubstDefaultArgument( /*ForDefinition*/ false); if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs)) return true; - const FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate(); - if (PrimaryTemplate && PrimaryTemplate->isOutOfLine()) { -TemplateArgumentList *CurrentTemplateArgumentList = -TemplateArgumentList::CreateCopy(getASTContext(), - TemplateArgs.
[clang] [Clang] warn on discarded [[nodiscard]] function results after casting in C (PR #104677)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/104677 Fixes #104391 >From cd7ce740464c9c46ab231cf773fd1cf28e3495eb Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 17 Aug 2024 19:43:45 +0300 Subject: [PATCH] [Clang] warn on discarded [[nodiscard]] function results after casting in C --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaStmt.cpp | 3 ++- clang/test/Sema/c2x-nodiscard.c | 6 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ffdd063ec99037..c8c6a98264b3a2 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -214,6 +214,8 @@ Improvements to Clang's diagnostics - Clang now diagnoses the use of ``main`` in an ``extern`` context as invalid according to [basic.start.main] p3. Fixes #GH101512. +- Clang now diagnoses when the result of a [[nodiscard]] function is discarded after being cast in C. Fixes #GH104391. + Improvements to Clang's time-trace -- diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index d283eaa511011b..ba681671eb3290 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -281,7 +281,8 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) { E = WarnExpr; if (const auto *Cast = dyn_cast(E)) if (Cast->getCastKind() == CK_NoOp || -Cast->getCastKind() == CK_ConstructorConversion) +Cast->getCastKind() == CK_ConstructorConversion || +Cast->getCastKind() == CK_IntegralCast) E = Cast->getSubExpr()->IgnoreImpCasts(); if (const CallExpr *CE = dyn_cast(E)) { diff --git a/clang/test/Sema/c2x-nodiscard.c b/clang/test/Sema/c2x-nodiscard.c index cb33c0c242e7db..8b48fe8118dfe7 100644 --- a/clang/test/Sema/c2x-nodiscard.c +++ b/clang/test/Sema/c2x-nodiscard.c @@ -54,3 +54,9 @@ void test_missiles(void) { launch_missiles(); } +[[nodiscard]] int f3(); + +void f4() { +#define M (unsigned int) f3() + M; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] warn on discarded [[nodiscard]] function results after casting in C (PR #104677)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) Changes Fixes #104391 --- Full diff: https://github.com/llvm/llvm-project/pull/104677.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+2) - (modified) clang/lib/Sema/SemaStmt.cpp (+2-1) - (modified) clang/test/Sema/c2x-nodiscard.c (+6) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ffdd063ec99037..c8c6a98264b3a2 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -214,6 +214,8 @@ Improvements to Clang's diagnostics - Clang now diagnoses the use of ``main`` in an ``extern`` context as invalid according to [basic.start.main] p3. Fixes #GH101512. +- Clang now diagnoses when the result of a [[nodiscard]] function is discarded after being cast in C. Fixes #GH104391. + Improvements to Clang's time-trace -- diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index d283eaa511011b..ba681671eb3290 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -281,7 +281,8 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) { E = WarnExpr; if (const auto *Cast = dyn_cast(E)) if (Cast->getCastKind() == CK_NoOp || -Cast->getCastKind() == CK_ConstructorConversion) +Cast->getCastKind() == CK_ConstructorConversion || +Cast->getCastKind() == CK_IntegralCast) E = Cast->getSubExpr()->IgnoreImpCasts(); if (const CallExpr *CE = dyn_cast(E)) { diff --git a/clang/test/Sema/c2x-nodiscard.c b/clang/test/Sema/c2x-nodiscard.c index cb33c0c242e7db..8b48fe8118dfe7 100644 --- a/clang/test/Sema/c2x-nodiscard.c +++ b/clang/test/Sema/c2x-nodiscard.c @@ -54,3 +54,9 @@ void test_missiles(void) { launch_missiles(); } +[[nodiscard]] int f3(); + +void f4() { +#define M (unsigned int) f3() + M; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} +} `` https://github.com/llvm/llvm-project/pull/104677 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Split invalid-cpu-note tests (PR #104601)
@@ -0,0 +1,90 @@ +// Use --implicit-check-not to ensure no additional CPUs are in this list + +// RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --implicit-check-not={{[a-zA-Z0-9]}} +// RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --implicit-check-not={{[a-zA-Z0-9]}} + +// CHECK: error: unknown target CPU 'not-a-cpu' +// CHECK-NEXT: note: valid target CPU values are: +// CHECK-SAME: a64fx, tmatheson-arm wrote: What would be the advantage though? Fewer test lines? It's more work to group them. And sometimes we have downstream additions to processor families which would make resolving diffs more difficult if they appear mid-group. https://github.com/llvm/llvm-project/pull/104601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [BPF] introduce `__attribute__((bpf_fastcall))` (PR #101228)
yonghong-song wrote: @AaronBallman the llvm side of change looks good to me! https://github.com/llvm/llvm-project/pull/101228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Introduce ffp-model=aggressive (PR #100453)
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/100453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Introduce ffp-model=aggressive (PR #100453)
@@ -2,13 +2,13 @@ // and other floating point options get a warning diagnostic. // -// RUN: %clang -### -ffp-model=fast -ffp-contract=off -c %s 2>&1 \ +// RUN: %clang -### -ffp-model=aggressive -ffp-contract=off -c %s 2>&1 \ MaskRay wrote: It's still useful to test the behavior of `-ffp-model=fast -ffp-contract=off` https://github.com/llvm/llvm-project/pull/100453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Introduce ffp-model=aggressive (PR #100453)
@@ -2879,10 +2879,31 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, std::string ComplexRangeStr = ""; std::string GccRangeComplexOption = ""; + auto setComplexRange = [&](LangOptions::ComplexRangeKind NewRange) { +// Warn if user expects to perform full implementation of complex +// multiplication or division in the presence of nan or ninf flags. MaskRay wrote: typo: nan => nnan ? https://github.com/llvm/llvm-project/pull/100453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Introduce ffp-model=aggressive (PR #100453)
https://github.com/MaskRay approved this pull request. fp-model= => -ffp-model= LGTM. I expect that the subject explicit mentions -ffp-model=fast behavior difference, even if it becomes less aggressive and unlikely breaks users. With "Introduce ...", nobody would expect behavior differences. https://github.com/llvm/llvm-project/pull/100453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Introduce ffp-model=aggressive (PR #100453)
@@ -3033,8 +3039,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, SignedZeros = true; StringRef Val = A->getValue(); - if (OFastEnabled && Val != "fast") { -// Only -ffp-model=fast is compatible with OFast, ignore. + if (OFastEnabled && Val != "aggressive") { +// Only -ffp-model=aggressive is compatible with OFast, ignore. MaskRay wrote: `-Ofast`. There isn't a variable named `OFast`. https://github.com/llvm/llvm-project/pull/100453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Introduce ffp-model=aggressive (PR #100453)
@@ -109,20 +112,37 @@ // CHECK-TRAP: "-cc1" // CHECK-TRAP: "-ffp-exception-behavior=strict" +// RUN: %clang -### -nostdinc -ffp-model=aggressive -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPM-AGGR %s +// CHECK-FPM-AGGR: "-cc1" +// CHECK-FPM-AGGR: "-menable-no-infs" MaskRay wrote: see my other comment: pack some options (to show they are adjacent) or use `-SAME: {{^}} "-menable-no-nans"` (clang/test/Driver/linux-cross.cpp style) https://github.com/llvm/llvm-project/pull/100453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Introduce ffp-model=aggressive (PR #100453)
@@ -163,23 +183,41 @@ // CHECK-FEB-IGNORE: "-fno-rounding-math" // CHECK-FEB-IGNORE: "-ffp-exception-behavior=ignore" -// RUN: %clang -### -nostdinc -Werror -ffast-math -ffp-model=fast -c %s 2>&1 \ +// RUN: %clang -### -nostdinc -Werror -ffast-math -ffp-model=aggressive -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FASTMATH-FPM-AGGR %s +// CHECK-FASTMATH-FPM-AGGR: "-cc1" MaskRay wrote: perhaps pack some options on the same line to show that they are adjacent (no other option in between) If this extra check isn't important, I expect at least `-SAME:` https://github.com/llvm/llvm-project/pull/100453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Introduce ffp-model=aggressive (PR #100453)
MaskRay wrote: > @MaskRay Are you OK with this change? Sorry for the delay. I've read through https://discourse.llvm.org/t/making-ffp-model-fast-more-user-friendly/78402, how we ended up with `-ffp-contract=fast-honor-pragmas` beside `=fast` (GCC compatibility, sigh), some notes that ICC/GCC have behavior differences. A different, safer mode for `-ffp-model` (absent from GCC) makes sense to me. https://github.com/llvm/llvm-project/pull/100453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Driver] Default -msmall-data-limit= to 0 and clean up code (PR #83093)
MaskRay wrote: Thanks! I'll land this in a few days. I believe it's now up to the gp default users to justify the default and why they cannot user a Clang configuration file (this is difficult to justify, as we've many many decisions to Clang configuration files). I think this is important to ensure that future sdata/sbss development like #87040 not cause disruption to users who don't use the feature. https://github.com/llvm/llvm-project/pull/83093 ___ 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 member functions with modernize-use-std-print/format (PR #104675)
https://github.com/PiotrZSL approved this pull request. https://github.com/llvm/llvm-project/pull/104675 ___ 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 member functions with modernize-use-std-print/format (PR #104675)
@@ -104,6 +104,12 @@ New check aliases Changes in existing checks ^^ +- Improved :doc:`modernize-use-std-print + ` and PiotrZSL wrote: wrong name, and split that entry into 2, even if you would need to duplicate description https://github.com/llvm/llvm-project/pull/104675 ___ 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 member functions with modernize-use-std-print/format (PR #104675)
https://github.com/mikecrowe updated https://github.com/llvm/llvm-project/pull/104675 >From afdd6c2a12735e1da69a46c6ff78b5d4e0dcdb6e Mon Sep 17 00:00:00 2001 From: Mike Crowe Date: Sun, 21 Jul 2024 20:37:02 +0100 Subject: [PATCH 1/2] [clang-tidy] Support member functions with modernize-use-std-print/format These checks can be made to work on member functions quite easily and it's not unknown to have at least printf-style functions as members. Let's remove the restriction. --- .../modernize/UseStdFormatCheck.cpp | 6 +- .../clang-tidy/modernize/UseStdPrintCheck.cpp | 8 +-- clang-tools-extra/docs/ReleaseNotes.rst | 6 ++ .../checks/modernize/use-std-format.rst | 5 +- .../checks/modernize/use-std-print.rst| 15 ++-- .../modernize/use-std-format-member.cpp | 44 .../modernize/use-std-print-member.cpp| 70 +++ 7 files changed, 138 insertions(+), 16 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-member.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-member.cpp diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp index 6cef21f1318a2a..cdb34aef1b0e61 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp @@ -50,8 +50,7 @@ void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( callExpr(argumentCountAtLeast(1), hasArgument(0, stringLiteral(isOrdinary())), - callee(functionDecl(unless(cxxMethodDecl()), - matchers::matchesAnyListedName( + callee(functionDecl(matchers::matchesAnyListedName( StrFormatLikeFunctions)) .bind("func_decl"))) .bind("strformat"), @@ -93,7 +92,8 @@ void UseStdFormatCheck::check(const MatchFinder::MatchResult &Result) { diag(StrFormatCall->getBeginLoc(), "use '%0' instead of %1") << ReplacementFormatFunction << OldFunction->getIdentifier(); Diag << FixItHint::CreateReplacement( - CharSourceRange::getTokenRange(StrFormatCall->getSourceRange()), + CharSourceRange::getTokenRange(StrFormatCall->getExprLoc(), + StrFormatCall->getEndLoc()), ReplacementFormatFunction); Converter.applyFixes(Diag, *Result.SourceManager); diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp index ff990feadc0c1d..16f2f4b3e7d1af 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp @@ -100,8 +100,7 @@ void UseStdPrintCheck::registerMatchers(MatchFinder *Finder) { unusedReturnValue( callExpr(argumentCountAtLeast(1), hasArgument(0, stringLiteral(isOrdinary())), - callee(functionDecl(unless(cxxMethodDecl()), - matchers::matchesAnyListedName( + callee(functionDecl(matchers::matchesAnyListedName( PrintfLikeFunctions)) .bind("func_decl"))) .bind("printf")), @@ -112,8 +111,7 @@ void UseStdPrintCheck::registerMatchers(MatchFinder *Finder) { unusedReturnValue( callExpr(argumentCountAtLeast(2), hasArgument(1, stringLiteral(isOrdinary())), - callee(functionDecl(unless(cxxMethodDecl()), - matchers::matchesAnyListedName( + callee(functionDecl(matchers::matchesAnyListedName( FprintfLikeFunctions)) .bind("func_decl"))) .bind("fprintf")), @@ -152,7 +150,7 @@ void UseStdPrintCheck::check(const MatchFinder::MatchResult &Result) { << ReplacementFunction << OldFunction->getIdentifier(); Diag << FixItHint::CreateReplacement( - CharSourceRange::getTokenRange(PrintfCall->getBeginLoc(), + CharSourceRange::getTokenRange(PrintfCall->getExprLoc(), PrintfCall->getEndLoc()), ReplacementFunction); Converter.applyFixes(Diag, *Result.SourceManager); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b72d109b3d3938..d542ec4e3e1721 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -104,6 +104,12 @@ New check aliases Changes in existing checks ^^ +- Improved :doc:`modernize-use-std-print + ` and + :doc:`modernize-use-std-print + ` checks to s
[clang] [llvm] [RISCV] Add Hazard3 Core as taped out for RP2350 (PR #102452)
@@ -402,6 +402,21 @@ // MCPU-SIFIVE-P670-SAME: "-target-feature" "+zvkt" // MCPU-SIFIVE-P670-SAME: "-target-abi" "lp64d" +// RUN: %clang -target riscv32 -### -c %s 2>&1 -mcpu=rp2350-hazard3 | FileCheck -check-prefix=MCPU-HAZARD3 %s +// MCPU-HAZARD3: "-target-cpu" "rp2350-hazard3" +// MCPU-HAZARD3-SAME: "-target-feature" "+m" +// MCPU-HAZARD3-SAME: "-target-feature" "+a" +// MCPU-HAZARD3-SAME: "-target-feature" "+c" +// MCPU-HAZARD3-SAME: "-target-feature" "+zicsr" +// MCPU-HAZARD3-SAME: "-target-feature" "+zifencei" +// MCPU-HAZARD3-SAME: "-target-feature" "+zcb" +// MCPU-HAZARD3-SAME: "-target-feature" "+zcmp" +// MCPU-HAZARD3-SAME: "-target-feature" "+zba" Wren6991 wrote: Understood, thanks. Conversely, does specifying B on its own still allow feature test via the `__riscv_zba` etc macros? If not, what is the preferred way to detect the presence of e.g. Zba? The context is that I want to avoid mis-detection of the core not having ZbaZbbZbs due to future code only checking the B alias for those extensions, and vice versa. If the preferred construct is something like `#if defined(__riscv_b) || defined(__riscv_zba)` then the extensions specified in this PR look correct to me. However that sort of code is liable to break next time RISC-V introduces yet another extension alias (see also A vs Zalrsc/Zaamo, C vs Zca/Zcf/Zcd). https://github.com/llvm/llvm-project/pull/102452 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add Hazard3 Core as taped out for RP2350 (PR #102452)
@@ -402,6 +402,21 @@ // MCPU-SIFIVE-P670-SAME: "-target-feature" "+zvkt" // MCPU-SIFIVE-P670-SAME: "-target-abi" "lp64d" +// RUN: %clang -target riscv32 -### -c %s 2>&1 -mcpu=rp2350-hazard3 | FileCheck -check-prefix=MCPU-HAZARD3 %s +// MCPU-HAZARD3: "-target-cpu" "rp2350-hazard3" +// MCPU-HAZARD3-SAME: "-target-feature" "+m" +// MCPU-HAZARD3-SAME: "-target-feature" "+a" +// MCPU-HAZARD3-SAME: "-target-feature" "+c" +// MCPU-HAZARD3-SAME: "-target-feature" "+zicsr" +// MCPU-HAZARD3-SAME: "-target-feature" "+zifencei" +// MCPU-HAZARD3-SAME: "-target-feature" "+zcb" +// MCPU-HAZARD3-SAME: "-target-feature" "+zcmp" +// MCPU-HAZARD3-SAME: "-target-feature" "+zba" topperc wrote: > Understood, thanks. Conversely, does specifying B on its own still allow > feature test via the __riscv_zba etc macros? Yes. B does imply Zba, Zbb, and Zbs so those macros will get set. https://github.com/llvm/llvm-project/pull/102452 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f620c5b - [clang][bytecode] Classify 1-bit unsigned integers as bool (#104662)
Author: Timm Baeder Date: 2024-08-17T22:06:46+02:00 New Revision: f620c5b692dd0bc08692979236073db0db27f0fc URL: https://github.com/llvm/llvm-project/commit/f620c5b692dd0bc08692979236073db0db27f0fc DIFF: https://github.com/llvm/llvm-project/commit/f620c5b692dd0bc08692979236073db0db27f0fc.diff LOG: [clang][bytecode] Classify 1-bit unsigned integers as bool (#104662) This happens for enum types with bool parent types. isBooleanType() returns false for them however. The previous version did the same thing by re-classifying the enum integer type, but that breaks with forward-declared enums. Added: Modified: clang/lib/AST/ByteCode/Context.cpp clang/test/AST/ByteCode/c.c Removed: diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index e9c1fd1b8dc9f9..48ae363f651f5a 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -135,9 +135,6 @@ std::optional Context::classify(QualType T) const { if (T->isAnyComplexType() || T->isVectorType()) return std::nullopt; - if (const auto *ET = T->getAs()) -return classify(ET->getDecl()->getIntegerType()); - if (T->isSignedIntegerOrEnumerationType()) { switch (Ctx.getIntWidth(T)) { case 64: @@ -163,6 +160,9 @@ std::optional Context::classify(QualType T) const { return PT_Uint16; case 8: return PT_Uint8; +case 1: + // Might happen for enum types. + return PT_Bool; default: return PT_IntAP; } diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c index 13a5e082a125f2..b38259d41130eb 100644 --- a/clang/test/AST/ByteCode/c.c +++ b/clang/test/AST/ByteCode/c.c @@ -295,4 +295,5 @@ void T1(void) { // pedantic-warning {{use of GNU statement expression extension}} } - +enum teste1 test1f(void), (*test1)(void) = test1f; // pedantic-warning {{ISO C forbids forward references to 'enum' types}} +enum teste1 { TEST1 }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Classify 1-bit unsigned integers as bool (PR #104662)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/104662 ___ 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 member functions with modernize-use-std-print/format (PR #104675)
https://github.com/PiotrZSL approved this pull request. https://github.com/llvm/llvm-project/pull/104675 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)
@@ -14638,6 +14649,8 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) { return true; } + case Builtin::BIfmin: + case Builtin::BIfminf: philnik777 wrote: I don't think anything should happen to the libc++ documentation in this patch. We can update the implementation to behave the same across the different overloads in a follow-up and update our documentation then. https://github.com/llvm/llvm-project/pull/88978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Fix shifting negative values (PR #104663)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/104663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 555399d - [clang][bytecode] Fix shifting negative values (#104663)
Author: Timm Baeder Date: 2024-08-17T22:57:19+02:00 New Revision: 555399d562201f3114fb22f883cd1b6710af1a0d URL: https://github.com/llvm/llvm-project/commit/555399d562201f3114fb22f883cd1b6710af1a0d DIFF: https://github.com/llvm/llvm-project/commit/555399d562201f3114fb22f883cd1b6710af1a0d.diff LOG: [clang][bytecode] Fix shifting negative values (#104663) Added: Modified: clang/lib/AST/ByteCode/Interp.h clang/test/AST/ByteCode/cxx23.cpp Removed: diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index c3ce21cb13770e..9891e3dba0d309 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -2354,6 +2354,17 @@ inline bool DoShift(InterpState &S, CodePtr OpPC, LT &LHS, RT &RHS) { LT::AsUnsigned::from(RHS, Bits), Bits, &R); } + // We did the shift above as unsigned. Restore the sign bit if we need to. + if constexpr (Dir == ShiftDir::Right) { +if (LHS.isSigned() && LHS.isNegative()) { + typename LT::AsUnsigned SignBit; + LT::AsUnsigned::shiftLeft(LT::AsUnsigned::from(1, Bits), +LT::AsUnsigned::from(Bits - 1, Bits), Bits, +&SignBit); + LT::AsUnsigned::bitOr(R, SignBit, Bits, &R); +} + } + S.Stk.push(LT::from(R)); return true; } diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp index eb05a9fda0dfb1..756eec5b825605 100644 --- a/clang/test/AST/ByteCode/cxx23.cpp +++ b/clang/test/AST/ByteCode/cxx23.cpp @@ -224,3 +224,17 @@ namespace ExplicitLambdaInstancePointer { static_assert(fp(1) == 1, ""); } } + +namespace TwosComplementShifts { + using uint32 = __UINT32_TYPE__; + using int32 = __INT32_TYPE__; + static_assert(uint32(int32(0x1234) << 16) == 0x1234); + static_assert(uint32(int32(0x1234) << 19) == 0x91a0); + static_assert(uint32(int32(0x1234) << 20) == 0x2340); + static_assert(uint32(int32(0x1234) << 24) == 0x3400); + static_assert(uint32(int32(-1) << 31) == 0x8000); + + static_assert(-2 >> 1 == -1); + static_assert(-3 >> 1 == -2); + static_assert(-7 >> 1 == -4); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Fix shifting negative values (PR #104663)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `sanitizer-windows` running on `sanitizer-windows` while building `clang` at step 4 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/107/builds/1989 Here is the relevant piece of the build log for the reference: ``` Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/sanitizer-windows.py ...' (failure) ... [8/20] Building CXX object tools\lld\Common\CMakeFiles\lldCommon.dir\Version.cpp.obj [9/20] Linking CXX static library lib\lldCommon.lib [10/20] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ByteCode\Context.cpp.obj [11/20] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ByteCode\InterpBuiltin.cpp.obj [12/20] Building CXX object lib\CodeGen\AsmPrinter\CMakeFiles\LLVMAsmPrinter.dir\AsmPrinter.cpp.obj [13/20] Linking CXX static library lib\LLVMAsmPrinter.lib [14/20] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ByteCode\EvalEmitter.cpp.obj [15/20] Building CXX object lib\LTO\CMakeFiles\LLVMLTO.dir\LTO.cpp.obj [16/20] Linking CXX static library lib\LLVMLTO.lib [17/20] Linking CXX executable bin\lld.exe command timed out: 1200 seconds without output running ['python', '../llvm-zorg/zorg/buildbot/builders/annotated/sanitizer-windows.py', '--jobs=16'], attempting to kill program finished with exit code 1 elapsedTime=1258.436000 Step 7 (stage 1 build) failure: stage 1 build (failure) @@@BUILD_STEP stage 1 build@@@ Running: ninja -j 16 compiler-rt [1/2] Building CXX object projects\compiler-rt\lib\asan\CMakeFiles\RTAsan_dynamic_version_script_dummy.x86_64.dir\dummy.cpp.obj [2/2] Linking CXX shared library lib\clang\20\lib\windows\clang_rt.asan_dynamic-x86_64.dll Running: ninja -j 16 clang lld [1/20] Generating VCSRevision.h [2/20] Generating VCSVersion.inc [3/20] Building CXX object tools\clang\lib\Basic\CMakeFiles\obj.clangBasic.dir\Version.cpp.obj [4/20] Building CXX object lib\Object\CMakeFiles\LLVMObject.dir\IRSymtab.cpp.obj [5/20] Linking CXX static library lib\LLVMObject.lib [6/20] Generating VCSVersion.inc [7/20] Linking CXX static library lib\clangBasic.lib [8/20] Building CXX object tools\lld\Common\CMakeFiles\lldCommon.dir\Version.cpp.obj [9/20] Linking CXX static library lib\lldCommon.lib [10/20] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ByteCode\Context.cpp.obj [11/20] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ByteCode\InterpBuiltin.cpp.obj [12/20] Building CXX object lib\CodeGen\AsmPrinter\CMakeFiles\LLVMAsmPrinter.dir\AsmPrinter.cpp.obj [13/20] Linking CXX static library lib\LLVMAsmPrinter.lib [14/20] Building CXX object tools\clang\lib\AST\CMakeFiles\obj.clangAST.dir\ByteCode\EvalEmitter.cpp.obj [15/20] Building CXX object lib\LTO\CMakeFiles\LLVMLTO.dir\LTO.cpp.obj [16/20] Linking CXX static library lib\LLVMLTO.lib [17/20] Linking CXX executable bin\lld.exe command timed out: 1200 seconds without output running ['python', '../llvm-zorg/zorg/buildbot/builders/annotated/sanitizer-windows.py', '--jobs=16'], attempting to kill program finished with exit code 1 elapsedTime=1258.436000 ``` https://github.com/llvm/llvm-project/pull/104663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)
@@ -1122,6 +1122,154 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints( PointOfInstantiation, Satisfaction); } +namespace { + +// We employ a TreeTransform because RAV couldn't recurse into a bunch of +// Exprs e.g. SizeOfPackExpr, CXXFoldExpr, etc. +// FIXME: Could we do the Decl instantiation as we substitute into +// the constraint expressions? +class InstantiateReferencedParameter +: public TreeTransform { + const MultiLevelTemplateArgumentList &TemplateArgs; + + llvm::SmallPtrSet InstantiatedDecls; + + FunctionDecl *PrimaryTemplatedFunction; + + using inherited = TreeTransform; + + bool instantiateParameterToScope(ParmVarDecl *OldParm, + LocalInstantiationScope &Scope) { +// The current context might have been changed by lambda expressions. So +// resume it before we substitute into parameters. +Sema::ContextRAII Context(SemaRef, PrimaryTemplatedFunction); +std::optional NumExpansions; +ParmVarDecl *NewParm = nullptr; +unsigned IndexAdjustment = 0; +if (OldParm->isParameterPack()) { + SmallVector Unexpanded; + TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); + PackExpansionTypeLoc ExpansionTL = TL.castAs(); + TypeLoc Pattern = ExpansionTL.getPatternLoc(); + SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); + + assert(!Unexpanded.empty() && + "A pack Decl doesn't contain anything unexpanded?"); + + bool ShouldExpand = false; + bool RetainExpansion = false; + std::optional OrigNumExpansions = + ExpansionTL.getTypePtr()->getNumExpansions(); + NumExpansions = OrigNumExpansions; + if (SemaRef.CheckParameterPacksForExpansion( + ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(), + Unexpanded, TemplateArgs, ShouldExpand, RetainExpansion, + NumExpansions)) +return true; + + assert(ShouldExpand && !RetainExpansion && + "Shouldn't retain an expansion here!"); + Scope.MakeInstantiatedLocalArgPack(OldParm); + + for (unsigned I = 0; I != *NumExpansions; ++I) { +Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); +ParmVarDecl *NewParm = SemaRef.SubstParmVarDecl( +OldParm, TemplateArgs, /*indexAdjustment=*/IndexAdjustment++, +NumExpansions, /*ExpectParameterPack=*/false, +/*EvaluateConstraints=*/false); +if (!NewParm) + return true; + } + + return false; +} +NewParm = SemaRef.SubstParmVarDecl(OldParm, TemplateArgs, + /*indexAdjustment=*/IndexAdjustment, + std::nullopt, + /*ExpectParameterPack=*/false); +if (!NewParm) + return true; +Scope.InstantiatedLocal(OldParm, NewParm); +return false; + } + +public: + InstantiateReferencedParameter( + Sema &SemaRef, const MultiLevelTemplateArgumentList &TemplateArgs, + FunctionDecl *PrimaryTemplatedFunction) + : inherited(SemaRef), TemplateArgs(TemplateArgs), +PrimaryTemplatedFunction(PrimaryTemplatedFunction) {} + + Decl *TransformDecl(SourceLocation Loc, Decl *D) { +if (auto *PVD = dyn_cast_if_present(D); +PVD && PVD->getDeclContext() == PrimaryTemplatedFunction && +!InstantiatedDecls.contains(PVD)) { + instantiateParameterToScope(PVD, *SemaRef.CurrentInstantiationScope); cor3ntin wrote: We probably need to handle errors here. But I think we should instantiate _ALL_ the parameters, not just the one referenced in the constraint https://github.com/llvm/llvm-project/pull/102857 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement support for HLSL intrinsic - saturate (PR #104619)
@@ -325,6 +325,16 @@ def Abs : DXILOp<6, unary> { let attributes = [Attributes]; } +def Saturate : DXILOp<7, unary> { + let Doc = "Clamps a single or double precision floating point value to [0.0f...1.0f]."; + let LLVMIntrinsic = int_dx_saturate; + let arguments = [overloadTy]; + let result = overloadTy; + let overloads = [Overloads]; farzonl wrote: I was a little suprised by `double` but yeah dxc generate `double @dx.op.unary.f64(i32 7, double %5)` https://github.com/llvm/llvm-project/pull/104619 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement support for HLSL intrinsic - saturate (PR #104619)
https://github.com/farzonl edited https://github.com/llvm/llvm-project/pull/104619 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement support for HLSL intrinsic - saturate (PR #104619)
@@ -362,6 +364,34 @@ static bool expandClampIntrinsic(CallInst *Orig, Intrinsic::ID ClampIntrinsic) { return true; } +static bool expandSaturateIntrinsic(CallInst *SaturateCall) { + FunctionType *FT = SaturateCall->getFunctionType(); + Type *FTRetTy = FT->getReturnType(); + assert(FTRetTy == FT->getParamType(0) && farzonl wrote: It looks like you are trying to do scalarization via this pass, but we haven't been doing that thus far. I wanted to take care of scalarization in a different pass because doing it here means we have to do it for each intrinsic which I want to avoid. My feeling is scalarization should be uniform across all intrinsics unless there are special cases like `dot2`, `dot3`, `dot4`. https://github.com/llvm/llvm-project/pull/104619 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add Hazard3 Core as taped out for RP2350 (PR #102452)
@@ -402,6 +402,21 @@ // MCPU-SIFIVE-P670-SAME: "-target-feature" "+zvkt" // MCPU-SIFIVE-P670-SAME: "-target-abi" "lp64d" +// RUN: %clang -target riscv32 -### -c %s 2>&1 -mcpu=rp2350-hazard3 | FileCheck -check-prefix=MCPU-HAZARD3 %s +// MCPU-HAZARD3: "-target-cpu" "rp2350-hazard3" +// MCPU-HAZARD3-SAME: "-target-feature" "+m" +// MCPU-HAZARD3-SAME: "-target-feature" "+a" +// MCPU-HAZARD3-SAME: "-target-feature" "+c" +// MCPU-HAZARD3-SAME: "-target-feature" "+zicsr" +// MCPU-HAZARD3-SAME: "-target-feature" "+zifencei" +// MCPU-HAZARD3-SAME: "-target-feature" "+zcb" +// MCPU-HAZARD3-SAME: "-target-feature" "+zcmp" +// MCPU-HAZARD3-SAME: "-target-feature" "+zba" Wren6991 wrote: Thanks. I got @lenary to explain the arch string expansion stuff to me offline, and I think I am clear on this now. I'm satisfied that not setting `FeatureStdExtB` is not going to cause any issues with feature detect in the future as long as people don't become too reliant on testing `__riscv_b` only. Thanks again for the clarification. https://github.com/llvm/llvm-project/pull/102452 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] warn on discarded [[nodiscard]] function results after casting in C (PR #104677)
cor3ntin wrote: can you add a test for void? we should make sure this still warns! https://github.com/llvm/llvm-project/pull/104677 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] IntPointer::atOffset() should append (PR #104686)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/104686 ... to current offset. This breaks other tests which this commit also fixes. Namely, getIndex() should return the integer representation for non-block pointers. >From c85a03aa716aa2c3d23ed2567b1d81066b160dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 17 Aug 2024 23:53:58 +0200 Subject: [PATCH] [clang][bytecode] IntPointer::atOffset() should append ... to current offset. This breaks other tests which this commit also fixes. Namely, getIndex() should return the integer representation for non-block pointers. --- clang/lib/AST/ByteCode/Interp.h| 11 +++ clang/lib/AST/ByteCode/Pointer.cpp | 2 +- clang/lib/AST/ByteCode/Pointer.h | 2 +- clang/test/AST/ByteCode/codegen.c | 19 +++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 clang/test/AST/ByteCode/codegen.c diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index c3ce21cb13770e..2332a479e79cde 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -1853,6 +1853,17 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset, if (!CheckArray(S, OpPC, Ptr)) return false; + // This is much simpler for integral pointers, so handle them first. + if (Ptr.isIntegralPointer()) { +uint64_t V = Ptr.getIntegerRepresentation(); +uint64_t O = static_cast(Offset) * Ptr.elemSize(); +if constexpr (Op == ArithOp::Add) + S.Stk.push(V + O, Ptr.asIntPointer().Desc); +else + S.Stk.push(V - O, Ptr.asIntPointer().Desc); +return true; + } + uint64_t MaxIndex = static_cast(Ptr.getNumElems()); uint64_t Index; if (Ptr.isOnePastEnd()) diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index 466e61666c76e9..ccab3b7f626811 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -647,5 +647,5 @@ IntPointer IntPointer::atOffset(const ASTContext &ASTCtx, uint64_t FieldOffset = ASTCtx.toCharUnitsFromBits(Layout.getFieldOffset(FieldIndex)) .getQuantity(); - return IntPointer{this->Desc, FieldOffset}; + return IntPointer{this->Desc, this->Value + FieldOffset}; } diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h index 8db081c0ec82b3..ba30449977376b 100644 --- a/clang/lib/AST/ByteCode/Pointer.h +++ b/clang/lib/AST/ByteCode/Pointer.h @@ -571,7 +571,7 @@ class Pointer { /// Returns the index into an array. int64_t getIndex() const { if (!isBlockPointer()) - return 0; + return getIntegerRepresentation(); if (isZero()) return 0; diff --git a/clang/test/AST/ByteCode/codegen.c b/clang/test/AST/ByteCode/codegen.c new file mode 100644 index 00..8434992823010e --- /dev/null +++ b/clang/test/AST/ByteCode/codegen.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s + +typedef __INTPTR_TYPE__ intptr_t; + +const intptr_t Z1 = (intptr_t)(((char*)-1LL) + 1); +// CHECK: @Z1 = constant i64 0 + +const intptr_t Z2 = (intptr_t)(((char*)1LL) - 1); +// CHECK: @Z2 = constant i64 0 + +struct A { + char num_fields; +}; +struct B { + char a, b[1]; +}; +const int A = (char *)(&( (struct B *)(16) )->b[0]) - (char *)(16); +// CHECK: @A = constant i32 1 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] IntPointer::atOffset() should append (PR #104686)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes ... to current offset. This breaks other tests which this commit also fixes. Namely, getIndex() should return the integer representation for non-block pointers. --- Full diff: https://github.com/llvm/llvm-project/pull/104686.diff 4 Files Affected: - (modified) clang/lib/AST/ByteCode/Interp.h (+11) - (modified) clang/lib/AST/ByteCode/Pointer.cpp (+1-1) - (modified) clang/lib/AST/ByteCode/Pointer.h (+1-1) - (added) clang/test/AST/ByteCode/codegen.c (+19) ``diff diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index c3ce21cb13770e..2332a479e79cde 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -1853,6 +1853,17 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset, if (!CheckArray(S, OpPC, Ptr)) return false; + // This is much simpler for integral pointers, so handle them first. + if (Ptr.isIntegralPointer()) { +uint64_t V = Ptr.getIntegerRepresentation(); +uint64_t O = static_cast(Offset) * Ptr.elemSize(); +if constexpr (Op == ArithOp::Add) + S.Stk.push(V + O, Ptr.asIntPointer().Desc); +else + S.Stk.push(V - O, Ptr.asIntPointer().Desc); +return true; + } + uint64_t MaxIndex = static_cast(Ptr.getNumElems()); uint64_t Index; if (Ptr.isOnePastEnd()) diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index 466e61666c76e9..ccab3b7f626811 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -647,5 +647,5 @@ IntPointer IntPointer::atOffset(const ASTContext &ASTCtx, uint64_t FieldOffset = ASTCtx.toCharUnitsFromBits(Layout.getFieldOffset(FieldIndex)) .getQuantity(); - return IntPointer{this->Desc, FieldOffset}; + return IntPointer{this->Desc, this->Value + FieldOffset}; } diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h index 8db081c0ec82b3..ba30449977376b 100644 --- a/clang/lib/AST/ByteCode/Pointer.h +++ b/clang/lib/AST/ByteCode/Pointer.h @@ -571,7 +571,7 @@ class Pointer { /// Returns the index into an array. int64_t getIndex() const { if (!isBlockPointer()) - return 0; + return getIntegerRepresentation(); if (isZero()) return 0; diff --git a/clang/test/AST/ByteCode/codegen.c b/clang/test/AST/ByteCode/codegen.c new file mode 100644 index 00..8434992823010e --- /dev/null +++ b/clang/test/AST/ByteCode/codegen.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s + +typedef __INTPTR_TYPE__ intptr_t; + +const intptr_t Z1 = (intptr_t)(((char*)-1LL) + 1); +// CHECK: @Z1 = constant i64 0 + +const intptr_t Z2 = (intptr_t)(((char*)1LL) - 1); +// CHECK: @Z2 = constant i64 0 + +struct A { + char num_fields; +}; +struct B { + char a, b[1]; +}; +const int A = (char *)(&( (struct B *)(16) )->b[0]) - (char *)(16); +// CHECK: @A = constant i32 1 `` https://github.com/llvm/llvm-project/pull/104686 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][NFC] Un-constify `MultiLevelTemplateArgumentList` (PR #104687)
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 27d37ee4d067f42e9a46a0871d3cb961323e5c85 919da31d73a408f16e1c855cb658359b73ad1d28 --extensions cpp,h -- clang/include/clang/AST/Decl.h clang/include/clang/AST/DeclTemplate.h clang/include/clang/AST/ExprConcepts.h clang/include/clang/AST/NestedNameSpecifier.h clang/include/clang/AST/Type.h clang/include/clang/Sema/Sema.h clang/include/clang/Sema/SemaConcept.h clang/include/clang/Sema/Template.h clang/lib/AST/Decl.cpp clang/lib/AST/DeclTemplate.cpp clang/lib/AST/Type.cpp clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaCodeComplete.cpp clang/lib/Sema/SemaConcept.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaInit.cpp clang/lib/Sema/SemaLookup.cpp clang/lib/Sema/SemaOverload.cpp clang/lib/Sema/SemaTemplate.cpp clang/lib/Sema/SemaTemplateDeduction.cpp clang/lib/Sema/SemaTemplateInstantiate.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/unittests/AST/SourceLocationTest.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 2ec49427e3..c6f3d59cda 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -290,9 +290,7 @@ public: } /// Retrieve a pointer to the template argument list. - TemplateArgument *data() { -return getTrailingObjects(); - } + TemplateArgument *data() { return getTrailingObjects(); } }; void *allocateDefaultArgStorageChain(const ASTContext &C); @@ -1892,11 +1890,10 @@ public: /// Retrieve the template arguments of the class template /// specialization. - TemplateArgumentList &getTemplateArgs() { -return *TemplateArgs; - } + TemplateArgumentList &getTemplateArgs() { return *TemplateArgs; } const TemplateArgumentList &getTemplateArgs() const { -return const_cast(this)->getTemplateArgs(); +return const_cast(this) +->getTemplateArgs(); } void setTemplateArgs(TemplateArgumentList *Args) { @@ -1998,7 +1995,8 @@ public: return getTemplateArgs(); } const TemplateArgumentList &getTemplateInstantiationArgs() const { -return const_cast(this)->getTemplateInstantiationArgs(); +return const_cast(this) +->getTemplateInstantiationArgs(); } /// Note that this class template specialization is actually an @@ -3231,11 +3229,12 @@ public: unsigned NumTemplateArgs); MutableArrayRef getTemplateArguments() { -return MutableArrayRef(getTrailingObjects(), - NumTemplateArgs); +return MutableArrayRef( +getTrailingObjects(), NumTemplateArgs); } ArrayRef getTemplateArguments() const { -return const_cast(this)->getTemplateArguments(); +return const_cast(this) +->getTemplateArguments(); } void setTemplateArguments(ArrayRef Converted); diff --git a/clang/include/clang/AST/ExprConcepts.h b/clang/include/clang/AST/ExprConcepts.h index 76ab0bbbcc..1c9889e102 100644 --- a/clang/include/clang/AST/ExprConcepts.h +++ b/clang/include/clang/AST/ExprConcepts.h @@ -82,7 +82,8 @@ public: return SpecDecl->getTemplateArguments(); } ArrayRef getTemplateArguments() const { -return const_cast(this)->getTemplateArguments(); +return const_cast(this) +->getTemplateArguments(); } ConceptReference *getConceptReference() const { return ConceptRef; } diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index e46af5797a..2956d6259e 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -11859,7 +11859,7 @@ public: bool isInvalid() const { return !ND && !DC; } NamedDecl *getDecl() { return ND; } -const NamedDecl *getDecl() const { +const NamedDecl *getDecl() const { return const_cast(this)->getDecl(); } @@ -13682,8 +13682,7 @@ public: /// Usually this should not be used, and template argument deduction should be /// used in its place. FunctionDecl *InstantiateFunctionDeclaration( - FunctionTemplateDecl *FTD, TemplateArgumentList *Args, - SourceLocation Loc, + FunctionTemplateDecl *FTD, TemplateArgumentList *Args, SourceLocation Loc, CodeSynthesisContext::SynthesisKind CSC = CodeSynthesisContext::ExplicitTemplateArgumentSubstitution); @@ -14435,8 +14434,7 @@ public: // for figuring out the relative 'depth' of the constraint. The depth of the // 'primary template' and the 'instantiated from' templates aren't necessarily // the same, such as a case when one is a 'friend' defined in a class. - bool AreConstraintExpressionsEqual(NamedDecl *Old, - const Expr *OldConstr, + bool AreConstraintExpressionsEqual(Nam
[clang] [Clang] `constexpr` builtin floating point classification / comparison functions (PR #94118)
Endilll wrote: @MitalAshok Is there anything left to do here? https://github.com/llvm/llvm-project/pull/94118 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Fix shifting negative values (PR #104663)
DTeachs wrote: We should probably backport this to 19.x https://github.com/llvm/llvm-project/pull/104663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)
@@ -1122,6 +1122,154 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints( PointOfInstantiation, Satisfaction); } +namespace { + +// We employ a TreeTransform because RAV couldn't recurse into a bunch of +// Exprs e.g. SizeOfPackExpr, CXXFoldExpr, etc. +// FIXME: Could we do the Decl instantiation as we substitute into +// the constraint expressions? +class InstantiateReferencedParameter +: public TreeTransform { + const MultiLevelTemplateArgumentList &TemplateArgs; + + llvm::SmallPtrSet InstantiatedDecls; + + FunctionDecl *PrimaryTemplatedFunction; + + using inherited = TreeTransform; + + bool instantiateParameterToScope(ParmVarDecl *OldParm, + LocalInstantiationScope &Scope) { +// The current context might have been changed by lambda expressions. So +// resume it before we substitute into parameters. +Sema::ContextRAII Context(SemaRef, PrimaryTemplatedFunction); +std::optional NumExpansions; +ParmVarDecl *NewParm = nullptr; +unsigned IndexAdjustment = 0; +if (OldParm->isParameterPack()) { + SmallVector Unexpanded; + TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); + PackExpansionTypeLoc ExpansionTL = TL.castAs(); + TypeLoc Pattern = ExpansionTL.getPatternLoc(); + SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); + + assert(!Unexpanded.empty() && + "A pack Decl doesn't contain anything unexpanded?"); + + bool ShouldExpand = false; + bool RetainExpansion = false; + std::optional OrigNumExpansions = + ExpansionTL.getTypePtr()->getNumExpansions(); + NumExpansions = OrigNumExpansions; + if (SemaRef.CheckParameterPacksForExpansion( + ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(), + Unexpanded, TemplateArgs, ShouldExpand, RetainExpansion, + NumExpansions)) +return true; + + assert(ShouldExpand && !RetainExpansion && + "Shouldn't retain an expansion here!"); + Scope.MakeInstantiatedLocalArgPack(OldParm); + + for (unsigned I = 0; I != *NumExpansions; ++I) { +Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); +ParmVarDecl *NewParm = SemaRef.SubstParmVarDecl( +OldParm, TemplateArgs, /*indexAdjustment=*/IndexAdjustment++, +NumExpansions, /*ExpectParameterPack=*/false, +/*EvaluateConstraints=*/false); +if (!NewParm) + return true; + } + + return false; +} +NewParm = SemaRef.SubstParmVarDecl(OldParm, TemplateArgs, + /*indexAdjustment=*/IndexAdjustment, + std::nullopt, + /*ExpectParameterPack=*/false); +if (!NewParm) + return true; +Scope.InstantiatedLocal(OldParm, NewParm); +return false; + } + +public: + InstantiateReferencedParameter( + Sema &SemaRef, const MultiLevelTemplateArgumentList &TemplateArgs, + FunctionDecl *PrimaryTemplatedFunction) + : inherited(SemaRef), TemplateArgs(TemplateArgs), +PrimaryTemplatedFunction(PrimaryTemplatedFunction) {} + + Decl *TransformDecl(SourceLocation Loc, Decl *D) { +if (auto *PVD = dyn_cast_if_present(D); +PVD && PVD->getDeclContext() == PrimaryTemplatedFunction && +!InstantiatedDecls.contains(PVD)) { + instantiateParameterToScope(PVD, *SemaRef.CurrentInstantiationScope); zyn0217 wrote: That would cause an implementation divergence with GCC: https://gcc.godbolt.org/z/7MobE9b61 If we instantiate all parameters, we wouldn't accept such a case that GCC currently accepts. The standard seems *vague* ([It](https://cplusplus.github.io/CWG/issues/2369.html) just said `function type` shouldn't be replaced before the constraint evaluation) about this, but I presume the intent was to instantiate parameters on demand. https://github.com/llvm/llvm-project/pull/102857 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement support for HLSL intrinsic - saturate (PR #104619)
https://github.com/farzonl edited https://github.com/llvm/llvm-project/pull/104619 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang][driver] Add pre-processing type to `.i` files (PR #104664)
https://github.com/ergawy updated https://github.com/llvm/llvm-project/pull/104664 >From 8b911e77c30edb19cc5dbb95423de0290ddf2c6b Mon Sep 17 00:00:00 2001 From: ergawy Date: Sat, 17 Aug 2024 00:20:11 -0500 Subject: [PATCH] [flang][driver] Add pre-processing type to `.i` files This diff allows `.i` files emitted by flang-new to be treated as valid files in the pre-processing phase. This, in turn, allows flang-new to add pre-processing options (e.g. `-I`) when launching compilation jobs for these files. This solves a bug when using `--save-temps` with source files that include modules from non-standard directories, for example: ``` flang-new -c --save-temps -I/tmp/module_dir -fno-integrated-as \ /tmp/ModuleUser.f90 ``` The problem was that `.i` files were treated as "binary" files and therefore the return value for `types::getPreprocessedType(InputType)` in `Flang::ConstructJob(...)` was `types::TY_INVALID`. --- clang/include/clang/Driver/Types.def| 2 +- flang/test/Driver/save-temps-use-module.f90 | 23 + 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 flang/test/Driver/save-temps-use-module.f90 diff --git a/clang/include/clang/Driver/Types.def b/clang/include/clang/Driver/Types.def index 0e0cae5fb7068d..b4e9e1f9f3f8b6 100644 --- a/clang/include/clang/Driver/Types.def +++ b/clang/include/clang/Driver/Types.def @@ -79,7 +79,7 @@ TYPE("c++-module-cpp-output",PP_CXXModule, INVALID, "iim",phases TYPE("ada", Ada, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link) TYPE("assembler",PP_Asm, INVALID, "s", phases::Assemble, phases::Link) TYPE("assembler-with-cpp", Asm, PP_Asm, "S", phases::Preprocess, phases::Assemble, phases::Link) -TYPE("f95", PP_Fortran, INVALID, "i", phases::Compile, phases::Backend, phases::Assemble, phases::Link) +TYPE("f95", PP_Fortran, PP_Fortran, "i", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link) TYPE("f95-cpp-input",Fortran, PP_Fortran, nullptr, phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link) TYPE("java", Java, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link) diff --git a/flang/test/Driver/save-temps-use-module.f90 b/flang/test/Driver/save-temps-use-module.f90 new file mode 100644 index 00..ad191ab631e9bb --- /dev/null +++ b/flang/test/Driver/save-temps-use-module.f90 @@ -0,0 +1,23 @@ +! Tests that `--save-temps` works properly when a module from a non standard dir +! is included with `-I/...`. + +! RUN: rm -rf %t && split-file %s %t +! RUN: mkdir %t/mod_inc_dir +! RUN: mv %t/somemodule.mod %t/mod_inc_dir +! RUN: %flang -c --save-temps=obj -I%t/mod_inc_dir -fno-integrated-as \ +! RUN: %t/ModuleUser.f90 -o %t/ModuleUser.o +! RUN: ls %t | FileCheck %s + +! Verify that the temp file(s) were written to disk. +! CHECK: ModuleUser.i + +!--- somemodule.mod +!mod$ v1 sum:e9e8fd2bd49e8daa +module SomeModule + +end module SomeModule +!--- ModuleUser.f90 + +module User + use SomeModule +end module User ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Correct typo in ReleaseNotes.rst (PR #104674)
https://github.com/xgupta approved this pull request. Thanks! https://github.com/llvm/llvm-project/pull/104674 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 88f8010 - [clang-tidy] Correct typo in ReleaseNotes.rst (#104674)
Author: Mike Crowe Date: 2024-08-18T11:28:25+05:30 New Revision: 88f801037338a2c273a8f6dea8ebcb0c48a2cc06 URL: https://github.com/llvm/llvm-project/commit/88f801037338a2c273a8f6dea8ebcb0c48a2cc06 DIFF: https://github.com/llvm/llvm-project/commit/88f801037338a2c273a8f6dea8ebcb0c48a2cc06.diff LOG: [clang-tidy] Correct typo in ReleaseNotes.rst (#104674) Added: Modified: clang-tools-extra/docs/ReleaseNotes.rst Removed: diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b72d109b3d3938..0f6b34cf400521 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -106,7 +106,7 @@ Changes in existing checks - Improved :doc:`readability-redundant-smartptr-get ` check to - remove `->`, when reduntant `get()` is removed. + remove `->`, when redundant `get()` is removed. Removed checks ^^ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Correct typo in ReleaseNotes.rst (PR #104674)
https://github.com/xgupta closed https://github.com/llvm/llvm-project/pull/104674 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Consider `readability-uppercase-literal-suffix` when dealing with `readability-implicit-bool-conversion`. (PR #104694)
https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/104694 None >From 5e2cd3fa3ce2676e4d528bd8c1342af138cca604 Mon Sep 17 00:00:00 2001 From: c8ef Date: Sun, 18 Aug 2024 06:17:32 + Subject: [PATCH] [clang-tidy] readability-implicit-bool-conversion take readability-uppercase-literal-suffix into account --- .../ImplicitBoolConversionCheck.cpp | 36 ++- .../readability/ImplicitBoolConversionCheck.h | 1 + .../implicit-bool-conversion-uppercase.cpp| 21 +++ 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-uppercase.cpp diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp index aa115cd450c4f6..3bd0b5530a9a5a 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -40,13 +40,18 @@ AST_MATCHER(Stmt, isNULLMacroExpansion) { StringRef getZeroLiteralToCompareWithForType(CastKind CastExprKind, QualType Type, + bool IsUseUppercaseSuffixEnabled, ASTContext &Context) { switch (CastExprKind) { case CK_IntegralToBoolean: -return Type->isUnsignedIntegerType() ? "0u" : "0"; +return Type->isUnsignedIntegerType() + ? (IsUseUppercaseSuffixEnabled ? "0U" : "0u") + : "0"; case CK_FloatingToBoolean: -return Context.hasSameType(Type, Context.FloatTy) ? "0.0f" : "0.0"; +return Context.hasSameType(Type, Context.FloatTy) + ? (IsUseUppercaseSuffixEnabled ? "0.0F" : "0.0f") + : "0.0"; case CK_PointerToBoolean: case CK_MemberPointerToBoolean: // Fall-through on purpose. @@ -66,6 +71,7 @@ bool isUnaryLogicalNotOperator(const Stmt *Statement) { void fixGenericExprCastToBool(DiagnosticBuilder &Diag, const ImplicitCastExpr *Cast, const Stmt *Parent, + bool IsUseUppercaseSuffixEnabled, ASTContext &Context) { // In case of expressions like (! integer), we should remove the redundant not // operator and use inverted comparison (integer == 0). @@ -113,7 +119,8 @@ void fixGenericExprCastToBool(DiagnosticBuilder &Diag, } EndLocInsertion += getZeroLiteralToCompareWithForType( - Cast->getCastKind(), SubExpr->getType(), Context); + Cast->getCastKind(), SubExpr->getType(), IsUseUppercaseSuffixEnabled, + Context); if (NeedOuterParens) { EndLocInsertion += ")"; @@ -192,7 +199,9 @@ void fixGenericExprCastFromBool(DiagnosticBuilder &Diag, } StringRef getEquivalentForBoolLiteral(const CXXBoolLiteralExpr *BoolLiteral, - QualType DestType, ASTContext &Context) { + QualType DestType, + bool IsUseUppercaseSuffixEnabled, + ASTContext &Context) { // Prior to C++11, false literal could be implicitly converted to pointer. if (!Context.getLangOpts().CPlusPlus11 && (DestType->isPointerType() || DestType->isMemberPointerType()) && @@ -202,13 +211,17 @@ StringRef getEquivalentForBoolLiteral(const CXXBoolLiteralExpr *BoolLiteral, if (DestType->isFloatingType()) { if (Context.hasSameType(DestType, Context.FloatTy)) { - return BoolLiteral->getValue() ? "1.0f" : "0.0f"; + return BoolLiteral->getValue() + ? (IsUseUppercaseSuffixEnabled ? "1.0F" : "1.0f") + : (IsUseUppercaseSuffixEnabled ? "0.0F" : "0.0f"); } return BoolLiteral->getValue() ? "1.0" : "0.0"; } if (DestType->isUnsignedIntegerType()) { -return BoolLiteral->getValue() ? "1u" : "0u"; +return BoolLiteral->getValue() + ? (IsUseUppercaseSuffixEnabled ? "1U" : "1u") + : (IsUseUppercaseSuffixEnabled ? "0U" : "0u"); } return BoolLiteral->getValue() ? "1" : "0"; } @@ -248,7 +261,9 @@ ImplicitBoolConversionCheck::ImplicitBoolConversionCheck( StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), AllowIntegerConditions(Options.get("AllowIntegerConditions", false)), - AllowPointerConditions(Options.get("AllowPointerConditions", false)) {} + AllowPointerConditions(Options.get("AllowPointerConditions", false)), + IsUseUppercaseSuffixEnabled( + Context->isCheckEnabled("readability-uppercase-literal-suffix")) {} void ImplicitBoolConversionCheck::storeOptions( ClangTidyOptions::OptionMap &Opts) { @@ -378,7 +393,8 @@ void ImplicitBoolConversionCheck::handleCastToBool(const ImplicitCastExpr *Cast, if (!EquivalentLiteral.empty()) {
[clang-tools-extra] [clang-tidy] Consider `readability-uppercase-literal-suffix` when dealing with `readability-implicit-bool-conversion`. (PR #104694)
https://github.com/c8ef edited https://github.com/llvm/llvm-project/pull/104694 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Consider `readability-uppercase-literal-suffix` when dealing with `readability-implicit-bool-conversion`. (PR #104694)
llvmbot wrote: @llvm/pr-subscribers-clang-tidy Author: None (c8ef) Changes close: #40544. --- Full diff: https://github.com/llvm/llvm-project/pull/104694.diff 3 Files Affected: - (modified) clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp (+27-9) - (modified) clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h (+1) - (added) clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-uppercase.cpp (+21) ``diff diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp index aa115cd450c4f6..3bd0b5530a9a5a 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -40,13 +40,18 @@ AST_MATCHER(Stmt, isNULLMacroExpansion) { StringRef getZeroLiteralToCompareWithForType(CastKind CastExprKind, QualType Type, + bool IsUseUppercaseSuffixEnabled, ASTContext &Context) { switch (CastExprKind) { case CK_IntegralToBoolean: -return Type->isUnsignedIntegerType() ? "0u" : "0"; +return Type->isUnsignedIntegerType() + ? (IsUseUppercaseSuffixEnabled ? "0U" : "0u") + : "0"; case CK_FloatingToBoolean: -return Context.hasSameType(Type, Context.FloatTy) ? "0.0f" : "0.0"; +return Context.hasSameType(Type, Context.FloatTy) + ? (IsUseUppercaseSuffixEnabled ? "0.0F" : "0.0f") + : "0.0"; case CK_PointerToBoolean: case CK_MemberPointerToBoolean: // Fall-through on purpose. @@ -66,6 +71,7 @@ bool isUnaryLogicalNotOperator(const Stmt *Statement) { void fixGenericExprCastToBool(DiagnosticBuilder &Diag, const ImplicitCastExpr *Cast, const Stmt *Parent, + bool IsUseUppercaseSuffixEnabled, ASTContext &Context) { // In case of expressions like (! integer), we should remove the redundant not // operator and use inverted comparison (integer == 0). @@ -113,7 +119,8 @@ void fixGenericExprCastToBool(DiagnosticBuilder &Diag, } EndLocInsertion += getZeroLiteralToCompareWithForType( - Cast->getCastKind(), SubExpr->getType(), Context); + Cast->getCastKind(), SubExpr->getType(), IsUseUppercaseSuffixEnabled, + Context); if (NeedOuterParens) { EndLocInsertion += ")"; @@ -192,7 +199,9 @@ void fixGenericExprCastFromBool(DiagnosticBuilder &Diag, } StringRef getEquivalentForBoolLiteral(const CXXBoolLiteralExpr *BoolLiteral, - QualType DestType, ASTContext &Context) { + QualType DestType, + bool IsUseUppercaseSuffixEnabled, + ASTContext &Context) { // Prior to C++11, false literal could be implicitly converted to pointer. if (!Context.getLangOpts().CPlusPlus11 && (DestType->isPointerType() || DestType->isMemberPointerType()) && @@ -202,13 +211,17 @@ StringRef getEquivalentForBoolLiteral(const CXXBoolLiteralExpr *BoolLiteral, if (DestType->isFloatingType()) { if (Context.hasSameType(DestType, Context.FloatTy)) { - return BoolLiteral->getValue() ? "1.0f" : "0.0f"; + return BoolLiteral->getValue() + ? (IsUseUppercaseSuffixEnabled ? "1.0F" : "1.0f") + : (IsUseUppercaseSuffixEnabled ? "0.0F" : "0.0f"); } return BoolLiteral->getValue() ? "1.0" : "0.0"; } if (DestType->isUnsignedIntegerType()) { -return BoolLiteral->getValue() ? "1u" : "0u"; +return BoolLiteral->getValue() + ? (IsUseUppercaseSuffixEnabled ? "1U" : "1u") + : (IsUseUppercaseSuffixEnabled ? "0U" : "0u"); } return BoolLiteral->getValue() ? "1" : "0"; } @@ -248,7 +261,9 @@ ImplicitBoolConversionCheck::ImplicitBoolConversionCheck( StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), AllowIntegerConditions(Options.get("AllowIntegerConditions", false)), - AllowPointerConditions(Options.get("AllowPointerConditions", false)) {} + AllowPointerConditions(Options.get("AllowPointerConditions", false)), + IsUseUppercaseSuffixEnabled( + Context->isCheckEnabled("readability-uppercase-literal-suffix")) {} void ImplicitBoolConversionCheck::storeOptions( ClangTidyOptions::OptionMap &Opts) { @@ -378,7 +393,8 @@ void ImplicitBoolConversionCheck::handleCastToBool(const ImplicitCastExpr *Cast, if (!EquivalentLiteral.empty()) { Diag << tooling::fixit::createReplacement(*Cast, EquivalentLiteral); } else { -fixGenericExprCastToBool(Diag, Cast, Parent, Context); +fixGenericExprCastToBool(Diag, Cast, Paren
[clang] 07bd3bb - [clang][bytecode][NFC] Improve Pointer::print()
Author: Timm Bäder Date: 2024-08-18T08:55:22+02:00 New Revision: 07bd3bb9b7eb34426a81de2b988f53f08611ab35 URL: https://github.com/llvm/llvm-project/commit/07bd3bb9b7eb34426a81de2b988f53f08611ab35 DIFF: https://github.com/llvm/llvm-project/commit/07bd3bb9b7eb34426a81de2b988f53f08611ab35.diff LOG: [clang][bytecode][NFC] Improve Pointer::print() Do not access PointeeStorage.BS.Pointee if we have a non-block pointer and extend printing to handle function pointers as well. Added: Modified: clang/lib/AST/ByteCode/Pointer.cpp Removed: diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index 466e61666c76e9..e39459578a5f52 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -265,10 +265,10 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const { } void Pointer::print(llvm::raw_ostream &OS) const { - OS << PointeeStorage.BS.Pointee << " ("; - if (isBlockPointer()) { + switch (StorageKind) { + case Storage::Block: { const Block *B = PointeeStorage.BS.Pointee; -OS << "Block) {"; +OS << "(Block) " << B << " {"; if (isRoot()) OS << "rootptr(" << PointeeStorage.BS.Base << "), "; @@ -284,11 +284,18 @@ void Pointer::print(llvm::raw_ostream &OS) const { OS << B->getSize(); else OS << "nullptr"; - } else { -OS << "Int) {"; -OS << PointeeStorage.Int.Value << ", " << PointeeStorage.Int.Desc; +OS << "}"; + } break; + case Storage::Int: +OS << "(Int) {"; +OS << PointeeStorage.Int.Value << " + " << Offset << ", " + << PointeeStorage.Int.Desc; +OS << "}"; +break; + case Storage::Fn: +OS << "(Fn) { " << asFunctionPointer().getFunction() << " + " << Offset + << " }"; } - OS << "}"; } std::string Pointer::toDiagnosticString(const ASTContext &Ctx) const { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] IntPointer::atOffset() should append (PR #104686)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/104686 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] dac1829 - [clang][bytecode] IntPointer::atOffset() should append (#104686)
Author: Timm Baeder Date: 2024-08-18T08:59:34+02:00 New Revision: dac182990dabe8d15cfb8079aba68df2ded015aa URL: https://github.com/llvm/llvm-project/commit/dac182990dabe8d15cfb8079aba68df2ded015aa DIFF: https://github.com/llvm/llvm-project/commit/dac182990dabe8d15cfb8079aba68df2ded015aa.diff LOG: [clang][bytecode] IntPointer::atOffset() should append (#104686) ... to current offset. This breaks other tests which this commit also fixes. Namely, getIndex() should return the integer representation for non-block pointers. Added: clang/test/AST/ByteCode/codegen.c Modified: clang/lib/AST/ByteCode/Interp.h clang/lib/AST/ByteCode/Pointer.cpp clang/lib/AST/ByteCode/Pointer.h Removed: diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 9891e3dba0d30..6cb7a42482ab2 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -1853,6 +1853,17 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset, if (!CheckArray(S, OpPC, Ptr)) return false; + // This is much simpler for integral pointers, so handle them first. + if (Ptr.isIntegralPointer()) { +uint64_t V = Ptr.getIntegerRepresentation(); +uint64_t O = static_cast(Offset) * Ptr.elemSize(); +if constexpr (Op == ArithOp::Add) + S.Stk.push(V + O, Ptr.asIntPointer().Desc); +else + S.Stk.push(V - O, Ptr.asIntPointer().Desc); +return true; + } + uint64_t MaxIndex = static_cast(Ptr.getNumElems()); uint64_t Index; if (Ptr.isOnePastEnd()) diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index e39459578a5f5..5b9e83764cfa5 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -654,5 +654,5 @@ IntPointer IntPointer::atOffset(const ASTContext &ASTCtx, uint64_t FieldOffset = ASTCtx.toCharUnitsFromBits(Layout.getFieldOffset(FieldIndex)) .getQuantity(); - return IntPointer{this->Desc, FieldOffset}; + return IntPointer{this->Desc, this->Value + FieldOffset}; } diff --git a/clang/lib/AST/ByteCode/Pointer.h b/clang/lib/AST/ByteCode/Pointer.h index 8db081c0ec82b..ba30449977376 100644 --- a/clang/lib/AST/ByteCode/Pointer.h +++ b/clang/lib/AST/ByteCode/Pointer.h @@ -571,7 +571,7 @@ class Pointer { /// Returns the index into an array. int64_t getIndex() const { if (!isBlockPointer()) - return 0; + return getIntegerRepresentation(); if (isZero()) return 0; diff --git a/clang/test/AST/ByteCode/codegen.c b/clang/test/AST/ByteCode/codegen.c new file mode 100644 index 0..8434992823010 --- /dev/null +++ b/clang/test/AST/ByteCode/codegen.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s + +typedef __INTPTR_TYPE__ intptr_t; + +const intptr_t Z1 = (intptr_t)(((char*)-1LL) + 1); +// CHECK: @Z1 = constant i64 0 + +const intptr_t Z2 = (intptr_t)(((char*)1LL) - 1); +// CHECK: @Z2 = constant i64 0 + +struct A { + char num_fields; +}; +struct B { + char a, b[1]; +}; +const int A = (char *)(&( (struct B *)(16) )->b[0]) - (char *)(16); +// CHECK: @A = constant i32 1 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits