[clang] [clang-format] Don't merge a short block for SBS_Never (PR #88238)

2024-04-10 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/88238

Also fix unit tests.

Fixes #87484.

>From 4122a4f0e189afa7aff1010f0061b4f4d2b2a627 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 10 Apr 2024 00:03:21 -0700
Subject: [PATCH] [clang-format] Don't merge a short block for SBS_Never

Also fix unit tests.

Fixes #87484.
---
 clang/lib/Format/FormatToken.h|  2 +
 clang/lib/Format/UnwrappedLineFormatter.cpp   |  8 +-
 clang/lib/Format/UnwrappedLineParser.cpp  |  7 +-
 clang/unittests/Format/BracesRemoverTest.cpp  |  4 +-
 clang/unittests/Format/FormatTest.cpp | 84 +++
 .../Format/FormatTestMacroExpansion.cpp   |  7 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 20 +
 7 files changed, 106 insertions(+), 26 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 48b6a9092a8c09..f651e6228c206d 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -35,6 +35,8 @@ namespace format {
   TYPE(BinaryOperator) 
\
   TYPE(BitFieldColon)  
\
   TYPE(BlockComment)   
\
+  /* l_brace of a block that is not the body of a (e.g. loop) statement. */
\
+  TYPE(BlockLBrace)
\
   TYPE(BracedListLBrace)   
\
   /* The colon at the end of a case label. */  
\
   TYPE(CaseLabelColon) 
\
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index fb31980ab9f491..4ae54e56331bdc 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -796,8 +796,12 @@ class LineJoiner {
   }
 }
 
