[PATCH] D153366: [dataflow] Add dedicated representation of boolean formulas

2023-06-23 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

In D153366#4441758 , @sammccall wrote:

>> Would you like me to review https://reviews.llvm.org/D153469 or should we 
>> wait for this patch to converge first?
>
> Similarly it'd be great to get high-level feedback there: whether the design 
> of FormulaBoolValue is right, whether the changes to use Atom/Formula more 
> pervasively seem sensible etc.
> For the details, probably better to wait until this one is stable to avoid 
> churn...
>
> Thanks!

Will do!




Comment at: clang/include/clang/Analysis/FlowSensitive/Formula.h:71
+  ArrayRef operands() const {
+return ArrayRef(reinterpret_cast(this + 1),
+numOperands(kind()));

sammccall wrote:
> mboehme wrote:
> > Is this technically legal? (I've taken a look, but the definition of 
> > similar types makes my eyes glaze over.)
> > 
> > Why not use `TrailingObjects` instead? (I'm not really familiar with 
> > `TrailingObjects`, so there may be good reasons against it -- just asking 
> > because it seems like an obvious existing mechanism that could be used 
> > here.)
> > Is this technically legal?
> 
> Yeah, it's OK: similar types etc is not relevant because these pointers are 
> not pointing to objects of different types: there's an object of type Formula 
> at one address that has a lifetime that begins at the constructor (but it's 
> trivially destructible and never destroyed), and then objects of type 
> `Formula*` at higher addresses - these don't overlap, and are both part of 
> the chunks of memory provided by malloc.
> 
> > Why not use TrailingObjects instead? 
> 
> TrailingObjects is complicated and ugly - it *can* work for this, but I don't 
> think it's actually easier to understand. (Do a code search for "this + 1" in 
> LLVM - this is often done "by hand" instead of with TrailingObjects for 
> simple cases like this one).
> 
> e.g. here we have a little magic in create() and a little in operands(). 
> TrailingObjects equally needs ~2 pieces of magic, they're *slightly* less 
> scary, but they also don't relate directly to the memory layout, and I don't 
> think you can have a meaningful understanding of what this is for without 
> also thinking about the memory layout.
> 
> TrailingObjects shines when the pointer arithmetic gets complicated, though...
> > Is this technically legal?
> 
> Yeah, it's OK: similar types etc is not relevant because these pointers are 
> not pointing to objects of different types: there's an object of type Formula 
> at one address that has a lifetime that begins at the constructor (but it's 
> trivially destructible and never destroyed), and then objects of type 
> `Formula*` at higher addresses - these don't overlap, and are both part of 
> the chunks of memory provided by malloc.

Thanks for the explanation!

Is it worth putting a (condensed) version of this in a comment, or is this 
well-known enough that it's not worth it?

> > Why not use TrailingObjects instead? 
> 
> TrailingObjects is complicated and ugly - it *can* work for this, but I don't 
> think it's actually easier to understand. (Do a code search for "this + 1" in 
> LLVM - this is often done "by hand" instead of with TrailingObjects for 
> simple cases like this one).
> 
> e.g. here we have a little magic in create() and a little in operands(). 
> TrailingObjects equally needs ~2 pieces of magic, they're *slightly* less 
> scary, but they also don't relate directly to the memory layout, and I don't 
> think you can have a meaningful understanding of what this is for without 
> also thinking about the memory layout.
> 
> TrailingObjects shines when the pointer arithmetic gets complicated, though...

Again, thanks for the explanation. I don't have any experience with 
`TrailingObjects` except for using classes that are implemented using it, so 
thanks for filling me in.



Comment at: clang/include/clang/Analysis/FlowSensitive/Formula.h:104
+  Kind FormulaKind;
+  unsigned Value;
+};

sammccall wrote:
> mboehme wrote:
> > Why not give this type `Atom`?
> I don't think it should always be Atom, even when it's used
> 
> see D153485 where I add a "Literal" formula and use value to distinguish 
> true/false
Ah, I understand now.

Maybe add a comment somewhere to explain this distinction? (If it had me 
scratching my head, it might do so for others too.)



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:218
 
-  BooleanFormula Formula(NextVar - 1, std::move(Atomics));
+  BooleanFormula Form(NextVar - 1, std::move(Atomics));
   std::vector ProcessedSubVals(NextVar, false);

sammccall wrote:
> mboehme wrote:
> > Now that we've added `Formula`, it's pretty confusing that we also have 
> > `BooleanFormula`.
> > 
> > I assume this is one of the renamings that you want to get to later? I 
> > guess `BooleanFormula` becomes something like `CnfFormula` (w

[PATCH] D153259: [clangd] Store offsets in MacroOccurrence

2023-06-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 533873.
hokein marked 2 inline comments as done.
hokein added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153259/new/

https://reviews.llvm.org/D153259

Files:
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -30,6 +30,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Testing/Annotations/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest-matchers.h"
 #include "gtest/gtest.h"
@@ -322,16 +323,16 @@
 
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Contents);
-Annotations Modified(Case.Contents);
+llvm::Annotations Modified(Case.Contents);
 EXPECT_THAT(getPreamblePatch("", Modified.code()),
 MatchesRegex(Case.ExpectedPatch));
 
 auto AST = createPatchedAST("", Modified.code());
 ASSERT_TRUE(AST);
-std::vector MacroRefRanges;
+std::vector MacroRefRanges;
 for (auto &M : AST->getMacros().MacroRefs) {
   for (auto &O : M.getSecond())
-MacroRefRanges.push_back(O.Rng);
+MacroRefRanges.push_back({O.StartOffset, O.EndOffset});
 }
 EXPECT_THAT(MacroRefRanges, Contains(Modified.range()));
   }
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -13,7 +13,6 @@
 
 #include "../../clang-tidy/ClangTidyCheck.h"
 #include "AST.h"
-#include "Annotations.h"
 #include "Compiler.h"
 #include "Config.h"
 #include "Diagnostics.h"
@@ -31,6 +30,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Testing/Annotations/Annotations.h"
 #include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock-matchers.h"
 #include "gmock/gmock.h"
@@ -281,7 +281,7 @@
 }
 
 TEST(ParsedASTTest, CollectsMainFileMacroExpansions) {
-  Annotations TestCase(R"cpp(
+  llvm::Annotations TestCase(R"cpp(
 #define ^MACRO_ARGS(X, Y) X Y
 // - preamble ends
 ^ID(int A);
@@ -334,15 +334,16 @@
 int D = DEF;
   )cpp";
   ParsedAST AST = TU.build();
-  std::vector MacroExpansionPositions;
+  std::vector MacroExpansionPositions;
   for (const auto &SIDToRefs : AST.getMacros().MacroRefs) {
 for (const auto &R : SIDToRefs.second)
-  MacroExpansionPositions.push_back(R.Rng.start);
+  MacroExpansionPositions.push_back(R.StartOffset);
   }
   for (const auto &R : AST.getMacros().UnknownMacros)
-MacroExpansionPositions.push_back(R.Rng.start);
-  EXPECT_THAT(MacroExpansionPositions,
-  testing::UnorderedElementsAreArray(TestCase.points()));
+MacroExpansionPositions.push_back(R.StartOffset);
+  EXPECT_THAT(
+  MacroExpansionPositions,
+  testing::UnorderedElementsAreArray(TestCase.points()));
 }
 
 MATCHER_P(withFileName, Inc, "") { return arg.FileName == Inc; }
Index: clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
===
--- clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
+++ clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
@@ -23,7 +23,9 @@
 
 using testing::UnorderedElementsAreArray;
 
-MATCHER_P(rangeIs, R, "") { return arg.Rng == R; }
+MATCHER_P(rangeIs, R, "") {
+  return arg.StartOffset == R.Begin && arg.EndOffset == R.End;
+}
 MATCHER(isDef, "") { return arg.IsDefinition; }
 MATCHER(inConditionalDirective, "") { return arg.InConditionalDirective; }
 
@@ -90,7 +92,7 @@
 #define $2(def)[[FOO]] $3[[BAR]]
 int A = $2[[FOO]];
   )cpp"};
