[clang] [clang] Fix sorting module headers (PR #73146)

2023-11-23 Thread David Blaikie via cfe-commits

dwblaikie wrote:

> OK. I modified this PR in order to only make the changes that fix #73145 . 
> Sorting will remain broken as it has been since 2021. I will provide another 
> PR after this one gets merged.

Thanks, really appreciate your patience/understanding here - I know it's a bit 
of a fuss to split things up, repost, etc. 

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


[clang] [clang] Fix sorting module headers (PR #73146)

2023-11-23 Thread David Blaikie via cfe-commits

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

Sounds reasonable to me, thanks!

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


[clang] [clang] Print static_assert values of arithmetic binary operators (PR #71671)

2023-11-23 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/71671

>From a4db205a672220282735af1c7fcee1b47b334dd7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 8 Nov 2023 13:32:41 +0100
Subject: [PATCH 1/2] [clang] Print static_assert values of arithmetic binary
 operators

These are actually quite useful to print.
---
 clang/lib/Sema/SemaDeclCXX.cpp |  8 
 clang/test/SemaCXX/complex-folding.cpp | 27 +-
 clang/test/SemaCXX/static-assert.cpp   | 10 ++
 3 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 3688192e6cbe5c5..91c9a82bcfa0edc 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17218,10 +17218,10 @@ static bool UsefulToPrintExpr(const Expr *E) {
   if (const auto *UnaryOp = dyn_cast(E))
 return UsefulToPrintExpr(UnaryOp->getSubExpr());
 
-  // Ignore nested binary operators. This could be a FIXME for improvements
-  // to the diagnostics in the future.
-  if (isa(E))
-return false;
+  // Only print nested arithmetic operators.
+  if (const auto *BO = dyn_cast(E))
+return (BO->isShiftOp() || BO->isAdditiveOp() || BO->isMultiplicativeOp() 
||
+BO->isBitwiseOp());
 
   return true;
 }
diff --git a/clang/test/SemaCXX/complex-folding.cpp 
b/clang/test/SemaCXX/complex-folding.cpp
index 8c56cf0e5d984b0..054f159e9ce0dd2 100644
--- a/clang/test/SemaCXX/complex-folding.cpp
+++ b/clang/test/SemaCXX/complex-folding.cpp
@@ -3,7 +3,8 @@
 // Test the constant folding of builtin complex numbers.
 
 static_assert((0.0 + 0.0j) == (0.0 + 0.0j));
-static_assert((0.0 + 0.0j) != (0.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 + 0.0j) != (0.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 
 static_assert((0.0 + 0.0j) == 0.0);
 static_assert(0.0 == (0.0 + 0.0j));
@@ -14,21 +15,29 @@ static_assert(0.0 != 1.0j);
 
 // Walk around the complex plane stepping between angular differences and
 // equality.
-static_assert((1.0 + 0.0j) == (0.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 + 0.0j) == (0.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 + 0.0j) == (1.0 + 0.0j));
-static_assert((1.0 + 1.0j) == (1.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 + 1.0j) == (1.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 + 1.0j) == (1.0 + 1.0j));
-static_assert((0.0 + 1.0j) == (1.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 + 1.0j) == (1.0 + 1.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((0.0 + 1.0j) == (0.0 + 1.0j));
-static_assert((-1.0 + 1.0j) == (0.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 + 1.0j) == (0.0 + 1.0j)); // expected-error {{static 
assertion}} \
+  // expected-note {{evaluates to}}
 static_assert((-1.0 + 1.0j) == (-1.0 + 1.0j));
-static_assert((-1.0 + 0.0j) == (-1.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 + 0.0j) == (-1.0 + 1.0j)); // expected-error {{static 
assertion}} \
+   // expected-note {{evaluates 
to}}
 static_assert((-1.0 + 0.0j) == (-1.0 + 0.0j));
-static_assert((-1.0 - 1.0j) == (-1.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 - 1.0j) == (-1.0 + 0.0j)); // expected-error {{static 
assertion}} \
+   // expected-note {{evaluates 
to}}
 static_assert((-1.0 - 1.0j) == (-1.0 - 1.0j));
-static_assert((0.0 - 1.0j) == (-1.0 - 1.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 - 1.0j) == (-1.0 - 1.0j)); // expected-error {{static 
assertion}} \
+  // expected-note {{evaluates to}}
 static_assert((0.0 - 1.0j) == (0.0 - 1.0j));
-static_assert((1.0 - 1.0j) == (0.0 - 1.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 - 1.0j) == (0.0 - 1.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 - 1.0j) == (1.0 - 1.0j));
 
 // Test basic mathematical folding of both complex and real operands.
diff --git a/clang/test/SemaCXX/static-assert.cpp 
b/clang/test/SemaCXX/static-assert.cpp
index 4200d821339edeb..6e1701602ae30cf 100644
--- a/clang/test/SemaCXX/static-assert.cpp
+++ b/clang/test/SemaCXX/static-assert.cpp
@@ -351,4 +351,14 @@ namespace Diagnostics {
 ""
   );
 
+  

[clang] d80e46d - [RISCV] Support target attribute for function

2023-11-23 Thread Piyou Chen via cfe-commits

Author: Piyou Chen
Date: 2023-11-23T23:05:21-08:00
New Revision: d80e46da7d20645afd7b751a4e6cba9837addcb4

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

LOG: [RISCV] Support target attribute for function

The proposal of target attribute is 
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/35

This patch implements it by emitting .option arch during codegen.

Reviewed By: craig.topper

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

Added: 
clang/test/CodeGen/RISCV/riscv-func-attr-target-err.c
clang/test/CodeGen/RISCV/riscv-func-attr-target.c

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Basic/Targets/RISCV.h
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 990692c06d7d3a8..6894e22da34e0c7 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3177,6 +3177,10 @@ def warn_unsupported_target_attribute
 def err_attribute_unsupported
 : Error<"%0 attribute is not supported on targets missing %1;"
 " specify an appropriate -march= or -mcpu=">;
+def err_duplicate_target_attribute
+: Error<"%select{unsupported|duplicate|unknown}0%select{| CPU|"
+  " tune CPU}1 '%2' in the 
'%select{target|target_clones|target_version}3' "
+  "attribute string; ">;
 // The err_*_attribute_argument_not_int are separate because they're used by
 // VerifyIntegerConstantExpression.
 def err_aligned_attribute_argument_not_int : Error<

diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 0b9ebeaf5e75bbd..0ecc35f3a332a9b 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -235,6 +235,47 @@ ArrayRef 
RISCVTargetInfo::getTargetBuiltins() const {
 clang::RISCV::LastTSBuiltin - Builtin::FirstTSBuiltin);
 }
 