-if (const auto *LastNonComment = Line.getLastNonComment();
-LastNonComment && LastNonComment->is(tok::l_brace)) {
+if (Line.endsWith(tok::l_brace)) {
+  if (Style.AllowShortBlocksOnASingleLine == FormatStyle::SBS_Never &&
+  Line.First->is(TT_BlockLBrace)) {
+return 0;
+  }
+
   if (IsSplitBlock && Line.First == Line.Last &&
   I > AnnotatedLines.begin() &&
   (I[-1]->endsWith(tok::kw_else) || IsCtrlStmt(*I[-1]))) {
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c1f7e2874beb24..603268f771ac52 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -395,9 +395,10 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
 ParseDefault();
 continue;
   }
-  if (!InRequiresExpression && FormatTok->isNot(TT_MacroBlockBegin) &&
-  tryToParseBracedList()) {
-continue;
+  if (!InRequiresExpression && FormatTok->isNot(TT_MacroBlockBegin)) {
+if (tryToParseBracedList())
+  continue;
+FormatTok->setFinalizedType(TT_BlockLBrace);
   }
   parseBlock();
   ++StatementCount;
diff --git a/clang/unittests/Format/BracesRemoverTest.cpp 
b/clang/unittests/Format/BracesRemoverTest.cpp
index 5155eefb9e08c9..2e983b887ffcb2 100644
--- a/clang/unittests/Format/BracesRemoverTest.cpp
+++ b/clang/unittests/Format/BracesRemoverTest.cpp
@@ -209,7 +209,9 @@ TEST_F(BracesRemoverTest, RemoveBraces) {
   verifyFormat("if (a) {\n"
"  b;\n"
"} else {\n"
-   "  { c; }\n"
+   "  {\n"
+   "c;\n"
+   "  }\n"
"}",
Style);
 
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index f312a9e21158a9..4906b3350b5b22 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -52,7 +52,13 @@ TEST_F(FormatTest, FormatsUnwrappedLinesAtFirstFormat) {
 }
 
 TEST_F(FormatTest, FormatsNestedBlockStatements) {
-  verifyFormat("{\n  {\n{}\n  }\n}", "{{{}}}");
+  verifyFormat("{\n"
+   "  {\n"
+   "{\n"
+   "}\n"
+   "  }\n"
+   "}",
+   "{{{}}}");
 }
 
 TEST_F(FormatTest, FormatsNestedCall) {
@@ -5669,7 +5675,10 @@ TEST_F(FormatTest, LayoutCodeInMacroDefinitions) {
getLLVMStyleWithColumns(14));
 }
 
-TEST_F(FormatTest, LayoutRemainingTokens) { verifyFormat("{}"); }
+TEST_F(FormatTest, LayoutRemainingTokens) {
+  verifyFormat("{\n"
+   "}");
+}
 
 TEST_F(FormatTest, MacroDefinitionInsideStatement) {
   verifyFormat("int x,\n"
@@ -6577,7 +6586,11 @@ TEST_F(FormatTest, 
FormatAlignInsidePreprocessorElseBlock) {
 }
 
 TEST_F(FormatTest, FormatHashIfNotAtStartOfLine) {
-  verifyFormat("{\n  { a #c; }\n}");
+  verifyFormat("{\n

[clang] [clang][dataflow] Propagate locations from result objects to initializers. (PR #87320)

2024-04-10 Thread via cfe-commits


@@ -385,6 +390,187 @@ getFieldsGlobalsAndFuncs(const Stmt &S, FieldSet &Fields,
   }
 }
 
+namespace {
+
+// Visitor that builds a map from record prvalues to result objects.
+// This traverses the body of the function to be analyzed; for each result
+// object that it encounters, it propagates the storage location of the result
+// object to all record prvalues that can initialize it.
+class ResultObjectVisitor : public RecursiveASTVisitor {
+public:
+  // `ResultObjectMap` will be filled with a map from record prvalues to result
+  // object. If the function being analyzed returns a record by value,
+  // `LocForRecordReturnVal` is the location to which this record should be
+  // written; otherwise, it is null.
+  explicit ResultObjectVisitor(
+  llvm::DenseMap &ResultObjectMap,
+  RecordStorageLocation *LocForRecordReturnVal,
+  DataflowAnalysisContext &DACtx)
+  : ResultObjectMap(ResultObjectMap),
+LocForRecordReturnVal(LocForRecordReturnVal), DACtx(DACtx) {}
+
+  bool shouldVisitImplicitCode() { return true; }
+
+  bool shouldVisitLambdaBody() const { return false; }
+
+  // Traverse all member and base initializers of `Ctor`. This function is not
+  // called by `RecursiveASTVisitor`; it should be called manually if we are
+  // analyzing a constructor. `ThisPointeeLoc` is the storage location that
+  // `this` points to.
+  void TraverseConstructorInits(const CXXConstructorDecl *Ctor,
+RecordStorageLocation *ThisPointeeLoc) {
+assert(ThisPointeeLoc != nullptr);
+for (const CXXCtorInitializer *Init : Ctor->inits()) {
+  Expr *InitExpr = Init->getInit();
+  if (FieldDecl *Field = Init->getMember();
+  Field != nullptr && Field->getType()->isRecordType()) {
+PropagateResultObject(InitExpr, cast(
+ThisPointeeLoc->getChild(*Field)));
+  } else if (Init->getBaseClass()) {
+PropagateResultObject(InitExpr, ThisPointeeLoc);
+  }
+
+  // Ensure that any result objects within `InitExpr` (e.g. temporaries)
+  // are also propagated to the prvalues that initialize them.
+  TraverseStmt(InitExpr);
+
+  // If this is a `CXXDefaultInitExpr`, also propagate any result objects
+  // within the default expression.
+  if (auto *DefaultInit = dyn_cast(InitExpr))
+TraverseStmt(DefaultInit->getExpr());
+}
+  }
+
+  bool TraverseBindingDecl(BindingDecl *BD) {
+// `RecursiveASTVisitor` doesn't traverse holding variables for
+// `BindingDecl`s by itself, so we need to tell it to.
+if (VarDecl *HoldingVar = BD->getHoldingVar())
+  TraverseDecl(HoldingVar);
+return RecursiveASTVisitor::TraverseBindingDecl(BD);
+  }
+
+  bool VisitVarDecl(VarDecl *VD) {
+if (VD->getType()->isRecordType() && VD->hasInit())
+  PropagateResultObject(
+  VD->getInit(),
+  &cast(DACtx.getStableStorageLocation(*VD)));
+return true;
+  }
+
+  bool VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *MTE) {
+if (MTE->getType()->isRecordType())
+  PropagateResultObject(
+  MTE->getSubExpr(),
+  &cast(DACtx.getStableStorageLocation(*MTE)));
+return true;
+  }
+
+  bool VisitReturnStmt(ReturnStmt *Return) {
+Expr *RetValue = Return->getRetValue();
+if (RetValue != nullptr && RetValue->getType()->isRecordType() &&
+RetValue->isPRValue())
+  PropagateResultObject(RetValue, LocForRecordReturnVal);
+return true;
+  }
+
+  bool VisitExpr(Expr *E) {
+// Clang's AST can have record-type prvalues without a result object -- for
+// example as full-expressions contained in a compound statement or as
+// arguments of call expressions. We notice this if we get here and a
+// storage location has not yet been associated with `E`. In this case,
+// treat this as if it was a `MaterializeTemporaryExpr`.
+if (E->isPRValue() && E->getType()->isRecordType() &&
+!ResultObjectMap.contains(E))
+  PropagateResultObject(
+  E, &cast(DACtx.getStableStorageLocation(*E)));
+return true;
+  }
+
+  // Assigns `Loc` as the result object location of `E`, then propagates the
+  // location to all lower-level prvalues that initialize the same object as
+  // `E` (or one of its base classes or member variables).
+  void PropagateResultObject(Expr *E, RecordStorageLocation *Loc) {
+if (!E->isPRValue() || !E->getType()->isRecordType()) {
+  assert(false);
+  // Ensure we don't propagate the result object if we hit this in a
+  // release build.
+  return;
+}
+
+ResultObjectMap[E] = Loc;
+
+// The following AST node kinds are "original initializers": They are the
+// lowest-level AST node that initializes a given object, and nothing
+// below them can initialize the same object (or part of it).
+if (isa(E) || isa(E) || isa(E) ||
+isa(E) || isa(E) ||
+isa(E)) {
+  return;
+}
+
+

[clang] [clang-format] Don't merge a short block for SBS_Never (PR #88238)

2024-04-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Also fix unit tests.

Fixes #87484.

---
Full diff: https://github.com/llvm/llvm-project/pull/88238.diff


7 Files Affected:

- (modified) clang/lib/Format/FormatToken.h (+2) 
- (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+6-2) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+4-3) 
- (modified) clang/unittests/Format/BracesRemoverTest.cpp (+3-1) 
- (modified) clang/unittests/Format/FormatTest.cpp (+67-17) 
- (modified) clang/unittests/Format/FormatTestMacroExpansion.cpp (+4-3) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+20) 


``diff
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 48b6a9092a8c09..f651e6228c206d 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -35,6 +35,8 @@ namespace format {
   TYPE(BinaryOperator) 
\
   TYPE(BitFieldColon)  
\
   TYPE(BlockComment)   
\
+  /* l_brace of a block that is not the body of a (e.g. loop) statement. */
\
+  TYPE(BlockLBrace)
\
   TYPE(BracedListLBrace)   
\
   /* The colon at the end of a case label. */  
\
   TYPE(CaseLabelColon) 
\
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index fb31980ab9f491..4ae54e56331bdc 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -796,8 +796,12 @@ class LineJoiner {
   }
 }
 
-if (const auto *LastNonComment = Line.getLastNonComment();
-LastNonComment && LastNonComment->is(tok::l_brace)) {
+if (Line.endsWith(tok::l_brace)) {
+  if (Style.AllowShortBlocksOnASingleLine == FormatStyle::SBS_Never &&
+  Line.First->is(TT_BlockLBrace)) {
+return 0;
+  }
+
   if (IsSplitBlock && Line.First == Line.Last &&
   I > AnnotatedLines.begin() &&
   (I[-1]->endsWith(tok::kw_else) || IsCtrlStmt(*I[-1]))) {
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c1f7e2874beb24..603268f771ac52 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -395,9 +395,10 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
 ParseDefault();
 continue;
   }
-  if (!InRequiresExpression && FormatTok->isNot(TT_MacroBlockBegin) &&
-  tryToParseBracedList()) {
-continue;
+  if (!InRequiresExpression && FormatTok->isNot(TT_MacroBlockBegin)) {
+if (tryToParseBracedList())
+  continue;
+FormatTok->setFinalizedType(TT_BlockLBrace);
   }
   parseBlock();
   ++StatementCount;
diff --git a/clang/unittests/Format/BracesRemoverTest.cpp 
b/clang/unittests/Format/BracesRemoverTest.cpp
index 5155eefb9e08c9..2e983b887ffcb2 100644
--- a/clang/unittests/Format/BracesRemoverTest.cpp
+++ b/clang/unittests/Format/BracesRemoverTest.cpp
@@ -209,7 +209,9 @@ TEST_F(BracesRemoverTest, RemoveBraces) {
   verifyFormat("if (a) {\n"
"  b;\n"
"} else {\n"
-   "  { c; }\n"
+   "  {\n"
+   "c;\n"
+   "  }\n"
"}",
Style);
 
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index f312a9e21158a9..4906b3350b5b22 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -52,7 +52,13 @@ TEST_F(FormatTest, FormatsUnwrappedLinesAtFirstFormat) {
 }
 
 TEST_F(FormatTest, FormatsNestedBlockStatements) {
-  verifyFormat("{\n  {\n{}\n  }\n}", "{{{}}}");
+  verifyFormat("{\n"
+   "  {\n"
+   "{\n"
+   "}\n"
+   "  }\n"
+   "}",
+   "{{{}}}");
 }
 
 TEST_F(FormatTest, FormatsNestedCall) {
@@ -5669,7 +5675,10 @@ TEST_F(FormatTest, LayoutCodeInMacroDefinitions) {
getLLVMStyleWithColumns(14));
 }
 
-TEST_F(FormatTest, LayoutRemainingTokens) { verifyFormat("{}"); }
+TEST_F(FormatTest, LayoutRemainingTokens) {
+  verifyFormat("{\n"
+   "}");
+}
 
 TEST_F(FormatTest, MacroDefinitionInsideStatement) {
   verifyFormat("int x,\n"
@@ -6577,7 +6586,11 @@ TEST_F(FormatTest, 
FormatAlignInsidePreprocessorElseBlock) {
 }
 
 TEST_F(FormatTest, FormatHashIfNotAtStartOfLine) {
-  verifyFormat("{\n  { a #c; }\n}");
+  verifyFormat("{\n"
+   "  {\n"
+   "a #c;\n"
+   "  }\n"
+   "}");
 }
 
 TEST_F(FormatTest, FormatUnbalanc

[clang] [clang][dataflow] Propagate locations from result objects to initializers. (PR #87320)

2024-04-10 Thread via cfe-commits

https://github.com/martinboehme updated 
https://github.com/llvm/llvm-project/pull/87320

>From 2d2aa88aab3e47e41588397471a90c03bb55d900 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Tue, 2 Apr 2024 08:00:00 +
Subject: [PATCH 1/3] [clang][dataflow] Propagate locations from result objects
 to initializers.

Previously, we were propagating storage locations the other way around, i.e.
from initializers to result objects, using `RecordValue::getLoc()`. This gave
the wrong behavior in some cases -- see the newly added or fixed tests in this
patch.

In addition, this patch now unblocks removing the `RecordValue` class entirely,
as we no longer need `RecordValue::getLoc()`.

With this patch, the test `TransferTest.DifferentReferenceLocInJoin` started to
fail because the framework now always uses the same storge location for a
`MaterializeTemporaryExpr`, meaning that the code under test no longer set up
the desired state where a variable of reference type is mapped to two different
storage locations in environments being joined. Rather than trying to modify
this test to set up the test condition again, I have chosen to replace the test
with an equivalent test in DataflowEnvironmentTest.cpp that sets up the test
condition directly; because this test is more direct, it will also be less
brittle in the face of future changes.
---
 .../FlowSensitive/DataflowEnvironment.h   |  64 ++-
 .../FlowSensitive/DataflowEnvironment.cpp | 402 +-
 clang/lib/Analysis/FlowSensitive/Transfer.cpp | 172 
 .../TypeErasedDataflowAnalysis.cpp|  13 +-
 .../FlowSensitive/DataflowEnvironmentTest.cpp |  43 ++
 .../Analysis/FlowSensitive/TransferTest.cpp   | 172 +---
 6 files changed, 582 insertions(+), 284 deletions(-)

diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index c30bccd06674a4..dc3a9c239552be 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -30,6 +30,7 @@
 #include "llvm/ADT/MapVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
+#include 
 #include 
 #include 
 
@@ -330,17 +331,6 @@ class Environment {
   /// location of the result object to pass in `this`, even though prvalues are
   /// otherwise not associated with storage locations.
   ///
-  /// FIXME: Currently, this simply returns a stable storage location for `E`,
-  /// but this doesn't do the right thing in scenarios like the following:
-  /// ```
-  /// MyClass c = some_condition()? MyClass(foo) : MyClass(bar);
-  /// ```
-  /// Here, `MyClass(foo)` and `MyClass(bar)` will have two different storage
-  /// locations, when in fact their storage locations should be the same.
-  /// Eventually, we want to propagate storage locations from result objects
-  /// down to the prvalues that initialize them, similar to the way that this 
is
-  /// done in Clang's CodeGen.
-  ///
   /// Requirements:
   ///  `E` must be a prvalue of record type.
   RecordStorageLocation &
@@ -448,7 +438,13 @@ class Environment {
   /// Initializes the fields (including synthetic fields) of `Loc` with values,
   /// unless values of the field type are not supported or we hit one of the
   /// limits at which we stop producing values.
-  void initializeFieldsWithValues(RecordStorageLocation &Loc);
+  /// If `Type` is provided, initializes only those fields that are modeled for
+  /// `Type`; this is intended for use in cases where `Loc` is a derived type
+  /// and we only want to initialize the fields of a base type.
+  void initializeFieldsWithValues(RecordStorageLocation &Loc, QualType Type);
+  void initializeFieldsWithValues(RecordStorageLocation &Loc) {
+initializeFieldsWithValues(Loc, Loc.getType());
+  }
 
   /// Assigns `Val` as the value of `Loc` in the environment.
   void setValue(const StorageLocation &Loc, Value &Val);
@@ -639,6 +635,9 @@ class Environment {
   LLVM_DUMP_METHOD void dump(raw_ostream &OS) const;
 
 private:
+  using PrValueToResultObject =
+  llvm::DenseMap;
+
   // The copy-constructor is for use in fork() only.
   Environment(const Environment &) = default;
 
@@ -668,8 +667,10 @@ class Environment {
   /// Initializes the fields (including synthetic fields) of `Loc` with values,
   /// unless values of the field type are not supported or we hit one of the
   /// limits at which we stop producing values (controlled by `Visited`,
-  /// `Depth`, and `CreatedValuesCount`).
-  void initializeFieldsWithValues(RecordStorageLocation &Loc,
+  /// `Depth`, and `CreatedValuesCount`). If `Type` is different from
+  /// `Loc.getType()`, initializes only those fields that are modeled for
+  /// `Type`.
+  void initializeFieldsWithValues(RecordStorageLocation &Loc, QualType Type,
   llvm::DenseSet &Visited, int Depth,
  

[clang] [clang][dataflow] Propagate locations from result objects to initializers. (PR #87320)

2024-04-10 Thread via cfe-commits


@@ -385,6 +390,187 @@ getFieldsGlobalsAndFuncs(const Stmt &S, FieldSet &Fields,
   }
 }
 
+namespace {
+
+// Visitor that builds a map from record prvalues to result objects.
+// This traverses the body of the function to be analyzed; for each result
+// object that it encounters, it propagates the storage location of the result
+// object to all record prvalues that can initialize it.
+class ResultObjectVisitor : public RecursiveASTVisitor {
+public:
+  // `ResultObjectMap` will be filled with a map from record prvalues to result
+  // object. If the function being analyzed returns a record by value,
+  // `LocForRecordReturnVal` is the location to which this record should be
+  // written; otherwise, it is null.
+  explicit ResultObjectVisitor(
+  llvm::DenseMap &ResultObjectMap,
+  RecordStorageLocation *LocForRecordReturnVal,
+  DataflowAnalysisContext &DACtx)
+  : ResultObjectMap(ResultObjectMap),
+LocForRecordReturnVal(LocForRecordReturnVal), DACtx(DACtx) {}
+
+  bool shouldVisitImplicitCode() { return true; }
+
+  bool shouldVisitLambdaBody() const { return false; }
+
+  // Traverse all member and base initializers of `Ctor`. This function is not
+  // called by `RecursiveASTVisitor`; it should be called manually if we are
+  // analyzing a constructor. `ThisPointeeLoc` is the storage location that
+  // `this` points to.
+  void TraverseConstructorInits(const CXXConstructorDecl *Ctor,
+RecordStorageLocation *ThisPointeeLoc) {
+assert(ThisPointeeLoc != nullptr);
+for (const CXXCtorInitializer *Init : Ctor->inits()) {
+  Expr *InitExpr = Init->getInit();
+  if (FieldDecl *Field = Init->getMember();
+  Field != nullptr && Field->getType()->isRecordType()) {
+PropagateResultObject(InitExpr, cast(
+ThisPointeeLoc->getChild(*Field)));
+  } else if (Init->getBaseClass()) {
+PropagateResultObject(InitExpr, ThisPointeeLoc);
+  }
+
+  // Ensure that any result objects within `InitExpr` (e.g. temporaries)
+  // are also propagated to the prvalues that initialize them.
+  TraverseStmt(InitExpr);
+
+  // If this is a `CXXDefaultInitExpr`, also propagate any result objects
+  // within the default expression.
+  if (auto *DefaultInit = dyn_cast(InitExpr))
+TraverseStmt(DefaultInit->getExpr());
+}
+  }
+
+  bool TraverseBindingDecl(BindingDecl *BD) {
+// `RecursiveASTVisitor` doesn't traverse holding variables for
+// `BindingDecl`s by itself, so we need to tell it to.
+if (VarDecl *HoldingVar = BD->getHoldingVar())
+  TraverseDecl(HoldingVar);
+return RecursiveASTVisitor::TraverseBindingDecl(BD);
+  }
+
+  bool VisitVarDecl(VarDecl *VD) {
+if (VD->getType()->isRecordType() && VD->hasInit())
+  PropagateResultObject(
+  VD->getInit(),
+  &cast(DACtx.getStableStorageLocation(*VD)));
+return true;
+  }
+
+  bool VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *MTE) {
+if (MTE->getType()->isRecordType())
+  PropagateResultObject(
+  MTE->getSubExpr(),
+  &cast(DACtx.getStableStorageLocation(*MTE)));
+return true;
+  }
+
+  bool VisitReturnStmt(ReturnStmt *Return) {
+Expr *RetValue = Return->getRetValue();
+if (RetValue != nullptr && RetValue->getType()->isRecordType() &&
+RetValue->isPRValue())
+  PropagateResultObject(RetValue, LocForRecordReturnVal);
+return true;
+  }
+
+  bool VisitExpr(Expr *E) {
+// Clang's AST can have record-type prvalues without a result object -- for
+// example as full-expressions contained in a compound statement or as
+// arguments of call expressions. We notice this if we get here and a
+// storage location has not yet been associated with `E`. In this case,
+// treat this as if it was a `MaterializeTemporaryExpr`.
+if (E->isPRValue() && E->getType()->isRecordType() &&
+!ResultObjectMap.contains(E))
+  PropagateResultObject(
+  E, &cast(DACtx.getStableStorageLocation(*E)));
+return true;
+  }
+
+  // Assigns `Loc` as the result object location of `E`, then propagates the
+  // location to all lower-level prvalues that initialize the same object as
+  // `E` (or one of its base classes or member variables).
+  void PropagateResultObject(Expr *E, RecordStorageLocation *Loc) {
+if (!E->isPRValue() || !E->getType()->isRecordType()) {
+  assert(false);
+  // Ensure we don't propagate the result object if we hit this in a
+  // release build.
+  return;
+}
+
+ResultObjectMap[E] = Loc;
+
+// The following AST node kinds are "original initializers": They are the
+// lowest-level AST node that initializes a given object, and nothing
+// below them can initialize the same object (or part of it).
+if (isa(E) || isa(E) || isa(E) ||
+isa(E) || isa(E) ||
+isa(E)) {
+  return;
+}
+
+

[clang] [clang][dataflow] Propagate locations from result objects to initializers. (PR #87320)

2024-04-10 Thread via cfe-commits


@@ -556,6 +763,10 @@ void Environment::pushCallInternal(const FunctionDecl 
*FuncDecl,
 const VarDecl *Param = *ParamIt;
 setStorageLocation(*Param, createObject(*Param, Args[ArgIndex]));
   }
+
+  ResultObjectMap = std::make_shared(

martinboehme wrote:

True -- if we're making several calls to the same function, it might indeed be 
worth caching this.

I think this isn't a priority for the time being though because a) I'm not 
aware of any non-test models that use context-sensitive analysis yet, and b) as 
you say, we should benchmark to see whether this makes up a significant portion 
of the total effort for analyzing the callee (which in itself will be 
expensive).

https://github.com/llvm/llvm-project/pull/87320
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Propagate locations from result objects to initializers. (PR #87320)

2024-04-10 Thread via cfe-commits


@@ -6830,50 +6932,6 @@ TEST(TransferTest, LambdaCaptureThis) {
   });
 }
 
-TEST(TransferTest, DifferentReferenceLocInJoin) {

martinboehme wrote:

See explanation in PR description. (tl;dr: We can no longer set up the desired 
situation, so I replaced this with an equivalent test in 
DataflowEnvironmentTest.cpp.)

https://github.com/llvm/llvm-project/pull/87320
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][AST][NFC] Fix printing of dependent PackIndexTypes (PR #88146)

2024-04-10 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

Oups
Thanks for fixing that!

https://github.com/llvm/llvm-project/pull/88146
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4e85e1f - [Clang][AArch64] Warn when calling non/streaming about vector size difference (#79842)

2024-04-10 Thread via cfe-commits

Author: Dinar Temirbulatov
Date: 2024-04-10T08:39:50+01:00
New Revision: 4e85e1ffcaf161736e27a24c291c1177be865976

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

LOG: [Clang][AArch64] Warn when calling non/streaming about vector size 
difference (#79842)

The compiler doesn't know in advance if the streaming and non-streaming
vector-lengths are different, so it should be safe to give a warning
diagnostic to warn the user about possible undefined behaviour. If the
user knows the vector lengths are equal, they can disable the warning
separately.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/aarch64-incompat-sm-builtin-calls.c
clang/test/Sema/aarch64-sme-func-attrs.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 5251774ff4efd6..47747d8704b6c8 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1412,6 +1412,9 @@ def MultiGPU: DiagGroup<"multi-gpu">;
 // libc and the CRT to be skipped.
 def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">;
 
+// A warning group related to AArch64 SME function attribues.
+def AArch64SMEAttributes : DiagGroup<"aarch64-sme-attributes">;
+
 // A warning group for things that will change semantics in the future.
 def FutureCompat : DiagGroup<"future-compat">;
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1c068f6cdb4293..64c58ab36338ba 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3755,6 +3755,16 @@ def err_sme_definition_using_za_in_non_sme_target : 
Error<
   "function using ZA state requires 'sme'">;
 def err_sme_definition_using_zt0_in_non_sme2_target : Error<
   "function using ZT0 state requires 'sme2'">;
+def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning<
+  "passing a VL-dependent argument to/from a function that has a 
diff erent"
+  " streaming-mode. The streaming and non-streaming vector lengths may be"
+  " 
diff erent">,
+  InGroup, DefaultIgnore;
+def warn_sme_locally_streaming_has_vl_args_returns : Warning<
+  "passing/returning a VL-dependent argument to/from a __arm_locally_streaming"
+  " function. The streaming and non-streaming vector"
+  " lengths may be 
diff erent">,
+  InGroup, DefaultIgnore;
 def err_conflicting_attributes_arm_state : Error<
   "conflicting attributes for state '%0'">;
 def err_sme_streaming_cannot_be_multiversioned : Error<

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b84a779b7189c0..abfd9a3031577b 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -7938,6 +7938,7 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 // For variadic functions, we may have more args than parameters.
 // For some K&R functions, we may have less args than parameters.
 const auto N = std::min(Proto->getNumParams(), Args.size());
+bool AnyScalableArgsOrRet = Proto->getReturnType()->isSizelessVectorType();
 for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) {
   // Args[ArgIdx] can be null in malformed code.
   if (const Expr *Arg = Args[ArgIdx]) {
@@ -7951,6 +7952,8 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   checkAIXMemberAlignment((Arg->getExprLoc()), Arg);
 
 QualType ParamTy = Proto->getParamType(ArgIdx);
+if (ParamTy->isSizelessVectorType())
+  AnyScalableArgsOrRet = true;
 QualType ArgTy = Arg->getType();
 CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1),
   ArgTy, ParamTy);
@@ -7971,6 +7974,23 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
+// If the call requires a streaming-mode change and has scalable vector
+// arguments or return values, then warn the user that the streaming and
+// non-streaming vector lengths may be 
diff erent.
+const auto *CallerFD = dyn_cast(CurContext);
+if (CallerFD && (!FD || !FD->getBuiltinID()) && AnyScalableArgsOrRet) {
+  bool IsCalleeStreaming =
+  ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask;
+  bool IsCalleeStreamingCompatible =
+  ExtInfo.AArch64SMEAttributes &
+  FunctionType::SME_PStateSMCompatibleMask;
+  ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD);
+  if (!IsCalleeStreamingCompatible &&
+  (Caller

[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

2024-04-10 Thread Dinar Temirbulatov via cfe-commits

https://github.com/dtemirbulatov closed 
https://github.com/llvm/llvm-project/pull/79842
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Don't merge a short block for SBS_Never (PR #88238)

2024-04-10 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/88238

>From 4122a4f0e189afa7aff1010f0061b4f4d2b2a627 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 10 Apr 2024 00:03:21 -0700
Subject: [PATCH 1/2] [clang-format] Don't merge a short block for SBS_Never

Also fix unit tests.

Fixes #87484.
---
 clang/lib/Format/FormatToken.h|  2 +
 clang/lib/Format/UnwrappedLineFormatter.cpp   |  8 +-
 clang/lib/Format/UnwrappedLineParser.cpp  |  7 +-
 clang/unittests/Format/BracesRemoverTest.cpp  |  4 +-
 clang/unittests/Format/FormatTest.cpp | 84 +++
 .../Format/FormatTestMacroExpansion.cpp   |  7 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 20 +
 7 files changed, 106 insertions(+), 26 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 48b6a9092a8c09..f651e6228c206d 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -35,6 +35,8 @@ namespace format {
   TYPE(BinaryOperator) 
\
   TYPE(BitFieldColon)  
\
   TYPE(BlockComment)   
\
+  /* l_brace of a block that is not the body of a (e.g. loop) statement. */
\
+  TYPE(BlockLBrace)
\
   TYPE(BracedListLBrace)   
\
   /* The colon at the end of a case label. */  
\
   TYPE(CaseLabelColon) 
\
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index fb31980ab9f491..4ae54e56331bdc 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -796,8 +796,12 @@ class LineJoiner {
   }
 }
 
-if (const auto *LastNonComment = Line.getLastNonComment();
-LastNonComment && LastNonComment->is(tok::l_brace)) {
+if (Line.endsWith(tok::l_brace)) {
+  if (Style.AllowShortBlocksOnASingleLine == FormatStyle::SBS_Never &&
+  Line.First->is(TT_BlockLBrace)) {
+return 0;
+  }
+
   if (IsSplitBlock && Line.First == Line.Last &&
   I > AnnotatedLines.begin() &&
   (I[-1]->endsWith(tok::kw_else) || IsCtrlStmt(*I[-1]))) {
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c1f7e2874beb24..603268f771ac52 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -395,9 +395,10 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
 ParseDefault();
 continue;
   }
-  if (!InRequiresExpression && FormatTok->isNot(TT_MacroBlockBegin) &&
-  tryToParseBracedList()) {
-continue;
+  if (!InRequiresExpression && FormatTok->isNot(TT_MacroBlockBegin)) {
+if (tryToParseBracedList())
+  continue;
+FormatTok->setFinalizedType(TT_BlockLBrace);
   }
   parseBlock();
   ++StatementCount;
diff --git a/clang/unittests/Format/BracesRemoverTest.cpp 
b/clang/unittests/Format/BracesRemoverTest.cpp
index 5155eefb9e08c9..2e983b887ffcb2 100644
--- a/clang/unittests/Format/BracesRemoverTest.cpp
+++ b/clang/unittests/Format/BracesRemoverTest.cpp
@@ -209,7 +209,9 @@ TEST_F(BracesRemoverTest, RemoveBraces) {
   verifyFormat("if (a) {\n"
"  b;\n"
"} else {\n"
-   "  { c; }\n"
+   "  {\n"
+   "c;\n"
+   "  }\n"
"}",
Style);
 
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index f312a9e21158a9..4906b3350b5b22 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -52,7 +52,13 @@ TEST_F(FormatTest, FormatsUnwrappedLinesAtFirstFormat) {
 }
 
 TEST_F(FormatTest, FormatsNestedBlockStatements) {
-  verifyFormat("{\n  {\n{}\n  }\n}", "{{{}}}");
+  verifyFormat("{\n"
+   "  {\n"
+   "{\n"
+   "}\n"
+   "  }\n"
+   "}",
+   "{{{}}}");
 }
 
 TEST_F(FormatTest, FormatsNestedCall) {
@@ -5669,7 +5675,10 @@ TEST_F(FormatTest, LayoutCodeInMacroDefinitions) {
getLLVMStyleWithColumns(14));
 }
 
-TEST_F(FormatTest, LayoutRemainingTokens) { verifyFormat("{}"); }
+TEST_F(FormatTest, LayoutRemainingTokens) {
+  verifyFormat("{\n"
+   "}");
+}
 
 TEST_F(FormatTest, MacroDefinitionInsideStatement) {
   verifyFormat("int x,\n"
@@ -6577,7 +6586,11 @@ TEST_F(FormatTest, 
FormatAlignInsidePreprocessorElseBlock) {
 }
 
 TEST_F(FormatTest, FormatHashIfNotAtStartOfLine) {
-  verifyFormat("{\n  { a #c; }\n}");
+  verifyFormat("{\n"
+   "  {\n"
+  

[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-10 Thread via cfe-commits


@@ -709,6 +712,11 @@ void ODRHash::AddFunctionDecl(const FunctionDecl *Function,
 return;
   }
 
+  if (DeletedMessage) {
+ID.AddString(DeletedMessage->getBytes());
+return;
+  }
+

Sirraide wrote:

> (there is a question of whether isExplicitlyDefaulted/isDeletedAsWritten 
> should be after skip body, but that seems logical as is, and at worse it 
> would be pre-existing)

Yeah, that’s true; considering those are already always included it makes sense 
to always include the message as well if it exists.

https://github.com/llvm/llvm-project/pull/86526
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-10 Thread via cfe-commits


@@ -1981,21 +1981,35 @@ class FunctionDecl : public DeclaratorDecl,
 
   };
 
-  /// Stashed information about a defaulted function definition whose body has
-  /// not yet been lazily generated.
-  class DefaultedFunctionInfo final
-  : llvm::TrailingObjects {
+  /// Stashed information about a defaulted/deleted function body.
+  class DefaultedOrDeletedFunctionInfo final
+  : llvm::TrailingObjects {
 friend TrailingObjects;
 unsigned NumLookups;
+bool HasDeletedMessage;

Sirraide wrote:

I don’t think it matters in this case because 
`sizeof(DefaultedOrDeletedFunctionInfo)` was already 16 before this, meaning 
this is just using one more byte of padding, from what I can tell, but I can 
also make it a bitfield seeing as we probably won’t ever need to store 4 
billion lookups here.

https://github.com/llvm/llvm-project/pull/86526
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-10 Thread via cfe-commits


@@ -2484,6 +2498,9 @@ class FunctionDecl : public DeclaratorDecl,
 
   void setDeletedAsWritten(bool D = true) { FunctionDeclBits.IsDeleted = D; }
 
+  /// Only valid if isDeletedAsWritten() returns true.
+  void setDeletedMessage(StringLiteral *Message);
+

Sirraide wrote:

So the main reasons I haven’t done that are:
1. `setDeletedAsWritten()` is called in many different places, but only in one 
of them do we also set the message;
2. `setDeletedMessage()` does a lot more than `setDeletedAsWritten()`, because 
whereas the latter just sets a bit to true, the former may also have to 
allocate a `DefaultedOrDeletedInfo` first and also has a couple asserts to make 
sure calling it is well-formed.

That said, `setDeletedMessage()` is currently only called in one place, 
directly after `setDeletedAsWritten()` (because all the other places where we 
need to set the message, e.g. serialisation, just directly create the 
`DefaultedOrDeletedInfo` instead), so if you still think we should just fold 
that into `setDeletedMessage()` then I’ll do that instead.

https://github.com/llvm/llvm-project/pull/86526
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b7a93bc - [clang][Interp] Start implementing vector types

2024-04-10 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-04-10T10:45:06+02:00
New Revision: b7a93bc1f230fe01f38f3648437cee74f339c5ac

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

LOG: [clang][Interp] Start implementing vector types

Map them to primtive arrays, much like complex types.

Added: 
clang/test/AST/Interp/vectors.cpp

Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/Pointer.cpp
clang/lib/AST/Interp/Program.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a1ce6575148325..acff63cd9dc022 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1033,6 +1033,34 @@ bool ByteCodeExprGen::VisitInitListExpr(const 
InitListExpr *E) {
 return true;
   }
 
+  if (const auto *VecT = E->getType()->getAs()) {
+unsigned NumVecElements = VecT->getNumElements();
+assert(NumVecElements >= E->getNumInits());
+
+QualType ElemQT = VecT->getElementType();
+PrimType ElemT = classifyPrim(ElemQT);
+
+// All initializer elements.
+unsigned InitIndex = 0;
+for (const Expr *Init : E->inits()) {
+  if (!this->visit(Init))
+return false;
+
+  if (!this->emitInitElem(ElemT, InitIndex, E))
+return false;
+  ++InitIndex;
+}
+
+// Fill the rest with zeroes.
+for (; InitIndex != NumVecElements; ++InitIndex) {
+  if (!this->visitZeroInitializer(ElemT, ElemQT, E))
+return false;
+  if (!this->emitInitElem(ElemT, InitIndex, E))
+return false;
+}
+return true;
+  }
+
   return false;
 }
 

diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index 15a9d46880e954..274178837bf047 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -120,7 +120,8 @@ std::optional Context::classify(QualType T) const 
{
   if (T->isBooleanType())
 return PT_Bool;
 
-  if (T->isAnyComplexType())
+  // We map these to primitive arrays.
+  if (T->isAnyComplexType() || T->isVectorType())
 return std::nullopt;
 
   if (T->isSignedIntegerOrEnumerationType()) {

diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index caffb69d83e379..d764b4b6f6d17b 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -51,7 +51,8 @@ EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD,
   this->CheckFullyInitialized = CheckFullyInitialized;
   this->ConvertResultToRValue =
   VD->getAnyInitializer() &&
-  (VD->getAnyInitializer()->getType()->isAnyComplexType());
+  (VD->getAnyInitializer()->getType()->isAnyComplexType() ||
+   VD->getAnyInitializer()->getType()->isVectorType());
   EvalResult.setSource(VD);
 
   if (!this->visitDecl(VD) && EvalResult.empty())

diff  --git a/clang/lib/AST/Interp/Pointer.cpp 
b/clang/lib/AST/Interp/Pointer.cpp
index 53998cc3233c94..cddcd6b0151e42 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -342,6 +342,25 @@ std::optional Pointer::toRValue(const Context 
&Ctx) const {
   return false;
 }
 
+// Vector types.
+if (const auto *VT = Ty->getAs()) {
+  assert(Ptr.getFieldDesc()->isPrimitiveArray());
+  QualType ElemTy = VT->getElementType();
+  PrimType ElemT = *Ctx.classify(ElemTy);
+
+  SmallVector Values;
+  Values.reserve(VT->getNumElements());
+  for (unsigned I = 0; I != VT->getNumElements(); ++I) {
+TYPE_SWITCH(ElemT, {
+  Values.push_back(Ptr.atIndex(I).deref().toAPValue());
+});
+  }
+
+  assert(Values.size() == VT->getNumElements());
+  R = APValue(Values.data(), Values.size());
+  return true;
+}
+
 llvm_unreachable("invalid value to return");
   };
 

diff  --git a/clang/lib/AST/Interp/Program.cpp 
b/clang/lib/AST/Interp/Program.cpp
index 25e938e0150322..82367164743fc3 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -411,5 +411,12 @@ Descriptor *Program::createDescriptor(const DeclTy &D, 
const Type *Ty,
   IsMutable);
   }
 
+  // Same with vector types.
+  if (const auto *VT = Ty->getAs()) {
+PrimType ElemTy = *Ctx.classify(VT->getElementType());
+return allocateDescriptor(D, ElemTy, MDSize, VT->getNumElements(), IsConst,
+  IsTemporary, IsMutable);
+  }
+
   return nullptr;
 }

diff  --git a/clang/test/AST/Interp/vectors.cpp 
b/clang/test/AST/Interp/vectors.cpp
new file mode 100644
index 00..8afef3c897bff7
--- /dev/null
+++ b/clang/test/AST/Interp/vectors.cpp
@@ -0,0 +1,22 @@
+// RUN:

[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-10 Thread via cfe-commits


@@ -1981,21 +1981,35 @@ class FunctionDecl : public DeclaratorDecl,
 
   };
 
-  /// Stashed information about a defaulted function definition whose body has
-  /// not yet been lazily generated.
-  class DefaultedFunctionInfo final
-  : llvm::TrailingObjects {
+  /// Stashed information about a defaulted/deleted function body.
+  class DefaultedOrDeletedFunctionInfo final
+  : llvm::TrailingObjects {
 friend TrailingObjects;
 unsigned NumLookups;
+bool HasDeletedMessage;

Sirraide wrote:

Actually, 8 not 16, but either way, making it a bitfield doesn’t seem to do 
much in this case.

https://github.com/llvm/llvm-project/pull/86526
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-10 Thread via cfe-commits


@@ -1981,21 +1981,35 @@ class FunctionDecl : public DeclaratorDecl,
 
   };
 
-  /// Stashed information about a defaulted function definition whose body has
-  /// not yet been lazily generated.
-  class DefaultedFunctionInfo final
-  : llvm::TrailingObjects {
+  /// Stashed information about a defaulted/deleted function body.
+  class DefaultedOrDeletedFunctionInfo final
+  : llvm::TrailingObjects {
 friend TrailingObjects;
 unsigned NumLookups;
+bool HasDeletedMessage;

Sirraide wrote:

I’m not too familiar w/ the internals of `TrailingObjects`, but I suspect it’s 
doing `alignas(...)` or something to that effect somewhere, 
which would then end up being `8` here.

https://github.com/llvm/llvm-project/pull/86526
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-10 Thread via cfe-commits


@@ -2484,6 +2498,9 @@ class FunctionDecl : public DeclaratorDecl,
 
   void setDeletedAsWritten(bool D = true) { FunctionDeclBits.IsDeleted = D; }
 
+  /// Only valid if isDeletedAsWritten() returns true.
+  void setDeletedMessage(StringLiteral *Message);
+

cor3ntin wrote:

Yes, I would prefer (my argument is that there is no scenario in which we would 
call setDeletedMessage without first calling setDeletedAsWritten, and we always 
have the information available.

https://github.com/llvm/llvm-project/pull/86526
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Reland "[Win32][ELF] Make CodeView a DebugInfoFormat only for COFF format", second try (PR #88245)

2024-04-10 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang created 
https://github.com/llvm/llvm-project/pull/88245

This is a second try to reland https://github.com/llvm/llvm-project/pull/87149.

The previous commit exposed failures on some targets. The reason is only a few 
targets support COFF ObjectFormatType on Windows: 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/TargetParser/Triple.cpp#L835-L842

With https://github.com/llvm/llvm-project/pull/87149, the targets don't support 
COFF will report "warning: argument unused during compilation: 
'-gcodeview-command-line' [-Wunused-command-line-argument]" in the test 
gcodeview-command-line.c

I was thinking `REQUIRES: *-registered-target` could solve the problem, but it 
didn't. We need to check the actual triple instead of just 
`*-registered-target`.

>From 569c7dfee58f7e4357d8af45b52a3135cb4e2e65 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Wed, 10 Apr 2024 15:38:49 +0800
Subject: [PATCH 1/2] "Reland "[Win32][ELF] Make CodeView a DebugInfoFormat
 only for COFF format" (#87987)", second try

This reverts commit 299b636a8f1c9cb2382f9dce4cdf6ec6330a79c6.
---
 clang/lib/Driver/ToolChains/MSVC.h | 5 ++---
 clang/test/Driver/gcodeview-command-line.c | 1 +
 clang/test/Misc/win32-elf.c| 5 +
 3 files changed, 8 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Misc/win32-elf.c

diff --git a/clang/lib/Driver/ToolChains/MSVC.h 
b/clang/lib/Driver/ToolChains/MSVC.h
index 48369e030aade2..3950a8ed38e8b4 100644
--- a/clang/lib/Driver/ToolChains/MSVC.h
+++ b/clang/lib/Driver/ToolChains/MSVC.h
@@ -61,9 +61,8 @@ class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public 
ToolChain {
   /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
   /// override the default.
   llvm::codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override 
{
-return getTriple().isOSBinFormatMachO()
-   ? llvm::codegenoptions::DIF_DWARF
-   : llvm::codegenoptions::DIF_CodeView;
+return getTriple().isOSBinFormatCOFF() ? llvm::codegenoptions::DIF_CodeView
+   : llvm::codegenoptions::DIF_DWARF;
   }
 
   /// Set the debugger tuning to "default", since we're definitely not tuning
diff --git a/clang/test/Driver/gcodeview-command-line.c 
b/clang/test/Driver/gcodeview-command-line.c
index da8708af322480..83542fc71aece4 100644
--- a/clang/test/Driver/gcodeview-command-line.c
+++ b/clang/test/Driver/gcodeview-command-line.c
@@ -1,5 +1,6 @@
 // Note: %s must be preceded by --, otherwise it may be interpreted as a
 // command-line option, e.g. on Mac where %s is commonly under /Users.
+// REQUIRES: 
aarch64-registered-target,arm-registered-target,x86-registered-target
 
 // ON-NOT: "-gno-codview-commandline"
 // OFF: "-gno-codeview-command-line"
diff --git a/clang/test/Misc/win32-elf.c b/clang/test/Misc/win32-elf.c
new file mode 100644
index 00..f75281dc418727
--- /dev/null
+++ b/clang/test/Misc/win32-elf.c
@@ -0,0 +1,5 @@
+// Check that basic use of win32-elf targets works.
+// RUN: %clang -fsyntax-only -target x86_64-pc-win32-elf %s
+
+// RUN: %clang -fsyntax-only -target x86_64-pc-win32-elf -g %s -### 2>&1 | 
FileCheck %s -check-prefix=DEBUG-INFO
+// DEBUG-INFO: -dwarf-version={{.*}}

>From e6a326dc4b21f8180e03d9f2157fd63792a1dc14 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Wed, 10 Apr 2024 17:02:23 +0800
Subject: [PATCH 2/2] Move codeview related tests to gcodeview-command-line.c

---
 clang/test/Driver/cl-options.c | 12 --
 clang/test/Driver/cl-outputs.c | 12 --
 clang/test/Driver/gcodeview-command-line.c | 26 +-
 clang/test/Driver/gcodeview-ghash.c|  1 +
 clang/test/lit.cfg.py  |  2 ++
 5 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 5b6dfe308a76ea..202f7a50e618fe 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -545,18 +545,6 @@
 // RTTI-NOT: "-fno-rtti-data"
 // RTTI-NOT: "-fno-rtti"
 
-// RUN: %clang_cl /Zi /c -### -- %s 2>&1 | FileCheck -check-prefix=Zi %s
-// Zi: "-gcodeview"
-// Zi: "-debug-info-kind=constructor"
-
-// RUN: %clang_cl /Z7 /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7 %s
-// Z7: "-gcodeview"
-// Z7: "-debug-info-kind=constructor"
-
-// RUN: %clang_cl -gline-tables-only /c -### -- %s 2>&1 | FileCheck 
-check-prefix=ZGMLT %s
-// ZGMLT: "-gcodeview"
-// ZGMLT: "-debug-info-kind=line-tables-only"
-
 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=BreproDefault %s
 // BreproDefault: "-mincremental-linker-compatible"
 
diff --git a/clang/test/Driver/cl-outputs.c b/clang/test/Driver/cl-outputs.c
index 4d58f0fb548b57..10bd0c97dcdca8 100644
--- a/clang/test/Driver/cl-outputs.c
+++ b/clang/test/Driver/cl-outputs.c
@@ -294,15 +294,3 @@
 // RUN: %clang_cl /P /Fifoo.x /obar.x -### -- %s 2>&1 | FileCheck 
-check-prefix=FioR

[clang] Reland "[Win32][ELF] Make CodeView a DebugInfoFormat only for COFF format", second try (PR #88245)

2024-04-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Phoebe Wang (phoebewang)


Changes

This is a second try to reland https://github.com/llvm/llvm-project/pull/87149.

The previous commit exposed failures on some targets. The reason is only a few 
targets support COFF ObjectFormatType on Windows: 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/TargetParser/Triple.cpp#L835-L842

With https://github.com/llvm/llvm-project/pull/87149, the targets don't support 
COFF will report "warning: argument unused during compilation: 
'-gcodeview-command-line' [-Wunused-command-line-argument]" in the test 
gcodeview-command-line.c

I was thinking `REQUIRES: *-registered-target` could solve the problem, but it 
didn't. We need to check the actual triple instead of just 
`*-registered-target`.

---
Full diff: https://github.com/llvm/llvm-project/pull/88245.diff


7 Files Affected:

- (modified) clang/lib/Driver/ToolChains/MSVC.h (+2-3) 
- (modified) clang/test/Driver/cl-options.c (-12) 
- (modified) clang/test/Driver/cl-outputs.c (-12) 
- (modified) clang/test/Driver/gcodeview-command-line.c (+25) 
- (modified) clang/test/Driver/gcodeview-ghash.c (+1) 
- (added) clang/test/Misc/win32-elf.c (+5) 
- (modified) clang/test/lit.cfg.py (+2) 


``diff
diff --git a/clang/lib/Driver/ToolChains/MSVC.h 
b/clang/lib/Driver/ToolChains/MSVC.h
index 48369e030aade2..3950a8ed38e8b4 100644
--- a/clang/lib/Driver/ToolChains/MSVC.h
+++ b/clang/lib/Driver/ToolChains/MSVC.h
@@ -61,9 +61,8 @@ class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public 
ToolChain {
   /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
   /// override the default.
   llvm::codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override 
{
-return getTriple().isOSBinFormatMachO()
-   ? llvm::codegenoptions::DIF_DWARF
-   : llvm::codegenoptions::DIF_CodeView;
+return getTriple().isOSBinFormatCOFF() ? llvm::codegenoptions::DIF_CodeView
+   : llvm::codegenoptions::DIF_DWARF;
   }
 
   /// Set the debugger tuning to "default", since we're definitely not tuning
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 5b6dfe308a76ea..202f7a50e618fe 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -545,18 +545,6 @@
 // RTTI-NOT: "-fno-rtti-data"
 // RTTI-NOT: "-fno-rtti"
 
-// RUN: %clang_cl /Zi /c -### -- %s 2>&1 | FileCheck -check-prefix=Zi %s
-// Zi: "-gcodeview"
-// Zi: "-debug-info-kind=constructor"
-
-// RUN: %clang_cl /Z7 /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7 %s
-// Z7: "-gcodeview"
-// Z7: "-debug-info-kind=constructor"
-
-// RUN: %clang_cl -gline-tables-only /c -### -- %s 2>&1 | FileCheck 
-check-prefix=ZGMLT %s
-// ZGMLT: "-gcodeview"
-// ZGMLT: "-debug-info-kind=line-tables-only"
-
 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=BreproDefault %s
 // BreproDefault: "-mincremental-linker-compatible"
 
diff --git a/clang/test/Driver/cl-outputs.c b/clang/test/Driver/cl-outputs.c
index 4d58f0fb548b57..10bd0c97dcdca8 100644
--- a/clang/test/Driver/cl-outputs.c
+++ b/clang/test/Driver/cl-outputs.c
@@ -294,15 +294,3 @@
 // RUN: %clang_cl /P /Fifoo.x /obar.x -### -- %s 2>&1 | FileCheck 
-check-prefix=FioRACE2 %s
 // FioRACE2: "-E"
 // FioRACE2: "-o" "foo.x"
-
-// RUN: %clang_cl /Z7 /Foa.obj -### -- %s 2>&1 | FileCheck 
-check-prefix=ABSOLUTE_OBJPATH %s
-// ABSOLUTE_OBJPATH: "-object-file-name={{.*}}a.obj"
-
-// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Foa.obj -### -- %s 2>&1 | 
FileCheck -check-prefix=RELATIVE_OBJPATH1 %s
-// RELATIVE_OBJPATH1: "-object-file-name=a.obj"
-
-// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Fo:a.obj -### -- %s 2>&1 | 
FileCheck -check-prefix=RELATIVE_OBJPATH1_COLON %s
-// RELATIVE_OBJPATH1_COLON: "-object-file-name=a.obj"
-
-// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Fofoo/a.obj -### -- %s 2>&1 | 
FileCheck -check-prefix=RELATIVE_OBJPATH2 %s
-// RELATIVE_OBJPATH2: "-object-file-name=foo\\a.obj"
diff --git a/clang/test/Driver/gcodeview-command-line.c 
b/clang/test/Driver/gcodeview-command-line.c
index da8708af322480..f65527a00dc97d 100644
--- a/clang/test/Driver/gcodeview-command-line.c
+++ b/clang/test/Driver/gcodeview-command-line.c
@@ -1,5 +1,6 @@
 // Note: %s must be preceded by --, otherwise it may be interpreted as a
 // command-line option, e.g. on Mac where %s is commonly under /Users.
+// REQUIRES: coff-supported-target
 
 // ON-NOT: "-gno-codview-commandline"
 // OFF: "-gno-codeview-command-line"
@@ -17,3 +18,27 @@
 // GCC-style driver
 // RUN: %clang -g -gcodeview -gno-codeview-command-line 
-gcodeview-command-line -### -- %s 2>&1 | FileCheck -check-prefix=ON %s
 // RUN: %clang -g -gcodeview -gcodeview-command-line 
-gno-codeview-command-line -### -- %s 2>&1 | FileCheck -check-prefix=OFF %s
+
+// RUN: %clang_cl /Zi /c -### -- %s 2>&1 | FileCheck -check-prefix=Zi %s
+// Zi: "-gcodeview"
+// Zi: "-debug-info-kind=cons

[clang] Reland "[Win32][ELF] Make CodeView a DebugInfoFormat only for COFF format", second try (PR #88245)

2024-04-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Phoebe Wang (phoebewang)


Changes

This is a second try to reland https://github.com/llvm/llvm-project/pull/87149.

The previous commit exposed failures on some targets. The reason is only a few 
targets support COFF ObjectFormatType on Windows: 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/TargetParser/Triple.cpp#L835-L842

With https://github.com/llvm/llvm-project/pull/87149, the targets don't support 
COFF will report "warning: argument unused during compilation: 
'-gcodeview-command-line' [-Wunused-command-line-argument]" in the test 
gcodeview-command-line.c

I was thinking `REQUIRES: *-registered-target` could solve the problem, but it 
didn't. We need to check the actual triple instead of just 
`*-registered-target`.

---
Full diff: https://github.com/llvm/llvm-project/pull/88245.diff


7 Files Affected:

- (modified) clang/lib/Driver/ToolChains/MSVC.h (+2-3) 
- (modified) clang/test/Driver/cl-options.c (-12) 
- (modified) clang/test/Driver/cl-outputs.c (-12) 
- (modified) clang/test/Driver/gcodeview-command-line.c (+25) 
- (modified) clang/test/Driver/gcodeview-ghash.c (+1) 
- (added) clang/test/Misc/win32-elf.c (+5) 
- (modified) clang/test/lit.cfg.py (+2) 


``diff
diff --git a/clang/lib/Driver/ToolChains/MSVC.h 
b/clang/lib/Driver/ToolChains/MSVC.h
index 48369e030aade2..3950a8ed38e8b4 100644
--- a/clang/lib/Driver/ToolChains/MSVC.h
+++ b/clang/lib/Driver/ToolChains/MSVC.h
@@ -61,9 +61,8 @@ class LLVM_LIBRARY_VISIBILITY MSVCToolChain : public 
ToolChain {
   /// formats, and to DWARF otherwise. Users can use -gcodeview and -gdwarf to
   /// override the default.
   llvm::codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override 
{
-return getTriple().isOSBinFormatMachO()
-   ? llvm::codegenoptions::DIF_DWARF
-   : llvm::codegenoptions::DIF_CodeView;
+return getTriple().isOSBinFormatCOFF() ? llvm::codegenoptions::DIF_CodeView
+   : llvm::codegenoptions::DIF_DWARF;
   }
 
   /// Set the debugger tuning to "default", since we're definitely not tuning
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 5b6dfe308a76ea..202f7a50e618fe 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -545,18 +545,6 @@
 // RTTI-NOT: "-fno-rtti-data"
 // RTTI-NOT: "-fno-rtti"
 
-// RUN: %clang_cl /Zi /c -### -- %s 2>&1 | FileCheck -check-prefix=Zi %s
-// Zi: "-gcodeview"
-// Zi: "-debug-info-kind=constructor"
-
-// RUN: %clang_cl /Z7 /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7 %s
-// Z7: "-gcodeview"
-// Z7: "-debug-info-kind=constructor"
-
-// RUN: %clang_cl -gline-tables-only /c -### -- %s 2>&1 | FileCheck 
-check-prefix=ZGMLT %s
-// ZGMLT: "-gcodeview"
-// ZGMLT: "-debug-info-kind=line-tables-only"
-
 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=BreproDefault %s
 // BreproDefault: "-mincremental-linker-compatible"
 
diff --git a/clang/test/Driver/cl-outputs.c b/clang/test/Driver/cl-outputs.c
index 4d58f0fb548b57..10bd0c97dcdca8 100644
--- a/clang/test/Driver/cl-outputs.c
+++ b/clang/test/Driver/cl-outputs.c
@@ -294,15 +294,3 @@
 // RUN: %clang_cl /P /Fifoo.x /obar.x -### -- %s 2>&1 | FileCheck 
-check-prefix=FioRACE2 %s
 // FioRACE2: "-E"
 // FioRACE2: "-o" "foo.x"
-
-// RUN: %clang_cl /Z7 /Foa.obj -### -- %s 2>&1 | FileCheck 
-check-prefix=ABSOLUTE_OBJPATH %s
-// ABSOLUTE_OBJPATH: "-object-file-name={{.*}}a.obj"
-
-// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Foa.obj -### -- %s 2>&1 | 
FileCheck -check-prefix=RELATIVE_OBJPATH1 %s
-// RELATIVE_OBJPATH1: "-object-file-name=a.obj"
-
-// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Fo:a.obj -### -- %s 2>&1 | 
FileCheck -check-prefix=RELATIVE_OBJPATH1_COLON %s
-// RELATIVE_OBJPATH1_COLON: "-object-file-name=a.obj"
-
-// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Fofoo/a.obj -### -- %s 2>&1 | 
FileCheck -check-prefix=RELATIVE_OBJPATH2 %s
-// RELATIVE_OBJPATH2: "-object-file-name=foo\\a.obj"
diff --git a/clang/test/Driver/gcodeview-command-line.c 
b/clang/test/Driver/gcodeview-command-line.c
index da8708af322480..f65527a00dc97d 100644
--- a/clang/test/Driver/gcodeview-command-line.c
+++ b/clang/test/Driver/gcodeview-command-line.c
@@ -1,5 +1,6 @@
 // Note: %s must be preceded by --, otherwise it may be interpreted as a
 // command-line option, e.g. on Mac where %s is commonly under /Users.
+// REQUIRES: coff-supported-target
 
 // ON-NOT: "-gno-codview-commandline"
 // OFF: "-gno-codeview-command-line"
@@ -17,3 +18,27 @@
 // GCC-style driver
 // RUN: %clang -g -gcodeview -gno-codeview-command-line 
-gcodeview-command-line -### -- %s 2>&1 | FileCheck -check-prefix=ON %s
 // RUN: %clang -g -gcodeview -gcodeview-command-line 
-gno-codeview-command-line -### -- %s 2>&1 | FileCheck -check-prefix=OFF %s
+
+// RUN: %clang_cl /Zi /c -### -- %s 2>&1 | FileCheck -check-prefix=Zi %s
+// Zi: "-gcodeview"
+// Zi: "-debug-info-ki

[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-10 Thread via cfe-commits


@@ -2484,6 +2498,9 @@ class FunctionDecl : public DeclaratorDecl,
 
   void setDeletedAsWritten(bool D = true) { FunctionDeclBits.IsDeleted = D; }
 
+  /// Only valid if isDeletedAsWritten() returns true.
+  void setDeletedMessage(StringLiteral *Message);
+

Sirraide wrote:

> there is no scenario in which we would call setDeletedMessage without first 
> calling setDeletedAsWritten

That’s true; I was thinking we might want to set the message elsewhere at some 
point, but I think that I was remembering the situation before I included it it 
in the `DefaultedOrDeletedInfo`. I’ll move it to `setDeletedAsWritten()` and 
just give it a default argument.

https://github.com/llvm/llvm-project/pull/86526
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Allow explicit specification of -lFortran_main (PR #78152)

2024-04-10 Thread Michael Klemm via cfe-commits

mjklemm wrote:

Should this PR be closed at some point?  It seems to be obsolete with the work 
that has been done in the recent past to improve the situation.

https://github.com/llvm/llvm-project/pull/78152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][AMDGPU] Add rocm-path flag (PR #88190)

2024-04-10 Thread Dominik Adamski via cfe-commits

https://github.com/DominikAdamski updated 
https://github.com/llvm/llvm-project/pull/88190

>From 44def17f36e8e27eb4232681e5ae7eff5de6d90f Mon Sep 17 00:00:00 2001
From: Dominik Adamski 
Date: Tue, 9 Apr 2024 14:35:26 -0500
Subject: [PATCH 1/2] [Flang][AMDGPU] Add rocm-path flag

ROCm installation path is used for finding and automatically
linking required bitcode libraries.
---
 clang/include/clang/Driver/Options.td|  3 ++-
 clang/lib/Driver/ToolChains/Flang.cpp|  4 
 flang/test/Driver/driver-help-hidden.f90 |  1 +
 flang/test/Driver/driver-help.f90|  1 +
 flang/test/Driver/omp-driver-offload.f90 | 21 +
 5 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f745e573eb2686..651aa10150c06e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1341,7 +1341,8 @@ def hip_link : Flag<["--"], "hip-link">, 
Group,
   HelpText<"Link clang-offload-bundler bundles for HIP">;
 def no_hip_rt: Flag<["-"], "no-hip-rt">, Group,
   HelpText<"Do not link against HIP runtime libraries">;
-def rocm_path_EQ : Joined<["--"], "rocm-path=">, Group,
+def rocm_path_EQ : Joined<["--"], "rocm-path=">,
+  Visibility<[FlangOption]>, Group,
   HelpText<"ROCm installation path, used for finding and automatically linking 
required bitcode libraries.">;
 def hip_path_EQ : Joined<["--"], "hip-path=">, Group,
   HelpText<"HIP runtime installation path, used for finding HIP version and 
adding HIP include path.">;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 2c83f70eb7887e..75e4ead81e43ed 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -342,6 +342,10 @@ void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
 StringRef Val = A->getValue();
 CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
   }
+
+  // Check ROCm path if specified
+  const ToolChain &TC = getToolChain();
+  TC.getDeviceLibs(Args);
 }
 
 void Flang::addTargetOptions(const ArgList &Args,
diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 48f48f5384fdc5..10b15fb454b9aa 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -144,6 +144,7 @@
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
 ! CHECK-NEXT: -pthreadSupport POSIX threads in generated code
 ! CHECK-NEXT: -P  Disable linemarker output in -E mode
+! CHECK-NEXT: --rocm-path= ROCm installation path, used for finding and 
automatically linking required bitcode libraries.
 ! CHECK-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! CHECK-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
 ! CHECK-NEXT: -Rpass=  Report transformations performed by 
optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index 38f74395a678ab..ed5af2a68eb044 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -132,6 +132,7 @@
 ! HELP-NEXT: -print-target-triplePrint the normalized target triple
 ! HELP-NEXT: -pthreadSupport POSIX threads in generated code
 ! HELP-NEXT: -P  Disable linemarker output in -E mode
+! HELP-NEXT:  --rocm-path= ROCm installation path, used for finding and 
automatically linking required bitcode libraries.
 ! HELP-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! HELP-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
 ! HELP-NEXT: -Rpass=  Report transformations performed by 
optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/omp-driver-offload.f90 
b/flang/test/Driver/omp-driver-offload.f90
index 7e9a73627cd757..836dcfc85eb9de 100644
--- a/flang/test/Driver/omp-driver-offload.f90
+++ b/flang/test/Driver/omp-driver-offload.f90
@@ -201,3 +201,24 @@
 ! RUN:  -nogpulibc %s 2>&1 \
 ! RUN:   | FileCheck --check-prefix=NO-LIBC-GPU-AMDGPU %s
 ! NO-LIBC-GPU-AMDGPU-NOT: "-lcgpu-amdgpu"
+
+! RUN:   rm -rf %t/Inputs
+
+! RUN:   not %flang -### -v --target=x86_64-unknown-linux-gnu -fopenmp  \
+! RUN:  --offload-arch=gfx900 \
+! RUN:  --rocm-path=%t/Inputs/rocm %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=ROCM-PATH-NOT-FOUND %s
+! ROCM-PATH-NOT-FOUND: error: cannot find ROCm device library;
+
+! RUN:   rm -rf %t/Inputs
+! RUN:   mkdir -p %t/Inputs
+! RUN:   cp -r %S/../../../clang/tes

[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-10 Thread via cfe-commits


@@ -1981,21 +1981,35 @@ class FunctionDecl : public DeclaratorDecl,
 
   };
 
-  /// Stashed information about a defaulted function definition whose body has
-  /// not yet been lazily generated.
-  class DefaultedFunctionInfo final
-  : llvm::TrailingObjects {
+  /// Stashed information about a defaulted/deleted function body.
+  class DefaultedOrDeletedFunctionInfo final
+  : llvm::TrailingObjects {
 friend TrailingObjects;
 unsigned NumLookups;
+bool HasDeletedMessage;

cor3ntin wrote:

The alignment is likely to go from 32 to 64, isn't it?
I don't insist (at best we would save a few KB per TU, presumably) , but also 
it doesn't cost much.

Maybe @AaronBallman would have an opinion

https://github.com/llvm/llvm-project/pull/86526
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)

2024-04-10 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

Great! Nothing else from my side

https://github.com/llvm/llvm-project/pull/87792
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-10 Thread via cfe-commits


@@ -1981,21 +1981,35 @@ class FunctionDecl : public DeclaratorDecl,
 
   };
 
-  /// Stashed information about a defaulted function definition whose body has
-  /// not yet been lazily generated.
-  class DefaultedFunctionInfo final
-  : llvm::TrailingObjects {
+  /// Stashed information about a defaulted/deleted function body.
+  class DefaultedOrDeletedFunctionInfo final
+  : llvm::TrailingObjects {
 friend TrailingObjects;
 unsigned NumLookups;
+bool HasDeletedMessage;

Sirraide wrote:

> The alignment is likely to go from 32 to 64, isn't it?

It would normally, but from what I can tell, because it’s inheriting from 
`TrailingObjects`, the alignment is set to the maximum of the alignment of what 
the type would normally have and the alignment of each of the trailing objects 
(by an `alignas` on `TralingObjectsBase`), and since the maximum alignment of 
the latter is `64`, that ends up being the alignment of the overall struct as 
well and thus also its size.

Printing out `sizeof(DefaultedOrDeletedFunctionInfo)` shows `8` in both cases 
(w/ and w/o the bitfield). I also don’t have a strong opinion on this 
personally; I just didn’t want to make it a bitfield when there’s space 
available anyway because this way, it’s at least obvious that we have more 
space left if we need to add more flags later.



https://github.com/llvm/llvm-project/pull/86526
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Allow explicit specification of -lFortran_main (PR #78152)

2024-04-10 Thread Tom Eccles via cfe-commits

https://github.com/tblah closed https://github.com/llvm/llvm-project/pull/78152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] `canReasonAbout` does not support `nonloc::LazyCompoundVal` (PR #87521)

2024-04-10 Thread Andrew V. Teylu via cfe-commits

https://github.com/aytey updated https://github.com/llvm/llvm-project/pull/87521

>From 1f70839ea1607f151c9f7eb390fcb974b32a54ca Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Wed, 3 Apr 2024 17:18:08 +0100
Subject: [PATCH 1/3] [analyzer] `canReasonAbout` does not support
 `nonloc::LazyCompoundVal`

This PR makes two modifications to the {Simple, Range} constraint managers:

* `nonloc::LazyCompoundVal` is now explicitly not able to be reasoned about; and

* When we have something that cannot be reasoned about, we return an unmodified 
state (and do not attempt to simplify)

For the added test-case, testing under `main` will either hit an 
`llvm_unreachable` (or go off the rails for other reasons). After this change, 
the test-case passes successfully.

The change stating "Non-integer types are not supported" for 
`nonloc::LazyCompoundVal` follows the same logic inside of 
`RangedConstraintManager::assumeSymUnsupported`. However, when a 
`nonloc::LazyCompoundVal`, we don't want to call 
`RangedConstraintManager::assumeSymUnsupported` because this will attempt to 
work with the `Sym` or `State` in a way that isn't compatible with a 
`nonloc::LazyCompoundVal`.
---
 .../Core/RangeConstraintManager.cpp |  4 
 .../Core/SimpleConstraintManager.cpp| 10 +++---
 clang/test/Analysis/non_loc_compound.cpp| 17 +
 3 files changed, 28 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Analysis/non_loc_compound.cpp

diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index c6f87b45ab887a..1f3e5711bcc71c 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2836,6 +2836,10 @@ bool RangeConstraintManager::canReasonAbout(SVal X) 
const {
 return false;
   }
 
+  // Non-integer types are not supported.
+  if (X.getAs())
+return false;
+
   return true;
 }
 
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
index 8ca2cdb9d3ab7a..b84a68ab93ef90 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
@@ -57,10 +57,14 @@ ProgramStateRef 
SimpleConstraintManager::assumeAux(ProgramStateRef State,
   // We cannot reason about SymSymExprs, and can only reason about some
   // SymIntExprs.
   if (!canReasonAbout(Cond)) {
-// Just add the constraint to the expression without trying to simplify.
 SymbolRef Sym = Cond.getAsSymbol();
-assert(Sym);
-return assumeSymUnsupported(State, Sym, Assumption);
+if (Sym) {
+  // this will simplify the symbol, so only call this if we have a
+  // symbol.
+  return assumeSymUnsupported(State, Sym, Assumption);
+} else {
+  return State;
+}
   }
 
   switch (Cond.getKind()) {
diff --git a/clang/test/Analysis/non_loc_compound.cpp 
b/clang/test/Analysis/non_loc_compound.cpp
new file mode 100644
index 00..b76ecb8d56635c
--- /dev/null
+++ b/clang/test/Analysis/non_loc_compound.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: crash-recovery, asserts
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=alpha.cplusplus.InvalidatedIterator \
+// RUN:   -analyzer-config aggressive-binary-operation-simplification=true \
+// RUN:   2>&1
+
+struct node {};
+struct prop : node {};
+struct bitvec : node {
+  prop operator==(bitvec) { return prop(); }
+  bitvec extend(); // { return *this; }
+};
+void convert() {
+  bitvec input;
+  bitvec output(input.extend());
+  output == input;
+}

>From 9f552209d9ce9bbddca247a46f79b331388908bf Mon Sep 17 00:00:00 2001
From: "Andrew V. Teylu" 
Date: Wed, 3 Apr 2024 17:18:08 +0100
Subject: [PATCH 2/3] [analyzer] `canReasonAbout` does not support
 `nonloc::LazyCompoundVal`

This PR makes two modifications to the {Simple, Range} constraint managers:

* `nonloc::LazyCompoundVal` is now explicitly not able to be reasoned about; and

* When we have something that cannot be reasoned about, we return an unmodified 
state (and do not attempt to simplify)

For the added test-case, testing under `main` will either hit an 
`llvm_unreachable` (or go off the rails for other reasons). After this change, 
the test-case passes successfully.

The change stating "Non-integer types are not supported" for 
`nonloc::LazyCompoundVal` follows the same logic inside of 
`RangedConstraintManager::assumeSymUnsupported`. However, when a 
`nonloc::LazyCompoundVal`, we don't want to call 
`RangedConstraintManager::assumeSymUnsupported` because this will attempt to 
work with the `Sym` or `State` in a way that isn't compatible with a 
`nonloc::LazyCompoundVal`.
---
 .../Core/RangeConstraintManager.cpp |  4 
 .../Core/SimpleConstraintManager.cpp| 10 +++---
 clang/test/Analysis/non_loc_compound.cpp| 17 +
 3 fi

[clang] [analyzer] `canReasonAbout` does not support `nonloc::LazyCompoundVal` (PR #87521)

2024-04-10 Thread Andrew V. Teylu via cfe-commits

aytey wrote:

@steakhal @haoNoQ how's this looking to you? anything further for me to do?

https://github.com/llvm/llvm-project/pull/87521
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)

2024-04-10 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/87792
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-10 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

Thanks for putting up with my comments and working on this feature.
I'm pretty happy with the state of the PR.

Please give it a day or two in case @erichkeane @AaronBallman @shafik 
@Fznamznon have further comments

https://github.com/llvm/llvm-project/pull/86526
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-04-10 Thread Jay Foad via cfe-commits

jayfoad wrote:

No further comments.

https://github.com/llvm/llvm-project/pull/79236
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ec40097 - [clang][Interp] Implement __builtin_{ctz,clz}g

2024-04-10 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-04-10T12:27:33+02:00
New Revision: ec40097db28374c1226f0f7e45f18491a596778b

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

LOG: [clang][Interp] Implement __builtin_{ctz,clz}g

Added: 


Modified: 
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 1bf5d55314f1f2..984ba4f7f2689c 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -16,6 +16,16 @@
 namespace clang {
 namespace interp {
 
+static unsigned callArgSize(const InterpState &S, const CallExpr *C) {
+  unsigned O = 0;
+
+  for (const Expr *E : C->arguments()) {
+O += align(primSize(*S.getContext().classify(E)));
+  }
+
+  return O;
+}
+
 template 
 static T getParam(const InterpFrame *Frame, unsigned Index) {
   assert(Frame->getFunction()->getNumParams() > Index);
@@ -816,9 +826,10 @@ static bool interp__builtin_carryop(InterpState &S, 
CodePtr OpPC,
 static bool interp__builtin_clz(InterpState &S, CodePtr OpPC,
 const InterpFrame *Frame, const Function *Func,
 const CallExpr *Call) {
+  unsigned CallSize = callArgSize(S, Call);
   unsigned BuiltinOp = Func->getBuiltinID();
   PrimType ValT = *S.getContext().classify(Call->getArg(0));
-  const APSInt &Val = peekToAPSInt(S.Stk, ValT);
+  const APSInt &Val = peekToAPSInt(S.Stk, ValT, CallSize);
 
   // When the argument is 0, the result of GCC builtins is undefined, whereas
   // for Microsoft intrinsics, the result is the bit-width of the argument.
@@ -826,8 +837,19 @@ static bool interp__builtin_clz(InterpState &S, CodePtr 
OpPC,
  BuiltinOp != Builtin::BI__lzcnt &&
  BuiltinOp != Builtin::BI__lzcnt64;
 
-  if (ZeroIsUndefined && Val == 0)
-return false;
+  if (Val == 0) {
+if (Func->getBuiltinID() == Builtin::BI__builtin_clzg &&
+Call->getNumArgs() == 2) {
+  // We have a fallback parameter.
+  PrimType FallbackT = *S.getContext().classify(Call->getArg(1));
+  const APSInt &Fallback = peekToAPSInt(S.Stk, FallbackT);
+  pushInteger(S, Fallback, Call->getType());
+  return true;
+}
+
+if (ZeroIsUndefined)
+  return false;
+  }
 
   pushInteger(S, Val.countl_zero(), Call->getType());
   return true;
@@ -836,11 +858,21 @@ static bool interp__builtin_clz(InterpState &S, CodePtr 
OpPC,
 static bool interp__builtin_ctz(InterpState &S, CodePtr OpPC,
 const InterpFrame *Frame, const Function *Func,
 const CallExpr *Call) {
+  unsigned CallSize = callArgSize(S, Call);
   PrimType ValT = *S.getContext().classify(Call->getArg(0));
-  const APSInt &Val = peekToAPSInt(S.Stk, ValT);
-
-  if (Val == 0)
+  const APSInt &Val = peekToAPSInt(S.Stk, ValT, CallSize);
+
+  if (Val == 0) {
+if (Func->getBuiltinID() == Builtin::BI__builtin_ctzg &&
+Call->getNumArgs() == 2) {
+  // We have a fallback parameter.
+  PrimType FallbackT = *S.getContext().classify(Call->getArg(1));
+  const APSInt &Fallback = peekToAPSInt(S.Stk, FallbackT);
+  pushInteger(S, Fallback, Call->getType());
+  return true;
+}
 return false;
+  }
 
   pushInteger(S, Val.countr_zero(), Call->getType());
   return true;
@@ -1223,6 +1255,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   case Builtin::BI__builtin_clzl:
   case Builtin::BI__builtin_clzll:
   case Builtin::BI__builtin_clzs:
+  case Builtin::BI__builtin_clzg:
   case Builtin::BI__lzcnt16: // Microsoft variants of count leading-zeroes
   case Builtin::BI__lzcnt:
   case Builtin::BI__lzcnt64:
@@ -1234,6 +1267,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   case Builtin::BI__builtin_ctzl:
   case Builtin::BI__builtin_ctzll:
   case Builtin::BI__builtin_ctzs:
+  case Builtin::BI__builtin_ctzg:
 if (!interp__builtin_ctz(S, OpPC, Frame, F, Call))
   return false;
 break;

diff  --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index 2e9d1a831dcf6e..a7adc92d3714fa 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -482,6 +482,9 @@ void test_noexcept(int *i) {
 #undef TEST_TYPE
 } // end namespace test_launder
 
+
+/// FIXME: The commented out tests here use a IntAP value and fail.
+/// This currently means we will leak the IntAP value since nothing cleans it 
up.
 namespace clz {
   char clz1[__builtin_clz(1) == BITSIZE(int) - 1 ? 1 : -1];
   char clz2[__builtin_clz(7) == BITSIZE(int) - 3 ? 1 : -1];

[clang] [llvm] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (PR #88251)

2024-04-10 Thread via cfe-commits

https://github.com/Lukacma created 
https://github.com/llvm/llvm-project/pull/88251

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics

```
  svbfloat16x2_t svclamp[_single_bf16_x2](svbfloat16x2_t zd, svbfloat16_t zn,
svbfloat16_t zm)  __arm_streaming;

  svbfloat16x4_t svclamp[_single_bf16_x4](svbfloat16x4_t zd, svbfloat16_t zn,
svbfloat16_t zm)  __arm_streaming;
```
These are available only  if __ARM_FEATURE_SME_B16B16 is enabled.

>From fe692284cd248e372302671e094eb9950edb5ee5 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 10 Apr 2024 10:20:03 +
Subject: [PATCH 1/2] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP

---
 clang/include/clang/Basic/arm_sve.td  |  5 ++
 .../aarch64-sme2-intrinsics/acle_sme2_clamp.c | 72 +--
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  2 +
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  6 ++
 .../AArch64/sve2p1-intrinsics-bfclamp.ll  | 26 ++-
 5 files changed, 106 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 6da30e08e7521e..63ca495a1bc9f1 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2148,6 +2148,11 @@ let TargetGuard = "sme2" in {
   def SVSCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "csil", 
MergeNone, "aarch64_sve_sclamp_single_x4",  [IsStreaming], []>;
   def SVUCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "UcUsUiUl", 
MergeNone, "aarch64_sve_uclamp_single_x4",  [IsStreaming], []>;
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
+
+  let TargetGuard = "b16b16"in {
+def SVBFCLAMP_X2 : SInst<"svclamp[_single_{d}_x2]",  "22dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x2",  [IsStreaming], []>;
+def SVBFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x4",  [IsStreaming], []>;
+  }
 }
 
 let TargetGuard = "sme2" in {
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
index 257cb595250181..1dd5aeee35fe73 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
@@ -1,12 +1,12 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // REQUIRES: aarch64-registered-target
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 \
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 \
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 \
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
-// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 \
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 \
 // RUN:  -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
@@ -745,3 +745,67 @@ svfloat32x4_t test_svclamp_single_f32_x4(svfloat32x4_t 
op1, svfloat32_t op2, svf
 svfloat64x4_t test_svclamp_single_f64_x4(svfloat64x4_t op1, svfloat64_t op2, 
svfloat64_t op3) __arm_streaming {
   return SVE_ACLE_FUNC(svclamp, _single_f64_x4, , )(op1, op2, op3);
 }
+
+// CHECK-LABEL: @test_svclamp_single_bf16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16

[clang] [llvm] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (PR #88251)

2024-04-10 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-clang

Author: None (Lukacma)


Changes

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics

```
  svbfloat16x2_t svclamp[_single_bf16_x2](svbfloat16x2_t zd, svbfloat16_t zn,
svbfloat16_t zm)  __arm_streaming;

  svbfloat16x4_t svclamp[_single_bf16_x4](svbfloat16x4_t zd, svbfloat16_t zn,
svbfloat16_t zm)  __arm_streaming;
```
These are available only  if __ARM_FEATURE_SME_B16B16 is enabled.

---
Full diff: https://github.com/llvm/llvm-project/pull/88251.diff


5 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
(+68-4) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+2) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (+6) 
- (modified) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfclamp.ll (+25-1) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 6da30e08e7521e..63ca495a1bc9f1 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2148,6 +2148,11 @@ let TargetGuard = "sme2" in {
   def SVSCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "csil", 
MergeNone, "aarch64_sve_sclamp_single_x4",  [IsStreaming], []>;
   def SVUCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "UcUsUiUl", 
MergeNone, "aarch64_sve_uclamp_single_x4",  [IsStreaming], []>;
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
+
+  let TargetGuard = "b16b16"in {
+def SVBFCLAMP_X2 : SInst<"svclamp[_single_{d}_x2]",  "22dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x2",  [IsStreaming], []>;
+def SVBFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x4",  [IsStreaming], []>;
+  }
 }
 
 let TargetGuard = "sme2" in {
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
index 257cb595250181..1dd5aeee35fe73 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
@@ -1,12 +1,12 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // REQUIRES: aarch64-registered-target
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 \
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 \
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 \
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
-// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 \
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 \
 // RUN:  -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
@@ -745,3 +745,67 @@ svfloat32x4_t test_svclamp_single_f32_x4(svfloat32x4_t 
op1, svfloat32_t op2, svf
 svfloat64x4_t test_svclamp_single_f64_x4(svfloat64x4_t op1, svfloat64_t op2, 
svfloat64_t op3) __arm_streaming {
   return SVE_ACLE_FUNC(svclamp, _single_f64_x4, , )(op1, op2, op3);
 }
+
+// CHECK-LABEL: @test_svclamp_single_bf16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
+// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[

[clang] [clang][ExtractAPI] Fix handling of anonymous TagDecls (PR #87772)

2024-04-10 Thread Daniel Grumberg via cfe-commits


@@ -54,6 +54,13 @@ RecordContext *APIRecord::castToRecordContext(const 
APIRecord *Record) {
   }
 }
 
+void RecordContext::stealRecordChain(RecordContext &Other) {
+  First = Other.First;
+  Last = Other.Last;
+  Other.First = nullptr;
+  Other.Last = nullptr;
+}

daniel-grumberg wrote:

Maybe a better name for this would be `transferRecordChain`?

https://github.com/llvm/llvm-project/pull/87772
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C99] Claim conformance for _Complex support (PR #88161)

2024-04-10 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

Note that
```c++
auto div(_Complex float lhs, _Complex float rhs) {
  return lhs / rhs;
}

int main() {
  return __real div(1.f, 2.f);
}
```
will fail to link on windows due to `__divsc3` not being available. Similar 
programs probably also fail due to other compiler-rt functions not being 
available.

https://github.com/llvm/llvm-project/pull/88161
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64][SME] Add intrinsics for vector groups ZERO (PR #88114)

2024-04-10 Thread via cfe-commits

https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/88114

>From c44bd42f8011dd09771fda50a76a7321342c2b2f Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Thu, 4 Apr 2024 14:36:54 +
Subject: [PATCH 1/2] WIP

---
 clang/include/clang/Basic/arm_sme.td  |  29 ++-
 .../acle_sme2p1_zero.c|  91 +
 .../acle_sme2p1_imm.cpp   | 190 ++
 llvm/include/llvm/IR/IntrinsicsAArch64.td |   6 +
 4 files changed, 315 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_zero.c
 create mode 100644 
clang/test/Sema/aarch64-sme2p1-intrinsics/acle_sme2p1_imm.cpp

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 1ac6d5170ea283..b00eabe331169f 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -146,6 +146,33 @@ let TargetGuard = "sme" in {
  [IsOverloadNone, IsStreamingCompatible, IsOutZA]>;
 }
 
+let TargetGuard = "sme2p1" in {
+  def SVZERO_ZA64_VG1x2 : SInst<"svzero_za64_vg1x2", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg1x2",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_7>]>;
+  def SVZERO_ZA64_VG1x4 : SInst<"svzero_za64_vg1x4", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg1x4",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_7>]>;
+  def SVZERO_ZA64_VG2x1 : SInst<"svzero_za64_vg2x1", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg2x1",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_7>]>;
+  def SVZERO_ZA64_VG2x2 : SInst<"svzero_za64_vg2x2", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg2x2",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_3>]>;
+  def SVZERO_ZA64_VG2x4 : SInst<"svzero_za64_vg2x4", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg2x4",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_3>]>;
+  def SVZERO_ZA64_VG4x1 : SInst<"svzero_za64_vg4x1", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg4x1",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_3>]>;
+  def SVZERO_ZA64_VG4x2 : SInst<"svzero_za64_vg4x2", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg4x2",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_1>]>;
+  def SVZERO_ZA64_VG4x4 : SInst<"svzero_za64_vg4x4", "vi", "", MergeNone, 
"aarch64_sme_zero_za64_vg4x4",
+[IsOverloadNone, IsStreaming, IsInOutZA],
+[ImmCheck<0, ImmCheck0_1>]>;
+}
+
 

 // SME - Counting elements in a streaming vector
 
@@ -673,4 +700,4 @@ let TargetGuard = "sme2" in {
 let TargetGuard = "sme2" in {
   def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
-}
+}
\ No newline at end of file
diff --git a/clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_zero.c 
b/clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_zero.c
new file mode 100644
index 00..3b661ec425cda5
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_zero.c
@@ -0,0 +1,91 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+#include 
+
+#define SVE_ACLE_FUNC(A1,A2) A1##A2
+
+// CHECK-LABEL: define dso_local void @test_svzero_za64_vg1x2(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero.za64.vg1x2(i32 0)
+// CHECK-NEXT:ret void
+//
+void test_svzero_za64_vg1x2(void) __arm_streaming __arm_inout("za")
+{
+   SVE_ACLE_FUNC(svzero_za64,_vg1x2)(0);
+}
+
+// CHECK-LABEL: define dso_local void @test_svzero_za64_vg1x4(
+// C

[clang] [llvm] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (PR #88251)

2024-04-10 Thread via cfe-commits

https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/88251

>From fe692284cd248e372302671e094eb9950edb5ee5 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 10 Apr 2024 10:20:03 +
Subject: [PATCH 1/2] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP

---
 clang/include/clang/Basic/arm_sve.td  |  5 ++
 .../aarch64-sme2-intrinsics/acle_sme2_clamp.c | 72 +--
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  2 +
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  6 ++
 .../AArch64/sve2p1-intrinsics-bfclamp.ll  | 26 ++-
 5 files changed, 106 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 6da30e08e7521e..63ca495a1bc9f1 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2148,6 +2148,11 @@ let TargetGuard = "sme2" in {
   def SVSCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "csil", 
MergeNone, "aarch64_sve_sclamp_single_x4",  [IsStreaming], []>;
   def SVUCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "UcUsUiUl", 
MergeNone, "aarch64_sve_uclamp_single_x4",  [IsStreaming], []>;
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
+
+  let TargetGuard = "b16b16"in {
+def SVBFCLAMP_X2 : SInst<"svclamp[_single_{d}_x2]",  "22dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x2",  [IsStreaming], []>;
+def SVBFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x4",  [IsStreaming], []>;
+  }
 }
 
 let TargetGuard = "sme2" in {
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
index 257cb595250181..1dd5aeee35fe73 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
@@ -1,12 +1,12 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // REQUIRES: aarch64-registered-target
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 \
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 \
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 \
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
-// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 \
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 \
 // RUN:  -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
@@ -745,3 +745,67 @@ svfloat32x4_t test_svclamp_single_f32_x4(svfloat32x4_t 
op1, svfloat32_t op2, svf
 svfloat64x4_t test_svclamp_single_f64_x4(svfloat64x4_t op1, svfloat64_t op2, 
svfloat64_t op3) __arm_streaming {
   return SVE_ACLE_FUNC(svclamp, _single_f64_x4, , )(op1, op2, op3);
 }
+
+// CHECK-LABEL: @test_svclamp_single_bf16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
+// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
+// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
+// CHECK-NEXT:ret  [[TMP6]]
+//
+// CPP-CHECK-LABEL: 
@_Z27test_svclamp_single_bf16_x214svbfloat16x2_tu14__SVBfloat16_tS0_(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CPP-CHE

[clang] 1709eac - [clang][Interp] Integral pointers (#84159)

2024-04-10 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-04-10T12:53:54+02:00
New Revision: 1709eac58fee8f559cd70cfce9e7f09192dcb1bc

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

LOG: [clang][Interp] Integral pointers (#84159)

This turns the current `Pointer` class into a discriminated union of
`BlockPointer` and `IntPointer`. The former is what `Pointer` currently
is while the latter is just an integer value and an optional
`Descriptor*`.

The `Pointer` then has type check functions like
`isBlockPointer()`/`isIntegralPointer()`/`asBlockPointer()`/`asIntPointer()`,
which can be used to access its data.

Right now, the `IntPointer` and `BlockPointer` structs do not have any
methods of their own and everything is instead implemented in Pointer
(like it was before) and the functions now just either assert for the
right type or decide what to do based on it.

This also implements bitcasts by decaying the pointer to an integral
pointer.

`test/AST/Interp/const-eval.c` is a new test testing all kinds of stuff
related to this. It still has a few tests `#ifdef`-ed out but that
mostly depends on other unimplemented things like
`__builtin_constant_p`.

Added: 
clang/test/AST/Interp/const-eval.c

Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/Descriptor.h
clang/lib/AST/Interp/FunctionPointer.h
clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpBlock.cpp
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/Pointer.cpp
clang/lib/AST/Interp/Pointer.h
clang/lib/AST/Interp/PrimType.h
clang/test/AST/Interp/c.c
clang/test/AST/Interp/functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index acff63cd9dc022..84bacd457c85b5 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -173,10 +173,18 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 return this->emitCastFloatingIntegral(*ToT, CE);
   }
 
-  case CK_NullToPointer:
+  case CK_NullToPointer: {
 if (DiscardResult)
   return true;
-return this->emitNull(classifyPrim(CE->getType()), CE);
+
+const Descriptor *Desc = nullptr;
+const QualType PointeeType = CE->getType()->getPointeeType();
+if (!PointeeType.isNull()) {
+  if (std::optional T = classify(PointeeType))
+Desc = P.createDescriptor(SubExpr, *T);
+}
+return this->emitNull(classifyPrim(CE->getType()), Desc, CE);
+  }
 
   case CK_PointerToIntegral: {
 if (DiscardResult)
@@ -199,6 +207,41 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 return true;
   }
 
+  case CK_IntegralToPointer: {
+QualType IntType = SubExpr->getType();
+assert(IntType->isIntegralOrEnumerationType());
+if (!this->visit(SubExpr))
+  return false;
+// FIXME: I think the discard is wrong since the int->ptr cast might cause 
a
+// diagnostic.
+PrimType T = classifyPrim(IntType);
+if (DiscardResult)
+  return this->emitPop(T, CE);
+
+QualType PtrType = CE->getType();
+assert(PtrType->isPointerType());
+
+const Descriptor *Desc;
+if (std::optional T = classify(PtrType->getPointeeType()))
+  Desc = P.createDescriptor(SubExpr, *T);
+else if (PtrType->getPointeeType()->isVoidType())
+  Desc = nullptr;
+else
+  Desc = P.createDescriptor(CE, PtrType->getPointeeType().getTypePtr(),
+Descriptor::InlineDescMD, true, false,
+/*IsMutable=*/false, nullptr);
+
+if (!this->emitGetIntPtr(T, Desc, CE))
+  return false;
+
+PrimType DestPtrT = classifyPrim(PtrType);
+if (DestPtrT == PT_Ptr)
+  return true;
+
+// In case we're converting the integer to a non-Pointer.
+return this->emitDecayPtr(PT_Ptr, DestPtrT, CE);
+  }
+
   case CK_AtomicToNonAtomic:
   case CK_ConstructorConversion:
   case CK_FunctionToPointerDecay:
@@ -207,13 +250,31 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
   case CK_UserDefinedConversion:
 return this->delegate(SubExpr);
 
-  case CK_BitCast:
+  case CK_BitCast: {
+// Reject bitcasts to atomic types.
 if (CE->getType()->isAtomicType()) {
   if (!this->discard(SubExpr))
 return false;
   return this->emitInvalidCast(CastKind::Reinterpret, CE);
 }
-return this->delegate(SubExpr);
+
+if (DiscardResult)
+  return this->discard(SubExpr);
+
+std::optional FromT = classify(SubExpr->getType());
+std::optional ToT = classifyPrim(CE->getType());
+if (!FromT || !ToT)
+  return false;
+
+assert(isPtrType(*FromT));
+assert(isPtrType(*ToT));
+if 

[clang] [clang][Interp] Integral pointers (PR #84159)

2024-04-10 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr closed 
https://github.com/llvm/llvm-project/pull/84159
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 89ba7e1 - [codegen] Emit missing cleanups for stmt-expr and coro suspensions [take-2] (#85398)

2024-04-10 Thread via cfe-commits

Author: Utkarsh Saxena
Date: 2024-04-10T12:59:24+02:00
New Revision: 89ba7e183e6e2c64370ed1b963e54c06352211db

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

LOG: [codegen] Emit missing cleanups for stmt-expr and coro suspensions 
[take-2] (#85398)

Fixes https://github.com/llvm/llvm-project/issues/63818 for control flow
out of an expressions.

 Background

A control flow could happen in the middle of an expression due to
stmt-expr and coroutine suspensions.

Due to branch-in-expr, we missed running cleanups for the temporaries
constructed in the expression before the branch.
Previously, these cleanups were only added as `EHCleanup` during the
expression and as normal expression after the full expression.

Examples of such deferred cleanups include:

`ParenList/InitList`: Cleanups for fields are performed by the
destructor of the object being constructed.
`Array init`: Cleanup for elements of an array is included in the array
cleanup.
`Lifetime-extended temporaries`: reference-binding temporaries in
braced-init are lifetime extended to the parent scope.
`Lambda capture init`: init in the lambda capture list is destroyed by
the lambda object.

---

 In this PR

In this PR, we change some of the `EHCleanups` cleanups to
`NormalAndEHCleanups` to make sure these are emitted when we see a
branch inside an expression (through statement expressions or coroutine
suspensions).

These are supposed to be deactivated after full expression and destroyed
later as part of the destructor of the aggregate or array being
constructed. To simplify deactivating cleanups, we add two utilities as
well:
* `DeferredDeactivationCleanupStack`: A stack to remember cleanups with
deferred deactivation.
* `CleanupDeactivationScope`: RAII for deactivating cleanups added to
the above stack.

---

 Deactivating normal cleanups
These were previously `EHCleanups` and not `Normal` and **deactivation**
of **required** `Normal` cleanups had some bugs. These specifically
include deactivating `Normal` cleanups which are not the top of
`EHStack`
[source1](https://github.com/llvm/llvm-project/blob/92b56011e6b61e7dc1628c0431ece432f282b3cb/clang/lib/CodeGen/CGCleanup.cpp#L1319),
[2](https://github.com/llvm/llvm-project/blob/92b56011e6b61e7dc1628c0431ece432f282b3cb/clang/lib/CodeGen/CGCleanup.cpp#L722-L746).
This has not been part of our test suite (maybe it was never required
before statement expressions). In this PR, we also fix the emission of
required-deactivated-normal cleanups.

Added: 
clang/test/CodeGenCXX/control-flow-in-stmt-expr.cpp
clang/test/CodeGenCoroutines/coro-suspend-cleanups.cpp

Modified: 
clang/lib/CodeGen/CGCleanup.cpp
clang/lib/CodeGen/CGCleanup.h
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenFunction.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index e6f8e6873004f2..5bf48bc22a5495 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -667,7 +667,8 @@ void CodeGenFunction::PopCleanupBlock(bool 
FallthroughIsBranchThrough) {
 
   // - whether there's a fallthrough
   llvm::BasicBlock *FallthroughSource = Builder.GetInsertBlock();
-  bool HasFallthrough = (FallthroughSource != nullptr && IsActive);
+  bool HasFallthrough =
+  FallthroughSource != nullptr && (IsActive || HasExistingBranches);
 
   // Branch-through fall-throughs leave the insertion point set to the
   // end of the last cleanup, which points to the current scope.  The
@@ -692,7 +693,11 @@ void CodeGenFunction::PopCleanupBlock(bool 
FallthroughIsBranchThrough) {
 
   // If we have a prebranched fallthrough into an inactive normal
   // cleanup, rewrite it so that it leads to the appropriate place.
-  if (Scope.isNormalCleanup() && HasPrebranchedFallthrough && !IsActive) {
+  if (Scope.isNormalCleanup() && HasPrebranchedFallthrough &&
+  !RequiresNormalCleanup) {
+// FIXME: Come up with a program which would need forwarding prebranched
+// fallthrough and add tests. Otherwise delete this and assert against it.
+assert(!IsActive);
 llvm::BasicBlock *prebranchDest;
 
 // If the prebranch is semantically branching through the next
@@ -765,6 +770,7 @@ void CodeGenFunction::PopCleanupBlock(bool 
FallthroughIsBranchThrough) {
 EmitSehCppScopeEnd();
 }
 destroyOptimisticNormalEntry(*this, Scope);
+Scope.MarkEmitted();
 EHStack.popCleanup();
   } else {
 // If we have a fallthrough and no other need for the cleanup,
@@ -781,6 +787,7 @@ void CodeGenFunction::PopCleanupBlock(bool 
FallthroughIsBranchThrough) {
   }
 
   d

[clang] [codegen] Emit missing cleanups for stmt-expr and coro suspensions [take-2] (PR #85398)

2024-04-10 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 closed https://github.com/llvm/llvm-project/pull/85398
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Avoid guessing unexpanded packs' size in getFullyPackExpandedSize (PR #87768)

2024-04-10 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/87768

>From bcebf176cd078c59bca9a2301931f0ec072b66c7 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 5 Apr 2024 19:12:28 +0800
Subject: [PATCH] [Clang][Sema] Avoid guessing unexpanded packs' size in
 getFullyPackExpandedSize

There has been an optimization for SizeOfPackExprs since c5452ed94, in which
we overlooked a case where the template arguments were not yet
formed into a PackExpansionType at the token annotation stage. This
led to a problem in that a template involving such expressions may
lose its nature of being dependent, causing some false-positive
diagnostics.

Fixes https://github.com/llvm/llvm-project/issues/84220
---
 clang/docs/ReleaseNotes.rst |  1 +
 clang/lib/Sema/SemaTemplateVariadic.cpp | 11 ++
 clang/test/SemaTemplate/alias-templates.cpp | 23 +
 3 files changed, 35 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 28e8ddb3c41c3e..4501bf3e8fe99f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -504,6 +504,7 @@ Bug Fixes to C++ Support
 - Fix crash when inheriting from a cv-qualified type. Fixes:
   (`#35603 `_)
 - Fix a crash when the using enum declaration uses an anonymous enumeration. 
Fixes (#GH86790).
+- Handled an edge case in ``getFullyPackExpandedSize`` so that we now avoid a 
false-positive diagnostic. (#GH84220)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 903fbfd18e779c..4909414c0c78d4 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1243,6 +1243,17 @@ std::optional 
Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
 // expanded this pack expansion into the enclosing pack if we could.
 if (Elem.isPackExpansion())
   return std::nullopt;
+// Don't guess the size of unexpanded packs. The pack within a template
+// argument may have yet to be of a PackExpansion type before we see the
+// ellipsis in the annotation stage.
+//
+// This doesn't mean we would invalidate the optimization: Arg can be an
+// unexpanded pack regardless of Elem's dependence. For instance,
+// A TemplateArgument that contains either a SubstTemplateTypeParmPackType
+// or SubstNonTypeTemplateParmPackExpr is always considered Unexpanded, but
+// the underlying TemplateArgument thereof may not.
+if (Elem.containsUnexpandedParameterPack())
+  return std::nullopt;
   }
   return Pack.pack_size();
 }
diff --git a/clang/test/SemaTemplate/alias-templates.cpp 
b/clang/test/SemaTemplate/alias-templates.cpp
index 8d7cc6118610a0..ab5cad72faf1b7 100644
--- a/clang/test/SemaTemplate/alias-templates.cpp
+++ b/clang/test/SemaTemplate/alias-templates.cpp
@@ -236,6 +236,29 @@ namespace PR14858 {
   void test_q(int (&a)[5]) { Q().f(&a); }
 }
 
+namespace PR84220 {
+
+template  class list {};
+
+template  struct foo_impl {
+  template  using f = int;
+};
+
+template 
+using foo = typename foo_impl::template f;
+
+// We call getFullyPackExpandedSize at the annotation stage
+// before parsing the ellipsis next to the foo. This happens before
+// a PackExpansionType is formed for foo.
+// getFullyPackExpandedSize shouldn't determine the value here. Otherwise,
+// foo_impl would lose its dependency despite the template
+// arguments being unsubstituted.
+template  using test = list...>;
+
+test a;
+
+}
+
 namespace redecl {
   template using A = int;
   template using A = int;

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


[clang] a0651db - [clang][Sema] Avoid guessing unexpanded packs' size in getFullyPackExpandedSize (#87768)

2024-04-10 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-04-10T19:23:32+08:00
New Revision: a0651db490328a972185e44ff637970b3456406b

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

LOG: [clang][Sema] Avoid guessing unexpanded packs' size in 
getFullyPackExpandedSize (#87768)

There has been an optimization for `SizeOfPackExprs` since c5452ed9, in
which
we overlooked a case where the template arguments were not yet
formed into a `PackExpansionType` at the token annotation stage. This
led to a problem in that a template involving such expressions may
lose its nature of being dependent, causing some false-positive
diagnostics.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/test/SemaTemplate/alias-templates.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f96cebbde3d825..6bff80ed4d210b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -526,6 +526,7 @@ Bug Fixes to C++ Support
 - Fix crash when inheriting from a cv-qualified type. Fixes:
   (`#35603 `_)
 - Fix a crash when the using enum declaration uses an anonymous enumeration. 
Fixes (#GH86790).
+- Handled an edge case in ``getFullyPackExpandedSize`` so that we now avoid a 
false-positive diagnostic. (#GH84220)
 - Clang now correctly tracks type dependence of by-value captures in lambdas 
with an explicit
   object parameter.
   Fixes (#GH70604), (#GH79754), (#GH84163), (#GH84425), (#GH86054), 
(#GH86398), and (#GH86399).

diff  --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 903fbfd18e779c..4909414c0c78d4 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1243,6 +1243,17 @@ std::optional 
Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
 // expanded this pack expansion into the enclosing pack if we could.
 if (Elem.isPackExpansion())
   return std::nullopt;
+// Don't guess the size of unexpanded packs. The pack within a template
+// argument may have yet to be of a PackExpansion type before we see the
+// ellipsis in the annotation stage.
+//
+// This doesn't mean we would invalidate the optimization: Arg can be an
+// unexpanded pack regardless of Elem's dependence. For instance,
+// A TemplateArgument that contains either a SubstTemplateTypeParmPackType
+// or SubstNonTypeTemplateParmPackExpr is always considered Unexpanded, but
+// the underlying TemplateArgument thereof may not.
+if (Elem.containsUnexpandedParameterPack())
+  return std::nullopt;
   }
   return Pack.pack_size();
 }

diff  --git a/clang/test/SemaTemplate/alias-templates.cpp 
b/clang/test/SemaTemplate/alias-templates.cpp
index 8d7cc6118610a0..ab5cad72faf1b7 100644
--- a/clang/test/SemaTemplate/alias-templates.cpp
+++ b/clang/test/SemaTemplate/alias-templates.cpp
@@ -236,6 +236,29 @@ namespace PR14858 {
   void test_q(int (&a)[5]) { Q().f(&a); }
 }
 
+namespace PR84220 {
+
+template  class list {};
+
+template  struct foo_impl {
+  template  using f = int;
+};
+
+template 
+using foo = typename foo_impl::template f;
+
+// We call getFullyPackExpandedSize at the annotation stage
+// before parsing the ellipsis next to the foo. This happens before
+// a PackExpansionType is formed for foo.
+// getFullyPackExpandedSize shouldn't determine the value here. Otherwise,
+// foo_impl would lose its dependency despite the template
+// arguments being unsubstituted.
+template  using test = list...>;
+
+test a;
+
+}
+
 namespace redecl {
   template using A = int;
   template using A = int;



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


[clang] [clang][Sema] Avoid guessing unexpanded packs' size in getFullyPackExpandedSize (PR #87768)

2024-04-10 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 closed 
https://github.com/llvm/llvm-project/pull/87768
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Introduce `SemaSYCL` (PR #88086)

2024-04-10 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/88086
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Allow renaming macro arguments (PR #87792)

2024-04-10 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman closed 
https://github.com/llvm/llvm-project/pull/87792
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 8d206f5 - [clang-tidy] Allow renaming macro arguments (#87792)

2024-04-10 Thread via cfe-commits

Author: Edwin Vane
Date: 2024-04-10T07:40:35-04:00
New Revision: 8d206f51497fdf1ceebd6430b2f7d31ef735d0dc

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

LOG: [clang-tidy] Allow renaming macro arguments (#87792)

Although the identifier-naming.cpp lit test expected macro arguments not
to be renamed, the code seemed to already allow it. The code was simply
not being exercised because a SourceManager argument wasn't being
provided. With this change, renaming of macro arguments that expand to
renamable decls is permitted.

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 69b7d40ef628d6..ad8048e2a92b7e 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -489,7 +489,7 @@ void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl 
*Decl,
   }
 
   Failure.Info = std::move(Info);
-  addUsage(Decl, Range);
+  addUsage(Decl, Range, &SourceMgr);
 }
 
 void RenamerClangTidyCheck::check(const MatchFinder::MatchResult &Result) {

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a7193e90c38da2..b66be44e9f8a6f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -268,7 +268,7 @@ Changes in existing checks
   ` check in 
`GetConfigPerFile`
   mode by resolving symbolic links to header files. Fixed handling of Hungarian
   Prefix when configured to `LowerCase`. Added support for renaming designated
-  initializers.
+  initializers. Added support for renaming macro arguments.
 
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
index 57ef4aae5ddb78..99149fe86aceec 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -108,10 +108,12 @@ USER_NS::object g_s2;
 // NO warnings or fixes expected as USER_NS and object are declared in a 
header file
 
 SYSTEM_MACRO(var1);
-// NO warnings or fixes expected as var1 is from macro expansion
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for global 
variable 'var1' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}SYSTEM_MACRO(g_var1);
 
 USER_MACRO(var2);
-// NO warnings or fixes expected as var2 is declared in a macro expansion
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global 
variable 'var2' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}USER_MACRO(g_var2);
 
 #define BLA int FOO_bar
 BLA;
@@ -602,9 +604,20 @@ static void static_Function() {
 // CHECK-FIXES: {{^}}#define MY_TEST_MACRO(X) X()
 
 void MY_TEST_Macro(function) {}
-// CHECK-FIXES: {{^}}void MY_TEST_MACRO(function) {}
-}
-}
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for global 
function 'function' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}void MY_TEST_MACRO(Function) {}
+
+#define MY_CAT_IMPL(l, r) l ## r
+#define MY_CAT(l, r) MY_CAT_IMPL(l, r)
+#define MY_MACRO2(foo) int MY_CAT(awesome_, MY_CAT(foo, __COUNTER__)) = 0
+#define MY_MACRO3(foo) int MY_CAT(awesome_, foo) = 0
+MY_MACRO2(myglob);
+MY_MACRO3(myglob);
+// No suggestions should occur even though the resulting decl of 
awesome_myglob#
+// or awesome_myglob are not entirely within a macro argument.
+
+} // namespace InlineNamespace
+} // namespace FOO_NS
 
 template  struct a {
 // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: invalid case style for struct 'a'



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


[clang] [flang] [Flang][AMDGPU] Add rocm-path flag (PR #88190)

2024-04-10 Thread Dominik Adamski via cfe-commits

https://github.com/DominikAdamski updated 
https://github.com/llvm/llvm-project/pull/88190

>From 44def17f36e8e27eb4232681e5ae7eff5de6d90f Mon Sep 17 00:00:00 2001
From: Dominik Adamski 
Date: Tue, 9 Apr 2024 14:35:26 -0500
Subject: [PATCH 1/3] [Flang][AMDGPU] Add rocm-path flag

ROCm installation path is used for finding and automatically
linking required bitcode libraries.
---
 clang/include/clang/Driver/Options.td|  3 ++-
 clang/lib/Driver/ToolChains/Flang.cpp|  4 
 flang/test/Driver/driver-help-hidden.f90 |  1 +
 flang/test/Driver/driver-help.f90|  1 +
 flang/test/Driver/omp-driver-offload.f90 | 21 +
 5 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f745e573eb2686..651aa10150c06e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1341,7 +1341,8 @@ def hip_link : Flag<["--"], "hip-link">, 
Group,
   HelpText<"Link clang-offload-bundler bundles for HIP">;
 def no_hip_rt: Flag<["-"], "no-hip-rt">, Group,
   HelpText<"Do not link against HIP runtime libraries">;
-def rocm_path_EQ : Joined<["--"], "rocm-path=">, Group,
+def rocm_path_EQ : Joined<["--"], "rocm-path=">,
+  Visibility<[FlangOption]>, Group,
   HelpText<"ROCm installation path, used for finding and automatically linking 
required bitcode libraries.">;
 def hip_path_EQ : Joined<["--"], "hip-path=">, Group,
   HelpText<"HIP runtime installation path, used for finding HIP version and 
adding HIP include path.">;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 2c83f70eb7887e..75e4ead81e43ed 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -342,6 +342,10 @@ void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
 StringRef Val = A->getValue();
 CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
   }
+
+  // Check ROCm path if specified
+  const ToolChain &TC = getToolChain();
+  TC.getDeviceLibs(Args);
 }
 
 void Flang::addTargetOptions(const ArgList &Args,
diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 48f48f5384fdc5..10b15fb454b9aa 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -144,6 +144,7 @@
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
 ! CHECK-NEXT: -pthreadSupport POSIX threads in generated code
 ! CHECK-NEXT: -P  Disable linemarker output in -E mode
+! CHECK-NEXT: --rocm-path= ROCm installation path, used for finding and 
automatically linking required bitcode libraries.
 ! CHECK-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! CHECK-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
 ! CHECK-NEXT: -Rpass=  Report transformations performed by 
optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index 38f74395a678ab..ed5af2a68eb044 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -132,6 +132,7 @@
 ! HELP-NEXT: -print-target-triplePrint the normalized target triple
 ! HELP-NEXT: -pthreadSupport POSIX threads in generated code
 ! HELP-NEXT: -P  Disable linemarker output in -E mode
+! HELP-NEXT:  --rocm-path= ROCm installation path, used for finding and 
automatically linking required bitcode libraries.
 ! HELP-NEXT: -Rpass-analysis= Report transformation analysis from 
optimization passes whose name matches the given POSIX regular expression
 ! HELP-NEXT: -Rpass-missed=   Report missed transformations by 
optimization passes whose name matches the given POSIX regular expression
 ! HELP-NEXT: -Rpass=  Report transformations performed by 
optimization passes whose name matches the given POSIX regular expression
diff --git a/flang/test/Driver/omp-driver-offload.f90 
b/flang/test/Driver/omp-driver-offload.f90
index 7e9a73627cd757..836dcfc85eb9de 100644
--- a/flang/test/Driver/omp-driver-offload.f90
+++ b/flang/test/Driver/omp-driver-offload.f90
@@ -201,3 +201,24 @@
 ! RUN:  -nogpulibc %s 2>&1 \
 ! RUN:   | FileCheck --check-prefix=NO-LIBC-GPU-AMDGPU %s
 ! NO-LIBC-GPU-AMDGPU-NOT: "-lcgpu-amdgpu"
+
+! RUN:   rm -rf %t/Inputs
+
+! RUN:   not %flang -### -v --target=x86_64-unknown-linux-gnu -fopenmp  \
+! RUN:  --offload-arch=gfx900 \
+! RUN:  --rocm-path=%t/Inputs/rocm %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=ROCM-PATH-NOT-FOUND %s
+! ROCM-PATH-NOT-FOUND: error: cannot find ROCm device library;
+
+! RUN:   rm -rf %t/Inputs
+! RUN:   mkdir -p %t/Inputs
+! RUN:   cp -r %S/../../../clang/tes

[clang] [clang][test] Avoid writing to a potentially write-protected dir (PR #88258)

2024-04-10 Thread Jordan Rupprecht via cfe-commits

https://github.com/rupprecht created 
https://github.com/llvm/llvm-project/pull/88258

This test just checks for the stdout/stderr of clang, but it incidentally tries 
to write to `a.out` in the current directory, which may be write protected. 
Typically one would write `clang -o %t.o` for a writeable dir, but since we 
only care about stdout/stderr, throw away the object file and just write to 
/dev/null instead.

>From b23bfe788d2fba00f8303c54e53507a8fd0bc53b Mon Sep 17 00:00:00 2001
From: Jordan Rupprecht 
Date: Wed, 10 Apr 2024 11:50:04 +
Subject: [PATCH] [clang][test] Avoid writing to a potentially write-protected
 dir

This test just checks for the stdout/stderr of clang, but it incidentally tries 
to write to `a.out` in the current directory, which may be write protected. 
Typically one would write `clang -o %t.o` for a writeable dir, but since we 
only care about stdout/stderr, throw away the object file and just write to 
/dev/null instead.
---
 clang/test/Driver/lld-repro.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/test/Driver/lld-repro.c b/clang/test/Driver/lld-repro.c
index 9457dd334b5b96..61904c0e6df306 100644
--- a/clang/test/Driver/lld-repro.c
+++ b/clang/test/Driver/lld-repro.c
@@ -4,12 +4,12 @@
 // RUN: echo "-nostartfiles -nostdlib -fuse-ld=lld -gen-reproducer=error 
-fcrash-diagnostics-dir=%t" \
 // RUN:   | sed -e 's/\\//g' > %t.rsp
 
-// RUN: not %clang %s @%t.rsp -fcrash-diagnostics=all 2>&1 \
+// RUN: not %clang %s @%t.rsp -fcrash-diagnostics=all -o /dev/null 2>&1 \
 // RUN:   | FileCheck %s
 
 // Test that the reproducer can still be created even when the input source 
cannot be preprocessed
 // again, like when reading from stdin.
-// RUN: not %clang -x c - @%t.rsp -fcrash-diagnostics=all 2>&1 < %s \
+// RUN: not %clang -x c - @%t.rsp -fcrash-diagnostics=all -o /dev/null 2>&1 < 
%s \
 // RUN:   | FileCheck %s
 
 // check that we still get lld's output
@@ -20,9 +20,9 @@
 // CHECK-NEXT: note: diagnostic msg:
 // CHECK: 
 
-// RUN: not %clang %s @%t.rsp -fcrash-diagnostics=compiler 2>&1 \
+// RUN: not %clang %s @%t.rsp -fcrash-diagnostics=compiler -o /dev/null 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=NO-LINKER
-// RUN: not %clang %s @%t.rsp 2>&1 \
+// RUN: not %clang %s @%t.rsp -o /dev/null 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=NO-LINKER
 
 // NO-LINKER-NOT: Preprocessed source(s) and associated run script(s) are 
located at:

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


[clang] [clang][test] Avoid writing to a potentially write-protected dir (PR #88258)

2024-04-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jordan Rupprecht (rupprecht)


Changes

This test just checks for the stdout/stderr of clang, but it incidentally tries 
to write to `a.out` in the current directory, which may be write protected. 
Typically one would write `clang -o %t.o` for a writeable dir, but since we 
only care about stdout/stderr, throw away the object file and just write to 
/dev/null instead.

---
Full diff: https://github.com/llvm/llvm-project/pull/88258.diff


1 Files Affected:

- (modified) clang/test/Driver/lld-repro.c (+4-4) 


``diff
diff --git a/clang/test/Driver/lld-repro.c b/clang/test/Driver/lld-repro.c
index 9457dd334b5b96..61904c0e6df306 100644
--- a/clang/test/Driver/lld-repro.c
+++ b/clang/test/Driver/lld-repro.c
@@ -4,12 +4,12 @@
 // RUN: echo "-nostartfiles -nostdlib -fuse-ld=lld -gen-reproducer=error 
-fcrash-diagnostics-dir=%t" \
 // RUN:   | sed -e 's/\\//g' > %t.rsp
 
-// RUN: not %clang %s @%t.rsp -fcrash-diagnostics=all 2>&1 \
+// RUN: not %clang %s @%t.rsp -fcrash-diagnostics=all -o /dev/null 2>&1 \
 // RUN:   | FileCheck %s
 
 // Test that the reproducer can still be created even when the input source 
cannot be preprocessed
 // again, like when reading from stdin.
-// RUN: not %clang -x c - @%t.rsp -fcrash-diagnostics=all 2>&1 < %s \
+// RUN: not %clang -x c - @%t.rsp -fcrash-diagnostics=all -o /dev/null 2>&1 < 
%s \
 // RUN:   | FileCheck %s
 
 // check that we still get lld's output
@@ -20,9 +20,9 @@
 // CHECK-NEXT: note: diagnostic msg:
 // CHECK: 
 
-// RUN: not %clang %s @%t.rsp -fcrash-diagnostics=compiler 2>&1 \
+// RUN: not %clang %s @%t.rsp -fcrash-diagnostics=compiler -o /dev/null 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=NO-LINKER
-// RUN: not %clang %s @%t.rsp 2>&1 \
+// RUN: not %clang %s @%t.rsp -o /dev/null 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=NO-LINKER
 
 // NO-LINKER-NOT: Preprocessed source(s) and associated run script(s) are 
located at:

``




https://github.com/llvm/llvm-project/pull/88258
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement Default clause for Compute Constructs (PR #88135)

2024-04-10 Thread via cfe-commits

https://github.com/Sirraide edited 
https://github.com/llvm/llvm-project/pull/88135
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement Default clause for Compute Constructs (PR #88135)

2024-04-10 Thread via cfe-commits

https://github.com/Sirraide commented:

Just happened to notice a few typos.

https://github.com/llvm/llvm-project/pull/88135
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement Default clause for Compute Constructs (PR #88135)

2024-04-10 Thread via cfe-commits


@@ -63,8 +79,43 @@ SemaOpenACC::ActOnClause(ArrayRef 
ExistingClauses,
 return nullptr;
   }
 
-  // TODO OpenACC: Switch over the clauses we implement here and 'create'
-  // them.
+  switch (Clause.getClauseKind()) {
+  case OpenACCClauseKind::Default: {
+// Restrictions only properly implemented on 'compute' constructs, and
+// 'compute' constructs are the only construct that can do anything with
+// this yet, so skip/treat as unimplemented in this case.
+if (Clause.getDirectiveKind() != OpenACCDirectiveKind::Parallel &&
+Clause.getDirectiveKind() != OpenACCDirectiveKind::Serial &&
+Clause.getDirectiveKind() != OpenACCDirectiveKind::Kernels)
+  break;
+
+// Don't add an invalid clause to the AST.
+if (Clause.getDefaultClauseKind() == OpenACCDefaultClauseKind::Invalid)
+  return nullptr;
+
+// OpenACC 3.3, Section 2.5.4:
+// At most one 'default' clause may appear, and it must have a value of
+// either 'none' or 'present'.
+// Second half of the sentence is diagnosed during parsing.
+auto Itr = llvm::find_if(ExistingClauses, [](const OpenACCClause *C) {
+  return C->getClauseKind() == OpenACCClauseKind::Default;
+});
+
+if (Itr != ExistingClauses.end()) {
+  SemaRef.Diag(Clause.getBeginLoc(),
+   diag::err_acc_duplicate_clause_diallowed)

Sirraide wrote:

```suggestion
   diag::err_acc_duplicate_clause_disallowed)
```

https://github.com/llvm/llvm-project/pull/88135
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement Default clause for Compute Constructs (PR #88135)

2024-04-10 Thread via cfe-commits


@@ -12254,6 +12254,10 @@ def err_acc_construct_appertainment
 "be used in a statement context">;
 def err_acc_clause_appertainment
 : Error<"OpenACC '%1' clause is not valid on '%0' directive">;
+def err_acc_duplicate_clause_diallowed

Sirraide wrote:

```suggestion
def err_acc_duplicate_clause_disallowed
```

https://github.com/llvm/llvm-project/pull/88135
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][AMDGPU] Add rocm-path flag (PR #88190)

2024-04-10 Thread Dominik Adamski via cfe-commits


@@ -342,6 +342,10 @@ void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
 StringRef Val = A->getValue();
 CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
   }
+
+  // Check ROCm path if specified
+  const ToolChain &TC = getToolChain();
+  TC.getDeviceLibs(Args);

DominikAdamski wrote:

Please look at the recent change:
https://github.com/llvm/llvm-project/pull/88190/commits/5b106231ab0f5432ba788035635a0d9d91b22ce0
Is this solution better?

https://github.com/llvm/llvm-project/pull/88190
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][Frontend] Implement printing defined macros via -dM (PR #87627)

2024-04-10 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/87627

>From f4917dcf99664442d262226cd1ce1058646d7a55 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Wed, 3 Apr 2024 17:09:24 -0500
Subject: [PATCH 01/10] [flang][Frontend] Implement printing defined macros via
 -dM

This should work the same way as in clang.
---
 clang/include/clang/Driver/Options.td |   2 +-
 clang/lib/Driver/ToolChains/Flang.cpp |   5 +-
 .../flang/Frontend/PreprocessorOptions.h  |   3 +
 flang/include/flang/Parser/parsing.h  |   5 +
 flang/lib/Frontend/CompilerInvocation.cpp |   1 +
 flang/lib/Frontend/FrontendActions.cpp|   4 +-
 flang/lib/Parser/parsing.cpp  |  18 ++-
 flang/lib/Parser/preprocessor.cpp | 128 ++
 flang/lib/Parser/preprocessor.h   |   6 +
 flang/test/Driver/driver-help-hidden.f90  |   1 +
 flang/test/Driver/driver-help.f90 |   2 +
 flang/test/Preprocessing/show-macros1.F90 |  14 ++
 flang/test/Preprocessing/show-macros2.F90 |   6 +
 flang/test/Preprocessing/show-macros3.F90 |  10 ++
 14 files changed, 196 insertions(+), 9 deletions(-)
 create mode 100644 flang/test/Preprocessing/show-macros1.F90
 create mode 100644 flang/test/Preprocessing/show-macros2.F90
 create mode 100644 flang/test/Preprocessing/show-macros3.F90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c3e90a70925b78..b1ed29cb1cbc44 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1446,7 +1446,7 @@ def dD : Flag<["-"], "dD">, Group, 
Visibility<[ClangOption, CC1Option]>
 def dI : Flag<["-"], "dI">, Group, Visibility<[ClangOption, 
CC1Option]>,
   HelpText<"Print include directives in -E mode in addition to normal output">,
   MarshallingInfoFlag>;
-def dM : Flag<["-"], "dM">, Group, Visibility<[ClangOption, 
CC1Option]>,
+def dM : Flag<["-"], "dM">, Group, Visibility<[ClangOption, 
CC1Option, FlangOption, FC1Option]>,
   HelpText<"Print macro definitions in -E mode instead of normal output">;
 def dead__strip : Flag<["-"], "dead_strip">;
 def dependency_file : Separate<["-"], "dependency-file">,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 70daa699e3a949..bfd07addfca811 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -688,7 +688,10 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   CmdArgs.push_back(Args.MakeArgString(TripleStr));
 
   if (isa(JA)) {
-  CmdArgs.push_back("-E");
+CmdArgs.push_back("-E");
+if (Args.getLastArg(options::OPT_dM)) {
+  CmdArgs.push_back("-dM");
+}
   } else if (isa(JA) || isa(JA)) {
 if (JA.getType() == types::TY_Nothing) {
   CmdArgs.push_back("-fsyntax-only");
diff --git a/flang/include/flang/Frontend/PreprocessorOptions.h 
b/flang/include/flang/Frontend/PreprocessorOptions.h
index b2e9ac0e963b73..13a91ee9a184f8 100644
--- a/flang/include/flang/Frontend/PreprocessorOptions.h
+++ b/flang/include/flang/Frontend/PreprocessorOptions.h
@@ -56,6 +56,9 @@ struct PreprocessorOptions {
   // -fno-reformat: Emit cooked character stream as -E output
   bool noReformat{false};
 
+  // -dM: Show macro definitions with -dM -E
+  bool showMacros{false};
+
   void addMacroDef(llvm::StringRef name) {
 macros.emplace_back(std::string(name), false);
   }
diff --git a/flang/include/flang/Parser/parsing.h 
b/flang/include/flang/Parser/parsing.h
index e80d8f724ac8f4..14891c44dacafd 100644
--- a/flang/include/flang/Parser/parsing.h
+++ b/flang/include/flang/Parser/parsing.h
@@ -16,6 +16,7 @@
 #include "provenance.h"
 #include "flang/Common/Fortran-features.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 #include 
 #include 
 #include 
@@ -23,6 +24,8 @@
 
 namespace Fortran::parser {
 
+class Preprocessor;
+
 struct Options {
   Options() {}
 
@@ -59,6 +62,7 @@ class Parsing {
   const SourceFile *Prescan(const std::string &path, Options);
   void EmitPreprocessedSource(
   llvm::raw_ostream &, bool lineDirectives = true) const;
+  void EmitPreprocessorMacros(llvm::raw_ostream &) const;
   void DumpCookedChars(llvm::raw_ostream &) const;
   void DumpProvenance(llvm::raw_ostream &) const;
   void DumpParsingLog(llvm::raw_ostream &) const;
@@ -83,6 +87,7 @@ class Parsing {
   const char *finalRestingPlace_{nullptr};
   std::optional parseTree_;
   ParsingLog log_;
+  std::unique_ptr preprocessor_;
 };
 } // namespace Fortran::parser
 #endif // FORTRAN_PARSER_PARSING_H_
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index c830c7af2462c9..8ce6ab7baf4812 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -772,6 +772,7 @@ static void 
parsePreprocessorArgs(Fortran::frontend::PreprocessorOptions &opts,
 
   opts.noReformat = args.ha

[clang] [flang] [flang][Frontend] Implement printing defined macros via -dM (PR #87627)

2024-04-10 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/87627

>From f4917dcf99664442d262226cd1ce1058646d7a55 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Wed, 3 Apr 2024 17:09:24 -0500
Subject: [PATCH 01/11] [flang][Frontend] Implement printing defined macros via
 -dM

This should work the same way as in clang.
---
 clang/include/clang/Driver/Options.td |   2 +-
 clang/lib/Driver/ToolChains/Flang.cpp |   5 +-
 .../flang/Frontend/PreprocessorOptions.h  |   3 +
 flang/include/flang/Parser/parsing.h  |   5 +
 flang/lib/Frontend/CompilerInvocation.cpp |   1 +
 flang/lib/Frontend/FrontendActions.cpp|   4 +-
 flang/lib/Parser/parsing.cpp  |  18 ++-
 flang/lib/Parser/preprocessor.cpp | 128 ++
 flang/lib/Parser/preprocessor.h   |   6 +
 flang/test/Driver/driver-help-hidden.f90  |   1 +
 flang/test/Driver/driver-help.f90 |   2 +
 flang/test/Preprocessing/show-macros1.F90 |  14 ++
 flang/test/Preprocessing/show-macros2.F90 |   6 +
 flang/test/Preprocessing/show-macros3.F90 |  10 ++
 14 files changed, 196 insertions(+), 9 deletions(-)
 create mode 100644 flang/test/Preprocessing/show-macros1.F90
 create mode 100644 flang/test/Preprocessing/show-macros2.F90
 create mode 100644 flang/test/Preprocessing/show-macros3.F90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c3e90a70925b78..b1ed29cb1cbc44 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1446,7 +1446,7 @@ def dD : Flag<["-"], "dD">, Group, 
Visibility<[ClangOption, CC1Option]>
 def dI : Flag<["-"], "dI">, Group, Visibility<[ClangOption, 
CC1Option]>,
   HelpText<"Print include directives in -E mode in addition to normal output">,
   MarshallingInfoFlag>;
-def dM : Flag<["-"], "dM">, Group, Visibility<[ClangOption, 
CC1Option]>,
+def dM : Flag<["-"], "dM">, Group, Visibility<[ClangOption, 
CC1Option, FlangOption, FC1Option]>,
   HelpText<"Print macro definitions in -E mode instead of normal output">;
 def dead__strip : Flag<["-"], "dead_strip">;
 def dependency_file : Separate<["-"], "dependency-file">,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 70daa699e3a949..bfd07addfca811 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -688,7 +688,10 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   CmdArgs.push_back(Args.MakeArgString(TripleStr));
 
   if (isa(JA)) {
-  CmdArgs.push_back("-E");
+CmdArgs.push_back("-E");
+if (Args.getLastArg(options::OPT_dM)) {
+  CmdArgs.push_back("-dM");
+}
   } else if (isa(JA) || isa(JA)) {
 if (JA.getType() == types::TY_Nothing) {
   CmdArgs.push_back("-fsyntax-only");
diff --git a/flang/include/flang/Frontend/PreprocessorOptions.h 
b/flang/include/flang/Frontend/PreprocessorOptions.h
index b2e9ac0e963b73..13a91ee9a184f8 100644
--- a/flang/include/flang/Frontend/PreprocessorOptions.h
+++ b/flang/include/flang/Frontend/PreprocessorOptions.h
@@ -56,6 +56,9 @@ struct PreprocessorOptions {
   // -fno-reformat: Emit cooked character stream as -E output
   bool noReformat{false};
 
+  // -dM: Show macro definitions with -dM -E
+  bool showMacros{false};
+
   void addMacroDef(llvm::StringRef name) {
 macros.emplace_back(std::string(name), false);
   }
diff --git a/flang/include/flang/Parser/parsing.h 
b/flang/include/flang/Parser/parsing.h
index e80d8f724ac8f4..14891c44dacafd 100644
--- a/flang/include/flang/Parser/parsing.h
+++ b/flang/include/flang/Parser/parsing.h
@@ -16,6 +16,7 @@
 #include "provenance.h"
 #include "flang/Common/Fortran-features.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 #include 
 #include 
 #include 
@@ -23,6 +24,8 @@
 
 namespace Fortran::parser {
 
+class Preprocessor;
+
 struct Options {
   Options() {}
 
@@ -59,6 +62,7 @@ class Parsing {
   const SourceFile *Prescan(const std::string &path, Options);
   void EmitPreprocessedSource(
   llvm::raw_ostream &, bool lineDirectives = true) const;
+  void EmitPreprocessorMacros(llvm::raw_ostream &) const;
   void DumpCookedChars(llvm::raw_ostream &) const;
   void DumpProvenance(llvm::raw_ostream &) const;
   void DumpParsingLog(llvm::raw_ostream &) const;
@@ -83,6 +87,7 @@ class Parsing {
   const char *finalRestingPlace_{nullptr};
   std::optional parseTree_;
   ParsingLog log_;
+  std::unique_ptr preprocessor_;
 };
 } // namespace Fortran::parser
 #endif // FORTRAN_PARSER_PARSING_H_
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index c830c7af2462c9..8ce6ab7baf4812 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -772,6 +772,7 @@ static void 
parsePreprocessorArgs(Fortran::frontend::PreprocessorOptions &opts,
 
   opts.noReformat = args.ha

[clang] [llvm] [AArch64][SME] Add intrinsics for vector groups ZERO (PR #88114)

2024-04-10 Thread via cfe-commits


@@ -0,0 +1,94 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc -verify-machineinstrs < %s | FileCheck %s
+
+target triple = "aarch64-linux"
+
+define  void @test_svzero_za64_vg1x2(i32  %slice)  #0 {

CarolineConcatto wrote:

Can you add tests for when slice is not zero. Something like:
define  void @test_svzero_za64_vg1x2(i32  %slice)  #0 {
 tail call void @llvm.aarch64.sme.zero.za64.vg1x2(i32 %slice)
%slice.max = add i32 %slice, 7
tail call void @llvm.aarch64.sme.zero.za64.vg1x2(i32 %slice.max)
ret void
}


https://github.com/llvm/llvm-project/pull/88114
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64][SME] Add intrinsics for vector groups ZERO (PR #88114)

2024-04-10 Thread via cfe-commits


@@ -4774,39 +4784,57 @@ class sme2p1_zero_matrix opc, Operand index_ty, 
string mnemonic,
 }
 
 multiclass sme2p1_zero_matrix {
-  def _VG2_Z : sme2p1_zero_matrix<{0b000,?,?,?}, sme_elm_idx0_7, mnemonic, 
"vgx2"> {
+  def _VG2_Z : sme2p1_zero_matrix<{0b000,?,?,?}, sme_elm_idx0_7, mnemonic, 
"vgx2">, SMEPseudo2Instr {
 bits<3> imm;
 let Inst{2-0} = imm;
   }
-  def _2Z : sme2p1_zero_matrix<{0b001,?,?,?}, uimm3s2range, mnemonic> {
+  def _2Z : sme2p1_zero_matrix<{0b001,?,?,?}, uimm3s2range, mnemonic>, 
SMEPseudo2Instr {
 bits<3> imm;
 let Inst{2-0} = imm;
   }
-  def _VG2_2Z : sme2p1_zero_matrix<{0b0100,?,?}, uimm2s2range, mnemonic, 
"vgx2"> {
+  def _VG2_2Z : sme2p1_zero_matrix<{0b0100,?,?}, uimm2s2range, mnemonic, 
"vgx2">, SMEPseudo2Instr {
 bits<2> imm;
 let Inst{1-0} = imm;
   }
-  def _VG4_2Z : sme2p1_zero_matrix<{0b0110,?,?}, uimm2s2range, mnemonic, 
"vgx4"> {
+  def _VG4_2Z : sme2p1_zero_matrix<{0b0110,?,?}, uimm2s2range, mnemonic, 
"vgx4">, SMEPseudo2Instr {
 bits<2> imm;
 let Inst{1-0} = imm;
   }
-  def _VG4_Z : sme2p1_zero_matrix<{0b100,?,?,?}, sme_elm_idx0_7, mnemonic, 
"vgx4"> {
+  def _VG4_Z : sme2p1_zero_matrix<{0b100,?,?,?}, sme_elm_idx0_7, mnemonic, 
"vgx4">, SMEPseudo2Instr {
 bits<3> imm;
 let Inst{2-0} = imm;
   }
-  def _4Z : sme2p1_zero_matrix<{0b1010,?,?}, uimm2s4range, mnemonic> {
+  def _4Z : sme2p1_zero_matrix<{0b1010,?,?}, uimm2s4range, mnemonic>, 
SMEPseudo2Instr {
 bits<2> imm;
 let Inst{1-0} = imm;
   }
-  def _VG2_4Z :sme2p1_zero_matrix<{0b11000,?}, uimm1s4range, mnemonic, "vgx2"> 
{
+  def _VG2_4Z : sme2p1_zero_matrix<{0b11000,?}, uimm1s4range, mnemonic, 
"vgx2">, SMEPseudo2Instr {
 bits<1> imm;
 let Inst{0}   = imm;
   }
-  def _VG4_4Z :sme2p1_zero_matrix<{0b11100,?}, uimm1s4range, mnemonic, "vgx4"> 
{
+  def _VG4_4Z : sme2p1_zero_matrix<{0b11100,?}, uimm1s4range, mnemonic, 
"vgx4">, SMEPseudo2Instr {
 bits<1> imm;
 let Inst{0}   = imm;
   }
-}
+
+  def NAME # _VG2_Z_PSEUDO : sem2p1_zero_matrix_pseudo;
+  def NAME # _VG4_Z_PSEUDO : sem2p1_zero_matrix_pseudo;
+  def NAME # _2Z_PSEUDO : sem2p1_zero_matrix_pseudo;
+  def NAME # _VG2_2Z_PSEUDO : sem2p1_zero_matrix_pseudo;
+  def NAME # _VG4_2Z_PSEUDO : sem2p1_zero_matrix_pseudo;
+  def NAME # _4Z_PSEUDO : sem2p1_zero_matrix_pseudo;
+  def NAME # _VG2_4Z_PSEUDO : sem2p1_zero_matrix_pseudo;
+  def NAME # _VG4_4Z_PSEUDO : sem2p1_zero_matrix_pseudo;
+
+  def : SME2_Zero_Matrix_Pat;

CarolineConcatto wrote:

Nothing to do here, but just to document that 
After debating with myself and reading the ACLE spec about vg1x2 and vg2x1 I 
think that the instructions and the vgs are correct.

```
*   Intrinsic functions have a `_vg1x2`, `_vg1x4` suffix if the function
operates on 2 or 4 single-vector groups within the ZA array.
*   Intrinsic functions have a `_vg2x1`, `_vg2x2`, `_vg2x4` suffix if
the function operates on 1, 2 or 4 double-vector groups within the ZA array.
*   Intrinsic functions have a `_vg4x1`, `_vg4x2`, `_vg4x4` suffix if the
function operates on 1, 2 or 4 quad-vector groups within the ZA array.
For example:
```


https://github.com/llvm/llvm-project/pull/88114
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][AMDGPU] Add rocm-path flag (PR #88190)

2024-04-10 Thread Dominik Adamski via cfe-commits


@@ -345,7 +345,13 @@ void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
 
   // Check ROCm path if specified
   const ToolChain &TC = getToolChain();
-  TC.getDeviceLibs(Args);
+  std::string HIPVersion;
+  llvm::raw_string_ostream HIPInfo(HIPVersion);
+  TC.printVerboseInfo(HIPInfo);
+  llvm::StringRef HIPInfoStrRef(HIPInfo.str());
+  if (!HIPInfoStrRef.contains("Found HIP installation") &&

DominikAdamski wrote:

Note: I can extract the `Found HIP installation` string into a separate 
constant so that it can be used by both clang and flang.

https://github.com/llvm/llvm-project/pull/88190
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (PR #87541)

2024-04-10 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

@rupprecht That's unintended, will revert and address it.

https://github.com/llvm/llvm-project/pull/87541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function" (PR #88264)

2024-04-10 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian created 
https://github.com/llvm/llvm-project/pull/88264

Reverts llvm/llvm-project#87541

>From 0fa09befb37c36ec1ed796c28f6b33605fc04ecd Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 10 Apr 2024 08:36:37 -0400
Subject: [PATCH] =?UTF-8?q?Revert=20"[Clang][Sema]=20Fix=20crash=20when=20?=
 =?UTF-8?q?'this'=20is=20used=20in=20a=20dependent=20class=20scop=E2=80=A6?=
 =?UTF-8?q?"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 4657ab1c968e486e9f45329daa07340ebcf3bffd.
---
 clang/docs/ReleaseNotes.rst   |  2 -
 clang/include/clang/Sema/Sema.h   |  8 +---
 clang/lib/Sema/SemaExpr.cpp   |  5 +--
 clang/lib/Sema/SemaExprCXX.cpp| 44 ++-
 clang/lib/Sema/SemaExprMember.cpp | 42 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  8 
 clang/lib/Sema/TreeTransform.h|  7 ++-
 ...ms-function-specialization-class-scope.cpp | 44 ++-
 8 files changed, 36 insertions(+), 124 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6bff80ed4d210b..f5359afe1f0999 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -520,8 +520,6 @@ Bug Fixes to C++ Support
 - Fix an issue caused by not handling invalid cases when substituting into the 
parameter mapping of a constraint. Fixes (#GH86757).
 - Fixed a bug that prevented member function templates of class templates 
declared with a deduced return type
   from being explicitly specialized for a given implicit instantiation of the 
class template.
-- Fixed a crash when ``this`` is used in a dependent class scope function 
template specialization
-  that instantiates to a static member function.
 
 - Fix crash when inheriting from a cv-qualified type. Fixes:
   (`#35603 `_)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f311f9f3743454..9769d36900664c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5439,8 +5439,7 @@ class Sema final : public SemaBase {
 
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R,
   bool NeedsADL,
-  bool AcceptInvalidDecl = false,
-  bool NeedUnresolved = false);
+  bool AcceptInvalidDecl = false);
   ExprResult BuildDeclarationNameExpr(
   const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl 
*D,
   NamedDecl *FoundD = nullptr,
@@ -6592,10 +6591,7 @@ class Sema final : public SemaBase {
 SourceLocation RParenLoc);
 
    ActOnCXXThis -  Parse 'this' pointer.
-  ExprResult ActOnCXXThis(SourceLocation Loc);
-
-  /// Check whether the type of 'this' is valid in the current context.
-  bool CheckCXXThisType(SourceLocation Loc, QualType Type);
+  ExprResult ActOnCXXThis(SourceLocation loc);
 
   /// Build a CXXThisExpr and mark it referenced in the current context.
   Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 45acbf197ea6b4..594c11788f4e7e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3442,11 +3442,10 @@ static bool 
ShouldLookupResultBeMultiVersionOverload(const LookupResult &R) {
 
 ExprResult Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
   LookupResult &R, bool NeedsADL,
-  bool AcceptInvalidDecl,
-  bool NeedUnresolved) {
+  bool AcceptInvalidDecl) {
   // If this is a single, fully-resolved result and we don't need ADL,
   // just build an ordinary singleton decl ref.
-  if (!NeedUnresolved && !NeedsADL && R.isSingleResult() &&
+  if (!NeedsADL && R.isSingleResult() &&
   !R.getAsSingle() &&
   !ShouldLookupResultBeMultiVersionOverload(R))
 return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), 
R.getFoundDecl(),
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 9822477260e592..7b9b8f149d9edd 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1415,42 +1415,26 @@ bool Sema::CheckCXXThisCapture(SourceLocation Loc, 
const bool Explicit,
 }
 
 ExprResult Sema::ActOnCXXThis(SourceLocation Loc) {
-  // C++20 [expr.prim.this]p1:
-  //   The keyword this names a pointer to the object for which an
-  //   implicit object member function is invoked or a non-static
-  //   data member's initializer is evaluated.
+  /// C++ 9.3.2: In the body of a non-static member function, the keyword this
+  /// is a non-lvalue expression 

[clang] Revert "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function" (PR #88264)

2024-04-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krystian Stasiowski (sdkrystian)


Changes

Reverts llvm/llvm-project#87541

---
Full diff: https://github.com/llvm/llvm-project/pull/88264.diff


8 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (-2) 
- (modified) clang/include/clang/Sema/Sema.h (+2-6) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+2-3) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+14-30) 
- (modified) clang/lib/Sema/SemaExprMember.cpp (+12-30) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (-8) 
- (modified) clang/lib/Sema/TreeTransform.h (+3-4) 
- (modified) clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp 
(+3-41) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6bff80ed4d210b..f5359afe1f0999 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -520,8 +520,6 @@ Bug Fixes to C++ Support
 - Fix an issue caused by not handling invalid cases when substituting into the 
parameter mapping of a constraint. Fixes (#GH86757).
 - Fixed a bug that prevented member function templates of class templates 
declared with a deduced return type
   from being explicitly specialized for a given implicit instantiation of the 
class template.
-- Fixed a crash when ``this`` is used in a dependent class scope function 
template specialization
-  that instantiates to a static member function.
 
 - Fix crash when inheriting from a cv-qualified type. Fixes:
   (`#35603 `_)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f311f9f3743454..9769d36900664c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5439,8 +5439,7 @@ class Sema final : public SemaBase {
 
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R,
   bool NeedsADL,
-  bool AcceptInvalidDecl = false,
-  bool NeedUnresolved = false);
+  bool AcceptInvalidDecl = false);
   ExprResult BuildDeclarationNameExpr(
   const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl 
*D,
   NamedDecl *FoundD = nullptr,
@@ -6592,10 +6591,7 @@ class Sema final : public SemaBase {
 SourceLocation RParenLoc);
 
    ActOnCXXThis -  Parse 'this' pointer.
-  ExprResult ActOnCXXThis(SourceLocation Loc);
-
-  /// Check whether the type of 'this' is valid in the current context.
-  bool CheckCXXThisType(SourceLocation Loc, QualType Type);
+  ExprResult ActOnCXXThis(SourceLocation loc);
 
   /// Build a CXXThisExpr and mark it referenced in the current context.
   Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 45acbf197ea6b4..594c11788f4e7e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3442,11 +3442,10 @@ static bool 
ShouldLookupResultBeMultiVersionOverload(const LookupResult &R) {
 
 ExprResult Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
   LookupResult &R, bool NeedsADL,
-  bool AcceptInvalidDecl,
-  bool NeedUnresolved) {
+  bool AcceptInvalidDecl) {
   // If this is a single, fully-resolved result and we don't need ADL,
   // just build an ordinary singleton decl ref.
-  if (!NeedUnresolved && !NeedsADL && R.isSingleResult() &&
+  if (!NeedsADL && R.isSingleResult() &&
   !R.getAsSingle() &&
   !ShouldLookupResultBeMultiVersionOverload(R))
 return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), 
R.getFoundDecl(),
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 9822477260e592..7b9b8f149d9edd 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1415,42 +1415,26 @@ bool Sema::CheckCXXThisCapture(SourceLocation Loc, 
const bool Explicit,
 }
 
 ExprResult Sema::ActOnCXXThis(SourceLocation Loc) {
-  // C++20 [expr.prim.this]p1:
-  //   The keyword this names a pointer to the object for which an
-  //   implicit object member function is invoked or a non-static
-  //   data member's initializer is evaluated.
+  /// C++ 9.3.2: In the body of a non-static member function, the keyword this
+  /// is a non-lvalue expression whose value is the address of the object for
+  /// which the function is called.
   QualType ThisTy = getCurrentThisType();
 
-  if (CheckCXXThisType(Loc, ThisTy))
-return ExprError();
+  if (ThisTy.isNull()) {
+DeclContext *DC = getFunctionLevelDeclContext();
 
-  return BuildCXXThisExpr(Loc, ThisTy, /*IsImplicit=*/false);
-}
+if (const auto *Method = dyn_cast(DC);
+Method && Method->isExplicitObjectMe

[clang] b47e439 - Revert "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function" (#88264)

2024-04-10 Thread via cfe-commits

Author: Krystian Stasiowski
Date: 2024-04-10T08:38:49-04:00
New Revision: b47e439559ad03a1b32614f573aad66f145a634d

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

LOG: Revert "[Clang][Sema] Fix crash when 'this' is used in a dependent class 
scope function template specialization that instantiates to a static member 
function" (#88264)

Reverts llvm/llvm-project#87541

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaExprMember.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/TreeTransform.h
clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6bff80ed4d210b..f5359afe1f0999 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -520,8 +520,6 @@ Bug Fixes to C++ Support
 - Fix an issue caused by not handling invalid cases when substituting into the 
parameter mapping of a constraint. Fixes (#GH86757).
 - Fixed a bug that prevented member function templates of class templates 
declared with a deduced return type
   from being explicitly specialized for a given implicit instantiation of the 
class template.
-- Fixed a crash when ``this`` is used in a dependent class scope function 
template specialization
-  that instantiates to a static member function.
 
 - Fix crash when inheriting from a cv-qualified type. Fixes:
   (`#35603 `_)

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f311f9f3743454..9769d36900664c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5439,8 +5439,7 @@ class Sema final : public SemaBase {
 
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R,
   bool NeedsADL,
-  bool AcceptInvalidDecl = false,
-  bool NeedUnresolved = false);
+  bool AcceptInvalidDecl = false);
   ExprResult BuildDeclarationNameExpr(
   const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl 
*D,
   NamedDecl *FoundD = nullptr,
@@ -6592,10 +6591,7 @@ class Sema final : public SemaBase {
 SourceLocation RParenLoc);
 
    ActOnCXXThis -  Parse 'this' pointer.
-  ExprResult ActOnCXXThis(SourceLocation Loc);
-
-  /// Check whether the type of 'this' is valid in the current context.
-  bool CheckCXXThisType(SourceLocation Loc, QualType Type);
+  ExprResult ActOnCXXThis(SourceLocation loc);
 
   /// Build a CXXThisExpr and mark it referenced in the current context.
   Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit);

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 45acbf197ea6b4..594c11788f4e7e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3442,11 +3442,10 @@ static bool 
ShouldLookupResultBeMultiVersionOverload(const LookupResult &R) {
 
 ExprResult Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
   LookupResult &R, bool NeedsADL,
-  bool AcceptInvalidDecl,
-  bool NeedUnresolved) {
+  bool AcceptInvalidDecl) {
   // If this is a single, fully-resolved result and we don't need ADL,
   // just build an ordinary singleton decl ref.
-  if (!NeedUnresolved && !NeedsADL && R.isSingleResult() &&
+  if (!NeedsADL && R.isSingleResult() &&
   !R.getAsSingle() &&
   !ShouldLookupResultBeMultiVersionOverload(R))
 return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), 
R.getFoundDecl(),

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 9822477260e592..7b9b8f149d9edd 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1415,42 +1415,26 @@ bool Sema::CheckCXXThisCapture(SourceLocation Loc, 
const bool Explicit,
 }
 
 ExprResult Sema::ActOnCXXThis(SourceLocation Loc) {
-  // C++20 [expr.prim.this]p1:
-  //   The keyword this names a pointer to the object for which an
-  //   implicit object member function is invoked or a non-static
-  //   data member's initializer is evaluated.
+  /// C++ 9.3.2: In the body of a non-static member function, the keyword this
+  /// is a non-lvalue expression whose value is the address of the object for
+  /// which the function is called.
   QualType ThisTy = getCurrentThisType();
 
-  if (CheckCXXThisType(Loc, Th

[clang] Revert "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function" (PR #88264)

2024-04-10 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian closed 
https://github.com/llvm/llvm-project/pull/88264
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1ca0195 - [Clang][AST][NFC] Fix printing of dependent PackIndexTypes (#88146)

2024-04-10 Thread via cfe-commits

Author: Krystian Stasiowski
Date: 2024-04-10T08:41:22-04:00
New Revision: 1ca01958310f2956abd72ece1652c3218bcf27e1

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

LOG: [Clang][AST][NFC] Fix printing of dependent PackIndexTypes (#88146)

Dependent `PackIndexType`s currently print the memory address of the
index `Expr*` rather than pretty printing the expression. This patch
fixes that.

Added: 


Modified: 
clang/lib/AST/TypePrinter.cpp

Removed: 




diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 075c8aba11fcb9..9602f448e94279 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1213,10 +1213,13 @@ void TypePrinter::printDecltypeBefore(const 
DecltypeType *T, raw_ostream &OS) {
 
 void TypePrinter::printPackIndexingBefore(const PackIndexingType *T,
   raw_ostream &OS) {
-  if (T->hasSelectedType())
+  if (T->hasSelectedType()) {
 OS << T->getSelectedType();
-  else
-OS << T->getPattern() << "...[" << T->getIndexExpr() << "]";
+  } else {
+OS << T->getPattern() << "...[";
+T->getIndexExpr()->printPretty(OS, nullptr, Policy);
+OS << "]";
+  }
   spaceBeforePlaceHolder(OS);
 }
 



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


[clang] [Clang][AST][NFC] Fix printing of dependent PackIndexTypes (PR #88146)

2024-04-10 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian closed 
https://github.com/llvm/llvm-project/pull/88146
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Add intrinsics for non-widening FMOPA/FMOPS (PR #88105)

2024-04-10 Thread via cfe-commits


@@ -815,8 +815,8 @@ defm FMLS_VG4_M4Z2Z_H : 
sme2_dot_mla_add_sub_array_vg4_multi<"fmls", 0b0100011,
 defm FCVT_2ZZ_H  : sme2p1_fp_cvt_vector_vg2_single<"fcvt", 0b0>;
 defm FCVTL_2ZZ_H : sme2p1_fp_cvt_vector_vg2_single<"fcvtl", 0b1>;
 
-defm FMOPA_MPPZZ_H : sme2p1_fmop_tile_fp16<"fmopa", 0b0, 0b0, 0b11, ZPR16>;
-defm FMOPS_MPPZZ_H : sme2p1_fmop_tile_fp16<"fmops", 0b0, 0b1, 0b11, ZPR16>;
+defm FMOPA_MPPZZ_H : sme2p1_fmop_tile_fp16<"fmopa", 0b0, 0b0, 0b11, nxv8f16, 
int_aarch64_sme_mopa_nonwide>;

CarolineConcatto wrote:

Just in case, maybe it is better to change this to;
 sme2_fmop_tile_fp16 and not change the fp8

https://github.com/llvm/llvm-project/pull/88105
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Add intrinsics for non-widening FMOPA/FMOPS (PR #88105)

2024-04-10 Thread via cfe-commits


@@ -674,3 +674,27 @@ let TargetGuard = "sme2" in {
   def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
 }
+
+
+// SME2p1 - FMOPA, FMOPS (non-widening)
+let TargetGuard = "sme,b16b16" in {
+  def SVMOPA_BF16_NW : SInst<"svmopa_za16[_bf16]", "viPPdd", "b",
+ MergeOp1, "aarch64_sme_mopa_nonwide",

CarolineConcatto wrote:

Just in case:
I remember a discussion that we said we could use MergeNone and in the name add 
 _m:
svmopa_za16[_bf16]_m
Because MergeOp1 is only adding _m

https://github.com/llvm/llvm-project/pull/88105
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Add intrinsics for non-widening FMOPA/FMOPS (PR #88105)

2024-04-10 Thread via cfe-commits


@@ -674,3 +674,27 @@ let TargetGuard = "sme2" in {
   def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
 }
+
+
+// SME2p1 - FMOPA, FMOPS (non-widening)
+let TargetGuard = "sme,b16b16" in {

CarolineConcatto wrote:

I think it should be  "sme2,b16b16" 
if we see the BFMOPA
https://developer.arm.com/documentation/ddi0602/2024-03/SME-Instructions/BFMOPA--non-widening---BFloat16-floating-point-outer-product-and-accumulate-?lang=en

if !IsFeatureImplemented(FEAT_SME2) || !IsFeatureImplemented(FEAT_SVE_B16B16) 
then UNDEFINED;

https://github.com/llvm/llvm-project/pull/88105
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Add intrinsics for non-widening FMOPA/FMOPS (PR #88105)

2024-04-10 Thread via cfe-commits


@@ -674,3 +674,27 @@ let TargetGuard = "sme2" in {
   def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
 }
+
+
+// SME2p1 - FMOPA, FMOPS (non-widening)
+let TargetGuard = "sme,b16b16" in {
+  def SVMOPA_BF16_NW : SInst<"svmopa_za16[_bf16]", "viPPdd", "b",
+ MergeOp1, "aarch64_sme_mopa_nonwide",
+ [IsStreaming, IsInOutZA],
+ [ImmCheck<0, ImmCheck0_1>]>;
+  def SVMOPS_BF16_NW : SInst<"svmops_za16[_bf16]", "viPPdd", "b",
+ MergeOp1, "aarch64_sme_mops_nonwide",
+ [IsStreaming, IsInOutZA],
+ [ImmCheck<0, ImmCheck0_1>]>;
+}
+
+let TargetGuard = "sme2,sme-f16f16" in {
+  def SVMOPA_F16_NW : SInst<"svmopa_za16[_f16]", "viPPdd", "h",
+MergeOp1, "aarch64_sme_mopa_nonwide",

CarolineConcatto wrote:

Can you replace: aarch64_sme_mopa_ by aarch64_sme_mopa_za16?

https://github.com/llvm/llvm-project/pull/88105
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Add intrinsics for non-widening FMOPA/FMOPS (PR #88105)

2024-04-10 Thread via cfe-commits


@@ -815,8 +815,8 @@ defm FMLS_VG4_M4Z2Z_H : 
sme2_dot_mla_add_sub_array_vg4_multi<"fmls", 0b0100011,
 defm FCVT_2ZZ_H  : sme2p1_fp_cvt_vector_vg2_single<"fcvt", 0b0>;
 defm FCVTL_2ZZ_H : sme2p1_fp_cvt_vector_vg2_single<"fcvtl", 0b1>;
 
-defm FMOPA_MPPZZ_H : sme2p1_fmop_tile_fp16<"fmopa", 0b0, 0b0, 0b11, ZPR16>;
-defm FMOPS_MPPZZ_H : sme2p1_fmop_tile_fp16<"fmops", 0b0, 0b1, 0b11, ZPR16>;
+defm FMOPA_MPPZZ_H : sme2p1_fmop_tile_fp16<"fmopa", 0b0, 0b0, 0b11, nxv8f16, 
int_aarch64_sme_mopa_nonwide>;

CarolineConcatto wrote:

Not in this patch, but I think all the instructions under 
`let Predicates = [HasSME2p1, HasSMEF16F16]`, 
should be under
`  let Predicates = [HasSME2, HasSMEF16F16].` to be consistent with clang
Otherwise we will have some problem with clang( clang has sme2 and the backend 
has sme2.1.
TBH when I look at
[FEAT_SME_F16F16](https://developer.arm.com/documentation/ddi0602/2024-03/SME-Instructions/FMOPS--non-widening---Floating-point-outer-product-and-subtract-?lang=en)
It maybe only  need FEAT_SME_F16F16, like

 defm USMOPA_MPPZZ_D : sme_int_outer_product_i64<0b100, "usmopa", 
int_aarch64_sme_usmopa_wide>;


https://github.com/llvm/llvm-project/pull/88105
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)

2024-04-10 Thread via cfe-commits

https://github.com/Sirraide created 
https://github.com/llvm/llvm-project/pull/88265

This is a tentative implementation of support for raw string literals in C 
following the discussion on #85703. 

GCC supports raw string literals in C in `-gnuXY` mode. This pr both enables 
raw string literals in `-gnuXY` mode in C and adds a 
`-f[no-]raw-string-literals` flag to override this beheviour. There are a few 
questions I still have though:

1. GCC does not seem to support raw string literals in C++ before C++11, even 
if e.g. `-std=gnu++03` is passed. Should we follow this behaviour or should we 
enable raw string literals in earlier C++ language modes as well if `-gnu++XY` 
is passed? `-fraw-string-literals` currently makes it possible to enable them 
in e.g. C++03.
2. `-fno-raw-string-literals` allows users to *disable* raw string literals in 
`-gnuXY` mode. I thought it might be useful to have this, but do we want it?
3. The implementation of this currently adds a `RawStringLiterals` option to 
the LangOpts; `-f[no-]raw-string-literals` overrides the default value for it 
which depends on the language standard. As a consequence, passing e.g. 
`-std=c++11 -fno-raw-string-literals` will *disable* raw string literals even 
though we’re in C++11 mode. Do we want to allow this or should we just ignore 
`-f[no-]raw-string-literals` if we’re in C++11 or later?
4. This probably deserves a note in `LanguageExtensions.rst`, but I’m not 
exactly sure where.
5. Should we add a flag for this to `__has_feature`/`__has_extension`?

>From 40e533e6f58acbe832b3fa4e14ca9fd600cf77cf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 10 Apr 2024 14:36:23 +0200
Subject: [PATCH] [Clang] Allow raw string literals in C as an extension

---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/include/clang/Basic/LangOptions.def |  2 ++
 clang/include/clang/Basic/LangStandard.h  |  6 ++
 clang/include/clang/Driver/Options.td |  6 ++
 clang/lib/Basic/LangOptions.cpp   |  1 +
 clang/lib/Driver/ToolChains/Clang.cpp |  2 ++
 clang/lib/Format/Format.cpp   |  1 +
 clang/lib/Lex/Lexer.cpp   | 10 +-
 clang/test/Lexer/raw-string-ext.c | 18 ++
 9 files changed, 44 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Lexer/raw-string-ext.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f96cebbde3d825..20d14130fb62bc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -43,6 +43,9 @@ code bases.
 C/C++ Language Potentially Breaking Changes
 ---
 
+- Clang now supports raw string literals in ``-std=gnuXY`` mode as an 
extension in
+  C. This behaviour can also be overridden using 
``-f[no-]raw-string-literals``.
+
 C++ Specific Potentially Breaking Changes
 -
 - Clang now diagnoses function/variable templates that shadow their own 
template parameters, e.g. ``template void T();``.
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 8ef6700ecdc78e..96bd339bb1851d 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -454,6 +454,8 @@ LANGOPT(MatrixTypes, 1, 0, "Enable or disable the builtin 
matrix type")
 
 LANGOPT(CXXAssumptions, 1, 1, "Enable or disable codegen and compile-time 
checks for C++23's [[assume]] attribute")
 
+LANGOPT(RawStringLiterals, 1, 0, "Enable or disable raw string literals")
+
 ENUM_LANGOPT(StrictFlexArraysLevel, StrictFlexArraysLevelKind, 2,
  StrictFlexArraysLevelKind::Default,
  "Rely on strict definition of flexible arrays")
diff --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index 8e25afc833661c..0a308b93ada746 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -130,6 +130,12 @@ struct LangStandard {
   /// hasDigraphs - Language supports digraphs.
   bool hasDigraphs() const { return Flags & Digraphs; }
 
+  /// hasRawStringLiterals - Language supports R"()" raw string literals.
+  bool hasRawStringLiterals() const {
+// GCC supports raw string literals in C, but not in C++ before C++11.
+return isCPlusPlus11() || (!isCPlusPlus() && isGNUMode());
+  }
+
   /// isGNUMode - Language includes GNU extensions.
   bool isGNUMode() const { return Flags & GNUMode; }
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f745e573eb2686..32e6c10e1251b7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4142,6 +4142,12 @@ def fenable_matrix : Flag<["-"], "fenable-matrix">, 
Group,
 HelpText<"Enable matrix data type and related builtin functions">,
 MarshallingInfoFlag>;
 
+defm raw_string_literals : BoolFOption<"raw-string-literals",
+LangOpts<"RawStringLiteral

[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)

2024-04-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: None (Sirraide)


Changes

This is a tentative implementation of support for raw string literals in C 
following the discussion on #85703. 

GCC supports raw string literals in C in `-gnuXY` mode. This pr both enables 
raw string literals in `-gnuXY` mode in C and adds a 
`-f[no-]raw-string-literals` flag to override this beheviour. There are a few 
questions I still have though:

1. GCC does not seem to support raw string literals in C++ before C++11, even 
if e.g. `-std=gnu++03` is passed. Should we follow this behaviour or should we 
enable raw string literals in earlier C++ language modes as well if `-gnu++XY` 
is passed? `-fraw-string-literals` currently makes it possible to enable them 
in e.g. C++03.
2. `-fno-raw-string-literals` allows users to *disable* raw string literals in 
`-gnuXY` mode. I thought it might be useful to have this, but do we want it?
3. The implementation of this currently adds a `RawStringLiterals` option to 
the LangOpts; `-f[no-]raw-string-literals` overrides the default value for it 
which depends on the language standard. As a consequence, passing e.g. 
`-std=c++11 -fno-raw-string-literals` will *disable* raw string literals even 
though we’re in C++11 mode. Do we want to allow this or should we just ignore 
`-f[no-]raw-string-literals` if we’re in C++11 or later?
4. This probably deserves a note in `LanguageExtensions.rst`, but I’m not 
exactly sure where.
5. Should we add a flag for this to `__has_feature`/`__has_extension`?

---
Full diff: https://github.com/llvm/llvm-project/pull/88265.diff


9 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Basic/LangOptions.def (+2) 
- (modified) clang/include/clang/Basic/LangStandard.h (+6) 
- (modified) clang/include/clang/Driver/Options.td (+6) 
- (modified) clang/lib/Basic/LangOptions.cpp (+1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+2) 
- (modified) clang/lib/Format/Format.cpp (+1) 
- (modified) clang/lib/Lex/Lexer.cpp (+5-5) 
- (added) clang/test/Lexer/raw-string-ext.c (+18) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f96cebbde3d825..20d14130fb62bc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -43,6 +43,9 @@ code bases.
 C/C++ Language Potentially Breaking Changes
 ---
 
+- Clang now supports raw string literals in ``-std=gnuXY`` mode as an 
extension in
+  C. This behaviour can also be overridden using 
``-f[no-]raw-string-literals``.
+
 C++ Specific Potentially Breaking Changes
 -
 - Clang now diagnoses function/variable templates that shadow their own 
template parameters, e.g. ``template void T();``.
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 8ef6700ecdc78e..96bd339bb1851d 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -454,6 +454,8 @@ LANGOPT(MatrixTypes, 1, 0, "Enable or disable the builtin 
matrix type")
 
 LANGOPT(CXXAssumptions, 1, 1, "Enable or disable codegen and compile-time 
checks for C++23's [[assume]] attribute")
 
+LANGOPT(RawStringLiterals, 1, 0, "Enable or disable raw string literals")
+
 ENUM_LANGOPT(StrictFlexArraysLevel, StrictFlexArraysLevelKind, 2,
  StrictFlexArraysLevelKind::Default,
  "Rely on strict definition of flexible arrays")
diff --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index 8e25afc833661c..0a308b93ada746 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -130,6 +130,12 @@ struct LangStandard {
   /// hasDigraphs - Language supports digraphs.
   bool hasDigraphs() const { return Flags & Digraphs; }
 
+  /// hasRawStringLiterals - Language supports R"()" raw string literals.
+  bool hasRawStringLiterals() const {
+// GCC supports raw string literals in C, but not in C++ before C++11.
+return isCPlusPlus11() || (!isCPlusPlus() && isGNUMode());
+  }
+
   /// isGNUMode - Language includes GNU extensions.
   bool isGNUMode() const { return Flags & GNUMode; }
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f745e573eb2686..32e6c10e1251b7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4142,6 +4142,12 @@ def fenable_matrix : Flag<["-"], "fenable-matrix">, 
Group,
 HelpText<"Enable matrix data type and related builtin functions">,
 MarshallingInfoFlag>;
 
+defm raw_string_literals : BoolFOption<"raw-string-literals",
+LangOpts<"RawStringLiterals">, Default,
+PosFlag,
+NegFlag,
+BothFlags<[], [ClangOption, CC1Option], " raw string literals">>;
+
 def fzero_call_used_regs_EQ
 : Joined<["-"], "fzero-call-used-regs=">, Group,
 Visibility<

[clang] [OpenACC] Implement Default clause for Compute Constructs (PR #88135)

2024-04-10 Thread Alexey Bataev via cfe-commits


@@ -15,3 +15,22 @@
 #include "clang/AST/ASTContext.h"
 
 using namespace clang;
+
+OpenACCDefaultClause *OpenACCDefaultClause::Create(const ASTContext &C,
+   OpenACCDefaultClauseKind K,
+   SourceLocation BeginLoc,
+   SourceLocation LParenLoc,
+   SourceLocation EndLoc) {
+  void *Mem =
+  C.Allocate(sizeof(OpenACCDefaultClause), alignof(OpenACCDefaultClause));
+
+  return new (Mem) OpenACCDefaultClause(K, BeginLoc, LParenLoc, EndLoc);
+}
+
+//===--===//
+//  OpenACC clauses printing methods
+//===--===//
+void OpenACCClausePrinter::VisitOpenACCDefaultClause(
+const OpenACCDefaultClause &C) {
+  OS << "default(" << C.getDefaultClauseKind();

alexey-bataev wrote:

Do you output closing ')' in some other place?

https://github.com/llvm/llvm-project/pull/88135
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement Default clause for Compute Constructs (PR #88135)

2024-04-10 Thread Alexey Bataev via cfe-commits


@@ -11074,13 +11079,44 @@ OMPClause 
*TreeTransform::TransformOMPXBareClause(OMPXBareClause *C) {
 
//===--===//
 // OpenACC transformation
 
//===--===//
+template 
+OpenACCClause *TreeTransform::TransformOpenACCClause(
+ArrayRef ExistingClauses,
+OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
+
+  SemaOpenACC::OpenACCParsedClause ParsedClause(
+  DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
+  ParsedClause.setEndLoc(OldClause->getEndLoc());
+
+  if (const auto *WithParms = dyn_cast(OldClause))
+ParsedClause.setLParenLoc(WithParms->getLParenLoc());
+
+  switch (OldClause->getClauseKind()) {
+  case OpenACCClauseKind::Default:
+// There is nothing to do here as nothing dependent can appear in this
+// clause. So just set the values so Sema can set the right value.
+ParsedClause.setDefaultDetails(
+cast(OldClause)->getDefaultClauseKind());
+break;
+  default:
+assert(false && "Unhandled OpenACC clause in TreeTransform");

alexey-bataev wrote:

llvm_unreachable?

https://github.com/llvm/llvm-project/pull/88135
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Headers meant to be included multiple times can be completely invisible in clang module builds (PR #83660)

2024-04-10 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

@ian-twilightcoder this change seemed to cause our internal builds to run out 
of source location space.
```
remark: source manager location address space usage: [-Rsloc-usage]
note: 408559B in local locations, 2146921126B in locations loaded from AST 
files, for a total of 2147329685B (99% of available space)
```

The main offenders from the 

https://github.com/llvm/llvm-project/pull/83660
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Catch missing format attributes (PR #70024)

2024-04-10 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovicsyrmia updated 
https://github.com/llvm/llvm-project/pull/70024

From e198dc5518f647fef0dff20f87dd01e2a187d892 Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 5 Apr 2024 15:20:37 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/Sema/SemaChecking.cpp   |   4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 119 ++-
 clang/test/Sema/attr-format-missing.c | 263 
 clang/test/Sema/attr-format-missing.cpp   | 293 ++
 8 files changed, 685 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a84ff16a1e4d4..c6cd05da32332d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -381,6 +381,9 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Clang now diagnoses missing format attributes for non-template functions and
+  class/struct/union members. Fixes #GH70024
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 520168f01fd846..5c6a69ff1586db 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -505,7 +505,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index df57f5e6ce11ba..d32bf4c8a9549e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1008,6 +1008,9 @@ def err_opencl_invalid_param : Error<
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
 def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 8c98d8c7fef7a7..2bf2537027d728 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3885,6 +3885,10 @@ class Sema final {
   bool DiagnoseSwiftName(Decl *D, StringRef Name, SourceLocation Loc,
  const ParsedAttr &AL, bool IsAsync);
 
+  void DiagnoseMissingFormatAttributes(const FunctionDecl *FDecl,
+   ArrayRef Args,
+   SourceLocation Loc);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3dcd18b3afc8b4..77e01ba344e5a5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -8034,8 +8034,10 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
   }
 
-  if (FD)
+  if (FD) {
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
+DiagnoseMissingFormatAttributes(FD, Args, Range.getBegin());
+  }
 }
 
 /// CheckConstructorCall - Check a constructor call for correctness and safety
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 8bce04640e748e..fbf6f8f6f9534d 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -159,6 +159,13 @@ static bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+static bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 static inline bool isNSStringType(QualType T, ASTContext &Ctx,
   bool AllowNSAttributedString = false) {
   const auto *PT = T->getAs();
@@ -308,7

[clang] [llvm] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (PR #88251)

2024-04-10 Thread via cfe-commits


@@ -2148,6 +2148,11 @@ let TargetGuard = "sme2" in {
   def SVSCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "csil", 
MergeNone, "aarch64_sve_sclamp_single_x4",  [IsStreaming], []>;
   def SVUCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "UcUsUiUl", 
MergeNone, "aarch64_sve_uclamp_single_x4",  [IsStreaming], []>;
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
+
+  let TargetGuard = "b16b16"in {

CarolineConcatto wrote:

Are you sure this work 
 TargetGuard = "sme2" in {
 TargetGuard = "b16b16" in {
I have a distant memory  saying it does not work, that we need 
 TargetGuard = "sme2,b16b16" in {

https://github.com/llvm/llvm-project/pull/88251
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][test] Avoid writing to a potentially write-protected dir (PR #88258)

2024-04-10 Thread Dmitri Gribenko via cfe-commits

https://github.com/gribozavr approved this pull request.


https://github.com/llvm/llvm-project/pull/88258
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (PR #88251)

2024-04-10 Thread Momchil Velikov via cfe-commits


@@ -2148,6 +2148,11 @@ let TargetGuard = "sme2" in {
   def SVSCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "csil", 
MergeNone, "aarch64_sve_sclamp_single_x4",  [IsStreaming], []>;
   def SVUCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "UcUsUiUl", 
MergeNone, "aarch64_sve_uclamp_single_x4",  [IsStreaming], []>;
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
+
+  let TargetGuard = "b16b16"in {

momchil-velikov wrote:

I does not work. A test for target features (in `Sema`) would catch that.

https://github.com/llvm/llvm-project/pull/88251
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-04-10 Thread Alex Voicu via cfe-commits


@@ -2216,7 +2216,7 @@ static llvm::Value *EmitTypeidFromVTable(CodeGenFunction 
&CGF, const Expr *E,
 }
 
 llvm::Value *CodeGenFunction::EmitCXXTypeidExpr(const CXXTypeidExpr *E) {
-  llvm::Type *PtrTy = llvm::PointerType::getUnqual(getLLVMContext());
+  llvm::Type *PtrTy = Int8PtrTy;

AlexVlx wrote:

It should but sadly it cannot, see our historical conversation here: 
. I've not got around to working on your 
suggestion there about supporting declaring a default AS for a class, so we 
have to keep things like so for now.

https://github.com/llvm/llvm-project/pull/88182
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement Default clause for Compute Constructs (PR #88135)

2024-04-10 Thread Erich Keane via cfe-commits


@@ -15,3 +15,22 @@
 #include "clang/AST/ASTContext.h"
 
 using namespace clang;
+
+OpenACCDefaultClause *OpenACCDefaultClause::Create(const ASTContext &C,
+   OpenACCDefaultClauseKind K,
+   SourceLocation BeginLoc,
+   SourceLocation LParenLoc,
+   SourceLocation EndLoc) {
+  void *Mem =
+  C.Allocate(sizeof(OpenACCDefaultClause), alignof(OpenACCDefaultClause));
+
+  return new (Mem) OpenACCDefaultClause(K, BeginLoc, LParenLoc, EndLoc);
+}
+
+//===--===//
+//  OpenACC clauses printing methods
+//===--===//
+void OpenACCClausePrinter::VisitOpenACCDefaultClause(
+const OpenACCDefaultClause &C) {
+  OS << "default(" << C.getDefaultClauseKind();

erichkeane wrote:

Yikes, guess not!  Good catch.

https://github.com/llvm/llvm-project/pull/88135
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement Default clause for Compute Constructs (PR #88135)

2024-04-10 Thread Erich Keane via cfe-commits


@@ -11074,13 +11079,44 @@ OMPClause 
*TreeTransform::TransformOMPXBareClause(OMPXBareClause *C) {
 
//===--===//
 // OpenACC transformation
 
//===--===//
+template 
+OpenACCClause *TreeTransform::TransformOpenACCClause(
+ArrayRef ExistingClauses,
+OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
+
+  SemaOpenACC::OpenACCParsedClause ParsedClause(
+  DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
+  ParsedClause.setEndLoc(OldClause->getEndLoc());
+
+  if (const auto *WithParms = dyn_cast(OldClause))
+ParsedClause.setLParenLoc(WithParms->getLParenLoc());
+
+  switch (OldClause->getClauseKind()) {
+  case OpenACCClauseKind::Default:
+// There is nothing to do here as nothing dependent can appear in this
+// clause. So just set the values so Sema can set the right value.
+ParsedClause.setDefaultDetails(
+cast(OldClause)->getDefaultClauseKind());
+break;
+  default:
+assert(false && "Unhandled OpenACC clause in TreeTransform");

erichkeane wrote:

According to Aaron Ballman, this isn't really what 'unreachable' is for.  

There is a pretty extensive discussion somewhere between 'assert(false...) ' 
and 'llvm_unreachable', as the latter performs optimizations on release builds 
that can result in an unstable compiler.

In this case, I'm using it somewhat for potential flow-control during 
development, but once I'm sure I have all the cases covered, this will either 
go away or switch to an unreachable.

https://github.com/llvm/llvm-project/pull/88135
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Add intrinsics for multi-vector to ZA array vector accumulators (PR #88266)

2024-04-10 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov created 
https://github.com/llvm/llvm-project/pull/88266

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics

void_svadd_za16_vg1x2_f16(uint32_t slice, svfloat16x2_t zn) __arm_streaming 
__arm_inout("za");
void_svadd_za16_vg1x4_f16(uint32_t slice, svfloat16x4_t zn) __arm_streaming 
__arm_inout("za");
void_svsub_za16_vg1x2_f16(uint32_t slice, svfloat16x2_t zn) __arm_streaming 
__arm_inout("za");
void_svsub_za16_vg1x4_f16(uint32_t slice, svfloat16x4_t zn) __arm_streaming 
__arm_inout("za");

as well as the corresponding `bf16` variants.

>From 2b0557d4a62476b827352b6775588cef15cecd33 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Wed, 10 Apr 2024 11:25:50 +0100
Subject: [PATCH] [AArch64] Add intrinsics for multi-vector to ZA array vector
 accumulators

---
 clang/include/clang/Basic/arm_sme.td  |  11 +
 .../acle_sme2_add_sub_za16.c  | 191 ++
 .../acle_sme2_add_sub_za16.c  |  26 +++
 llvm/include/llvm/IR/IntrinsicsAArch64.td |   4 +-
 .../lib/Target/AArch64/AArch64SMEInstrInfo.td |  16 +-
 .../AArch64/sme2-intrinsics-add-sub-za16.ll   | 146 +
 6 files changed, 384 insertions(+), 10 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c
 create mode 100644 
clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-add-sub-za16.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 1ac6d5170ea283..dcfaefa7a3e266 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,6 +298,17 @@ multiclass ZAAddSub {
 def NAME # _ZA64_VG1X2_F64 : Inst<"sv" # n_suffix # "_za64[_{d}]_vg1x2", 
"vm2", "d", MergeNone, "aarch64_sme_" # n_suffix # "_za64_vg1x2", [IsStreaming, 
IsInOutZA], []>;
 def NAME # _ZA64_VG1X4_F64 : Inst<"sv" # n_suffix # "_za64[_{d}]_vg1x4", 
"vm4", "d", MergeNone, "aarch64_sme_" # n_suffix # "_za64_vg1x4", [IsStreaming, 
IsInOutZA], []>;
   }
+
+  let TargetGuard = "sme2p1,sme-f16f16" in {
+def NAME # _ZA16_VG1X2_F16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x2", 
"vm2", "h", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x2", [IsStreaming, 
IsInOutZA], []>;
+def NAME # _ZA16_VG1X4_F16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x4", 
"vm4", "h", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x4", [IsStreaming, 
IsInOutZA], []>;
+  }
+
+  let TargetGuard = "sme2p1,b16b16" in {
+def NAME # _ZA16_VG1X2_BF16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x2", 
"vm2", "b", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x2", [IsStreaming, 
IsInOutZA], []>;
+def NAME # _ZA16_VG1X4_BF16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x4", 
"vm4", "b", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x4", [IsStreaming, 
IsInOutZA], []>;
+  }
+
 }
 
 defm SVADD : ZAAddSub<"add">;
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c
new file mode 100644
index 00..bdf07f86b9c93d
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c
@@ -0,0 +1,191 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1   -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1  -target-feature 
+sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1-x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1  -target-feature 
+sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK-CXX
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS-fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1  -target-feature 
+sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1  -target-feature 
+sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK-CXX
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+// CHECK-LABEL: define dso_local void @test_svadd_za16_vg1x2_f16(
+// CHECK-SAME: i32 noundef [[SLICE:%.*]],  [[ZN:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8f16.nxv16f16( [[ZN]], i64 0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extr

[clang] [llvm] [AArch64] Add intrinsics for multi-vector to ZA array vector accumulators (PR #88266)

2024-04-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: Momchil Velikov (momchil-velikov)


Changes

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics

void_svadd_za16_vg1x2_f16(uint32_t slice, svfloat16x2_t zn) __arm_streaming 
__arm_inout("za");
void_svadd_za16_vg1x4_f16(uint32_t slice, svfloat16x4_t zn) __arm_streaming 
__arm_inout("za");
void_svsub_za16_vg1x2_f16(uint32_t slice, svfloat16x2_t zn) __arm_streaming 
__arm_inout("za");
void_svsub_za16_vg1x4_f16(uint32_t slice, svfloat16x4_t zn) __arm_streaming 
__arm_inout("za");

as well as the corresponding `bf16` variants.

---

Patch is 31.84 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/88266.diff


6 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+11) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c 
(+191) 
- (added) clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c 
(+26) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+2-2) 
- (modified) llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td (+8-8) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-add-sub-za16.ll (+146) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 1ac6d5170ea283..dcfaefa7a3e266 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,6 +298,17 @@ multiclass ZAAddSub {
 def NAME # _ZA64_VG1X2_F64 : Inst<"sv" # n_suffix # "_za64[_{d}]_vg1x2", 
"vm2", "d", MergeNone, "aarch64_sme_" # n_suffix # "_za64_vg1x2", [IsStreaming, 
IsInOutZA], []>;
 def NAME # _ZA64_VG1X4_F64 : Inst<"sv" # n_suffix # "_za64[_{d}]_vg1x4", 
"vm4", "d", MergeNone, "aarch64_sme_" # n_suffix # "_za64_vg1x4", [IsStreaming, 
IsInOutZA], []>;
   }
+
+  let TargetGuard = "sme2p1,sme-f16f16" in {
+def NAME # _ZA16_VG1X2_F16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x2", 
"vm2", "h", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x2", [IsStreaming, 
IsInOutZA], []>;
+def NAME # _ZA16_VG1X4_F16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x4", 
"vm4", "h", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x4", [IsStreaming, 
IsInOutZA], []>;
+  }
+
+  let TargetGuard = "sme2p1,b16b16" in {
+def NAME # _ZA16_VG1X2_BF16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x2", 
"vm2", "b", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x2", [IsStreaming, 
IsInOutZA], []>;
+def NAME # _ZA16_VG1X4_BF16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x4", 
"vm4", "b", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x4", [IsStreaming, 
IsInOutZA], []>;
+  }
+
 }
 
 defm SVADD : ZAAddSub<"add">;
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c
new file mode 100644
index 00..bdf07f86b9c93d
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c
@@ -0,0 +1,191 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1   -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1  -target-feature 
+sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1-x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1  -target-feature 
+sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK-CXX
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS-fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1  -target-feature 
+sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1  -target-feature 
+sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK-CXX
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+// CHECK-LABEL: define dso_local void @test_svadd_za16_vg1x2_f16(
+// CHECK-SAME: i32 noundef [[SLICE:%.*]],  [[ZN:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8f16.nxv16f16( [[ZN]], i64 0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8f16.nxv16f16( [[ZN]], i64 8)
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.add.za16.vg1x2.nxv8f16(i32 
[[SLICE]],  [[TMP0]],  [[TMP1]])
+// CHECK-NEXT:ret void
+//
+// CHECK-CXX-LABEL: define dso_local void 
@_Z25test_svadd_za16_vg1x2_f16j13svfloat16x2_t(
+// CHECK-CXX-

[clang] [llvm] [AArch64] Add intrinsics for multi-vector to ZA array vector accumulators (PR #88266)

2024-04-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Momchil Velikov (momchil-velikov)


Changes

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics

void_svadd_za16_vg1x2_f16(uint32_t slice, svfloat16x2_t zn) __arm_streaming 
__arm_inout("za");
void_svadd_za16_vg1x4_f16(uint32_t slice, svfloat16x4_t zn) __arm_streaming 
__arm_inout("za");
void_svsub_za16_vg1x2_f16(uint32_t slice, svfloat16x2_t zn) __arm_streaming 
__arm_inout("za");
void_svsub_za16_vg1x4_f16(uint32_t slice, svfloat16x4_t zn) __arm_streaming 
__arm_inout("za");

as well as the corresponding `bf16` variants.

---

Patch is 31.84 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/88266.diff


6 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+11) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c 
(+191) 
- (added) clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c 
(+26) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+2-2) 
- (modified) llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td (+8-8) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-add-sub-za16.ll (+146) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 1ac6d5170ea283..dcfaefa7a3e266 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,6 +298,17 @@ multiclass ZAAddSub {
 def NAME # _ZA64_VG1X2_F64 : Inst<"sv" # n_suffix # "_za64[_{d}]_vg1x2", 
"vm2", "d", MergeNone, "aarch64_sme_" # n_suffix # "_za64_vg1x2", [IsStreaming, 
IsInOutZA], []>;
 def NAME # _ZA64_VG1X4_F64 : Inst<"sv" # n_suffix # "_za64[_{d}]_vg1x4", 
"vm4", "d", MergeNone, "aarch64_sme_" # n_suffix # "_za64_vg1x4", [IsStreaming, 
IsInOutZA], []>;
   }
+
+  let TargetGuard = "sme2p1,sme-f16f16" in {
+def NAME # _ZA16_VG1X2_F16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x2", 
"vm2", "h", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x2", [IsStreaming, 
IsInOutZA], []>;
+def NAME # _ZA16_VG1X4_F16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x4", 
"vm4", "h", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x4", [IsStreaming, 
IsInOutZA], []>;
+  }
+
+  let TargetGuard = "sme2p1,b16b16" in {
+def NAME # _ZA16_VG1X2_BF16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x2", 
"vm2", "b", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x2", [IsStreaming, 
IsInOutZA], []>;
+def NAME # _ZA16_VG1X4_BF16 : Inst<"sv" # n_suffix # "_za16[_{d}]_vg1x4", 
"vm4", "b", MergeNone, "aarch64_sme_" # n_suffix # "_za16_vg1x4", [IsStreaming, 
IsInOutZA], []>;
+  }
+
 }
 
 defm SVADD : ZAAddSub<"add">;
diff --git 
a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c
new file mode 100644
index 00..bdf07f86b9c93d
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add_sub_za16.c
@@ -0,0 +1,191 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1   -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1  -target-feature 
+sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1-x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1  -target-feature 
+sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK-CXX
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS-fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1  -target-feature 
+sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -x c++ -fclang-abi-compat=latest 
-triple aarch64-none-linux-gnu -target-feature +sme2p1  -target-feature 
+sme-f16f16 -target-feature +b16b16 -O2 -S -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK-CXX
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+// CHECK-LABEL: define dso_local void @test_svadd_za16_vg1x2_f16(
+// CHECK-SAME: i32 noundef [[SLICE:%.*]],  [[ZN:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8f16.nxv16f16( [[ZN]], i64 0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8f16.nxv16f16( [[ZN]], i64 8)
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.add.za16.vg1x2.nxv8f16(i32 
[[SLICE]],  [[TMP0]],  [[TMP1]])
+// CHECK-NEXT:ret void
+//
+// CHECK-CXX-LABEL: define dso_local void 
@_Z25test_svadd_za16_vg1x2_f16j13svfloat16x2_t(
+// CHECK-CXX-SAME: i3

[clang] [OpenACC] Implement Default clause for Compute Constructs (PR #88135)

2024-04-10 Thread Erich Keane via cfe-commits

https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/88135

>From b0595276f2b8d74d036ff9bf94c5baea86a57f17 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Mon, 8 Apr 2024 14:23:17 -0700
Subject: [PATCH 1/3] g This is a combination of 3 commits.

[OpenACC] Implement Default clause for Compute Constructs

As a followup to my previous commits, this is an implementation of a
single clause, in this case the 'default' clause.  This implements all
semantic analysis for it on compute clauses, and continues to leave it
rejected for all others (some as 'doesnt appertain', others as 'not
implemented' as appropriate).

This also implements and tests the TreeTransform as requested in the
previous patch.
---
 clang/include/clang/AST/OpenACCClause.h   | 38 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +
 clang/include/clang/Basic/OpenACCKinds.h  | 23 ++
 clang/include/clang/Sema/SemaOpenACC.h| 17 -
 clang/lib/AST/OpenACCClause.cpp   | 19 +
 clang/lib/AST/StmtProfile.cpp |  5 ++
 clang/lib/AST/TextNodeDumper.cpp  | 11 +++
 clang/lib/Parse/ParseOpenACC.cpp  |  8 +-
 clang/lib/Sema/SemaOpenACC.cpp| 65 ++--
 clang/lib/Sema/TreeTransform.h| 42 ++-
 clang/lib/Serialization/ASTReader.cpp |  7 +-
 clang/lib/Serialization/ASTWriter.cpp |  7 +-
 clang/test/ParserOpenACC/parse-clauses.c  | 20 ++---
 .../SemaOpenACC/compute-construct-ast.cpp | 14 +++-
 .../compute-construct-clause-ast.cpp  | 74 +++
 .../compute-construct-default-clause.c| 55 ++
 .../compute-construct-default-clause.cpp  | 39 ++
 17 files changed, 415 insertions(+), 33 deletions(-)
 create mode 100644 clang/test/SemaOpenACC/compute-construct-clause-ast.cpp
 create mode 100644 clang/test/SemaOpenACC/compute-construct-default-clause.c
 create mode 100644 clang/test/SemaOpenACC/compute-construct-default-clause.cpp

diff --git a/clang/include/clang/AST/OpenACCClause.h 
b/clang/include/clang/AST/OpenACCClause.h
index 06a0098bbda4cd..c979550ed00fc3 100644
--- a/clang/include/clang/AST/OpenACCClause.h
+++ b/clang/include/clang/AST/OpenACCClause.h
@@ -51,6 +51,36 @@ class OpenACCClauseWithParams : public OpenACCClause {
   SourceLocation getLParenLoc() const { return LParenLoc; }
 };
 
+// A 'default' clause, has the optional 'none' or 'present' argument.
+class OpenACCDefaultClause : public OpenACCClauseWithParams {
+  friend class ASTReaderStmt;
+  friend class ASTWriterStmt;
+
+  OpenACCDefaultClauseKind DefaultClauseKind;
+
+protected:
+  OpenACCDefaultClause(OpenACCDefaultClauseKind K, SourceLocation BeginLoc,
+   SourceLocation LParenLoc, SourceLocation EndLoc)
+  : OpenACCClauseWithParams(OpenACCClauseKind::Default, BeginLoc, 
LParenLoc,
+EndLoc),
+DefaultClauseKind(K) {
+assert((DefaultClauseKind == OpenACCDefaultClauseKind::None ||
+DefaultClauseKind == OpenACCDefaultClauseKind::Present) &&
+   "Invalid Clause Kind");
+  }
+
+public:
+  OpenACCDefaultClauseKind getDefaultClauseKind() const {
+return DefaultClauseKind;
+  }
+
+  static OpenACCDefaultClause *Create(const ASTContext &C,
+  OpenACCDefaultClauseKind K,
+  SourceLocation BeginLoc,
+  SourceLocation LParenLoc,
+  SourceLocation EndLoc);
+};
+
 template  class OpenACCClauseVisitor {
   Impl &getDerived() { return static_cast(*this); }
 
@@ -66,6 +96,8 @@ template  class OpenACCClauseVisitor {
 
 switch (C->getClauseKind()) {
 case OpenACCClauseKind::Default:
+  VisitOpenACCDefaultClause(*static_cast(C));
+  return;
 case OpenACCClauseKind::Finalize:
 case OpenACCClauseKind::IfPresent:
 case OpenACCClauseKind::Seq:
@@ -112,6 +144,10 @@ template  class OpenACCClauseVisitor {
 }
 llvm_unreachable("Invalid Clause kind");
   }
+
+  void VisitOpenACCDefaultClause(const OpenACCDefaultClause &Clause) {
+return getDerived().VisitOpenACCDefaultClause(Clause);
+  }
 };
 
 class OpenACCClausePrinter final
@@ -128,6 +164,8 @@ class OpenACCClausePrinter final
 }
   }
   OpenACCClausePrinter(raw_ostream &OS) : OS(OS) {}
+
+  void VisitOpenACCDefaultClause(const OpenACCDefaultClause &Clause);
 };
 
 } // namespace clang
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4fbbc42273ba93..ad9abd121bab6f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12254,6 +12254,10 @@ def err_acc_construct_appertainment
 "be used in a statement context">;
 def err_acc_clause_appertainment
 : Error<"OpenACC '%1' clause is not valid on '%0' directive">;
+def

[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-10 Thread Edwin Vane via cfe-commits

https://github.com/revane updated 
https://github.com/llvm/llvm-project/pull/88186

>From bc5071c54e825d7036b6a54f4dfa02268e3a5c72 Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:07:52 -0400
Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py

Makes it possible to export fixes from running llvm-lit on a clang-tidy
test. To enable, modify the RUN invocation directly in the test with the
new -export flag. llvm-lit will report the test passed and fixes
can be found in the file specified to the -export flag.
---
 .../test/clang-tidy/check_clang_tidy.py   | 70 ++-
 1 file changed, 51 insertions(+), 19 deletions(-)

diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..4065eb5cbf2cdb 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export, the tool simply exports fixes to a provided file
+and does not run FileCheck.
+
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export = args.export
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -181,7 +193,9 @@ def run_clang_tidy(self):
 [
 "clang-tidy",
 self.temp_file_name,
-"-fix",
+]
++ ["-fix" if self.export is None else "--export-fixes=" + 
self.export]
++ [
 "--checks=-*," + self.check_name,
 ]
 + self.clang_tidy_extra_args
@@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output):
 
 def run(self):
 self.read_input()
-self.get_prefixes()
+if self.export is None:
+self.get_prefixes()
 self.prepare_test_inputs()
 clang_tidy_output = self.run_clang_tidy()
-self.check_fixes()
-self.check_messages(clang_tidy_output)
-self.check_notes(clang_tidy_output)
+if self.export is None:
+self.check_fixes()
+self.check_messages(clang_tidy_output)
+self.check_notes(clang_tidy_output)
 
 
 def expand_std(std):
@@ -284,7 +300,11 @@ def csv(string):
 
 
 def parse_arguments():
-parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(
+prog=pathlib.Path(__file__).stem,
+description=__doc__,
+formatter_class=argparse.RawDescriptionHelpFormatter,
+)
 parser.add_argument("-expect-clang-tidy-error", action="store_true")
 parser.add_argument("-resource-dir")
 parser.add_argument("-assume-filename")
@@ -298,7 +318,19 @@ def parse_arguments():
 type=csv,
 help="comma-separated list of FileCheck suffixes",
 )
-parser.add_argument("-std", type=csv, default=["c++11-or-later"])
+parser.add_argument(
+"-export",
+default=None,
+type=str,
+metavar="file",
+help="A file to export fixes into instead of fixing.",
+)
+parser.add_argument(
+"-std",
+type=csv,
+default=["c++11-or-later"],
+help="Passed to clang. Special -or-later values are expanded.",
+)
 return parser.parse_known_args()
 
 

___

[clang] [clang] Introduce `SemaSYCL` (PR #88086)

2024-04-10 Thread Erich Keane via cfe-commits

https://github.com/erichkeane approved this pull request.


https://github.com/llvm/llvm-project/pull/88086
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Use CDM::CLibrary instead of isGlobalCFunction() (PR #88267)

2024-04-10 Thread via cfe-commits

https://github.com/NagyDonat created 
https://github.com/llvm/llvm-project/pull/88267

This commit updates several checkers to use call descriptions with the matching 
mode `CDM::CLibrary` instead checking `Call.isGlobalCFunction()` after 
performing the match. This resolves several TODOs in various checkers.

Note that both matching with `CDM::CLibrary` and calling `isGlobalCFunction` 
leads to `CheckerContext::isCLibraryFunction()` checks (so this change is close 
to being NFC), but if it is used via the matching mode then the checker can 
automatically recognize the builtin variants of the matched functions.

I'll also make similar changes in GenericTaintChecker, but that checker has 
separate and inconsistent rules for handling the normal and the builtin variant 
of several functions (e.g. `memcpy` and `__builtin_memcpy`), so I'll put those 
changes into a separate commit.

>From fd16342e77dd34ca63be20658d410b99a8122f49 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Thu, 21 Mar 2024 16:59:42 +0100
Subject: [PATCH] [analyzer] Use CDM::CLibrary instead of isGlobalCFunction()

This commit updates several checkers to use call descriptions with the
matching mode `CDM::CLibrary` instead checking `Call.isGlobalCFunction()`
after performing the match. This resolves several TODOs in various
checkers.

Note that both matching with `CDM::CLibrary` and calling
`isGlobalCFunction` leads to `CheckerContext::isCLibraryFunction()`
checks (so this change is close to being NFC), but if it is used via the
matching mode then the checker can automatically recognize the builtin
variants of the matched functions.

I'll also make similar changes in GenericTaintChecker, but that checker
has separate and inconsistent rules for handling the normal and the
builtin variant of several functions (e.g. `memcpy` and
`__builtin_memcpy`), so I'll put those changes into a separate commit.
---
 .../Checkers/BasicObjCFoundationChecks.cpp|  12 +-
 .../Checkers/PthreadLockChecker.cpp   | 115 +++---
 .../Checkers/SimpleStreamChecker.cpp  |  10 +-
 .../StaticAnalyzer/Checkers/StreamChecker.cpp |  69 +--
 .../StaticAnalyzer/Checkers/ValistChecker.cpp |  35 +++---
 5 files changed, 130 insertions(+), 111 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index c72a97cc01e914..80f128b917b200 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -542,10 +542,10 @@ namespace {
 class CFRetainReleaseChecker : public Checker {
   mutable APIMisuse BT{this, "null passed to CF memory management function"};
   const CallDescriptionSet ModelledCalls = {
-  {{"CFRetain"}, 1},
-  {{"CFRelease"}, 1},
-  {{"CFMakeCollectable"}, 1},
-  {{"CFAutorelease"}, 1},
+  {CDM::CLibrary, {"CFRetain"}, 1},
+  {CDM::CLibrary, {"CFRelease"}, 1},
+  {CDM::CLibrary, {"CFMakeCollectable"}, 1},
+  {CDM::CLibrary, {"CFAutorelease"}, 1},
   };
 
 public:
@@ -555,10 +555,6 @@ class CFRetainReleaseChecker : public 
Checker {
 
 void CFRetainReleaseChecker::checkPreCall(const CallEvent &Call,
   CheckerContext &C) const {
-  // TODO: Make this check part of CallDescription.
-  if (!Call.isGlobalCFunction())
-return;
-
   // Check if we called CFRetain/CFRelease/CFMakeCollectable/CFAutorelease.
   if (!ModelledCalls.contains(Call))
 return;
diff --git a/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
index fa8572cf85edfe..86530086ff1b27 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
@@ -87,7 +87,8 @@ class PthreadLockChecker : public Checker PThreadCallbacks = {
   // Init.
-  {{{"pthread_mutex_init"}, 2}, &PthreadLockChecker::InitAnyLock},
+  {{CDM::CLibrary, {"pthread_mutex_init"}, 2},
+   &PthreadLockChecker::InitAnyLock},
   // TODO: pthread_rwlock_init(2 arguments).
   // TODO: lck_mtx_init(3 arguments).
   // TODO: lck_mtx_alloc_init(2 arguments) => returns the mutex.
@@ -95,74 +96,106 @@ class PthreadLockChecker : public Checker returns the mutex.
 
   // Acquire.
-  {{{"pthread_mutex_lock"}, 1}, &PthreadLockChecker::AcquirePthreadLock},
-  {{{"pthread_rwlock_rdlock"}, 1}, 
&PthreadLockChecker::AcquirePthreadLock},
-  {{{"pthread_rwlock_wrlock"}, 1}, 
&PthreadLockChecker::AcquirePthreadLock},
-  {{{"lck_mtx_lock"}, 1}, &PthreadLockChecker::AcquireXNULock},
-  {{{"lck_rw_lock_exclusive"}, 1}, &PthreadLockChecker::AcquireXNULock},
-  {{{"lck_rw_lock_shared"}, 1}, &PthreadLockChecker::AcquireXNULock},
+  {{CDM::CLibrary, {"pthread_mutex_lock"}, 1},
+   &PthreadLockChecker::AcquirePthreadLock},
+  {{CDM::CLibrary, {"pthre

[clang-tools-extra] [clang-tidy] Export fixes from check_clang_tidy.py (PR #88186)

2024-04-10 Thread Edwin Vane via cfe-commits

https://github.com/revane updated 
https://github.com/llvm/llvm-project/pull/88186

>From 91d07d734c92ee807bc804c2d08374771cae8c0a Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:07:52 -0400
Subject: [PATCH] [clang-tidy] Export fixes from check_clang_tidy.py

Makes it possible to export fixes from running llvm-lit on a clang-tidy
test. To enable, modify the RUN invocation directly in the test with the
new -export flag. llvm-lit will report the test passed and fixes
can be found in the file specified to the -export flag.
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  2 +
 .../test/clang-tidy/check_clang_tidy.py   | 70 ++-
 2 files changed, 53 insertions(+), 19 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b66be44e9f8a6f..59d50f49120fc0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -100,6 +100,8 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
   similar fashion to what `-header-filter` does for header files.
+- Improved :program:`check_clang_tidy.py` script. Added argument `-export`
+  to aid in clang-tidy and test development.
 
 New checks
 ^^
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 53ffca0bad8d06..4065eb5cbf2cdb 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -8,25 +8,35 @@
 #
 # 
======#
 
-r"""
+"""
 ClangTidy Test Helper
 =
 
-This script runs clang-tidy in fix mode and verify fixes, messages or both.
+This script is used to simplify writing, running, and debugging tests 
compatible
+with llvm-lit. By default it runs clang-tidy in fix mode and uses FileCheck to
+verify messages and/or fixes.
+
+For debugging, with --export, the tool simply exports fixes to a provided file
+and does not run FileCheck.
+
+Extra arguments, those after the first -- if any, are passed to either
+clang-tidy or clang:
+* Arguments between the first -- and second -- are clang-tidy arguments.
+  * May be only whitespace if there are no clang-tidy arguments.
+  * clang-tidy's --config would go here.
+* Arguments after the second -- are clang arguments
 
-Usage:
-  check_clang_tidy.py [-resource-dir=] \
-[-assume-filename=] \
-[-check-suffix=] \
-[-check-suffixes=] \
-[-std=c++(98|11|14|17|20)[-or-later]] \
-   \
--- [optional clang-tidy arguments]
+Examples
+
 
-Example:
   // RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs
 
-Notes:
+or
+
+  // RUN: %check_clang_tidy %s llvm-include-order --export=fixes.yaml %t 
-std=c++20
+
+Notes
+-
   -std=c++(98|11|14|17|20)-or-later:
 This flag will cause multiple runs within the same check_clang_tidy
 execution. Make sure you don't have shared state across these runs.
@@ -34,6 +44,7 @@
 
 import argparse
 import os
+import pathlib
 import re
 import subprocess
 import sys
@@ -88,6 +99,7 @@ def __init__(self, args, extra_args):
 self.has_check_fixes = False
 self.has_check_messages = False
 self.has_check_notes = False
+self.export = args.export
 self.fixes = MessagePrefix("CHECK-FIXES")
 self.messages = MessagePrefix("CHECK-MESSAGES")
 self.notes = MessagePrefix("CHECK-NOTES")
@@ -181,7 +193,9 @@ def run_clang_tidy(self):
 [
 "clang-tidy",
 self.temp_file_name,
-"-fix",
+]
++ ["-fix" if self.export is None else "--export-fixes=" + 
self.export]
++ [
 "--checks=-*," + self.check_name,
 ]
 + self.clang_tidy_extra_args
@@ -255,12 +269,14 @@ def check_notes(self, clang_tidy_output):
 
 def run(self):
 self.read_input()
-self.get_prefixes()
+if self.export is None:
+self.get_prefixes()
 self.prepare_test_inputs()
 clang_tidy_output = self.run_clang_tidy()
-self.check_fixes()
-self.check_messages(clang_tidy_output)
-self.check_notes(clang_tidy_output)
+if self.export is None:
+self.check_fixes()
+self.check_messages(clang_tidy_output)
+self.check_notes(clang_tidy_output)
 
 
 def expand_std(std):
@@ -284,7 +300,11 @@ def csv(string):
 
 
 def parse_arguments():
-parser = argparse.ArgumentParser()
+parser = argparse.ArgumentParser(
+prog=pathlib.Path(__file__).stem,
+description=__doc__,
+formatter_class=argparse.RawDescriptionHelpFormatter,
+)
 parser.add_argument("-expect-clang-tidy-error", action="store

[clang] [analyzer] Use CDM::CLibrary instead of isGlobalCFunction() (PR #88267)

2024-04-10 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: None (NagyDonat)


Changes

This commit updates several checkers to use call descriptions with the matching 
mode `CDM::CLibrary` instead checking `Call.isGlobalCFunction()` after 
performing the match. This resolves several TODOs in various checkers.

Note that both matching with `CDM::CLibrary` and calling `isGlobalCFunction` 
leads to `CheckerContext::isCLibraryFunction()` checks (so this change is close 
to being NFC), but if it is used via the matching mode then the checker can 
automatically recognize the builtin variants of the matched functions.

I'll also make similar changes in GenericTaintChecker, but that checker has 
separate and inconsistent rules for handling the normal and the builtin variant 
of several functions (e.g. `memcpy` and `__builtin_memcpy`), so I'll put those 
changes into a separate commit.

---

Patch is 20.19 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/88267.diff


5 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp 
(+4-8) 
- (modified) clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp (+72-43) 
- (modified) clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp (+2-8) 
- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+35-34) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp (+17-18) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index c72a97cc01e914..80f128b917b200 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -542,10 +542,10 @@ namespace {
 class CFRetainReleaseChecker : public Checker {
   mutable APIMisuse BT{this, "null passed to CF memory management function"};
   const CallDescriptionSet ModelledCalls = {
-  {{"CFRetain"}, 1},
-  {{"CFRelease"}, 1},
-  {{"CFMakeCollectable"}, 1},
-  {{"CFAutorelease"}, 1},
+  {CDM::CLibrary, {"CFRetain"}, 1},
+  {CDM::CLibrary, {"CFRelease"}, 1},
+  {CDM::CLibrary, {"CFMakeCollectable"}, 1},
+  {CDM::CLibrary, {"CFAutorelease"}, 1},
   };
 
 public:
@@ -555,10 +555,6 @@ class CFRetainReleaseChecker : public 
Checker {
 
 void CFRetainReleaseChecker::checkPreCall(const CallEvent &Call,
   CheckerContext &C) const {
-  // TODO: Make this check part of CallDescription.
-  if (!Call.isGlobalCFunction())
-return;
-
   // Check if we called CFRetain/CFRelease/CFMakeCollectable/CFAutorelease.
   if (!ModelledCalls.contains(Call))
 return;
diff --git a/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
index fa8572cf85edfe..86530086ff1b27 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
@@ -87,7 +87,8 @@ class PthreadLockChecker : public Checker PThreadCallbacks = {
   // Init.
-  {{{"pthread_mutex_init"}, 2}, &PthreadLockChecker::InitAnyLock},
+  {{CDM::CLibrary, {"pthread_mutex_init"}, 2},
+   &PthreadLockChecker::InitAnyLock},
   // TODO: pthread_rwlock_init(2 arguments).
   // TODO: lck_mtx_init(3 arguments).
   // TODO: lck_mtx_alloc_init(2 arguments) => returns the mutex.
@@ -95,74 +96,106 @@ class PthreadLockChecker : public Checker returns the mutex.
 
   // Acquire.
-  {{{"pthread_mutex_lock"}, 1}, &PthreadLockChecker::AcquirePthreadLock},
-  {{{"pthread_rwlock_rdlock"}, 1}, 
&PthreadLockChecker::AcquirePthreadLock},
-  {{{"pthread_rwlock_wrlock"}, 1}, 
&PthreadLockChecker::AcquirePthreadLock},
-  {{{"lck_mtx_lock"}, 1}, &PthreadLockChecker::AcquireXNULock},
-  {{{"lck_rw_lock_exclusive"}, 1}, &PthreadLockChecker::AcquireXNULock},
-  {{{"lck_rw_lock_shared"}, 1}, &PthreadLockChecker::AcquireXNULock},
+  {{CDM::CLibrary, {"pthread_mutex_lock"}, 1},
+   &PthreadLockChecker::AcquirePthreadLock},
+  {{CDM::CLibrary, {"pthread_rwlock_rdlock"}, 1},
+   &PthreadLockChecker::AcquirePthreadLock},
+  {{CDM::CLibrary, {"pthread_rwlock_wrlock"}, 1},
+   &PthreadLockChecker::AcquirePthreadLock},
+  {{CDM::CLibrary, {"lck_mtx_lock"}, 1},
+   &PthreadLockChecker::AcquireXNULock},
+  {{CDM::CLibrary, {"lck_rw_lock_exclusive"}, 1},
+   &PthreadLockChecker::AcquireXNULock},
+  {{CDM::CLibrary, {"lck_rw_lock_shared"}, 1},
+   &PthreadLockChecker::AcquireXNULock},
 
   // Try.
-  {{{"pthread_mutex_trylock"}, 1}, &PthreadLockChecker::TryPthreadLock},
-  {{{"pthread_rwlock_tryrdlock"}, 1}, &PthreadLockChecker::TryPthreadLock},
-  {{{"pthread_rwlock_trywrlock"}, 1}, &PthreadLockChecker::TryPthreadLock},
-  {{{"lck_mtx_try_lock"}, 1}, &PthreadLockChecker::TryXNULo

[clang-tools-extra] [clang-tidy] Simplify RenamerClangTidyCheck API (PR #88268)

2024-04-10 Thread Edwin Vane via cfe-commits

https://github.com/revane created 
https://github.com/llvm/llvm-project/pull/88268

Some functions allow a null SourceManager, no SourceManager, or a SourceManager 
in an inconsistent argument position. Since SourceManager is generally not null 
and it doesn't make sense to apply renaming without one, these inconsistencies 
are now gone.

>From 9808bf777883ecdb041db92e1f611be5ff82996a Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Tue, 9 Apr 2024 16:25:06 -0400
Subject: [PATCH] [clang-tidy] Simplify RenamerClangTidyCheck API

Some functions allow a null SourceManager, no SourceManager, or a
SourceManager in an inconsistent argument position. Since SourceManager
is generally not null and it doesn't make sense to apply renaming
without one, these inconsistencies are now gone.
---
 .../utils/RenamerClangTidyCheck.cpp   | 46 +++
 .../clang-tidy/utils/RenamerClangTidyCheck.h  | 11 +++--
 2 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index ad8048e2a92b7e..962a243ce94d48 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -169,14 +169,14 @@ class RenamerClangTidyCheckPPCallbacks : public 
PPCallbacks {
   return;
 if (SM.isWrittenInCommandLineFile(MacroNameTok.getLocation()))
   return;
-Check->checkMacro(SM, MacroNameTok, Info);
+Check->checkMacro(MacroNameTok, Info, SM);
   }
 
   /// MacroExpands calls expandMacro for macros in the main file
   void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
 SourceRange /*Range*/,
 const MacroArgs * /*Args*/) override {
-Check->expandMacro(MacroNameTok, MD.getMacroInfo());
+Check->expandMacro(MacroNameTok, MD.getMacroInfo(), SM);
   }
 
 private:
@@ -187,7 +187,7 @@ class RenamerClangTidyCheckPPCallbacks : public PPCallbacks 
{
 class RenamerClangTidyVisitor
 : public RecursiveASTVisitor {
 public:
-  RenamerClangTidyVisitor(RenamerClangTidyCheck *Check, const SourceManager 
*SM,
+  RenamerClangTidyVisitor(RenamerClangTidyCheck *Check, const SourceManager 
&SM,
   bool AggressiveDependentMemberLookup)
   : Check(Check), SM(SM),
 AggressiveDependentMemberLookup(AggressiveDependentMemberLookup) {}
@@ -258,7 +258,7 @@ class RenamerClangTidyVisitor
 // Fix overridden methods
 if (const auto *Method = dyn_cast(Decl)) {
   if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) {
-Check->addUsage(Overridden, Method->getLocation());
+Check->addUsage(Overridden, Method->getLocation(), SM);
 return true; // Don't try to add the actual decl as a Failure.
   }
 }
@@ -268,7 +268,7 @@ class RenamerClangTidyVisitor
 if (isa(Decl))
   return true;
 
-Check->checkNamedDecl(Decl, *SM);
+Check->checkNamedDecl(Decl, SM);
 return true;
   }
 
@@ -385,7 +385,7 @@ class RenamerClangTidyVisitor
 
 private:
   RenamerClangTidyCheck *Check;
-  const SourceManager *SM;
+  const SourceManager &SM;
   const bool AggressiveDependentMemberLookup;
 };
 
@@ -415,7 +415,7 @@ void RenamerClangTidyCheck::registerPPCallbacks(
 
 void RenamerClangTidyCheck::addUsage(
 const RenamerClangTidyCheck::NamingCheckId &Decl, SourceRange Range,
-const SourceManager *SourceMgr) {
+const SourceManager &SourceMgr) {
   // Do nothing if the provided range is invalid.
   if (Range.isInvalid())
 return;
@@ -425,8 +425,7 @@ void RenamerClangTidyCheck::addUsage(
   // spelling location to different source locations, and we only want to fix
   // the token once, before it is expanded by the macro.
   SourceLocation FixLocation = Range.getBegin();
-  if (SourceMgr)
-FixLocation = SourceMgr->getSpellingLoc(FixLocation);
+  FixLocation = SourceMgr.getSpellingLoc(FixLocation);
   if (FixLocation.isInvalid())
 return;
 
@@ -440,15 +439,15 @@ void RenamerClangTidyCheck::addUsage(
   if (!Failure.shouldFix())
 return;
 
-  if (SourceMgr && SourceMgr->isWrittenInScratchSpace(FixLocation))
+  if (SourceMgr.isWrittenInScratchSpace(FixLocation))
 Failure.FixStatus = RenamerClangTidyCheck::ShouldFixStatus::InsideMacro;
 
-  if (!utils::rangeCanBeFixed(Range, SourceMgr))
+  if (!utils::rangeCanBeFixed(Range, &SourceMgr))
 Failure.FixStatus = RenamerClangTidyCheck::ShouldFixStatus::InsideMacro;
 }
 
 void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range,
- const SourceManager *SourceMgr) {
+ const SourceManager &SourceMgr) {
   // Don't keep track for non-identifier names.
   auto *II = Decl->getIdentifier();
   if (!II)
@@ -489,18 +488,24 @@ void RenamerClangTidyCheck::checkNamedDecl(const 
NamedDecl *Decl,
   }
 
   Failure.Info = std::move(Info);
-  ad

[clang-tools-extra] [clang-tidy] Simplify RenamerClangTidyCheck API (PR #88268)

2024-04-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Edwin Vane (revane)


Changes

Some functions allow a null SourceManager, no SourceManager, or a SourceManager 
in an inconsistent argument position. Since SourceManager is generally not null 
and it doesn't make sense to apply renaming without one, these inconsistencies 
are now gone.

---
Full diff: https://github.com/llvm/llvm-project/pull/88268.diff


2 Files Affected:

- (modified) clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
(+26-20) 
- (modified) clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h (+6-5) 


``diff
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index ad8048e2a92b7e..962a243ce94d48 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -169,14 +169,14 @@ class RenamerClangTidyCheckPPCallbacks : public 
PPCallbacks {
   return;
 if (SM.isWrittenInCommandLineFile(MacroNameTok.getLocation()))
   return;
-Check->checkMacro(SM, MacroNameTok, Info);
+Check->checkMacro(MacroNameTok, Info, SM);
   }
 
   /// MacroExpands calls expandMacro for macros in the main file
   void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
 SourceRange /*Range*/,
 const MacroArgs * /*Args*/) override {
-Check->expandMacro(MacroNameTok, MD.getMacroInfo());
+Check->expandMacro(MacroNameTok, MD.getMacroInfo(), SM);
   }
 
 private:
@@ -187,7 +187,7 @@ class RenamerClangTidyCheckPPCallbacks : public PPCallbacks 
{
 class RenamerClangTidyVisitor
 : public RecursiveASTVisitor {
 public:
-  RenamerClangTidyVisitor(RenamerClangTidyCheck *Check, const SourceManager 
*SM,
+  RenamerClangTidyVisitor(RenamerClangTidyCheck *Check, const SourceManager 
&SM,
   bool AggressiveDependentMemberLookup)
   : Check(Check), SM(SM),
 AggressiveDependentMemberLookup(AggressiveDependentMemberLookup) {}
@@ -258,7 +258,7 @@ class RenamerClangTidyVisitor
 // Fix overridden methods
 if (const auto *Method = dyn_cast(Decl)) {
   if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) {
-Check->addUsage(Overridden, Method->getLocation());
+Check->addUsage(Overridden, Method->getLocation(), SM);
 return true; // Don't try to add the actual decl as a Failure.
   }
 }
@@ -268,7 +268,7 @@ class RenamerClangTidyVisitor
 if (isa(Decl))
   return true;
 
-Check->checkNamedDecl(Decl, *SM);
+Check->checkNamedDecl(Decl, SM);
 return true;
   }
 
@@ -385,7 +385,7 @@ class RenamerClangTidyVisitor
 
 private:
   RenamerClangTidyCheck *Check;
-  const SourceManager *SM;
+  const SourceManager &SM;
   const bool AggressiveDependentMemberLookup;
 };
 
@@ -415,7 +415,7 @@ void RenamerClangTidyCheck::registerPPCallbacks(
 
 void RenamerClangTidyCheck::addUsage(
 const RenamerClangTidyCheck::NamingCheckId &Decl, SourceRange Range,
-const SourceManager *SourceMgr) {
+const SourceManager &SourceMgr) {
   // Do nothing if the provided range is invalid.
   if (Range.isInvalid())
 return;
@@ -425,8 +425,7 @@ void RenamerClangTidyCheck::addUsage(
   // spelling location to different source locations, and we only want to fix
   // the token once, before it is expanded by the macro.
   SourceLocation FixLocation = Range.getBegin();
-  if (SourceMgr)
-FixLocation = SourceMgr->getSpellingLoc(FixLocation);
+  FixLocation = SourceMgr.getSpellingLoc(FixLocation);
   if (FixLocation.isInvalid())
 return;
 
@@ -440,15 +439,15 @@ void RenamerClangTidyCheck::addUsage(
   if (!Failure.shouldFix())
 return;
 
-  if (SourceMgr && SourceMgr->isWrittenInScratchSpace(FixLocation))
+  if (SourceMgr.isWrittenInScratchSpace(FixLocation))
 Failure.FixStatus = RenamerClangTidyCheck::ShouldFixStatus::InsideMacro;
 
-  if (!utils::rangeCanBeFixed(Range, SourceMgr))
+  if (!utils::rangeCanBeFixed(Range, &SourceMgr))
 Failure.FixStatus = RenamerClangTidyCheck::ShouldFixStatus::InsideMacro;
 }
 
 void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range,
- const SourceManager *SourceMgr) {
+ const SourceManager &SourceMgr) {
   // Don't keep track for non-identifier names.
   auto *II = Decl->getIdentifier();
   if (!II)
@@ -489,18 +488,24 @@ void RenamerClangTidyCheck::checkNamedDecl(const 
NamedDecl *Decl,
   }
 
   Failure.Info = std::move(Info);
-  addUsage(Decl, Range, &SourceMgr);
+  addUsage(Decl, Range, SourceMgr);
 }
 
 void RenamerClangTidyCheck::check(const MatchFinder::MatchResult &Result) {
-  RenamerClangTidyVisitor Visitor(this, Result.SourceManager,
+  if (!Result.SourceManager) {
+// In principle SourceManager is not null but going only by the definition
+// of MatchResult it mu

[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-10 Thread Erich Keane via cfe-commits

https://github.com/erichkeane edited 
https://github.com/llvm/llvm-project/pull/86526
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-10 Thread Erich Keane via cfe-commits


@@ -14527,20 +14525,24 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, 
UnaryOperatorKind Opc,
 UnaryOperator::getOpcodeStr(Opc), OpLoc);
 return ExprError();
 
-  case OR_Deleted:
+  case OR_Deleted: {
 // CreateOverloadedUnaryOp fills the first element of ArgsArray with the
 // object whose method was called. Later in NoteCandidates size of 
ArgsArray
 // is passed further and it eventually ends up compared to number of
 // function candidate parameters which never includes the object parameter,
 // so slice ArgsArray to make sure apples are compared to apples.
+StringLiteral *Msg = Best->Function->getDeletedMessage();
 CandidateSet.NoteCandidates(
 PartialDiagnosticAt(OpLoc, PDiag(diag::err_ovl_deleted_oper)
<< UnaryOperator::getOpcodeStr(Opc)
+   << !!Msg

erichkeane wrote:

Same a few times here... this is a 'neat' trick, but it is something that we 
don't ever do, so it is a touch jarring/takes more thinking than something like 
this should.

https://github.com/llvm/llvm-project/pull/86526
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   >