-  auto ExpectedResults = [](const Annotations &T, StringRef Name) {
+  auto ExpectedResults = [](const llvm::Annotations &T, StringRef Name) {
 std::vector> ExpectedLocations;
 for (const auto &[R, Bits] : T.rangesWithPayload(Name)) {
   if (Bits == "def")
@@ -105,7 +107,7 @@
   };
 
   for (const char *Test : Tests) {
-Annotations T(Test);
+llvm::Annotations T(Test);
 auto Inputs = TestTU::withCode(T.code());
 Inputs.ExtraArgs.push_back("-std=c++2b");
 auto AST = Inputs.build();
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
==

[PATCH] D153469: [dataflow] Replace most BoolValue subclasses with references to Formula (and AtomicBoolValue => Atom and BoolValue => Formula where appropriate)

2023-06-23 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

Just some top-level comments to begin with.

In D153469#4439770 , @sammccall wrote:

> Here we start to see benefits: Value becomes less reliant on inheritance, 
> flow conditions are no longer Values that can uselessly bear properties, 
> atomic variables are numbered in order of creation, we'll soon be able to 
> have distinct BoolValues with the same formula (but different properties).

I like where this is going. Specifically, I like that we will soon no longer be 
relying in `BoolValue` object identity and will be able to have different 
`BoolValue`s with the same formula. I'm working on a similar change for 
`StructValue`, so I'm well aware of how problematic it is to share the same 
`Value` but then modify properties on it -- it seems like a potential source of 
really puzzling bugs.

> I think I could separate the Value/Arena changes from the ones to use 
> Atom/Formula in DAContext if you think it's useful (the drawback is some risk 
> of ending up in merge hell...)

I don't think that's necessary -- this patch is large in terms of numbers of 
lines changed, but when you eliminate the mechanical changes, there's not too 
much going on.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153469/new/

https://reviews.llvm.org/D153469

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 7298bcf - [clangd] Store offsets in MacroOccurrence

2023-06-23 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-23T09:21:08+02:00
New Revision: 7298bcf7f06145e2d4dfdb177b94dc42fc95dc55

URL: 
https://github.com/llvm/llvm-project/commit/7298bcf7f06145e2d4dfdb177b94dc42fc95dc55
DIFF: 
https://github.com/llvm/llvm-project/commit/7298bcf7f06145e2d4dfdb177b94dc42fc95dc55.diff

LOG: [clangd] Store offsets in MacroOccurrence

Remove the existing `Rng` field.

>From the review comment: https://reviews.llvm.org/D147034

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D153259

Added: 


Modified: 
clang-tools-extra/clangd/CollectMacros.cpp
clang-tools-extra/clangd/CollectMacros.h
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
clang-tools-extra/clangd/unittests/PreambleTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CollectMacros.cpp 
b/clang-tools-extra/clangd/CollectMacros.cpp
index 9fa3d6955fc6f..c5ba8d903ba48 100644
--- a/clang-tools-extra/clangd/CollectMacros.cpp
+++ b/clang-tools-extra/clangd/CollectMacros.cpp
@@ -8,12 +8,22 @@
 
 #include "CollectMacros.h"
 #include "AST.h"
+#include "Protocol.h"
+#include "SourceCode.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/STLExtras.h"
+#include 
 
 namespace clang {
 namespace clangd {
 
+Range MacroOccurrence::toRange(const SourceManager &SM) const {
+  auto MainFile = SM.getMainFileID();
+  return halfOpenToRange(
+  SM, syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM));
+}
+
 void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,
 bool IsDefinition, bool InIfCondition) {
   if (!InMainFile)
@@ -24,12 +34,12 @@ void CollectMainFileMacros::add(const Token &MacroNameTok, 
const MacroInfo *MI,
 
   auto Name = MacroNameTok.getIdentifierInfo()->getName();
   Out.Names.insert(Name);
-  auto Range = halfOpenToRange(
-  SM, CharSourceRange::getCharRange(Loc, MacroNameTok.getEndLoc()));
+  size_t Start = SM.getFileOffset(Loc);
+  size_t End = SM.getFileOffset(MacroNameTok.getEndLoc());
   if (auto SID = getSymbolID(Name, MI, SM))
-Out.MacroRefs[SID].push_back({Range, IsDefinition, InIfCondition});
+Out.MacroRefs[SID].push_back({Start, End, IsDefinition, InIfCondition});
   else
-Out.UnknownMacros.push_back({Range, IsDefinition, InIfCondition});
+Out.UnknownMacros.push_back({Start, End, IsDefinition, InIfCondition});
 }
 
 void CollectMainFileMacros::FileChanged(SourceLocation Loc, FileChangeReason,

diff  --git a/clang-tools-extra/clangd/CollectMacros.h 
b/clang-tools-extra/clangd/CollectMacros.h
index 716a5d58070fd..e3900c08e5df7 100644
--- a/clang-tools-extra/clangd/CollectMacros.h
+++ b/clang-tools-extra/clangd/CollectMacros.h
@@ -16,18 +16,22 @@
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/DenseMap.h"
+#include 
 #include 
 
 namespace clang {
 namespace clangd {
 
 struct MacroOccurrence {
-  // Instead of storing SourceLocation, we have to store the token range 
because
-  // SourceManager from preamble is not available when we build the AST.
-  Range Rng;
+  // Half-open range (end offset is exclusive) inside the main file.
+  size_t StartOffset;
+  size_t EndOffset;
+
   bool IsDefinition;
   // True if the occurence is used in a conditional directive, e.g. #ifdef 
MACRO
   bool InConditionalDirective;
+
+  Range toRange(const SourceManager &SM) const;
 };
 
 struct MainFileMacros {

diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 6a835f31f064b..3826170892e8c 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -1211,7 +1211,8 @@ getSemanticHighlightings(ParsedAST &AST, bool 
IncludeInactiveRegionTokens) {
   AST.getHeuristicResolver());
   // Add highlightings for macro references.
   auto AddMacro = [&](const MacroOccurrence &M) {
-auto &T = Builder.addToken(M.Rng, HighlightingKind::Macro);
+auto &T = Builder.addToken(M.toRange(C.getSourceManager()),
+   HighlightingKind::Macro);
 T.addModifier(HighlightingModifier::GlobalScope);
 if (M.IsDefinition)
   T.addModifier(HighlightingModifier::Declaration);

diff  --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index ad4819fe4b4db..b608296deefad 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1408,7 +1408,7 @@ ReferencesResult findReferences(ParsedAST &AST, Position 
Pos, uint32_t Limit,
   if (Refs != IDToRefs.end()) {
 for (const auto &Ref : Refs->second) {

[PATCH] D153259: [clangd] Store offsets in MacroOccurrence

2023-06-23 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7298bcf7f061: [clangd] Store offsets in MacroOccurrence 
(authored by hokein).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153259/new/

https://reviews.llvm.org/D153259

Files:
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -30,6 +30,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Testing/Annotations/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest-matchers.h"
 #include "gtest/gtest.h"
@@ -322,16 +323,16 @@
 
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Contents);
-Annotations Modified(Case.Contents);
+llvm::Annotations Modified(Case.Contents);
 EXPECT_THAT(getPreamblePatch("", Modified.code()),
 MatchesRegex(Case.ExpectedPatch));
 
 auto AST = createPatchedAST("", Modified.code());
 ASSERT_TRUE(AST);
-std::vector MacroRefRanges;
+std::vector MacroRefRanges;
 for (auto &M : AST->getMacros().MacroRefs) {
   for (auto &O : M.getSecond())
-MacroRefRanges.push_back(O.Rng);
+MacroRefRanges.push_back({O.StartOffset, O.EndOffset});
 }
 EXPECT_THAT(MacroRefRanges, Contains(Modified.range()));
   }
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -13,7 +13,6 @@
 
 #include "../../clang-tidy/ClangTidyCheck.h"
 #include "AST.h"
-#include "Annotations.h"
 #include "Compiler.h"
 #include "Config.h"
 #include "Diagnostics.h"
@@ -31,6 +30,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Testing/Annotations/Annotations.h"
 #include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock-matchers.h"
 #include "gmock/gmock.h"
@@ -281,7 +281,7 @@
 }
 
 TEST(ParsedASTTest, CollectsMainFileMacroExpansions) {
-  Annotations TestCase(R"cpp(
+  llvm::Annotations TestCase(R"cpp(
 #define ^MACRO_ARGS(X, Y) X Y
 // - preamble ends
 ^ID(int A);
@@ -334,15 +334,16 @@
 int D = DEF;
   )cpp";
   ParsedAST AST = TU.build();
-  std::vector MacroExpansionPositions;
+  std::vector MacroExpansionPositions;
   for (const auto &SIDToRefs : AST.getMacros().MacroRefs) {
 for (const auto &R : SIDToRefs.second)
-  MacroExpansionPositions.push_back(R.Rng.start);
+  MacroExpansionPositions.push_back(R.StartOffset);
   }
   for (const auto &R : AST.getMacros().UnknownMacros)
-MacroExpansionPositions.push_back(R.Rng.start);
-  EXPECT_THAT(MacroExpansionPositions,
-  testing::UnorderedElementsAreArray(TestCase.points()));
+MacroExpansionPositions.push_back(R.StartOffset);
+  EXPECT_THAT(
+  MacroExpansionPositions,
+  testing::UnorderedElementsAreArray(TestCase.points()));
 }
 
 MATCHER_P(withFileName, Inc, "") { return arg.FileName == Inc; }
Index: clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
===
--- clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
+++ clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
@@ -23,7 +23,9 @@
 
 using testing::UnorderedElementsAreArray;
 
-MATCHER_P(rangeIs, R, "") { return arg.Rng == R; }
+MATCHER_P(rangeIs, R, "") {
+  return arg.StartOffset == R.Begin && arg.EndOffset == R.End;
+}
 MATCHER(isDef, "") { return arg.IsDefinition; }
 MATCHER(inConditionalDirective, "") { return arg.InConditionalDirective; }
 
@@ -90,7 +92,7 @@
 #define $2(def)[[FOO]] $3[[BAR]]
 int A = $2[[FOO]];
   )cpp"};
-  auto ExpectedResults = [](const Annotations &T, StringRef Name) {
+  auto ExpectedResults = [](const llvm::Annotations &T, StringRef Name) {
 std::vector> ExpectedLocations;
 for (const auto &[R, Bits] : T.rangesWithPayload(Name)) {
   if (Bits == "def")
@@ -105,7 +107,7 @@
   };
 
   for (const char *Test : Tests) {
-Annotations T(Test);
+llvm::Annotations T(Test);
 auto Inputs = TestTU::withCode(T.code());
 Inputs.ExtraArgs.push_back("-std=c++2b");
 auto AST = Inputs.build();
I

[PATCH] D153612: [clang][analyzer] Add and change NoteTags in StdLibraryFunctionsChecker.

2023-06-23 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, gamesh411, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a reviewer: NoQ.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Change 1: ErrnoChecker notes show only messages related to errno,
not to assumption of success or failure of functions.
Change 2: StdLibraryFunctionsChecker adds its own note about success
or failure of functions, and the errno related note, independently.
Change 3: Every modeled function in StdLibraryFunctionsChecker
should have a note tag message in all "cases". This is not implemented yet,
only for file (stream) related functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153612

Files:
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/errno-stdlibraryfunctions-notes.c
  clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
  clang/test/Analysis/std-c-library-functions-path-notes.c
  clang/test/Analysis/stream-errno-note.c

Index: clang/test/Analysis/stream-errno-note.c
===
--- clang/test/Analysis/stream-errno-note.c
+++ clang/test/Analysis/stream-errno-note.c
@@ -10,7 +10,7 @@
 
 void check_fopen(void) {
   FILE *F = fopen("xxx", "r");
-  // expected-note@-1{{Assuming that function 'fopen' is successful, in this case the value 'errno' may be undefined after the call and should not be used}}
+  // expected-note@-1{{'errno' may be undefined after successful call to 'fopen'}}
   // expected-note@+2{{'F' is non-null}}
   // expected-note@+1{{Taking false branch}}
   if (!F)
@@ -22,7 +22,7 @@
 
 void check_tmpfile(void) {
   FILE *F = tmpfile();
-  // expected-note@-1{{Assuming that function 'tmpfile' is successful, in this case the value 'errno' may be undefined after the call and should not be used}}
+  // expected-note@-1{{'errno' may be undefined after successful call to 'tmpfile'}}
   // expected-note@+2{{'F' is non-null}}
   // expected-note@+1{{Taking false branch}}
   if (!F)
@@ -39,7 +39,7 @@
   if (!F)
 return;
   F = freopen("xxx", "w", F);
-  // expected-note@-1{{Assuming that function 'freopen' is successful}}
+  // expected-note@-1{{'errno' may be undefined after successful call to 'freopen'}}
   // expected-note@+2{{'F' is non-null}}
   // expected-note@+1{{Taking false branch}}
   if (!F)
@@ -56,7 +56,7 @@
   if (!F)
 return;
   (void)fclose(F);
-  // expected-note@-1{{Assuming that function 'fclose' is successful}}
+  // expected-note@-1{{'errno' may be undefined after successful call to 'fclose'}}
   if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
   // expected-note@-1{{An undefined value may be read from 'errno'}}
 }
@@ -69,7 +69,7 @@
   if (!F)
 return;
   (void)fread(Buf, 1, 10, F);
-  // expected-note@-1{{Assuming that function 'fread' is successful}}
+  // expected-note@-1{{'errno' may be undefined after successful call to 'fread'}}
   if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
   // expected-note@-1{{An undefined value may be read from 'errno'}}
   (void)fclose(F);
@@ -83,7 +83,7 @@
   if (!F)
 return;
   int R = fwrite(Buf, 1, 10, F);
-  // expected-note@-1{{Assuming that function 'fwrite' is successful}}
+  // expected-note@-1{{'errno' may be undefined after successful call to 'fwrite'}}
   if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
   // expected-note@-1{{An undefined value may be read from 'errno'}}
   (void)fclose(F);
@@ -96,7 +96,7 @@
   if (!F)
 return;
   (void)fseek(F, 11, SEEK_SET);
-  // expected-note@-1{{Assuming that function 'fseek' is successful}}
+  // expected-note@-1{{'errno' may be undefined after successful call to 'fseek'}}
   if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
   // expected-note@-1{{An undefined value may be read from 'errno'}}
   (void)fclose(F);
@@ -109,7 +109,7 @@
   if (!F)
 return;
   errno = 0;
-  rewind(F); // expected-note{{Function 'rewind' indicates failure only by setting of 'errno'}}
+  rewind(F); // expected-note{{'rewind' indicates failure only by setting 'errno'}}
   fclose(F); // expected-warning{{Value of 'errno' was not checked and may be overwritten by function 'fclose' [alpha.unix.Errno]}}
   // expected-note@-1{{Value of 'errno' was not checked and may be overwritten by function 'fclose'}}
 }
@@ -121,7 +121,8 @@
   if (!F)
 return;
   fileno(F);
-  // expected-note@-1{{Assuming that function 'fileno' is successful}}
+  // expected-note@-1{{Assuming that the call is successful}}
+  // expected-note@

[PATCH] D143241: [Clang] Reset FP options before function instantiations

2023-06-23 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

In D143241#4441812 , @rjmccall wrote:

> Hmm.  Why are we clearing the FP pragma stack instead of saving the old 
> context onto it and then restoring after instantiation?  I don't think 
> semantic analysis ever depends on enclosing members of the stack, does it?

It shouldn't but the function body may contain pragmas and in the case of 
errors we could have weird behavior. Anyway, parsing in this case occurs at the 
end of translation unit, so it should be safe to clear pragma stack.

> Clearing the entire stack might not matter much if we're at the end of the 
> translation unit, which is the normal time to instantiate things, but it 
> would matter if we're eagerly instantiating within the translation unit, 
> which we have to do for various reasons, including explicit instantiation and 
> `constexpr`.

Explicit instantiation performs late parsing at the end of translation unit, 
just as implicit one. Constexpr functions are parsed as usualy, at the point of 
definition (see `Sema::canDelayFunctionBody`). It seems late parsing always 
occurs at the end of TU.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143241/new/

https://reviews.llvm.org/D143241

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153616: [clang][Interp] Create a new local variable in visitLambdaExpr()

2023-06-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  Move the logic for initialization of a lambda into
  visitRecordInitializer(). When we visit a LambdaExpr outside of the
  visitInitializer() logic, we need to create a new local variable so we
  have a place to write the lambda members into.

This fixes passing lambas as arguments to function calls.

In that case, we visit a `LambdaExpr` without it being an initializer to 
anything, so we should create a new local variable and return a pointer to it, 
which we then pass to the function call.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153616

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/lambda.cpp

Index: clang/test/AST/Interp/lambda.cpp
===
--- clang/test/AST/Interp/lambda.cpp
+++ clang/test/AST/Interp/lambda.cpp
@@ -107,6 +107,29 @@
   static_assert(foo() == 1); // expected-error {{not an integral constant expression}}
 }
 
+namespace LambdasAsParams {
+  template
+  constexpr auto call(F f) {
+return f();
+  }
+  static_assert(call([](){ return 1;}) == 1);
+  static_assert(call([](){ return 2;}) == 2);
+
+
+  constexpr unsigned L = call([](){ return 12;});
+  static_assert(L == 12);
+
+
+  constexpr float heh() {
+auto a = []() {
+  return 1.0;
+};
+
+return static_cast(a());
+  }
+  static_assert(heh() == 1.0);
+}
+
 namespace StaticInvoker {
   constexpr int sv1(int i) {
 auto l = []() { return 12; };
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1062,39 +1062,15 @@
 
 template 
 bool ByteCodeExprGen::VisitLambdaExpr(const LambdaExpr *E) {
-  // XXX We assume here that a pointer-to-initialize is on the stack.
 
-  const Record *R = P.getOrCreateRecord(E->getLambdaClass());
-
-  auto *CaptureInitIt = E->capture_init_begin();
-  // Initialize all fields (which represent lambda captures) of the
-  // record with their initializers.
-  for (const Record::Field &F : R->fields()) {
-const Expr *Init = *CaptureInitIt;
-++CaptureInitIt;
-
-if (std::optional T = classify(Init)) {
-  if (!this->visit(Init))
-return false;
-
-  if (!this->emitSetField(*T, F.Offset, E))
-return false;
-} else {
-  if (!this->emitDupPtr(E))
-return false;
-
-  if (!this->emitGetPtrField(F.Offset, E))
-return false;
-
-  if (!this->visitInitializer(Init))
-return false;
+  if (std::optional GI = allocateLocal(E, /*IsExtended=*/false)) {
+if (!this->emitGetPtrLocal(*GI, E))
+  return false;
 
-  if (!this->emitPopPtr(E))
-return false;
-}
+return this->visitRecordInitializer(E);
   }
 
-  return true;
+  return false;
 }
 
 template 
@@ -1714,7 +1690,39 @@
 return this->visitConditional(
 ACO, [this](const Expr *E) { return this->visitRecordInitializer(E); });
   } else if (const auto *LE = dyn_cast(Initializer)) {
-return this->VisitLambdaExpr(LE);
+// XXX We assume here that a pointer-to-initialize is on the stack.
+
+const Record *R = P.getOrCreateRecord(LE->getLambdaClass());
+
+auto *CaptureInitIt = LE->capture_init_begin();
+// Initialize all fields (which represent lambda captures) of the
+// record with their initializers.
+for (const Record::Field &F : R->fields()) {
+  const Expr *Init = *CaptureInitIt;
+  ++CaptureInitIt;
+
+  if (std::optional T = classify(Init)) {
+if (!this->visit(Init))
+  return false;
+
+if (!this->emitSetField(*T, F.Offset, LE))
+  return false;
+  } else {
+if (!this->emitDupPtr(LE))
+  return false;
+
+if (!this->emitGetPtrField(F.Offset, LE))
+  return false;
+
+if (!this->visitInitializer(Init))
+  return false;
+
+if (!this->emitPopPtr(LE))
+  return false;
+  }
+}
+
+return true;
   }
 
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] dd639eb - [clang][ASTImporter] Add import of CXXRewrittenBinaryOperator.

2023-06-23 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2023-06-23T10:04:01+02:00
New Revision: dd639eb15aacfc865409915516f52385c4381923

URL: 
https://github.com/llvm/llvm-project/commit/dd639eb15aacfc865409915516f52385c4381923
DIFF: 
https://github.com/llvm/llvm-project/commit/dd639eb15aacfc865409915516f52385c4381923.diff

LOG: [clang][ASTImporter] Add import of CXXRewrittenBinaryOperator.

Fix for issue #62770.

Reviewed By: donat.nagy

Differential Revision: https://reviews.llvm.org/D153424

Added: 
clang/test/ASTMerge/cxx-rewritten-binary-operator/Inputs/rbo.cpp
clang/test/ASTMerge/cxx-rewritten-binary-operator/Inputs/std-compare.h
clang/test/ASTMerge/cxx-rewritten-binary-operator/test.cpp

Modified: 
clang/lib/AST/ASTImporter.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 5e1ddadb071b6..183104d16306d 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -640,6 +640,7 @@ namespace clang {
 ExpectedStmt VisitBinaryOperator(BinaryOperator *E);
 ExpectedStmt VisitConditionalOperator(ConditionalOperator *E);
 ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E);
+ExpectedStmt VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator 
*E);
 ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E);
 ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E);
 ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E);
@@ -7456,6 +7457,17 @@ 
ASTNodeImporter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
   E->getObjectKind());
 }
 
+ExpectedStmt ASTNodeImporter::VisitCXXRewrittenBinaryOperator(
+CXXRewrittenBinaryOperator *E) {
+  Error Err = Error::success();
+  auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
+  if (Err)
+return std::move(Err);
+
+  return new (Importer.getToContext())
+  CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
+}
+
 ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
   Error Err = Error::success();
   auto ToBeginLoc = importChecked(Err, E->getBeginLoc());

diff  --git a/clang/test/ASTMerge/cxx-rewritten-binary-operator/Inputs/rbo.cpp 
b/clang/test/ASTMerge/cxx-rewritten-binary-operator/Inputs/rbo.cpp
new file mode 100644
index 0..bb928ab3fadb4
--- /dev/null
+++ b/clang/test/ASTMerge/cxx-rewritten-binary-operator/Inputs/rbo.cpp
@@ -0,0 +1,8 @@
+#include "std-compare.h"
+
+struct A {
+  int a;
+  constexpr auto operator<=>(const A&) const = default;
+};
+
+bool foo(A x, A y) { return x < y; }

diff  --git 
a/clang/test/ASTMerge/cxx-rewritten-binary-operator/Inputs/std-compare.h 
b/clang/test/ASTMerge/cxx-rewritten-binary-operator/Inputs/std-compare.h
new file mode 100644
index 0..eaf7951edf79c
--- /dev/null
+++ b/clang/test/ASTMerge/cxx-rewritten-binary-operator/Inputs/std-compare.h
@@ -0,0 +1,307 @@
+#ifndef STD_COMPARE_H
+#define STD_COMPARE_H
+
+namespace std {
+inline namespace __1 {
+
+// exposition only
+enum class _EqResult : unsigned char {
+  __equal = 0,
+  __equiv = __equal,
+};
+
+enum class _OrdResult : signed char {
+  __less = -1,
+  __greater = 1
+};
+
+enum class _NCmpResult : signed char {
+  __unordered = -127
+};
+
+struct _CmpUnspecifiedType;
+using _CmpUnspecifiedParam = void (_CmpUnspecifiedType::*)();
+
+class partial_ordering {
+  using _ValueT = signed char;
+  explicit constexpr partial_ordering(_EqResult __v) noexcept
+  : __value_(_ValueT(__v)) {}
+  explicit constexpr partial_ordering(_OrdResult __v) noexcept
+  : __value_(_ValueT(__v)) {}
+  explicit constexpr partial_ordering(_NCmpResult __v) noexcept
+  : __value_(_ValueT(__v)) {}
+
+  constexpr bool __is_ordered() const noexcept {
+return __value_ != _ValueT(_NCmpResult::__unordered);
+  }
+
+public:
+  // valid values
+  static const partial_ordering less;
+  static const partial_ordering equivalent;
+  static const partial_ordering greater;
+  static const partial_ordering unordered;
+
+  // comparisons
+  friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) 
noexcept;
+  friend constexpr bool operator!=(partial_ordering __v, _CmpUnspecifiedParam) 
noexcept;
+  friend constexpr bool operator<(partial_ordering __v, _CmpUnspecifiedParam) 
noexcept;
+  friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) 
noexcept;
+  friend constexpr bool operator>(partial_ordering __v, _CmpUnspecifiedParam) 
noexcept;
+  friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) 
noexcept;
+  friend constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) 
noexcept;
+  friend constexpr bool operator!=(_CmpUnspecifiedParam, partial_ordering __v) 
noexcept;
+  friend constexpr bool operator<(_CmpUnspecifiedParam, partial_ordering __v) 
noexcept;
+  friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_

[PATCH] D153424: [clang][ASTImporter] Add import of CXXRewrittenBinaryOperator.

2023-06-23 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdd639eb15aac: [clang][ASTImporter] Add import of 
CXXRewrittenBinaryOperator. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153424/new/

https://reviews.llvm.org/D153424

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/test/ASTMerge/cxx-rewritten-binary-operator/Inputs/rbo.cpp
  clang/test/ASTMerge/cxx-rewritten-binary-operator/Inputs/std-compare.h
  clang/test/ASTMerge/cxx-rewritten-binary-operator/test.cpp

Index: clang/test/ASTMerge/cxx-rewritten-binary-operator/test.cpp
===
--- /dev/null
+++ clang/test/ASTMerge/cxx-rewritten-binary-operator/test.cpp
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -std=c++20 -emit-pch -o %t.1.ast %S/Inputs/rbo.cpp
+// RUN: %clang_cc1 -std=c++20 -ast-merge %t.1.ast -fsyntax-only %s 2>&1 | FileCheck --allow-empty %s
+// CHECK-NOT: unsupported AST node
Index: clang/test/ASTMerge/cxx-rewritten-binary-operator/Inputs/std-compare.h
===
--- /dev/null
+++ clang/test/ASTMerge/cxx-rewritten-binary-operator/Inputs/std-compare.h
@@ -0,0 +1,307 @@
+#ifndef STD_COMPARE_H
+#define STD_COMPARE_H
+
+namespace std {
+inline namespace __1 {
+
+// exposition only
+enum class _EqResult : unsigned char {
+  __equal = 0,
+  __equiv = __equal,
+};
+
+enum class _OrdResult : signed char {
+  __less = -1,
+  __greater = 1
+};
+
+enum class _NCmpResult : signed char {
+  __unordered = -127
+};
+
+struct _CmpUnspecifiedType;
+using _CmpUnspecifiedParam = void (_CmpUnspecifiedType::*)();
+
+class partial_ordering {
+  using _ValueT = signed char;
+  explicit constexpr partial_ordering(_EqResult __v) noexcept
+  : __value_(_ValueT(__v)) {}
+  explicit constexpr partial_ordering(_OrdResult __v) noexcept
+  : __value_(_ValueT(__v)) {}
+  explicit constexpr partial_ordering(_NCmpResult __v) noexcept
+  : __value_(_ValueT(__v)) {}
+
+  constexpr bool __is_ordered() const noexcept {
+return __value_ != _ValueT(_NCmpResult::__unordered);
+  }
+
+public:
+  // valid values
+  static const partial_ordering less;
+  static const partial_ordering equivalent;
+  static const partial_ordering greater;
+  static const partial_ordering unordered;
+
+  // comparisons
+  friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
+  friend constexpr bool operator!=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
+  friend constexpr bool operator<(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
+  friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
+  friend constexpr bool operator>(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
+  friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
+  friend constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
+  friend constexpr bool operator!=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
+  friend constexpr bool operator<(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
+  friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
+  friend constexpr bool operator>(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
+  friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
+
+  friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
+  friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
+
+  // test helper
+  constexpr bool test_eq(partial_ordering const &other) const noexcept {
+return __value_ == other.__value_;
+  }
+
+private:
+  _ValueT __value_;
+};
+
+inline constexpr partial_ordering partial_ordering::less(_OrdResult::__less);
+inline constexpr partial_ordering partial_ordering::equivalent(_EqResult::__equiv);
+inline constexpr partial_ordering partial_ordering::greater(_OrdResult::__greater);
+inline constexpr partial_ordering partial_ordering::unordered(_NCmpResult ::__unordered);
+constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
+  return __v.__is_ordered() && __v.__value_ == 0;
+}
+constexpr bool operator<(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
+  return __v.__is_ordered() && __v.__value_ < 0;
+}
+constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
+  return __v.__is_ordered() && __v.__value_ <= 0;
+}
+constexpr bool operator>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
+  return __v.__is_ordered() && __v.__value_ > 0;
+}
+constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
+  return __v.__is_ordered() && __v.__value_ >= 0;
+}
+constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
+  return __v.__is_ordered() && 0 == __v.__valu

[PATCH] D153430: [Clang][Driver] Warn on invalid Arm or AArch64 baremetal target triple

2023-06-23 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

> Does that make it clearer? (I still suspect that people won't understand what 
> is meant by "environment" here but I can't think of a better explanation).

"clang triple environment" into Google gets you the cross compilation guide and 
the Triple class docs so "environment" is useful here as one more keyword for 
that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153430/new/

https://reviews.llvm.org/D153430

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153491: [dataflow] Avoid copying environment

2023-06-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

This sounds extremely error-prone to me. In case copying the analysis state has 
side effects like this, I would argue we want such operations to be really 
explicit. What do you think?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153491/new/

https://reviews.llvm.org/D153491

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152263: [clang][CFG] Add support for partitioning CFG into intervals.

2023-06-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Analysis/IntervalPartition.cpp:26
+
+  std::queue Worklist;
+  for (const CFGBlock *S : Header.succs())

ymandel wrote:
> xazax.hun wrote:
> > Is it possible we end up adding the same node to the queue multiple times? 
> > Is that desirable or do we want to make sure we only have each node at most 
> > once?
> Added an answer in comments, but repeating here in case you want to discuss 
> further:
> 
>   // The worklist *may* contain duplicates. We guard against this possibility 
> by
>   // checking each popped element for completion (that is, presence in
>   // `Partitioned`). We choose this approach over using a set because the 
> queue
>   // allows us to flexibly insert and delete elements while iterating through
>   // the list. A set would require two separate phases for iterating and
>   // mutation.
I see, thanks! This addresses my concerns. I think in some cases we use a 
bitset with the blocks' ids to more efficiently track things like that.



Comment at: clang/lib/Analysis/IntervalPartition.cpp:46-47
+
+// Check whether all predecessors are in the interval, in which case `B`
+// is included as well.
+bool AllInInterval = true;

ymandel wrote:
> xazax.hun wrote:
> > I wonder if this approach is correct. Consider the following scenario:
> > 
> > ```
> >A
> >   / \
> >  B   C
> >  |   |
> >  |   D
> >   \ /
> >E
> > ```
> > 
> > In the BFS, we might visit: ABCED. Since we visit `E` before `D`, we might 
> > not recognize that `E` is part of the interval. Do I miss something?
> > I wonder if this approach is correct. Consider the following scenario:
> > 
> > ```
> >A
> >   / \
> >  B   C
> >  |   |
> >  |   D
> >   \ /
> >E
> > ```
> > 
> > In the BFS, we might visit: ABCED. Since we visit `E` before `D`, we might 
> > not recognize that `E` is part of the interval. Do I miss something?
> 
> When we add `D` to the interval, we'll push `E` onto the queue again (lines 
> 58-59). The second time that `E` is considered it will have both successors 
> in the interval and will be added as well.
Ah, I see, makse sense, thanks! This also makes me wonder, would this algorithm 
be more efficient if we used RPO (in case we can use that without recalculating 
the order)? :D But we do not need to benchmark this for the first version. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152263/new/

https://reviews.llvm.org/D152263

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153340: [include-cleaner] Add an IgnoreHeaders flag to the command-line tool.

2023-06-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 533896.
hokein marked 2 inline comments as done.
hokein added a comment.
Herald added a subscriber: arphaman.

address comments:

- move the filtering in analysis API
- add an actual -edit lit test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153340/new/

https://reviews.llvm.org/D153340

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/Types.cpp
  clang-tools-extra/include-cleaner/test/tool.cpp
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -14,8 +14,11 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -47,6 +50,14 @@
 cl::cat(IncludeCleaner),
 };
 
+cl::opt IgnoreHeaders{
+"ignore-headers",
+cl::desc("A comma-separated list of regexes to match against suffix of a "
+ "header, and disable analysis if matched."),
+cl::init(""),
+cl::cat(IncludeCleaner),
+};
+
 enum class PrintStyle { Changes, Final };
 cl::opt Print{
 "print",
@@ -91,9 +102,15 @@
 }
 
 class Action : public clang::ASTFrontendAction {
+public:
+  Action(llvm::function_ref HeaderFilter)
+  : HeaderFilter(HeaderFilter){};
+
+private:
   RecordedAST AST;
   RecordedPP PP;
   PragmaIncludes PI;
+  llvm::function_ref HeaderFilter;
 
   void ExecuteAction() override {
 auto &P = getCompilerInstance().getPreprocessor();
@@ -126,8 +143,8 @@
 assert(!Path.empty() && "Main file path not known?");
 llvm::StringRef Code = SM.getBufferData(SM.getMainFileID());
 
-auto Results =
-analyze(AST.Roots, PP.MacroReferences, PP.Includes, &PI, SM, HS);
+auto Results = analyze(AST.Roots, PP.MacroReferences, PP.Includes, &PI, SM,
+   HS, HeaderFilter);
 if (!Insert)
   Results.Missing.clear();
 if (!Remove)
@@ -137,10 +154,12 @@
 if (Print.getNumOccurrences()) {
   switch (Print) {
   case PrintStyle::Changes:
-for (const Include *I : Results.Unused)
+for (const Include *I : Results.Unused) {
   llvm::outs() << "- " << I->quote() << " @Line:" << I->Line << "\n";
-for (const auto &I : Results.Missing)
+}
+for (const auto &I : Results.Missing) {
   llvm::outs() << "+ " << I << "\n";
+}
 break;
   case PrintStyle::Final:
 llvm::outs() << Final;
@@ -176,6 +195,18 @@
 getCompilerInstance().getPreprocessor().getHeaderSearchInfo(), &PI, OS);
   }
 };
+class ActionFactory : public tooling::FrontendActionFactory {
+public:
+  ActionFactory(llvm::function_ref HeaderFilter)
+  : HeaderFilter(HeaderFilter) {}
+
+  std::unique_ptr create() override {
+return std::make_unique(HeaderFilter);
+  }
+
+private:
+  llvm::function_ref HeaderFilter;
+};
 
 } // namespace
 } // namespace include_cleaner
@@ -191,6 +222,26 @@
 llvm::errs() << toString(OptionsParser.takeError());
 return 1;
   }
+  std::vector FilterRegs;
+  llvm::SmallVector Headers;
+  llvm::StringRef(IgnoreHeaders).split(Headers, ',', -1, /*KeepEmpty*/ false);
+  for (auto HeaderPattern : Headers) {
+std::string AnchoredPattern = "(" + HeaderPattern.str() + ")$";
+llvm::Regex CompiledRegex(AnchoredPattern);
+std::string RegexError;
+if (!CompiledRegex.isValid(RegexError)) {
+  llvm::errs() << llvm::formatv("Invalid regular expression '{0}': {1}\n",
+HeaderPattern, RegexError);
+  return 1;
+}
+FilterRegs.push_back(std::move(CompiledRegex));
+  }
+  auto HeaderFilter = [&FilterRegs](llvm::StringRef Path) {
+for (const auto &F : FilterRegs)
+  if (F.match(Path))
+return true;
+return false;
+  };
 
   if (OptionsParser->getSourcePathList().size() != 1) {
 std::vector IncompatibleFlags = {&HTMLReportPath, &Print};
@@ -201,9 +252,9 @@
   }
 }
   }
-  auto Factory = clang::tooling::newFrontendActionFactory();
+  ActionFactory Factory(HeaderFilter);
   return clang::tooling::ClangTool(OptionsParser->getCompilations(),
OptionsParser->getSourcePathList())
- .run(Factory.get()) ||
+ .run(&Factory) ||
  Errors 

[PATCH] D153340: [include-cleaner] Add an IgnoreHeaders flag to the command-line tool.

2023-06-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp:160
 auto Results =
 analyze(AST.Roots, PP.MacroReferences, PP.Includes, &PI, SM, HS);
 if (!Insert)

kadircet wrote:
> we actually want to perform filtering inside `analyze`. it's not enough to 
> filter only when printing, we should also filter before applying fixes :D. 
> but we should also be applying filtering to absolute paths in all cases, for 
> missing includes this is being applied to spelling instead.
oops, good catch. Added an actual --edit test. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153340/new/

https://reviews.llvm.org/D153340

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153228: [clang-format] Fixed bad performance with enabled qualifier fixer.

2023-06-23 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/Format.cpp:3571-3585
+  // Don't make replacements that replace nothing. This can affect e.g. the
+  // output of clang-format with the --output-replacements-xml option.
+  tooling::Replacements NonNoOpFixes;
+  for (const tooling::Replacement &Fix : Fixes) {
+StringRef OriginalCode = Code.substr(Fix.getOffset(), Fix.getLength());
+if (!OriginalCode.equals(Fix.getReplacementText())) {
+  auto Err = NonNoOpFixes.add(Fix);

Sedeniono wrote:
> owenpan wrote:
> > You only need this for the `QualifierAlignment` passes as others (e.g. 
> > `IntegerLiteralSeparatorFixer`) already skip no-op replacements.
> Yes, in principle I need to do this only after all QualifierAlignment passes 
> ran. The key point is that it needs to be done only after **all** 
> QualifierAlignment passes ran. In other words, I cannot move this to 
> `LeftRightQualifierAlignmentFixer::analyze()`; it would do nothing there. The 
> non-no-op code exists so that if e.g. `const volatile` becomes `volatile 
> const` in one pass and then again `const volatile` in another pass, we end up 
> with no replacements.
> 
> I also cannot simply put all the QualifierAlignment passes into a simple 
> dedicated loop that directly runs them after one another; the part with 
> `applyAllReplacements()` etc (line 3554 till 3566 above) would be missing 
> between the passes. I could, of course, extract lines 3554 till 3566 into a 
> new function and call it in both places. Should I do that?
> 
> Or do you mean that I should wrap the NonNoOpFixes code in an `if 
> (Style.QualifierAlignment != FormatStyle::QAS_Leave)`?
> Or do you mean that I should wrap the NonNoOpFixes code in an `if 
> (Style.QualifierAlignment != FormatStyle::QAS_Leave)`?

I was thinking about something like that at the minimum.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153228/new/

https://reviews.llvm.org/D153228

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-06-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/Lexer/unicode.c:30
 
-int _;
+int a;
 

Are these changes only for the case where we compile as c++? I know lots of C 
(and c++?) projects use `_` as GNU gettext identifier to mark a translatable 
string.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153536/new/

https://reviews.llvm.org/D153536

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152720: [clangd][ObjC] Support ObjC class rename from implementation decls

2023-06-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:164
   AST.getHeuristicResolver())) {
 Result.insert(canonicalRenameDecl(D));
   }

before calling `canonicalRenameDecl` here we can do a `D = 
pickInterestingTarget(D);` and map it to interface decl once (we'll probably 
need something similar for propertydecls?), rather than canonicalizing all 
ObjcCategoryDecls. that way we'll still get to rename proper references that 
target ObjcInterfaceDecls.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:288
+// the interface(s) which they reference.
+if (isa(Target))
+  continue;

i am afraid we're doing this at the wrong layer. the discrepancy is actually 
arising from the fact that `findExplicitReferences` will report name locations 
for an entity whose primary location contains a different name (e.g. 
`@interface ^Foo (^Bar)` saying that there's a reference to objccategorydecl at 
`Bar`, but canonicalizing it to `Foo`).

so i think what we really want is not to canonicalize objccategory(impl)decls 
to objcinterfacedecl, but rather pick rename target as objcinterfacedecl when 
the user is trying to rename a categorydecl inside `locatelDeclAt` (put more 
comments near that part of the code).

sorry for the extra round trip here :/



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:787
+  // names like class and protocol names.
+  if (const auto *CD = dyn_cast(&RenameDecl))
+if (CD->getName() != IdentifierToken->text(SM))

this special casing should no longer be needed if we just map CategoryDecls to 
InterfaceDecls in `locateDeclAt` rather than at canonicalization time



Comment at: clang-tools-extra/clangd/unittests/FindTargetTests.cpp:1990
+
+  std::pair
+  AllRefsCases[] = {// Simple expressions.

can you move this into a separate test case?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152720/new/

https://reviews.llvm.org/D152720

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151923: [APFloat] Add APFloat semantic support for TF32

2023-06-23 Thread Mehdi AMINI via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG55c2211a233e: [APFloat] Add APFloat semantic support for 
TF32 (authored by jfurtek, committed by mehdi_amini).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151923/new/

https://reviews.llvm.org/D151923

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/Support/APFloat.cpp
  llvm/unittests/ADT/APFloatTest.cpp

Index: llvm/unittests/ADT/APFloatTest.cpp
===
--- llvm/unittests/ADT/APFloatTest.cpp
+++ llvm/unittests/ADT/APFloatTest.cpp
@@ -682,6 +682,26 @@
 EXPECT_TRUE(T.isDenormal());
 EXPECT_EQ(fcPosSubnormal, T.classify());
   }
+
+  // Test TF32
+  {
+const char *MinNormalStr = "1.17549435082228750797e-38";
+EXPECT_FALSE(APFloat(APFloat::FloatTF32(), MinNormalStr).isDenormal());
+EXPECT_FALSE(APFloat(APFloat::FloatTF32(), 0).isDenormal());
+
+APFloat Val2(APFloat::FloatTF32(), 2);
+APFloat T(APFloat::FloatTF32(), MinNormalStr);
+T.divide(Val2, rdmd);
+EXPECT_TRUE(T.isDenormal());
+EXPECT_EQ(fcPosSubnormal, T.classify());
+
+const char *NegMinNormalStr = "-1.17549435082228750797e-38";
+EXPECT_FALSE(APFloat(APFloat::FloatTF32(), NegMinNormalStr).isDenormal());
+APFloat NegT(APFloat::FloatTF32(), NegMinNormalStr);
+NegT.divide(Val2, rdmd);
+EXPECT_TRUE(NegT.isDenormal());
+EXPECT_EQ(fcNegSubnormal, NegT.classify());
+  }
 }
 
 TEST(APFloatTest, IsSmallestNormalized) {
@@ -1350,6 +1370,16 @@
 {   0x80ULL, APFloat::Float8E4M3B11FNUZ(), false, true, 0xaaULL },
 {   0x80ULL, APFloat::Float8E4M3B11FNUZ(), true, false, 0xaaULL },
 {   0x80ULL, APFloat::Float8E4M3B11FNUZ(), true, true,  0xaaULL },
+{0x3fe00ULL, APFloat::FloatTF32(), false, false,  0xULL },
+{0x7fe00ULL, APFloat::FloatTF32(), false,  true,  0xULL },
+{0x3feaaULL, APFloat::FloatTF32(), false, false,0xaaULL },
+{0x3ffaaULL, APFloat::FloatTF32(), false, false,   0xdaaULL },
+{0x3ffaaULL, APFloat::FloatTF32(), false, false,  0xfdaaULL },
+{0x3fd00ULL, APFloat::FloatTF32(),  true, false,  0xULL },
+{0x7fd00ULL, APFloat::FloatTF32(),  true,  true,  0xULL },
+{0x3fcaaULL, APFloat::FloatTF32(),  true, false,0xaaULL },
+{0x3fdaaULL, APFloat::FloatTF32(),  true, false,   0xfaaULL },
+{0x3fdaaULL, APFloat::FloatTF32(),  true, false,   0x1aaULL },
   // clang-format on
   };
 
@@ -1780,6 +1810,8 @@
 APFloat::getLargest(APFloat::Float8E5M2FNUZ()).convertToDouble());
   EXPECT_EQ(
   30, APFloat::getLargest(APFloat::Float8E4M3B11FNUZ()).convertToDouble());