+static std::vector
+collectNonISAExtFeature(const std::vector ,
+int XLen) {
+  auto ParseResult =
+  llvm::RISCVISAInfo::parseFeatures(XLen, FeaturesNeedOverride);
+
+  if (!ParseResult) {
+consumeError(ParseResult.takeError());
+return std::vector();
+  }
+
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+
+  std::vector NonISAExtFeatureVec;
+
+  llvm::copy_if(FeaturesNeedOverride, std::back_inserter(NonISAExtFeatureVec),
+[&](const std::string ) {
+  return !llvm::is_contained(ImpliedFeatures, Feat);
+});
+
+  return NonISAExtFeatureVec;
+}
+
+static std::vector
+resolveTargetAttrOverride(const std::vector ,
+  int XLen) {
+  auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride");
+  if (I == FeaturesVec.end())
+return FeaturesVec;
+
+  const std::vector FeaturesNeedOverride(FeaturesVec.begin(), I);
+  std::vector NonISAExtFeature =
+  collectNonISAExtFeature(FeaturesNeedOverride, XLen);
+
+  auto ResolvedFeature = std::vector(++I, FeaturesVec.end());
+  ResolvedFeature.insert(ResolvedFeature.end(), NonISAExtFeature.begin(),
+ NonISAExtFeature.end());
+
+  return ResolvedFeature;
+}
+
 bool RISCVTargetInfo::initFeatureMap(
 llvm::StringMap , DiagnosticsEngine , StringRef CPU,
 const std::vector ) const {
@@ -248,7 +289,10 @@ bool RISCVTargetInfo::initFeatureMap(
 Features["32bit"] = true;
   }
 
-  auto ParseResult = llvm::RISCVISAInfo::parseFeatures(XLen, FeaturesVec);
+  std::vector NewFeaturesVec =
+  resolveTargetAttrOverride(FeaturesVec, XLen);
+
+  auto ParseResult = llvm::RISCVISAInfo::parseFeatures(XLen, NewFeaturesVec);
   if (!ParseResult) {
 std::string Buffer;
 llvm::raw_string_ostream OutputErrMsg(Buffer);
@@ -262,7 +306,7 @@ bool RISCVTargetInfo::initFeatureMap(
   // RISCVISAInfo makes implications for ISA features
   std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
   // Add non-ISA features like `relax` and `save-restore` back
-  for (const std::string  : FeaturesVec)
+  for (const std::string  : NewFeaturesVec)
 if (!llvm::is_contained(ImpliedFeatures, Feature))
   ImpliedFeatures.push_back(Feature);
 
@@ -359,3 +403,82 @@ void RISCVTargetInfo::fillValidTuneCPUList(
   bool Is64Bit = getTriple().isArch64Bit();
   llvm::RISCV::fillValidTuneCPUArchList(Values, Is64Bit);
 }
+
+static void handleFullArchString(StringRef FullArchStr,
+ std::vector ) {
+  Features.push_back("__RISCV_TargetAttrNeedOverride");
+  auto RII = llvm::RISCVISAInfo::parseArchString(
+  FullArchStr, /* EnableExperimentalExtension */ true);
+  if (!RII) 

[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)

2023-11-23 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/73290

>From a29523ed19ccb36554ea7ad2597631da26d8baaa Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 24 Nov 2023 13:55:45 +0800
Subject: [PATCH] [clang][ASTImporter] IdentifierInfo of Attribute should be
 set using ToASTContext

---
 clang/include/clang/Basic/AttributeCommonInfo.h |  1 +
 clang/lib/AST/ASTImporter.cpp   |  7 +--
 clang/unittests/AST/ASTImporterTest.cpp | 13 +++--
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 3140d1a838afcec..018b92fdc11f559 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -177,6 +177,7 @@ class AttributeCommonInfo {
 IsRegularKeywordAttribute);
   }
   const IdentifierInfo *getAttrName() const { return AttrName; }
+  void setAttrName(const IdentifierInfo *AttrNameII) { AttrName = AttrNameII; }
   SourceLocation getLoc() const { return AttrRange.getBegin(); }
   SourceRange getRange() const { return AttrRange; }
   void setRange(SourceRange R) { AttrRange = R; }
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index c4e931e220f69b5..19e3e94c70c82d5 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -9241,9 +9241,12 @@ Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) {
 return Error::success();
   for (const Attr *FromAttr : FromD->getAttrs()) {
 auto ToAttrOrErr = Import(FromAttr);
-if (ToAttrOrErr)
+if (ToAttrOrErr) {
+  if (auto *FromAttrNameII = FromAttr->getAttrName())
+(*ToAttrOrErr)
+->setAttrName((FromAttrNameII->getName()));
   ToD->addAttr(*ToAttrOrErr);
-else
+} else
   return ToAttrOrErr.takeError();
   }
   return Error::success();
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 5f4d8d040772cb1..2df92ad9d5985a4 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/AST/RecordLayout.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/SmallVectorMemoryBuffer.h"
 
 #include "clang/AST/DeclContextInternals.h"
@@ -7362,11 +7363,12 @@ struct ImportAttributes : public 
ASTImporterOptionSpecificTestBase {
   }
 
   template 
-  void importAttr(const char *Code, AT *, AT *) {
+  void importAttr(const char *Code, AT *, AT *,
+  TestLanguage Lang = Lang_CXX11) {
 static_assert(std::is_base_of::value, "AT should be an Attr");
 static_assert(std::is_base_of::value, "DT should be a Decl");
 
-Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc");
+Decl *FromTU = getTuDecl(Code, Lang, "input.cc");
 DT *FromD =
 FirstDeclMatcher().match(FromTU, namedDecl(hasName("test")));
 ASSERT_TRUE(FromD);
@@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) {
   checkImportVariadicArg(FromAttr->args(), ToAttr->args());
 }
 
+TEST_P(ImportAttributes, ImportC99NoThrowAttr) {
+  NoThrowAttr *FromAttr, *ToAttr;
+  importAttr("void test () __attribute__ ((__nothrow__));",
+   FromAttr, ToAttr, Lang_C99);
+  checkImported(FromAttr->getAttrName(), ToAttr->getAttrName());
+}
+
 template 
 auto ExtendWithOptions(const T , const std::vector ) {
   auto Copy = Values;

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


[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)

2023-11-23 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/73290

>From 52b972fd84877793fa8099cfb0b5d934c39e5925 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 24 Nov 2023 13:55:45 +0800
Subject: [PATCH] [clang][ASTImporter] IdentifierInfo of Attribute should be
 set using ToASTContext

---
 clang/include/clang/Basic/AttributeCommonInfo.h |  1 +
 clang/lib/AST/ASTImporter.cpp   |  7 +--
 clang/unittests/AST/ASTImporterTest.cpp | 13 +++--
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 3140d1a838afcec..f84f51b1cd25022 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -177,6 +177,7 @@ class AttributeCommonInfo {
 IsRegularKeywordAttribute);
   }
   const IdentifierInfo *getAttrName() const { return AttrName; }
+  void setAttrName(const IdentifierInfo *A) { AttrName = A; }
   SourceLocation getLoc() const { return AttrRange.getBegin(); }
   SourceRange getRange() const { return AttrRange; }
   void setRange(SourceRange R) { AttrRange = R; }
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index c4e931e220f69b5..19e3e94c70c82d5 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -9241,9 +9241,12 @@ Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) {
 return Error::success();
   for (const Attr *FromAttr : FromD->getAttrs()) {
 auto ToAttrOrErr = Import(FromAttr);
-if (ToAttrOrErr)
+if (ToAttrOrErr) {
+  if (auto *FromAttrNameII = FromAttr->getAttrName())
+(*ToAttrOrErr)
+->setAttrName((FromAttrNameII->getName()));
   ToD->addAttr(*ToAttrOrErr);
-else
+} else
   return ToAttrOrErr.takeError();
   }
   return Error::success();
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 5f4d8d040772cb1..2df92ad9d5985a4 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/AST/RecordLayout.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/SmallVectorMemoryBuffer.h"
 
 #include "clang/AST/DeclContextInternals.h"
@@ -7362,11 +7363,12 @@ struct ImportAttributes : public 
ASTImporterOptionSpecificTestBase {
   }
 
   template 
-  void importAttr(const char *Code, AT *, AT *) {
+  void importAttr(const char *Code, AT *, AT *,
+  TestLanguage Lang = Lang_CXX11) {
 static_assert(std::is_base_of::value, "AT should be an Attr");
 static_assert(std::is_base_of::value, "DT should be a Decl");
 
-Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc");
+Decl *FromTU = getTuDecl(Code, Lang, "input.cc");
 DT *FromD =
 FirstDeclMatcher().match(FromTU, namedDecl(hasName("test")));
 ASSERT_TRUE(FromD);
@@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) {
   checkImportVariadicArg(FromAttr->args(), ToAttr->args());
 }
 
+TEST_P(ImportAttributes, ImportC99NoThrowAttr) {
+  NoThrowAttr *FromAttr, *ToAttr;
+  importAttr("void test () __attribute__ ((__nothrow__));",
+   FromAttr, ToAttr, Lang_C99);
+  checkImported(FromAttr->getAttrName(), ToAttr->getAttrName());
+}
+
 template 
 auto ExtendWithOptions(const T , const std::vector ) {
   auto Copy = Values;

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


[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)

2023-11-23 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/73290

>From 150993c21943203d3fd116c3a0456eaea81008de Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 24 Nov 2023 13:55:45 +0800
Subject: [PATCH] [clang][ASTImporter] IdentifierInfo of Attribute should be
 set using ToASTContext

---
 clang/lib/AST/ASTImporter.cpp   |  7 +--
 clang/unittests/AST/ASTImporterTest.cpp | 13 +++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index c4e931e220f69b5..19e3e94c70c82d5 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -9241,9 +9241,12 @@ Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) {
 return Error::success();
   for (const Attr *FromAttr : FromD->getAttrs()) {
 auto ToAttrOrErr = Import(FromAttr);
-if (ToAttrOrErr)
+if (ToAttrOrErr) {
+  if (auto *FromAttrNameII = FromAttr->getAttrName())
+(*ToAttrOrErr)
+->setAttrName((FromAttrNameII->getName()));
   ToD->addAttr(*ToAttrOrErr);
-else
+} else
   return ToAttrOrErr.takeError();
   }
   return Error::success();
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 5f4d8d040772cb1..2df92ad9d5985a4 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/AST/RecordLayout.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/SmallVectorMemoryBuffer.h"
 
 #include "clang/AST/DeclContextInternals.h"
@@ -7362,11 +7363,12 @@ struct ImportAttributes : public 
ASTImporterOptionSpecificTestBase {
   }
 
   template 
-  void importAttr(const char *Code, AT *, AT *) {
+  void importAttr(const char *Code, AT *, AT *,
+  TestLanguage Lang = Lang_CXX11) {
 static_assert(std::is_base_of::value, "AT should be an Attr");
 static_assert(std::is_base_of::value, "DT should be a Decl");
 
-Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc");
+Decl *FromTU = getTuDecl(Code, Lang, "input.cc");
 DT *FromD =
 FirstDeclMatcher().match(FromTU, namedDecl(hasName("test")));
 ASSERT_TRUE(FromD);
@@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) {
   checkImportVariadicArg(FromAttr->args(), ToAttr->args());
 }
 
+TEST_P(ImportAttributes, ImportC99NoThrowAttr) {
+  NoThrowAttr *FromAttr, *ToAttr;
+  importAttr("void test () __attribute__ ((__nothrow__));",
+   FromAttr, ToAttr, Lang_C99);
+  checkImported(FromAttr->getAttrName(), ToAttr->getAttrName());
+}
+
 template 
 auto ExtendWithOptions(const T , const std::vector ) {
   auto Copy = Values;

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


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -0,0 +1,109 @@
+//===--- RedundantInlineSpecifierCheck.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Token.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  if (const auto *FD = dyn_cast())
+return FD->isInlineSpecified();
+  if (const auto *VD = dyn_cast())
+return VD->isInlineSpecified();
+  llvm_unreachable("Not a valid polymorphic type");
+}
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  Token FirstToken;
+  Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
+ true);
+  std::optional CurrentToken = FirstToken;
+  while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
+ CurrentToken->isNot(tok::eof)) {
+if (CurrentToken->is(tok::raw_identifier) &&
+CurrentToken->getRawIdentifier() == "inline")
+  return CurrentToken->getLocation();
+
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), isInlineSpecified(),
+   anyOf(isConstexpr(), isDeleted(),

PiotrZSL wrote:

maybe methods that are = default also should be ignored ?

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


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -0,0 +1,109 @@
+//===--- RedundantInlineSpecifierCheck.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Token.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  if (const auto *FD = dyn_cast())
+return FD->isInlineSpecified();
+  if (const auto *VD = dyn_cast())
+return VD->isInlineSpecified();
+  llvm_unreachable("Not a valid polymorphic type");
+}
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  Token FirstToken;
+  Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
+ true);
+  std::optional CurrentToken = FirstToken;
+  while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
+ CurrentToken->isNot(tok::eof)) {
+if (CurrentToken->is(tok::raw_identifier) &&
+CurrentToken->getRawIdentifier() == "inline")
+  return CurrentToken->getLocation();
+
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), isInlineSpecified(),
+   anyOf(isConstexpr(), isDeleted(),
+ allOf(isDefinition(), hasAncestor(recordDecl()
+  .bind("fun_decl"),
+  this);
+
+  Finder->addMatcher(
+  varDecl(isInlineSpecified(),
+  anyOf(allOf(isConstexpr(), unless(isStaticStorageClass())),
+hasAncestor(recordDecl(
+  .bind("var_decl"),
+  this);
+
+  Finder->addMatcher(
+  functionTemplateDecl(has(functionDecl(isInlineSpecified(

PiotrZSL wrote:

what about code like this:
```
template  inline T f();

template   T f()
{
return T{};
}
```

do we want to spam a warning for a forward declaration ?
or 

```
template   T f();

template  inline T f()
{
return T{};
}
```

Wont warning be emitted here a forward declaration ?

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


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -0,0 +1,109 @@
+//===--- RedundantInlineSpecifierCheck.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Token.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  if (const auto *FD = dyn_cast())
+return FD->isInlineSpecified();
+  if (const auto *VD = dyn_cast())
+return VD->isInlineSpecified();
+  llvm_unreachable("Not a valid polymorphic type");
+}
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  Token FirstToken;
+  Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
+ true);
+  std::optional CurrentToken = FirstToken;
+  while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
+ CurrentToken->isNot(tok::eof)) {
+if (CurrentToken->is(tok::raw_identifier) &&
+CurrentToken->getRawIdentifier() == "inline")
+  return CurrentToken->getLocation();
+
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), isInlineSpecified(),

PiotrZSL wrote:

what if function is in anonymous namespace

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


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -0,0 +1,109 @@
+//===--- RedundantInlineSpecifierCheck.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Token.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  if (const auto *FD = dyn_cast())
+return FD->isInlineSpecified();
+  if (const auto *VD = dyn_cast())
+return VD->isInlineSpecified();
+  llvm_unreachable("Not a valid polymorphic type");
+}
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  Token FirstToken;
+  Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
+ true);
+  std::optional CurrentToken = FirstToken;
+  while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
+ CurrentToken->isNot(tok::eof)) {
+if (CurrentToken->is(tok::raw_identifier) &&
+CurrentToken->getRawIdentifier() == "inline")
+  return CurrentToken->getLocation();
+
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), isInlineSpecified(),
+   anyOf(isConstexpr(), isDeleted(),
+ allOf(isDefinition(), hasAncestor(recordDecl()
+  .bind("fun_decl"),
+  this);
+
+  Finder->addMatcher(

PiotrZSL wrote:

You could check LangOpts if inline variables are enabled, and do not register 
this matcher at all if not.

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


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -0,0 +1,110 @@
+// RUN: %check_clang_tidy %s readability-redundant-inline-specifier %t
+
+template  inline T f()
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: function 'f' has inline specifier 
but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: template  T f()
+{
+return T{};
+}
+
+template <> inline double f() = delete;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'f' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: template <> double f() = delete;
+
+inline int g(float a)
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:1: warning: function 'g' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+{
+return static_cast(a - 5.F);
+}
+
+inline int g(double) = delete;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: function 'g' has inline specifier 
but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: int g(double) = delete;
+
+class C
+{
+  public:
+inline C& operator=(const C&) = delete;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'operator=' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+// CHECK-FIXES: C& operator=(const C&) = delete;
+
+constexpr inline C& operator=(int a);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'operator=' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr C& operator=(int a);
+
+inline C() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'C' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: C() {}
+
+constexpr inline C(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'C' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr C(int);
+
+inline int Get42() const { return 42; }
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'Get42' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: int Get42() const { return 42; }
+
+static inline constexpr int C_STATIC = 42;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'C_STATIC' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+// CHECK-FIXES: static constexpr int C_STATIC = 42;
+
+static constexpr int C_STATIC_2 = 42;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: variable 'C_STATIC_2' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+};
+
+constexpr inline int Get42() { return 42; }
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: function 'Get42' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr int Get42() { return 42; }
+
+
+static constexpr inline int NAMESPACE_STATIC = 42;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:18: warning: variable 'NAMESPACE_STATIC' 
has inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+
+inline static int fn0(int i)
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:1: warning: function 'fn0' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+{
+return i - 1;
+}
+
+static constexpr inline int fn1(int i)
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: function 'fn1' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: static constexpr int fn1(int i)
+{
+return i - 1;
+}
+
+namespace
+{
+inline int fn2(int i)
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: function 'fn2' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+{
+return i - 1;
+}
+
+inline constexpr int fn3(int i)
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'fn3' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr int fn3(int i)
+{
+return i - 1;
+}
+}
+
+namespace ns
+{
+inline int fn4(int i)
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: function 'fn4' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+{
+return i - 1;
+}
+
+inline constexpr int fn5(int i)
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'fn5' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr int fn5(int i)
+{
+return i - 1;
+}
+}
+
+auto fn6 = [](){};
+//CHECK-MESSAGES-NOT: :[[@LINE-1]]:1: warning: function 'operator()' has 
inline specifier 

[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -0,0 +1,109 @@
+//===--- RedundantInlineSpecifierCheck.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Token.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  if (const auto *FD = dyn_cast())
+return FD->isInlineSpecified();
+  if (const auto *VD = dyn_cast())
+return VD->isInlineSpecified();
+  llvm_unreachable("Not a valid polymorphic type");
+}
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  Token FirstToken;
+  Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
+ true);
+  std::optional CurrentToken = FirstToken;
+  while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
+ CurrentToken->isNot(tok::eof)) {
+if (CurrentToken->is(tok::raw_identifier) &&
+CurrentToken->getRawIdentifier() == "inline")
+  return CurrentToken->getLocation();
+
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), isInlineSpecified(),

PiotrZSL wrote:

You can remove isExpansionInSystemHeader, it were added as an optimization.


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


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -0,0 +1,109 @@
+//===--- RedundantInlineSpecifierCheck.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Token.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  if (const auto *FD = dyn_cast())
+return FD->isInlineSpecified();
+  if (const auto *VD = dyn_cast())
+return VD->isInlineSpecified();
+  llvm_unreachable("Not a valid polymorphic type");
+}
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  Token FirstToken;
+  Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
+ true);
+  std::optional CurrentToken = FirstToken;
+  while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
+ CurrentToken->isNot(tok::eof)) {
+if (CurrentToken->is(tok::raw_identifier) &&
+CurrentToken->getRawIdentifier() == "inline")
+  return CurrentToken->getLocation();
+
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), isInlineSpecified(),
+   anyOf(isConstexpr(), isDeleted(),
+ allOf(isDefinition(), hasAncestor(recordDecl()
+  .bind("fun_decl"),
+  this);
+
+  Finder->addMatcher(
+  varDecl(isInlineSpecified(),
+  anyOf(allOf(isConstexpr(), unless(isStaticStorageClass())),

PiotrZSL wrote:

what about variables in anonymous namespace ?
what if variable already got internal linkage ?

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


[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)

2023-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qizhi Hu (jcsxky)


Changes



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


3 Files Affected:

- (modified) clang/include/clang/Basic/AttributeCommonInfo.h (+1) 
- (modified) clang/lib/AST/ASTImporter.cpp (+5-2) 
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+11-2) 


``diff
diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 3140d1a838afcec..f84f51b1cd25022 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -177,6 +177,7 @@ class AttributeCommonInfo {
 IsRegularKeywordAttribute);
   }
   const IdentifierInfo *getAttrName() const { return AttrName; }
+  void setAttrName(const IdentifierInfo *A) { AttrName = A; }
   SourceLocation getLoc() const { return AttrRange.getBegin(); }
   SourceRange getRange() const { return AttrRange; }
   void setRange(SourceRange R) { AttrRange = R; }
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index c4e931e220f69b5..19e3e94c70c82d5 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -9241,9 +9241,12 @@ Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) {
 return Error::success();
   for (const Attr *FromAttr : FromD->getAttrs()) {
 auto ToAttrOrErr = Import(FromAttr);
-if (ToAttrOrErr)
+if (ToAttrOrErr) {
+  if (auto *FromAttrNameII = FromAttr->getAttrName())
+(*ToAttrOrErr)
+->setAttrName((FromAttrNameII->getName()));
   ToD->addAttr(*ToAttrOrErr);
-else
+} else
   return ToAttrOrErr.takeError();
   }
   return Error::success();
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 5f4d8d040772cb1..2df92ad9d5985a4 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/AST/RecordLayout.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/SmallVectorMemoryBuffer.h"
 
 #include "clang/AST/DeclContextInternals.h"
@@ -7362,11 +7363,12 @@ struct ImportAttributes : public 
ASTImporterOptionSpecificTestBase {
   }
 
   template 
-  void importAttr(const char *Code, AT *, AT *) {
+  void importAttr(const char *Code, AT *, AT *,
+  TestLanguage Lang = Lang_CXX11) {
 static_assert(std::is_base_of::value, "AT should be an Attr");
 static_assert(std::is_base_of::value, "DT should be a Decl");
 
-Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc");
+Decl *FromTU = getTuDecl(Code, Lang, "input.cc");
 DT *FromD =
 FirstDeclMatcher().match(FromTU, namedDecl(hasName("test")));
 ASSERT_TRUE(FromD);
@@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) {
   checkImportVariadicArg(FromAttr->args(), ToAttr->args());
 }
 
+TEST_P(ImportAttributes, ImportC99NoThrowAttr) {
+  NoThrowAttr *FromAttr, *ToAttr;
+  importAttr("void test () __attribute__ ((__nothrow__));",
+   FromAttr, ToAttr, Lang_C99);
+  checkImported(FromAttr->getAttrName(), ToAttr->getAttrName());
+}
+
 template 
 auto ExtendWithOptions(const T , const std::vector ) {
   auto Copy = Values;

``




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


[clang] [clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (PR #73290)

2023-11-23 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky created 
https://github.com/llvm/llvm-project/pull/73290

None

>From cc883836b0c24368a7a438873cec2229776323da Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 24 Nov 2023 13:55:45 +0800
Subject: [PATCH] [clang][ASTImporter] IdentifierInfo of Attribute should be
 set using ToASTContext

---
 clang/include/clang/Basic/AttributeCommonInfo.h |  1 +
 clang/lib/AST/ASTImporter.cpp   |  7 +--
 clang/unittests/AST/ASTImporterTest.cpp | 13 +++--
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 3140d1a838afcec..f84f51b1cd25022 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -177,6 +177,7 @@ class AttributeCommonInfo {
 IsRegularKeywordAttribute);
   }
   const IdentifierInfo *getAttrName() const { return AttrName; }
+  void setAttrName(const IdentifierInfo *A) { AttrName = A; }
   SourceLocation getLoc() const { return AttrRange.getBegin(); }
   SourceRange getRange() const { return AttrRange; }
   void setRange(SourceRange R) { AttrRange = R; }
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index c4e931e220f69b5..19e3e94c70c82d5 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -9241,9 +9241,12 @@ Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) {
 return Error::success();
   for (const Attr *FromAttr : FromD->getAttrs()) {
 auto ToAttrOrErr = Import(FromAttr);
-if (ToAttrOrErr)
+if (ToAttrOrErr) {
+  if (auto *FromAttrNameII = FromAttr->getAttrName())
+(*ToAttrOrErr)
+->setAttrName((FromAttrNameII->getName()));
   ToD->addAttr(*ToAttrOrErr);
-else
+} else
   return ToAttrOrErr.takeError();
   }
   return Error::success();
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 5f4d8d040772cb1..2df92ad9d5985a4 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/AST/RecordLayout.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Testing/CommandLineArgs.h"
 #include "llvm/Support/SmallVectorMemoryBuffer.h"
 
 #include "clang/AST/DeclContextInternals.h"
@@ -7362,11 +7363,12 @@ struct ImportAttributes : public 
ASTImporterOptionSpecificTestBase {
   }
 
   template 
-  void importAttr(const char *Code, AT *, AT *) {
+  void importAttr(const char *Code, AT *, AT *,
+  TestLanguage Lang = Lang_CXX11) {
 static_assert(std::is_base_of::value, "AT should be an Attr");
 static_assert(std::is_base_of::value, "DT should be a Decl");
 
-Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc");
+Decl *FromTU = getTuDecl(Code, Lang, "input.cc");
 DT *FromD =
 FirstDeclMatcher().match(FromTU, namedDecl(hasName("test")));
 ASSERT_TRUE(FromD);
@@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) {
   checkImportVariadicArg(FromAttr->args(), ToAttr->args());
 }
 
+TEST_P(ImportAttributes, ImportC99NoThrowAttr) {
+  NoThrowAttr *FromAttr, *ToAttr;
+  importAttr("void test () __attribute__ ((__nothrow__));",
+   FromAttr, ToAttr, Lang_C99);
+  checkImported(FromAttr->getAttrName(), ToAttr->getAttrName());
+}
+
 template 
 auto ExtendWithOptions(const T , const std::vector ) {
   auto Copy = Values;

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


[clang] [clang][AST][ASTMerge] prevent AST nodes from being deallocated early (PR #73096)

2023-11-23 Thread Qizhi Hu via cfe-commits

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


[clang] [clang][AST][ASTMerge] prevent AST nodes from being deallocated early (PR #73096)

2023-11-23 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> You have found that reason for the crash is that references to 
> `IdentifierInfo` are remaining in `OnDiskChainedHashTableGenerator` and 
> previously deallocated by `ASTUnit` destruction? In this case why is the 
> `ASTUnit` (or something in it, probably `ASTContext`) the owner of the data, 
> and not `OnDiskChainedHashTableGenerator`? By using `ASTImporter` it is 
> possible that it moves data from the "old" AST to the "new" without copy (if 
> yes this is a bug) and such a situation can cause memory errors.

Thanks for your remind! Indeed, root cause of the issue is ASTImporter and I 
have checked the code. IdentifierInfo of attribute should set with 
`ToASTContext` instead of copying from `FromASTContext`.




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


[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-23 Thread Lu Weining via cfe-commits

https://github.com/SixWeining updated 
https://github.com/llvm/llvm-project/pull/72514

>From 8dd5bebcd4681e5e7849743aba0ce90c2959ee23 Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Thu, 16 Nov 2023 21:57:03 +0800
Subject: [PATCH 1/2] [Driver] Support -mcmodel= for LoongArch

7e42545 rejects unsupported mcmodel options, but small/medium/large
should be supported models for LoongArch. In addition, to be compatible
with gcc, mapping some of their values to clang's.

The mapping is:
 gcc[1] vs clang[2]
   "normal""small"
   "medium""medium"
   "extreme"   "large"

And AFAIK, gcc side doesn't plan to implement the "large" code model.

[1]: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html
[2]: https://reviews.llvm.org/D150522
---
 clang/lib/Driver/ToolChains/Clang.cpp | 10 ++
 clang/test/Driver/mcmodel.c   | 13 +
 2 files changed, 23 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b462f5a44057d94..3a7e56f37259cb8 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   if (CM == "large" && RelocationModel != llvm::Reloc::Static)
 D.Diag(diag::err_drv_argument_only_allowed_with)
 << A->getAsString(Args) << "-fno-pic";
+} else if (Triple.isLoongArch()) {
+  CM = llvm::StringSwitch(CM)
+   .Case("normal", "small")
+   .Case("extreme", "large")
+   .Default(CM);
+  if (CM == "large" &&
+  Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false))
+D.Diag(diag::err_drv_argument_not_allowed_with)
+<< A->getAsString(Args) << "-fplt";
+  Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isPPC64() || Triple.isOSAIX()) {
   Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isRISCV()) {
diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c
index d8a41b0f5abd9aa..72be740216a81b3 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -15,6 +15,15 @@
 // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | 
FileCheck --check-prefix=ERR-MEDIUM %s
 // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | 
FileCheck --check-prefix=ERR-KERNEL %s
 // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | 
FileCheck --check-prefix=ERR-AARCH64_32 %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=small %s 2>&1 | FileCheck 
--check-prefix=SMALL %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | 
FileCheck --check-prefix=SMALL %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | 
FileCheck --check-prefix=MEDIUM %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=large %s 2>&1 | FileCheck 
--check-prefix=LARGE %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | 
FileCheck --check-prefix=LARGE %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=tiny %s 2>&1 | 
FileCheck --check-prefix=ERR-TINY %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=kernel %s 2>&1 | 
FileCheck --check-prefix=ERR-KERNEL %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=large -fplt %s 2>&1 | 
FileCheck --check-prefix=ERR-LOONGARCH64-PLT-LARGE %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=extreme -fplt %s 2>&1 
| FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s
 
 // TINY: "-mcmodel=tiny"
 // SMALL: "-mcmodel=small"
@@ -25,9 +34,13 @@
 
 // INVALID: error: unsupported argument 'lager' to option '-mcmodel=' for 
target '{{.*}}'
 
+// ERR-TINY: error: unsupported argument 'tiny' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-MEDIUM: error: unsupported argument 'medium' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-KERNEL: error: unsupported argument 'kernel' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-LARGE:  error: unsupported argument 'large' to option '-mcmodel=' for 
target '{{.*}}'
 
 // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed 
with '-fno-pic'
 // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' 
for target 'aarch64_32-unknown-linux'
+
+// ERR-LOONGARCH64-PLT-LARGE: error: invalid argument '-mcmodel=large' not 
allowed with '-fplt'
+// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not 
allowed with '-fplt'

>From 240149f7196c88d418d9c39c60b478b5c3aeb11c Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Fri, 24 Nov 2023 13:56:28 +0800
Subject: [PATCH 2/2] Reject small and large. Only accept normal, medium and
 extreme

---
 clang/lib/Driver/ToolChains/Clang.cpp | 16 +---
 clang/test/Driver/mcmodel.c   |  8 
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git 

[flang] [libcxx] [lld] [clang] [llvm] [compiler-rt] [libc] Fix ISel crash when lowering BUILD_VECTOR (PR #73186)

2023-11-23 Thread David Li via cfe-commits


@@ -7254,6 +7255,10 @@ static SDValue 
lowerBuildVectorAsBroadcast(BuildVectorSDNode *BVOp,
 EVT CVT = Ld.getValueType();
 assert(!CVT.isVector() && "Must not broadcast a vector type");
 
+// 512 bit vpbroadcastw is only available with AVX512BW
+if (ScalarSize == 16 && IsGT256 && !Subtarget.hasBWI())
+  return SDValue();

david-xl wrote:

Done with some refactoring. PTAL.

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


[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-23 Thread Lu Weining via cfe-commits

SixWeining wrote:

> [gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html](https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html)
>  says
> 
> ‘large (Not implemented yet)’ ‘extreme’ This mode does not limit the size of 
> the code segment and data segment. The -mcmodel=extreme option is 
> incompatible with -fplt, and it requires -mexplicit-relocs=always.
> 
> Is there a psABI defining 'extreme' or 'large'?

Currently there is no definition in psABI except in gcc doc: 
https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html. Maybe we can define 
them in next psABI version.

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


[clang-tools-extra] [llvm] [RISCV][Zba] Optimize mul with SH*ADD (PR #68144)

2023-11-23 Thread Alexandr Lekomtsev via cfe-commits

https://github.com/vacma updated 
https://github.com/llvm/llvm-project/pull/68144

>From 64e5deade92206cd04f86e0665a482ea78d0f3bf Mon Sep 17 00:00:00 2001
From: Alexandr 
Date: Sun, 1 Oct 2023 19:57:01 +0300
Subject: [PATCH 1/3] [RISCV][Zba] Optimize mul with SH*ADD

Optimized multiplication by constants 23, 29, 35, 39, 43, 47,
49, 51, 53, 55, 57, 59, 61, 69, 75, 77, 83, 85, 87, 89, 91,
93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 117, 121,
123, 125, 135, 137, 145, 147, 149, 153, 155, 157, 161, 163,
165, 169, 171, 173, 181, 185, 189, 201, 203, 205, 217, 219,
225, 243, 293, 297, 301, 305, 325, 329, 333, 361, 365, 369,
405, 585, 593, 649, 657, 729
---
 llvm/lib/Target/RISCV/RISCVInstrInfoZb.td |  161 +++
 llvm/test/CodeGen/RISCV/rv32zba.ll| 1292 +
 llvm/test/CodeGen/RISCV/rv64zba.ll| 1292 +
 3 files changed, 2745 insertions(+)

diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td 
b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
index a21c3d132636bea..cbd8fad30cd1a20 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
@@ -718,12 +718,173 @@ def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 41)),
   (SH3ADD (SH2ADD GPR:$r, GPR:$r), GPR:$r)>;
 def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 73)),
   (SH3ADD (SH3ADD GPR:$r, GPR:$r), GPR:$r)>;
+
 def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 27)),
   (SH1ADD (SH3ADD GPR:$r, GPR:$r), (SH3ADD GPR:$r, GPR:$r))>;
 def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 45)),
   (SH2ADD (SH3ADD GPR:$r, GPR:$r), (SH3ADD GPR:$r, GPR:$r))>;
 def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 81)),
   (SH3ADD (SH3ADD GPR:$r, GPR:$r), (SH3ADD GPR:$r, GPR:$r))>;
+
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 61)),
+  (SH2ADD (SH2ADD (SH1ADD GPR:$r, GPR:$r), (SH1ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 121)),
+  (SH3ADD (SH2ADD (SH1ADD GPR:$r, GPR:$r), (SH1ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 55)),
+  (SH1ADD (SH3ADD (SH1ADD GPR:$r, GPR:$r), (SH1ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 109)),
+  (SH2ADD (SH3ADD (SH1ADD GPR:$r, GPR:$r), (SH1ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 217)),
+  (SH3ADD (SH3ADD (SH1ADD GPR:$r, GPR:$r), (SH1ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 51)),
+  (SH1ADD (SH2ADD (SH2ADD GPR:$r, GPR:$r), (SH2ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 101)),
+  (SH2ADD (SH2ADD (SH2ADD GPR:$r, GPR:$r), (SH2ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 201)),
+  (SH3ADD (SH2ADD (SH2ADD GPR:$r, GPR:$r), (SH2ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 91)),
+  (SH1ADD (SH3ADD (SH2ADD GPR:$r, GPR:$r), (SH2ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 181)),
+  (SH2ADD (SH3ADD (SH2ADD GPR:$r, GPR:$r), (SH2ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 361)),
+  (SH3ADD (SH3ADD (SH2ADD GPR:$r, GPR:$r), (SH2ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 163)),
+  (SH1ADD (SH3ADD (SH3ADD GPR:$r, GPR:$r), (SH3ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 325)),
+  (SH2ADD (SH3ADD (SH3ADD GPR:$r, GPR:$r), (SH3ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 649)),
+  (SH3ADD (SH3ADD (SH3ADD GPR:$r, GPR:$r), (SH3ADD GPR:$r, GPR:$r)), 
GPR:$r)>;
+
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 29)),
+  (SH2ADD (SH1ADD (SH1ADD GPR:$r, GPR:$r), GPR:$r), GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 57)),
+  (SH3ADD (SH1ADD (SH1ADD GPR:$r, GPR:$r), GPR:$r), GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 53)),
+  (SH2ADD (SH2ADD (SH1ADD GPR:$r, GPR:$r), GPR:$r), GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 105)),
+  (SH3ADD (SH2ADD (SH1ADD GPR:$r, GPR:$r), GPR:$r), GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 23)),
+  (SH1ADD (SH1ADD (SH2ADD GPR:$r, GPR:$r), GPR:$r), GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 89)),
+  (SH3ADD (SH1ADD (SH2ADD GPR:$r, GPR:$r), GPR:$r), GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 43)),
+  (SH1ADD (SH2ADD (SH2ADD GPR:$r, GPR:$r), GPR:$r), GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 85)),
+  (SH2ADD (SH2ADD (SH2ADD GPR:$r, GPR:$r), GPR:$r), GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 169)),
+  (SH3ADD (SH2ADD (SH2ADD GPR:$r, GPR:$r), GPR:$r), GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 83)),
+  (SH1ADD (SH3ADD (SH2ADD GPR:$r, GPR:$r), GPR:$r), GPR:$r)>;
+def : Pat<(mul_const_oneuse GPR:$r, (XLenVT 165)),
+   

[clang] [clang] Add missing LinkageSpec case to getCursorKindForDecl (PR #72401)

2023-11-23 Thread Shivam Gupta via cfe-commits

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

It looks good to me, maybe we need a release note change as a formal practice.

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


[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread via cfe-commits
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -0,0 +1,25 @@
+.. title:: clang-tidy - readability-redundant-inline-specifier
+
+readability-redundant-inline-specifier
+==
+
+Checks for instances of the ``inline`` keyword in code where it is redundant

EugeneZelenko wrote:

Please synchronize with statement in Release Notes.

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


[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread via cfe-commits
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin,
=?utf-8?q?F=C3=A9lix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


https://github.com/EugeneZelenko requested changes to this pull request.


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


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


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


[llvm] [clang] [flang] [libc] [compiler-rt] [libcxx] [clang-tools-extra] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

2023-11-23 Thread via cfe-commits


@@ -341,30 +341,27 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 // This allows us to potentially uncover some "always unreachable" code
 // within the "sometimes unreachable" code.
 // Look at the successors and mark then reachable.
-std::optional TreatAllSuccessorsAsReachable;
-if (!IncludeSometimesUnreachableEdges)
+bool TreatAllSuccessorsAsReachable;
+if (IncludeSometimesUnreachableEdges) {
+  assert(PP);
+  TreatAllSuccessorsAsReachable =
+  shouldTreatSuccessorsAsReachable(item, *PP);
+} else {
   TreatAllSuccessorsAsReachable = false;
+}
 
 for (CFGBlock::const_succ_iterator I = item->succ_begin(),
  E = item->succ_end(); I != E; ++I) {
   const CFGBlock *B = *I;
-  if (!B) do {
+  if (!B) {
 const CFGBlock *UB = I->getPossiblyUnreachableBlock();
 if (!UB)
   break;

thyecust wrote:

Thanks for review. The fix is done.

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


[llvm] [clang] [flang] [libc] [compiler-rt] [libcxx] [clang-tools-extra] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

2023-11-23 Thread via cfe-commits

https://github.com/thyecust updated 
https://github.com/llvm/llvm-project/pull/72257

>From 52b0204fec8394f9c2cfaeb3cc4f28e5d4c16170 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 21:51:55 +0800
Subject: [PATCH 1/4] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 1bf0d9aec8620e1..9c9e1a0fffb3c98 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -341,30 +341,27 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 // This allows us to potentially uncover some "always unreachable" code
 // within the "sometimes unreachable" code.
 // Look at the successors and mark then reachable.
-std::optional TreatAllSuccessorsAsReachable;
-if (!IncludeSometimesUnreachableEdges)
+bool TreatAllSuccessorsAsReachable;
+if (IncludeSometimesUnreachableEdges) {
+  assert(PP);
+  TreatAllSuccessorsAsReachable =
+shouldTreatSuccessorsAsReachable(item, *PP);
+} else {
   TreatAllSuccessorsAsReachable = false;
+}
 
 for (CFGBlock::const_succ_iterator I = item->succ_begin(),
  E = item->succ_end(); I != E; ++I) {
   const CFGBlock *B = *I;
-  if (!B) do {
+  if (!B) {
 const CFGBlock *UB = I->getPossiblyUnreachableBlock();
 if (!UB)
   break;
 
-if (!TreatAllSuccessorsAsReachable) {
-  assert(PP);
-  TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
-}
-
-if (*TreatAllSuccessorsAsReachable) {
+if (TreatAllSuccessorsAsReachable) {
   B = UB;
-  break;
 }
   }
-  while (false);
 
   if (B) {
 unsigned blockID = B->getBlockID();

>From e6ff52675af755e442ffd86906097271a7a3f596 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 22:01:14 +0800
Subject: [PATCH 2/4] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 9c9e1a0fffb3c98..0123730d8ff9798 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -60,7 +60,7 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt 
*S) {
   return false;
 }
 
-static bool isBuiltinUnreachable(const Stmt *S) {
+static isBuiltinUnreachable(const Stmt *S) {
   if (const auto *DRE = dyn_cast(S))
 if (const auto *FDecl = dyn_cast(DRE->getDecl()))
   return FDecl->getIdentifier() &&
@@ -345,7 +345,7 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 if (IncludeSometimesUnreachableEdges) {
   assert(PP);
   TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
+  shouldTreatSuccessorsAsReachable(item, *PP);
 } else {
   TreatAllSuccessorsAsReachable = false;
 }

>From bcb3f98540cefc570432e541a929b61e9b89e08d Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 22:09:16 +0800
Subject: [PATCH 3/4] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 0123730d8ff9798..257fb19e0fcfeb9 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -60,7 +60,7 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt 
*S) {
   return false;
 }
 
-static isBuiltinUnreachable(const Stmt *S) {
+static bool isBuiltinUnreachable(const Stmt *S) {
   if (const auto *DRE = dyn_cast(S))
 if (const auto *FDecl = dyn_cast(DRE->getDecl()))
   return FDecl->getIdentifier() &&

>From af5a98520a17a716a5cfb0a7fb0c63e507697bc7 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Fri, 24 Nov 2023 09:51:56 +0800
Subject: [PATCH 4/4] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 257fb19e0fcfeb9..6d9c60cad73620b 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -356,7 +356,7 @@ static unsigned scanFromBlock(const CFGBlock *Start,
   if (!B) {
 const CFGBlock *UB = I->getPossiblyUnreachableBlock();
 if (!UB)
-  break;
+  continue;
 
 if (TreatAllSuccessorsAsReachable) {
   B = UB;

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


[llvm] [clang] [flang] [libc] [compiler-rt] [libcxx] [clang-tools-extra] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

2023-11-23 Thread via cfe-commits

https://github.com/thyecust updated 
https://github.com/llvm/llvm-project/pull/72257

>From 52b0204fec8394f9c2cfaeb3cc4f28e5d4c16170 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 21:51:55 +0800
Subject: [PATCH 1/4] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 1bf0d9aec8620e1..9c9e1a0fffb3c98 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -341,30 +341,27 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 // This allows us to potentially uncover some "always unreachable" code
 // within the "sometimes unreachable" code.
 // Look at the successors and mark then reachable.
-std::optional TreatAllSuccessorsAsReachable;
-if (!IncludeSometimesUnreachableEdges)
+bool TreatAllSuccessorsAsReachable;
+if (IncludeSometimesUnreachableEdges) {
+  assert(PP);
+  TreatAllSuccessorsAsReachable =
+shouldTreatSuccessorsAsReachable(item, *PP);
+} else {
   TreatAllSuccessorsAsReachable = false;
+}
 
 for (CFGBlock::const_succ_iterator I = item->succ_begin(),
  E = item->succ_end(); I != E; ++I) {
   const CFGBlock *B = *I;
-  if (!B) do {
+  if (!B) {
 const CFGBlock *UB = I->getPossiblyUnreachableBlock();
 if (!UB)
   break;
 
-if (!TreatAllSuccessorsAsReachable) {
-  assert(PP);
-  TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
-}
-
-if (*TreatAllSuccessorsAsReachable) {
+if (TreatAllSuccessorsAsReachable) {
   B = UB;
-  break;
 }
   }
-  while (false);
 
   if (B) {
 unsigned blockID = B->getBlockID();

>From e6ff52675af755e442ffd86906097271a7a3f596 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 22:01:14 +0800
Subject: [PATCH 2/4] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 9c9e1a0fffb3c98..0123730d8ff9798 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -60,7 +60,7 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt 
*S) {
   return false;
 }
 
-static bool isBuiltinUnreachable(const Stmt *S) {
+static isBuiltinUnreachable(const Stmt *S) {
   if (const auto *DRE = dyn_cast(S))
 if (const auto *FDecl = dyn_cast(DRE->getDecl()))
   return FDecl->getIdentifier() &&
@@ -345,7 +345,7 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 if (IncludeSometimesUnreachableEdges) {
   assert(PP);
   TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
+  shouldTreatSuccessorsAsReachable(item, *PP);
 } else {
   TreatAllSuccessorsAsReachable = false;
 }

>From bcb3f98540cefc570432e541a929b61e9b89e08d Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 22:09:16 +0800
Subject: [PATCH 3/4] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 0123730d8ff9798..257fb19e0fcfeb9 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -60,7 +60,7 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt 
*S) {
   return false;
 }
 
-static isBuiltinUnreachable(const Stmt *S) {
+static bool isBuiltinUnreachable(const Stmt *S) {
   if (const auto *DRE = dyn_cast(S))
 if (const auto *FDecl = dyn_cast(DRE->getDecl()))
   return FDecl->getIdentifier() &&

>From af5a98520a17a716a5cfb0a7fb0c63e507697bc7 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Fri, 24 Nov 2023 09:51:56 +0800
Subject: [PATCH 4/4] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 257fb19e0fcfeb9..6d9c60cad73620b 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -356,7 +356,7 @@ static unsigned scanFromBlock(const CFGBlock *Start,
   if (!B) {
 const CFGBlock *UB = I->getPossiblyUnreachableBlock();
 if (!UB)
-  break;
+  continue;
 
 if (TreatAllSuccessorsAsReachable) {
   B = UB;

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


[llvm] [clang] [flang] [libc] [compiler-rt] [libcxx] [clang-tools-extra] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

2023-11-23 Thread via cfe-commits


@@ -341,30 +341,27 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 // This allows us to potentially uncover some "always unreachable" code
 // within the "sometimes unreachable" code.
 // Look at the successors and mark then reachable.
-std::optional TreatAllSuccessorsAsReachable;
-if (!IncludeSometimesUnreachableEdges)
+bool TreatAllSuccessorsAsReachable;
+if (IncludeSometimesUnreachableEdges) {
+  assert(PP);
+  TreatAllSuccessorsAsReachable =
+  shouldTreatSuccessorsAsReachable(item, *PP);
+} else {
   TreatAllSuccessorsAsReachable = false;
+}
 
 for (CFGBlock::const_succ_iterator I = item->succ_begin(),
  E = item->succ_end(); I != E; ++I) {
   const CFGBlock *B = *I;
-  if (!B) do {
+  if (!B) {
 const CFGBlock *UB = I->getPossiblyUnreachableBlock();
 if (!UB)
   break;

thyecust wrote:

Yes, you are right. I should replace this break with continue.

Because previously this break, under `if (!B) {`, was going to `if (B) {` and 
contining the next `for` loop iteration.

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


[compiler-rt] [flang] [llvm] [libc] [libcxx] [clang] [clang-tools-extra] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

2023-11-23 Thread Gábor Horváth via cfe-commits


@@ -341,30 +341,27 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 // This allows us to potentially uncover some "always unreachable" code
 // within the "sometimes unreachable" code.
 // Look at the successors and mark then reachable.
-std::optional TreatAllSuccessorsAsReachable;
-if (!IncludeSometimesUnreachableEdges)
+bool TreatAllSuccessorsAsReachable;
+if (IncludeSometimesUnreachableEdges) {
+  assert(PP);
+  TreatAllSuccessorsAsReachable =
+  shouldTreatSuccessorsAsReachable(item, *PP);
+} else {
   TreatAllSuccessorsAsReachable = false;
+}
 
 for (CFGBlock::const_succ_iterator I = item->succ_begin(),
  E = item->succ_end(); I != E; ++I) {
   const CFGBlock *B = *I;
-  if (!B) do {
+  if (!B) {
 const CFGBlock *UB = I->getPossiblyUnreachableBlock();
 if (!UB)
   break;

Xazax-hun wrote:

This looks like a functional change. Previously this break was breaking out of 
the `do-while` loop, now it is breaking out of the `for` loop.

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


[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-23 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

I think the original `alloca(0)` warning message might be clearer/easier to 
understand. While it might have platform or compiler dependent meaning, those 
behaviors are non-portable, so I think it is undesirable in most cases and 
people probably want to be notified about it. Regarding binding the return 
value outside of `evalCall`, I think that could be addressed in a separate PR. 
This one does not make the current situation any worse. But the very least we 
should add a FIXME now (and potentially open a ticket), to reduce the chances 
of this getting forgotten.

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


[clang] [clang][analyzer] Support `fprintf` in the SecuritySyntaxChecker (PR #73247)

2023-11-23 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

This is unrelated to this particular patch, but it would be great if this 
checker would also give suggestions what other functions should be used 
instead. 

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


[clang] [clang][analyzer] Support `fprintf` in the SecuritySyntaxChecker (PR #73247)

2023-11-23 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.


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


[clang] [clang][analyzer] Move `security.cert.env.InvalidPtr` out of `alpha` (PR #71912)

2023-11-23 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.


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


[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)

2023-11-23 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

Note that [idx] is perfectly valid code when `idx == number of elements`. 
And it is relatively common to do that when one is using STL algorithms on 
arrays:
```
auto it = std::find([0], [size], foo);
```

Of course, one could use the `begin/end` free functions, but those are only 
available since C++11. 

Could you elaborate on alternative approaches you considered fixing the problem 
and why you chose this one? E.g., would trying to look at the parent regions 
for expressions like `foo[idx].bar` work? Or is the source of the problem that 
you'd also need the exact expression for the subscript instead of the 
`MemberExpr`?

Alternatively, would it be possible to suppress warnings on the common pattern 
`[idx]` by checking the parent of the subscript expression in the AST 
(but still emitting a warning when the pointer is dereferenced)?


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


[llvm] [clang-tools-extra] [SimplifyCFG] Find the minimal table considering overflow in `switchToLookupTable` (PR #67885)

2023-11-23 Thread via cfe-commits


@@ -6519,17 +6518,55 @@ static bool SwitchToLookupTable(SwitchInst *SI, 
IRBuilder<> ,
   SmallDenseMap ResultTypes;
   SmallVector PHIs;
 
-  for (SwitchInst::CaseIt E = SI->case_end(); CI != E; ++CI) {
-ConstantInt *CaseVal = CI->getCaseValue();
-if (CaseVal->getValue().slt(MinCaseVal->getValue()))
-  MinCaseVal = CaseVal;
-if (CaseVal->getValue().sgt(MaxCaseVal->getValue()))
-  MaxCaseVal = CaseVal;
+  SmallVector CaseVals;
+  for (const auto  : SI->cases())
+CaseVals.push_back(CI.getCaseValue());
+
+  // We want to find a range of indexes that will create the minimal table.
+  // When considering overflow, the next indexed value of the maximum signed
+  // integer is the minimum signed integer.
+  llvm::sort(CaseVals, [](const auto *L, const auto *R) {
+return L->getValue().slt(R->getValue());
+  });
+  auto *CaseValIter = CaseVals.begin();
+  // We start by using the minimum signed integer and maximum signed as the
+  // minimal table. It's the most common case.
+  ConstantInt *BeginCaseVal = *CaseValIter;
+  ConstantInt *EndCaseVal = CaseVals.back();
+  bool RangeOverflow = false;
+  uint64_t MinTableSize = EndCaseVal->getValue()
+  .ssub_ov(BeginCaseVal->getValue(), RangeOverflow)
+  .getLimitedValue() +
+  1;
+  // If there is no overflow, then this must be the minimal table.
+  if (RangeOverflow) {

DianQK wrote:

I put it in #73269.

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


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Félix-Antoine Constantin via cfe-commits


@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  SourceLocation CurrentLocation = RangeLocation.getBegin();
+  Token CurrentToken;
+  while (!Lexer::getRawToken(CurrentLocation, CurrentToken, Sources, LangOpts,
+ true) &&
+ CurrentLocation < RangeLocation.getEnd() &&
+ CurrentToken.isNot(tok::eof)) {
+if (CurrentToken.is(tok::raw_identifier)) {
+  if (CurrentToken.getRawIdentifier() == "inline") {
+return CurrentToken.getLocation();
+  }
+}
+CurrentLocation = CurrentToken.getEndLoc();
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), unless(isImplicit()),
+   unless(hasAncestor(lambdaExpr())), isInline(),

felix642 wrote:

Using `TK_IgnoreUnlessSpelledInSource` instead of `isImplicit()` seems to have 
to solved this issue. 

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


[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/73069

From 89281ccb5354e3d6349d10e6f9446194d2d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Thu, 16 Nov 2023 22:03:15 -0500
Subject: [PATCH 1/5] =?UTF-8?q?[clang-tidy]=C2=A0Added=20check=20to=20dete?=
 =?UTF-8?q?ct=20redundant=20inline=20keyword?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This checks find usages of the inline keywork where it is
already implicitly defined by the compiler and suggests it's removal.

Fixes #72397
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../RedundantInlineSpecifierCheck.cpp |  99 
 .../RedundantInlineSpecifierCheck.h   |  36 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../redundant-inline-specifier.rst|  34 ++
 .../redundant-inline-specifier.cpp| 110 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h |   2 +-
 9 files changed, 290 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a46173..811310db8c721a6 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyReadabilityModule
   IdentifierLengthCheck.cpp
   IdentifierNamingCheck.cpp
   ImplicitBoolConversionCheck.cpp
+  RedundantInlineSpecifierCheck.cpp
   InconsistentDeclarationParameterNameCheck.cpp
   IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e6414320600..3ce7bfecaecba64 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "RedundantControlFlowCheck.h"
 #include "RedundantDeclarationCheck.h"
 #include "RedundantFunctionPtrDereferenceCheck.h"
+#include "RedundantInlineSpecifierCheck.h"
 #include "RedundantMemberInitCheck.h"
 #include "RedundantPreprocessorCheck.h"
 #include "RedundantSmartptrGetCheck.h"
@@ -93,6 +94,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-identifier-naming");
 CheckFactories.registerCheck(
 "readability-implicit-bool-conversion");
+CheckFactories.registerCheck(
+"readability-redundant-inline-specifier");
 CheckFactories.registerCheck(
 "readability-inconsistent-declaration-parameter-name");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
new file mode 100644
index 000..e73b570df759153
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  SourceLocation CurrentLocation = RangeLocation.getBegin();
+  Token CurrentToken;
+  while (!Lexer::getRawToken(CurrentLocation, CurrentToken, Sources, LangOpts,
+ true) &&
+ CurrentLocation < RangeLocation.getEnd() &&
+ CurrentToken.isNot(tok::eof)) {
+if (CurrentToken.is(tok::raw_identifier)) {
+  if 

[clang] [analyzer] Switch to PostStmt callbacks in ArrayBoundV2 (PR #72107)

2023-11-23 Thread Gábor Horváth via cfe-commits


@@ -34,20 +34,37 @@ using llvm::formatv;
 namespace {
 enum OOB_Kind { OOB_Precedes, OOB_Exceeds, OOB_Taint };
 
-class ArrayBoundCheckerV2 :
-public Checker {
+struct Messages {
+  std::string Short, Full;
+};
+
+class ArrayBoundCheckerV2 : public Checker,
+   check::PostStmt,
+   check::PostStmt> {
   BugType BT{this, "Out-of-bound access"};
   BugType TaintBT{this, "Out-of-bound access", categories::TaintedData};
 
+  void performCheck(const Expr *E, CheckerContext ) const;
+
   void reportOOB(CheckerContext , ProgramStateRef ErrorState, OOB_Kind Kind,
- NonLoc Offset, std::string RegName, std::string Msg) const;
+ NonLoc Offset, Messages Msgs) const;
 
   static bool isFromCtypeMacro(const Stmt *S, ASTContext );
 
 public:
-  void checkLocation(SVal l, bool isLoad, const Stmt *S,
- CheckerContext ) const;
+  void checkPostStmt(const ArraySubscriptExpr *E, CheckerContext ) const {

Xazax-hun wrote:

Any particular reason for PostStmt vs PreStmt? The index being in bound is a 
precondition, and I think we generally prefer checking preconditions in 
PreStmt. 

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


[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Félix-Antoine Constantin via cfe-commits


@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  SourceLocation CurrentLocation = RangeLocation.getBegin();
+  Token CurrentToken;
+  while (!Lexer::getRawToken(CurrentLocation, CurrentToken, Sources, LangOpts,

felix642 wrote:

Hi @PiotrZSL, thank you for the feedback. I've made some changes to the method, 
let me know if that's what you meant.

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


[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/73069

From 89281ccb5354e3d6349d10e6f9446194d2d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Thu, 16 Nov 2023 22:03:15 -0500
Subject: [PATCH 1/4] =?UTF-8?q?[clang-tidy]=C2=A0Added=20check=20to=20dete?=
 =?UTF-8?q?ct=20redundant=20inline=20keyword?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This checks find usages of the inline keywork where it is
already implicitly defined by the compiler and suggests it's removal.

Fixes #72397
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../RedundantInlineSpecifierCheck.cpp |  99 
 .../RedundantInlineSpecifierCheck.h   |  36 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../redundant-inline-specifier.rst|  34 ++
 .../redundant-inline-specifier.cpp| 110 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h |   2 +-
 9 files changed, 290 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a46173..811310db8c721a6 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyReadabilityModule
   IdentifierLengthCheck.cpp
   IdentifierNamingCheck.cpp
   ImplicitBoolConversionCheck.cpp
+  RedundantInlineSpecifierCheck.cpp
   InconsistentDeclarationParameterNameCheck.cpp
   IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e6414320600..3ce7bfecaecba64 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "RedundantControlFlowCheck.h"
 #include "RedundantDeclarationCheck.h"
 #include "RedundantFunctionPtrDereferenceCheck.h"
+#include "RedundantInlineSpecifierCheck.h"
 #include "RedundantMemberInitCheck.h"
 #include "RedundantPreprocessorCheck.h"
 #include "RedundantSmartptrGetCheck.h"
@@ -93,6 +94,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-identifier-naming");
 CheckFactories.registerCheck(
 "readability-implicit-bool-conversion");
+CheckFactories.registerCheck(
+"readability-redundant-inline-specifier");
 CheckFactories.registerCheck(
 "readability-inconsistent-declaration-parameter-name");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
new file mode 100644
index 000..e73b570df759153
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  SourceLocation CurrentLocation = RangeLocation.getBegin();
+  Token CurrentToken;
+  while (!Lexer::getRawToken(CurrentLocation, CurrentToken, Sources, LangOpts,
+ true) &&
+ CurrentLocation < RangeLocation.getEnd() &&
+ CurrentToken.isNot(tok::eof)) {
+if (CurrentToken.is(tok::raw_identifier)) {
+  if 

[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 42d484082cd190400e0e493a8d679762ce0efbba 
3fadac1a7cab42eb962eaa4b6f79335e77196c4d -- 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
 clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
index 65fd363ebf..4a685c83c2 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -24,9 +24,9 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
 
-AST_POLYMORPHIC_MATCHER(isInlineSpecified, AST_POLYMORPHIC_SUPPORTED_TYPES(
-  FunctionDecl,
-  VarDecl)) {
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
   if (const auto *FD = dyn_cast())
 return FD->isInlineSpecified();
   if (const auto *VD = dyn_cast())
@@ -34,13 +34,12 @@ AST_POLYMORPHIC_MATCHER(isInlineSpecified, 
AST_POLYMORPHIC_SUPPORTED_TYPES(
   llvm_unreachable("Not a valid polymorphic type");
 }
 
-
 static std::optional
 getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
const LangOptions ) {
   Token FirstToken;
   Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
- true);
+ true);
   std::optional CurrentToken = FirstToken;
   while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
  CurrentToken->isNot(tok::eof)) {
@@ -48,7 +47,8 @@ getInlineTokenLocation(SourceRange RangeLocation, const 
SourceManager ,
 CurrentToken->getRawIdentifier() == "inline")
   return CurrentToken->getLocation();
 
-CurrentToken = Lexer::findNextToken(CurrentToken->getLocation(), Sources, 
LangOpts);
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
   }
   return std::nullopt;
 }
@@ -71,7 +71,8 @@ void 
RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
   this);
 
   Finder->addMatcher(
-  
functionTemplateDecl(has(functionDecl(isInlineSpecified(.bind("templ_decl"),
+  functionTemplateDecl(has(functionDecl(isInlineSpecified(
+  .bind("templ_decl"),
   this);
 }
 
@@ -79,8 +80,9 @@ template 
 void RedundantInlineSpecifierCheck::handleMatchedDecl(
 const T *MatchedDecl, const SourceManager ,
 const MatchFinder::MatchResult , StringRef Message) {
-  if (std::optional Loc = 
getInlineTokenLocation(MatchedDecl->getSourceRange(), Sources,
-Result.Context->getLangOpts()))
+  if (std::optional Loc =
+  getInlineTokenLocation(MatchedDecl->getSourceRange(), Sources,
+ Result.Context->getLangOpts()))
 diag(*Loc, Message) << MatchedDecl << FixItHint::CreateRemoval(*Loc);
 }
 
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
index 1a510f586f..b4d1f2159a 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
@@ -13,7 +13,8 @@
 
 namespace clang::tidy::readability {
 
-/// Detects redundant ``inline`` specifiers on function and variable 
declarations.
+/// Detects redundant ``inline`` specifiers on function and variable
+/// declarations.
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/readability/readability-redundant-inline-specifier.html

``




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


[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/73069

From 89281ccb5354e3d6349d10e6f9446194d2d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Thu, 16 Nov 2023 22:03:15 -0500
Subject: [PATCH 1/3] =?UTF-8?q?[clang-tidy]=C2=A0Added=20check=20to=20dete?=
 =?UTF-8?q?ct=20redundant=20inline=20keyword?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This checks find usages of the inline keywork where it is
already implicitly defined by the compiler and suggests it's removal.

Fixes #72397
---
 .../clang-tidy/readability/CMakeLists.txt |   1 +
 .../readability/ReadabilityTidyModule.cpp |   3 +
 .../RedundantInlineSpecifierCheck.cpp |  99 
 .../RedundantInlineSpecifierCheck.h   |  36 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../redundant-inline-specifier.rst|  34 ++
 .../redundant-inline-specifier.cpp| 110 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h |   2 +-
 9 files changed, 290 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-inline-specifier.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a46173..811310db8c721a6 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyReadabilityModule
   IdentifierLengthCheck.cpp
   IdentifierNamingCheck.cpp
   ImplicitBoolConversionCheck.cpp
+  RedundantInlineSpecifierCheck.cpp
   InconsistentDeclarationParameterNameCheck.cpp
   IsolateDeclarationCheck.cpp
   MagicNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e6414320600..3ce7bfecaecba64 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -39,6 +39,7 @@
 #include "RedundantControlFlowCheck.h"
 #include "RedundantDeclarationCheck.h"
 #include "RedundantFunctionPtrDereferenceCheck.h"
+#include "RedundantInlineSpecifierCheck.h"
 #include "RedundantMemberInitCheck.h"
 #include "RedundantPreprocessorCheck.h"
 #include "RedundantSmartptrGetCheck.h"
@@ -93,6 +94,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-identifier-naming");
 CheckFactories.registerCheck(
 "readability-implicit-bool-conversion");
+CheckFactories.registerCheck(
+"readability-redundant-inline-specifier");
 CheckFactories.registerCheck(
 "readability-inconsistent-declaration-parameter-name");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
new file mode 100644
index 000..e73b570df759153
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  SourceLocation CurrentLocation = RangeLocation.getBegin();
+  Token CurrentToken;
+  while (!Lexer::getRawToken(CurrentLocation, CurrentToken, Sources, LangOpts,
+ true) &&
+ CurrentLocation < RangeLocation.getEnd() &&
+ CurrentToken.isNot(tok::eof)) {
+if (CurrentToken.is(tok::raw_identifier)) {
+  if 

[clang] [clang-tools-extra] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-11-23 Thread Félix-Antoine Constantin via cfe-commits


@@ -0,0 +1,99 @@
+//===--- RedundantInlineSpecifierCheck.cpp -
+// clang-tidy--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager ,
+   const LangOptions ) {
+  SourceLocation CurrentLocation = RangeLocation.getBegin();
+  Token CurrentToken;
+  while (!Lexer::getRawToken(CurrentLocation, CurrentToken, Sources, LangOpts,
+ true) &&
+ CurrentLocation < RangeLocation.getEnd() &&
+ CurrentToken.isNot(tok::eof)) {
+if (CurrentToken.is(tok::raw_identifier)) {
+  if (CurrentToken.getRawIdentifier() == "inline") {
+return CurrentToken.getLocation();
+  }
+}
+CurrentLocation = CurrentToken.getEndLoc();
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(unless(isExpansionInSystemHeader()), unless(isImplicit()),
+   unless(hasAncestor(lambdaExpr())), isInline(),
+   anyOf(isConstexpr(), isDeleted(),
+ allOf(isDefinition(), hasAncestor(recordDecl()),
+   unless(hasAncestor(cxxConstructorDecl())
+  .bind("fun_decl"),
+  this);
+
+  Finder->addMatcher(
+  varDecl(isInline(), unless(isImplicit()),
+  anyOf(allOf(isConstexpr(), unless(isStaticStorageClass())),

felix642 wrote:

The description of this matcher says : 

>Matches variable/function declarations that have "static" storage
>class specifier ("static" keyword) written in the source.

From what I understand, it needs to have the "static" keyword written in the 
source. 
Is there a better matcher that I could use in that case?  

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


[lld] [clang] [libcxx] [llvm] [libc] [compiler-rt] [flang] Fix ISel crash when lowering BUILD_VECTOR (PR #73186)

2023-11-23 Thread David Li via cfe-commits


@@ -7254,6 +7255,10 @@ static SDValue 
lowerBuildVectorAsBroadcast(BuildVectorSDNode *BVOp,
 EVT CVT = Ld.getValueType();
 assert(!CVT.isVector() && "Must not broadcast a vector type");
 
+// 512 bit vpbroadcastw is only available with AVX512BW
+if (ScalarSize == 16 && IsGT256 && !Subtarget.hasBWI())
+  return SDValue();

david-xl wrote:

Sounds good. Will add support there.

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


[libcxxabi] [libunwind] [libcxx] [libunwind][libc++][libc++abi] Add cross-compilation flags to tests (PR #67201)

2023-11-23 Thread Louis Dionne via cfe-commits

ldionne wrote:

Closing since it seems we don't want to pursue this anymore, since 
`@CMAKE_CXX_FLAGS_INIT@` are flags for the library build, not necessarily for 
the tests to use.

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


[libcxx] [libunwind] [libcxxabi] [libunwind][libc++][libc++abi] Add cross-compilation flags to tests (PR #67201)

2023-11-23 Thread Louis Dionne via cfe-commits

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


[llvm] [clang] [PowerPC][X86] Make cpu id builtins target independent and lower for PPC (PR #68919)

2023-11-23 Thread via cfe-commits


@@ -0,0 +1,80 @@
+#ifndef PPC_FEATURE

diggerlin wrote:

we will support these feature in AIX OS soon.
can we change `PPC_FEATURE` to `PPC_LINUX_FEATURE`

and `PPC_CPU` to `PPC_LINUX_CPU` 

and when implement the __builtin_cpu_is and __builtin_cpu_supports in AIX OD

we can `PPC_AIX_FEATURE` and `PPC_AIX_CPU`

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


[clang] fix: C++ empty record with align lead to va_list out of sync (PR #72197)

2023-11-23 Thread John McCall via cfe-commits


@@ -307,7 +307,12 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool 
IsVariadic,
 // 0.
 if (IsEmpty && Size == 0)
   return ABIArgInfo::getIgnore();
-return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext()));
+// An empty struct can have size greater than one byte if alignment is
+// involved.
+// When size <= 64, we still hold it by i8 in IR and lowering to registers.
+// When Size > 64, just fall through to avoid va_list out of sync.

rjmccall wrote:

Yes, I intended that as a suggestion for the comment, and you're welcome to 
include it verbatim.

I agree with Eli that I'd like to understand why we need to have this `i8` 
carve-out.

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-23 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,8 @@
+#include 
+
+int main(int argc, char * argv[]) {
+// Irrelevant what to do in here.
+// Test is supposed to fail at link time.
+printf("Hello from C [%s]\n", __FUNCTION__);

banach-space wrote:

Note that if you remove this line and `#include ` then this 
translation becomes super trivial, yet sufficient. 

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-23 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,13 @@
+! RUN: %clang -x c -o %t.c-part -c %s.c-part

banach-space wrote:

That's a shame - thanks for checking. One alternative would be to add LLVM IR 
instead of a C file, but LLVM IR is not stable. Though a plain function 
definition should be fairly stable:
```
define i32 @main(i32 noundef %0, ptr noundef %1) {
  ret i32 0
}
```

Would this work? @kiranchandramohan - what do you think?

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-23 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,15 @@
+! UNSUPPORTED: system-windows
+
+! RUN: %clang -o %t.c-object -c %S/Inputs/main_dupes.c

banach-space wrote:

Check:
* 
https://github.com/llvm/llvm-project/blob/main/flang/test/lit.site.cfg.py.in#L24,
 and
* https://github.com/llvm/llvm-project/blob/main/flang/test/lit.cfg.py#L169

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


[clang] [clang] Avoid memcopy for small structure with padding under -ftrivial-auto-var-init (PR #71677)

2023-11-23 Thread Florian Hahn via cfe-commits

fhahn wrote:

@serge-sans-paille those test failures were also highlighted by the precommit 
checks, would be good to check those before landing

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


[clang] [clang] Avoid memcopy for small structure with padding under -ftrivial-auto-var-init (PR #71677)

2023-11-23 Thread Florian Hahn via cfe-commits

fhahn wrote:

Reverted the change for now, as many build bots have been red due to the test 
failures

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


[clang] 419a4e4 - Revert "[clang] Avoid memcopy for small structure with padding under -ftrivial-auto-var-init (#71677)"

2023-11-23 Thread Florian Hahn via cfe-commits

Author: Florian Hahn
Date: 2023-11-23T20:18:55Z
New Revision: 419a4e41fc36a91999da6cbe06d430cac07224f1

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

LOG: Revert "[clang] Avoid memcopy for small structure with padding under 
-ftrivial-auto-var-init (#71677)"

This reverts commit fe5c360a9aae61db37886c0c795c409b5129905f.
The commit causes the tests below to fail on many buildbots, e.g.
https://lab.llvm.org/buildbot/#/builders/245/builds/17047

  Clang :: CodeGen/aapcs-align.cpp
  Clang :: CodeGen/aapcs64-align.cpp

Added: 


Modified: 
clang/lib/CodeGen/CGDecl.cpp
clang/test/CodeGenCXX/auto-var-init.cpp
clang/test/CodeGenOpenCL/amdgpu-printf.cl
clang/test/OpenMP/bug54082.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index a5da0aa2965a000..e5795d811c76de7 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1244,24 +1244,29 @@ static void emitStoresForConstant(CodeGenModule , 
const VarDecl ,
   // If the initializer is small, use a handful of stores.
   if (shouldSplitConstantStore(CGM, ConstantSize)) {
 if (auto *STy = dyn_cast(Ty)) {
-  const llvm::StructLayout *Layout =
-  CGM.getDataLayout().getStructLayout(STy);
-  for (unsigned i = 0; i != constant->getNumOperands(); i++) {
-CharUnits CurOff = 
CharUnits::fromQuantity(Layout->getElementOffset(i));
-Address EltPtr = Builder.CreateConstInBoundsByteGEP(
-Loc.withElementType(CGM.Int8Ty), CurOff);
-emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder,
-  constant->getAggregateElement(i), IsAutoInit);
+  // FIXME: handle the case when STy != Loc.getElementType().
+  if (STy == Loc.getElementType()) {
+for (unsigned i = 0; i != constant->getNumOperands(); i++) {
+  Address EltPtr = Builder.CreateStructGEP(Loc, i);
+  emitStoresForConstant(
+  CGM, D, EltPtr, isVolatile, Builder,
+  cast(Builder.CreateExtractValue(constant, i)),
+  IsAutoInit);
+}
+return;
   }
-  return;
 } else if (auto *ATy = dyn_cast(Ty)) {
-  for (unsigned i = 0; i != ATy->getNumElements(); i++) {
-Address EltPtr = Builder.CreateConstGEP(
-Loc.withElementType(ATy->getElementType()), i);
-emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder,
-  constant->getAggregateElement(i), IsAutoInit);
+  // FIXME: handle the case when ATy != Loc.getElementType().
+  if (ATy == Loc.getElementType()) {
+for (unsigned i = 0; i != ATy->getNumElements(); i++) {
+  Address EltPtr = Builder.CreateConstArrayGEP(Loc, i);
+  emitStoresForConstant(
+  CGM, D, EltPtr, isVolatile, Builder,
+  cast(Builder.CreateExtractValue(constant, i)),
+  IsAutoInit);
+}
+return;
   }
-  return;
 }
   }
 

diff  --git a/clang/test/CodeGenCXX/auto-var-init.cpp 
b/clang/test/CodeGenCXX/auto-var-init.cpp
index e5a9d015f22f276..6cb18528ebadcdf 100644
--- a/clang/test/CodeGenCXX/auto-var-init.cpp
+++ b/clang/test/CodeGenCXX/auto-var-init.cpp
@@ -89,14 +89,22 @@ struct padded { char c; int i; };
 // PATTERN-O1-NOT: @__const.test_paddednullinit_custom.custom
 struct paddednullinit { char c = 0; int i = 0; };
 // PATTERN-O0: @__const.test_paddedpacked_uninit.uninit = private unnamed_addr 
constant %struct.paddedpacked <{ i8 [[I8]], i32 [[I32]] }>, align 1
+// PATTERN: @__const.test_paddedpacked_custom.custom = private unnamed_addr 
constant %struct.paddedpacked <{ i8 42, i32 13371337 }>, align 1
+// ZERO: @__const.test_paddedpacked_custom.custom = private unnamed_addr 
constant %struct.paddedpacked <{ i8 42, i32 13371337 }>, align 1
 struct paddedpacked { char c; int i; } __attribute__((packed));
 // PATTERN-O0: @__const.test_paddedpackedarray_uninit.uninit = private 
unnamed_addr constant %struct.paddedpackedarray { [2 x %struct.paddedpacked] 
[%struct.paddedpacked <{ i8 [[I8]], i32 [[I32]] }>, %struct.paddedpacked <{ i8 
[[I8]], i32 [[I32]] }>] }, align 1
+// PATTERN: @__const.test_paddedpackedarray_custom.custom = private 
unnamed_addr constant %struct.paddedpackedarray { [2 x %struct.paddedpacked] 
[%struct.paddedpacked <{ i8 42, i32 13371337 }>, %struct.paddedpacked <{ i8 43, 
i32 13371338 }>] }, align 1
+// ZERO: @__const.test_paddedpackedarray_custom.custom = private unnamed_addr 
constant %struct.paddedpackedarray { [2 x %struct.paddedpacked] 
[%struct.paddedpacked <{ i8 42, i32 13371337 }>, %struct.paddedpacked <{ i8 43, 
i32 13371338 }>] }, align 1
 struct paddedpackedarray { struct paddedpacked p[2]; };
 // PATTERN-O0: @__const.test_unpackedinpacked_uninit.uninit = 

[clang] [clang] Refactor TBAA Base Info construction (PR #70499)

2023-11-23 Thread Nathan Sidwell via cfe-commits

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


[clang] [clang] Avoid recalculating TBAA base type info (PR #73264)

2023-11-23 Thread Nathan Sidwell via cfe-commits

https://github.com/urnathan created 
https://github.com/llvm/llvm-project/pull/73264

I noticed that TBAA BaseTypeMetadataCache can legitimately store null values, 
but it also uses that to mean 'no entry'. Thus nullptr entries get continually 
recalculated. (AFAICT null entries can never become non-null.)  This changes 
the hash lookup/insertion to use find and try_emplace rather than the subscript 
operator.

While there, getBaseTypeInfoHelper will insert non-null values into the 
hashtable itself, but simply return nullptr values.  The only caller, 
getBaseTypeInfo unconditionally inserts the value anyway. It seems clearer to 
let getBaseTypeInfo do the insertion and getBaseTypeInfoHelper merely computes.

[This is the second of a pair of prs]

>From e4c92cd687782743ba939becf7ea8862eea6a108 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Thu, 23 Nov 2023 11:30:12 -0500
Subject: [PATCH] [clang] Avoid recalculating TBAA base type info

I noticed that TBAA BaseTypeMetadataCache can legitimately store null
values, but it also uses that to mean 'no entry'. Thus nullptr entries
get continually recalculated. (AFAICT null entries can never become
non-null.)  This changes the hash lookup/insertion to use find and
try_emplace rather than the subscript operator.

While there, getBaseTypeInfoHelper will insert non-null values into
the hashtable itself, but simply return nullptr values.  The only
caller, getBaseTypeInfo unconditionally inserts the value anyway. It
seems clearer to let getBaseTypeInfo do the insertion and
getBaseTypeInfoHelper merely computes.
---
 clang/lib/CodeGen/CodeGenTBAA.cpp | 24 +++-
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 8705d3d65f1a573..94dc304bfc243b9 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -342,7 +342,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type 
*Ty) {
   // field. Virtual bases are more complex and omitted, but avoid an
   // incomplete view for NewStructPathTBAA.
   if (CodeGenOpts.NewStructPathTBAA && CXXRD->getNumVBases() != 0)
-return BaseTypeMetadataCache[Ty] = nullptr;
+return nullptr;
   for (const CXXBaseSpecifier  : CXXRD->bases()) {
 if (B.isVirtual())
   continue;
@@ -354,7 +354,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type 
*Ty) {
  ? getBaseTypeInfo(BaseQTy)
  : getTypeInfo(BaseQTy);
 if (!TypeNode)
-  return BaseTypeMetadataCache[Ty] = nullptr;
+  return nullptr;
 uint64_t Offset = Layout.getBaseClassOffset(BaseRD).getQuantity();
 uint64_t Size =
 Context.getASTRecordLayout(BaseRD).getDataSize().getQuantity();
@@ -378,7 +378,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type 
*Ty) {
   llvm::MDNode *TypeNode = isValidBaseType(FieldQTy) ?
   getBaseTypeInfo(FieldQTy) : getTypeInfo(FieldQTy);
   if (!TypeNode)
-return BaseTypeMetadataCache[Ty] = nullptr;
+return nullptr;
 
   uint64_t BitOffset = Layout.getFieldOffset(Field->getFieldIndex());
   uint64_t Offset = Context.toCharUnitsFromBits(BitOffset).getQuantity();
@@ -418,14 +418,20 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
 return nullptr;
 
   const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
-  if (llvm::MDNode *N = BaseTypeMetadataCache[Ty])
-return N;
 
-  // Note that the following helper call is allowed to add new nodes to the
-  // cache, which invalidates all its previously obtained iterators. So we
-  // first generate the node for the type and then add that node to the cache.
+  // nullptr is a valid value in the cache, so use find rather than []
+  auto I = BaseTypeMetadataCache.find(Ty);
+  if (I != BaseTypeMetadataCache.end())
+return I->second;
+
+  // First calculate the metadata, before recomputing the insertion point, as
+  // the helper can recursively call us.
   llvm::MDNode *TypeNode = getBaseTypeInfoHelper(Ty);
-  return BaseTypeMetadataCache[Ty] = TypeNode;
+  LLVM_ATTRIBUTE_UNUSED auto inserted =
+  BaseTypeMetadataCache.try_emplace(Ty, TypeNode);
+  assert(inserted.second && "BaseType metadata was already inserted");
+
+  return TypeNode;
 }
 
 llvm::MDNode *CodeGenTBAA::getAccessTagInfo(TBAAAccessInfo Info) {

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


[clang] [clang][NFC] Adjust TBAA Base Info API (PR #73263)

2023-11-23 Thread Nathan Sidwell via cfe-commits

https://github.com/urnathan created 
https://github.com/llvm/llvm-project/pull/73263

I noticed a couple of minor issues with CodeGenTBAA::getBaseTypeInfo.

1) isValidBaseType explicitly checks for a reference type to return false, but 
then also returns false for all non-record types. Just remove that reference 
check.

2) All uses of CodeGenTBAA::getBaseTypeInfo from within that class are when 
we've already checked the type isValidBaseType. The only case where this isn't 
true is from outside the class. It seems better to have two entry points in 
this case.  Adding a new
'maybeGetBaseTypeInfo' entry point for external uses that returns nullptr for 
non valid base types.  (Open to other names?)

[This is part one of a pair of changes.]

>From 2a312ddadae91ea52b184edaa0d19495c6e0f4a3 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell 
Date: Wed, 22 Nov 2023 20:45:38 -0500
Subject: [PATCH] [clang][NFC] Adjust TBAA Base Info API

I noticed a couple of minor issues with CodeGenTBAA::getBaseTypeInfo.

1) isValidBaseType explicitly checks for a reference type to return
false, but then also returns false for all non-record types. Just
remove that reference check.

2) All uses of CodeGenTBAA::getBaseTypeInfo from within that class are
when we've already checked the type isValidBaseType. The only case
where this isn't true is from outside the class. It seems better to
have two entry points in this case.  Adding a new
'maybeGetBaseTypeInfo' entry point for external uses that returns
nullptr for non valid base types.  (Open to other names?)

[This is part one of a pair of changes.]
---
 clang/lib/CodeGen/CodeGenModule.cpp |  2 +-
 clang/lib/CodeGen/CodeGenTBAA.cpp   |  9 +
 clang/lib/CodeGen/CodeGenTBAA.h | 11 ---
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 7cdf50a281cd278..e01fdc3579d88b8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1318,7 +1318,7 @@ llvm::MDNode *CodeGenModule::getTBAAStructInfo(QualType 
QTy) {
 llvm::MDNode *CodeGenModule::getTBAABaseTypeInfo(QualType QTy) {
   if (!TBAA)
 return nullptr;
-  return TBAA->getBaseTypeInfo(QTy);
+  return TBAA->maybeGetBaseTypeInfo(QTy);
 }
 
 llvm::MDNode *CodeGenModule::getTBAAAccessTagInfo(TBAAAccessInfo Info) {
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 8705d3d65f1a573..9b45a644937b8d9 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -95,8 +95,6 @@ static bool TypeHasMayAlias(QualType QTy) {
 
 /// Check if the given type is a valid base type to be used in access tags.
 static bool isValidBaseType(QualType QTy) {
-  if (QTy->isReferenceType())
-return false;
   if (const RecordType *TTy = QTy->getAs()) {
 const RecordDecl *RD = TTy->getDecl()->getDefinition();
 // Incomplete types are not valid base access types.
@@ -414,8 +412,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type 
*Ty) {
 }
 
 llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
-  if (!isValidBaseType(QTy))
-return nullptr;
+  assert(isValidBaseType(QTy) && "Must be a valid base type");
 
   const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
   if (llvm::MDNode *N = BaseTypeMetadataCache[Ty])
@@ -428,6 +425,10 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
   return BaseTypeMetadataCache[Ty] = TypeNode;
 }
 
+llvm::MDNode *CodeGenTBAA::maybeGetBaseTypeInfo(QualType QTy) {
+  return isValidBaseType(QTy) ? getBaseTypeInfo(QTy) : nullptr;
+}
+
 llvm::MDNode *CodeGenTBAA::getAccessTagInfo(TBAAAccessInfo Info) {
   assert(!Info.isIncomplete() && "Access to an object of an incomplete type!");
 
diff --git a/clang/lib/CodeGen/CodeGenTBAA.h b/clang/lib/CodeGen/CodeGenTBAA.h
index a65963596fe9def..53d77e1fefc4352 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.h
+++ b/clang/lib/CodeGen/CodeGenTBAA.h
@@ -166,6 +166,10 @@ class CodeGenTBAA {
   /// used to describe accesses to objects of the given base type.
   llvm::MDNode *getBaseTypeInfoHelper(const Type *Ty);
 
+  /// getBaseTypeInfo - Return metadata that describes the given base access
+  /// type. The type must be suitable.
+  llvm::MDNode *getBaseTypeInfo(QualType QTy);
+
 public:
   CodeGenTBAA(ASTContext , llvm::Module , const CodeGenOptions ,
   const LangOptions , MangleContext );
@@ -187,9 +191,10 @@ class CodeGenTBAA {
   /// the given type.
   llvm::MDNode *getTBAAStructInfo(QualType QTy);
 
-  /// getBaseTypeInfo - Get metadata that describes the given base access type.
-  /// Return null if the type is not suitable for use in TBAA access tags.
-  llvm::MDNode *getBaseTypeInfo(QualType QTy);
+  /// maybeGetBaseTypeInfo - Get metadata that describes the given base access
+  /// type. Return null if the type is not suitable for use in TBAA access
+  /// tags.
+  llvm::MDNode *maybeGetBaseTypeInfo(QualType QTy);
 
   

[llvm] [clang-tools-extra] [PowerPC] Implement llvm.set.rounding intrinsic (PR #67302)

2023-11-23 Thread Serge Pavlov via cfe-commits

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


[llvm] [clang-tools-extra] [PowerPC] Implement llvm.set.rounding intrinsic (PR #67302)

2023-11-23 Thread Serge Pavlov via cfe-commits


@@ -8900,6 +8900,83 @@ SDValue PPCTargetLowering::LowerINT_TO_FP(SDValue Op,
   return FP;
 }
 
+SDValue PPCTargetLowering::LowerSET_ROUNDING(SDValue Op,
+ SelectionDAG ) const {
+  SDLoc Dl(Op);
+  MachineFunction  = DAG.getMachineFunction();
+  EVT PtrVT = getPointerTy(MF.getDataLayout());
+  SDValue Chain = Op.getOperand(0);
+
+  // If requested mode is constant, just use simpler mtfsb.
+  if (auto *CVal = dyn_cast(Op.getOperand(1))) {
+uint64_t Mode = CVal->getZExtValue();
+if (Mode >= 4)
+  llvm_unreachable("Unsupported rounding mode!");
+unsigned InternalRnd = Mode ^ (~(Mode >> 1) & 1);
+SDNode *SetHi = DAG.getMachineNode(
+(InternalRnd & 2) ? PPC::MTFSB1 : PPC::MTFSB0, Dl, MVT::Other,
+{DAG.getConstant(30, Dl, MVT::i32, true), Chain});
+SDNode *SetLo = DAG.getMachineNode(
+(InternalRnd & 1) ? PPC::MTFSB1 : PPC::MTFSB0, Dl, MVT::Other,
+{DAG.getConstant(31, Dl, MVT::i32, true), SDValue(SetHi, 0)});
+return SDValue(SetLo, 0);
+  }
+
+  // Use x ^ (~(x >> 1) & 1) to transform LLVM rounding mode to Power format.
+  SDValue One = DAG.getConstant(1, Dl, MVT::i32);
+  SDValue SrcFlag = DAG.getNode(ISD::AND, Dl, MVT::i32, Op.getOperand(1),
+DAG.getConstant(3, Dl, MVT::i32));
+  SDValue DstFlag = DAG.getNode(
+  ISD::XOR, Dl, MVT::i32, SrcFlag,
+  DAG.getNode(ISD::AND, Dl, MVT::i32,
+  DAG.getNOT(Dl,
+ DAG.getNode(ISD::SRL, Dl, MVT::i32, SrcFlag, One),
+ MVT::i32),
+  One));
+  SDValue MFFS = DAG.getNode(PPCISD::MFFS, Dl, {MVT::f64, MVT::Other}, Chain);
+  Chain = MFFS.getValue(1);
+  SDValue NewFPSCR;
+  if (isTypeLegal(MVT::i64)) {
+// Set the last two bits (rounding mode) of bitcasted FPSCR.
+NewFPSCR = DAG.getNode(
+ISD::OR, Dl, MVT::i64,
+DAG.getNode(ISD::AND, Dl, MVT::i64,
+DAG.getNode(ISD::BITCAST, Dl, MVT::i64, MFFS),
+DAG.getNOT(Dl, DAG.getConstant(3, Dl, MVT::i64), 
MVT::i64)),
+DAG.getNode(ISD::ZERO_EXTEND, Dl, MVT::i64, DstFlag));

spavloff wrote:

Is there guarantee that the upper bits (63-2) of `DestFlag` are zeros? 

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


[clang-tools-extra] [llvm] [PowerPC] Implement llvm.set.rounding intrinsic (PR #67302)

2023-11-23 Thread Serge Pavlov via cfe-commits


@@ -8900,6 +8900,83 @@ SDValue PPCTargetLowering::LowerINT_TO_FP(SDValue Op,
   return FP;
 }
 
+SDValue PPCTargetLowering::LowerSET_ROUNDING(SDValue Op,
+ SelectionDAG ) const {
+  SDLoc Dl(Op);
+  MachineFunction  = DAG.getMachineFunction();
+  EVT PtrVT = getPointerTy(MF.getDataLayout());
+  SDValue Chain = Op.getOperand(0);
+
+  // If requested mode is constant, just use simpler mtfsb.
+  if (auto *CVal = dyn_cast(Op.getOperand(1))) {
+uint64_t Mode = CVal->getZExtValue();
+if (Mode >= 4)
+  llvm_unreachable("Unsupported rounding mode!");

spavloff wrote:

Would using `assert` be more appropriate?

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


[clang-tools-extra] [llvm] [PowerPC] Implement llvm.set.rounding intrinsic (PR #67302)

2023-11-23 Thread Serge Pavlov via cfe-commits

https://github.com/spavloff commented:

The patch looks good but I am not familiar with PPC instructions enough. Could 
you please run the runtime tests from here: 
https://github.com/llvm/llvm-test-suite/tree/main/MultiSource/UnitTests/Float/rounding?
 You just need to build application from two files: `clang rounding.c 
rounding-dynamic.c`.

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


[clang-tools-extra] [llvm] [PowerPC] Implement llvm.set.rounding intrinsic (PR #67302)

2023-11-23 Thread Serge Pavlov via cfe-commits

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


[clang] Revert "[ClangRepl] Type Directed Code Completion" (PR #73259)

2023-11-23 Thread Vassil Vassilev via cfe-commits

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


[clang] 9ebe6e2 - Revert "[ClangRepl] Type Directed Code Completion" (#73259)

2023-11-23 Thread via cfe-commits

Author: Fred Fu
Date: 2023-11-23T21:07:51+02:00
New Revision: 9ebe6e28cdbe97f6c03209b87e91be6b55a8026a

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

LOG: Revert "[ClangRepl] Type Directed Code Completion" (#73259)

Reverts llvm/llvm-project#67349

There are some issues with the sanitizers. We will reland once that's fixed.

Added: 


Modified: 
clang/include/clang/Interpreter/CodeCompletion.h
clang/include/clang/Interpreter/Interpreter.h
clang/lib/Interpreter/CodeCompletion.cpp
clang/lib/Interpreter/Interpreter.cpp
clang/tools/clang-repl/ClangRepl.cpp
clang/unittests/Interpreter/CodeCompletionTest.cpp

Removed: 




diff  --git a/clang/include/clang/Interpreter/CodeCompletion.h 
b/clang/include/clang/Interpreter/CodeCompletion.h
index c64aa899759fd87..9adcdf0dc3afac6 100644
--- a/clang/include/clang/Interpreter/CodeCompletion.h
+++ b/clang/include/clang/Interpreter/CodeCompletion.h
@@ -23,27 +23,8 @@ namespace clang {
 class CodeCompletionResult;
 class CompilerInstance;
 
-struct ReplCodeCompleter {
-  ReplCodeCompleter() = default;
-  std::string Prefix;
-
-  /// \param InterpCI [in] The compiler instance that is used to trigger code
-  /// completion
-
-  /// \param Content [in] The string where code completion is triggered.
-
-  /// \param Line [in] The line number of the code completion point.
-
-  /// \param Col [in] The column number of the code completion point.
-
-  /// \param ParentCI [in] The running interpreter compiler instance that
-  /// provides ASTContexts.
-
-  /// \param CCResults [out] The completion results.
-  void codeComplete(CompilerInstance *InterpCI, llvm::StringRef Content,
-unsigned Line, unsigned Col,
-const CompilerInstance *ParentCI,
-std::vector );
-};
+void codeComplete(CompilerInstance *InterpCI, llvm::StringRef Content,
+  unsigned Line, unsigned Col, const CompilerInstance 
*ParentCI,
+  std::vector );
 } // namespace clang
 #endif

diff  --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 01858dfcc90ac5a..43573fb1a4b8915 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -101,7 +101,6 @@ class Interpreter {
   const ASTContext () const;
   ASTContext ();
   const CompilerInstance *getCompilerInstance() const;
-  CompilerInstance *getCompilerInstance();
   llvm::Expected getExecutionEngine();
 
   llvm::Expected Parse(llvm::StringRef Code);

diff  --git a/clang/lib/Interpreter/CodeCompletion.cpp 
b/clang/lib/Interpreter/CodeCompletion.cpp
index c34767c3ef9b87d..c40e11b9d1ece0a 100644
--- a/clang/lib/Interpreter/CodeCompletion.cpp
+++ b/clang/lib/Interpreter/CodeCompletion.cpp
@@ -12,7 +12,6 @@
 
 #include "clang/Interpreter/CodeCompletion.h"
 #include "clang/AST/ASTImporter.h"
-#include "clang/AST/DeclLookups.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/Basic/IdentifierTable.h"
@@ -24,8 +23,6 @@
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/CodeCompleteOptions.h"
 #include "clang/Sema/Sema.h"
-#include "llvm/Support/Debug.h"
-#define DEBUG_TYPE "REPLCC"
 
 namespace clang {
 
@@ -42,15 +39,11 @@ clang::CodeCompleteOptions getClangCompleteOpts() {
 
 class ReplCompletionConsumer : public CodeCompleteConsumer {
 public:
-  ReplCompletionConsumer(std::vector ,
- ReplCodeCompleter )
+  ReplCompletionConsumer(std::vector )
   : CodeCompleteConsumer(getClangCompleteOpts()),
 CCAllocator(std::make_shared()),
-CCTUInfo(CCAllocator), Results(Results), CC(CC) {}
+CCTUInfo(CCAllocator), Results(Results){};
 
-  // The entry of handling code completion. When the function is called, we
-  // create a `Context`-based handler (see classes defined below) to handle 
each
-  // completion result.
   void ProcessCodeCompleteResults(class Sema , CodeCompletionContext Context,
   CodeCompletionResult *InResults,
   unsigned NumResults) final;
@@ -63,146 +56,26 @@ class ReplCompletionConsumer : public CodeCompleteConsumer 
{
   std::shared_ptr CCAllocator;
   CodeCompletionTUInfo CCTUInfo;
   std::vector 
-  ReplCodeCompleter 
-};
-
-/// The class CompletionContextHandler contains four interfaces, each of
-/// which handles one type of completion result.
-/// Its derived classes are used to create concrete handlers based on
-/// \c CodeCompletionContext.
-class CompletionContextHandler {
-protected:
-  CodeCompletionContext CCC;
-  std::vector 
-
-private:
-  Sema 
-
-public:
-  CompletionContextHandler(Sema , CodeCompletionContext CCC,
-  

[clang] Revert "[ClangRepl] Type Directed Code Completion" (PR #73259)

2023-11-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Fred Fu (capfredf)


Changes

Reverts llvm/llvm-project#67349

---

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


6 Files Affected:

- (modified) clang/include/clang/Interpreter/CodeCompletion.h (+3-22) 
- (modified) clang/include/clang/Interpreter/Interpreter.h (-1) 
- (modified) clang/lib/Interpreter/CodeCompletion.cpp (+23-199) 
- (modified) clang/lib/Interpreter/Interpreter.cpp (-4) 
- (modified) clang/tools/clang-repl/ClangRepl.cpp (+15-9) 
- (modified) clang/unittests/Interpreter/CodeCompletionTest.cpp (+10-209) 


``diff
diff --git a/clang/include/clang/Interpreter/CodeCompletion.h 
b/clang/include/clang/Interpreter/CodeCompletion.h
index c64aa899759fd87..9adcdf0dc3afac6 100644
--- a/clang/include/clang/Interpreter/CodeCompletion.h
+++ b/clang/include/clang/Interpreter/CodeCompletion.h
@@ -23,27 +23,8 @@ namespace clang {
 class CodeCompletionResult;
 class CompilerInstance;
 
-struct ReplCodeCompleter {
-  ReplCodeCompleter() = default;
-  std::string Prefix;
-
-  /// \param InterpCI [in] The compiler instance that is used to trigger code
-  /// completion
-
-  /// \param Content [in] The string where code completion is triggered.
-
-  /// \param Line [in] The line number of the code completion point.
-
-  /// \param Col [in] The column number of the code completion point.
-
-  /// \param ParentCI [in] The running interpreter compiler instance that
-  /// provides ASTContexts.
-
-  /// \param CCResults [out] The completion results.
-  void codeComplete(CompilerInstance *InterpCI, llvm::StringRef Content,
-unsigned Line, unsigned Col,
-const CompilerInstance *ParentCI,
-std::vector );
-};
+void codeComplete(CompilerInstance *InterpCI, llvm::StringRef Content,
+  unsigned Line, unsigned Col, const CompilerInstance 
*ParentCI,
+  std::vector );
 } // namespace clang
 #endif
diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 01858dfcc90ac5a..43573fb1a4b8915 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -101,7 +101,6 @@ class Interpreter {
   const ASTContext () const;
   ASTContext ();
   const CompilerInstance *getCompilerInstance() const;
-  CompilerInstance *getCompilerInstance();
   llvm::Expected getExecutionEngine();
 
   llvm::Expected Parse(llvm::StringRef Code);
diff --git a/clang/lib/Interpreter/CodeCompletion.cpp 
b/clang/lib/Interpreter/CodeCompletion.cpp
index c34767c3ef9b87d..c40e11b9d1ece0a 100644
--- a/clang/lib/Interpreter/CodeCompletion.cpp
+++ b/clang/lib/Interpreter/CodeCompletion.cpp
@@ -12,7 +12,6 @@
 
 #include "clang/Interpreter/CodeCompletion.h"
 #include "clang/AST/ASTImporter.h"
-#include "clang/AST/DeclLookups.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/Basic/IdentifierTable.h"
@@ -24,8 +23,6 @@
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/CodeCompleteOptions.h"
 #include "clang/Sema/Sema.h"
-#include "llvm/Support/Debug.h"
-#define DEBUG_TYPE "REPLCC"
 
 namespace clang {
 
@@ -42,15 +39,11 @@ clang::CodeCompleteOptions getClangCompleteOpts() {
 
 class ReplCompletionConsumer : public CodeCompleteConsumer {
 public:
-  ReplCompletionConsumer(std::vector ,
- ReplCodeCompleter )
+  ReplCompletionConsumer(std::vector )
   : CodeCompleteConsumer(getClangCompleteOpts()),
 CCAllocator(std::make_shared()),
-CCTUInfo(CCAllocator), Results(Results), CC(CC) {}
+CCTUInfo(CCAllocator), Results(Results){};
 
-  // The entry of handling code completion. When the function is called, we
-  // create a `Context`-based handler (see classes defined below) to handle 
each
-  // completion result.
   void ProcessCodeCompleteResults(class Sema , CodeCompletionContext Context,
   CodeCompletionResult *InResults,
   unsigned NumResults) final;
@@ -63,146 +56,26 @@ class ReplCompletionConsumer : public CodeCompleteConsumer 
{
   std::shared_ptr CCAllocator;
   CodeCompletionTUInfo CCTUInfo;
   std::vector 
-  ReplCodeCompleter 
-};
-
-/// The class CompletionContextHandler contains four interfaces, each of
-/// which handles one type of completion result.
-/// Its derived classes are used to create concrete handlers based on
-/// \c CodeCompletionContext.
-class CompletionContextHandler {
-protected:
-  CodeCompletionContext CCC;
-  std::vector 
-
-private:
-  Sema 
-
-public:
-  CompletionContextHandler(Sema , CodeCompletionContext CCC,
-   std::vector )
-  : CCC(CCC), Results(Results), S(S) {}
-
-  /// Converts a Declaration completion result to a completion string, and then
-  /// stores it in Results.
-  virtual void 

[clang] Revert "[ClangRepl] Type Directed Code Completion" (PR #73259)

2023-11-23 Thread Fred Fu via cfe-commits

capfredf wrote:

@vgvassilev 

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


[clang] [clang] Print static_assert values of arithmetic binary operators (PR #71671)

2023-11-23 Thread via cfe-commits


@@ -17219,10 +17219,10 @@ static bool UsefulToPrintExpr(const Expr *E) {
   if (const auto *UnaryOp = dyn_cast(E))
 return UsefulToPrintExpr(UnaryOp->getSubExpr());
 
-  // Ignore nested binary operators. This could be a FIXME for improvements
-  // to the diagnostics in the future.
-  if (isa(E))
-return false;
+  // Only print nested arithmetic operators.
+  if (const auto *BO = dyn_cast(E))
+return (BO->isShiftOp() || BO->isAdditiveOp() || BO->isMultiplicativeOp() 
||
+BO->isBitwiseOp());
 

cor3ntin wrote:

Oh, I see

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


[clang] Revert "[ClangRepl] Type Directed Code Completion" (PR #73259)

2023-11-23 Thread Fred Fu via cfe-commits

https://github.com/capfredf created 
https://github.com/llvm/llvm-project/pull/73259

Reverts llvm/llvm-project#67349

>From ad46f098f845c6a67cce0229dd402bd8cf31ac16 Mon Sep 17 00:00:00 2001
From: Fred Fu 
Date: Thu, 23 Nov 2023 14:06:49 -0500
Subject: [PATCH] Revert "[ClangRepl] Type Directed Code Completion (#67349)"

This reverts commit 002d471a4a3cd8b429e4ca7c84fd54a642e50e4c.
---
 .../clang/Interpreter/CodeCompletion.h|  25 +-
 clang/include/clang/Interpreter/Interpreter.h |   1 -
 clang/lib/Interpreter/CodeCompletion.cpp  | 222 ++
 clang/lib/Interpreter/Interpreter.cpp |   4 -
 clang/tools/clang-repl/ClangRepl.cpp  |  24 +-
 .../Interpreter/CodeCompletionTest.cpp| 219 +
 6 files changed, 51 insertions(+), 444 deletions(-)

diff --git a/clang/include/clang/Interpreter/CodeCompletion.h 
b/clang/include/clang/Interpreter/CodeCompletion.h
index c64aa899759fd87..9adcdf0dc3afac6 100644
--- a/clang/include/clang/Interpreter/CodeCompletion.h
+++ b/clang/include/clang/Interpreter/CodeCompletion.h
@@ -23,27 +23,8 @@ namespace clang {
 class CodeCompletionResult;
 class CompilerInstance;
 
-struct ReplCodeCompleter {
-  ReplCodeCompleter() = default;
-  std::string Prefix;
-
-  /// \param InterpCI [in] The compiler instance that is used to trigger code
-  /// completion
-
-  /// \param Content [in] The string where code completion is triggered.
-
-  /// \param Line [in] The line number of the code completion point.
-
-  /// \param Col [in] The column number of the code completion point.
-
-  /// \param ParentCI [in] The running interpreter compiler instance that
-  /// provides ASTContexts.
-
-  /// \param CCResults [out] The completion results.
-  void codeComplete(CompilerInstance *InterpCI, llvm::StringRef Content,
-unsigned Line, unsigned Col,
-const CompilerInstance *ParentCI,
-std::vector );
-};
+void codeComplete(CompilerInstance *InterpCI, llvm::StringRef Content,
+  unsigned Line, unsigned Col, const CompilerInstance 
*ParentCI,
+  std::vector );
 } // namespace clang
 #endif
diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 01858dfcc90ac5a..43573fb1a4b8915 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -101,7 +101,6 @@ class Interpreter {
   const ASTContext () const;
   ASTContext ();
   const CompilerInstance *getCompilerInstance() const;
-  CompilerInstance *getCompilerInstance();
   llvm::Expected getExecutionEngine();
 
   llvm::Expected Parse(llvm::StringRef Code);
diff --git a/clang/lib/Interpreter/CodeCompletion.cpp 
b/clang/lib/Interpreter/CodeCompletion.cpp
index c34767c3ef9b87d..c40e11b9d1ece0a 100644
--- a/clang/lib/Interpreter/CodeCompletion.cpp
+++ b/clang/lib/Interpreter/CodeCompletion.cpp
@@ -12,7 +12,6 @@
 
 #include "clang/Interpreter/CodeCompletion.h"
 #include "clang/AST/ASTImporter.h"
-#include "clang/AST/DeclLookups.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/Basic/IdentifierTable.h"
@@ -24,8 +23,6 @@
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/CodeCompleteOptions.h"
 #include "clang/Sema/Sema.h"
-#include "llvm/Support/Debug.h"
-#define DEBUG_TYPE "REPLCC"
 
 namespace clang {
 
@@ -42,15 +39,11 @@ clang::CodeCompleteOptions getClangCompleteOpts() {
 
 class ReplCompletionConsumer : public CodeCompleteConsumer {
 public:
-  ReplCompletionConsumer(std::vector ,
- ReplCodeCompleter )
+  ReplCompletionConsumer(std::vector )
   : CodeCompleteConsumer(getClangCompleteOpts()),
 CCAllocator(std::make_shared()),
-CCTUInfo(CCAllocator), Results(Results), CC(CC) {}
+CCTUInfo(CCAllocator), Results(Results){};
 
-  // The entry of handling code completion. When the function is called, we
-  // create a `Context`-based handler (see classes defined below) to handle 
each
-  // completion result.
   void ProcessCodeCompleteResults(class Sema , CodeCompletionContext Context,
   CodeCompletionResult *InResults,
   unsigned NumResults) final;
@@ -63,146 +56,26 @@ class ReplCompletionConsumer : public CodeCompleteConsumer 
{
   std::shared_ptr CCAllocator;
   CodeCompletionTUInfo CCTUInfo;
   std::vector 
-  ReplCodeCompleter 
-};
-
-/// The class CompletionContextHandler contains four interfaces, each of
-/// which handles one type of completion result.
-/// Its derived classes are used to create concrete handlers based on
-/// \c CodeCompletionContext.
-class CompletionContextHandler {
-protected:
-  CodeCompletionContext CCC;
-  std::vector 
-
-private:
-  Sema 
-
-public:
-  CompletionContextHandler(Sema , CodeCompletionContext CCC,
-   std::vector )
-  : CCC(CCC), Results(Results), 

[clang] [clang] Print static_assert values of arithmetic binary operators (PR #71671)

2023-11-23 Thread via cfe-commits

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


[clang] [clang] Print static_assert values of arithmetic binary operators (PR #71671)

2023-11-23 Thread via cfe-commits

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

LGTM.
I wonder if we should add an entry in the release notes?

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


[clang] [ClangRepl] Type Directed Code Completion (PR #67349)

2023-11-23 Thread Fred Fu via cfe-commits

capfredf wrote:

@vgvassilev there are some issues reported by sanitizers. Let's revert the 
patch. I will fix those issues and then re-land the patch

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


[clang] [ClangRepl] Type Directed Code Completion (PR #67349)

2023-11-23 Thread Fred Fu via cfe-commits

capfredf wrote:

@vgvassilev Thank you very much!

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


[clang] [APINotes] Upstream Driver and Frontend options that enable API Notes (PR #73120)

2023-11-23 Thread Egor Zhdan via cfe-commits

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


[clang] 07d799f - [APINotes] Upstream Driver and Frontend options that enable API Notes

2023-11-23 Thread via cfe-commits

Author: Egor Zhdan
Date: 2023-11-23T18:52:27Z
New Revision: 07d799f08fec4cb9ceb14a43cc134dee7f1621fc

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

LOG: [APINotes] Upstream Driver and Frontend options that enable API Notes

This upstreams more of the Clang API Notes functionality that is
currently implemented in the Apple fork:
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index cd77b22bf3ace4b..c3d5399905a3fda 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -405,6 +405,7 @@ LANGOPT(XLPragmaPack, 1, 0, "IBM XL #pragma pack handling")
 LANGOPT(RetainCommentsFromSystemHeaders, 1, 0, "retain documentation comments 
from system headers in the AST")
 
 LANGOPT(APINotes, 1, 0, "use external API notes")
+LANGOPT(APINotesModules, 1, 0, "use module-based external API notes")
 
 LANGOPT(SanitizeAddressFieldPadding, 2, 0, "controls how aggressive is ASan "
"field padding (0: none, 1:least "

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b2f2bcb6ac37910..9191ccd2a66ac4a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1754,6 +1754,18 @@ def fswift_async_fp_EQ : Joined<["-"], 
"fswift-async-fp=">,
 NormalizedValuesScope<"CodeGenOptions::SwiftAsyncFramePointerKind">,
 NormalizedValues<["Auto", "Always", "Never"]>,
 MarshallingInfoEnum, "Always">;
+defm apinotes : BoolOption<"f", "apinotes",
+LangOpts<"APINotes">, DefaultFalse,
+PosFlag,
+NegFlag,
+BothFlags<[], [ClangOption, CC1Option], "external API notes support">>,
+Group;
+defm apinotes_modules : BoolOption<"f", "apinotes-modules",
+LangOpts<"APINotesModules">, DefaultFalse,
+PosFlag,
+NegFlag,
+BothFlags<[], [ClangOption, CC1Option], "module-based external API notes 
support">>,
+Group;
 def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">,
   Group, Visibility<[ClangOption, CC1Option]>,
   MetaVarName<"">,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 6dec117aed1056b..2d73f42772a29dc 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6720,6 +6720,13 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
  options::OPT_fno_assume_sane_operator_new);
 
+  if (Args.hasFlag(options::OPT_fapinotes, options::OPT_fno_apinotes, false))
+CmdArgs.push_back("-fapinotes");
+  if (Args.hasFlag(options::OPT_fapinotes_modules,
+   options::OPT_fno_apinotes_modules, false))
+CmdArgs.push_back("-fapinotes-modules");
+  Args.AddLastArg(CmdArgs, options::OPT_fapinotes_swift_version);
+
   // -fblocks=0 is default.
   if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks,
TC.IsBlocksDefault()) ||

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index be5b38d6110fc3b..e5f8c0746a99dd4 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -756,6 +756,14 @@ void CompilerInstance::createSema(TranslationUnitKind 
TUKind,
 TheSema->addExternalSource(ExternalSemaSrc.get());
 ExternalSemaSrc->InitializeSema(*TheSema);
   }
+
+  // If we're building a module and are supposed to load API notes,
+  // notify the API notes manager.
+  if (auto *currentModule = getPreprocessor().getCurrentModule()) {
+(void)TheSema->APINotes.loadCurrentModuleAPINotes(
+currentModule, getLangOpts().APINotesModules,
+getAPINotesOpts().ModuleSearchPaths);
+  }
 }
 
 // Output Files

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 3f4ca02539080d0..3b92cc1281f9e0e 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3267,6 +3267,16 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
, ArgList ,
   return Diags.getNumErrors() == NumErrorsBefore;
 }
 
+static void GenerateAPINotesArgs(const APINotesOptions ,
+ ArgumentConsumer Consumer) {
+  if (!Opts.SwiftVersion.empty())
+GenerateArg(Consumer, OPT_fapinotes_swift_version,
+

[clang] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-11-23 Thread via cfe-commits

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


[clang] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-11-23 Thread via cfe-commits

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


[clang] [clang] Print static_assert values of arithmetic binary operators (PR #71671)

2023-11-23 Thread Timm Baeder via cfe-commits


@@ -17219,10 +17219,10 @@ static bool UsefulToPrintExpr(const Expr *E) {
   if (const auto *UnaryOp = dyn_cast(E))
 return UsefulToPrintExpr(UnaryOp->getSubExpr());
 
-  // Ignore nested binary operators. This could be a FIXME for improvements
-  // to the diagnostics in the future.
-  if (isa(E))
-return false;
+  // Only print nested arithmetic operators.
+  if (const auto *BO = dyn_cast(E))
+return (BO->isShiftOp() || BO->isAdditiveOp() || BO->isMultiplicativeOp() 
||
+BO->isBitwiseOp());
 

tbaederr wrote:

For
```c++
static_assert(1 << 1 == 0);
```
we can print the result rather easily, but for 
```c++
static_assert(foo() > 1 && bar() == 10);
```
it's kind useless to print the LHS and RHS of the `&&` operator because they 
just evaluate to `true` or `false`. To print this in a useful way, we would 
have to dig deeper into the expression and print what `foo()` and `bar()` 
evaluate to. 

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


[clang] [clang] Print static_assert values of arithmetic binary operators (PR #71671)

2023-11-23 Thread via cfe-commits


@@ -17219,10 +17219,10 @@ static bool UsefulToPrintExpr(const Expr *E) {
   if (const auto *UnaryOp = dyn_cast(E))
 return UsefulToPrintExpr(UnaryOp->getSubExpr());
 
-  // Ignore nested binary operators. This could be a FIXME for improvements
-  // to the diagnostics in the future.
-  if (isa(E))
-return false;
+  // Only print nested arithmetic operators.
+  if (const auto *BO = dyn_cast(E))
+return (BO->isShiftOp() || BO->isAdditiveOp() || BO->isMultiplicativeOp() 
||
+BO->isBitwiseOp());
 

cor3ntin wrote:

Can you clarify? I'm not sure i understood this comment. thanks

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


[clang] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-11-23 Thread via cfe-commits

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


[clang] Header (PR #73258)

2023-11-23 Thread via cfe-commits

https://github.com/CarolineConcatto updated 
https://github.com/llvm/llvm-project/pull/73258

>From e0f245e8d6a395afac5de471b55358c7b730a170 Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Wed, 22 Nov 2023 10:03:50 +
Subject: [PATCH] [Clang][AArch64] Add  fix vector types to header into SVE

This patch is needed for the reduction instructions in sve2.1

It add ta new header to sve with all the fixed vector types.
The new types are only added if neon is not declared.
---
 clang/include/clang/Basic/arm_vector_type.td  |  13 ++
 clang/lib/Headers/CMakeLists.txt  |   3 +
 .../CodeGen/arm-vector_type-params-returns.c  | 113 ++
 clang/utils/TableGen/NeonEmitter.cpp  |  44 +++
 clang/utils/TableGen/SveEmitter.cpp   |   2 +
 clang/utils/TableGen/TableGen.cpp |  15 ++-
 clang/utils/TableGen/TableGenBackends.h   |   1 +
 7 files changed, 188 insertions(+), 3 deletions(-)
 create mode 100644 clang/include/clang/Basic/arm_vector_type.td
 create mode 100644 clang/test/CodeGen/arm-vector_type-params-returns.c

diff --git a/clang/include/clang/Basic/arm_vector_type.td 
b/clang/include/clang/Basic/arm_vector_type.td
new file mode 100644
index 000..5018b0cdfc13785
--- /dev/null
+++ b/clang/include/clang/Basic/arm_vector_type.td
@@ -0,0 +1,13 @@
+//===--- arm_vector_type.td - ARM Fixed vector types compiler interface 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines the TableGen definitions from which the ARM BF16 header
+//  file will be generated.
+//
+//===--===//
+include "arm_neon_incl.td"
diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 8b1e2bc4afa4dcd..0beb6ade4292045 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -385,6 +385,8 @@ if(ARM IN_LIST LLVM_TARGETS_TO_BUILD OR AArch64 IN_LIST 
LLVM_TARGETS_TO_BUILD)
   clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
   # Generate arm_cde.h
   clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
+  # Generate arm_vector_type.h
+  clang_generate_header(-gen-arm-vector-type arm_vector_type.td 
arm_vector_type.h)
 
   # Add headers to target specific lists
   list(APPEND arm_common_generated_files
@@ -401,6 +403,7 @@ if(ARM IN_LIST LLVM_TARGETS_TO_BUILD OR AArch64 IN_LIST 
LLVM_TARGETS_TO_BUILD)
 "${CMAKE_CURRENT_BINARY_DIR}/arm_sve.h"
 "${CMAKE_CURRENT_BINARY_DIR}/arm_sme_draft_spec_subject_to_change.h"
 "${CMAKE_CURRENT_BINARY_DIR}/arm_bf16.h"
+"${CMAKE_CURRENT_BINARY_DIR}/arm_vector_type.h"
 )
 endif()
 if(RISCV IN_LIST LLVM_TARGETS_TO_BUILD)
diff --git a/clang/test/CodeGen/arm-vector_type-params-returns.c 
b/clang/test/CodeGen/arm-vector_type-params-returns.c
new file mode 100644
index 000..48c19d01b6257cc
--- /dev/null
+++ b/clang/test/CodeGen/arm-vector_type-params-returns.c
@@ -0,0 +1,113 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sve -emit-llvm -O2 -o - %s 
| opt -S -passes=mem2reg,sroa | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -o - /dev/null %s
+#include 
+
+// function return types
+// CHECK-LABEL: define dso_local <8 x half> @test_ret_v8f16(
+// CHECK-SAME: <8 x half> noundef returned [[V:%.*]]) local_unnamed_addr 
#[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret <8 x half> [[V]]
+//
+float16x8_t test_ret_v8f16(float16x8_t v) {
+  return v;
+}
+
+// CHECK-LABEL: define dso_local <4 x float> @test_ret_v4f32(
+// CHECK-SAME: <4 x float> noundef returned [[V:%.*]]) local_unnamed_addr 
#[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret <4 x float> [[V]]
+//
+float32x4_t test_ret_v4f32(float32x4_t v) {
+  return v;
+}
+
+// CHECK-LABEL: define dso_local <2 x double> @test_ret_v2f64(
+// CHECK-SAME: <2 x double> noundef returned [[V:%.*]]) local_unnamed_addr 
#[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret <2 x double> [[V]]
+//
+float64x2_t test_ret_v2f64(float64x2_t v) {
+  return v;
+}
+
+// CHECK-LABEL: define dso_local <8 x bfloat> @test_ret_v8bf16(
+// CHECK-SAME: <8 x bfloat> noundef returned [[V:%.*]]) local_unnamed_addr 
#[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret <8 x bfloat> [[V]]
+//
+bfloat16x8_t test_ret_v8bf16(bfloat16x8_t v) {
+  return v;
+}
+
+// CHECK-LABEL: define dso_local <16 x i8> @test_ret_v16s8(
+// CHECK-SAME: <16 x i8> noundef returned [[V:%.*]]) local_unnamed_addr 
#[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret <16 

[clang] [clang] Print static_assert values of arithmetic binary operators (PR #71671)

2023-11-23 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[llvm] [clang] Header (PR #73258)

2023-11-23 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-clang

Author: None (CarolineConcatto)


Changes



---

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


49 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+17-1) 
- (added) clang/include/clang/Basic/arm_vector_type.td (+13) 
- (modified) clang/lib/Headers/CMakeLists.txt (+3) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfadd.c 
(+133) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfclamp.c 
(+31) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmax.c 
(+134) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmaxnm.c 
(+134) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmin.c 
(+134) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfminnm.c 
(+134) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmla.c 
(+133) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmla_lane.c 
(+60) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmls.c 
(+133) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmls_lane.c 
(+60) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmul.c 
(+134) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmul_lane.c 
(+61) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfsub.c 
(+134) 
- (added) clang/test/CodeGen/arm-vector_type-params-returns.c (+113) 
- (modified) clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp 
(+17) 
- (modified) clang/utils/TableGen/NeonEmitter.cpp (+44) 
- (modified) clang/utils/TableGen/SveEmitter.cpp (+2) 
- (modified) clang/utils/TableGen/TableGen.cpp (+12-3) 
- (modified) clang/utils/TableGen/TableGenBackends.h (+1) 
- (modified) llvm/lib/Target/AArch64/AArch64.td (+4-4) 
- (modified) llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td (+45-17) 
- (modified) llvm/lib/Target/AArch64/SVEInstrFormats.td (+56-2) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfadd.ll (+62) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfclamp.ll (+13) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmax.ll (+74) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmaxnm.ll (+74) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmin.ll (+74) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfminnm.ll (+74) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmla.ll (+35) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmla_lane.ll (+31) 
- (modified) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmls.ll (+21-28) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmls_lane.ll (+31) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmlsl.ll (+43) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmul.ll (+62) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfmul_lane.ll (+37) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfsub.ll (+62) 
- (modified) llvm/test/MC/AArch64/SVE2p1/bfadd.s (+10-10) 
- (modified) llvm/test/MC/AArch64/SVE2p1/bfclamp.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2p1/bfmax.s (+6-6) 
- (modified) llvm/test/MC/AArch64/SVE2p1/bfmaxnm.s (+6-6) 
- (modified) llvm/test/MC/AArch64/SVE2p1/bfmin.s (+6-6) 
- (modified) llvm/test/MC/AArch64/SVE2p1/bfminnm.s (+6-6) 
- (modified) llvm/test/MC/AArch64/SVE2p1/bfmla.s (+11-11) 
- (modified) llvm/test/MC/AArch64/SVE2p1/bfmls.s (+11-11) 
- (modified) llvm/test/MC/AArch64/SVE2p1/bfmul.s (+14-14) 
- (modified) llvm/test/MC/AArch64/SVE2p1/bfsub.s (+10-10) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index bc6b0874f28d..a1ac926ab9577bb7 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2039,7 +2039,23 @@ def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", 
"QcQsQiQl", MergeNone, "aarch64_sv
 defm SVREVD : SInstZPZ<"svrevd", "csilUcUsUiUl", "aarch64_sve_revd">;
 }
 
-
+
+let TargetGuard = "sve2p1,b16b16" in {
+defm SVMUL_BF  : SInstZPZZ<"svmul",  "b", "aarch64_sve_fmul",   
"aarch64_sve_fmul_u">;
+defm SVADD_BF  : SInstZPZZ<"svadd",  "b", "aarch64_sve_fadd",   
"aarch64_sve_fadd_u">;
+defm SVSUB_BF  : SInstZPZZ<"svsub",  "b", "aarch64_sve_fsub",   
"aarch64_sve_fsub_u">;
+defm SVMAXNM_BF  : SInstZPZZ<"svmaxnm","b", "aarch64_sve_fmaxnm", 
"aarch64_sve_fmaxnm_u">;
+defm SVMINNM_BF  : SInstZPZZ<"svminnm","b", "aarch64_sve_fminnm", 
"aarch64_sve_fminnm_u">;
+defm SVMAX_BF: SInstZPZZ<"svmax",  "b", "aarch64_sve_fmax",   
"aarch64_sve_fmax_u">;
+defm SVMIN_BF: SInstZPZZ<"svmin",  "b", "aarch64_sve_fmin",   
"aarch64_sve_fmin_u">;
+defm SVMLA_BF  : SInstZPZZZ<"svmla",  "b", "aarch64_sve_fmla",  
"aarch64_sve_fmla_u", []>;
+defm 

[clang] [clang][Interp] Implement dynamic memory allocation handling (PR #70306)

2023-11-23 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/70306

>From 29270191a209af2d8bcf270c84a87d6fa456fa0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 25 Oct 2023 08:33:30 +0200
Subject: [PATCH] [clang][Interp] Implement dynamic memory allocation handling

---
 clang/lib/AST/CMakeLists.txt   |   1 +
 clang/lib/AST/Interp/ByteCodeExprGen.cpp   |  76 +
 clang/lib/AST/Interp/ByteCodeExprGen.h |   2 +
 clang/lib/AST/Interp/Context.cpp   |   2 +-
 clang/lib/AST/Interp/DynamicAllocator.cpp  |  90 ++
 clang/lib/AST/Interp/DynamicAllocator.h|  92 ++
 clang/lib/AST/Interp/EvalEmitter.cpp   |   4 +-
 clang/lib/AST/Interp/Interp.cpp|  49 
 clang/lib/AST/Interp/Interp.h  | 141 +
 clang/lib/AST/Interp/InterpBuiltin.cpp |   1 +
 clang/lib/AST/Interp/InterpState.cpp   |  15 +
 clang/lib/AST/Interp/InterpState.h |  10 +
 clang/lib/AST/Interp/Opcodes.td|  28 ++
 clang/test/AST/Interp/new-delete.cpp   | 320 +
 clang/test/SemaCXX/paren-list-agg-init.cpp |   8 +-
 15 files changed, 834 insertions(+), 5 deletions(-)
 create mode 100644 clang/lib/AST/Interp/DynamicAllocator.cpp
 create mode 100644 clang/lib/AST/Interp/DynamicAllocator.h
 create mode 100644 clang/test/AST/Interp/new-delete.cpp

diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index fe3f8c485ec1c56e..1423623fb038cab4 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -75,6 +75,7 @@ add_clang_library(clangAST
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
   Interp/Floating.cpp
+  Interp/DynamicAllocator.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 5dc1f9dfb10ff321..ef53f5fdf2478235 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1620,6 +1620,82 @@ bool ByteCodeExprGen::VisitSizeOfPackExpr(const 
SizeOfPackExpr *E) {
   return this->emitConst(E->getPackLength(), E);
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXNewExpr(const CXXNewExpr *E) {
+  assert(classifyPrim(E->getType()) == PT_Ptr);
+  const Expr *Init = E->getInitializer();
+  QualType ElementType = E->getAllocatedType();
+  std::optional ElemT = classify(ElementType);
+
+  const Descriptor *Desc;
+  if (ElemT) {
+if (E->isArray())
+  Desc = nullptr; // We're not going to use it in this case.
+else
+  Desc = P.createDescriptor(E, *ElemT, Descriptor::InlineDescMD,
+/*IsConst=*/false, /*IsTemporary=*/false,
+/*IsMutable=*/false);
+  } else {
+Desc = P.createDescriptor(
+E, ElementType.getTypePtr(),
+E->isArray() ? std::nullopt : Descriptor::InlineDescMD,
+/*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false, Init);
+  }
+
+  if (E->isArray()) {
+assert(E->getArraySize());
+PrimType SizeT = classifyPrim((*E->getArraySize())->getType());
+
+if (!this->visit(*E->getArraySize()))
+  return false;
+
+if (ElemT) {
+  // N primitive elements.
+  if (!this->emitAllocN(SizeT, *ElemT, E, E))
+return false;
+} else {
+  // N Composite elements.
+  if (!this->emitAllocCN(SizeT, Desc, E))
+return false;
+}
+
+  } else {
+// Allocate just one element.
+if (!this->emitAlloc(Desc, E))
+  return false;
+
+if (Init) {
+  if (ElemT) {
+if (!this->visit(Init))
+  return false;
+
+if (!this->emitInit(*ElemT, E))
+  return false;
+  } else {
+// Composite.
+if (!this->visitInitializer(Init))
+  return false;
+  }
+}
+  }
+
+  if (DiscardResult)
+return this->emitPopPtr(E);
+
+  return true;
+}
+
+template 
+bool ByteCodeExprGen::VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
+  const Expr *Arg = E->getArgument();
+
+  // Arg must be an lvalue.
+  if (!this->visit(Arg))
+return false;
+
+  return this->emitFree(E->isArrayForm(), E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index bc1d5d11a1151356..bcb892c6c565feb8 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -107,6 +107,8 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitOffsetOfExpr(const OffsetOfExpr *E);
   bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E);
   bool VisitSizeOfPackExpr(const SizeOfPackExpr *E);
+  bool VisitCXXNewExpr(const CXXNewExpr *E);
+  bool VisitCXXDeleteExpr(const CXXDeleteExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
diff --git a/clang/lib/AST/Interp/Context.cpp 

[clang] [Clang] Improve support for expression messages in `static_assert` (PR #73234)

2023-11-23 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -std=c++2c -verify %s
+
+namespace dr2798 { // dr2798: 17 drafting
+#if __cpp_static_assert >= 202306
+struct string {
+constexpr string() {
+data_ = new char[6]();
+__builtin_memcpy(data_, "Hello", 5);
+data_[5] = 0;
+}
+constexpr ~string() {
+delete[] data_;
+}
+constexpr unsigned long size() const {
+return 5;
+};
+constexpr const char* data() const {
+return data_;
+}
+
+char* data_;
+};
+struct X {
+string s;
+};
+consteval X f() { return {}; }
+
+static_assert(false, f().s); // expected-error {{static assertion failed: 
Hello}}

Endilll wrote:

Would be nice to convert this to `// expected-error@-1` style.

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


[clang] [Clang] Improve support for expression messages in `static_assert` (PR #73234)

2023-11-23 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -std=c++2c -verify %s
+
+namespace dr2798 { // dr2798: 17 drafting
+#if __cpp_static_assert >= 202306
+struct string {
+constexpr string() {

Endilll wrote:

Is there a reason not to format this test with clang-format?

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


[clang] [Clang] Improve support for expression messages in `static_assert` (PR #73234)

2023-11-23 Thread Vlad Serebrennikov via cfe-commits

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

DR testing part looks good, save for a couple of minor comments.

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


[clang] [Clang] Improve support for expression messages in `static_assert` (PR #73234)

2023-11-23 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [Clang] Improve support for expression messages in `static_assert` (PR #73234)

2023-11-23 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [Clang] Improve support for expression messages in `static_assert` (PR #73234)

2023-11-23 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/73234

>From c274d62d03e1ab390284b26d6e23a23d099a98f6 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 23 Nov 2023 12:51:46 +0100
Subject: [PATCH 1/2] [Clang] Improve support for expression messages in
 `static_assert`

- Support non-member functions and callable objects for size and data().
  We previously tried to (badly) pick the best overload ourselves,
  in a way that would only support member functions.
  We now leave clamg construct an unresolved member expression and call that,
  properly performing overload resolution with callable objects and
  static functions, cojnsistent with the logic for `get` calls for structured 
bindings.
- Support UDLs as message expression.
- Add tests and mark CWG2798 as resolved
---
 clang/docs/ReleaseNotes.rst|  3 ++
 clang/lib/Parse/ParseDeclCXX.cpp   |  2 +-
 clang/lib/Sema/SemaDeclCXX.cpp | 24 ++
 clang/test/CXX/drs/dr27xx.cpp  | 30 
 clang/test/SemaCXX/static-assert-cxx26.cpp | 54 ++
 clang/www/cxx_dr_status.html   |  2 +-
 6 files changed, 82 insertions(+), 33 deletions(-)
 create mode 100644 clang/test/CXX/drs/dr27xx.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e2c990d03e7f27..5a8e63be1258a28 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -617,6 +617,9 @@ Bug Fixes in This Version
 - Fix crash during code generation of C++ coroutine initial suspend when the 
return
   type of await_resume is not trivially destructible.
   Fixes (`#63803 `_)
+- Fix crash when the object used as a ``static_asssert`` message has ``size`` 
or ``data`` members
+  which are not member functions.
+- Support UDLs in ``static_asssert`` message.
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index d9125955fda2783..910112ecae964cc 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1023,7 +1023,7 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation 
) {
 const Token  = GetLookAheadToken(I);
 if (T.is(tok::r_paren))
   break;
-if (!tokenIsLikeStringLiteral(T, getLangOpts())) {
+if (!tokenIsLikeStringLiteral(T, getLangOpts()) || T.hasUDSuffix()) {
   ParseAsExpression = true;
   break;
 }
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 3688192e6cbe5c5..1d9e4a0ac46fffe 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17291,33 +17291,15 @@ bool Sema::EvaluateStaticAssertMessageAsString(Expr 
*Message,
 
   auto FindMember = [&](StringRef Member, bool ,
 bool Diag = false) -> std::optional {
-QualType ObjectType = Message->getType();
-Expr::Classification ObjectClassification =
-Message->Classify(getASTContext());
-
 DeclarationName DN = PP.getIdentifierInfo(Member);
 LookupResult MemberLookup(*this, DN, Loc, Sema::LookupMemberName);
 LookupQualifiedName(MemberLookup, RD);
 Empty = MemberLookup.empty();
 OverloadCandidateSet Candidates(MemberLookup.getNameLoc(),
 OverloadCandidateSet::CSK_Normal);
-for (NamedDecl *D : MemberLookup) {
-  AddMethodCandidate(DeclAccessPair::make(D, D->getAccess()), ObjectType,
- ObjectClassification, /*Args=*/{}, Candidates);
-}
-OverloadCandidateSet::iterator Best;
-switch (Candidates.BestViableFunction(*this, Loc, Best)) {
-case OR_Success:
-  return std::move(MemberLookup);
-default:
-  if (Diag)
-Candidates.NoteCandidates(
-PartialDiagnosticAt(
-Loc, PDiag(diag::err_static_assert_invalid_mem_fn_ret_ty)
- << (Member == "data")),
-*this, OCD_AllCandidates, /*Args=*/{});
-}
-return std::nullopt;
+if (MemberLookup.empty())
+  return std::nullopt;
+return MemberLookup;
   };
 
   bool SizeNotFound, DataNotFound;
diff --git a/clang/test/CXX/drs/dr27xx.cpp b/clang/test/CXX/drs/dr27xx.cpp
new file mode 100644
index 000..f17726eb045f933
--- /dev/null
+++ b/clang/test/CXX/drs/dr27xx.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -std=c++2c -verify %s
+
+namespace dr2798 { // dr2798: 17 drafting
+#if __cpp_static_assert >= 202306
+struct string {
+constexpr string() {
+data_ = new char[6]();
+__builtin_memcpy(data_, "Hello", 5);
+data_[5] = 0;
+}
+constexpr ~string() {
+delete[] data_;
+}
+constexpr unsigned long size() const {
+return 5;
+};
+constexpr const char* data() const {
+return data_;
+}
+
+char* data_;
+};
+struct X {
+string s;
+};
+consteval X 

[clang] [ClangRepl] Type Directed Code Completion (PR #67349)

2023-11-23 Thread Vassil Vassilev via cfe-commits

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


[clang] 002d471 - [ClangRepl] Type Directed Code Completion (#67349)

2023-11-23 Thread via cfe-commits

Author: Fred Fu
Date: 2023-11-23T19:56:35+02:00
New Revision: 002d471a4a3cd8b429e4ca7c84fd54a642e50e4c

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

LOG: [ClangRepl] Type Directed Code Completion (#67349)

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

Added: 


Modified: 
clang/include/clang/Interpreter/CodeCompletion.h
clang/include/clang/Interpreter/Interpreter.h
clang/lib/Interpreter/CodeCompletion.cpp
clang/lib/Interpreter/Interpreter.cpp
clang/tools/clang-repl/ClangRepl.cpp
clang/unittests/Interpreter/CodeCompletionTest.cpp

Removed: 




diff  --git a/clang/include/clang/Interpreter/CodeCompletion.h 
b/clang/include/clang/Interpreter/CodeCompletion.h
index 9adcdf0dc3afac6..c64aa899759fd87 100644
--- a/clang/include/clang/Interpreter/CodeCompletion.h
+++ b/clang/include/clang/Interpreter/CodeCompletion.h
@@ -23,8 +23,27 @@ namespace clang {
 class CodeCompletionResult;
 class CompilerInstance;
 
-void codeComplete(CompilerInstance *InterpCI, llvm::StringRef Content,
-  unsigned Line, unsigned Col, const CompilerInstance 
*ParentCI,
-  std::vector );
+struct ReplCodeCompleter {
+  ReplCodeCompleter() = default;
+  std::string Prefix;
+
+  /// \param InterpCI [in] The compiler instance that is used to trigger code
+  /// completion
+
+  /// \param Content [in] The string where code completion is triggered.
+
+  /// \param Line [in] The line number of the code completion point.
+
+  /// \param Col [in] The column number of the code completion point.
+
+  /// \param ParentCI [in] The running interpreter compiler instance that
+  /// provides ASTContexts.
+
+  /// \param CCResults [out] The completion results.
+  void codeComplete(CompilerInstance *InterpCI, llvm::StringRef Content,
+unsigned Line, unsigned Col,
+const CompilerInstance *ParentCI,
+std::vector );
+};
 } // namespace clang
 #endif

diff  --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 43573fb1a4b8915..01858dfcc90ac5a 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -101,6 +101,7 @@ class Interpreter {
   const ASTContext () const;
   ASTContext ();
   const CompilerInstance *getCompilerInstance() const;
+  CompilerInstance *getCompilerInstance();
   llvm::Expected getExecutionEngine();
 
   llvm::Expected Parse(llvm::StringRef Code);

diff  --git a/clang/lib/Interpreter/CodeCompletion.cpp 
b/clang/lib/Interpreter/CodeCompletion.cpp
index c40e11b9d1ece0a..c34767c3ef9b87d 100644
--- a/clang/lib/Interpreter/CodeCompletion.cpp
+++ b/clang/lib/Interpreter/CodeCompletion.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/Interpreter/CodeCompletion.h"
 #include "clang/AST/ASTImporter.h"
+#include "clang/AST/DeclLookups.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/Basic/IdentifierTable.h"
@@ -23,6 +24,8 @@
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/CodeCompleteOptions.h"
 #include "clang/Sema/Sema.h"
+#include "llvm/Support/Debug.h"
+#define DEBUG_TYPE "REPLCC"
 
 namespace clang {
 
@@ -39,11 +42,15 @@ clang::CodeCompleteOptions getClangCompleteOpts() {
 
 class ReplCompletionConsumer : public CodeCompleteConsumer {
 public:
-  ReplCompletionConsumer(std::vector )
+  ReplCompletionConsumer(std::vector ,
+ ReplCodeCompleter )
   : CodeCompleteConsumer(getClangCompleteOpts()),
 CCAllocator(std::make_shared()),
-CCTUInfo(CCAllocator), Results(Results){};
+CCTUInfo(CCAllocator), Results(Results), CC(CC) {}
 
+  // The entry of handling code completion. When the function is called, we
+  // create a `Context`-based handler (see classes defined below) to handle 
each
+  // completion result.
   void ProcessCodeCompleteResults(class Sema , CodeCompletionContext Context,
   CodeCompletionResult *InResults,
   unsigned NumResults) final;
@@ -56,26 +63,146 @@ class ReplCompletionConsumer : public CodeCompleteConsumer 
{
   std::shared_ptr CCAllocator;
   CodeCompletionTUInfo CCTUInfo;
   std::vector 
+  ReplCodeCompleter 
+};
+
+/// The class CompletionContextHandler contains four interfaces, each of
+/// which handles one type of completion result.
+/// Its derived classes are used to create concrete handlers based on
+/// \c CodeCompletionContext.
+class CompletionContextHandler {
+protected:
+  CodeCompletionContext CCC;
+  std::vector 
+
+private:
+  Sema 
+
+public:
+  CompletionContextHandler(Sema , CodeCompletionContext CCC,
+   std::vector )
+  : CCC(CCC), 

[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-23 Thread Michael Klemm via cfe-commits


@@ -0,0 +1,15 @@
+! UNSUPPORTED: system-windows
+
+! RUN: %clang -o %t.c-object -c %S/Inputs/main_dupes.c

mjklemm wrote:

When I do this, the test goes to "unsupported" for me, as it seems that %cc is 
not set as a substitution in lit.cfg.py.

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-23 Thread Kiran Chandramohan via cfe-commits


@@ -122,6 +122,7 @@
 # the build directory holding that tool.
 tools = [
 ToolSubst("%flang", command=FindTool("flang-new"), unresolved="fatal"),
+ToolSubst("%clang", command=FindTool("clang"), unresolved="fatal"),

kiranchandramohan wrote:

Remove this if using the system compiler works.

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-23 Thread Kiran Chandramohan via cfe-commits


@@ -0,0 +1,15 @@
+! UNSUPPORTED: system-windows
+
+! RUN: %clang -o %t.c-object -c %S/Inputs/main_dupes.c

kiranchandramohan wrote:

You can use %cc for the system-compiler and REQUIRE it to be present for this 
test. 
Reference: 
https://github.com/llvm/llvm-project/blob/main/flang/test/Runtime/no-cpp-dep.c

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


[clang] [clang] Avoid memcopy for small structure with padding under -ftrivial-auto-var-init (PR #71677)

2023-11-23 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

FYI, the following `clang` tests seem to fail after revision 
[fe5c360](https://github.com/llvm/llvm-project/commit/fe5c360a9aae61db37886c0c795c409b5129905f)
```
Failed Tests (2):
  Clang :: CodeGen/aapcs-align.cpp
  Clang :: CodeGen/aapcs64-align.cpp
```

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


[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-11-23 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff e5cc3da6a9077548f613eee3aacc5e7b017c81f3 
3b0090997023b1b6392bc23d386ace7c7cb796ce -- 
flang/test/Driver/Inputs/main_dupes.c clang/lib/Driver/ToolChains/CommonArgs.cpp
``





View the diff from clang-format here.


``diff
diff --git a/flang/test/Driver/Inputs/main_dupes.c 
b/flang/test/Driver/Inputs/main_dupes.c
index baae10f94e..dd318c0816 100644
--- a/flang/test/Driver/Inputs/main_dupes.c
+++ b/flang/test/Driver/Inputs/main_dupes.c
@@ -1,8 +1,8 @@
 #include 
 
-int main(int argc, char * argv[]) {
-// Irrelevant what to do in here.
-// Test is supposed to fail at link time.
-printf("Hello from C [%s]\n", __FUNCTION__);
-return 0;
+int main(int argc, char *argv[]) {
+  // Irrelevant what to do in here.
+  // Test is supposed to fail at link time.
+  printf("Hello from C [%s]\n", __FUNCTION__);
+  return 0;
 }

``




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


[clang] [APINotes] Upstream Driver and Frontend options that enable API Notes (PR #73120)

2023-11-23 Thread Saleem Abdulrasool via cfe-commits

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

Thanks!

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


[clang] [APINotes] Upstream Driver and Frontend options that enable API Notes (PR #73120)

2023-11-23 Thread Egor Zhdan via cfe-commits


@@ -6720,6 +6720,17 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
  options::OPT_fno_assume_sane_operator_new);
 
+  if (Args.hasFlag(options::OPT_fapinotes, options::OPT_fno_apinotes, false) ||
+  Args.hasArg(options::OPT_iapinotes_modules)) {

egorzhdan wrote:

That's a good point, we don't actually need the outer check here. I removed it.

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


  1   2   3   >