+  EXPECT_EQ(3.40116213421e+38f,
+APFloat::getLargest(APFloat::FloatTF32()).convertToFloat());
 }
 
 TEST(APFloatTest, getSmallest) {
@@ -1831,6 +1863,13 @@
   EXPECT_TRUE(test.isFiniteNonZero());
   EXPECT_TRUE(test.isDenormal());
   EXPECT_TRUE(test.bitwiseIsEqual(expected));
+
+  test = APFloat::getSmallest(APFloat::FloatTF32(), true);
+  expected = APFloat(APFloat::FloatTF32(), "-0x0.004p-126");
+  EXPECT_TRUE(test.isNegative());
+  EXPECT_TRUE(test.isFiniteNonZero());
+  EXPECT_TRUE(test.isDenormal());
+  EXPECT_TRUE(test.bitwiseIsEqual(expected));
 }
 
 TEST(APFloatTest, getSmallestNormalized) {
@@ -1905,6 +1944,14 @@
   EXPECT_FALSE(test.isDenormal());
   EXPECT_TRUE(test.bitwiseIsEqual(expected));
   EXPECT_TRUE(test.isSmallestNormalized());
+
+  test = APFloat::getSmallestNormalized(APFloat::FloatTF32(), false);
+  expected = APFloat(APFloat::FloatTF32(), "0x1p-126");
+  EXPECT_FALSE(test.isNegative());
+  EXPECT_TRUE(test.isFiniteNonZero());
+  EXPECT_FALSE(test.isDenormal());
+  EXPECT_TRUE(test.bitwiseIsEqual(expected));
+  EXPECT_TRUE(test.isSmallestNormalized());
 }
 
 TEST(APFloatTest, getZero) {
@@ -1936,7 +1983,9 @@
   {&APFloat::Float8E4M3FNUZ(), false, false, {0, 0}, 1},
   {&APFloat::Float8E4M3FNUZ(), true, false, {0, 0}, 1},
   {&APFloat::Float8E4M3B11FNUZ(), false, false, {0, 0}, 1},
-  {&APFloat::Float8E4M3B11FNUZ(), true, false, {0, 0}, 1}};
+  {&APFloat::Float8E4M3B11FNUZ(), true, false, {0, 0}, 1},
+  {&APFloat::FloatTF32(), false, true, {0, 0}, 1},
+  {&APFloat::FloatTF32(), true, true, {0x4ULL, 0}, 1}};
   const unsigned NumGetZeroTests = std::size(GetZeroTest);
   for (unsigned i = 0; i < NumGetZeroTests; ++i) {
 APFloat test = APFloat::getZero(*GetZeroTest[i].semantics,
@@ -6229,6 +6278,34 @@
   EXPECT_TRUE(std::isnan(QNaN.convertToDouble()));
 }
 
+TEST(APFloatTest, FloatTF32ToDouble) {
+  APFloat One(APFloat::FloatTF32(), "1.0");
+  EXPECT_EQ(

[clang] 55c2211 - [APFloat] Add APFloat semantic support for TF32

2023-06-23 Thread Mehdi Amini via cfe-commits

Author: Jeremy Furtek
Date: 2023-06-23T10:54:49+02:00
New Revision: 55c2211a233e11179048cf58778f40e5a62f444a

URL: 
https://github.com/llvm/llvm-project/commit/55c2211a233e11179048cf58778f40e5a62f444a
DIFF: 
https://github.com/llvm/llvm-project/commit/55c2211a233e11179048cf58778f40e5a62f444a.diff

LOG: [APFloat] Add APFloat semantic support for TF32

This diff adds APFloat support for a semantic that matches the TF32 data type
used by some accelerators (most notably GPUs from both NVIDIA and AMD).

For more information on the TF32 data type, see 
https://blogs.nvidia.com/blog/2020/05/14/tensorfloat-32-precision-format/.
Some intrinsics that support the TF32 data type were added in 
https://reviews.llvm.org/D122044.

For some discussion on supporting common semantics in `APFloat`, see similar
efforts for 8-bit formats at https://reviews.llvm.org/D146441, as well as
https://discourse.llvm.org/t/rfc-adding-the-amd-graphcore-maybe-others-float8-formats-to-apfloat/67969.

A subsequent diff will extend MLIR to use this data type. (Those changes are
not part of this diff to simplify the review process.)

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D151923

Added: 


Modified: 
clang/lib/AST/MicrosoftMangle.cpp
llvm/include/llvm/ADT/APFloat.h
llvm/lib/Support/APFloat.cpp
llvm/unittests/ADT/APFloatTest.cpp

Removed: 




diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 9fede7bbad323..430a57d7b4ec0 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -898,6 +898,7 @@ void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat 
Number) {
   case APFloat::S_Float8E5M2FNUZ:
   case APFloat::S_Float8E4M3FNUZ:
   case APFloat::S_Float8E4M3B11FNUZ:
+  case APFloat::S_FloatTF32:
 llvm_unreachable("Tried to mangle unexpected APFloat semantics");
   }
 

diff  --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index 1875706362f79..64caa5a765456 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -184,6 +184,10 @@ struct APFloatBase {
 // This format's exponent bias is 11, instead of the 7 (2 ** (4 - 1) - 1)
 // that IEEE precedent would imply.
 S_Float8E4M3B11FNUZ,
+// Floating point number that occupies 32 bits or less of storage, 
providing
+// improved range compared to half (16-bit) formats, at (potentially)
+// greater throughput than single precision (32-bit) formats.
+S_FloatTF32,
 
 S_x87DoubleExtended,
 S_MaxSemantics = S_x87DoubleExtended,
@@ -203,6 +207,7 @@ struct APFloatBase {
   static const fltSemantics &Float8E4M3FN() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FNUZ() LLVM_READNONE;
   static const fltSemantics &Float8E4M3B11FNUZ() LLVM_READNONE;
+  static const fltSemantics &FloatTF32() LLVM_READNONE;
   static const fltSemantics &x87DoubleExtended() LLVM_READNONE;
 
   /// A Pseudo fltsemantic used to construct APFloats that cannot conflict with
@@ -605,6 +610,7 @@ class IEEEFloat final : public APFloatBase {
   APInt convertFloat8E4M3FNAPFloatToAPInt() const;
   APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
   APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
+  APInt convertFloatTF32APFloatToAPInt() const;
   void initFromAPInt(const fltSemantics *Sem, const APInt &api);
   template  void initFromIEEEAPInt(const APInt &api);
   void initFromHalfAPInt(const APInt &api);
@@ -619,6 +625,7 @@ class IEEEFloat final : public APFloatBase {
   void initFromFloat8E4M3FNAPInt(const APInt &api);
   void initFromFloat8E4M3FNUZAPInt(const APInt &api);
   void initFromFloat8E4M3B11FNUZAPInt(const APInt &api);
+  void initFromFloatTF32APInt(const APInt &api);
 
   void assign(const IEEEFloat &);
   void copySignificand(const IEEEFloat &);

diff  --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index c882c08b256e7..4a73739b5282a 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -138,6 +138,7 @@ static constexpr fltSemantics semFloat8E4M3FNUZ = {
 7, -7, 4, 8, fltNonfiniteBehavior::NanOnly, fltNanEncoding::NegativeZero};
 static constexpr fltSemantics semFloat8E4M3B11FNUZ = {
 4, -10, 4, 8, fltNonfiniteBehavior::NanOnly, fltNanEncoding::NegativeZero};
+static constexpr fltSemantics semFloatTF32 = {127, -126, 11, 19};
 static constexpr fltSemantics semX87DoubleExtended = {16383, -16382, 64, 80};
 static constexpr fltSemantics semBogus = {0, 0, 0, 0};
 
@@ -203,6 +204,8 @@ const llvm::fltSemantics 
&APFloatBase::EnumToSemantics(Semantics S) {
 return Float8E4M3FNUZ();
   case S_Float8E4M3B11FNUZ:
 return Float8E4M3B11FNUZ();
+  case S_FloatTF32:
+return FloatTF32();
   case S_x87DoubleExtended:
 return x87DoubleExtended();
   }
@@ -233,6 +236,8 @@ APFloatBase::SemanticsToEnum(const llvm::fltSemantics &Sem) 
{
 return S_Float8E4

[PATCH] D135476: [clang-tidy] Support concepts in `bugprone-forwarding-reference-overload`

2023-06-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

May require rebase, but looks fine.
Release notes entry should be added.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135476/new/

https://reviews.llvm.org/D135476

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153617: [clangd] Fix an assertion failure in NamedDecl::getName during the prepareRename

2023-06-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

getName method required to be called on a simple-identifier NamedDecl,
otherwise it will trigger an assertion.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153617

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1106,6 +1106,15 @@
 using ns::^foo;
   )cpp",
"there are multiple symbols at the given location", !HeaderFile},
+
+  {R"cpp(
+void test() {
+  // no crash
+  using namespace std;
+  int [[V^ar]];
+}
+  )cpp",
+nullptr, !HeaderFile},
   };
 
   for (const auto& Case : Cases) {
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -318,7 +318,8 @@
   return nullptr;
 for (const auto &Child : DS->getDeclGroup())
   if (const auto *ND = dyn_cast(Child))
-if (ND != &RenamedDecl && ND->getName() == Name)
+if (ND != &RenamedDecl && ND->getDeclName().isIdentifier() &&
+ND->getName() == Name)
   return ND;
 return nullptr;
   };


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1106,6 +1106,15 @@
 using ns::^foo;
   )cpp",
"there are multiple symbols at the given location", !HeaderFile},
+
+  {R"cpp(
+void test() {
+  // no crash
+  using namespace std;
+  int [[V^ar]];
+}
+  )cpp",
+nullptr, !HeaderFile},
   };
 
   for (const auto& Case : Cases) {
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -318,7 +318,8 @@
   return nullptr;
 for (const auto &Child : DS->getDeclGroup())
   if (const auto *ND = dyn_cast(Child))
-if (ND != &RenamedDecl && ND->getName() == Name)
+if (ND != &RenamedDecl && ND->getDeclName().isIdentifier() &&
+ND->getName() == Name)
   return ND;
 return nullptr;
   };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153476: [dataflow] document & test determinism of formula structure

2023-06-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Analysis/FlowSensitive/Arena.cpp:13
 
+// Compute a canonical key for an unordered poir of operands, so that we
+// can intern (A & B) and (B & A) to the same formula.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153476/new/

https://reviews.llvm.org/D153476

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-06-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/Lexer/unicode.c:30
 
-int _;
+int a;
 

tbaeder wrote:
> Are these changes only for the case where we compile as c++? I know lots of C 
> (and c++?) projects use `_` as GNU gettext identifier to mark a translatable 
> string.
> Are these changes only for the case where we compile as c++
Yes

>  I know lots of C (and c++?) projects use _ as GNU gettext identifier to mark 
> a translatable string.

That's doesn't interfere with this feature. if `_` is defined as a macro, it's 
simply not possible to declare a variable of that name,  let alone more than 
one.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153536/new/

https://reviews.llvm.org/D153536

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153488: [dataflow] HTMLLogger: meaningful names for flow condition variables

2023-06-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.
This revision is now accepted and ready to land.

Should we have some documentation or tooltip explaining the users what the 
meaning of those names are?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153488/new/

https://reviews.llvm.org/D153488

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153584: [dataflow] Make SAT solver deterministic

2023-06-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Is there a measurable perf cost for this determinism?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153584/new/

https://reviews.llvm.org/D153584

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153430: [Clang][Driver] Warn on invalid Arm or AArch64 baremetal target triple

2023-06-23 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 533904.
michaelplatings added a comment.

Tweak warning message


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153430/new/

https://reviews.llvm.org/D153430

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/lib/Driver/Driver.cpp
  clang/test/CodeGen/aapcs64-align.cpp
  clang/test/CodeGen/aarch64-sign-return-address.c
  clang/test/CodeGen/arm_acle.c
  clang/test/CodeGenCXX/float16-declarations.cpp
  clang/test/Driver/aarch64-cssc.c
  clang/test/Driver/aarch64-d128.c
  clang/test/Driver/aarch64-hbc.c
  clang/test/Driver/aarch64-ite.c
  clang/test/Driver/aarch64-lrcpc3.c
  clang/test/Driver/aarch64-ls64.c
  clang/test/Driver/aarch64-lse128.c
  clang/test/Driver/aarch64-mops.c
  clang/test/Driver/aarch64-mte.c
  clang/test/Driver/aarch64-perfmon.c
  clang/test/Driver/aarch64-predres.c
  clang/test/Driver/aarch64-rand.c
  clang/test/Driver/aarch64-ras.c
  clang/test/Driver/aarch64-rdm.c
  clang/test/Driver/aarch64-ssbs.c
  clang/test/Driver/aarch64-the.c
  clang/test/Driver/arm-matrix-multiply.c
  clang/test/Driver/arm-sb.c
  clang/test/Driver/constructors.c
  clang/test/Driver/unsupported-target-arch.c
  clang/test/Frontend/gnu-mcount.c
  clang/test/Headers/arm-fp16-header.c
  clang/test/Headers/arm-neon-header.c
  clang/test/Preprocessor/aarch64-target-features.c
  llvm/test/CodeGen/AArch64/andcompare.ll
  llvm/test/CodeGen/AArch64/andorbrcompare.ll
  llvm/test/CodeGen/AArch64/blockaddress.ll
  llvm/test/CodeGen/AArch64/extern-weak.ll
  llvm/test/CodeGen/AArch64/init-array.ll
  llvm/test/CodeGen/AArch64/literal_pools_float.ll
  llvm/test/CodeGen/AArch64/neg-selects.ll
  llvm/test/CodeGen/AArch64/qmovn.ll
  llvm/test/CodeGen/AArch64/select-constant-xor.ll
  llvm/test/MC/AArch64/armv8.9a-clrbhb.s

Index: llvm/test/MC/AArch64/armv8.9a-clrbhb.s
===
--- llvm/test/MC/AArch64/armv8.9a-clrbhb.s
+++ llvm/test/MC/AArch64/armv8.9a-clrbhb.s
@@ -2,37 +2,37 @@
 // Assembly is always permitted for instructions in the hint space.
 
 // Optional, off by default
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v8a < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v8.8a < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v9a < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v9.3a < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v8a < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v8.8a < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v9a < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v9.3a < %s | FileCheck %s --check-prefix=HINT_22
 
 // Optional, off by default, doubly disabled
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v8a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v8.8a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v9a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v9.3a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v8a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v8.8a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v9a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v9.3a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
 
 // Optional, off by default, manually enabled
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+clrbhb < %s | FileCheck %s --check-prefix=CLRBHB
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v8a,+clrbhb < %s | FileCheck %s --check-prefix=CLRBHB
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v8.8a,+clrbhb < %s | FileCheck %s --check-prefix=CLRBHB
-// RUN: llvm-m

[PATCH] D152436: [clang][analyzer] Move checker alpha.unix.StdCLibraryFunctions out of alpha.

2023-06-23 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

For first experiment I have made patch D153612 
 that adds a `NoteTag` to "all" standard 
function calls.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152436/new/

https://reviews.llvm.org/D152436

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153476: [dataflow] document & test determinism of formula structure

2023-06-23 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/unittests/Analysis/FlowSensitive/ArenaTest.cpp:169
+  auto &BOr = A.makeOr(BY, BX);
+  auto &BEqual = A.makeEquals(BOr, BAnd);
+  EXPECT_EQ(Expected, llvm::to_string(B.getFormula(BEqual)));

Shouldn't these lines use "A.make...()"?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153476/new/

https://reviews.llvm.org/D153476

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153476: [dataflow] document & test determinism of formula structure

2023-06-23 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/unittests/Analysis/FlowSensitive/ArenaTest.cpp:165-169
+  auto &BX = A.create();
+  auto &BY = A.create();
+  auto &BAnd = A.makeAnd(BX, BY);
+  auto &BOr = A.makeOr(BY, BX);
+  auto &BEqual = A.makeEquals(BOr, BAnd);





Comment at: clang/unittests/Analysis/FlowSensitive/ArenaTest.cpp:169
+  auto &BOr = A.makeOr(BY, BX);
+  auto &BEqual = A.makeEquals(BOr, BAnd);
+  EXPECT_EQ(Expected, llvm::to_string(B.getFormula(BEqual)));

gribozavr2 wrote:
> Shouldn't these lines use "A.make...()"?
Sorry, I meant, shouldn't these lines use "B.make...()"?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153476/new/

https://reviews.llvm.org/D153476

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153612: [clang][analyzer] Add and change NoteTags in StdLibraryFunctionsChecker.

2023-06-23 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/test/Analysis/errno-stdlibraryfunctions-notes.c:17
   access("path", 0);
-  // expected-note@-1{{Assuming that function 'access' is successful, in this 
case the value 'errno' may be undefined after the call and should not be used}}
+  // expected-note@-1{{Assuming that the call fails}}
+  access("path", 0);

This is the type of note that looks not necessary and even confusing. It could 
be any case of failure or success, the failure is chosen. This does not matter 
for the end result but can be confusing for users (one may think that there is 
a connection to the found bug).



Comment at: clang/test/Analysis/std-c-library-functions-path-notes.c:72
+return 0;
+  int l = islower(c);
+  f = fileno(f1); // \

Here no note is shown. Probably because the summary of `islower` has cases 
without note, these notes should be added.



Comment at: clang/test/Analysis/stream-errno-note.c:24
 void check_tmpfile(void) {
   FILE *F = tmpfile();
+  // expected-note@-1{{'errno' may be undefined after successful call to 
'tmpfile'}}

At this place a note 'Assuming that the call is successful' should be 
displayed. But this is not working because `StreamChecker` is enabled. 
`StreamChecker` makes a state split before `StdCLibraryFunctionsChecker` for 
`tmpfile` failure and success, then in `StdCLibraryFunctionsChecker` the 
successor count is 1 and the note is not added. Probably the logic can be 
improved by finding the first node that belongs to the `CallEvent`. Or count 
how many cases are applied before adding the note tags.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153612/new/

https://reviews.llvm.org/D153612

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152436: [clang][analyzer] Move checker alpha.unix.StdCLibraryFunctions out of alpha.

2023-06-23 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

In D152436#4438956 , @NoQ wrote:

> Uh-oh, looks like I'm not paying nearly enough attention to this discussion 
> (sorry about that!!)
>
> I'm somewhat skeptical of the decision made in D151225 
>  because the entire reason I originally 
> implemented `StdCLibraryFunctions` was to deal with false positives I was 
> seeing. It was really valuable even without the bug-finding part. So I really 
> wish we could find some way to keep bug-finding and modeling separate.
>
> I haven't read the entire discussion though, I need to catch up 😓

The problem was that modeling and report generation could not be separated 
correctly. Both are implemented in one class but are differently named checkers 
that should run in a specific order because dependency issues, this was not 
good. Other problem was that if the modeling checker runs first, it will apply 
state changes for pre and post conditions without generating a bug report even 
if a bug could be found in the previous state. The old state is then lost and 
other checkers will not find that bug. For example a case of null pointer 
argument to a function is always removed by the modeling part of the checker, 
even if this was a case when a bug report should be generated.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152436/new/

https://reviews.llvm.org/D152436

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153430: [Clang][Driver] Warn on invalid Arm or AArch64 baremetal target triple

2023-06-23 Thread Peter Smith via Phabricator via cfe-commits
peter.smith accepted this revision.
peter.smith added a comment.
This revision is now accepted and ready to land.

Thanks for the update! LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153430/new/

https://reviews.llvm.org/D153430

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153430: [Clang][Driver] Warn on invalid Arm or AArch64 baremetal target triple

2023-06-23 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett accepted this revision.
DavidSpickett added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153430/new/

https://reviews.llvm.org/D153430

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 041ffc1 - [Clang][Driver] Warn on invalid Arm or AArch64 baremetal target triple

2023-06-23 Thread Michael Platings via cfe-commits

Author: Michael Platings
Date: 2023-06-23T11:54:29+01:00
New Revision: 041ffc155fd7d154af1ea59853fbe5932d0216d3

URL: 
https://github.com/llvm/llvm-project/commit/041ffc155fd7d154af1ea59853fbe5932d0216d3
DIFF: 
https://github.com/llvm/llvm-project/commit/041ffc155fd7d154af1ea59853fbe5932d0216d3.diff

LOG: [Clang][Driver] Warn on invalid Arm or AArch64 baremetal target triple

A common user mistake is specifying a target of aarch64-none-eabi or
arm-none-elf whereas the correct names are aarch64-none-elf &
arm-none-eabi. Currently if a target of aarch64-none-eabi is specified
then the Generic_ELF toolchain is used, unlike aarch64-none-elf which
will use the BareMetal toolchain. This is unlikely to be intended by the
user so issue a warning that the target is invalid.

The target parser is liberal in what input it accepts so invalid triples
may yield behaviour that's sufficiently close to what the user intended.
Therefore invalid triples were used in many tests. This change updates
those tests to use valid triples.
One test (gnu-mcount.c) relies on the Generic_ELF toolchain behaviour so
change it to explicitly specify aarch64-unknown-none-gnu as the target.

Reviewed By: peter.smith, DavidSpickett

Differential Revision: https://reviews.llvm.org/D153430

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/lib/Driver/Driver.cpp
clang/test/CodeGen/aapcs64-align.cpp
clang/test/CodeGen/aarch64-sign-return-address.c
clang/test/CodeGen/arm_acle.c
clang/test/CodeGenCXX/float16-declarations.cpp
clang/test/Driver/aarch64-cssc.c
clang/test/Driver/aarch64-d128.c
clang/test/Driver/aarch64-hbc.c
clang/test/Driver/aarch64-ite.c
clang/test/Driver/aarch64-lrcpc3.c
clang/test/Driver/aarch64-ls64.c
clang/test/Driver/aarch64-lse128.c
clang/test/Driver/aarch64-mops.c
clang/test/Driver/aarch64-mte.c
clang/test/Driver/aarch64-perfmon.c
clang/test/Driver/aarch64-predres.c
clang/test/Driver/aarch64-rand.c
clang/test/Driver/aarch64-ras.c
clang/test/Driver/aarch64-rdm.c
clang/test/Driver/aarch64-ssbs.c
clang/test/Driver/aarch64-the.c
clang/test/Driver/arm-matrix-multiply.c
clang/test/Driver/arm-sb.c
clang/test/Driver/constructors.c
clang/test/Driver/unsupported-target-arch.c
clang/test/Frontend/gnu-mcount.c
clang/test/Headers/arm-fp16-header.c
clang/test/Headers/arm-neon-header.c
clang/test/Preprocessor/aarch64-target-features.c
llvm/test/CodeGen/AArch64/andcompare.ll
llvm/test/CodeGen/AArch64/andorbrcompare.ll
llvm/test/CodeGen/AArch64/blockaddress.ll
llvm/test/CodeGen/AArch64/extern-weak.ll
llvm/test/CodeGen/AArch64/init-array.ll
llvm/test/CodeGen/AArch64/literal_pools_float.ll
llvm/test/CodeGen/AArch64/neg-selects.ll
llvm/test/CodeGen/AArch64/qmovn.ll
llvm/test/CodeGen/AArch64/select-constant-xor.ll
llvm/test/MC/AArch64/armv8.9a-clrbhb.s

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index eb1649cc238a5..3ccdaada1ee27 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -341,6 +341,9 @@ def err_opt_not_valid_on_target : Error<
   "option '%0' cannot be specified on this target">;
 def err_invalid_feature_combination : Error<
   "invalid feature combination: %0">;
+def warn_target_unrecognized_env : Warning<
+  "mismatch between architecture and environment in target triple '%0'; did 
you mean '%1'?">,
+  InGroup;
 
 // Source manager
 def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal;

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 4c282241d2b25..696db21d97c51 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1437,6 +1437,36 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 << TC.getTriple().str();
   }
 
+  // A common user mistake is specifying a target of aarch64-none-eabi or
+  // arm-none-elf whereas the correct names are aarch64-none-elf &
+  // arm-none-eabi. Detect these cases and issue a warning.
+  if (TC.getTriple().getOS() == llvm::Triple::UnknownOS &&
+  TC.getTriple().getVendor() == llvm::Triple::UnknownVendor) {
+switch (TC.getTriple().getArch()) {
+case llvm::Triple::arm:
+case llvm::Triple::armeb:
+case llvm::Triple::thumb:
+case llvm::Triple::thumbeb:
+  if (TC.getTriple().getEnvironmentName() == "elf") {
+Diag(diag::warn_target_unrecognized_env)
+<< TargetTriple
+<< (TC.getTriple().getArchName().str() + "-none-eabi");
+  }
+  break;
+case llvm::Triple::aarch64:
+case llvm::Triple::aarch64_be:
+case llvm::Triple::aarch64_32:
+  if (TC.getTriple().getEnvironmentName().startswith("eabi")) {
+Diag(

[PATCH] D153430: [Clang][Driver] Warn on invalid Arm or AArch64 baremetal target triple

2023-06-23 Thread Michael Platings via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG041ffc155fd7: [Clang][Driver] Warn on invalid Arm or AArch64 
baremetal target triple (authored by michaelplatings).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153430/new/

https://reviews.llvm.org/D153430

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/lib/Driver/Driver.cpp
  clang/test/CodeGen/aapcs64-align.cpp
  clang/test/CodeGen/aarch64-sign-return-address.c
  clang/test/CodeGen/arm_acle.c
  clang/test/CodeGenCXX/float16-declarations.cpp
  clang/test/Driver/aarch64-cssc.c
  clang/test/Driver/aarch64-d128.c
  clang/test/Driver/aarch64-hbc.c
  clang/test/Driver/aarch64-ite.c
  clang/test/Driver/aarch64-lrcpc3.c
  clang/test/Driver/aarch64-ls64.c
  clang/test/Driver/aarch64-lse128.c
  clang/test/Driver/aarch64-mops.c
  clang/test/Driver/aarch64-mte.c
  clang/test/Driver/aarch64-perfmon.c
  clang/test/Driver/aarch64-predres.c
  clang/test/Driver/aarch64-rand.c
  clang/test/Driver/aarch64-ras.c
  clang/test/Driver/aarch64-rdm.c
  clang/test/Driver/aarch64-ssbs.c
  clang/test/Driver/aarch64-the.c
  clang/test/Driver/arm-matrix-multiply.c
  clang/test/Driver/arm-sb.c
  clang/test/Driver/constructors.c
  clang/test/Driver/unsupported-target-arch.c
  clang/test/Frontend/gnu-mcount.c
  clang/test/Headers/arm-fp16-header.c
  clang/test/Headers/arm-neon-header.c
  clang/test/Preprocessor/aarch64-target-features.c
  llvm/test/CodeGen/AArch64/andcompare.ll
  llvm/test/CodeGen/AArch64/andorbrcompare.ll
  llvm/test/CodeGen/AArch64/blockaddress.ll
  llvm/test/CodeGen/AArch64/extern-weak.ll
  llvm/test/CodeGen/AArch64/init-array.ll
  llvm/test/CodeGen/AArch64/literal_pools_float.ll
  llvm/test/CodeGen/AArch64/neg-selects.ll
  llvm/test/CodeGen/AArch64/qmovn.ll
  llvm/test/CodeGen/AArch64/select-constant-xor.ll
  llvm/test/MC/AArch64/armv8.9a-clrbhb.s

Index: llvm/test/MC/AArch64/armv8.9a-clrbhb.s
===
--- llvm/test/MC/AArch64/armv8.9a-clrbhb.s
+++ llvm/test/MC/AArch64/armv8.9a-clrbhb.s
@@ -2,37 +2,37 @@
 // Assembly is always permitted for instructions in the hint space.
 
 // Optional, off by default
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v8a < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v8.8a < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v9a < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v9.3a < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v8a < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v8.8a < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v9a < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v9.3a < %s | FileCheck %s --check-prefix=HINT_22
 
 // Optional, off by default, doubly disabled
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v8a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v8.8a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v9a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v9.3a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v8a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v8.8a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v9a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
+// RUN: llvm-mc -show-encoding -triple aarch64-none-elf -mattr=+v9.3a,-clrbhb < %s | FileCheck %s --check-prefix=HINT_22
 
 // Optional, off by default, manually enabled
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+clrbhb < %s | FileCheck %s --check-prefix=CLRBHB
-// RUN: llvm-mc -show-encoding -triple aarch64-none-none-eabi -mattr=+v8a,+clrbhb < %s | FileCheck %s --check-prefix=CLRBHB
-// RUN: llvm-mc -show-encoding -triple aar

[clang] 63342ae - Fix a failing assertion with implicit function definitions

2023-06-23 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-06-23T07:02:21-04:00
New Revision: 63342ae4b8f7573fd03fdb6eb38d55097b9a6922

URL: 
https://github.com/llvm/llvm-project/commit/63342ae4b8f7573fd03fdb6eb38d55097b9a6922
DIFF: 
https://github.com/llvm/llvm-project/commit/63342ae4b8f7573fd03fdb6eb38d55097b9a6922.diff

LOG: Fix a failing assertion with implicit function definitions

When implicitly defining a function in C, we would try to find an
appropriate declaration context for the function to be declared within.
However, we did not account for GNU statement expressions, which
masquerade as a compound statement and can be used in other contexts
such as within structure member declarations.

Fixes https://github.com/llvm/llvm-project/issues/48579

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/implicit-decl.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7c6a350c7eab2..52669132be889 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -524,6 +524,10 @@ Bug Fixes in This Version
   type by the default argument promotions, and thus this is UB. Clang's
   behavior now matches GCC's behavior in C++.
   (`#38717 _`).
+- Fixed a failing assertion when implicitly defining a function within a GNU
+  statement expression that appears outside of a function block scope. The
+  assertion was benign outside of asserts builds and would only fire in C.
+  (`#48579 _`).
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 27cb9695e9424..9fe1cb20a76f6 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16000,8 +16000,14 @@ NamedDecl 
*Sema::ImplicitlyDefineFunction(SourceLocation Loc,
   while (!BlockScope->isCompoundStmtScope() && BlockScope->getParent())
 BlockScope = BlockScope->getParent();
 
+  // Loop until we find a DeclContext that is either a function/method or the
+  // translation unit, which are the only two valid places to implicitly define
+  // a function. This avoids accidentally defining the function within a tag
+  // declaration, for example.
   Scope *ContextScope = BlockScope;
-  while (!ContextScope->getEntity())
+  while (!ContextScope->getEntity() ||
+ (!ContextScope->getEntity()->isFunctionOrMethod() &&
+  !ContextScope->getEntity()->isTranslationUnit()))
 ContextScope = ContextScope->getParent();
   ContextRAII SavedContext(*this, ContextScope->getEntity());
 

diff  --git a/clang/test/Sema/implicit-decl.c b/clang/test/Sema/implicit-decl.c
index 351f70ea33665..d7d3e108e8048 100644
--- a/clang/test/Sema/implicit-decl.c
+++ b/clang/test/Sema/implicit-decl.c
@@ -1,18 +1,16 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only 
-Werror=implicit-function-declaration -std=c99
-// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11
-// RUN: %clang_cc1 %s -verify=c2x -fsyntax-only -std=c2x
+// RUN: %clang_cc1 %s -verify=expected,both -fsyntax-only 
-Werror=implicit-function-declaration -std=c99
+// RUN: %clang_cc1 %s -verify=expected,both -fsyntax-only -std=c11
+// RUN: %clang_cc1 %s -verify=c2x,both -fsyntax-only -std=c2x
 
 /// -Werror-implicit-function-declaration is a deprecated alias used by many 
projects.
-// RUN: %clang_cc1 %s -verify -fsyntax-only 
-Werror-implicit-function-declaration
+// RUN: %clang_cc1 %s -verify=expected,both -fsyntax-only 
-Werror-implicit-function-declaration
 
 // c2x-note@*:* {{'__builtin_va_list' declared here}}
 
 typedef int int32_t;
 typedef unsigned char Boolean;
 
-extern int printf(__const char *__restrict __format, ...); // 
expected-note{{'printf' declared here}} \
-  c2x-note 
{{'printf' declared here}}
-
+extern int printf(__const char *__restrict __format, ...); // 
both-note{{'printf' declared here}}
 void func(void) {
int32_t *vector[16];
const char compDesc[16 + 1];
@@ -53,3 +51,26 @@ void test_suggestion(void) {
   bork(); // expected-error {{call to undeclared function 'bork'; ISO C99 and 
later do not support implicit function declarations}} \
  c2x-error {{use of undeclared identifier 'bork'}}
 }
+
+// The following used to cause an assertion from trying to define the implicit
+// function within a structure scope as opposed to within function or global
+// scoped.
+int GH48579_1(void) {
+  struct {
+int x __attribute__((aligned(({ a(); }; // expected-error {{call to 
undeclared function 'a'; ISO C99 and later do not support implicit function 
declarations}} \
+   c2x-error {{use of 
undeclared identifier 'a'}} \
+   both-error {{'aligned' 
at

[PATCH] D153621: [Clang] Correctly handle $, @, and ` when represented as UCN

2023-06-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This covers

- P2558R2 (C++, wg21.link/P2558 )
- N2701 (C, https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2701.htm)
- N3124 (C, https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3124.pdf)

This patch

- Disallow representing $ as a UCN in all language mode, which did not properly 
work (see GH62133), and which in made ill-formed in C++ and C by P2558 
 and N3124 respectively
- Allow a UCN for any character in C2X, in string and character literals

Fixes #62133


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153621

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/Lexer/char-literal.cpp
  clang/test/Lexer/utf8-char-literal.cpp
  clang/test/Preprocessor/ucn-allowed-chars.c
  clang/test/Preprocessor/ucn-pp-identifier.c

Index: clang/test/Preprocessor/ucn-pp-identifier.c
===
--- clang/test/Preprocessor/ucn-pp-identifier.c
+++ clang/test/Preprocessor/ucn-pp-identifier.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify=expected,ext -Wundef -DTRIGRAPHS=1
+// RUN: %clang_cc1 %s -fsyntax-only -std=c2x -pedantic -verify=expected,ext -Wundef -DTRIGRAPHS=1
 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -fno-trigraphs
 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -std=c++23 -pedantic -ftrigraphs -DTRIGRAPHS=1 -verify=expected,cxx23 -Wundef -Wpre-c++23-compat
 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -ftrigraphs -DTRIGRAPHS=1
@@ -40,7 +41,8 @@
// ext-warning {{extension}} cxx23-warning {{before C++23}}
 #define \N{WASTEBASKET} // expected-error {{macro name must be an identifier}} \
 // ext-warning {{extension}} cxx23-warning {{before C++23}}
-#define a\u0024
+#define a\u0024a  // expected-error {{character '$' cannot be specified by a universal character name}} \
+  // expected-warning {{requires whitespace after the macro name}}
 
 #if \u0110 // expected-warning {{is not defined, evaluates to 0}}
 #endif
@@ -112,7 +114,7 @@
 #define capital_u_\U00FC
 // expected-warning@-1 {{incomplete universal character name}} expected-note@-1 {{did you mean to use '\u'?}} expected-warning@-1 {{whitespace}}
 // CHECK: note: did you mean to use '\u'?
-// CHECK-NEXT: {{^  112 | #define capital_u_\U00FC}}
+// CHECK-NEXT: {{^  114 | #define capital_u_\U00FC}}
 // CHECK-NEXT: {{^  |\^}}
 // CHECK-NEXT: {{^  |u}}
 
@@ -155,5 +157,5 @@
 int a\N{LATIN CAPITAL LETTER A WITH GRAVE??>;
 // expected-warning@-1 {{trigraph ignored}}\
 // expected-warning@-1 {{incomplete}}\
-// expected-error@-1 {{expected ';' after top level declarator}}
+// expected-error@-1 {{expected}}
 #endif
Index: clang/test/Preprocessor/ucn-allowed-chars.c
===
--- clang/test/Preprocessor/ucn-allowed-chars.c
+++ clang/test/Preprocessor/ucn-allowed-chars.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -std=c99 -verify
+// RUN: %clang_cc1 %s -fsyntax-only -std=c2x -Wc99-compat -verify
 // RUN: %clang_cc1 %s -fsyntax-only -std=c11 -Wc99-compat -verify
 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -std=c++03 -Wc++11-compat -verify
 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -std=c++11 -Wc++98-compat -verify
@@ -13,7 +14,6 @@
 
 
 
-
 // Identifier initial characters
 extern char \u0E50; // C++03, C11, C++11
 extern char \u0300; // disallowed in C99/C++03
@@ -38,8 +38,8 @@
 
 
 #if __cplusplus
-// expected-error@9 {{character  not allowed in an identifier}}
-// expected-error@11 {{character  not allowed in an identifier}}
+// expected-error@10 {{character  not allowed in an identifier}}
+// expected-error@12 {{character  not allowed in an identifier}}
 // expected-error@18 {{expected unqualified-id}}
 # if __cplusplus >= 201103L
 // C++11
@@ -53,23 +53,49 @@
 
 # endif
 #else
-# if __STDC_VERSION__ >= 201112L
+# if __STDC_VERSION__ >= 201800L
+// C2X
+// expected-warning@8 {{using this character in an identifier is incompatible with C99}}
+// expected-error@10 {{character  not allowed in an identifier}}
+// expected-error@12 {{character  not allowed in an identifier}}
+// expected-error@18 {{expected identifier}}
+// expected-error@19 {{expected identifier}}
+// expected-error@33 {{invalid universal character}}
+# elif __STDC_VERSION__ >= 201112L
 // C11
-// expected-warning@7 {{using this character in an identifier is incompatible with C99}}
-// expected-warning@9 {{using this character in an identifier is incompatible with C99}}
-// expected-error@11 {{character  not allowed in an identifier}}
+// 

[PATCH] D153576: [Headers] Fix up some conditionals

2023-06-23 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

In D153576#4442096 , @craig.topper 
wrote:

> The mulx function being 32-bit mode only is also true in gcc. It probably 
> won't generate a mulx instruction on x86-64. Maybe that's why it was 32-bit 
> only? But it should still be functionally correct.

It's not functionally correct. Candidate fix D153620 
.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153576/new/

https://reviews.llvm.org/D153576

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147034: [clangd] Replace the hacky include-cleaner macro-reference implementation.

2023-06-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:360
+for (const auto &Ref : Refs) {
+  SourceLocation Loc = SM.getLocForStartOfFile(SM.getMainFileID())
+   .getLocWithOffset(Ref.StartOffset);

nit: `auto Loc = SM.getComposedLoc(MainFile, Offset)`



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:369
+
+  if (auto DefLoc = Macro->NameLoc; DefLoc.isValid())
+Macros.push_back(

nit: do early exit here as well


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147034/new/

https://reviews.llvm.org/D147034

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152900: [clangd] Update symbol collector to use include-cleaner.

2023-06-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:846
+void SymbolCollector::setSymbolProviders(
+const Symbol &S, const llvm::SmallVector Headers) 
{
+  if (Opts.CollectIncludePath &&

kadircet wrote:
> what about merging this one and `setIncludeLocation` ?
> 
> e.g:
> ```
> void SymbolCollector::setIncludeLocation(const Symbol &IdxS, SourceLocation 
> DefLoc, const include_cleaner::Symbol &Sym) {
> if (!Opts.CollectIncludePath ||
>   shouldCollectIncludePath(S.SymInfo.Kind) == Symbol::Invalid)
>   return;
> IncludeFiles[SID] = ...;
> SymbolProviders[SID] = headersForSymbol(...);
> }
> ```
also sorry for missing this so far, but i think we should limit this to first 
provider initially. as otherwise we'll have providers that just accidentally 
declare certain symbols and we don't want them to be inserted (unless they're 
the only provider and end up at the top) just because our ranking heuristics 
fail or something.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152900/new/

https://reviews.llvm.org/D152900

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153582: [SystemZ][z/OS] Add required options/macro/etc for z/os compilation step

2023-06-23 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan added a comment.

The CI shows the following lit tests are failing due to this patch which should 
be resolved first

Failed Tests (7):

  Clang :: CodeGen/SystemZ/zos-alignment.c
  Clang :: CodeGen/target-data.c
  Clang :: CodeGen/wchar-size.c
  Clang :: Driver/zos-comp-cxx.cpp
  Clang :: Driver/zos-driver-defaults.c
  Clang :: Driver/zos-dwarfversion.c
  Clang :: Preprocessor/init-s390x.c


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153582/new/

https://reviews.llvm.org/D153582

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147034: [clangd] Replace the hacky include-cleaner macro-reference implementation.

2023-06-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 533926.
hokein marked 2 inline comments as done.
hokein added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147034/new/

https://reviews.llvm.org/D147034

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -186,6 +186,10 @@
 #define DEF(X) const Foo *X;
 #define BAZ(X) const X x
 
+// No missing include insertion for ambiguous macro refs.
+#if defined(FOO)
+#endif
+
   void foo() {
 $b[[b]]();
 
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -353,20 +353,29 @@
 std::vector
 collectMacroReferences(ParsedAST &AST) {
   const auto &SM = AST.getSourceManager();
-  //  FIXME: !!this is a hacky way to collect macro references.
-  std::vector Macros;
   auto &PP = AST.getPreprocessor();
-  for (const syntax::Token &Tok :
-   AST.getTokens().spelledTokens(SM.getMainFileID())) {
-auto Macro = locateMacroAt(Tok, PP);
-if (!Macro)
-  continue;
-if (auto DefLoc = Macro->Info->getDefinitionLoc(); DefLoc.isValid())
+  std::vector Macros;
+  for (const auto &[_, Refs] : AST.getMacros().MacroRefs) {
+for (const auto &Ref : Refs) {
+  auto Loc = SM.getComposedLoc(SM.getMainFileID(), Ref.StartOffset);
+  const auto *Tok = AST.getTokens().spelledTokenAt(Loc);
+  if (!Tok)
+continue;
+  auto Macro = locateMacroAt(*Tok, PP);
+  if (!Macro)
+continue;
+  auto DefLoc = Macro->NameLoc;
+  if (!DefLoc.isValid())
+continue;
   Macros.push_back(
-  {include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)),
+  {include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok->text(SM)),
   DefLoc},
-   Tok.location(), include_cleaner::RefType::Explicit});
+   Tok->location(),
+   Ref.InConditionalDirective ? include_cleaner::RefType::Ambiguous
+  : include_cleaner::RefType::Explicit});
+}
   }
+
   return Macros;
 }
 


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -186,6 +186,10 @@
 #define DEF(X) const Foo *X;
 #define BAZ(X) const X x
 
+// No missing include insertion for ambiguous macro refs.
+#if defined(FOO)
+#endif
+
   void foo() {
 $b[[b]]();
 
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -353,20 +353,29 @@
 std::vector
 collectMacroReferences(ParsedAST &AST) {
   const auto &SM = AST.getSourceManager();
-  //  FIXME: !!this is a hacky way to collect macro references.
-  std::vector Macros;
   auto &PP = AST.getPreprocessor();
-  for (const syntax::Token &Tok :
-   AST.getTokens().spelledTokens(SM.getMainFileID())) {
-auto Macro = locateMacroAt(Tok, PP);
-if (!Macro)
-  continue;
-if (auto DefLoc = Macro->Info->getDefinitionLoc(); DefLoc.isValid())
+  std::vector Macros;
+  for (const auto &[_, Refs] : AST.getMacros().MacroRefs) {
+for (const auto &Ref : Refs) {
+  auto Loc = SM.getComposedLoc(SM.getMainFileID(), Ref.StartOffset);
+  const auto *Tok = AST.getTokens().spelledTokenAt(Loc);
+  if (!Tok)
+continue;
+  auto Macro = locateMacroAt(*Tok, PP);
+  if (!Macro)
+continue;
+  auto DefLoc = Macro->NameLoc;
+  if (!DefLoc.isValid())
+continue;
   Macros.push_back(
-  {include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)),
+  {include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok->text(SM)),
   DefLoc},
-   Tok.location(), include_cleaner::RefType::Explicit});
+   Tok->location(),
+   Ref.InConditionalDirective ? include_cleaner::RefType::Ambiguous
+  : include_cleaner::RefType::Explicit});
+}
   }
+
   return Macros;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 6585dd3 - [clangd] Replace the hacky include-cleaner macro-reference implementation.

2023-06-23 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-23T14:08:55+02:00
New Revision: 6585dd3b83738789dff5ca82008efdf84c9b922c

URL: 
https://github.com/llvm/llvm-project/commit/6585dd3b83738789dff5ca82008efdf84c9b922c
DIFF: 
https://github.com/llvm/llvm-project/commit/6585dd3b83738789dff5ca82008efdf84c9b922c.diff

LOG: [clangd] Replace the hacky include-cleaner macro-reference implementation.

Now MainFileMacros preserves enough information, we perform a just-in-time
convertion to interop with include-cleaner::Macro for include-cleaer features.

Differential Revision: https://reviews.llvm.org/D147034

Added: 


Modified: 
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index e04e28bd30f18..dd8b5afc2a24f 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -353,20 +353,29 @@ getUnused(ParsedAST &AST,
 std::vector
 collectMacroReferences(ParsedAST &AST) {
   const auto &SM = AST.getSourceManager();
-  //  FIXME: !!this is a hacky way to collect macro references.
-  std::vector Macros;
   auto &PP = AST.getPreprocessor();
-  for (const syntax::Token &Tok :
-   AST.getTokens().spelledTokens(SM.getMainFileID())) {
-auto Macro = locateMacroAt(Tok, PP);
-if (!Macro)
-  continue;
-if (auto DefLoc = Macro->Info->getDefinitionLoc(); DefLoc.isValid())
+  std::vector Macros;
+  for (const auto &[_, Refs] : AST.getMacros().MacroRefs) {
+for (const auto &Ref : Refs) {
+  auto Loc = SM.getComposedLoc(SM.getMainFileID(), Ref.StartOffset);
+  const auto *Tok = AST.getTokens().spelledTokenAt(Loc);
+  if (!Tok)
+continue;
+  auto Macro = locateMacroAt(*Tok, PP);
+  if (!Macro)
+continue;
+  auto DefLoc = Macro->NameLoc;
+  if (!DefLoc.isValid())
+continue;
   Macros.push_back(
-  {include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)),
+  {include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok->text(SM)),
   DefLoc},
-   Tok.location(), include_cleaner::RefType::Explicit});
+   Tok->location(),
+   Ref.InConditionalDirective ? include_cleaner::RefType::Ambiguous
+  : include_cleaner::RefType::Explicit});
+}
   }
+
   return Macros;
 }
 

diff  --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp 
b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
index 33e3960689505..6397f32c525f1 100644
--- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -186,6 +186,10 @@ TEST(IncludeCleaner, GenerateMissingHeaderDiags) {
 #define DEF(X) const Foo *X;
 #define BAZ(X) const X x
 
+// No missing include insertion for ambiguous macro refs.
+#if defined(FOO)
+#endif
+
   void foo() {
 $b[[b]]();
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147034: [clangd] Replace the hacky include-cleaner macro-reference implementation.

2023-06-23 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6585dd3b8373: [clangd] Replace the hacky include-cleaner 
macro-reference implementation. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147034/new/

https://reviews.llvm.org/D147034

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -186,6 +186,10 @@
 #define DEF(X) const Foo *X;
 #define BAZ(X) const X x
 
+// No missing include insertion for ambiguous macro refs.
+#if defined(FOO)
+#endif
+
   void foo() {
 $b[[b]]();
 
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -353,20 +353,29 @@
 std::vector
 collectMacroReferences(ParsedAST &AST) {
   const auto &SM = AST.getSourceManager();
-  //  FIXME: !!this is a hacky way to collect macro references.
-  std::vector Macros;
   auto &PP = AST.getPreprocessor();
-  for (const syntax::Token &Tok :
-   AST.getTokens().spelledTokens(SM.getMainFileID())) {
-auto Macro = locateMacroAt(Tok, PP);
-if (!Macro)
-  continue;
-if (auto DefLoc = Macro->Info->getDefinitionLoc(); DefLoc.isValid())
+  std::vector Macros;
+  for (const auto &[_, Refs] : AST.getMacros().MacroRefs) {
+for (const auto &Ref : Refs) {
+  auto Loc = SM.getComposedLoc(SM.getMainFileID(), Ref.StartOffset);
+  const auto *Tok = AST.getTokens().spelledTokenAt(Loc);
+  if (!Tok)
+continue;
+  auto Macro = locateMacroAt(*Tok, PP);
+  if (!Macro)
+continue;
+  auto DefLoc = Macro->NameLoc;
+  if (!DefLoc.isValid())
+continue;
   Macros.push_back(
-  {include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)),
+  {include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok->text(SM)),
   DefLoc},
-   Tok.location(), include_cleaner::RefType::Explicit});
+   Tok->location(),
+   Ref.InConditionalDirective ? include_cleaner::RefType::Ambiguous
+  : include_cleaner::RefType::Explicit});
+}
   }
+
   return Macros;
 }
 


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -186,6 +186,10 @@
 #define DEF(X) const Foo *X;
 #define BAZ(X) const X x
 
+// No missing include insertion for ambiguous macro refs.
+#if defined(FOO)
+#endif
+
   void foo() {
 $b[[b]]();
 
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -353,20 +353,29 @@
 std::vector
 collectMacroReferences(ParsedAST &AST) {
   const auto &SM = AST.getSourceManager();
-  //  FIXME: !!this is a hacky way to collect macro references.
-  std::vector Macros;
   auto &PP = AST.getPreprocessor();
-  for (const syntax::Token &Tok :
-   AST.getTokens().spelledTokens(SM.getMainFileID())) {
-auto Macro = locateMacroAt(Tok, PP);
-if (!Macro)
-  continue;
-if (auto DefLoc = Macro->Info->getDefinitionLoc(); DefLoc.isValid())
+  std::vector Macros;
+  for (const auto &[_, Refs] : AST.getMacros().MacroRefs) {
+for (const auto &Ref : Refs) {
+  auto Loc = SM.getComposedLoc(SM.getMainFileID(), Ref.StartOffset);
+  const auto *Tok = AST.getTokens().spelledTokenAt(Loc);
+  if (!Tok)
+continue;
+  auto Macro = locateMacroAt(*Tok, PP);
+  if (!Macro)
+continue;
+  auto DefLoc = Macro->NameLoc;
+  if (!DefLoc.isValid())
+continue;
   Macros.push_back(
-  {include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)),
+  {include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok->text(SM)),
   DefLoc},
-   Tok.location(), include_cleaner::RefType::Explicit});
+   Tok->location(),
+   Ref.InConditionalDirective ? include_cleaner::RefType::Ambiguous
+  : include_cleaner::RefType::Explicit});
+}
   }
+
   return Macros;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153294: [clang] Do not create ExprWithCleanups while checking immediate invocation

2023-06-23 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

While we wait for Richard's response... @Fznamznon what are your thoughts on 
wrapping all `ConstantExpr` that span immediate invocations with redundant 
`ExprWithCleanups` per Richard's suggestions?
I would be comfortable LGTMing such a change even if we choose to remove some 
of this redundancy later in a follow-ups.

This bug looks scary enough to me to warrant a fix asap.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153294/new/

https://reviews.llvm.org/D153294

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153294: [clang] Do not create ExprWithCleanups while checking immediate invocation

2023-06-23 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

> While we wait for Richard's response... @Fznamznon what are your thoughts on 
> wrapping all ConstantExpr that span immediate invocations with redundant 
> ExprWithCleanups per Richard's suggestions?
> This bug looks scary enough to me to warrant a fix asap.

Agree. I was thinking of implementing Richard's suggestions in a separate 
review for some time. I'll do that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153294/new/

https://reviews.llvm.org/D153294

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 82e29c6 - Fixed failed assertion w/attribute on anon unions

2023-06-23 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-06-23T08:58:37-04:00
New Revision: 82e29c65e3112fd5d7ed71250bf53ffaec87c2be

URL: 
https://github.com/llvm/llvm-project/commit/82e29c65e3112fd5d7ed71250bf53ffaec87c2be
DIFF: 
https://github.com/llvm/llvm-project/commit/82e29c65e3112fd5d7ed71250bf53ffaec87c2be.diff

LOG: Fixed failed assertion w/attribute on anon unions

This amends 304d1304b7bac190b6c9733eb07be284bfc17030 to process the
declaration attributes rather than assert on them; nothing prevents an
attribute from being written on an anonymous union.

Fixes https://github.com/llvm/llvm-project/issues/48512

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/anonymous-union.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52669132be889..117449f4e2fad 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -528,6 +528,9 @@ Bug Fixes in This Version
   statement expression that appears outside of a function block scope. The
   assertion was benign outside of asserts builds and would only fire in C.
   (`#48579 _`).
+- Fixed a failing assertion when applying an attribute to an anonymous union.
+  The assertion was benign outside of asserts builds and would only fire in 
C++.
+  (`#48512 _`).
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9fe1cb20a76f6..f33542e05b983 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5716,10 +5716,10 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, 
DeclSpec &DS,
   SC = SC_None;
 }
 
-assert(DS.getAttributes().empty() && "No attribute expected");
 Anon = VarDecl::Create(Context, Owner, DS.getBeginLoc(),
Record->getLocation(), /*IdentifierInfo=*/nullptr,
Context.getTypeDeclType(Record), TInfo, SC);
+ProcessDeclAttributes(S, Anon, Dc);
 
 // Default-initialize the implicit variable. This initialization will be
 // trivial in almost all cases, except if a union member has an in-class

diff  --git a/clang/test/SemaCXX/anonymous-union.cpp 
b/clang/test/SemaCXX/anonymous-union.cpp
index 27dd2f0083b8a..0f1a972d0aa05 100644
--- a/clang/test/SemaCXX/anonymous-union.cpp
+++ b/clang/test/SemaCXX/anonymous-union.cpp
@@ -215,3 +215,8 @@ namespace PR16630 {
 b.y = 0; // expected-error {{'y' is a private member of 'PR16630::A'}}
   }
 }
+
+namespace GH48512 {
+  // This would previously cause an assertion in C++ mode.
+  static __attribute__((a)) union { int a; }; // expected-warning {{unknown 
attribute 'a' ignored}}
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d7feba7 - HIP: Directly call trunc builtins

2023-06-23 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2023-06-23T09:11:06-04:00
New Revision: d7feba74b649cb8aabc0cb09b9bef5d79659e31c

URL: 
https://github.com/llvm/llvm-project/commit/d7feba74b649cb8aabc0cb09b9bef5d79659e31c
DIFF: 
https://github.com/llvm/llvm-project/commit/d7feba74b649cb8aabc0cb09b9bef5d79659e31c.diff

LOG: HIP: Directly call trunc builtins

Added: 


Modified: 
clang/lib/Headers/__clang_hip_math.h
clang/test/Headers/__clang_hip_math.hip

Removed: 




diff  --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index 850dbbef0f4e3..7e95b66232122 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -522,7 +522,7 @@ __DEVICE__
 float tgammaf(float __x) { return __ocml_tgamma_f32(__x); }
 
 __DEVICE__
-float truncf(float __x) { return __ocml_trunc_f32(__x); }
+float truncf(float __x) { return __builtin_truncf(__x); }
 
 __DEVICE__
 float y0f(float __x) { return __ocml_y0_f32(__x); }
@@ -1078,7 +1078,7 @@ __DEVICE__
 double tgamma(double __x) { return __ocml_tgamma_f64(__x); }
 
 __DEVICE__
-double trunc(double __x) { return __ocml_trunc_f64(__x); }
+double trunc(double __x) { return __builtin_trunc(__x); }
 
 __DEVICE__
 double y0(double __x) { return __ocml_y0_f64(__x); }

diff  --git a/clang/test/Headers/__clang_hip_math.hip 
b/clang/test/Headers/__clang_hip_math.hip
index 80501d1d43e46..984adf6da4ba2 100644
--- a/clang/test/Headers/__clang_hip_math.hip
+++ b/clang/test/Headers/__clang_hip_math.hip
@@ -3073,13 +3073,13 @@ extern "C" __device__ double test_tgamma(double x) {
 
 // DEFAULT-LABEL: @test_truncf(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[CALL_I:%.*]] = tail call contract float 
@__ocml_trunc_f32(float noundef [[X:%.*]]) #[[ATTR14]]
-// DEFAULT-NEXT:ret float [[CALL_I]]
+// DEFAULT-NEXT:[[TMP0:%.*]] = tail call contract float 
@llvm.trunc.f32(float [[X:%.*]])
+// DEFAULT-NEXT:ret float [[TMP0]]
 //
 // FINITEONLY-LABEL: @test_truncf(
 // FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:[[CALL_I:%.*]] = tail call nnan ninf contract 
nofpclass(nan inf) float @__ocml_trunc_f32(float noundef nofpclass(nan inf) 
[[X:%.*]]) #[[ATTR14]]
-// FINITEONLY-NEXT:ret float [[CALL_I]]
+// FINITEONLY-NEXT:[[TMP0:%.*]] = tail call nnan ninf contract float 
@llvm.trunc.f32(float [[X:%.*]])
+// FINITEONLY-NEXT:ret float [[TMP0]]
 //
 extern "C" __device__ float test_truncf(float x) {
   return truncf(x);
@@ -3087,13 +3087,13 @@ extern "C" __device__ float test_truncf(float x) {
 
 // DEFAULT-LABEL: @test_trunc(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[CALL_I:%.*]] = tail call contract double 
@__ocml_trunc_f64(double noundef [[X:%.*]]) #[[ATTR14]]
-// DEFAULT-NEXT:ret double [[CALL_I]]
+// DEFAULT-NEXT:[[TMP0:%.*]] = tail call contract double 
@llvm.trunc.f64(double [[X:%.*]])
+// DEFAULT-NEXT:ret double [[TMP0]]
 //
 // FINITEONLY-LABEL: @test_trunc(
 // FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:[[CALL_I:%.*]] = tail call nnan ninf contract 
nofpclass(nan inf) double @__ocml_trunc_f64(double noundef nofpclass(nan inf) 
[[X:%.*]]) #[[ATTR14]]
-// FINITEONLY-NEXT:ret double [[CALL_I]]
+// FINITEONLY-NEXT:[[TMP0:%.*]] = tail call nnan ninf contract double 
@llvm.trunc.f64(double [[X:%.*]])
+// FINITEONLY-NEXT:ret double [[TMP0]]
 //
 extern "C" __device__ double test_trunc(double x) {
   return trunc(x);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153293: [clang][WebAssembly] support wasm32-wasi shared libraries

2023-06-23 Thread Joel Dice via Phabricator via cfe-commits
dicej added a comment.

@sbc100 @sunfish I believe I've addressed all your feedback so far.  Anything 
else you'd like me to do before we call this ready?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153293/new/

https://reviews.llvm.org/D153293

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153229: [llvm] Move StringExtras.h include from Error.h to Error.cpp

2023-06-23 Thread Elliot Goodrich via Phabricator via cfe-commits
IncludeGuardian updated this revision to Diff 533941.
IncludeGuardian added a comment.
Herald added subscribers: vkmr, kadircet, arphaman, emaste.
Herald added a reviewer: bollu.
Herald added a reviewer: aartbik.
Herald added a reviewer: MaskRay.
Herald added a project: clang-tools-extra.

Fix compile issues


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153229/new/

https://reviews.llvm.org/D153229

Files:
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/FileDistance.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/index/SymbolID.cpp
  clang-tools-extra/clangd/unittests/TestIndex.cpp
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/Basic/Sarif.cpp
  clang/lib/Driver/Job.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
  clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
  clang/tools/driver/cc1as_main.cpp
  lld/COFF/Chunks.cpp
  lld/COFF/DebugTypes.cpp
  lld/COFF/DriverUtils.cpp
  lld/Common/Strings.cpp
  lld/Common/Timer.cpp
  lld/ELF/AArch64ErrataFix.cpp
  lld/ELF/InputSection.h
  lld/ELF/Target.h
  lld/wasm/WriterUtils.cpp
  llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
  llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
  llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
  llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h
  llvm/include/llvm/Debuginfod/HTTPClient.h
  llvm/include/llvm/ProfileData/GCOV.h
  llvm/include/llvm/Support/Error.h
  llvm/lib/Analysis/AliasSetTracker.cpp
  llvm/lib/Analysis/CallGraphSCCPass.cpp
  llvm/lib/Analysis/InlineAdvisor.cpp
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
  llvm/lib/CodeGen/MachineBasicBlock.cpp
  llvm/lib/CodeGen/MachineCheckDebugify.cpp
  llvm/lib/CodeGen/RegisterBankInfo.cpp
  llvm/lib/DWARFLinker/DWARFLinker.cpp
  llvm/lib/DWARFLinker/DWARFLinkerCompileUnit.cpp
  llvm/lib/DWARFLinkerParallel/DWARFLinkerUnit.h
  llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
  llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
  llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeEnumInjectedSources.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeSourceFile.cpp
  llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
  llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
  llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h
  llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h
  llvm/lib/FileCheck/FileCheck.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/MC/MCAsmInfo.cpp
  llvm/lib/MC/MCParser/ELFAsmParser.cpp
  llvm/lib/MC/MCParser/WasmAsmParser.cpp
  llvm/lib/ObjCopy/COFF/COFFObjcopy.cpp
  llvm/lib/Object/Decompressor.cpp
  llvm/lib/Object/ELF.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
  llvm/lib/Remarks/YAMLRemarkParser.cpp
  llvm/lib/Support/BinaryStreamWriter.cpp
  llvm/lib/Support/DataExtractor.cpp
  llvm/lib/Support/Error.cpp
  llvm/lib/Support/JSON.cpp
  llvm/lib/Support/Path.cpp
  llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
  llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
  llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
  llvm/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
  llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/Target/X86/X86PreAMXConfig.cpp
  llvm/lib/Transforms/IPO/AttributorAttributes.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/lib/Transforms/Vectorize/VPlan.cpp
  llvm/tools/llvm-cov/CoverageReport.cpp
  llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/tools/llvm-opt-report/OptReport.cpp
  llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
  llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
  llvm/tools/

[PATCH] D153229: [llvm] Move StringExtras.h include from Error.h to Error.cpp

2023-06-23 Thread Elliot Goodrich via Phabricator via cfe-commits
IncludeGuardian added a comment.

@barannikov88 no it's not. I was going to commit separately to keep the change 
small, but it turns out that if I move this to the source file there are no 
additional changes needed. SmallVector.h has now been moved to Error.cpp as 
well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153229/new/

https://reviews.llvm.org/D153229

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153296: [AST] Stop evaluate constant expression if the condition expression which in switch statement contains errors

2023-06-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:4989
 if (SS->getCond()->isValueDependent()) {
   if (!EvaluateDependentExpr(SS->getCond(), Info))
 return ESR_Failed;

shafik wrote:
> As far as I can tell `Value` will still not be set if we don't return here 
> and we will still crash when we attempt to compare `Value` below:
> 
> ```
> LHS <= Value && Value <= RHS
> ```
I don't understand the comment?   We're returning 'failed', aren't we?  Except 
now `EvaluateDependentExpr`is where the failure is coming from?



Comment at: clang/lib/AST/ExprConstant.cpp:4893
+  // Stop evaluate if E is a RecoveryExpr.
+  if (isa(E))
+return false;

yronglin wrote:
> yronglin wrote:
> > erichkeane wrote:
> > > I'd probably suggest `E->containsErrors()` instead, to cover cases where 
> > > we're not the 'root' of a recovery expr?  So something like:
> > > 
> > > `switch(func_call(unknown_value))`
> > > 
> > > should create a dependent call expr, but would still contain errors.
> > Thanks! Use `E->containsErrors()` and added into release note.
> Seems check error inside `EvaluateDependentExpr` will missing diagnostic 
> messages.
> 
> This case was introduced in D84637
> ```
> constexpr int test5() { // expected-error {{constexpr function never produce}}
>   for (;; a++); // expected-error {{use of undeclared identifier}}  \
>expected-note {{constexpr evaluation hit maximum step 
> limit; possible infinite loop?}}
>   return 1;
> }
> ```
> ```
> ./main.cpp:2:11: error: use of undeclared identifier 'a'
> 2 |   for (;; a++); // expected-error {{use of undeclared identifier}}  \
>   |   ^
> 1 error generated.
> ```
> But I think the `infinite loop` diagnostic is unnecessary, should we update 
> the test case? WDYT?
Huh... thats interesting.  The 'Info.noteSideEffect' is sufficient to do that?  
Looking closer, I wonder if this is the wrong fix and his original idea was 
better.  It seems that this already has a 'containsError' check at the end, and 
should if it doesn't have side effects.  

I was hoping to have the problem generalized, but I think I was wrong, and we 
should go back to just fixing the 'switch' statements.



Comment at: clang/lib/AST/ExprConstant.cpp:4988
+  if (SS->getCond()->containsErrors() ||
+  !EvaluateDependentExpr(SS->getCond(), Info))
 return ESR_Failed;

shafik wrote:
> yronglin wrote:
> > erichkeane wrote:
> > > It seems to me that the 'better' solution is to make 
> > > EvaluateDependentExpr (or one of its children) be RecoveryExpr aware, and 
> > > result in a failed value instead.  That way we get this 'fix' for more 
> > > than just switch statements.
> > Thanks for your review!
> Erich so there are places in `ExprConstant.cpp` where if we  
> `isValueDependent()` we bail out like in the `Stmt::ReturnStmtClass` case 
> inside `EvaluateStmt1()`. The gist I get from the comment there is 
> 
> ```cpp
> // We know we returned, but we don't know what the value is.
> ```
> 
> Is that not correct or does it depend on each specific case?
TBH, i don't have a good idea of that.  I spent a little time digging here, but 
the constant evaluator isn't my forte.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153296/new/

https://reviews.llvm.org/D153296

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 940c94e - [clang][Sema] Fix comments to conform to bugprone-argument-comment (NFC)

2023-06-23 Thread Takuya Shimizu via cfe-commits

Author: Takuya Shimizu
Date: 2023-06-23T22:25:04+09:00
New Revision: 940c94e1c1b99511630b6f61890ac54161b5829c

URL: 
https://github.com/llvm/llvm-project/commit/940c94e1c1b99511630b6f61890ac54161b5829c
DIFF: 
https://github.com/llvm/llvm-project/commit/940c94e1c1b99511630b6f61890ac54161b5829c.diff

LOG: [clang][Sema] Fix comments to conform to bugprone-argument-comment (NFC)

Makes some comments conform to bugprone-argument-comment 
(https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html)

Added: 


Modified: 
clang/lib/Sema/Sema.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 694e07b46aaf0..24363af392ea2 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1365,12 +1365,12 @@ void Sema::ActOnEndOfTranslationUnit() {
   << DiagD << DiagRange;
 else
   Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
-  << /*function*/ 0 << DiagD << DiagRange;
+  << /*function=*/0 << DiagD << DiagRange;
   }
 } else {
   if (FD->getDescribedFunctionTemplate())
 Diag(DiagD->getLocation(), diag::warn_unused_template)
-<< /*function*/ 0 << DiagD << DiagRange;
+<< /*function=*/0 << DiagD << DiagRange;
   else
 Diag(DiagD->getLocation(), isa(DiagD)
? diag::warn_unused_member_function
@@ -1389,10 +1389,10 @@ void Sema::ActOnEndOfTranslationUnit() {
 }
 if (DiagD->isReferenced()) {
   Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
-  << /*variable*/ 1 << DiagD << DiagRange;
+  << /*variable=*/1 << DiagD << DiagRange;
 } else if (DiagD->getDescribedVarTemplate()) {
   Diag(DiagD->getLocation(), diag::warn_unused_template)
-  << /*variable*/ 1 << DiagD << DiagRange;
+  << /*variable=*/1 << DiagD << DiagRange;
 } else if (DiagD->getType().isConstQualified()) {
   const SourceManager &SM = SourceMgr;
   if (SM.getMainFileID() != SM.getFileID(DiagD->getLocation()) ||



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152796: [clang][Sema] Fix diagnostic message for unused constant varialbe templates

2023-06-23 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet marked an inline comment as done.
hazohelet added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:1385
+  Diag(DiagD->getLocation(), diag::warn_unused_template)
+  << /*variable*/ 1 << DiagD;
 } else if (DiagD->getType().isConstQualified()) {

shafik wrote:
> Sorry for late review but we should conform to 
> [bugprone-argument-comment](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html)
>  for these.
Thanks. Fixed in 940c94e1c1b99511630b6f61890ac54161b5829c


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152796/new/

https://reviews.llvm.org/D152796

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149246: [RISCV] Relax rules for ordering s/z/x prefixed extensions in ISA naming strings

2023-06-23 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.
Herald added a subscriber: wangpc.

All feedback so far has been positive and this has two LGTMs, but I also 
recognise this patch has been left for a while. Heads up that I intend to 
commit this towards the end of the working day Monday UK time unless anyone has 
any objections / concerns.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149246/new/

https://reviews.llvm.org/D149246

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-06-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:2024
   if (const VarDecl *VD = dyn_cast(D)) {
+if (D->isPlaceholderVar())
+  return !VD->hasInit();

Why would we get here?  Doesn't line 1995 pick this up?  Or am I missing where 
D is modified?

ALSO, I'd suggest making this VD->isPlaceholderVar, as to not annoy the SA 
tools.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:725
 
+void Sema::NotePlaceholderVariableDefinition(SourceLocation Loc) {
+  Diag(Loc, getLangOpts().CPlusPlus26

Not a fan of this function name... Perhaps Diag instead of Note?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153536/new/

https://reviews.llvm.org/D153536

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-06-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 533952.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144828/new/

https://reviews.llvm.org/D144828

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
  clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
@@ -0,0 +1,58 @@
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+// RUN: mkdir %T/misc-header-include-cycle-headers
+// RUN: cp -r %S/Inputs/header-include-cycle* %T/misc-header-include-cycle-headers/
+// RUN: mkdir %T/misc-header-include-cycle-headers/system
+// RUN: cp -r %S/Inputs/system/header-include-cycle* %T/misc-header-include-cycle-headers/system
+// RUN: clang-tidy %s -checks='-*,misc-header-include-cycle' -header-filter=.* \
+// RUN: -config="{CheckOptions: [{key: misc-header-include-cycle.IgnoredFilesList, value: 'header-include-cycle.self-e.hpp'}]}" \
+// RUN: -- -I%T/misc-header-include-cycle-headers -isystem %T/misc-header-include-cycle-headers/system \
+// RUN: --include %T/misc-header-include-cycle-headers/header-include-cycle.self-i.hpp | FileCheck %s \
+// RUN: -check-prefix=CHECK-MESSAGES "-implicit-check-not={{note|warning|error}}:"
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+
+#ifndef MAIN_GUARD
+#define MAIN_GUARD
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth-d.hpp:3:10: warning: circular header file dependency detected while including 'header-include-cycle.first-d.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third-d.hpp:3:10: note: 'header-include-cycle.fourth-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second-d.hpp:3:10: note: 'header-include-cycle.third-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first-d.hpp:3:10: note: 'header-include-cycle.second-d.hpp' included from here
+// CHECK-MESSAGES: :[[@LINE-5]]:10: note: 'header-include-cycle.first-d.hpp' included from here
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth.hpp:2:10: warning: circular header file dependency detected while including 'header-include-cycle.first.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third.hpp:2:10: note: 'header-include-cycle.fourth.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second.hpp:2:10: note: 'header-include-cycle.third.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first.hpp:2:10: note: 'header-include-cycle.second.hpp' included from here
+// CHECK-MESSAGES:

[PATCH] D153229: [llvm] Move StringExtras.h include from Error.h to Error.cpp

2023-06-23 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

In D153229#134 , @IncludeGuardian 
wrote:

> @barannikov88 no it's not. I was going to commit separately to keep the 
> change small, but it turns out that if I move this to the source file there 
> are no additional changes needed. SmallVector.h has now been moved to 
> Error.cpp as well.

I guess it is transitively included from some other header, probably Twine.h.
LGTM with build fixed. I'll leave it for someone else to accept so that it does 
not disappear from review queue.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153229/new/

https://reviews.llvm.org/D153229

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7a38b3b - [clang-format] Respect ColumnLimit 0 line breaks in inline asm

2023-06-23 Thread Emilia Kond via cfe-commits

Author: Emilia Kond
Date: 2023-06-23T17:30:24+03:00
New Revision: 7a38b3bfeb5623fb970a03ed9f295288802f4506

URL: 
https://github.com/llvm/llvm-project/commit/7a38b3bfeb5623fb970a03ed9f295288802f4506
DIFF: 
https://github.com/llvm/llvm-project/commit/7a38b3bfeb5623fb970a03ed9f295288802f4506.diff

LOG: [clang-format] Respect ColumnLimit 0 line breaks in inline asm

Previously, using ColumnLimit: 0 with extended inline asm with the
BreakBeforeInlineASMColon: OnlyMultiline option (the default style),
the formatter would act as if in Always mode, meaning a line break was
added before every colon in an extended inline assembly block.

This patch respects the already existing line breaks, and doesn't add
any new ones, if in ColumnLimit 0 mode.

Behaviour with Always stays as expected, with a break before every colon
regardless of any existing line breaks.

Behaviour with Never was broken before, and remains broken with this patch,
it is just never respected in ColumnLimit 0 mode.

Fixes https://github.com/llvm/llvm-project/issues/62754

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D150848

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index f6f6bf61f1c37..13b853ea9e226 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -357,7 +357,8 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   if (Current.MustBreakBefore ||
   (Current.is(TT_InlineASMColon) &&
(Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_Always ||
-Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_OnlyMultiline))) 
{
+(Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_OnlyMultiline &&
+ Style.ColumnLimit > 0 {
 return true;
   }
   if (CurrentState.BreakBeforeClosingBrace &&

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 6b0540400d7b7..7c0645c7cf01b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4612,6 +4612,24 @@ TEST_F(FormatTest, FormatsInlineASM) {
 format("__asm   {\n"
"}\n"
"int   i;"));
+
+  auto Style = getLLVMStyleWithColumns(0);
+  const StringRef Code1{"asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));"};
+  const StringRef Code2{"asm(\"xyz\"\n"
+": \"=a\"(a), \"=d\"(b)\n"
+": \"a\"(data));"};
+  const StringRef Code3{"asm(\"xyz\" : \"=a\"(a), \"=d\"(b)\n"
+": \"a\"(data));"};
+
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
+  verifyFormat(Code1, Style);
+  EXPECT_EQ(Code2, format(Code2, Style));
+  EXPECT_EQ(Code3, format(Code3, Style));
+
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_Always;
+  EXPECT_EQ(Code2, format(Code1, Style));
+  EXPECT_EQ(Code2, format(Code2, Style));
+  EXPECT_EQ(Code2, format(Code3, Style));
 }
 
 TEST_F(FormatTest, FormatTryCatch) {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150848: [clang-format] Respect ColumnLimit 0 line breaks in inline asm

2023-06-23 Thread Emilia Kond via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7a38b3bfeb56: [clang-format] Respect ColumnLimit 0 line 
breaks in inline asm (authored by rymiel).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150848/new/

https://reviews.llvm.org/D150848

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4612,6 +4612,24 @@
 format("__asm   {\n"
"}\n"
"int   i;"));
+
+  auto Style = getLLVMStyleWithColumns(0);
+  const StringRef Code1{"asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));"};
+  const StringRef Code2{"asm(\"xyz\"\n"
+": \"=a\"(a), \"=d\"(b)\n"
+": \"a\"(data));"};
+  const StringRef Code3{"asm(\"xyz\" : \"=a\"(a), \"=d\"(b)\n"
+": \"a\"(data));"};
+
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
+  verifyFormat(Code1, Style);
+  EXPECT_EQ(Code2, format(Code2, Style));
+  EXPECT_EQ(Code3, format(Code3, Style));
+
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_Always;
+  EXPECT_EQ(Code2, format(Code1, Style));
+  EXPECT_EQ(Code2, format(Code2, Style));
+  EXPECT_EQ(Code2, format(Code3, Style));
 }
 
 TEST_F(FormatTest, FormatTryCatch) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -357,7 +357,8 @@
   if (Current.MustBreakBefore ||
   (Current.is(TT_InlineASMColon) &&
(Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_Always ||
-Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_OnlyMultiline))) 
{
+(Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_OnlyMultiline &&
+ Style.ColumnLimit > 0 {
 return true;
   }
   if (CurrentState.BreakBeforeClosingBrace &&


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4612,6 +4612,24 @@
 format("__asm   {\n"
"}\n"
"int   i;"));
+
+  auto Style = getLLVMStyleWithColumns(0);
+  const StringRef Code1{"asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));"};
+  const StringRef Code2{"asm(\"xyz\"\n"
+": \"=a\"(a), \"=d\"(b)\n"
+": \"a\"(data));"};
+  const StringRef Code3{"asm(\"xyz\" : \"=a\"(a), \"=d\"(b)\n"
+": \"a\"(data));"};
+
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
+  verifyFormat(Code1, Style);
+  EXPECT_EQ(Code2, format(Code2, Style));
+  EXPECT_EQ(Code3, format(Code3, Style));
+
+  Style.BreakBeforeInlineASMColon = FormatStyle::BBIAS_Always;
+  EXPECT_EQ(Code2, format(Code1, Style));
+  EXPECT_EQ(Code2, format(Code2, Style));
+  EXPECT_EQ(Code2, format(Code3, Style));
 }
 
 TEST_F(FormatTest, FormatTryCatch) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -357,7 +357,8 @@
   if (Current.MustBreakBefore ||
   (Current.is(TT_InlineASMColon) &&
(Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_Always ||
-Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_OnlyMultiline))) {
+(Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_OnlyMultiline &&
+ Style.ColumnLimit > 0 {
 return true;
   }
   if (CurrentState.BreakBeforeClosingBrace &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153510: [Clang] Check type support for local variable declaration

2023-06-23 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 533961.
eopXD added a comment.

Extract RVV type check as a separate function as Craig has commented.
Add test case from Aaron's comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153510/new/

https://reviews.llvm.org/D153510

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/riscv-types.c
  clang/test/Sema/riscv-vector-float16-check.c
  clang/test/Sema/riscv-vector-float32-check.c
  clang/test/Sema/riscv-vector-float64-check.c
  clang/test/Sema/riscv-vector-int64-check.c

Index: clang/test/Sema/riscv-vector-int64-check.c
===
--- clang/test/Sema/riscv-vector-int64-check.c
+++ clang/test/Sema/riscv-vector-int64-check.c
@@ -6,3 +6,9 @@
 
 vint64m1_t foo() { /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vint64m1_t i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+
+  (void)i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+}
Index: clang/test/Sema/riscv-vector-float64-check.c
===
--- clang/test/Sema/riscv-vector-float64-check.c
+++ clang/test/Sema/riscv-vector-float64-check.c
@@ -6,3 +6,9 @@
 
 vfloat64m1_t foo() { /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vfloat64m1_t f64m1; /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
+
+  (void)f64m1; /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
+}
Index: clang/test/Sema/riscv-vector-float32-check.c
===
--- clang/test/Sema/riscv-vector-float32-check.c
+++ clang/test/Sema/riscv-vector-float32-check.c
@@ -6,3 +6,9 @@
 
 vfloat32m1_t foo() { /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vfloat32m1_t f32m1; /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
+
+  (void)f32m1; /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
+}
Index: clang/test/Sema/riscv-vector-float16-check.c
===
--- clang/test/Sema/riscv-vector-float16-check.c
+++ clang/test/Sema/riscv-vector-float16-check.c
@@ -6,3 +6,9 @@
 
 vfloat16m1_t foo() { /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vfloat16m1_t f16m1; /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
+
+  (void)f16m1; /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
+}
Index: clang/test/Sema/riscv-types.c
===
--- clang/test/Sema/riscv-types.c
+++ clang/test/Sema/riscv-types.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple riscv64 -target-feature +v -ast-print %s \
-// RUN:| FileCheck %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v \
+// RUN: -target-feature +experimental-zvfh -ast-print %s | FileCheck %s
 
 void bar(void) {
   // CHECK: __rvv_int64m1_t x0;
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -8769,6 +8769,8 @@
   return;
 }
   }
+  if (T->isRVVType())
+checkRVVTypeSupport(T, NewVD->getLocation(), cast(CurContext));
 }
 
 /// Perform semantic checking on a newly-created variable
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4964,6 +4964,22 @@
   return false;
 }
 
+void Sema::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
+  const TargetInfo &TI = Context.getTargetInfo();
+  if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ false) &&
+  !TI.hasFeature("zve64x"))
+Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64x";
+  if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ true) &&
+  !TI.hasFeature("experiment

[PATCH] D153229: [llvm] Move StringExtras.h include from Error.h to Error.cpp

2023-06-23 Thread Elliot Goodrich via Phabricator via cfe-commits
IncludeGuardian updated this revision to Diff 533966.
IncludeGuardian added a comment.

Fix missing include


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153229/new/

https://reviews.llvm.org/D153229

Files:
  llvm/unittests/Support/CompressionTest.cpp


Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Support/Compression.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/Error.h"


Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Support/Compression.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/Error.h"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152785: [COFF] Support -gsplit-dwarf for COFF on Windows

2023-06-23 Thread Haohai, Wen via Phabricator via cfe-commits
HaohaiWen updated this revision to Diff 533967.
HaohaiWen added a comment.

Restore DWARFContext.cpp since D153602  has 
fixed that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152785/new/

https://reviews.llvm.org/D152785

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/split-debug.c
  llvm/include/llvm/MC/MCWinCOFFObjectWriter.h
  llvm/lib/MC/MCAsmBackend.cpp
  llvm/lib/MC/WinCOFFObjectWriter.cpp
  llvm/test/DebugInfo/COFF/dwarf-headers.ll
  llvm/test/DebugInfo/COFF/fission-cu.ll
  llvm/test/DebugInfo/COFF/fission-sections.ll

Index: llvm/test/DebugInfo/COFF/fission-sections.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/fission-sections.ll
@@ -0,0 +1,42 @@
+; RUN: llc -split-dwarf-file=baz.dwo -split-dwarf-output=%t.dwo -O0 %s -mtriple=x86_64-unknown-windows-msvc -filetype=obj -o %t
+; RUN: llvm-objdump -h %t | FileCheck --check-prefix=OBJ %s
+; RUN: llvm-objdump -h %t.dwo | FileCheck --check-prefix=DWO %s
+
+; This test is derived from test/DebugInfo/X86/fission-cu.ll
+; But it checks that the output objects have the expected sections
+
+source_filename = "test/DebugInfo/X86/fission-cu.ll"
+
+@a = common global i32 0, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!4}
+!llvm.module.flags = !{!7}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = !DIGlobalVariable(name: "a", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true)
+!2 = !DIFile(filename: "baz.c", directory: "e:\\llvm-project\\tmp")
+!3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!4 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 3.3 (trunk 169021) (llvm/trunk 169020)", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "baz.dwo", emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5)
+!5 = !{}
+!6 = !{!0}
+!7 = !{i32 1, !"Debug Info Version", i32 3}
+
+; CHECK-LABEL: Sections:
+
+; OBJ: Idx Name
+; OBJ-NEXT:  0 .text
+; OBJ-NEXT:  1 .data
+; OBJ-NEXT:  2 .bss
+; OBJ-NEXT:  3 .debug_abbrev
+; OBJ-NEXT:  4 .debug_info
+; OBJ-NEXT:  5 .debug_str
+; OBJ-NEXT:  6 .debug_addr
+; OBJ-NEXT:  7 .debug_pubnames
+; OBJ-NEXT:  8 .debug_pubtypes
+; OBJ-NEXT:  9 .debug_line
+
+; DWO:  Idx Name
+; DWO-NEXT:   0 .debug_str.dwo
+; DWO-NEXT:   1 .debug_str_offsets.dwo
+; DWO-NEXT:   2 .debug_info.dwo
+; DWO-NEXT:   3 .debug_abbrev.dwo
Index: llvm/test/DebugInfo/COFF/fission-cu.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/fission-cu.ll
@@ -0,0 +1,120 @@
+; RUN: llc -split-dwarf-file=baz.dwo -O0 %s -mtriple=x86_64-unknown-windows-msvc -filetype=obj -o %t
+; RUN: llvm-dwarfdump -v -all %t | FileCheck %s
+; RUN: llvm-readobj --relocations %t | FileCheck --check-prefix=OBJ %s
+; RUN: llvm-objdump -h %t | FileCheck --check-prefix=HDR %s
+
+; This test is derived from test/DebugInfo/X86/fission-cu.ll
+
+source_filename = "test/DebugInfo/X86/fission-cu.ll"
+
+@a = common global i32 0, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!4}
+!llvm.module.flags = !{!7}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = !DIGlobalVariable(name: "a", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true)
+!2 = !DIFile(filename: "baz.c", directory: "e:\\llvm-project\\tmp")
+!3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!4 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 3.3 (trunk 169021) (llvm/trunk 169020)", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "baz.dwo", emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5)
+!5 = !{}
+; Check that the skeleton compile unit contains the proper attributes:
+; This DIE has the following attributes: DW_AT_comp_dir, DW_AT_stmt_list,
+; DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_dwo_name, DW_AT_dwo_id,
+; DW_AT_ranges_base, DW_AT_addr_base.
+
+; CHECK: .debug_abbrev contents:
+; CHECK: Abbrev table for offset: 0x
+; CHECK: [1] DW_TAG_compile_unit DW_CHILDREN_no
+; CHECK: DW_AT_stmt_list DW_FORM_sec_offset
+; CHECK: DW_AT_comp_dir  DW_FORM_strp
+; CHECK: DW_AT_GNU_dwo_name  DW_FORM_strp
+; CHECK: DW_AT_GNU_dwo_idDW_FORM_data8
+
+; Check that we're using the right forms.
+; CHECK: .debug_abbrev.dwo contents:
+; CHECK: Abbrev table for offset: 0x
+; CHECK: [1] DW_TAG_compile_unit DW_CHILDREN_yes
+; CHECK: DW_AT_producer  DW_FORM_GNU_str_index
+; CHECK: DW_AT_language  DW_FORM_data2
+; CHECK: DW_AT_name  DW_FORM_GNU_str_index
+; CHECK: DW_AT_GNU_dwo_name  DW_FORM_GNU_str_index
+; CHECK-NOT: DW_AT_low_pc
+; CHECK-NOT: DW_AT_stmt_list
+; CHECK-NOT: DW_AT_comp_dir
+; CHECK: 

[PATCH] D151720: [clang][ExprConstant] Fix display of syntactically-invalid note for member function calls

2023-06-23 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet updated this revision to Diff 533964.
hazohelet added a comment.

Address review comment NFC

- make some arguments conform to bugprone-argument-comments
- edit release note text


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151720/new/

https://reviews.llvm.org/D151720

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ExprConstant.cpp
  clang/test/AST/Interp/constexpr-nqueens.cpp
  clang/test/AST/Interp/lambda.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp
  clang/test/CXX/temp/temp.param/p8-cxx20.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/constexpr-frame-describe.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  clang/test/SemaCXX/deduced-return-type-cxx14.cpp

Index: clang/test/SemaCXX/deduced-return-type-cxx14.cpp
===
--- clang/test/SemaCXX/deduced-return-type-cxx14.cpp
+++ clang/test/SemaCXX/deduced-return-type-cxx14.cpp
@@ -296,7 +296,7 @@
   void f() {
 X().f();
 Y().f();
-constexpr int q = Y().f(); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to '&Y()->f()'}}
+constexpr int q = Y().f(); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'Y().f()'}}
   }
   struct NonLiteral { ~NonLiteral(); } nl; // cxx14-note {{user-provided destructor}}
   // cxx20_23-note@-1 {{'NonLiteral' is not literal because its destructor is not constexpr}}
Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -840,13 +840,13 @@
   copy fail1{good0}; // expected-error {{call to consteval function 'defaulted_special_member_template::copy::copy' is not a constant expression}} \
  expected-note {{in call to 'copy(good0)'}}
   fail1 = good0;  // expected-error {{call to consteval function 'defaulted_special_member_template::copy::operator=' is not a constant expression}} \
- expected-note {{in call to '&fail1->operator=(good0)'}}
+ expected-note {{in call to 'fail1.operator=(good0)'}}
 
   move good1;
   move fail2{static_cast&&>(good1)}; // expected-error {{call to consteval function 'defaulted_special_member_template::move::move' is not a constant expression}} \
expected-note {{in call to 'move(good1)'}}
   fail2 = static_cast&&>(good1);  // expected-error {{call to consteval function 'defaulted_special_member_template::move::operator=' is not a constant expression}} \
-   expected-note {{in call to '&fail2->operator=(good1)'}}
+   expected-note {{in call to 'fail2.operator=(good1)'}}
 }
 } // namespace defaulted_special_member_template
 
Index: clang/test/SemaCXX/constexpr-frame-describe.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constexpr-frame-describe.cpp
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+
+struct Foo {
+constexpr void zomg() const { (void)(1 / 0); } // expected-error {{constant expression}} \
+  expected-warning {{division by zero}} \
+  expected-note 2{{division by zero}}
+};
+
+struct S {
+constexpr S() {}
+constexpr bool operator==(const S&) const { // expected-error {{never produces a constant expression}}
+  return 1 / 0; // expected-warning {{division by zero}} \
+   expected-note 3{{division by zero}}
+}
+
+constexpr bool heh() const {
+auto F = new Foo();
+F->zomg(); // expected-note {{in call to 'F->zomg()'}}
+delete F;
+return false;
+}
+};
+
+constexpr S s;
+
+static_assert(s.heh()); // expected-error {{constant expression}} \
+   expected-note {{in call to 's.heh()'}}
+
+constexpr S s2;
+constexpr const S *sptr = &s;
+constexpr const S *sptr2 = &s2;
+static_assert(s == s2); // expected-error {{constant expression}} \
+   expected-note {{in call to 's.operator==(s2)'}}
+static_assert(*sptr == *sptr2); // expected-error {{constant expression}} \
+   expected-note {{in call to '*sptr.operator==(s2)'}}
+
+struct A {
+  constexpr int foo() { (void)(1/0); return 1;} // expected-error {{never produces a constant expression}} \
+   expected-warning {{division by zero}} \
+   expected-note 2{{division by zero}}
+};
+
+struct B {
+  A aa;
+  A *a = &aa;
+};
+
+struct C {
+  B b;
+};
+
+struct D {
+  C cc;
+  C *c = &cc;
+};
+
+c

[PATCH] D151720: [clang][ExprConstant] Fix display of syntactically-invalid note for member function calls

2023-06-23 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet marked 4 inline comments as done.
hazohelet added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:983
   EnableNewConstInterp(C.getLangOpts().EnableNewConstInterp),
-  BottomFrame(*this, SourceLocation(), nullptr, nullptr, CallRef()),
+  BottomFrame(*this, SourceLocation(), nullptr, nullptr,
+  /*CallExpr=*/nullptr, CallRef()),

shafik wrote:
> Let's fix the missing one while here.
Thanks for all the fix.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151720/new/

https://reviews.llvm.org/D151720

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153229: [llvm] Move StringExtras.h include from Error.h to Error.cpp

2023-06-23 Thread Elliot Goodrich via Phabricator via cfe-commits
IncludeGuardian updated this revision to Diff 533968.
IncludeGuardian added a comment.

Add back all includes (bad arc change)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153229/new/

https://reviews.llvm.org/D153229

Files:
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/FileDistance.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/index/SymbolID.cpp
  clang-tools-extra/clangd/unittests/TestIndex.cpp
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/Basic/Sarif.cpp
  clang/lib/Driver/Job.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
  clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
  clang/tools/driver/cc1as_main.cpp
  lld/COFF/Chunks.cpp
  lld/COFF/DebugTypes.cpp
  lld/COFF/DriverUtils.cpp
  lld/Common/Strings.cpp
  lld/Common/Timer.cpp
  lld/ELF/AArch64ErrataFix.cpp
  lld/ELF/InputSection.h
  lld/ELF/Target.h
  lld/wasm/WriterUtils.cpp
  llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
  llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
  llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
  llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h
  llvm/include/llvm/Debuginfod/HTTPClient.h
  llvm/include/llvm/ProfileData/GCOV.h
  llvm/include/llvm/Support/Error.h
  llvm/lib/Analysis/AliasSetTracker.cpp
  llvm/lib/Analysis/CallGraphSCCPass.cpp
  llvm/lib/Analysis/InlineAdvisor.cpp
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
  llvm/lib/CodeGen/MachineBasicBlock.cpp
  llvm/lib/CodeGen/MachineCheckDebugify.cpp
  llvm/lib/CodeGen/RegisterBankInfo.cpp
  llvm/lib/DWARFLinker/DWARFLinker.cpp
  llvm/lib/DWARFLinker/DWARFLinkerCompileUnit.cpp
  llvm/lib/DWARFLinkerParallel/DWARFLinkerUnit.h
  llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
  llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
  llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeEnumInjectedSources.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeSourceFile.cpp
  llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
  llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
  llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h
  llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h
  llvm/lib/FileCheck/FileCheck.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/MC/MCAsmInfo.cpp
  llvm/lib/MC/MCParser/ELFAsmParser.cpp
  llvm/lib/MC/MCParser/WasmAsmParser.cpp
  llvm/lib/ObjCopy/COFF/COFFObjcopy.cpp
  llvm/lib/Object/Decompressor.cpp
  llvm/lib/Object/ELF.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
  llvm/lib/Remarks/YAMLRemarkParser.cpp
  llvm/lib/Support/BinaryStreamWriter.cpp
  llvm/lib/Support/DataExtractor.cpp
  llvm/lib/Support/Error.cpp
  llvm/lib/Support/JSON.cpp
  llvm/lib/Support/Path.cpp
  llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
  llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
  llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
  llvm/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
  llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/Target/X86/X86PreAMXConfig.cpp
  llvm/lib/Transforms/IPO/AttributorAttributes.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/lib/Transforms/Vectorize/VPlan.cpp
  llvm/tools/llvm-cov/CoverageReport.cpp
  llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/tools/llvm-opt-report/OptReport.cpp
  llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
  llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
  llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
  llvm/tools/llvm-pdbutil/PrettyCompilandDumper.cpp
  llvm/tools/llvm-rc/ResourceScriptParser.cpp
  llvm/tools/llvm-strings/llvm-strings.cpp
  llvm/

[PATCH] D150978: [clang][Sema] Add CodeCompletionContext::CCC_ObjCClassForwardDecl

2023-06-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 533969.
dgoldman marked an inline comment as done.
dgoldman added a comment.

Add a contextAllowsHeaderInsertion helper to clangd


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150978/new/

https://reviews.llvm.org/D150978

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp

Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -537,6 +537,7 @@
 case CodeCompletionContext::CCC_Other:
 case CodeCompletionContext::CCC_ObjCInterface:
 case CodeCompletionContext::CCC_ObjCImplementation:
+case CodeCompletionContext::CCC_ObjCClassForwardDecl:
 case CodeCompletionContext::CCC_NewName:
 case CodeCompletionContext::CCC_MacroName:
 case CodeCompletionContext::CCC_PreprocessorExpression:
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -8460,6 +8460,24 @@
 Results.data(), Results.size());
 }
 
+void Sema::CodeCompleteObjCClassForwardDecl(Scope *S) {
+  ResultBuilder Results(*this, CodeCompleter->getAllocator(),
+CodeCompleter->getCodeCompletionTUInfo(),
+CodeCompletionContext::CCC_ObjCClassForwardDecl);
+  Results.EnterNewScope();
+
+  if (CodeCompleter->includeGlobals()) {
+// Add all classes.
+AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false,
+false, Results);
+  }
+
+  Results.ExitScope();
+
+  HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
+Results.data(), Results.size());
+}
+
 void Sema::CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName,
   SourceLocation ClassNameLoc) {
   ResultBuilder Results(*this, CodeCompleter->getAllocator(),
Index: clang/lib/Sema/CodeCompleteConsumer.cpp
===
--- clang/lib/Sema/CodeCompleteConsumer.cpp
+++ clang/lib/Sema/CodeCompleteConsumer.cpp
@@ -83,6 +83,7 @@
   case CCC_ObjCCategoryName:
   case CCC_IncludedFile:
   case CCC_Attribute:
+  case CCC_ObjCClassForwardDecl:
 return false;
   }
 
@@ -166,6 +167,8 @@
 return "Attribute";
   case CCKind::CCC_Recovery:
 return "Recovery";
+  case CCKind::CCC_ObjCClassForwardDecl:
+return "ObjCClassForwardDecl";
   }
   llvm_unreachable("Invalid CodeCompletionContext::Kind!");
 }
Index: clang/lib/Parse/ParseObjc.cpp
===
--- clang/lib/Parse/ParseObjc.cpp
+++ clang/lib/Parse/ParseObjc.cpp
@@ -153,6 +153,11 @@
 
   while (true) {
 MaybeSkipAttributes(tok::objc_class);
+if (Tok.is(tok::code_completion)) {
+  cutOffParsing();
+  Actions.CodeCompleteObjCClassForwardDecl(getCurScope());
+  return Actions.ConvertDeclToDeclGroup(nullptr);
+}
 if (expectIdentifier()) {
   SkipUntil(tok::semi);
   return Actions.ConvertDeclToDeclGroup(nullptr);
Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -322,6 +322,7 @@
   if (ID->getDefinition())
 Contexts |= (1LL << CodeCompletionContext::CCC_Expression);
   Contexts |= (1LL << CodeCompletionContext::CCC_ObjCInterfaceName);
+  Contexts |= (1LL << CodeCompletionContext::CCC_ObjCClassForwardDecl);
 }
 
 // Deal with tag names.
@@ -2027,6 +2028,7 @@
   case CodeCompletionContext::CCC_IncludedFile:
   case CodeCompletionContext::CCC_Attribute:
   case CodeCompletionContext::CCC_NewName:
+  case CodeCompletionContext::CCC_ObjCClassForwardDecl:
 // We're looking for nothing, or we're looking for names that cannot
 // be hidden.
 return;
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -13417,6 +13417,7 @@
  ArrayRef Protocols);
   void CodeCompleteObjCProtocolDecl(Scope *S);
   void CodeCompleteObjCInterfaceDecl(Scope *S);
+  void CodeCompleteObjCClassForwardDecl(Scope *S);
   void CodeCompleteObjCSuperclass(Scope *S,
   IdentifierInfo *ClassName,
   Sourc

[PATCH] D153267: [clang][Diagnostics] Provide parameter source range to arity-mismatch notes

2023-06-23 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet updated this revision to Diff 533971.
hazohelet marked an inline comment as done.
hazohelet edited the summary of this revision.
hazohelet added a comment.

Address comments from @cjdb and @aaron.ballman

- Remove unnecessary cast to void in test
- Add release note


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153267/new/

https://reviews.llvm.org/D153267

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/Misc/diag-func-call-ranges.c
  clang/test/Misc/diag-func-call-ranges.cpp


Index: clang/test/Misc/diag-func-call-ranges.cpp
===
--- /dev/null
+++ clang/test/Misc/diag-func-call-ranges.cpp
@@ -0,0 +1,14 @@
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 
2>&1 | FileCheck %s --strict-whitespace
+
+// CHECK: error: no matching function for call to 'func'
+
+// CHECK:  :{[[@LINE+1]]:12-[[@LINE+1]]:18}: note: {{.*}} requires single 
argument
+void func( int aa ) {}
+// CHECK:  :{[[@LINE+1]]:12-[[@LINE+3]]:18}: note: {{.*}} requires 3 
arguments
+void func( int aa,
+   int bb,
+   int cc) {}
+
+void arity_mismatch() {
+  func(2, 4);
+}
Index: clang/test/Misc/diag-func-call-ranges.c
===
--- /dev/null
+++ clang/test/Misc/diag-func-call-ranges.c
@@ -0,0 +1,11 @@
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 
2>&1 | FileCheck %s --strict-whitespace
+
+// CHECK:  :{9:3-9:7}: error: too few arguments
+// CHECK:  :{7:12-7:26}: note: 'func' declared here
+// CHECK:  :{10:3-10:7}{10:13-10:17}: error: too many arguments
+// CHECK:  :{7:12-7:26}: note: 'func' declared here
+void func( int aa, int bb) {}
+void arity_mismatch() {
+  func(3);
+  func(3, 4,5, 6);
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -11037,11 +11037,13 @@
   if (modeCount == 1 && Fn->getParamDecl(0)->getDeclName())
 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity_one)
 << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second
-<< Description << mode << Fn->getParamDecl(0) << NumFormalArgs;
+<< Description << mode << Fn->getParamDecl(0) << NumFormalArgs
+<< Fn->getParametersSourceRange();
   else
 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity)
 << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second
-<< Description << mode << modeCount << NumFormalArgs;
+<< Description << mode << modeCount << NumFormalArgs
+<< Fn->getParametersSourceRange();
 
   MaybeEmitInheritedConstructorNote(S, Found);
 }
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -6449,7 +6449,8 @@
 
   // Emit the location of the prototype.
   if (!TC && FDecl && !FDecl->getBuiltinID() && !IsExecConfig)
-Diag(FDecl->getLocation(), diag::note_callee_decl) << FDecl;
+Diag(FDecl->getLocation(), diag::note_callee_decl)
+<< FDecl << FDecl->getParametersSourceRange();
 
   return true;
 }
@@ -6494,7 +6495,8 @@
 
   // Emit the location of the prototype.
   if (!TC && FDecl && !FDecl->getBuiltinID() && !IsExecConfig)
-Diag(FDecl->getLocation(), diag::note_callee_decl) << FDecl;
+Diag(FDecl->getLocation(), diag::note_callee_decl)
+<< FDecl << FDecl->getParametersSourceRange();
 
   // This deletes the extra arguments.
   Call->shrinkNumArgs(NumParams);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -359,6 +359,8 @@
 - The Fix-It emitted for unused labels used to expand to the next line, which 
caused
   visual oddities now that Clang shows more than one line of code snippet. 
This has
   been fixed and the Fix-It now only spans to the end of the ``:``.
+- Clang now underlines the parameter list of function declaration when emitting
+  a note about the mismatch in the number of arguments.
 
 Bug Fixes in This Version
 -


Index: clang/test/Misc/diag-func-call-ranges.cpp
===
--- /dev/null
+++ clang/test/Misc/diag-func-call-ranges.cpp
@@ -0,0 +1,14 @@
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 2>&1 | FileCheck %s --strict-whitespace
+
+// CHECK: error: no matching function for call to 'func'
+
+// CHECK:  :{[[@LINE+1]]:12-[[@LINE+1]]:18}: note: {{.*}} requires single argument
+void func( int aa ) {}
+// CHECK:  :{[[@LINE+1]]:12-[[@LINE+3]]:18}: note: {{.*}} requires 3 arguments
+void func( int aa,
+ 

[PATCH] D153639: [clang-tidy] Document modernize-raw-string-literal check options

2023-06-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Add missing documentation for DelimiterStem and ReplaceShorterLiterals
options.

Fixes #54662


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153639

Files:
  clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst


Index: clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
@@ -8,7 +8,7 @@
 
 Example:
 
-.. code-blocK:: c++
+.. code-block:: c++
 
   const char *const Quotes{"embedded \"quotes\""};
   const char *const Paragraph{"Line one.\nLine two.\nLine three.\n"};
@@ -44,3 +44,15 @@
 An escaped horizontal tab, form feed, or vertical tab prevents the string
 literal from being converted. The presence of a horizontal tab, form feed or
 vertical tab in source code is not visually obvious.
+
+.. option:: DelimiterStem
+
+  Custom delimiter to escape characters in raw string literals. It is used in
+  the following construction: ``R"stem_delimiter(contents)stem_delimiter"``.
+  The default value is `lit`.
+
+.. option:: ReplaceShorterLiterals
+
+  Controls replacing shorter non-raw string literals with longer raw string
+  literals. Setting this option to `true` enables the replacement.
+  The default value is `false` (shorter literals are not replaced).


Index: clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
@@ -8,7 +8,7 @@
 
 Example:
 
-.. code-blocK:: c++
+.. code-block:: c++
 
   const char *const Quotes{"embedded \"quotes\""};
   const char *const Paragraph{"Line one.\nLine two.\nLine three.\n"};
@@ -44,3 +44,15 @@
 An escaped horizontal tab, form feed, or vertical tab prevents the string
 literal from being converted. The presence of a horizontal tab, form feed or
 vertical tab in source code is not visually obvious.
+
+.. option:: DelimiterStem
+
+  Custom delimiter to escape characters in raw string literals. It is used in
+  the following construction: ``R"stem_delimiter(contents)stem_delimiter"``.
+  The default value is `lit`.
+
+.. option:: ReplaceShorterLiterals
+
+  Controls replacing shorter non-raw string literals with longer raw string
+  literals. Setting this option to `true` enables the replacement.
+  The default value is `false` (shorter literals are not replaced).
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153641: [clang-format] Preserve AmpAmpTokenType in nested parentheses

2023-06-23 Thread Emilia Kond via Phabricator via cfe-commits
rymiel created this revision.
rymiel added a project: clang-format.
rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay.
Herald added projects: All, clang.
Herald added a subscriber: cfe-commits.
rymiel requested review of this revision.

When parsing a requires clause, the UnwrappedLineParser would delegate to
parseParens with an AmpAmpTokenType set to BinaryOperator. However,
parseParens would not carry this over into any nested parens, meaning it
could assign a different token type to an && in a requires clause.

This patch makes sure parseParens inherits its parameter when performing
a recursive call.

Fixes https://github.com/llvm/llvm-project/issues/63251


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153641

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -906,6 +906,16 @@
   annotate("auto bar() -> Template requires(is_integral_v) {}");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("void foo() requires((A) && C) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("void foo() requires(((A) && C)) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2431,14 +2431,14 @@
 
 /// \brief Parses a pair of parentheses (and everything between them).
 /// \param AmpAmpTokenType If different than TT_Unknown sets this type for all
-/// double ampersands. This only counts for the current parens scope.
+/// double ampersands. This applies for all nested scopes as well.
 void UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
   assert(FormatTok->is(tok::l_paren) && "'(' expected.");
   nextToken();
   do {
 switch (FormatTok->Tok.getKind()) {
 case tok::l_paren:
-  parseParens();
+  parseParens(AmpAmpTokenType);
   if (Style.Language == FormatStyle::LK_Java && 
FormatTok->is(tok::l_brace))
 parseChildBlock();
   break;


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -906,6 +906,16 @@
   annotate("auto bar() -> Template requires(is_integral_v) {}");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("void foo() requires((A) && C) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("void foo() requires(((A) && C)) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2431,14 +2431,14 @@
 
 /// \brief Parses a pair of parentheses (and everything between them).
 /// \param AmpAmpTokenType If different than TT_Unknown sets this type for all
-/// double ampersands. This only counts for the current parens scope.
+/// double ampersands. This applies for all nested scopes as well.
 void UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
   assert(FormatTok->is(tok::l_paren) && "'(' expected.");
   nextToken();
   do {
 switch (FormatTok->Tok.getKind()) {
 case tok::l_paren:
-  parseParens();
+  parseParens(AmpAmpTokenType);
   if (Style.Language == FormatStyle::LK_Java && FormatTok->is(tok::l_brace))
 parseChildBlock();
   break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153641: [clang-format] Preserve AmpAmpTokenType in nested parentheses

2023-06-23 Thread Emilia Kond via Phabricator via cfe-commits
rymiel added a comment.

@HazardyKnusperkeks I'm not sure why it didn't recurse already, given that you 
even documented that it doesn't, but I chose to trust in the Beyoncé rule.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153641/new/

https://reviews.llvm.org/D153641

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153590: Don't use float_t and double_t with #pragma clang fp eval_method.

2023-06-23 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 533981.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153590/new/

https://reviews.llvm.org/D153590

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-only-in-default-eval.cpp
  clang/test/Sema/fp-eval-pragma-with-float-double_t-1.c
  clang/test/Sema/fp-eval-pragma-with-float-double_t-2.c
  clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c

Index: clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
===
--- /dev/null
+++ clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
@@ -0,0 +1,102 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -verify -DNOERROR %s
+// RUN: %clang_cc1 -verify -fsyntax-only -x c++ -DCPP -DNOERROR %s
+
+// RUN: %clang_cc1 -verify -fsyntax-only -ffp-eval-method=extended -DNOERROR %s
+// RUN: %clang_cc1 -verify -fsyntax-only -x c++ -DCPP \
+// RUN: -ffp-eval-method=extended -DNOERROR %s
+
+// RUN: %clang_cc1 -verify -fsyntax-only -ffp-eval-method=source %s
+// RUN: %clang_cc1 -verify -fsyntax-only -x c++ -DCPP -ffp-eval-method=source %s
+
+// RUN: %clang_cc1 -verify -fsyntax-only -ffp-eval-method=double %s
+// RUN: %clang_cc1 -verify -fsyntax-only -x c++ -DCPP -ffp-eval-method=double %s
+
+
+#ifdef NOERROR
+// expected-no-diagnostics
+typedef float float_t;
+typedef double double_t;
+#else
+#ifdef CPP
+typedef float float_t; //expected-error 9 {{cannot use type 'float_t' within '#pragma clang fp eval_method'; type is set according to the default eval method for the translation unit}}
+
+typedef double double_t; //expected-error 9 {{cannot use type 'double_t' within '#pragma clang fp eval_method'; type is set according to the default eval method for the translation unit}}
+#else
+typedef float float_t; //expected-error 7 {{cannot use type 'float_t' within '#pragma clang fp eval_method'; type is set according to the default eval method for the translation unit}}
+  
+typedef double double_t; //expected-error 7 {{cannot use type 'double_t' within '#pragma clang fp eval_method'; type is set according to the default eval method for the translation unit}}
+#endif
+#endif
+
+float foo1() {
+#pragma clang fp eval_method(extended)
+  float a;
+  double b;
+  return a - b;
+}
+  
+float foo2() {
+#pragma clang fp eval_method(extended)
+  float_t a; 
+  double_t b; 
+  return a - b;
+}
+  
+void foo3() {
+#pragma clang fp eval_method(extended)
+  char buff[sizeof(float_t)];
+  char bufd[sizeof(double_t)];
+  buff[1] = bufd[2];
+}
+  
+float foo4() {
+#pragma clang fp eval_method(extended)
+  typedef float_t FT;
+  typedef double_t DT;
+  FT a;
+  DT b;
+  return a - b;
+}
+  
+int foo5() {
+#pragma clang fp eval_method(extended)
+  int t = _Generic( 1.0L, float_t:1, default:0);
+  int v = _Generic( 1.0L, double_t:1, default:0);
+  return t;
+}
+
+void foo6() {
+#pragma clang fp eval_method(extended)
+  float f = (float_t)1; 
+  double d = (double_t)2; 
+}
+  
+void foo7() {
+#pragma clang fp eval_method(extended)
+  float c1 = (float_t)12;
+  double c2 = (double_t)13;
+}
+  
+float foo8() {
+#pragma clang fp eval_method(extended)
+  extern float_t f;
+  extern double_t g;
+  return f-g;
+}
+
+#ifdef CPP
+void foo9() {
+#pragma clang fp eval_method(extended)
+  auto resf = [](float_t f) { return f; };
+  auto resd = [](double_t g) { return g; };
+}
+
+void foo10() {
+#pragma clang fp eval_method(extended)
+  using Ft = float_t;
+  using Dt = double_t;
+  Ft a;
+  Dt b;
+}
+#endif
+ 
Index: clang/test/Sema/fp-eval-pragma-with-float-double_t-2.c
===
--- /dev/null
+++ clang/test/Sema/fp-eval-pragma-with-float-double_t-2.c
@@ -0,0 +1,100 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -DNOERROR %s
+// RUN: %clang_cc1 -verify -fsyntax-only -x c++ -DCPP -DNOERROR %s
+
+// RUN: %clang_cc1 -verify -fsyntax-only -ffp-eval-method=double -DNOERROR %s
+// RUN: %clang_cc1 -verify -fsyntax-only -x c++ -DCPP -ffp-eval-method=double -DNOERROR %s
+
+// RUN: %clang_cc1 -verify -fsyntax-only -ffp-eval-method=source %s
+// RUN: %clang_cc1 -verify -fsyntax-only -x c++ -DCPP -ffp-eval-method=source %s
+
+// RUN: %clang_cc1 -verify -fsyntax-only -ffp-eval-method=extended %s
+// RUN: %clang_cc1 -verify -fsyntax-only -x c++ -DCPP -ffp-eval-method=extended %s 
+
+#ifdef NOERROR
+// expected-no-diagnostics
+typedef float float_t;
+typedef double double_t;
+#else
+#ifdef CPP
+typedef float float_t; //expected-error 9 {{cannot use type 'float_t' within '#pragma clang fp eval_method'; type is set according to the default eval method for the translation unit}}
+  
+typedef double double_t; //expected-error 9 {{cannot use type 'double_t' within '#pragma 

[PATCH] D95299: Fix truncated __OPENMP_NVPTX__ preprocessor condition

2023-06-23 Thread Nicolas Capens via Phabricator via cfe-commits
capn added a comment.

Can a committer go ahead and land this please? I'm running into this warning 
for any CUDA code compiled by Clang.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95299/new/

https://reviews.llvm.org/D95299

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153639: [clang-tidy] Document modernize-raw-string-literal check options

2023-06-23 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb0f6fd24dc12: [clang-tidy] Document 
modernize-raw-string-literal check options (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153639/new/

https://reviews.llvm.org/D153639

Files:
  clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst


Index: clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
@@ -8,7 +8,7 @@
 
 Example:
 
-.. code-blocK:: c++
+.. code-block:: c++
 
   const char *const Quotes{"embedded \"quotes\""};
   const char *const Paragraph{"Line one.\nLine two.\nLine three.\n"};
@@ -44,3 +44,15 @@
 An escaped horizontal tab, form feed, or vertical tab prevents the string
 literal from being converted. The presence of a horizontal tab, form feed or
 vertical tab in source code is not visually obvious.
+
+.. option:: DelimiterStem
+
+  Custom delimiter to escape characters in raw string literals. It is used in
+  the following construction: ``R"stem_delimiter(contents)stem_delimiter"``.
+  The default value is `lit`.
+
+.. option:: ReplaceShorterLiterals
+
+  Controls replacing shorter non-raw string literals with longer raw string
+  literals. Setting this option to `true` enables the replacement.
+  The default value is `false` (shorter literals are not replaced).


Index: clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
@@ -8,7 +8,7 @@
 
 Example:
 
-.. code-blocK:: c++
+.. code-block:: c++
 
   const char *const Quotes{"embedded \"quotes\""};
   const char *const Paragraph{"Line one.\nLine two.\nLine three.\n"};
@@ -44,3 +44,15 @@
 An escaped horizontal tab, form feed, or vertical tab prevents the string
 literal from being converted. The presence of a horizontal tab, form feed or
 vertical tab in source code is not visually obvious.
+
+.. option:: DelimiterStem
+
+  Custom delimiter to escape characters in raw string literals. It is used in
+  the following construction: ``R"stem_delimiter(contents)stem_delimiter"``.
+  The default value is `lit`.
+
+.. option:: ReplaceShorterLiterals
+
+  Controls replacing shorter non-raw string literals with longer raw string
+  literals. Setting this option to `true` enables the replacement.
+  The default value is `false` (shorter literals are not replaced).
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] b0f6fd2 - [clang-tidy] Document modernize-raw-string-literal check options

2023-06-23 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-06-23T16:14:15Z
New Revision: b0f6fd24dc12cf860e6b01f417badb115c7535ce

URL: 
https://github.com/llvm/llvm-project/commit/b0f6fd24dc12cf860e6b01f417badb115c7535ce
DIFF: 
https://github.com/llvm/llvm-project/commit/b0f6fd24dc12cf860e6b01f417badb115c7535ce.diff

LOG: [clang-tidy] Document modernize-raw-string-literal check options

Add missing documentation for DelimiterStem and ReplaceShorterLiterals
options.

Fixes #54662

Reviewed By: Eugene.Zelenko

Differential Revision: https://reviews.llvm.org/D153639

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
index 3525d571742ef..6d7589a0011bb 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst
@@ -8,7 +8,7 @@ with raw string literals.
 
 Example:
 
-.. code-blocK:: c++
+.. code-block:: c++
 
   const char *const Quotes{"embedded \"quotes\""};
   const char *const Paragraph{"Line one.\nLine two.\nLine three.\n"};
@@ -44,3 +44,15 @@ string literals are left unchanged.
 An escaped horizontal tab, form feed, or vertical tab prevents the string
 literal from being converted. The presence of a horizontal tab, form feed or
 vertical tab in source code is not visually obvious.
+
+.. option:: DelimiterStem
+
+  Custom delimiter to escape characters in raw string literals. It is used in
+  the following construction: ``R"stem_delimiter(contents)stem_delimiter"``.
+  The default value is `lit`.
+
+.. option:: ReplaceShorterLiterals
+
+  Controls replacing shorter non-raw string literals with longer raw string
+  literals. Setting this option to `true` enables the replacement.
+  The default value is `false` (shorter literals are not replaced).



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153590: Don't use float_t and double_t with #pragma clang fp eval_method.

2023-06-23 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153590/new/

https://reviews.llvm.org/D153590

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153229: [llvm] Move StringExtras.h include from Error.h to Error.cpp

2023-06-23 Thread Elliot Goodrich via Phabricator via cfe-commits
IncludeGuardian updated this revision to Diff 533989.
IncludeGuardian added a comment.

Fix missing includes for Windows-only files


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153229/new/

https://reviews.llvm.org/D153229

Files:
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/FileDistance.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/index/SymbolID.cpp
  clang-tools-extra/clangd/unittests/TestIndex.cpp
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/Basic/Sarif.cpp
  clang/lib/Driver/Job.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
  clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
  clang/tools/driver/cc1as_main.cpp
  lld/COFF/Chunks.cpp
  lld/COFF/DebugTypes.cpp
  lld/COFF/DriverUtils.cpp
  lld/Common/Strings.cpp
  lld/Common/Timer.cpp
  lld/ELF/AArch64ErrataFix.cpp
  lld/ELF/InputSection.h
  lld/ELF/Target.h
  lld/wasm/WriterUtils.cpp
  llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
  llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
  llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
  llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h
  llvm/include/llvm/Debuginfod/HTTPClient.h
  llvm/include/llvm/ProfileData/GCOV.h
  llvm/include/llvm/Support/Error.h
  llvm/lib/Analysis/AliasSetTracker.cpp
  llvm/lib/Analysis/CallGraphSCCPass.cpp
  llvm/lib/Analysis/InlineAdvisor.cpp
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
  llvm/lib/CodeGen/MachineBasicBlock.cpp
  llvm/lib/CodeGen/MachineCheckDebugify.cpp
  llvm/lib/CodeGen/RegisterBankInfo.cpp
  llvm/lib/DWARFLinker/DWARFLinker.cpp
  llvm/lib/DWARFLinker/DWARFLinkerCompileUnit.cpp
  llvm/lib/DWARFLinkerParallel/DWARFLinkerUnit.h
  llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
  llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
  llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeEnumInjectedSources.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeSourceFile.cpp
  llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
  llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
  llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h
  llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h
  llvm/lib/FileCheck/FileCheck.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/MC/MCAsmInfo.cpp
  llvm/lib/MC/MCParser/ELFAsmParser.cpp
  llvm/lib/MC/MCParser/WasmAsmParser.cpp
  llvm/lib/ObjCopy/COFF/COFFObjcopy.cpp
  llvm/lib/Object/Decompressor.cpp
  llvm/lib/Object/ELF.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
  llvm/lib/Remarks/YAMLRemarkParser.cpp
  llvm/lib/Support/BinaryStreamWriter.cpp
  llvm/lib/Support/DataExtractor.cpp
  llvm/lib/Support/Error.cpp
  llvm/lib/Support/JSON.cpp
  llvm/lib/Support/Path.cpp
  llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
  llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
  llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
  llvm/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
  llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/Target/X86/X86PreAMXConfig.cpp
  llvm/lib/Transforms/IPO/AttributorAttributes.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/lib/Transforms/Vectorize/VPlan.cpp
  llvm/lib/WindowsDriver/MSVCPaths.cpp
  llvm/tools/llvm-cov/CoverageReport.cpp
  llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/tools/llvm-opt-report/OptReport.cpp
  llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
  llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
  llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
  llvm/tools/llvm-pdbutil/PrettyCompilandDumper.cpp
  llvm/tools/llvm-rc/ResourceScriptParser.cpp
  llvm

[PATCH] D151697: [clang] Add test for CWG1710 and related issues

2023-06-23 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151697/new/

https://reviews.llvm.org/D151697

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152720: [clangd][ObjC] Support ObjC class rename from implementation decls

2023-06-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 533993.
dgoldman marked 4 inline comments as done.
dgoldman added a comment.

Fixes for review


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152720/new/

https://reviews.llvm.org/D152720

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -840,6 +840,20 @@
   foo('x');
 }
   )cpp",
+
+  // ObjC class with a category.
+  R"cpp(
+@interface [[Fo^o]]
+@end
+@implementation [[F^oo]]
+@end
+@interface [[Fo^o]] (Category)
+@end
+@implementation [[F^oo]] (Category)
+@end
+
+void func([[Fo^o]] *f) {}
+  )cpp",
   };
   llvm::StringRef NewName = "NewName";
   for (llvm::StringRef T : Tests) {
@@ -890,6 +904,15 @@
   )cpp",
"not a supported kind", HeaderFile},
 
+  {R"cpp(// disallow - category rename.
+@interface Foo
+@end
+@interface Foo (Cate^gory)
+@end
+  )cpp",
+   "Cannot rename symbol: there is no symbol at the given location",
+   HeaderFile},
+
   {
   R"cpp(
  #define MACRO 1
@@ -1468,7 +1491,7 @@
 
 TEST(CrossFileRenameTests, WithUpToDateIndex) {
   MockCompilationDatabase CDB;
-  CDB.ExtraClangFlags = {"-xc++"};
+  CDB.ExtraClangFlags = {"-xobjective-c++"};
   // rename is runnning on all "^" points in FooH, and "[[]]" ranges are the
   // expected rename occurrences.
   struct Case {
@@ -1557,13 +1580,12 @@
 }
   )cpp",
   },
-  {
-  // virtual templated method
-  R"cpp(
+  {// virtual templated method
+   R"cpp(
 template  class Foo { virtual void [[m]](); };
 class Bar : Foo { void [[^m]]() override; };
   )cpp",
-  R"cpp(
+   R"cpp(
   #include "foo.h"
 
   template void Foo::[[m]]() {}
@@ -1571,8 +1593,7 @@
   // the canonical Foo::m().
   // https://github.com/clangd/clangd/issues/1325
   class Baz : Foo { void m() override; };
-)cpp"
-  },
+)cpp"},
   {
   // rename on constructor and destructor.
   R"cpp(
@@ -1677,6 +1698,20 @@
 }
   )cpp",
   },
+  {
+  // Objective-C classes.
+  R"cpp(
+@interface [[Fo^o]]
+@end
+  )cpp",
+  R"cpp(
+#include "foo.h"
+@implementation [[F^oo]]
+@end
+
+void func([[Foo]] *f) {}
+  )cpp",
+  },
   };
 
   trace::TestTracer Tracer;
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -1054,6 +1054,16 @@
   )cpp";
   EXPECT_DECLS("ObjCCategoryImplDecl", "@interface Foo(Ext)");
 
+  Code = R"cpp(
+@interface Foo
+@end
+@interface Foo (Ext)
+@end
+@implementation Foo ([[Ext]])
+@end
+  )cpp";
+  EXPECT_DECLS("ObjCCategoryImplDecl", "@interface Foo(Ext)");
+
   Code = R"cpp(
 void test(id p);
   )cpp";
@@ -1143,10 +1153,7 @@
 std::string DumpedReferences;
   };
 
-  /// Parses \p Code, finds function or namespace '::foo' and annotates its body
-  /// with results of findExplicitReferences.
-  /// See actual tests for examples of annotation format.
-  AllRefs annotateReferencesInFoo(llvm::StringRef Code) {
+  TestTU newTU(llvm::StringRef Code) {
 TestTU TU;
 TU.Code = std::string(Code);
 
@@ -1155,30 +1162,11 @@
 TU.ExtraArgs.push_back("-std=c++20");
 TU.ExtraArgs.push_back("-xobjective-c++");
 
-auto AST = TU.build();
-auto *TestDecl = &findDecl(AST, "foo");
-if (auto *T = llvm::dyn_cast(TestDecl))
-  TestDecl = T->getTemplatedDecl();
-
-std::vector Refs;
-if (const auto *Func = llvm::dyn_cast(TestDecl))
-  findExplicitReferences(
-  Func->getBody(),
-  [&Refs](ReferenceLoc R) { Refs.push_back(std::move(R)); },
-  AST.getHeuristicResolver());
-else if (const auto *NS = llvm::dyn_cast(TestDecl))
-  findExplicitReferences(
-  NS,
-  [&Refs, &NS](ReferenceLoc R) {
-// Avoid adding the namespace foo decl to the results.
-if (R.Targets.size() == 1 && R.Targets.front() == NS)
-  return;
-Refs.push_back(std::move(R));
-  },
-  AST.getHeuristicResolver());
-else
-  ADD_FAILURE() << "Failed to find ::foo decl for test";
+return

[PATCH] D152720: [clangd][ObjC] Support ObjC class rename from implementation decls

2023-06-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman added inline comments.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:787
+  // names like class and protocol names.
+  if (const auto *CD = dyn_cast(&RenameDecl))
+if (CD->getName() != IdentifierToken->text(SM))

kadircet wrote:
> this special casing should no longer be needed if we just map CategoryDecls 
> to InterfaceDecls in `locateDeclAt` rather than at canonicalization time
Yep, no longer needed since the `Check the rename-triggering location is 
actually being renamed` check catches this although the error is no symbol 
found instead of unsupported symbol.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152720/new/

https://reviews.llvm.org/D152720

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153296: [AST] Stop evaluate constant expression if the condition expression which in switch statement contains errors

2023-06-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

So I think I'm pretty confident that the only time we would call 
`EvaluateDependentExpr` is when we are in an error condition, so I'm convinced 
the fix 'as is' is incorrect.  The check for noteSideEffect records that we 
HAVE a side effect, then returns if we are OK ignoring them right now.

So since we are in a state where ignoring this error-case is acceptable, I 
think returning early there is incorrect as well, at least from a 'code 
correctness' (even if there isn't a reproducer that would matter?).  I think 
we're in a case where we want to continue in order to ensure we go through the 
entire flow, so I THINK we should treat this as 'we have a value we don't know, 
so its just not found', and should fall into the check on 5019 (unless of 
course, there is a 'default' option!).

So I think that we should be checking if `Value` is valid right after the 
default check, which lets us fall into the 'default' branch and get additional 
diagnostics/continued evaluation.  WDYT @shafik / @yronglin ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153296/new/

https://reviews.llvm.org/D153296

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153294: [clang] Do not create ExprWithCleanups while checking immediate invocation

2023-06-23 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D153294#065 , @Fznamznon wrote:

>> While we wait for Richard's response... @Fznamznon what are your thoughts on 
>> wrapping all ConstantExpr that span immediate invocations with redundant 
>> ExprWithCleanups per Richard's suggestions?
>> This bug looks scary enough to me to warrant a fix asap.
>
> Agree. I was thinking of implementing Richard's suggestions in a separate 
> review for some time. I'll do that.

Many thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153294/new/

https://reviews.llvm.org/D153294

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147732: [AMDGPU] Add type mangling for {read, write, readfirst, perm}lane intrinsics

2023-06-23 Thread Jeffrey Byrnes via Phabricator via cfe-commits
jrbyrnes added a comment.

In D147732#4434557 , @arsenm wrote:

> I think this may not hard break mesa. I believe mesa bypasses the intrinsic 
> creation API, and just declares the string name of the intrinsic. The type 
> name mangling suffix is technically irrelevant, and as long as you use a 
> consistent type with a consistent suffix things should work out (and the null 
> suffix also works). After committing mesa should still move to adding the 
> type suffix

I can echo this sentiment.

The main issues arises when there are untyped calls to CreateIntrinsic, as the 
intrinsics are no longer defined with a type.

For {read, readfirst, write, perm}lanes, Mesa uses LLVMAddFunction and 
LLVMBuildCall2 APIs under its own ac_build_intrinsic -- these calls are all 
typed in the current implementation. Also, (as expected) the implementation 
inserts bitcasts to cast to Int32Ty before inserting these calls since only 
that version of the intrinsic currently exists. This also implies they wont 
have an issue with intrinsic / type declarations.

Unless I have missed something, I don't see why switching to type-mangling 
would cause an issue with Mesa's current implementation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147732/new/

https://reviews.llvm.org/D147732

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153649: [clang][Interp] Fix return statements with expresssion in void functions

2023-06-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  If the return type of a function is void, ReturnType is not set, but we
  used to emit a RVOPtr instruction, which doesn't make sense for a
  function returning void.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153649

Files:
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/test/AST/Interp/functions.cpp


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -265,3 +265,12 @@
 g(0);
   }
 }
+
+namespace VoidReturn {
+  /// ReturnStmt with an expression in a void function used to cause problems.
+  constexpr void bar() {}
+  constexpr void foo() {
+return bar();
+  }
+  static_assert((foo(),1) == 1);
+}
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -309,6 +309,9 @@
 return false;
   this->emitCleanup();
   return this->emitRet(*ReturnType, RS);
+} else if (RE->getType()->isVoidType()) {
+  if (!this->visit(RE))
+return false;
 } else {
   // RVO - construct the value in the return location.
   if (!this->emitRVOPtr(RE))


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -265,3 +265,12 @@
 g(0);
   }
 }
+
+namespace VoidReturn {
+  /// ReturnStmt with an expression in a void function used to cause problems.
+  constexpr void bar() {}
+  constexpr void foo() {
+return bar();
+  }
+  static_assert((foo(),1) == 1);
+}
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -309,6 +309,9 @@
 return false;
   this->emitCleanup();
   return this->emitRet(*ReturnType, RS);
+} else if (RE->getType()->isVoidType()) {
+  if (!this->visit(RE))
+return false;
 } else {
   // RVO - construct the value in the return location.
   if (!this->emitRVOPtr(RE))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153370: [RISCV] Add support for custom instructions for Sifive S76.

2023-06-23 Thread garvit gupta via Phabricator via cfe-commits
garvitgupta08 updated this revision to Diff 534018.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153370/new/

https://reviews.llvm.org/D153370

Files:
  clang/test/Driver/riscv-cpus.c
  llvm/docs/RISCVUsage.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td
  llvm/lib/Target/RISCV/RISCVProcessors.td
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/xsfcie-invalid.s
  llvm/test/MC/RISCV/xsfcie-valid.s

Index: llvm/test/MC/RISCV/xsfcie-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/xsfcie-valid.s
@@ -0,0 +1,42 @@
+# SCIE - SiFive Custom Instructions Extension.
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+xsfcie -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+xsfcie -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+xsfcie < %s \
+# RUN: | llvm-objdump --mattr=+xsfcie -M no-aliases -d - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+xsfcie < %s \
+# RUN: | llvm-objdump --mattr=+xsfcie -M no-aliases -d - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv64 -mcpu=sifive-s76 -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mcpu=sifive-s76 < %s \
+# RUN: | llvm-objdump --mcpu=sifive-s76 -M no-aliases -d - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+
+# CHECK-INST: cflush.d.l1 zero
+# CHECK-ENC: encoding: [0x73,0x00,0x00,0xfc]
+# CHECK-INST: cflush.d.l1 zero
+# CHECK-ENC: encoding: [0x73,0x00,0x00,0xfc]
+cflush.d.l1 x0
+cflush.d.l1
+
+# CHECK-INST: cflush.d.l1 t2
+# CHECK-ENC: encoding: [0x73,0x80,0x03,0xfc]
+cflush.d.l1 x7
+
+# CHECK-INST: cdiscard.d.l1   zero
+# CHECK-ENC: encoding: [0x73,0x00,0x20,0xfc]
+# CHECK-INST: cdiscard.d.l1 zero
+# CHECK-ENC: encoding: [0x73,0x00,0x20,0xfc]
+cdiscard.d.l1 x0
+cdiscard.d.l1
+
+# CHECK-INST: cdiscard.d.l1   t2
+# CHECK-ENC: encoding: [0x73,0x80,0x23,0xfc]
+cdiscard.d.l1 x7
+
+# CHECK-INST: cease
+# CHECK-ENC: encoding: [0x73,0x00,0x50,0x30]
+cease
Index: llvm/test/MC/RISCV/xsfcie-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/xsfcie-invalid.s
@@ -0,0 +1,25 @@
+# SCIE - SiFive Custom Instructions Extension.
+# RUN: not llvm-mc -triple riscv32 -mattr=-xsfcie < %s 2>&1 | FileCheck %s
+# RUN: not llvm-mc -triple riscv64 -mattr=-xsfcie < %s 2>&1 | FileCheck %s
+
+cflush.d.l1 0x10 # CHECK: :[[@LINE]]:13: error: invalid operand for instruction
+
+cdiscard.d.l1 0x10 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction
+
+cflush.d.l1 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
+
+cdiscard.d.l1 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
+
+cflush.d.l1 x0 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
+
+cflush.d.l1 x7 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
+
+cdiscard.d.l1 x0 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
+
+cdiscard.d.l1 x7 # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
+
+cease x1 # CHECK: :[[@LINE]]:7: error: invalid operand for instruction
+
+cease 0x10 # CHECK: :[[@LINE]]:7: error: invalid operand for instruction
+
+cease # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'XSfcie' (SiFive Custom Instruction Extension SCIE.)
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -278,3 +278,6 @@
 
 .attribute arch, "rv32i_zvfbfwma0p6"
 # CHECK: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zve32f1p0_zve32x1p0_zvfbfwma0p6_zvl32b1p0"
+
+.attribute arch, "rv64i_xsfcie"
+# CHECK: attribute  5, "rv64i2p1_xsfcie1p0"
Index: llvm/lib/Target/RISCV/RISCVProcessors.td
===
--- llvm/lib/Target/RISCV/RISCVProcessors.td
+++ llvm/lib/Target/RISCV/RISCVProcessors.td
@@ -142,7 +142,9 @@
   FeatureStdExtA,
   FeatureStdExtF,
   FeatureStdExtD,
-

[PATCH] D153649: [clang][Interp] Fix return statements with expresssion in void functions

2023-06-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 534021.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153649/new/

https://reviews.llvm.org/D153649

Files:
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/test/AST/Interp/functions.cpp


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -265,3 +265,12 @@
 g(0);
   }
 }
+
+namespace VoidReturn {
+  /// ReturnStmt with an expression in a void function used to cause problems.
+  constexpr void bar() {}
+  constexpr void foo() {
+return bar();
+  }
+  static_assert((foo(),1) == 1, "");
+}
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -309,6 +309,9 @@
 return false;
   this->emitCleanup();
   return this->emitRet(*ReturnType, RS);
+} else if (RE->getType()->isVoidType()) {
+  if (!this->visit(RE))
+return false;
 } else {
   // RVO - construct the value in the return location.
   if (!this->emitRVOPtr(RE))


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -265,3 +265,12 @@
 g(0);
   }
 }
+
+namespace VoidReturn {
+  /// ReturnStmt with an expression in a void function used to cause problems.
+  constexpr void bar() {}
+  constexpr void foo() {
+return bar();
+  }
+  static_assert((foo(),1) == 1, "");
+}
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -309,6 +309,9 @@
 return false;
   this->emitCleanup();
   return this->emitRet(*ReturnType, RS);
+} else if (RE->getType()->isVoidType()) {
+  if (!this->visit(RE))
+return false;
 } else {
   // RVO - construct the value in the return location.
   if (!this->emitRVOPtr(RE))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153652: [llvm][Support] Don'tt set "all_exe" mode by default for file written by llvm::writeToOutput.

2023-06-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: avl.
Herald added a subscriber: hiraditya.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153652

Files:
  llvm/lib/Support/raw_ostream.cpp


Index: llvm/lib/Support/raw_ostream.cpp
===
--- llvm/lib/Support/raw_ostream.cpp
+++ llvm/lib/Support/raw_ostream.cpp
@@ -1007,7 +1007,7 @@
 return Write(Out);
   }
 
-  unsigned Mode = sys::fs::all_read | sys::fs::all_write | sys::fs::all_exe;
+  unsigned Mode = sys::fs::all_read | sys::fs::all_write;
   Expected Temp =
   sys::fs::TempFile::create(OutputFileName + ".temp-stream-%%", Mode);
   if (!Temp)


Index: llvm/lib/Support/raw_ostream.cpp
===
--- llvm/lib/Support/raw_ostream.cpp
+++ llvm/lib/Support/raw_ostream.cpp
@@ -1007,7 +1007,7 @@
 return Write(Out);
   }
 
-  unsigned Mode = sys::fs::all_read | sys::fs::all_write | sys::fs::all_exe;
+  unsigned Mode = sys::fs::all_read | sys::fs::all_write;
   Expected Temp =
   sys::fs::TempFile::create(OutputFileName + ".temp-stream-%%", Mode);
   if (!Temp)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153228: [clang-format] Fixed bad performance with enabled qualifier fixer.

2023-06-23 Thread Sedenion via Phabricator via cfe-commits
Sedeniono updated this revision to Diff 534024.
Sedeniono added a comment.

As suggested by the reviewers, the noop fixes are now filtered only if the 
qualifier alignment passes are active. Also implemented the other minor 
refactorings.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153228/new/

https://reviews.llvm.org/D153228

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -1016,8 +1016,8 @@
   std::vector Left;
   std::vector Right;
   std::vector ConfiguredTokens;
-  QualifierAlignmentFixer::PrepareLeftRightOrdering(Style.QualifierOrder, Left,
-Right, ConfiguredTokens);
+  prepareLeftRightOrderingForQualifierAlignmentFixer(Style.QualifierOrder, Left,
+ Right, ConfiguredTokens);
 
   EXPECT_EQ(Left.size(), (size_t)2);
   EXPECT_EQ(Right.size(), (size_t)2);
@@ -1181,10 +1181,12 @@
   Style.QualifierAlignment = FormatStyle::QAS_Custom;
   Style.QualifierOrder = {"static", "const", "type"};
 
-  ReplacementCount = 0;
-  EXPECT_EQ(ReplacementCount, 0);
   verifyFormat("static const uint32 foo[] = {0, 31};", Style);
+  EXPECT_EQ(ReplacementCount, 0);
+
   verifyFormat("#define MACRO static const", Style);
+  EXPECT_EQ(ReplacementCount, 0);
+
   verifyFormat("using sc = static const", Style);
   EXPECT_EQ(ReplacementCount, 0);
 }
Index: clang/lib/Format/QualifierAlignmentFixer.h
===
--- clang/lib/Format/QualifierAlignmentFixer.h
+++ clang/lib/Format/QualifierAlignmentFixer.h
@@ -25,32 +25,13 @@
 const Environment &)>
 AnalyzerPass;
 
-class QualifierAlignmentFixer : public TokenAnalyzer {
-  // Left to Right ordering requires multiple passes
-  SmallVector Passes;
-  StringRef &Code;
-  ArrayRef Ranges;
-  unsigned FirstStartColumn;
-  unsigned NextStartColumn;
-  unsigned LastStartColumn;
-  StringRef FileName;
+void addQualifierAlignmentFixerPasses(const FormatStyle &Style,
+  SmallVectorImpl &Passes);
 
-public:
-  QualifierAlignmentFixer(const Environment &Env, const FormatStyle &Style,
-  StringRef &Code, ArrayRef Ranges,
-  unsigned FirstStartColumn, unsigned NextStartColumn,
-  unsigned LastStartColumn, StringRef FileName);
-
-  std::pair
-  analyze(TokenAnnotator &Annotator,
-  SmallVectorImpl &AnnotatedLines,
-  FormatTokenLexer &Tokens) override;
-
-  static void PrepareLeftRightOrdering(const std::vector &Order,
-   std::vector &LeftOrder,
-   std::vector &RightOrder,
-   std::vector &Qualifiers);
-};
+void prepareLeftRightOrderingForQualifierAlignmentFixer(
+const std::vector &Order, std::vector &LeftOrder,
+std::vector &RightOrder,
+std::vector &Qualifiers);
 
 class LeftRightQualifierAlignmentFixer : public TokenAnalyzer {
   std::string Qualifier;
Index: clang/lib/Format/QualifierAlignmentFixer.cpp
===
--- clang/lib/Format/QualifierAlignmentFixer.cpp
+++ clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -25,18 +25,13 @@
 namespace clang {
 namespace format {
 
-QualifierAlignmentFixer::QualifierAlignmentFixer(
-const Environment &Env, const FormatStyle &Style, StringRef &Code,
-ArrayRef Ranges, unsigned FirstStartColumn,
-unsigned NextStartColumn, unsigned LastStartColumn, StringRef FileName)
-: TokenAnalyzer(Env, Style), Code(Code), Ranges(Ranges),
-  FirstStartColumn(FirstStartColumn), NextStartColumn(NextStartColumn),
-  LastStartColumn(LastStartColumn), FileName(FileName) {
+void addQualifierAlignmentFixerPasses(const FormatStyle &Style,
+  SmallVectorImpl &Passes) {
   std::vector LeftOrder;
   std::vector RightOrder;
   std::vector ConfiguredQualifierTokens;
-  PrepareLeftRightOrdering(Style.QualifierOrder, LeftOrder, RightOrder,
-   ConfiguredQualifierTokens);
+  prepareLeftRightOrderingForQualifierAlignmentFixer(
+  Style.QualifierOrder, LeftOrder, RightOrder, ConfiguredQualifierTokens);
 
   // Handle the left and right alignment separately.
   for (const auto &Qualifier : LeftOrder) {
@@ -59,51 +54,6 @@
   }
 }
 
-std::pair QualifierAlignmentFixer::analyze(
-TokenAnnotator & /*Annotator*/,
-SmallVectorImpl & /*AnnotatedLines*/,
-FormatTokenLexer & /*Tokens*/) {
-  auto Env = Environment::make(Code, FileName, Ranges, 

[PATCH] D153228: [clang-format] Fixed bad performance with enabled qualifier fixer.

2023-06-23 Thread Sedenion via Phabricator via cfe-commits
Sedeniono marked 6 inline comments as done.
Sedeniono added inline comments.



Comment at: clang/lib/Format/Format.cpp:3476-3477
+
+  // Regarding the 16: Note that multiple passes are added in
+  // addQualifierAlignmentFixerPasses().
+  SmallVector Passes;

HazardyKnusperkeks wrote:
> owenpan wrote:
> > This comment is unnecessary and too verbose IMO. I suggest that it be 
> > deleted.
> > This comment is unnecessary and too verbose IMO. I suggest that it be 
> > deleted.
> 
> I think one should note that there are more passes added than directly meets 
> the eye here.
After looking at the code again, I decided to remove the comment. I think the 
"structure" of the code below that adds the passes already highlights that 
there is something "special" going on with the qualifier alignment passes, 
since they aren't added via a lambda.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153228/new/

https://reviews.llvm.org/D153228

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61670: [RFC] [MinGW] Allow opting out from .refptr stubs

2023-06-23 Thread Alex Henrie via Phabricator via cfe-commits
alexhenrie added a comment.
Herald added a project: All.

Any update on this? The Wine project would like to omit the refptr symbols, see 
https://gitlab.winehq.org/wine/wine/-/merge_requests/3109


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61670/new/

https://reviews.llvm.org/D61670

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151047: [clang-format] Fix indentation for selective formatting.

2023-06-23 Thread Sedenion via Phabricator via cfe-commits
Sedeniono marked an inline comment as done.
Sedeniono added a comment.

@owenpan , @MyDeveloperDay Any opinion on the latest changes? 
Otherwise, since I do not have commit rights, someone needs to commit the 
changes to main (my name and mail: `Sedenion 
<39583823+sedeni...@users.noreply.github.com>`). Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151047/new/

https://reviews.llvm.org/D151047

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153510: [Clang] Check type support for local variable declaration

2023-06-23 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 534025.
eopXD added a comment.

Rebase to latest main.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153510/new/

https://reviews.llvm.org/D153510

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/riscv-types.c
  clang/test/Sema/riscv-vector-float16-check.c
  clang/test/Sema/riscv-vector-float32-check.c
  clang/test/Sema/riscv-vector-float64-check.c
  clang/test/Sema/riscv-vector-int64-check.c

Index: clang/test/Sema/riscv-vector-int64-check.c
===
--- clang/test/Sema/riscv-vector-int64-check.c
+++ clang/test/Sema/riscv-vector-int64-check.c
@@ -6,3 +6,9 @@
 
 vint64m1_t foo() { /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vint64m1_t i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+
+  (void)i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+}
Index: clang/test/Sema/riscv-vector-float64-check.c
===
--- clang/test/Sema/riscv-vector-float64-check.c
+++ clang/test/Sema/riscv-vector-float64-check.c
@@ -6,3 +6,9 @@
 
 vfloat64m1_t foo() { /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vfloat64m1_t f64m1; /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
+
+  (void)f64m1; /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
+}
Index: clang/test/Sema/riscv-vector-float32-check.c
===
--- clang/test/Sema/riscv-vector-float32-check.c
+++ clang/test/Sema/riscv-vector-float32-check.c
@@ -6,3 +6,9 @@
 
 vfloat32m1_t foo() { /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vfloat32m1_t f32m1; /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
+
+  (void)f32m1; /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
+}
Index: clang/test/Sema/riscv-vector-float16-check.c
===
--- clang/test/Sema/riscv-vector-float16-check.c
+++ clang/test/Sema/riscv-vector-float16-check.c
@@ -6,3 +6,9 @@
 
 vfloat16m1_t foo() { /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vfloat16m1_t f16m1; /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
+
+  (void)f16m1; /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
+}
Index: clang/test/Sema/riscv-types.c
===
--- clang/test/Sema/riscv-types.c
+++ clang/test/Sema/riscv-types.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple riscv64 -target-feature +v -ast-print %s \
-// RUN:| FileCheck %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v \
+// RUN: -target-feature +experimental-zvfh -ast-print %s | FileCheck %s
 
 void bar(void) {
   // CHECK: __rvv_int64m1_t x0;
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -8777,6 +8777,8 @@
   return;
 }
   }
+  if (T->isRVVType())
+checkRVVTypeSupport(T, NewVD->getLocation(), cast(CurContext));
 }
 
 /// Perform semantic checking on a newly-created variable
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4964,6 +4964,22 @@
   return false;
 }
 
+void Sema::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
+  const TargetInfo &TI = Context.getTargetInfo();
+  if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ false) &&
+  !TI.hasFeature("zve64x"))
+Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64x";
+  if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ true) &&
+  !TI.hasFeature("experimental-zvfh"))
+Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zvf

[PATCH] D153653: [clang][Interp] Make CXXTemporaryObjectExprs leave a value behind

2023-06-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  visitLocalInitializer() pops the pointer from the stack again, but we
  might be called in a situation where the caller would actually like to
  use the value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153653

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -880,3 +880,13 @@
   }
 }
 
+namespace TemporaryObjectExpr {
+  struct F {
+int a;
+constexpr F() : a(12) {}
+  };
+  constexpr int foo(F f) {
+return 0;
+  }
+  static_assert(foo(F()) == 0, "");
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1011,10 +1011,17 @@
 template 
 bool ByteCodeExprGen::VisitCXXTemporaryObjectExpr(
 const CXXTemporaryObjectExpr *E) {
-
   if (std::optional LocalIndex =
   allocateLocal(E, /*IsExtended=*/false)) {
-return this->visitLocalInitializer(E, *LocalIndex);
+if (!this->emitGetPtrLocal(*LocalIndex, E))
+  return false;
+
+if (!this->visitInitializer(E))
+  return false;
+
+if (DiscardResult)
+  return this->emitPopPtr(E);
+return true;
   }
   return false;
 }


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -880,3 +880,13 @@
   }
 }
 
+namespace TemporaryObjectExpr {
+  struct F {
+int a;
+constexpr F() : a(12) {}
+  };
+  constexpr int foo(F f) {
+return 0;
+  }
+  static_assert(foo(F()) == 0, "");
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1011,10 +1011,17 @@
 template 
 bool ByteCodeExprGen::VisitCXXTemporaryObjectExpr(
 const CXXTemporaryObjectExpr *E) {
-
   if (std::optional LocalIndex =
   allocateLocal(E, /*IsExtended=*/false)) {
-return this->visitLocalInitializer(E, *LocalIndex);
+if (!this->emitGetPtrLocal(*LocalIndex, E))
+  return false;
+
+if (!this->visitInitializer(E))
+  return false;
+
+if (DiscardResult)
+  return this->emitPopPtr(E);
+return true;
   }
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153370: [RISCV] Add support for custom instructions for Sifive S76.

2023-06-23 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/docs/ReleaseNotes.rst:209
   disassembler/assembler.
+* Added support for the vendor-defined Xsfcie (SiFive SCIE) extension
+  disassembler/assembler.

SCIE->CIE since the S already stands for SiFive.



Comment at: llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp:562
+TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfcie, DecoderTableXSfcie32,
+  "SCIE custom opcode table");
 TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXCVbitmanip,

SCIE -> SiFive CIE


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153370/new/

https://reviews.llvm.org/D153370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144911: adding bf16 support to NVPTX

2023-06-23 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

The latest patch revision still fails on a few LLVM tests:

  Failed Tests (3):
LLVM :: CodeGen/NVPTX/bf16-instructions.ll
LLVM :: CodeGen/NVPTX/f16x2-instructions.ll
LLVM :: CodeGen/NVPTX/math-intrins-sm80-ptx70.ll




Comment at: llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp:1308
 return TypeSplitVector;
-  if (VT == MVT::v2f16)
+  if (Isv2f16Orv2bf16Type((EVT)VT))
 return TypeLegal;

I do not think the cast is necessary. 




Comment at: llvm/lib/Target/NVPTX/NVPTXInstrInfo.td:595-596
 FromName, ".f16 \t$dst, $src;"), []>;
+def _bf16 :
+  NVPTXInst<(outs RC:$dst),
+(ins Int16Regs:$src, CvtMode:$mode),

tra wrote:
> While we're here, it also needs `Requires<[hasPTX<70>, hasSM<80>]>`
This is needed in *addition* to whatever predicate is supplied as an argument. 
E.g. when we do `defm CVT_f32 : CVT_FROM_ALL<"f32", Float32Regs>;` conversion 
from f32 to bf16 should still be predicated on `[hasPTX<70>, hasSM<80>]`.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144911/new/

https://reviews.llvm.org/D144911

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153298: [clang-tidy] Extend bugprone-exception-escape diagnostics

2023-06-23 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp:390
   for (const Type *T : TypesToDelete)
-ThrownExceptions.erase(T);
+ThrownExceptions.erase({T, SourceLocation()});
 

PiotrZSL wrote:
> isuckatcs wrote:
> > This line makes me wonder if it's worth using a `map` instead of a `set` 
> > for `ThrownExceptions`. You could map the type to the location. I mean 
> > technically, that happens now too, but not with the appropriate data 
> > structure. 
> > 
> > Also I wonder what happens if a function can throw the same type from 
> > multiple locations. E.g.:
> > ```lang=c++
> > void foo(int x) {
> >   if(x == 0) 
> > throw 1;
> >   
> >   if(x == 1)
> > throw 2;
> > }
> > ```
> > Here only the last location will be preserved, so maybe mapping `Type` to 
> > `vector` would be better.
> We use llvm::SmallSet, but there is no llvm::SmallMap. I wanted to preserve 
> memory optimizations, as using some map could hit performance, after all we 
> create many of those temporary containers.
> And with map I run into some issues (it didn't like const pointer as key).
> 
> As for double throw of same type. I agree, but I don't think its worth being 
> implemented currently.
> Once user remove one exception, check will show second. Many checks work like 
> that.
> This is just to provide small hint.
I still feel like creating these `{T, SourceLocation()}` entries is bloated. In 
case of a map, you wouldn't need to create dummy `SourceLocation`s. 

We have `DenseMap`, which is documented like this:
> DenseMap is a simple quadratically probed hash table. It excels at supporting 
> small keys and values: [...] DenseMap is a great way to map pointers to 
> pointers, or map other small types to each other.

Here you would map pointers to `SourceLocation`s, which are basically `int`s, 
so they are smaller than pointers. I think it worths giving `DenseMap` a try.

Also note that the number of exceptions we store is very low, so even 
`std::map<>` wouldn't cause a significant performance loss. Also currently our 
`SmallSet<>` is set to 2 elements, which means if we store more than 2 
elements, it will switch to `std::set<>` instead. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153298/new/

https://reviews.llvm.org/D153298

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153298: [clang-tidy] Extend bugprone-exception-escape diagnostics

2023-06-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp:390
   for (const Type *T : TypesToDelete)
-ThrownExceptions.erase(T);
+ThrownExceptions.erase({T, SourceLocation()});
 

isuckatcs wrote:
> PiotrZSL wrote:
> > isuckatcs wrote:
> > > This line makes me wonder if it's worth using a `map` instead of a `set` 
> > > for `ThrownExceptions`. You could map the type to the location. I mean 
> > > technically, that happens now too, but not with the appropriate data 
> > > structure. 
> > > 
> > > Also I wonder what happens if a function can throw the same type from 
> > > multiple locations. E.g.:
> > > ```lang=c++
> > > void foo(int x) {
> > >   if(x == 0) 
> > > throw 1;
> > >   
> > >   if(x == 1)
> > > throw 2;
> > > }
> > > ```
> > > Here only the last location will be preserved, so maybe mapping `Type` to 
> > > `vector` would be better.
> > We use llvm::SmallSet, but there is no llvm::SmallMap. I wanted to preserve 
> > memory optimizations, as using some map could hit performance, after all we 
> > create many of those temporary containers.
> > And with map I run into some issues (it didn't like const pointer as key).
> > 
> > As for double throw of same type. I agree, but I don't think its worth 
> > being implemented currently.
> > Once user remove one exception, check will show second. Many checks work 
> > like that.
> > This is just to provide small hint.
> I still feel like creating these `{T, SourceLocation()}` entries is bloated. 
> In case of a map, you wouldn't need to create dummy `SourceLocation`s. 
> 
> We have `DenseMap`, which is documented like this:
> > DenseMap is a simple quadratically probed hash table. It excels at 
> > supporting small keys and values: [...] DenseMap is a great way to map 
> > pointers to pointers, or map other small types to each other.
> 
> Here you would map pointers to `SourceLocation`s, which are basically `int`s, 
> so they are smaller than pointers. I think it worths giving `DenseMap` a try.
> 
> Also note that the number of exceptions we store is very low, so even 
> `std::map<>` wouldn't cause a significant performance loss. Also currently 
> our `SmallSet<>` is set to 2 elements, which means if we store more than 2 
> elements, it will switch to `std::set<>` instead. 
For SourceLocation{}, I can add constructors to ThrowInfo to hide it, but 
that's also not elegant solution.
Thing is that llvm::SmallSet here wont allocate memory for up to 2 elements, 
this mean no memory allocation and so on.
And because on every function we basically doing a copy of this container, or 
we create new one, then allocating memory with DenseMap could be potentially 
costly (allocate 64 elements).
I also run into compilation issues when using const Type* as a key for a 
DenseMap (yes I tried it before I choose this solution).
If we talk about std::map, well, that is a better option, as it's not allocate 
memory by default.
I can give it a try...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153298/new/

https://reviews.llvm.org/D153298

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 62fa708 - [RISCV] Implement KCFI operand bundle lowering

2023-06-23 Thread Sami Tolvanen via cfe-commits

Author: Sami Tolvanen
Date: 2023-06-23T18:25:24Z
New Revision: 62fa708ceb027713b386c7e0efda994f8bdc27e2

URL: 
https://github.com/llvm/llvm-project/commit/62fa708ceb027713b386c7e0efda994f8bdc27e2
DIFF: 
https://github.com/llvm/llvm-project/commit/62fa708ceb027713b386c7e0efda994f8bdc27e2.diff

LOG: [RISCV] Implement KCFI operand bundle lowering

With `-fsanitize=kcfi` (Kernel Control-Flow Integrity), Clang emits
"kcfi" operand bundles to indirect call instructions. Similarly to
the target-specific lowering added in D119296, implement KCFI operand
bundle lowering for RISC-V.

This patch disables the generic KCFI pass for RISC-V in Clang, and
adds the KCFI machine function pass in `RISCVPassConfig::addPreSched`
to emit target-specific `KCFI_CHECK` pseudo instructions before calls
that have KCFI operand bundles. The machine function pass also bundles
the instructions to ensure we emit the checks immediately before the
calls, which is not possible with the generic pass.

`KCFI_CHECK` instructions are lowered in `RISCVAsmPrinter` to a
contiguous code sequence that traps if the expected hash in the
operand bundle doesn't match the hash before the target function
address. This patch emits an `ebreak` instruction for error handling
to match the Linux kernel's `BUG()` implementation. Just like for X86,
we also emit trap locations to a `.kcfi_traps` section to support
error handling, as we cannot embed additional information to the trap
instruction itself.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D148385

Added: 
llvm/test/CodeGen/RISCV/kcfi-isel.mir
llvm/test/CodeGen/RISCV/kcfi-patchable-function-prefix.ll
llvm/test/CodeGen/RISCV/kcfi.ll
llvm/test/CodeGen/RISCV/kcfi.mir

Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.h
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
llvm/lib/Target/RISCV/RISCVInstrInfo.h
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
llvm/test/CodeGen/RISCV/O0-pipeline.ll
llvm/test/CodeGen/RISCV/O3-pipeline.ll

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index f7a174a5fe462..d00c5654a190c 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -631,7 +631,7 @@ static void addKCFIPass(const Triple &TargetTriple, const 
LangOptions &LangOpts,
 PassBuilder &PB) {
   // If the back-end supports KCFI operand bundle lowering, skip KCFIPass.
   if (TargetTriple.getArch() == llvm::Triple::x86_64 ||
-  TargetTriple.isAArch64(64))
+  TargetTriple.isAArch64(64) || TargetTriple.isRISCV())
 return;
 
   // Ensure we lower KCFI operand bundles with -O0.

diff  --git a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp 
b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
index 9f4d363f83ef2..f7d11e921c7de 100644
--- a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
+++ b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
@@ -19,6 +19,7 @@
 #include "RISCVMachineFunctionInfo.h"
 #include "RISCVTargetMachine.h"
 #include "TargetInfo/RISCVTargetInfo.h"
+#include "llvm/ADT/APInt.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/CodeGen/AsmPrinter.h"
@@ -72,6 +73,7 @@ class RISCVAsmPrinter : public AsmPrinter {
   typedef std::tuple HwasanMemaccessTuple;
   std::map HwasanMemaccessSymbols;
   void LowerHWASAN_CHECK_MEMACCESS(const MachineInstr &MI);
+  void LowerKCFI_CHECK(const MachineInstr &MI);
   void EmitHwasanMemaccessSymbols(Module &M);
 
   // Wrapper needed for tblgenned pseudo lowering.
@@ -150,6 +152,9 @@ void RISCVAsmPrinter::emitInstruction(const MachineInstr 
*MI) {
   case RISCV::HWASAN_CHECK_MEMACCESS_SHORTGRANULES:
 LowerHWASAN_CHECK_MEMACCESS(*MI);
 return;
+  case RISCV::KCFI_CHECK:
+LowerKCFI_CHECK(*MI);
+return;
   case RISCV::PseudoRVVInitUndefM1:
   case RISCV::PseudoRVVInitUndefM2:
   case RISCV::PseudoRVVInitUndefM4:
@@ -305,6 +310,92 @@ void RISCVAsmPrinter::LowerHWASAN_CHECK_MEMACCESS(const 
MachineInstr &MI) {
   EmitToStreamer(*OutStreamer, MCInstBuilder(RISCV::PseudoCALL).addExpr(Expr));
 }
 
+void RISCVAsmPrinter::LowerKCFI_CHECK(const MachineInstr &MI) {
+  Register AddrReg = MI.getOperand(0).getReg();
+  assert(std::next(MI.getIterator())->isCall() &&
+ "KCFI_CHECK not followed by a call instruction");
+  assert(std::next(MI.getIterator())->getOperand(0).getReg() == AddrReg &&
+ "KCFI_CHECK call target doesn't match call operand");
+
+  // Temporary registers for comparing the hashes. If a register is used
+  // for the call target, or reserved by the user, we can clobber another
+  // temporary register as the check is immediately followed by the
+  // call. The check defaults to X6/X7, but can fall back t

[PATCH] D148385: [RISCV] Implement KCFI operand bundle lowering

2023-06-23 Thread Sami Tolvanen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG62fa708ceb02: [RISCV] Implement KCFI operand bundle lowering 
(authored by samitolvanen).
Herald added a subscriber: wangpc.

Changed prior to commit:
  https://reviews.llvm.org/D148385?vs=531476&id=534032#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148385/new/

https://reviews.llvm.org/D148385

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfo.h
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
  llvm/test/CodeGen/RISCV/O0-pipeline.ll
  llvm/test/CodeGen/RISCV/O3-pipeline.ll
  llvm/test/CodeGen/RISCV/kcfi-isel.mir
  llvm/test/CodeGen/RISCV/kcfi-patchable-function-prefix.ll
  llvm/test/CodeGen/RISCV/kcfi.ll
  llvm/test/CodeGen/RISCV/kcfi.mir

Index: llvm/test/CodeGen/RISCV/kcfi.mir
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/kcfi.mir
@@ -0,0 +1,185 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2
+# RUN: llc -mtriple=riscv64 -stop-after=kcfi -o - %s | FileCheck %s
+--- |
+  ; ModuleID = ''
+  source_filename = ""
+  target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
+  target triple = "riscv64"
+
+  define void @f1(ptr noundef %x) !kcfi_type !1 {
+call void %x() [ "kcfi"(i32 12345678) ]
+ret void
+  }
+
+  define void @f2(ptr noundef %x) #0 {
+tail call void %x() [ "kcfi"(i32 12345678) ]
+ret void
+  }
+
+  attributes #0 = { "patchable-function-entry"="2" }
+
+  !llvm.module.flags = !{!0}
+
+  !0 = !{i32 4, !"kcfi", i32 1}
+  !1 = !{i32 12345678}
+
+...
+---
+name:f1
+alignment:   4
+exposesReturnsTwice: false
+legalized:   false
+regBankSelected: false
+selected:false
+failedISel:  false
+tracksRegLiveness: true
+hasWinCFI:   false
+callsEHReturn:   false
+callsUnwindInit: false
+hasEHCatchret:   false
+hasEHScopes: false
+hasEHFunclets:   false
+isOutlined:  false
+debugInstrRef:   false
+failsVerification: false
+tracksDebugUserValues: true
+registers:   []
+liveins:
+  - { reg: '$x10', virtual-reg: '' }
+frameInfo:
+  isFrameAddressTaken: false
+  isReturnAddressTaken: false
+  hasStackMap: false
+  hasPatchPoint:   false
+  stackSize:   16
+  offsetAdjustment: 0
+  maxAlignment:8
+  adjustsStack:true
+  hasCalls:true
+  stackProtector:  ''
+  functionContext: ''
+  maxCallFrameSize: 0
+  cvBytesOfCalleeSavedRegisters: 0
+  hasOpaqueSPAdjustment: false
+  hasVAStart:  false
+  hasMustTailInVarArgFunc: false
+  hasTailCall: false
+  localFrameSize:  0
+  savePoint:   ''
+  restorePoint:''
+fixedStack:  []
+stack:
+  - { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
+  stack-id: default, callee-saved-register: '$x1', callee-saved-restored: true,
+  debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+callSites:   []
+debugValueSubstitutions: []
+constants:   []
+machineFunctionInfo:
+  varArgsFrameIndex: 0
+  varArgsSaveSize: 0
+body: |
+  bb.0 (%ir-block.0):
+liveins: $x10, $x1
+
+; CHECK-LABEL: name: f1
+; CHECK: liveins: $x1, $x10
+; CHECK-NEXT: {{  $}}
+; CHECK-NEXT: $x2 = frame-setup ADDI $x2, -16
+; CHECK-NEXT: frame-setup CFI_INSTRUCTION def_cfa_offset 16
+; CHECK-NEXT: SD $x1, $x2, 8 :: (store (s64) into %stack.1)
+; CHECK-NEXT: frame-setup CFI_INSTRUCTION offset $x1, -8
+; CHECK-NEXT: $x2 = frame-setup ADDI $x2, -16
+; CHECK-NEXT: frame-setup CFI_INSTRUCTION def_cfa_offset 16
+; CHECK-NEXT: SD $x1, $x2, 8 :: (store (s64) into %stack.0)
+; CHECK-NEXT: frame-setup CFI_INSTRUCTION offset $x1, -8
+; CHECK-NEXT: BUNDLE implicit-def dead $x6, implicit-def dead $x7, implicit-def dead $x28, implicit-def dead $x29, implicit-def dead $x30, implicit-def dead $x31, implicit-def dead $x1, implicit-def $x2, implicit $x10 {
+; CHECK-NEXT:   KCFI_CHECK $x10, 12345678, implicit-def $x6, implicit-def $x7, implicit-def $x28, implicit-def $x29, implicit-def $x30, implicit-def $x31
+; CHECK-NEXT:   PseudoCALLIndirect $x10, csr_ilp32_lp64, implicit-def dead $x1, implicit-def $x2
+; CHECK-NEXT: }
+; CHECK-NEXT: dead $x1 = LD $x2, 8 :: (load (s64) from %stack.0)
+; CHECK-NEXT: $x2 = frame-destroy ADDI $x2, 16
+; CHECK-NEXT: $x1 = LD $x2, 8 :: (load (s64) from %stack.1)
+; CHECK-NEXT: $x2 = frame-destroy ADDI $x2, 16
+; CHECK-NEXT: PseudoRET
+$x2 = frame-setup ADDI $x2, -16
+frame-setup CFI_INSTRUCTION def_cfa_offset 16
+SD killed $x1, $x2, 8 :: (store (s64) into %stack.0)
+frame-setup CFI_INSTRUCTION offset $x1, -8
+   

  1   2   >