[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Vinayak Dev via cfe-commits


@@ -16538,6 +16538,27 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
 }
   }
 
+  // Complain if we are converting a lambda expression to a boolean value
+  if (auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+  if (auto *MRecordDecl = MCallExpr->getRecordDecl()) {
+if (MRecordDecl->isLambda()) {
+  std::string Str;
+  llvm::raw_string_ostream S(Str);
+  const unsigned DiagID = diag::warn_impcast_pointer_to_bool;
+  // For lambdas, the pointer type is function, which corresponds to 1.
+  const unsigned FunctionPointerType = 1;
+  // Pretty print the diagnostic for the warning
+  E->printPretty(S, nullptr, getPrintingPolicy());
+  Diag(E->getExprLoc(), DiagID)
+  << FunctionPointerType << S.str() << E->getSourceRange() << Range
+  << IsEqual;
+  return;

vinayakdsci wrote:

OK, understood. I will make the required changes, and force push again. Thanks 
for the  review!

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-02-28 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

Friendly ping. I'm looking for your feedback before fixing other similar bugs, 
e.g. #82104.

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


[clang] [llvm] [RISCV] Remove experimental from Zacas. (PR #83195)

2024-02-28 Thread Yingwei Zheng via cfe-commits

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

LGTM.

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


[clang-tools-extra] [clang-tidy] Improve `google-explicit-constructor` checks handling of `explicit(bool)` (PR #82689)

2024-02-28 Thread via cfe-commits

https://github.com/AMS21 updated https://github.com/llvm/llvm-project/pull/82689

>From ffde0d326b7ab2c451c9070a894d6c487fe90682 Mon Sep 17 00:00:00 2001
From: AMS21 
Date: Thu, 22 Feb 2024 22:10:09 +0100
Subject: [PATCH] [clang-tidy] Improve `google-explicit-constructor` checks
 handling of `explicit(bool)`

We now treat `explicit(false)` the same way we treat `noexcept(false)` in
the noexcept checks, which is ignoring it.

Also introduced a new warning message if a constructor has an `explicit`
declaration which evaluates to false and no longer emit a faulty FixIt.

Fixes #81121
---
 .../google/ExplicitConstructorCheck.cpp   | 33 ---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ++
 .../google/explicit-constructor-cxx20.cpp | 59 +++
 3 files changed, 88 insertions(+), 8 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/google/explicit-constructor-cxx20.cpp

diff --git a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp 
b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
index 34d49af9f81e23..6f26de9881357f 100644
--- a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
@@ -79,8 +79,10 @@ static bool isStdInitializerList(QualType Type) {
 }
 
 void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
-  constexpr char WarningMessage[] =
+  constexpr char NoExpressionWarningMessage[] =
   "%0 must be marked explicit to avoid unintentional implicit conversions";
+  constexpr char WithExpressionWarningMessage[] =
+  "%0 explicit expression evaluates to 'false'";
 
   if (const auto *Conversion =
   Result.Nodes.getNodeAs("conversion")) {
@@ -91,7 +93,7 @@ void ExplicitConstructorCheck::check(const 
MatchFinder::MatchResult &Result) {
 // gmock to define matchers).
 if (Loc.isMacroID())
   return;
-diag(Loc, WarningMessage)
+diag(Loc, NoExpressionWarningMessage)
 << Conversion << FixItHint::CreateInsertion(Loc, "explicit ");
 return;
   }
@@ -101,9 +103,11 @@ void ExplicitConstructorCheck::check(const 
MatchFinder::MatchResult &Result) {
   Ctor->getMinRequiredArguments() > 1)
 return;
 
+  const ExplicitSpecifier ExplicitSpec = Ctor->getExplicitSpecifier();
+
   bool TakesInitializerList = isStdInitializerList(
   Ctor->getParamDecl(0)->getType().getNonReferenceType());
-  if (Ctor->isExplicit() &&
+  if (ExplicitSpec.isExplicit() &&
   (Ctor->isCopyOrMoveConstructor() || TakesInitializerList)) {
 auto IsKwExplicit = [](const Token &Tok) {
   return Tok.is(tok::raw_identifier) &&
@@ -130,18 +134,31 @@ void ExplicitConstructorCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
 
-  if (Ctor->isExplicit() || Ctor->isCopyOrMoveConstructor() ||
+  if (ExplicitSpec.isExplicit() || Ctor->isCopyOrMoveConstructor() ||
   TakesInitializerList)
 return;
 
-  bool SingleArgument =
+  // Don't complain about explicit(false) or dependent expressions
+  const Expr *ExplicitExpr = ExplicitSpec.getExpr();
+  if (ExplicitExpr) {
+ExplicitExpr = ExplicitExpr->IgnoreImplicit();
+if (isa(ExplicitExpr) ||
+ExplicitExpr->isInstantiationDependent())
+  return;
+  }
+
+  const bool SingleArgument =
   Ctor->getNumParams() == 1 && !Ctor->getParamDecl(0)->isParameterPack();
   SourceLocation Loc = Ctor->getLocation();
-  diag(Loc, WarningMessage)
+  auto Diag =
+  diag(Loc, ExplicitExpr ? WithExpressionWarningMessage
+ : NoExpressionWarningMessage)
   << (SingleArgument
   ? "single-argument constructors"
-  : "constructors that are callable with a single argument")
-  << FixItHint::CreateInsertion(Loc, "explicit ");
+  : "constructors that are callable with a single argument");
+
+  if (!ExplicitExpr)
+Diag << FixItHint::CreateInsertion(Loc, "explicit ");
 }
 
 } // namespace clang::tidy::google
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3f90e7d63d6b23..f2df3d0d737c6b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -151,6 +151,10 @@ Changes in existing checks
   ` check by replacing the local
   option `HeaderFileExtensions` by the global option of the same name.
 
+- Improved :doc:`google-explicit-constructor
+  ` check to better handle
+  ``C++-20`` `explicit(bool)`.
+
 - Improved :doc:`google-global-names-in-headers
   ` check by replacing the 
local
   option `HeaderFileExtensions` by the global option of the same name.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/explicit-constructor-cxx20.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/google/explicit-constructor-cxx20.cpp
new file mode 100644
index 00..e47538babbbc16
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/goog

[clang-tools-extra] [clang-tidy] Improve `google-explicit-constructor` checks handling of `explicit(bool)` (PR #82689)

2024-02-28 Thread via cfe-commits


@@ -79,8 +79,10 @@ static bool isStdInitializerList(QualType Type) {
 }
 
 void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
-  constexpr char WarningMessage[] =
+  constexpr char NoExpressionWarningMessage[] =
   "%0 must be marked explicit to avoid unintentional implicit conversions";
+  constexpr char WithExpressionWarningMessage[] =
+  "%0 explicit expression evaluated to false";

AMS21 wrote:

I agree sound better :)

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


[clang] 49c399c - [clang][Interp] Toplevel destructors may fail

2024-02-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-28T09:48:27+01:00
New Revision: 49c399c2d113df1654b09c9b5afa38924829a8fe

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

LOG: [clang][Interp] Toplevel destructors may fail

We used to run them, but not check if they failed. If they do,
the expression is invalid, even if we already have a result.

I do have a suspicion that we need to manually call destroyLocals()
in more places (everywhere basically?), but I'll wait with that
until I have a reproducer at hand.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/EvaluationResult.h
clang/test/AST/Interp/cxx20.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index f193f959d3a6c0..b151f8d0d7a79c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2587,7 +2587,10 @@ bool ByteCodeExprGen::visitExpr(const Expr *E) {
 
 if (!this->emitFinishInit(E))
   return false;
-return this->emitRetValue(E);
+// We are destroying the locals AFTER the Ret op.
+// The Ret op needs to copy the (alive) values, but the
+// destructors may still turn the entire expression invalid.
+return this->emitRetValue(E) && RootScope.destroyLocals();
   }
 
   return false;
@@ -3414,14 +3417,15 @@ bool 
ByteCodeExprGen::emitRecordDestruction(const Record *R) {
   // Now emit the destructor and recurse into base classes.
   if (const CXXDestructorDecl *Dtor = R->getDestructor();
   Dtor && !Dtor->isTrivial()) {
-if (const Function *DtorFunc = getFunction(Dtor)) {
-  assert(DtorFunc->hasThisPointer());
-  assert(DtorFunc->getNumParams() == 1);
-  if (!this->emitDupPtr(SourceInfo{}))
-return false;
-  if (!this->emitCall(DtorFunc, 0, SourceInfo{}))
-return false;
-}
+const Function *DtorFunc = getFunction(Dtor);
+if (!DtorFunc)
+  return false;
+assert(DtorFunc->hasThisPointer());
+assert(DtorFunc->getNumParams() == 1);
+if (!this->emitDupPtr(SourceInfo{}))
+  return false;
+if (!this->emitCall(DtorFunc, 0, SourceInfo{}))
+  return false;
   }
 
   for (const Record::Base &Base : llvm::reverse(R->bases())) {

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 5b3b533dba3877..acbbcc3dc9619a 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -332,7 +332,7 @@ template  class VariableScope {
   }
 
   virtual void emitDestruction() {}
-  virtual void emitDestructors() {}
+  virtual bool emitDestructors() { return true; }
   VariableScope *getParent() const { return Parent; }
 
 protected:
@@ -356,13 +356,18 @@ template  class LocalScope : public 
VariableScope {
   }
 
   /// Overriden to support explicit destruction.
-  void emitDestruction() override {
+  void emitDestruction() override { destroyLocals(); }
+
+  /// Explicit destruction of local variables.
+  bool destroyLocals() {
 if (!Idx)
-  return;
-this->emitDestructors();
+  return true;
+
+bool Success = this->emitDestructors();
 this->Ctx->emitDestroy(*Idx, SourceInfo{});
 removeStoredOpaqueValues();
 this->Idx = std::nullopt;
+return Success;
   }
 
   void addLocal(const Scope::Local &Local) override {
@@ -374,19 +379,25 @@ template  class LocalScope : public 
VariableScope {
 this->Ctx->Descriptors[*Idx].emplace_back(Local);
   }
 
-  void emitDestructors() override {
+  bool emitDestructors() override {
 if (!Idx)
-  return;
+  return true;
 // Emit destructor calls for local variables of record
 // type with a destructor.
 for (Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
   if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) {
-this->Ctx->emitGetPtrLocal(Local.Offset, SourceInfo{});
-this->Ctx->emitDestruction(Local.Desc);
-this->Ctx->emitPopPtr(SourceInfo{});
+if (!this->Ctx->emitGetPtrLocal(Local.Offset, SourceInfo{}))
+  return false;
+
+if (!this->Ctx->emitDestruction(Local.Desc))
+  return false;
+
+if (!this->Ctx->emitPopPtr(SourceInfo{}))
+  return false;
 removeIfStoredOpaqueValue(Local);
   }
 }
+return true;
   }
 
   void removeStoredOpaqueValues() {

diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index 9cae25f5c4d642..c9c2bf9b145b22 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -38,8 +38,11 @@ EvaluationResult EvalEmitter::interpretExpr(cons

[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Vinayak Dev via cfe-commits

vinayakdsci wrote:

> There are some related test failures caught by precommit CI that need to be 
> addressed.
> 
> The issue in dr18xx.cpp looks to be a case where we should replace `bool b = 
> ` with `auto b = ` (it doesn't change the testing for what's discussed in 
> http://wg21.link/cwg1837).

Changing `bool b = ` to `auto b =` does not compile, as the compiler complains 
that `auto` is not allowed in non-static struct members. `b` cannot be declared 
as `static` either, which would cause an invalid use of `this` outside of a 
non-static member function. It looks like type deduction using auto for member 
variables is not allowed.

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


[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Vinayak Dev via cfe-commits


@@ -16538,6 +16538,27 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
 }
   }
 
+  // Complain if we are converting a lambda expression to a boolean value
+  if (auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+  if (auto *MRecordDecl = MCallExpr->getRecordDecl()) {
+if (MRecordDecl->isLambda()) {
+  std::string Str;
+  llvm::raw_string_ostream S(Str);
+  const unsigned DiagID = diag::warn_impcast_pointer_to_bool;
+  // For lambdas, the pointer type is function, which corresponds to 1.
+  const unsigned FunctionPointerType = 1;
+  // Pretty print the diagnostic for the warning
+  E->printPretty(S, nullptr, getPrintingPolicy());
+  Diag(E->getExprLoc(), DiagID)
+  << FunctionPointerType << S.str() << E->getSourceRange() << Range
+  << IsEqual;
+  return;

vinayakdsci wrote:

Removing the call to `printPretty` will not populate `S`, so the diagnostic 
will not have the name for the identifier describing the error-causing function 
but instead display `' '`. Is there a workaround for this? Or should I leave it 
be? Thanks!

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


[clang] 9f99eda - [clang][Interp][NFC] Convert test to verify=expected,both style

2024-02-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-28T09:53:44+01:00
New Revision: 9f99eda1208787364b1a381b2d4e146fc4868cd5

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

LOG: [clang][Interp][NFC] Convert test to verify=expected,both style

Added: 


Modified: 
clang/test/AST/Interp/cxx20.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index b24b0c8a3ba0ec..2c28e53784c5c6 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -58,13 +58,10 @@ static_assert(pointerAssign2() == 12, "");
 
 constexpr int unInitLocal() {
   int a;
-  return a; // ref-note {{read of uninitialized object}} \
-// expected-note {{read of uninitialized object}}
+  return a; // both-note {{read of uninitialized object}}
 }
-static_assert(unInitLocal() == 0, ""); // ref-error {{not an integral constant 
expression}} \
-   // ref-note {{in call to 
'unInitLocal()'}} \
-   // expected-error {{not an integral 
constant expression}} \
-   // expected-note {{in call to 
'unInitLocal()'}} \
+static_assert(unInitLocal() == 0, ""); // both-error {{not an integral 
constant expression}} \
+   // both-note {{in call to 
'unInitLocal()'}}
 
 constexpr int initializedLocal() {
   int a;
@@ -75,25 +72,19 @@ static_assert(initializedLocal() == 20);
 
 constexpr int initializedLocal2() {
   int a[2];
-  return *a; // expected-note {{read of uninitialized object is not allowed in 
a constant expression}} \
- // ref-note {{read of uninitialized object is not allowed in a 
constant expression}}
+  return *a; // both-note {{read of uninitialized object is not allowed in a 
constant expression}}
 }
-static_assert(initializedLocal2() == 20); // expected-error {{not an integral 
constant expression}} \
-  // expected-note {{in call to}} \
-  // ref-error {{not an integral 
constant expression}} \
-  // ref-note {{in call to}}
+static_assert(initializedLocal2() == 20); // both-error {{not an integral 
constant expression}} \
+  // both-note {{in call to}}
 
 
 struct Int { int a; };
 constexpr int initializedLocal3() {
   Int i;
-  return i.a; // ref-note {{read of uninitialized object is not allowed in a 
constant expression}} \
-  // expected-note {{read of uninitialized object}}
+  return i.a; // both-note {{read of uninitialized object is not allowed in a 
constant expression}}
 }
-static_assert(initializedLocal3() == 20); // expected-error {{not an integral 
constant expression}} \
-  // expected-note {{in call to}} \
-  // ref-error {{not an integral 
constant expression}} \
-  // ref-note {{in call to}}
+static_assert(initializedLocal3() == 20); // both-error {{not an integral 
constant expression}} \
+  // both-note {{in call to}}
 
 
 
@@ -137,22 +128,16 @@ static_assert(!b4); // ref-error {{not an integral 
constant expression}} \
 namespace UninitializedFields {
   class A {
   public:
-int a; // expected-note 4{{subobject declared here}} \
-   // ref-note 4{{subobject declared here}}
+int a; // both-note 4{{subobject declared here}}
 constexpr A() {}
   };
-  constexpr A a; // expected-error {{must be initialized by a constant 
expression}} \
- // expected-note {{subobject 'a' is not initialized}} \
- // ref-error {{must be initialized by a constant expression}} 
\
- // ref-note {{subobject 'a' is not initialized}}
-  constexpr A aarr[2]; // expected-error {{must be initialized by a constant 
expression}} \
-   // expected-note {{subobject 'a' is not initialized}} \
-   // ref-error {{must be initialized by a constant 
expression}} \
-   // ref-note {{subobject 'a' is not initialized}}
+  constexpr A a; // both-error {{must be initialized by a constant 
expression}} \
+ // both-note {{subobject 'a' is not initialized}}
+  constexpr A aarr[2]; // both-error {{must be initialized by a constant 
expression}} \
+   // both-note {{subobject 'a' is not initialized}}
   class F {
 public:
-  int f; // expected-note 3{{subobject declared here}} \
- // ref-note 3{{subobject declared here}}
+  int f; // both-note 3{{subobject declared here}}
 
   constexpr F() {}
   constexpr F

[clang] [clang] Better bitfield access units (PR #65742)

2024-02-28 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 8cfb71613c452dd45a84a74affe8464bfd33de02 
b4cb8945224633fef27b69f0eed34f505032f76e -- 
clang/test/CodeGen/aapcs-bitfield-access-unit.c 
clang/test/CodeGen/bitfield-access-pad.c 
clang/test/CodeGen/bitfield-access-unit.c 
clang/test/CodeGenCXX/bitfield-access-empty.cpp 
clang/test/CodeGenCXX/bitfield-access-tail.cpp 
clang/test/CodeGenCXX/bitfield-ir.cpp clang/include/clang/Basic/TargetInfo.h 
clang/lib/Basic/TargetInfo.cpp clang/lib/Basic/Targets/AArch64.cpp 
clang/lib/Basic/Targets/AArch64.h clang/lib/Basic/Targets/ARM.cpp 
clang/lib/Basic/Targets/ARM.h clang/lib/Basic/Targets/LoongArch.cpp 
clang/lib/Basic/Targets/LoongArch.h clang/lib/Basic/Targets/Mips.h 
clang/lib/Basic/Targets/PPC.h clang/lib/Basic/Targets/SystemZ.h 
clang/lib/Basic/Targets/VE.h clang/lib/Basic/Targets/WebAssembly.h 
clang/lib/Basic/Targets/X86.h clang/lib/CodeGen/CGRecordLayoutBuilder.cpp 
clang/test/CodeGen/aapcs-bitfield.c clang/test/CodeGen/arm-bitfield-alignment.c 
clang/test/CodeGen/arm64-be-bitfield.c clang/test/CodeGen/bitfield-2.c 
clang/test/CodeGen/debug-info-bitfield-0-struct.c 
clang/test/CodeGen/no-bitfield-type-align.c 
clang/test/CodeGen/struct-x86-darwin.c clang/test/CodeGenCXX/bitfield.cpp 
clang/test/OpenMP/atomic_capture_codegen.cpp 
clang/test/OpenMP/atomic_read_codegen.c 
clang/test/OpenMP/atomic_update_codegen.cpp 
clang/test/OpenMP/atomic_write_codegen.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index aab571e1d2..c046cab93d 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -863,9 +863,7 @@ public:
 
   /// Return true, iff unaligned accesses are a single instruction (rather than
   /// a synthesized sequence).
-  bool hasUnalignedAccess() const {
-return HasUnalignedAccess;
-  }
+  bool hasUnalignedAccess() const { return HasUnalignedAccess; }
 
   /// \brief Returns the default value of the __USER_LABEL_PREFIX__ macro,
   /// which is the prefix given to user symbols by default.

``




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


[clang] [clang] Better bitfield access units (PR #65742)

2024-02-28 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

> > 
> 
> Thinking further, several (AArch64, ARM & Loongson) targets have a 
> 'HasUnaligned' bool in their TargetInfo objects. Perhaps the way forwards is 
> to promote that to the base TargetInfo and just use that, rather than the 
> bitfield-specific field I added (which just duplicates that functionality on 
> those targets)?

I've added such a change.  The AArch64 & ARM targets record this information to 
determine whether a `__ARM_FEATURE_UNALIGNED` macro should be defined.  The 
Loongson target just needs to check the `-ual` target feature.


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


[clang] [OpenCL] Fix BIenqueue_kernel fallthrough (PR #83238)

2024-02-28 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh created 
https://github.com/llvm/llvm-project/pull/83238

Handling of the `BIenqueue_kernel` builtin must not fallthrough to the 
`BIget_kernel_work_group_size` builtin, as these builtins have no common 
functionality.

>From a7375b651a2ec392e0edf4cbe3658981f56ea67a Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Wed, 28 Feb 2024 08:37:22 +
Subject: [PATCH] [OpenCL] Fix BIenqueue_kernel fallthrough

Handling of the `BIenqueue_kernel` builtin must not fallthrough to
the `BIget_kernel_work_group_size` builtin, as these builtins have
no common functionality.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2d16e7cdc06053..7a42174d7ec692 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5640,7 +5640,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 EmitLifetimeEnd(TmpSize, TmpPtr);
   return Call;
 }
-[[fallthrough]];
+llvm_unreachable("Unexpected enqueue_kernel signature");
   }
   // OpenCL v2.0 s6.13.17.6 - Kernel query functions need bitcast of block
   // parameter.

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


[clang] [OpenCL] Fix BIenqueue_kernel fallthrough (PR #83238)

2024-02-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Sven van Haastregt (svenvh)


Changes

Handling of the `BIenqueue_kernel` builtin must not fallthrough to the 
`BIget_kernel_work_group_size` builtin, as these builtins have no common 
functionality.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2d16e7cdc06053..7a42174d7ec692 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5640,7 +5640,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 EmitLifetimeEnd(TmpSize, TmpPtr);
   return Call;
 }
-[[fallthrough]];
+llvm_unreachable("Unexpected enqueue_kernel signature");
   }
   // OpenCL v2.0 s6.13.17.6 - Kernel query functions need bitcast of block
   // parameter.

``




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


[clang] [alpha.webkit.UncountedLocalVarsChecker] Allow uncounted object references within trivial statements (PR #82229)

2024-02-28 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/82229

>From 099640652b62c52160b12542a16eb66da90cfc93 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Mon, 19 Feb 2024 01:07:13 -0800
Subject: [PATCH 1/2] [alpha.webkit.UncountedLocalVarsChecker] Allow uncounted
 object references within trivial statements

This PR makes alpha.webkit.UncountedLocalVarsChecker ignore raw references and 
pointers to
a ref counted type which appears within "trival" statements. To do this, this 
PR extends
TrivialFunctionAnalysis so that it can also analyze "triviality" of statements 
as well as
that of functions Each Visit* function is now augmented with withCachedResult, 
which is
responsible for looking up and updating the cache for each Visit* functions.

As this PR dramatically improves the false positive rate of the checker, it 
also deletes
the code to ignore raw pointers and references within if and for statements.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 221 --
 .../Checkers/WebKit/PtrTypesSemantics.h   |  21 +-
 .../WebKit/UncountedLocalVarsChecker.cpp  |  69 +++---
 .../Analysis/Checkers/WebKit/mock-types.h |   2 +
 .../Checkers/WebKit/uncounted-local-vars.cpp  |  92 +++-
 5 files changed, 286 insertions(+), 119 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index a7891d2da07c18..cb89ce59a60878 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -244,18 +244,41 @@ class TrivialFunctionAnalysisVisitor
 
   // Returns false if at least one child is non-trivial.
   bool VisitChildren(const Stmt *S) {
-for (const Stmt *Child : S->children()) {
-  if (Child && !Visit(Child))
+return withCachedResult(S, [&]() {
+  for (const Stmt *Child : S->children()) {
+if (Child && !Visit(Child))
+  return false;
+  }
+  return true;
+});
+  }
+
+  bool VisitSubExpr(const Expr *Parent, const Expr *E) {
+return withCachedResult(Parent, [&]() {
+  if (!Visit(E))
 return false;
-}
+  return true;
+});
+  }
 
-return true;
+  template 
+  bool withCachedResult(const StmtType *S, CheckFunction Function) {
+// Insert false to the cache first to avoid infinite recursion.
+auto [It, IsNew] = StatementCache.insert(std::make_pair(S, false));
+if (!IsNew)
+  return It->second;
+bool Result = Function();
+It->second = Result;
+return Result;
   }
 
 public:
-  using CacheTy = TrivialFunctionAnalysis::CacheTy;
+  using FunctionCacheTy = TrivialFunctionAnalysis::FunctionCacheTy;
+  using StatementCacheTy = TrivialFunctionAnalysis::StatementCacheTy;
 
-  TrivialFunctionAnalysisVisitor(CacheTy &Cache) : Cache(Cache) {}
+  TrivialFunctionAnalysisVisitor(FunctionCacheTy &FunctionCache,
+ StatementCacheTy &StatementCache)
+  : FunctionCache(FunctionCache), StatementCache(StatementCache) {}
 
   bool VisitStmt(const Stmt *S) {
 // All statements are non-trivial unless overriden later.
@@ -271,13 +294,21 @@ class TrivialFunctionAnalysisVisitor
 
   bool VisitReturnStmt(const ReturnStmt *RS) {
 // A return statement is allowed as long as the return value is trivial.
-if (auto *RV = RS->getRetValue())
-  return Visit(RV);
-return true;
+return withCachedResult(RS, [&]() {
+  if (auto *RV = RS->getRetValue())
+return Visit(RV);
+  return true;
+});
+  }
+
+  bool VisitCXXForRangeStmt(const CXXForRangeStmt *FS) {
+return VisitChildren(FS);
   }
 
   bool VisitDeclStmt(const DeclStmt *DS) { return VisitChildren(DS); }
   bool VisitDoStmt(const DoStmt *DS) { return VisitChildren(DS); }
+  bool VisitForStmt(const ForStmt *FS) { return VisitChildren(FS); }
+  bool VisitWhileStmt(const WhileStmt *WS) { return VisitChildren(WS); }
   bool VisitIfStmt(const IfStmt *IS) { return VisitChildren(IS); }
   bool VisitSwitchStmt(const SwitchStmt *SS) { return VisitChildren(SS); }
   bool VisitCaseStmt(const CaseStmt *CS) { return VisitChildren(CS); }
@@ -285,17 +316,26 @@ class TrivialFunctionAnalysisVisitor
 
   bool VisitUnaryOperator(const UnaryOperator *UO) {
 // Operator '*' and '!' are allowed as long as the operand is trivial.
-if (UO->getOpcode() == UO_Deref || UO->getOpcode() == UO_AddrOf ||
-UO->getOpcode() == UO_LNot)
-  return Visit(UO->getSubExpr());
-
-// Other operators are non-trivial.
-return false;
+return withCachedResult(UO, [&]() {
+  auto op = UO->getOpcode();
+  if (op == UO_Deref || op == UO_AddrOf || op == UO_LNot)
+return Visit(UO->getSubExpr());
+  if (UO->isIncrementOp() || UO->isDecrementOp()) {
+if (auto *RefExpr = dyn_cast(UO->getSubExpr())) {
+  if (auto *Decl = dyn_cast(RefExpr->getDecl()))
+return Decl->i

[clang] [Driver] Unify InstalledDir and Dir (PR #80527)

2024-02-28 Thread Martin Storsjö via cfe-commits

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

If nobody else wants to chime in here, I guess I'll go ahead and approve it. 
LGTM!

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


[clang] [-Wunsafe-buffer-usage][NFC] clang-format UnsafeBufferUsage.cpp (PR #82027)

2024-02-28 Thread via cfe-commits

https://github.com/jkorous-apple updated 
https://github.com/llvm/llvm-project/pull/82027

>From 2a068ce8dd6c54814a45151759e34f8e56181649 Mon Sep 17 00:00:00 2001
From: Jan Korous 
Date: Fri, 16 Feb 2024 10:51:00 -0800
Subject: [PATCH 1/2] [-Wunsafe-buffer-usage][NFC] clang-format
 UnsafeBufferUsage.cpp

---
 clang/lib/Analysis/UnsafeBufferUsage.cpp | 265 +++
 1 file changed, 132 insertions(+), 133 deletions(-)

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 769c6d9ebefaa5..50f5d9fb2ba29d 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -130,42 +130,42 @@ class MatchDescendantVisitor
 
   bool TraverseGenericSelectionExpr(GenericSelectionExpr *Node) {
 // These are unevaluated, except the result expression.
-if(ignoreUnevaluatedContext)
+if (ignoreUnevaluatedContext)
   return TraverseStmt(Node->getResultExpr());
 return VisitorBase::TraverseGenericSelectionExpr(Node);
   }
 
   bool TraverseUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node) {
 // Unevaluated context.
-if(ignoreUnevaluatedContext)
+if (ignoreUnevaluatedContext)
   return true;
 return VisitorBase::TraverseUnaryExprOrTypeTraitExpr(Node);
   }
 
   bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc Node) {
 // Unevaluated context.
-if(ignoreUnevaluatedContext)
+if (ignoreUnevaluatedContext)
   return true;
 return VisitorBase::TraverseTypeOfExprTypeLoc(Node);
   }
 
   bool TraverseDecltypeTypeLoc(DecltypeTypeLoc Node) {
 // Unevaluated context.
-if(ignoreUnevaluatedContext)
+if (ignoreUnevaluatedContext)
   return true;
 return VisitorBase::TraverseDecltypeTypeLoc(Node);
   }
 
   bool TraverseCXXNoexceptExpr(CXXNoexceptExpr *Node) {
 // Unevaluated context.
-if(ignoreUnevaluatedContext)
+if (ignoreUnevaluatedContext)
   return true;
 return VisitorBase::TraverseCXXNoexceptExpr(Node);
   }
 
   bool TraverseCXXTypeidExpr(CXXTypeidExpr *Node) {
 // Unevaluated context.
-if(ignoreUnevaluatedContext)
+if (ignoreUnevaluatedContext)
   return true;
 return VisitorBase::TraverseCXXTypeidExpr(Node);
   }
@@ -213,24 +213,26 @@ class MatchDescendantVisitor
 
 // Because we're dealing with raw pointers, let's define what we mean by that.
 static auto hasPointerType() {
-return hasType(hasCanonicalType(pointerType()));
+  return hasType(hasCanonicalType(pointerType()));
 }
 
-static auto hasArrayType() {
-return hasType(hasCanonicalType(arrayType()));
-}
+static auto hasArrayType() { return hasType(hasCanonicalType(arrayType())); }
 
-AST_MATCHER_P(Stmt, forEachDescendantEvaluatedStmt, internal::Matcher, 
innerMatcher) {
+AST_MATCHER_P(Stmt, forEachDescendantEvaluatedStmt, internal::Matcher,
+  innerMatcher) {
   const DynTypedMatcher &DTM = static_cast(innerMatcher);
 
-  MatchDescendantVisitor Visitor(&DTM, Finder, Builder, 
ASTMatchFinder::BK_All, true);
+  MatchDescendantVisitor Visitor(&DTM, Finder, Builder, ASTMatchFinder::BK_All,
+ true);
   return Visitor.findMatch(DynTypedNode::create(Node));
 }
 
-AST_MATCHER_P(Stmt, forEachDescendantStmt, internal::Matcher, 
innerMatcher) {
+AST_MATCHER_P(Stmt, forEachDescendantStmt, internal::Matcher,
+  innerMatcher) {
   const DynTypedMatcher &DTM = static_cast(innerMatcher);
 
-  MatchDescendantVisitor Visitor(&DTM, Finder, Builder, 
ASTMatchFinder::BK_All, false);
+  MatchDescendantVisitor Visitor(&DTM, Finder, Builder, ASTMatchFinder::BK_All,
+ false);
   return Visitor.findMatch(DynTypedNode::create(Node));
 }
 
@@ -268,10 +270,9 @@ static auto 
isInUnspecifiedLvalueContext(internal::Matcher innerMatcher) {
 hasLHS(innerMatcher)
   )
 ));
-// clang-format on
+  // clang-format on
 }
 
-
 // Returns a matcher that matches any expression `e` such that `InnerMatcher`
 // matches `e` and `e` is in an Unspecified Pointer Context (UPC).
 static internal::Matcher
@@ -315,7 +316,7 @@ isInUnspecifiedPointerContext(internal::Matcher 
InnerMatcher) {
   // clang-format on
 
   return stmt(anyOf(CallArgMatcher, CastOperandMatcher, CompOperandMatcher,
-   PtrSubtractionMatcher));
+PtrSubtractionMatcher));
   // FIXME: any more cases? (UPC excludes the RHS of an assignment.  For now we
   // don't have to check that.)
 }
@@ -481,7 +482,9 @@ class Gadget {
 #ifndef NDEBUG
   StringRef getDebugName() const {
 switch (K) {
-#define GADGET(x) case Kind::x: return #x;
+#define GADGET(x)  
\
+  case Kind::x:
\
+return #x;
 #include "clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def"
 }
 llvm_unreachable("Unhandled Gadget::Kind enum");
@@ -502,7 +505,6 @@ class Gadget {
   Kind K;
 }

[clang] [clang][analyzer] StreamChecker: Model getc, vfscanf, putc, vfprintf (PR #82476)

2024-02-28 Thread Alejandro Álvarez Ayllón via cfe-commits

https://github.com/alejandro-alvarez-sonarsource updated 
https://github.com/llvm/llvm-project/pull/82476

From a886005893585ce060415619e1fa6164ba4e1729 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 
Date: Tue, 14 Nov 2023 09:28:45 +0100
Subject: [PATCH 01/11] [clang][analyzer] StreamChecker: add more APIs,
 invalidate fscanf args

1. Model getc, vfscanf, putc, vfprintf.
2. fscanf invalidates all arguments after the format string.
---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp |  37 -
 ...ystem-header-simulator-for-simple-stream.h |   2 +-
 .../system-header-simulator-for-valist.h  |   4 +
 .../Analysis/Inputs/system-header-simulator.h |   3 +
 clang/test/Analysis/stream.c  | 128 ++
 5 files changed, 172 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 65bdc4cac30940..247d612989fd87 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -172,7 +172,7 @@ using FnCheck = std::function;
 
 using ArgNoTy = unsigned int;
-static const ArgNoTy ArgNone = std::numeric_limits::max();
+const ArgNoTy ArgNone = std::numeric_limits::max();
 
 struct FnDescription {
   FnCheck PreFn;
@@ -180,6 +180,26 @@ struct FnDescription {
   ArgNoTy StreamArgNo;
 };
 
+[[nodiscard]] ProgramStateRef
+escapeArgsAfterIndex(ProgramStateRef State, CheckerContext &C,
+ const CallEvent &Call, unsigned FirstEscapingArgIndex) {
+  const auto *CE = Call.getOriginExpr();
+  assert(CE);
+
+  if (Call.getNumArgs() <= FirstEscapingArgIndex)
+return State;
+
+  SmallVector EscapingArgs;
+  EscapingArgs.reserve(Call.getNumArgs() - FirstEscapingArgIndex);
+  for (auto EscArgIdx :
+   llvm::seq(FirstEscapingArgIndex, Call.getNumArgs()))
+EscapingArgs.push_back(Call.getArgSVal(EscArgIdx));
+  State = State->invalidateRegions(EscapingArgs, CE, C.blockCount(),
+   C.getLocationContext(),
+   /*CausesPointerEscape=*/false);
+  return State;
+}
+
 /// Get the value of the stream argument out of the passed call event.
 /// The call should contain a function that is described by Desc.
 SVal getStreamArg(const FnDescription *Desc, const CallEvent &Call) {
@@ -397,6 +417,18 @@ class StreamChecker : public Checker FnTestDescriptions = {
@@ -1021,6 +1053,9 @@ void StreamChecker::evalFscanf(const FnDescription *Desc, 
const CallEvent &Call,
   if (!E.Init(Desc, Call, C, State))
 return;
 
+  // The pointers passed to fscanf escape and get invalidated.
+  State = escapeArgsAfterIndex(State, C, Call, /*FirstEscapingArgIndex=*/2);
+
   // Add the success state.
   // In this context "success" means there is not an EOF or other read error
   // before any item is matched in 'fscanf'. But there may be match failure,
diff --git 
a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h 
b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
index 098a2208fecbe9..c26d3582149120 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
@@ -5,7 +5,7 @@
 // suppressed.
 #pragma clang system_header
 
-typedef struct __sFILE {
+typedef struct _FILE {
   unsigned char *_p;
 } FILE;
 FILE *fopen(const char *restrict, const char *restrict) __asm("_" "fopen" );
diff --git a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h 
b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
index 7299b61353d460..87688bd8b312f4 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
@@ -10,6 +10,8 @@
 #define restrict /*restrict*/
 #endif
 
+typedef struct _FILE FILE;
+
 typedef __builtin_va_list va_list;
 
 #define va_start(ap, param) __builtin_va_start(ap, param)
@@ -21,6 +23,8 @@ int vprintf (const char *restrict format, va_list arg);
 
 int vsprintf (char *restrict s, const char *restrict format, va_list arg);
 
+int vfscanf(FILE *stream, const char *format, va_list ap);
+
 int some_library_function(int n, va_list arg);
 
 // No warning from system header.
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index 15986984802c0e..8fd51449ecc0a4 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -73,6 +73,9 @@ int ferror(FILE *stream);
 int fileno(FILE *stream);
 int fflush(FILE *stream);
 
+
+int getc(FILE *stream);
+
 size_t strlen(const char *);
 
 char *strcpy(char *restrict, const char *restrict);
diff --git a/clang/test/Analysis/stream.c b/clang/test/Analysis/stream.c
index 378c9154f8f6a8..d0fee68d482e7f 100644
--- a/clang/test/Analysis/

[clang] [clang][analyzer] StreamChecker: Model getc, vfscanf, putc, vfprintf (PR #82476)

2024-02-28 Thread Alejandro Álvarez Ayllón via cfe-commits

alejandro-alvarez-sonarsource wrote:

Rebased on top of main to solve a conflict.

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


[clang] 3fa9102 - [-Wunsafe-buffer-usage][NFC] clang-format UnsafeBufferUsage.cpp (#82027)

2024-02-28 Thread via cfe-commits

Author: jkorous-apple
Date: 2024-02-28T02:05:20-08:00
New Revision: 3fa91021257ec89ccbfa8aae80312700c2de9d11

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

LOG: [-Wunsafe-buffer-usage][NFC] clang-format UnsafeBufferUsage.cpp (#82027)

Added: 


Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 701f1ac852c256..e1ff0d92f6b2f8 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -130,42 +130,42 @@ class MatchDescendantVisitor
 
   bool TraverseGenericSelectionExpr(GenericSelectionExpr *Node) {
 // These are unevaluated, except the result expression.
-if(ignoreUnevaluatedContext)
+if (ignoreUnevaluatedContext)
   return TraverseStmt(Node->getResultExpr());
 return VisitorBase::TraverseGenericSelectionExpr(Node);
   }
 
   bool TraverseUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node) {
 // Unevaluated context.
-if(ignoreUnevaluatedContext)
+if (ignoreUnevaluatedContext)
   return true;
 return VisitorBase::TraverseUnaryExprOrTypeTraitExpr(Node);
   }
 
   bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc Node) {
 // Unevaluated context.
-if(ignoreUnevaluatedContext)
+if (ignoreUnevaluatedContext)
   return true;
 return VisitorBase::TraverseTypeOfExprTypeLoc(Node);
   }
 
   bool TraverseDecltypeTypeLoc(DecltypeTypeLoc Node) {
 // Unevaluated context.
-if(ignoreUnevaluatedContext)
+if (ignoreUnevaluatedContext)
   return true;
 return VisitorBase::TraverseDecltypeTypeLoc(Node);
   }
 
   bool TraverseCXXNoexceptExpr(CXXNoexceptExpr *Node) {
 // Unevaluated context.
-if(ignoreUnevaluatedContext)
+if (ignoreUnevaluatedContext)
   return true;
 return VisitorBase::TraverseCXXNoexceptExpr(Node);
   }
 
   bool TraverseCXXTypeidExpr(CXXTypeidExpr *Node) {
 // Unevaluated context.
-if(ignoreUnevaluatedContext)
+if (ignoreUnevaluatedContext)
   return true;
 return VisitorBase::TraverseCXXTypeidExpr(Node);
   }
@@ -213,24 +213,26 @@ class MatchDescendantVisitor
 
 // Because we're dealing with raw pointers, let's define what we mean by that.
 static auto hasPointerType() {
-return hasType(hasCanonicalType(pointerType()));
+  return hasType(hasCanonicalType(pointerType()));
 }
 
-static auto hasArrayType() {
-return hasType(hasCanonicalType(arrayType()));
-}
+static auto hasArrayType() { return hasType(hasCanonicalType(arrayType())); }
 
-AST_MATCHER_P(Stmt, forEachDescendantEvaluatedStmt, internal::Matcher, 
innerMatcher) {
+AST_MATCHER_P(Stmt, forEachDescendantEvaluatedStmt, internal::Matcher,
+  innerMatcher) {
   const DynTypedMatcher &DTM = static_cast(innerMatcher);
 
-  MatchDescendantVisitor Visitor(&DTM, Finder, Builder, 
ASTMatchFinder::BK_All, true);
+  MatchDescendantVisitor Visitor(&DTM, Finder, Builder, ASTMatchFinder::BK_All,
+ true);
   return Visitor.findMatch(DynTypedNode::create(Node));
 }
 
-AST_MATCHER_P(Stmt, forEachDescendantStmt, internal::Matcher, 
innerMatcher) {
+AST_MATCHER_P(Stmt, forEachDescendantStmt, internal::Matcher,
+  innerMatcher) {
   const DynTypedMatcher &DTM = static_cast(innerMatcher);
 
-  MatchDescendantVisitor Visitor(&DTM, Finder, Builder, 
ASTMatchFinder::BK_All, false);
+  MatchDescendantVisitor Visitor(&DTM, Finder, Builder, ASTMatchFinder::BK_All,
+ false);
   return Visitor.findMatch(DynTypedNode::create(Node));
 }
 
@@ -268,10 +270,9 @@ static auto 
isInUnspecifiedLvalueContext(internal::Matcher innerMatcher) {
 hasLHS(innerMatcher)
   )
 ));
-// clang-format on
+  // clang-format on
 }
 
-
 // Returns a matcher that matches any expression `e` such that `InnerMatcher`
 // matches `e` and `e` is in an Unspecified Pointer Context (UPC).
 static internal::Matcher
@@ -315,7 +316,7 @@ isInUnspecifiedPointerContext(internal::Matcher 
InnerMatcher) {
   // clang-format on
 
   return stmt(anyOf(CallArgMatcher, CastOperandMatcher, CompOperandMatcher,
-   PtrSubtractionMatcher));
+PtrSubtractionMatcher));
   // FIXME: any more cases? (UPC excludes the RHS of an assignment.  For now we
   // don't have to check that.)
 }
@@ -481,7 +482,9 @@ class Gadget {
 #ifndef NDEBUG
   StringRef getDebugName() const {
 switch (K) {
-#define GADGET(x) case Kind::x: return #x;
+#define GADGET(x)  
\
+  case Kind::x:
\
+return #x;
 #include "clang/Analysis/Analyses/UnsafeBufferUsageGadgets.de

[clang] [-Wunsafe-buffer-usage][NFC] clang-format UnsafeBufferUsage.cpp (PR #82027)

2024-02-28 Thread via cfe-commits

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


[clang] [clang-repl] Expose RuntimeInterfaceBuilder to allow customization (PR #83126)

2024-02-28 Thread Stefan Gränitz via cfe-commits

https://github.com/weliveindetail updated 
https://github.com/llvm/llvm-project/pull/83126

From 3a6fdd006f00b0530e7fe6ead1fcd2765c1bfe07 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= 
Date: Mon, 26 Feb 2024 19:12:41 +0100
Subject: [PATCH 1/4] [clang-repl] Split out TypeVisitor from
 RuntimeInterfaceBuilder

---
 clang/lib/Interpreter/Interpreter.cpp | 171 ++
 1 file changed, 92 insertions(+), 79 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 9f97a3c6b0be9e..7afe55bbb266a3 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -541,21 +541,104 @@ bool Interpreter::FindRuntimeInterface() {
 
 namespace {
 
-class RuntimeInterfaceBuilder
-: public TypeVisitor {
-  clang::Interpreter &Interp;
+class InterfaceKindVisitor
+: public TypeVisitor {
+  friend class RuntimeInterfaceBuilder;
+
   ASTContext &Ctx;
   Sema &S;
   Expr *E;
   llvm::SmallVector Args;
 
+public:
+  InterfaceKindVisitor(ASTContext &Ctx, Sema &S, Expr *E)
+  : Ctx(Ctx), S(S), E(E) {}
+
+  Interpreter::InterfaceKind VisitRecordType(const RecordType *Ty) {
+return Interpreter::InterfaceKind::WithAlloc;
+  }
+
+  Interpreter::InterfaceKind
+  VisitMemberPointerType(const MemberPointerType *Ty) {
+return Interpreter::InterfaceKind::WithAlloc;
+  }
+
+  Interpreter::InterfaceKind
+  VisitConstantArrayType(const ConstantArrayType *Ty) {
+return Interpreter::InterfaceKind::CopyArray;
+  }
+
+  Interpreter::InterfaceKind
+  VisitFunctionProtoType(const FunctionProtoType *Ty) {
+HandlePtrType(Ty);
+return Interpreter::InterfaceKind::NoAlloc;
+  }
+
+  Interpreter::InterfaceKind VisitPointerType(const PointerType *Ty) {
+HandlePtrType(Ty);
+return Interpreter::InterfaceKind::NoAlloc;
+  }
+
+  Interpreter::InterfaceKind VisitReferenceType(const ReferenceType *Ty) {
+ExprResult AddrOfE = S.CreateBuiltinUnaryOp(SourceLocation(), UO_AddrOf, 
E);
+assert(!AddrOfE.isInvalid() && "Can not create unary expression");
+Args.push_back(AddrOfE.get());
+return Interpreter::InterfaceKind::NoAlloc;
+  }
+
+  Interpreter::InterfaceKind VisitBuiltinType(const BuiltinType *Ty) {
+if (Ty->isNullPtrType())
+  Args.push_back(E);
+else if (Ty->isFloatingType())
+  Args.push_back(E);
+else if (Ty->isIntegralOrEnumerationType())
+  HandleIntegralOrEnumType(Ty);
+else if (Ty->isVoidType()) {
+  // Do we need to still run `E`?
+}
+
+return Interpreter::InterfaceKind::NoAlloc;
+  }
+
+  Interpreter::InterfaceKind VisitEnumType(const EnumType *Ty) {
+HandleIntegralOrEnumType(Ty);
+return Interpreter::InterfaceKind::NoAlloc;
+  }
+
+private:
+  // Force cast these types to uint64 to reduce the number of overloads of
+  // `__clang_Interpreter_SetValueNoAlloc`.
+  void HandleIntegralOrEnumType(const Type *Ty) {
+TypeSourceInfo *TSI = Ctx.getTrivialTypeSourceInfo(Ctx.UnsignedLongLongTy);
+ExprResult CastedExpr =
+S.BuildCStyleCastExpr(SourceLocation(), TSI, SourceLocation(), E);
+assert(!CastedExpr.isInvalid() && "Cannot create cstyle cast expr");
+Args.push_back(CastedExpr.get());
+  }
+
+  void HandlePtrType(const Type *Ty) {
+TypeSourceInfo *TSI = Ctx.getTrivialTypeSourceInfo(Ctx.VoidPtrTy);
+ExprResult CastedExpr =
+S.BuildCStyleCastExpr(SourceLocation(), TSI, SourceLocation(), E);
+assert(!CastedExpr.isInvalid() && "Can not create cstyle cast expression");
+Args.push_back(CastedExpr.get());
+  }
+};
+
+class RuntimeInterfaceBuilder {
+  clang::Interpreter &Interp;
+  ASTContext &Ctx;
+  Sema &S;
+  Expr *E;
+  InterfaceKindVisitor Visitor;
+
 public:
   RuntimeInterfaceBuilder(clang::Interpreter &In, ASTContext &C, Sema &SemaRef,
   Expr *VE, ArrayRef FixedArgs)
-  : Interp(In), Ctx(C), S(SemaRef), E(VE) {
+  : Interp(In), Ctx(C), S(SemaRef), E(VE), Visitor(C, SemaRef, VE) {
 // The Interpreter* parameter and the out parameter `OutVal`.
 for (Expr *E : FixedArgs)
-  Args.push_back(E);
+  Visitor.Args.push_back(E);
 
 // Get rid of ExprWithCleanups.
 if (auto *EWC = llvm::dyn_cast_if_present(E))
@@ -575,11 +658,11 @@ class RuntimeInterfaceBuilder
 Expr *TypeArg =
 CStyleCastPtrExpr(S, Ctx.VoidPtrTy, (uintptr_t)Ty.getAsOpaquePtr());
 // The QualType parameter `OpaqueType`, represented as `void*`.
-Args.push_back(TypeArg);
+Visitor.Args.push_back(TypeArg);
 
 // We push the last parameter based on the type of the Expr. Note we need
 // special care for rvalue struct.
-Interpreter::InterfaceKind Kind = Visit(&*DesugaredTy);
+Interpreter::InterfaceKind Kind = Visitor.Visit(&*DesugaredTy);
 switch (Kind) {
 case Interpreter::InterfaceKind::WithAlloc:
 case Interpreter::InterfaceKind::CopyArray: {
@@ -587,7 +670,7 @@ class RuntimeInterfaceBuilder
   ExprResult AllocCall = S

[clang] [clang-repl] Expose RuntimeInterfaceBuilder to allow customization (PR #83126)

2024-02-28 Thread via cfe-commits
Stefan =?utf-8?q?Gränitz?= ,
Stefan =?utf-8?q?Gränitz?= ,
Stefan =?utf-8?q?Gränitz?= 
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 841a4168addba6931114e81d446c35114208eda2 
f069bafd8a3c597934f17236b530ffbcfe8d0f92 -- 
clang/include/clang/Interpreter/Interpreter.h 
clang/lib/Interpreter/Interpreter.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 0aae00ddd2..5c2741a19d 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -77,7 +77,8 @@ class RuntimeInterfaceBuilder {
 public:
   virtual ~RuntimeInterfaceBuilder() = default;
 
-  using AddCallToRuntimeInterfaceFunction = ExprResult(RuntimeInterfaceBuilder 
*Builder, Expr *, ArrayRef);
+  using AddCallToRuntimeInterfaceFunction =
+  ExprResult(RuntimeInterfaceBuilder *Builder, Expr *, ArrayRef);
   virtual AddCallToRuntimeInterfaceFunction *getCallCallback() = 0;
 };
 
@@ -102,7 +103,8 @@ class Interpreter {
 protected:
   Interpreter(std::unique_ptr CI, llvm::Error &Err);
 
-  RuntimeInterfaceBuilder::AddCallToRuntimeInterfaceFunction* 
AddCallToRuntimeInterface = nullptr;
+  RuntimeInterfaceBuilder::AddCallToRuntimeInterfaceFunction
+  *AddCallToRuntimeInterface = nullptr;
 
   void finalizeInitPTUStack();
 
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index a1c577bd28..7bd4691224 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -647,7 +647,8 @@ public:
   : Interp(Interp), Ctx(C), S(S) {}
 
   AddCallToRuntimeInterfaceFunction *getCallCallback() override {
-return [](RuntimeInterfaceBuilder *Builder, Expr *E, ArrayRef 
FixedArgs) -> ExprResult {
+return [](RuntimeInterfaceBuilder *Builder, Expr *E,
+  ArrayRef FixedArgs) -> ExprResult {
   auto *B = static_cast(Builder);
 
   // Get rid of ExprWithCleanups.
@@ -669,8 +670,8 @@ public:
 Ty = B->Ctx.getLValueReferenceType(Ty);
   }
 
-  Expr *TypeArg =
-  CStyleCastPtrExpr(B->S, B->Ctx.VoidPtrTy, 
(uintptr_t)Ty.getAsOpaquePtr());
+  Expr *TypeArg = CStyleCastPtrExpr(B->S, B->Ctx.VoidPtrTy,
+(uintptr_t)Ty.getAsOpaquePtr());
   // The QualType parameter `OpaqueType`, represented as `void*`.
   Visitor.Args.push_back(TypeArg);
 
@@ -683,11 +684,14 @@ public:
 // __clang_Interpreter_SetValueWithAlloc.
 ExprResult AllocCall = B->S.ActOnCallExpr(
 /*Scope=*/nullptr,
-
B->Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::WithAlloc],
+B->Interp
+.getValuePrintingInfo()[Interpreter::InterfaceKind::WithAlloc],
 E->getBeginLoc(), Visitor.Args, E->getEndLoc());
-assert(!AllocCall.isInvalid() && "Can't create runtime interface 
call!");
+assert(!AllocCall.isInvalid() &&
+   "Can't create runtime interface call!");
 
-TypeSourceInfo *TSI = B->Ctx.getTrivialTypeSourceInfo(Ty, 
SourceLocation());
+TypeSourceInfo *TSI =
+B->Ctx.getTrivialTypeSourceInfo(Ty, SourceLocation());
 
 // Force CodeGen to emit destructor.
 if (auto *RD = Ty->getAsCXXRecordDecl()) {
@@ -706,13 +710,14 @@ public:
   Expr *Args[] = {E, AllocCall.get(), ArrSizeExpr};
   return B->S.ActOnCallExpr(
   /*Scope *=*/nullptr,
-  B->Interp
-  
.getValuePrintingInfo()[Interpreter::InterfaceKind::CopyArray],
+  B->Interp.getValuePrintingInfo()
+  [Interpreter::InterfaceKind::CopyArray],
   SourceLocation(), Args, SourceLocation());
 }
 Expr *Args[] = {
 AllocCall.get(),
-
B->Interp.getValuePrintingInfo()[Interpreter::InterfaceKind::NewTag]};
+B->Interp
+.getValuePrintingInfo()[Interpreter::InterfaceKind::NewTag]};
 ExprResult CXXNewCall = B->S.BuildCXXNew(
 E->getSourceRange(),
 /*UseGlobal=*/true, /*PlacementLParen=*/SourceLocation(), Args,
@@ -721,16 +726,17 @@ public:
 E->getSourceRange(), E);
 
 assert(!CXXNewCall.isInvalid() &&
-  "Can't create runtime placement new call!");
+   "Can't create runtime placement new call!");
 
 return B->S.ActOnFinishFullExpr(CXXNewCall.get(),
-/*DiscardedValue=*/false);
+/*DiscardedValue=*/false);
   }
 // __clang_Interpreter_SetValueNoAlloc.
   case Interpreter::InterfaceKind::NoAlloc: {
 return B->S.ActOnCallExpr(
 /

[clang] [llvm] [LLVM][TypeSize] Remove default constructor. (PR #82810)

2024-02-28 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm approved this pull request.


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


[clang] [OpenMP] Clang Codegen Interop : Accept multiple init (PR #82604)

2024-02-28 Thread via cfe-commits

SunilKuravinakop wrote:

Alexey, 
Can you please review my changes?

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


[clang] [clang-repl] Expose RuntimeInterfaceBuilder to allow customization (PR #83126)

2024-02-28 Thread Stefan Gränitz via cfe-commits

weliveindetail wrote:

Alright. The above change makes it as cheap as it gets with an abstraction: 
virtual function calls only on init and one function pointer call for each 
processed statement.

> I was wondering if we can extend that functionality via a callback mechanism 

How would that look like? I assume the runtime interface will have other 
functions than `getCall()` in the future right? Then we need to keep it as an 
entity. What is the difference between a callback and the virtual function call 
from the first patch?

We can change it to provide function pointers instead like in my last patch. 
It's less idiomatic but a bit cheaper. Of course we could use `std::function` 
callbacks and capturing lambdas instead, but I am afraid that would be even 
more expensive than the virtual function proposal.

> We also have some pending work (which I was planning on working when time 
> permits) in that area [D146809](https://reviews.llvm.org/D146809). I was 
> wondering if that'd interfere with your work...

Your patch doesn't actually touch the `RuntimeInterfaceBuilder`, so this should 
be no problem.


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


[clang] [clang-repl] Expose RuntimeInterfaceBuilder to allow customization (PR #83126)

2024-02-28 Thread Stefan Gränitz via cfe-commits

https://github.com/weliveindetail updated 
https://github.com/llvm/llvm-project/pull/83126

From 3a6fdd006f00b0530e7fe6ead1fcd2765c1bfe07 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= 
Date: Mon, 26 Feb 2024 19:12:41 +0100
Subject: [PATCH 1/5] [clang-repl] Split out TypeVisitor from
 RuntimeInterfaceBuilder

---
 clang/lib/Interpreter/Interpreter.cpp | 171 ++
 1 file changed, 92 insertions(+), 79 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 9f97a3c6b0be9e..7afe55bbb266a3 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -541,21 +541,104 @@ bool Interpreter::FindRuntimeInterface() {
 
 namespace {
 
-class RuntimeInterfaceBuilder
-: public TypeVisitor {
-  clang::Interpreter &Interp;
+class InterfaceKindVisitor
+: public TypeVisitor {
+  friend class RuntimeInterfaceBuilder;
+
   ASTContext &Ctx;
   Sema &S;
   Expr *E;
   llvm::SmallVector Args;
 
+public:
+  InterfaceKindVisitor(ASTContext &Ctx, Sema &S, Expr *E)
+  : Ctx(Ctx), S(S), E(E) {}
+
+  Interpreter::InterfaceKind VisitRecordType(const RecordType *Ty) {
+return Interpreter::InterfaceKind::WithAlloc;
+  }
+
+  Interpreter::InterfaceKind
+  VisitMemberPointerType(const MemberPointerType *Ty) {
+return Interpreter::InterfaceKind::WithAlloc;
+  }
+
+  Interpreter::InterfaceKind
+  VisitConstantArrayType(const ConstantArrayType *Ty) {
+return Interpreter::InterfaceKind::CopyArray;
+  }
+
+  Interpreter::InterfaceKind
+  VisitFunctionProtoType(const FunctionProtoType *Ty) {
+HandlePtrType(Ty);
+return Interpreter::InterfaceKind::NoAlloc;
+  }
+
+  Interpreter::InterfaceKind VisitPointerType(const PointerType *Ty) {
+HandlePtrType(Ty);
+return Interpreter::InterfaceKind::NoAlloc;
+  }
+
+  Interpreter::InterfaceKind VisitReferenceType(const ReferenceType *Ty) {
+ExprResult AddrOfE = S.CreateBuiltinUnaryOp(SourceLocation(), UO_AddrOf, 
E);
+assert(!AddrOfE.isInvalid() && "Can not create unary expression");
+Args.push_back(AddrOfE.get());
+return Interpreter::InterfaceKind::NoAlloc;
+  }
+
+  Interpreter::InterfaceKind VisitBuiltinType(const BuiltinType *Ty) {
+if (Ty->isNullPtrType())
+  Args.push_back(E);
+else if (Ty->isFloatingType())
+  Args.push_back(E);
+else if (Ty->isIntegralOrEnumerationType())
+  HandleIntegralOrEnumType(Ty);
+else if (Ty->isVoidType()) {
+  // Do we need to still run `E`?
+}
+
+return Interpreter::InterfaceKind::NoAlloc;
+  }
+
+  Interpreter::InterfaceKind VisitEnumType(const EnumType *Ty) {
+HandleIntegralOrEnumType(Ty);
+return Interpreter::InterfaceKind::NoAlloc;
+  }
+
+private:
+  // Force cast these types to uint64 to reduce the number of overloads of
+  // `__clang_Interpreter_SetValueNoAlloc`.
+  void HandleIntegralOrEnumType(const Type *Ty) {
+TypeSourceInfo *TSI = Ctx.getTrivialTypeSourceInfo(Ctx.UnsignedLongLongTy);
+ExprResult CastedExpr =
+S.BuildCStyleCastExpr(SourceLocation(), TSI, SourceLocation(), E);
+assert(!CastedExpr.isInvalid() && "Cannot create cstyle cast expr");
+Args.push_back(CastedExpr.get());
+  }
+
+  void HandlePtrType(const Type *Ty) {
+TypeSourceInfo *TSI = Ctx.getTrivialTypeSourceInfo(Ctx.VoidPtrTy);
+ExprResult CastedExpr =
+S.BuildCStyleCastExpr(SourceLocation(), TSI, SourceLocation(), E);
+assert(!CastedExpr.isInvalid() && "Can not create cstyle cast expression");
+Args.push_back(CastedExpr.get());
+  }
+};
+
+class RuntimeInterfaceBuilder {
+  clang::Interpreter &Interp;
+  ASTContext &Ctx;
+  Sema &S;
+  Expr *E;
+  InterfaceKindVisitor Visitor;
+
 public:
   RuntimeInterfaceBuilder(clang::Interpreter &In, ASTContext &C, Sema &SemaRef,
   Expr *VE, ArrayRef FixedArgs)
-  : Interp(In), Ctx(C), S(SemaRef), E(VE) {
+  : Interp(In), Ctx(C), S(SemaRef), E(VE), Visitor(C, SemaRef, VE) {
 // The Interpreter* parameter and the out parameter `OutVal`.
 for (Expr *E : FixedArgs)
-  Args.push_back(E);
+  Visitor.Args.push_back(E);
 
 // Get rid of ExprWithCleanups.
 if (auto *EWC = llvm::dyn_cast_if_present(E))
@@ -575,11 +658,11 @@ class RuntimeInterfaceBuilder
 Expr *TypeArg =
 CStyleCastPtrExpr(S, Ctx.VoidPtrTy, (uintptr_t)Ty.getAsOpaquePtr());
 // The QualType parameter `OpaqueType`, represented as `void*`.
-Args.push_back(TypeArg);
+Visitor.Args.push_back(TypeArg);
 
 // We push the last parameter based on the type of the Expr. Note we need
 // special care for rvalue struct.
-Interpreter::InterfaceKind Kind = Visit(&*DesugaredTy);
+Interpreter::InterfaceKind Kind = Visitor.Visit(&*DesugaredTy);
 switch (Kind) {
 case Interpreter::InterfaceKind::WithAlloc:
 case Interpreter::InterfaceKind::CopyArray: {
@@ -587,7 +670,7 @@ class RuntimeInterfaceBuilder
   ExprResult AllocCall = S

[clang] [alpha.webkit.UncountedLocalVarsChecker] Allow uncounted object references within trivial statements (PR #82229)

2024-02-28 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/82229

>From 099640652b62c52160b12542a16eb66da90cfc93 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Mon, 19 Feb 2024 01:07:13 -0800
Subject: [PATCH 1/2] [alpha.webkit.UncountedLocalVarsChecker] Allow uncounted
 object references within trivial statements

This PR makes alpha.webkit.UncountedLocalVarsChecker ignore raw references and 
pointers to
a ref counted type which appears within "trival" statements. To do this, this 
PR extends
TrivialFunctionAnalysis so that it can also analyze "triviality" of statements 
as well as
that of functions Each Visit* function is now augmented with withCachedResult, 
which is
responsible for looking up and updating the cache for each Visit* functions.

As this PR dramatically improves the false positive rate of the checker, it 
also deletes
the code to ignore raw pointers and references within if and for statements.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 221 --
 .../Checkers/WebKit/PtrTypesSemantics.h   |  21 +-
 .../WebKit/UncountedLocalVarsChecker.cpp  |  69 +++---
 .../Analysis/Checkers/WebKit/mock-types.h |   2 +
 .../Checkers/WebKit/uncounted-local-vars.cpp  |  92 +++-
 5 files changed, 286 insertions(+), 119 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index a7891d2da07c18..cb89ce59a60878 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -244,18 +244,41 @@ class TrivialFunctionAnalysisVisitor
 
   // Returns false if at least one child is non-trivial.
   bool VisitChildren(const Stmt *S) {
-for (const Stmt *Child : S->children()) {
-  if (Child && !Visit(Child))
+return withCachedResult(S, [&]() {
+  for (const Stmt *Child : S->children()) {
+if (Child && !Visit(Child))
+  return false;
+  }
+  return true;
+});
+  }
+
+  bool VisitSubExpr(const Expr *Parent, const Expr *E) {
+return withCachedResult(Parent, [&]() {
+  if (!Visit(E))
 return false;
-}
+  return true;
+});
+  }
 
-return true;
+  template 
+  bool withCachedResult(const StmtType *S, CheckFunction Function) {
+// Insert false to the cache first to avoid infinite recursion.
+auto [It, IsNew] = StatementCache.insert(std::make_pair(S, false));
+if (!IsNew)
+  return It->second;
+bool Result = Function();
+It->second = Result;
+return Result;
   }
 
 public:
-  using CacheTy = TrivialFunctionAnalysis::CacheTy;
+  using FunctionCacheTy = TrivialFunctionAnalysis::FunctionCacheTy;
+  using StatementCacheTy = TrivialFunctionAnalysis::StatementCacheTy;
 
-  TrivialFunctionAnalysisVisitor(CacheTy &Cache) : Cache(Cache) {}
+  TrivialFunctionAnalysisVisitor(FunctionCacheTy &FunctionCache,
+ StatementCacheTy &StatementCache)
+  : FunctionCache(FunctionCache), StatementCache(StatementCache) {}
 
   bool VisitStmt(const Stmt *S) {
 // All statements are non-trivial unless overriden later.
@@ -271,13 +294,21 @@ class TrivialFunctionAnalysisVisitor
 
   bool VisitReturnStmt(const ReturnStmt *RS) {
 // A return statement is allowed as long as the return value is trivial.
-if (auto *RV = RS->getRetValue())
-  return Visit(RV);
-return true;
+return withCachedResult(RS, [&]() {
+  if (auto *RV = RS->getRetValue())
+return Visit(RV);
+  return true;
+});
+  }
+
+  bool VisitCXXForRangeStmt(const CXXForRangeStmt *FS) {
+return VisitChildren(FS);
   }
 
   bool VisitDeclStmt(const DeclStmt *DS) { return VisitChildren(DS); }
   bool VisitDoStmt(const DoStmt *DS) { return VisitChildren(DS); }
+  bool VisitForStmt(const ForStmt *FS) { return VisitChildren(FS); }
+  bool VisitWhileStmt(const WhileStmt *WS) { return VisitChildren(WS); }
   bool VisitIfStmt(const IfStmt *IS) { return VisitChildren(IS); }
   bool VisitSwitchStmt(const SwitchStmt *SS) { return VisitChildren(SS); }
   bool VisitCaseStmt(const CaseStmt *CS) { return VisitChildren(CS); }
@@ -285,17 +316,26 @@ class TrivialFunctionAnalysisVisitor
 
   bool VisitUnaryOperator(const UnaryOperator *UO) {
 // Operator '*' and '!' are allowed as long as the operand is trivial.
-if (UO->getOpcode() == UO_Deref || UO->getOpcode() == UO_AddrOf ||
-UO->getOpcode() == UO_LNot)
-  return Visit(UO->getSubExpr());
-
-// Other operators are non-trivial.
-return false;
+return withCachedResult(UO, [&]() {
+  auto op = UO->getOpcode();
+  if (op == UO_Deref || op == UO_AddrOf || op == UO_LNot)
+return Visit(UO->getSubExpr());
+  if (UO->isIncrementOp() || UO->isDecrementOp()) {
+if (auto *RefExpr = dyn_cast(UO->getSubExpr())) {
+  if (auto *Decl = dyn_cast(RefExpr->getDecl()))
+return Decl->i

[clang-tools-extra] [NFC][clang] add a clang tool for mlir refactor (PR #75279)

2024-02-28 Thread via cfe-commits

https://github.com/lipracer updated 
https://github.com/llvm/llvm-project/pull/75279

>From 71ae35b1538201790e5fc7a25d1d7aba7df7913d Mon Sep 17 00:00:00 2001
From: lipracer 
Date: Wed, 13 Dec 2023 11:37:12 +0800
Subject: [PATCH] [NFC][clang] add a clang tool for mlir refactor

---
 clang-tools-extra/CMakeLists.txt  |   1 +
 .../mlir-cast-refactor/CMakeLists.txt |  18 ++
 .../mlir-cast-refactor/MlirCastRefactor.cpp   | 172 ++
 3 files changed, 191 insertions(+)
 create mode 100644 clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
 create mode 100644 clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp

diff --git a/clang-tools-extra/CMakeLists.txt b/clang-tools-extra/CMakeLists.txt
index 6a3f741721ee6c..44e4f02dca3326 100644
--- a/clang-tools-extra/CMakeLists.txt
+++ b/clang-tools-extra/CMakeLists.txt
@@ -27,6 +27,7 @@ add_subdirectory(include-cleaner)
 add_subdirectory(pp-trace)
 add_subdirectory(pseudo)
 add_subdirectory(tool-template)
+add_subdirectory(mlir-cast-refactor)
 
 option(CLANG_TOOLS_EXTRA_INCLUDE_DOCS "Generate build targets for the Clang 
Extra Tools docs."
   ${LLVM_INCLUDE_DOCS})
diff --git a/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt 
b/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
new file mode 100644
index 00..ebdabf23fc53c3
--- /dev/null
+++ b/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_executable(mlirCastRefactor
+  MlirCastRefactor.cpp
+  )
+target_link_libraries(mlirCastRefactor
+  PRIVATE
+clangAST
+clangBasic
+clangFormat
+clangFrontend
+clangLex
+clangRewrite
+clangSerialization
+clangTooling
+clangToolingCore
+clangToolingRefactoring
+  )
\ No newline at end of file
diff --git a/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp 
b/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
new file mode 100644
index 00..0ebb48b60940c7
--- /dev/null
+++ b/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
@@ -0,0 +1,172 @@
+//===-- MlirCastRefactor.cpp - mlir refactor implementation 
---===//
+//
+// 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 "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Refactoring/AtomicChange.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace clang::tooling;
+using namespace llvm;
+
+// Apply a custom category to all command-line options so that they are the
+// only ones displayed.
+static llvm::cl::OptionCategory MyToolCategory("my-tool options");
+static cl::opt target_type("target-type",
+cl::desc("refactoring type name"),
+cl::value_desc("type name"),
+cl::ValueRequired, cl::NotHidden,
+cl::cat(MyToolCategory));
+
+// CommonOptionsParser declares HelpMessage with a description of the common
+// command-line options related to the compilation database and input files.
+// It's nice to have this help message in all tools.
+static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+
+// A help message for this specific tool can be added afterwards.
+static cl::extrahelp MoreHelp("\nMore help text...\n");
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+class MemberFunctionCallMatcher : public MatchFinder::MatchCallback {
+public:
+  void run(const MatchFinder::MatchResult &Result) override {
+if (const CXXMemberCallExpr *MemberCall =
+Result.Nodes.getNodeAs("memberCall")) {
+  auto objExpr = MemberCall->getImplicitObjectArgument();
+  auto endLoc = MemberCall->getExprLoc();
+
+  auto exprRange = objExpr->getSourceRange();
+
+  SourceLocation StartLoc = objExpr->getBeginLoc();
+
+  const SourceManager &SM = *Result.SourceManager;
+  const char *StartPtr = SM.getCharacterData(StartLoc);
+  const char *EndPtr = SM.getCharacterData(endLoc);
+
+  tooling::AtomicChange change(*Result.SourceManager,
+   MemberCall->getExprLoc());
+  const auto *ME = Result.Nodes.getNodeAs("member");
+  size_t dropbackCount = ME->isArrow() ? 2 : 1;
+
+  {
+auto length = EndPtr - StartPtr;
+objExprStrings.emplace_back(StartPtr, length);
+change.replace(*Result.SourceManager, StartLoc, EndPtr - StartPtr, "");
+  }
+
+  {
+// remove keyword template e.g. obj->tem

[clang-tools-extra] [NFC][clang] add a clang tool for mlir refactor (PR #75279)

2024-02-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: long.chen (lipracer)


Changes

I am unable to modify the title; however, the detailed description is 
[here](https://discourse.llvm.org/t/rfc-add-a-mlir-refactor-tool-to-clang-tools-extra/75451).
 This is an NFC (No Functional Change) rather than RFC (Request for Comments)

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


3 Files Affected:

- (modified) clang-tools-extra/CMakeLists.txt (+1) 
- (added) clang-tools-extra/mlir-cast-refactor/CMakeLists.txt (+18) 
- (added) clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp (+172) 


``diff
diff --git a/clang-tools-extra/CMakeLists.txt b/clang-tools-extra/CMakeLists.txt
index 6a3f741721ee6c..44e4f02dca3326 100644
--- a/clang-tools-extra/CMakeLists.txt
+++ b/clang-tools-extra/CMakeLists.txt
@@ -27,6 +27,7 @@ add_subdirectory(include-cleaner)
 add_subdirectory(pp-trace)
 add_subdirectory(pseudo)
 add_subdirectory(tool-template)
+add_subdirectory(mlir-cast-refactor)
 
 option(CLANG_TOOLS_EXTRA_INCLUDE_DOCS "Generate build targets for the Clang 
Extra Tools docs."
   ${LLVM_INCLUDE_DOCS})
diff --git a/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt 
b/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
new file mode 100644
index 00..ebdabf23fc53c3
--- /dev/null
+++ b/clang-tools-extra/mlir-cast-refactor/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_executable(mlirCastRefactor
+  MlirCastRefactor.cpp
+  )
+target_link_libraries(mlirCastRefactor
+  PRIVATE
+clangAST
+clangBasic
+clangFormat
+clangFrontend
+clangLex
+clangRewrite
+clangSerialization
+clangTooling
+clangToolingCore
+clangToolingRefactoring
+  )
\ No newline at end of file
diff --git a/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp 
b/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
new file mode 100644
index 00..0ebb48b60940c7
--- /dev/null
+++ b/clang-tools-extra/mlir-cast-refactor/MlirCastRefactor.cpp
@@ -0,0 +1,172 @@
+//===-- MlirCastRefactor.cpp - mlir refactor implementation 
---===//
+//
+// 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 "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Refactoring/AtomicChange.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace clang::tooling;
+using namespace llvm;
+
+// Apply a custom category to all command-line options so that they are the
+// only ones displayed.
+static llvm::cl::OptionCategory MyToolCategory("my-tool options");
+static cl::opt target_type("target-type",
+cl::desc("refactoring type name"),
+cl::value_desc("type name"),
+cl::ValueRequired, cl::NotHidden,
+cl::cat(MyToolCategory));
+
+// CommonOptionsParser declares HelpMessage with a description of the common
+// command-line options related to the compilation database and input files.
+// It's nice to have this help message in all tools.
+static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+
+// A help message for this specific tool can be added afterwards.
+static cl::extrahelp MoreHelp("\nMore help text...\n");
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+class MemberFunctionCallMatcher : public MatchFinder::MatchCallback {
+public:
+  void run(const MatchFinder::MatchResult &Result) override {
+if (const CXXMemberCallExpr *MemberCall =
+Result.Nodes.getNodeAs("memberCall")) {
+  auto objExpr = MemberCall->getImplicitObjectArgument();
+  auto endLoc = MemberCall->getExprLoc();
+
+  auto exprRange = objExpr->getSourceRange();
+
+  SourceLocation StartLoc = objExpr->getBeginLoc();
+
+  const SourceManager &SM = *Result.SourceManager;
+  const char *StartPtr = SM.getCharacterData(StartLoc);
+  const char *EndPtr = SM.getCharacterData(endLoc);
+
+  tooling::AtomicChange change(*Result.SourceManager,
+   MemberCall->getExprLoc());
+  const auto *ME = Result.Nodes.getNodeAs("member");
+  size_t dropbackCount = ME->isArrow() ? 2 : 1;
+
+  {
+auto length = EndPtr - StartPtr;
+objExprStrings.emplace_back(StartPtr, length);
+change.replace(*Result.SourceManager, StartLoc, EndPtr - StartPtr, "");
+  }
+
+  {
+// remove keyword template e.g. obj->template 

[clang] [clang][analyzer] StreamChecker: Model getc, vfscanf, putc, vfprintf (PR #82476)

2024-02-28 Thread Balazs Benics via cfe-commits
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: 


https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/82476

>From 414fb841815ee020ee4fbb0049f9072d889cbf4a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 
Date: Tue, 14 Nov 2023 09:28:45 +0100
Subject: [PATCH 01/11] [clang][analyzer] StreamChecker: add more APIs,
 invalidate fscanf args

1. Model getc, vfscanf, putc, vfprintf.
2. fscanf invalidates all arguments after the format string.
---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp |  37 -
 ...ystem-header-simulator-for-simple-stream.h |   2 +-
 .../system-header-simulator-for-valist.h  |   4 +
 .../Analysis/Inputs/system-header-simulator.h |   3 +
 clang/test/Analysis/stream.c  | 128 ++
 5 files changed, 172 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 65bdc4cac30940..247d612989fd87 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -172,7 +172,7 @@ using FnCheck = std::function;
 
 using ArgNoTy = unsigned int;
-static const ArgNoTy ArgNone = std::numeric_limits::max();
+const ArgNoTy ArgNone = std::numeric_limits::max();
 
 struct FnDescription {
   FnCheck PreFn;
@@ -180,6 +180,26 @@ struct FnDescription {
   ArgNoTy StreamArgNo;
 };
 
+[[nodiscard]] ProgramStateRef
+escapeArgsAfterIndex(ProgramStateRef State, CheckerContext &C,
+ const CallEvent &Call, unsigned FirstEscapingArgIndex) {
+  const auto *CE = Call.getOriginExpr();
+  assert(CE);
+
+  if (Call.getNumArgs() <= FirstEscapingArgIndex)
+return State;
+
+  SmallVector EscapingArgs;
+  EscapingArgs.reserve(Call.getNumArgs() - FirstEscapingArgIndex);
+  for (auto EscArgIdx :
+   llvm::seq(FirstEscapingArgIndex, Call.getNumArgs()))
+EscapingArgs.push_back(Call.getArgSVal(EscArgIdx));
+  State = State->invalidateRegions(EscapingArgs, CE, C.blockCount(),
+   C.getLocationContext(),
+   /*CausesPointerEscape=*/false);
+  return State;
+}
+
 /// Get the value of the stream argument out of the passed call event.
 /// The call should contain a function that is described by Desc.
 SVal getStreamArg(const FnDescription *Desc, const CallEvent &Call) {
@@ -397,6 +417,18 @@ class StreamChecker : public Checker FnTestDescriptions = {
@@ -1021,6 +1053,9 @@ void StreamChecker::evalFscanf(const FnDescription *Desc, 
const CallEvent &Call,
   if (!E.Init(Desc, Call, C, State))
 return;
 
+  // The pointers passed to fscanf escape and get invalidated.
+  State = escapeArgsAfterIndex(State, C, Call, /*FirstEscapingArgIndex=*/2);
+
   // Add the success state.
   // In this context "success" means there is not an EOF or other read error
   // before any item is matched in 'fscanf'. But there may be match failure,
diff --git 
a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h 
b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
index 098a2208fecbe9..c26d3582149120 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
@@ -5,7 +5,7 @@
 // suppressed.
 #pragma clang system_header
 
-typedef struct __sFILE {
+typedef struct _FILE {
   unsigned char *_p;
 } FILE;
 FILE *fopen(const char *restrict, const char *restrict) __asm("_" "fopen" );
diff --git a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h 
b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
index 7299b61353d460..87688bd8b312f4 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
@@ -10,6 +10,8 @@
 #define restrict /*restrict*/
 #endif
 
+typedef struct _FILE FILE;
+
 typedef __builtin_va_list va_list;
 
 #define va_start(ap, param) __builtin_va_start(ap, param)
@@ -21,6 +23,8 @@ int vprintf (const char *restrict format, va_list arg);
 
 int vsprintf (char *restrict s, const char *restrict format, va_list arg);
 
+int vfscanf(FILE *stream, const char *format, va_list ap);
+
 int some_library_function(int n, va_list arg);
 
 // No warning from system header.
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index 15986984802c0e..8fd51449ecc0a4 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs

[clang] ffe7049 - [clang][analyzer] StreamChecker: Model getc, vfscanf, putc, vfprintf (#82476)

2024-02-28 Thread via cfe-commits

Author: Alejandro Álvarez Ayllón
Date: 2024-02-28T12:22:57+01:00
New Revision: ffe7049b543adb9739261d28a60d4a47a00aa2e0

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

LOG: [clang][analyzer] StreamChecker: Model getc, vfscanf, putc, vfprintf 
(#82476)

Model `getc` and `putc` as equivalent to `fgetc` and `fputc` respectively.

Model `vfscanf` and `vfprintf` as `fscanf` and `fprintf`, except that
`vfscanf` can not invalidate the parameters due to the indirection via a
`va_list`. Nevertheless, we can still track EOF and errors as for `fscanf`.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
clang/test/Analysis/Inputs/system-header-simulator.h
clang/test/Analysis/stream-invalidate.c
clang/test/Analysis/stream.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 65bdc4cac30940..29956fed2b3c24 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -348,18 +348,30 @@ class StreamChecker : public Checker EscArgs;
-for (auto EscArg : llvm::seq(2u, Call.getNumArgs()))
-  EscArgs.push_back(EscArg);
-StateNotFailed = escapeArgs(StateNotFailed, C, Call, EscArgs);
+if (auto const *Callee = Call.getCalleeIdentifier();
+!Callee || !Callee->getName().equals("vfscanf")) {
+  SmallVector EscArgs;
+  for (auto EscArg : llvm::seq(2u, Call.getNumArgs()))
+EscArgs.push_back(EscArg);
+  StateNotFailed = escapeArgs(StateNotFailed, C, Call, EscArgs);
+}
 
 if (StateNotFailed)
   C.addTransition(StateNotFailed);

diff  --git 
a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h 
b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
index 098a2208fecbe9..c26d3582149120 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
@@ -5,7 +5,7 @@
 // suppressed.
 #pragma clang system_header
 
-typedef struct __sFILE {
+typedef struct _FILE {
   unsigned char *_p;
 } FILE;
 FILE *fopen(const char *restrict, const char *restrict) __asm("_" "fopen" );

diff  --git a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h 
b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
index 7299b61353d460..720944abb8ad47 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
@@ -10,6 +10,8 @@
 #define restrict /*restrict*/
 #endif
 
+typedef struct _FILE FILE;
+
 typedef __builtin_va_list va_list;
 
 #define va_start(ap, param) __builtin_va_start(ap, param)
@@ -21,6 +23,10 @@ int vprintf (const char *restrict format, va_list arg);
 
 int vsprintf (char *restrict s, const char *restrict format, va_list arg);
 
+int vfprintf(FILE *stream, const char *format, va_list ap);
+
+int vfscanf(FILE *stream, const char *format, va_list ap);
+
 int some_library_function(int n, va_list arg);
 
 // No warning from system header.

diff  --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index 15986984802c0e..8fd51449ecc0a4 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -73,6 +73,9 @@ int ferror(FILE *stream);
 int fileno(FILE *stream);
 int fflush(FILE *stream);
 
+
+int getc(FILE *stream);
+
 size_t strlen(const char *);
 
 char *strcpy(char *restrict, const char *restrict);

diff  --git a/clang/test/Analysis/stream-invalidate.c 
b/clang/test/Analysis/stream-invalidate.c
index 6745d11a2fe701..5046a356d0583d 100644
--- a/clang/test/Analysis/stream-invalidate.c
+++ b/clang/test/Analysis/stream-invalidate.c
@@ -4,6 +4,7 @@
 // RUN: -analyzer-checker=debug.ExprInspection
 
 #include "Inputs/system-header-simulator.h"
+#include "Inputs/system-header-simulator-for-valist.h"
 
 void clang_analyzer_eval(int);
 void clang_analyzer_dump(int);
@@ -145,3 +146,44 @@ void test_fgetpos() {
 
   fclose(F);
 }
+
+void test_fprintf() {
+  FILE *F1 = tmpfile();
+  if (!F1)
+return;
+
+  unsigned a = 42;
+  char *output = "HELLO";
+  int r = fprintf(F1, "%s\t%u\n", output, a);
+  // fprintf does not invalidate any of its input
+  // 69 is ascii for 'E'
+  clang_analyzer_dump(a); // expected-warning {{42 S32b}}
+  clang_analyzer_dump(output[1]); // expected-warning {{69 S32b}}
+  fclose(F1);
+}
+
+int test_vfscanf_inner(const char *fmt, ...) {
+  FILE *F1 = tmpfile(

[clang] [clang][analyzer] StreamChecker: Model getc, vfscanf, putc, vfprintf (PR #82476)

2024-02-28 Thread Balazs Benics via cfe-commits
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?=,
Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: 


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


[clang] fe97a59 - [clang] remove (clang::)ast_matchers:: namespace from AST matcher args for docs (#81437)

2024-02-28 Thread via cfe-commits

Author: Julian Schmidt
Date: 2024-02-28T12:43:43+01:00
New Revision: fe97a59a7be51dfc7e92619536963051604d155a

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

LOG: [clang] remove (clang::)ast_matchers:: namespace from AST matcher args for 
docs (#81437)

When parsing the ASTMatchers.h file, a matcher could specify an argument
that is a matcher using the not needed namespace
`(clang::)ast_matchers::`.
Change the argument parsing in dump_ast_matchers.py to remove those
namespaces such that when parameters with these namespaces slip through,
the namespaces will be not be shown in the matchers reference, like it
is done with the `internal` namespace.
Additionally, remove the not needed namespaces from arguments in
ASTMatchers.h.

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/docs/tools/dump_ast_matchers.py
clang/include/clang/ASTMatchers/ASTMatchers.h

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index c40d679e383bb2..8a06084955aa6b 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -7049,7 +7049,7 @@ AST Traversal Matchers
 
 
 
-MatcherCXXFoldExpr>hasFoldInitast_matchers::MatcherExpr> 
InnerMacher
+MatcherCXXFoldExpr>hasFoldInitMatcherExpr> 
InnerMacher
 Matches the operand 
that does not contain the parameter pack.
 
 Example matches `(0 + ... + args)` and `(args * ... * 1)`
@@ -7089,7 +7089,7 @@ AST Traversal Matchers
 
 
 
-MatcherCXXFoldExpr>hasPatternast_matchers::MatcherExpr> 
InnerMacher
+MatcherCXXFoldExpr>hasPatternMatcherExpr> 
InnerMacher
 Matches the operand that 
contains the parameter pack.
 
 Example matches `(0 + ... + args)`
@@ -7859,7 +7859,7 @@ AST Traversal Matchers
 
 
 
-MatcherClassTemplateSpecializationDecl>forEachTemplateArgumentclang::ast_matchers::MatcherTemplateArgument>
 InnerMatcher
+MatcherClassTemplateSpecializationDecl>forEachTemplateArgumentMatcherTemplateArgument>
 InnerMatcher
 Matches 
classTemplateSpecialization, templateSpecializationType and
 functionDecl nodes where the template argument matches the inner matcher.
 This matcher may produce multiple matches.
@@ -8454,7 +8454,7 @@ AST Traversal Matchers
 
 
 
-MatcherExpr>ignoringElidableConstructorCallast_matchers::MatcherExpr> 
InnerMatcher
+MatcherExpr>ignoringElidableConstructorCallMatcherExpr> 
InnerMatcher
 Matches expressions that match 
InnerMatcher that are possibly wrapped in an
 elidable constructor and other corresponding bookkeeping nodes.
 
@@ -8691,7 +8691,7 @@ AST Traversal Matchers
 
 
 
-MatcherFunctionDecl>forEachTemplateArgumentclang::ast_matchers::MatcherTemplateArgument>
 InnerMatcher
+MatcherFunctionDecl>forEachTemplateArgumentMatcherTemplateArgument>
 InnerMatcher
 Matches 
classTemplateSpecialization, templateSpecializationType and
 functionDecl nodes where the template argument matches the inner matcher.
 This matcher may produce multiple matches.
@@ -8959,7 +8959,7 @@ AST Traversal Matchers
 
 
 
-MatcherInitListExpr>hasInitunsigned N, 
ast_matchers::MatcherExpr> 
InnerMatcher
+MatcherInitListExpr>hasInitunsigned N, MatcherExpr> 
InnerMatcher
 Matches the n'th item of an 
initializer list expressi

[clang] [clang] remove (clang::)ast_matchers:: namespace from AST matcher args for docs (PR #81437)

2024-02-28 Thread Julian Schmidt via cfe-commits

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


[clang] 3d454d2 - [LLVM][TypeSize] Remove default constructor. (#82810)

2024-02-28 Thread via cfe-commits

Author: Paul Walker
Date: 2024-02-28T11:48:53Z
New Revision: 3d454d2895820cd1e6caa92f1e82ba468b5b5f09

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

LOG: [LLVM][TypeSize] Remove default constructor. (#82810)

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
llvm/include/llvm/Support/TypeSize.h
llvm/unittests/Support/TypeSizeTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index d05cf1c6e1814e..0d86fcf544d0fd 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3221,12 +3221,10 @@ void CodeGenFunction::EmitFunctionProlog(const 
CGFunctionInfo &FI,
 
   llvm::StructType *STy =
   dyn_cast(ArgI.getCoerceToType());
-  llvm::TypeSize StructSize;
-  llvm::TypeSize PtrElementSize;
   if (ArgI.isDirect() && !ArgI.getCanBeFlattened() && STy &&
   STy->getNumElements() > 1) {
-StructSize = CGM.getDataLayout().getTypeAllocSize(STy);
-PtrElementSize =
+llvm::TypeSize StructSize = CGM.getDataLayout().getTypeAllocSize(STy);
+llvm::TypeSize PtrElementSize =
 CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(Ty));
 if (STy->containsHomogeneousScalableVectorTypes()) {
   assert(StructSize == PtrElementSize &&
@@ -5310,12 +5308,11 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 
   llvm::StructType *STy =
   dyn_cast(ArgInfo.getCoerceToType());
-  llvm::Type *SrcTy = ConvertTypeForMem(I->Ty);
-  llvm::TypeSize SrcTypeSize;
-  llvm::TypeSize DstTypeSize;
   if (STy && ArgInfo.isDirect() && !ArgInfo.getCanBeFlattened()) {
-SrcTypeSize = CGM.getDataLayout().getTypeAllocSize(SrcTy);
-DstTypeSize = CGM.getDataLayout().getTypeAllocSize(STy);
+llvm::Type *SrcTy = ConvertTypeForMem(I->Ty);
+llvm::TypeSize SrcTypeSize =
+CGM.getDataLayout().getTypeAllocSize(SrcTy);
+llvm::TypeSize DstTypeSize = CGM.getDataLayout().getTypeAllocSize(STy);
 if (STy->containsHomogeneousScalableVectorTypes()) {
   assert(SrcTypeSize == DstTypeSize &&
  "Only allow non-fractional movement of structure with "

diff  --git a/llvm/include/llvm/Support/TypeSize.h 
b/llvm/include/llvm/Support/TypeSize.h
index 1b793b0eccf3c7..68dbe1ea3062ab 100644
--- a/llvm/include/llvm/Support/TypeSize.h
+++ b/llvm/include/llvm/Support/TypeSize.h
@@ -321,8 +321,6 @@ class TypeSize : public 
details::FixedOrScalableQuantity {
   : FixedOrScalableQuantity(V) {}
 
 public:
-  constexpr TypeSize() : FixedOrScalableQuantity(0, false) {}
-
   constexpr TypeSize(ScalarTy Quantity, bool Scalable)
   : FixedOrScalableQuantity(Quantity, Scalable) {}
 

diff  --git a/llvm/unittests/Support/TypeSizeTest.cpp 
b/llvm/unittests/Support/TypeSizeTest.cpp
index 34fe376989e7ba..b02b7e60095359 100644
--- a/llvm/unittests/Support/TypeSizeTest.cpp
+++ b/llvm/unittests/Support/TypeSizeTest.cpp
@@ -81,7 +81,6 @@ static_assert(INT64_C(2) * TSFixed32 == 
TypeSize::getFixed(64));
 static_assert(UINT64_C(2) * TSFixed32 == TypeSize::getFixed(64));
 static_assert(alignTo(TypeSize::getFixed(7), 8) == TypeSize::getFixed(8));
 
-static_assert(TypeSize() == TypeSize::getFixed(0));
 static_assert(TypeSize::getZero() == TypeSize::getFixed(0));
 static_assert(TypeSize::getZero() != TypeSize::getScalable(0));
 static_assert(TypeSize::getFixed(0) != TypeSize::getScalable(0));



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


[clang] [llvm] [LLVM][TypeSize] Remove default constructor. (PR #82810)

2024-02-28 Thread Paul Walker via cfe-commits

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


[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-28 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/81893

>From 4bff4f1378140b084256cf1647d26466e95d6ef7 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 15 Feb 2024 15:53:51 +
Subject: [PATCH] [clang] Refactor target attribute mangling.

Before this patch all of the 'target', 'target_version' and 'target_clones'
attributes were sharing a common mangling logic across different targets.
However we would like to differenciate this logic, therefore I have moved
the default path to ABIInfo and provided overrides for AArch64. This
way we can resolve feature aliases without affecting the name mangling
The PR #80540 demonstrates a motivating case.
---
 clang/lib/CodeGen/ABIInfo.cpp |  52 
 clang/lib/CodeGen/ABIInfo.h   |   8 ++
 clang/lib/CodeGen/CodeGenModule.cpp   | 111 --
 clang/lib/CodeGen/Targets/AArch64.cpp |  37 +
 4 files changed, 113 insertions(+), 95 deletions(-)

diff --git a/clang/lib/CodeGen/ABIInfo.cpp b/clang/lib/CodeGen/ABIInfo.cpp
index 1b56cf7c596d06..efcff958ce5452 100644
--- a/clang/lib/CodeGen/ABIInfo.cpp
+++ b/clang/lib/CodeGen/ABIInfo.cpp
@@ -184,6 +184,58 @@ ABIArgInfo ABIInfo::getNaturalAlignIndirectInReg(QualType 
Ty,
   /*ByVal*/ false, Realign);
 }
 
+void ABIInfo::appendAttributeMangling(TargetAttr *Attr,
+  raw_ostream &Out) const {
+  if (Attr->isDefaultVersion())
+return;
+  appendAttributeMangling(Attr->getFeaturesStr(), Out);
+}
+
+void ABIInfo::appendAttributeMangling(TargetVersionAttr *Attr,
+  raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getNamesStr(), Out);
+}
+
+void ABIInfo::appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
+  raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getFeatureStr(Index), Out);
+  Out << '.' << Attr->getMangledIndex(Index);
+}
+
+void ABIInfo::appendAttributeMangling(StringRef AttrStr,
+  raw_ostream &Out) const {
+  if (AttrStr == "default") {
+Out << ".default";
+return;
+  }
+
+  Out << '.';
+  const TargetInfo &TI = CGT.getTarget();
+  ParsedTargetAttr Info = TI.parseTargetAttr(AttrStr);
+
+  llvm::sort(Info.Features, [&TI](StringRef LHS, StringRef RHS) {
+// Multiversioning doesn't allow "no-${feature}", so we can
+// only have "+" prefixes here.
+assert(LHS.starts_with("+") && RHS.starts_with("+") &&
+   "Features should always have a prefix.");
+return TI.multiVersionSortPriority(LHS.substr(1)) >
+   TI.multiVersionSortPriority(RHS.substr(1));
+  });
+
+  bool IsFirst = true;
+  if (!Info.CPU.empty()) {
+IsFirst = false;
+Out << "arch_" << Info.CPU;
+  }
+
+  for (StringRef Feat : Info.Features) {
+if (!IsFirst)
+  Out << '_';
+IsFirst = false;
+Out << Feat.substr(1);
+  }
+}
+
 // Pin the vtable to this file.
 SwiftABIInfo::~SwiftABIInfo() = default;
 
diff --git a/clang/lib/CodeGen/ABIInfo.h b/clang/lib/CodeGen/ABIInfo.h
index b9a5ef6e436693..dccd23c0f97411 100644
--- a/clang/lib/CodeGen/ABIInfo.h
+++ b/clang/lib/CodeGen/ABIInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
 #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
 
+#include "clang/AST/Attr.h"
 #include "clang/AST/CharUnits.h"
 #include "clang/AST/Type.h"
 #include "llvm/IR/CallingConv.h"
@@ -111,6 +112,13 @@ class ABIInfo {
 
   CodeGen::ABIArgInfo getNaturalAlignIndirectInReg(QualType Ty,
bool Realign = false) const;
+
+  virtual void appendAttributeMangling(TargetAttr *Attr, raw_ostream &Out) 
const;
+  virtual void appendAttributeMangling(TargetVersionAttr *Attr,
+   raw_ostream &Out) const;
+  virtual void appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
+   raw_ostream &Out) const;
+  virtual void appendAttributeMangling(StringRef AttrStr, raw_ostream &Out) 
const;
 };
 
 /// Target specific hooks for defining how a type should be passed or returned
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 95e457bef28ed3..160917d47da1f3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1726,59 +1726,6 @@ static void AppendCPUSpecificCPUDispatchMangling(const 
CodeGenModule &CGM,
 Out << ".resolver";
 }
 
-static void AppendTargetVersionMangling(const CodeGenModule &CGM,
-const TargetVersionAttr *Attr,
-raw_ostream &Out) {
-  if (Attr->isDefaultVersion()) {
-Out << ".default";
-return;
-  }
-  Out << "._";
-  const TargetInfo &TI = CGM.getTarget();
-  llvm::SmallVector Feats;
-  Attr->getFeatures(Feats);
-  llvm::stable_sort(Feats, [&TI](const StringRef FeatL, const StringRef 

[clang] [Clang][Sema] placement new initializes typedef array with correct size (PR #83124)

2024-02-28 Thread via cfe-commits

https://github.com/mahtohappy updated 
https://github.com/llvm/llvm-project/pull/83124

>From 7de2ca730de7a51f4bb3c6178914bf57a7efb321 Mon Sep 17 00:00:00 2001
From: mahtohappy 
Date: Tue, 27 Feb 2024 03:13:51 -0800
Subject: [PATCH] [Clang][Sema] placement new initializes typedef array with
 correct size

---
 clang/lib/Sema/TreeTransform.h| 14 +-
 .../instantiate-new-placement-size.cpp| 19 +++
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/instantiate-new-placement-size.cpp

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 7389a48fe56fcc..0cda78650fcc83 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -12669,6 +12669,19 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr 
*E) {
 ArraySize = NewArraySize.get();
   }
 
+  // Per C++0x [expr.new]p5, the type being constructed may be a
+  // typedef of an array type.
+  QualType AllocType = AllocTypeInfo->getType();
+  if (ArraySize) {
+if (const ConstantArrayType *Array =
+SemaRef.Context.getAsConstantArrayType(AllocType)) {
+  ArraySize = IntegerLiteral::Create(SemaRef.Context, Array->getSize(),
+ SemaRef.Context.getSizeType(),
+ E->getBeginLoc());
+  AllocType = Array->getElementType();
+}
+  }
+
   // Transform the placement arguments (if any).
   bool ArgumentChanged = false;
   SmallVector PlacementArgs;
@@ -12730,7 +12743,6 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr 
*E) {
 return E;
   }
 
-  QualType AllocType = AllocTypeInfo->getType();
   if (!ArraySize) {
 // If no array size was specified, but the new expression was
 // instantiated with an array type (e.g., "new T" where T is
diff --git a/clang/test/SemaCXX/instantiate-new-placement-size.cpp 
b/clang/test/SemaCXX/instantiate-new-placement-size.cpp
new file mode 100644
index 00..ccb67f9fe822bc
--- /dev/null
+++ b/clang/test/SemaCXX/instantiate-new-placement-size.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang -S -Xclang -triple=x86_64-pc-linux-gnu -fno-discard-value-names 
-emit-llvm -o - %s | FileCheck %s
+#include 
+
+// CHECK: call void @llvm.memset.p0.i64(ptr align 1 %x, i8 0, i64 8, i1 false)
+// CHECK: call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 32, i1 
false)
+template 
+void f()
+{
+typedef TYPE TArray[8];
+
+TArray x;
+new(&x) TArray();
+}
+
+int main()
+{
+f();
+f();
+}

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


[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Aaron Ballman via cfe-commits


@@ -16538,6 +16538,27 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
 }
   }
 
+  // Complain if we are converting a lambda expression to a boolean value
+  if (auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+  if (auto *MRecordDecl = MCallExpr->getRecordDecl()) {
+if (MRecordDecl->isLambda()) {
+  std::string Str;
+  llvm::raw_string_ostream S(Str);
+  const unsigned DiagID = diag::warn_impcast_pointer_to_bool;
+  // For lambdas, the pointer type is function, which corresponds to 1.
+  const unsigned FunctionPointerType = 1;
+  // Pretty print the diagnostic for the warning
+  E->printPretty(S, nullptr, getPrintingPolicy());
+  Diag(E->getExprLoc(), DiagID)
+  << FunctionPointerType << S.str() << E->getSourceRange() << Range
+  << IsEqual;
+  return;

AaronBallman wrote:

Oh gosh, this was a think-o on my part, you're right, that is being passed 
through the diagnostics engine. Sorry for the noise, I must have been tired. :-)

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


[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > There are some related test failures caught by precommit CI that need to be 
> > addressed.
> > The issue in dr18xx.cpp looks to be a case where we should replace `bool b 
> > = ` with `auto b = ` (it doesn't change the testing for what's discussed in 
> > http://wg21.link/cwg1837).
> 
> Changing `bool b = ` to `auto b =` does not compile, as the compiler 
> complains that `auto` is not allowed in non-static struct members. `b` cannot 
> be declared as `static` either, which would cause an invalid use of `this` 
> outside of a non-static member function. It looks like type deduction using 
> auto for member variables is not allowed.

Yeah, another think-o on my part. I think it's fine to add the expected 
diagnostic to the file instead of silencing the warning.

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


[clang] [cfi][CodeGen] Call SetLLVMFunctionAttributes{, ForDefinition} on __cf… (PR #78253)

2024-02-28 Thread Aaron Ballman via cfe-commits

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


[clang] [cfi][CodeGen] Call SetLLVMFunctionAttributes{, ForDefinition} on __cf… (PR #78253)

2024-02-28 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

I think the code looks pretty reasonable, but I've added codegen code owners 
for final sign-off. Should we add a release note to 
`clang/docs/ReleaseNotes.rst` so users know about the changes?

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


[clang] [cfi][CodeGen] Call SetLLVMFunctionAttributes{, ForDefinition} on __cf… (PR #78253)

2024-02-28 Thread Aaron Ballman via cfe-commits


@@ -3443,11 +3443,28 @@ void CodeGenFunction::EmitCfiSlowPathCheck(
 void CodeGenFunction::EmitCfiCheckStub() {
   llvm::Module *M = &CGM.getModule();
   auto &Ctx = M->getContext();
+  auto &C = getContext();

AaronBallman wrote:

Please spell out the types here instead of using `auto`, it's not clear that 
these are different context objects.

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


[clang] 27b297b - [clang] Fix -Wunused-variable in CGCall.cpp (NFC)

2024-02-28 Thread Jie Fu via cfe-commits

Author: Jie Fu
Date: 2024-02-28T20:58:20+08:00
New Revision: 27b297bf21b6637047c1ac403f983351b9a3fc64

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

LOG: [clang] Fix -Wunused-variable in CGCall.cpp (NFC)

llvm-project/clang/lib/CodeGen/CGCall.cpp:3226:24:
error: unused variable 'StructSize' [-Werror,-Wunused-variable]
llvm::TypeSize StructSize = CGM.getDataLayout().getTypeAllocSize(STy);
   ^
llvm-project/clang/lib/CodeGen/CGCall.cpp:3227:24:
error: unused variable 'PtrElementSize' [-Werror,-Wunused-variable]
llvm::TypeSize PtrElementSize =
   ^
llvm-project/clang/lib/CodeGen/CGCall.cpp:5313:24:
error: unused variable 'SrcTypeSize' [-Werror,-Wunused-variable]
llvm::TypeSize SrcTypeSize =
   ^
llvm-project/clang/lib/CodeGen/CGCall.cpp:5315:24:
error: unused variable 'DstTypeSize' [-Werror,-Wunused-variable]
llvm::TypeSize DstTypeSize = CGM.getDataLayout().getTypeAllocSize(STy);
   ^
4 errors generated.

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 0d86fcf544d0fd..13f68237b464d6 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3223,8 +3223,9 @@ void CodeGenFunction::EmitFunctionProlog(const 
CGFunctionInfo &FI,
   dyn_cast(ArgI.getCoerceToType());
   if (ArgI.isDirect() && !ArgI.getCanBeFlattened() && STy &&
   STy->getNumElements() > 1) {
-llvm::TypeSize StructSize = CGM.getDataLayout().getTypeAllocSize(STy);
-llvm::TypeSize PtrElementSize =
+[[maybe_unused]] llvm::TypeSize StructSize =
+CGM.getDataLayout().getTypeAllocSize(STy);
+[[maybe_unused]] llvm::TypeSize PtrElementSize =
 CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(Ty));
 if (STy->containsHomogeneousScalableVectorTypes()) {
   assert(StructSize == PtrElementSize &&
@@ -5310,9 +5311,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   dyn_cast(ArgInfo.getCoerceToType());
   if (STy && ArgInfo.isDirect() && !ArgInfo.getCanBeFlattened()) {
 llvm::Type *SrcTy = ConvertTypeForMem(I->Ty);
-llvm::TypeSize SrcTypeSize =
+[[maybe_unused]] llvm::TypeSize SrcTypeSize =
 CGM.getDataLayout().getTypeAllocSize(SrcTy);
-llvm::TypeSize DstTypeSize = CGM.getDataLayout().getTypeAllocSize(STy);
+[[maybe_unused]] llvm::TypeSize DstTypeSize =
+CGM.getDataLayout().getTypeAllocSize(STy);
 if (STy->containsHomogeneousScalableVectorTypes()) {
   assert(SrcTypeSize == DstTypeSize &&
  "Only allow non-fractional movement of structure with "



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


[clang] 570bc5d - Revert "[clang][analyzer] StreamChecker: Model getc, vfscanf, putc, vfprintf (#82476)"

2024-02-28 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2024-02-28T14:10:22+01:00
New Revision: 570bc5d291f92e19f6264262b02ddff1a2f2e09b

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

LOG: Revert "[clang][analyzer] StreamChecker: Model getc, vfscanf, putc, 
vfprintf (#82476)"

This reverts commit ffe7049b543adb9739261d28a60d4a47a00aa2e0.

This commit breaks on e.g. arm:
Example:
https://lab.llvm.org/buildbot/#/builders/245/builds/21177/steps/5/logs/FAIL__Clang__stream_c

```
 TEST 'Clang :: Analysis/stream.c' FAILED 

Exit Code: 1
Command Output (stderr):
--
RUN: at line 1: /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang 
-cc1 -internal-isystem 
/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/19/include 
-nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection -verify 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Analysis/stream.c
+ /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 
-internal-isystem 
/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/19/include 
-nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection -verify 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Analysis/stream.c
error: 'expected-warning' diagnostics expected but not seen:
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Analysis/stream.c 
Line 147: Stream pointer might be NULL
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Analysis/stream.c 
Line 153: Stream pointer might be NULL
error: 'expected-warning' diagnostics seen but not expected:
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Analysis/stream.c 
Line 148: Stream pointer might be NULL [alpha.unix.Stream]
  File 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Analysis/stream.c 
Line 154: Stream pointer might be NULL [alpha.unix.Stream]
4 errors generated.
--

```

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
clang/test/Analysis/Inputs/system-header-simulator.h
clang/test/Analysis/stream-invalidate.c
clang/test/Analysis/stream.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 29956fed2b3c24..65bdc4cac30940 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -348,30 +348,18 @@ class StreamChecker : public CheckergetName().equals("vfscanf")) {
-  SmallVector EscArgs;
-  for (auto EscArg : llvm::seq(2u, Call.getNumArgs()))
-EscArgs.push_back(EscArg);
-  StateNotFailed = escapeArgs(StateNotFailed, C, Call, EscArgs);
-}
+SmallVector EscArgs;
+for (auto EscArg : llvm::seq(2u, Call.getNumArgs()))
+  EscArgs.push_back(EscArg);
+StateNotFailed = escapeArgs(StateNotFailed, C, Call, EscArgs);
 
 if (StateNotFailed)
   C.addTransition(StateNotFailed);

diff  --git 
a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h 
b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
index c26d3582149120..098a2208fecbe9 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
@@ -5,7 +5,7 @@
 // suppressed.
 #pragma clang system_header
 
-typedef struct _FILE {
+typedef struct __sFILE {
   unsigned char *_p;
 } FILE;
 FILE *fopen(const char *restrict, const char *restrict) __asm("_" "fopen" );

diff  --git a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h 
b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
index 720944abb8ad47..7299b61353d460 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
@@ -10,8 +10,6 @@
 #define restrict /*restrict*/
 #endif
 
-typedef struct _FILE FILE;
-
 typedef __builtin_va_list va_list;
 
 #define va_start(ap, param) __builtin_va_start(ap, param)
@@ -23,10 +21,6 @@ int vprintf (const char *restrict format, va_list arg);
 
 int vsprintf (char *restrict s, const char *restrict format, va_list arg);
 
-int vfprintf(FILE *stream, const char *format, va_list ap);
-
-int vfscanf(FILE *stream, const char *format, va_list ap);
-
 int some_library_function(int n, va_list arg);
 
 // No warning from system header.

diff  --git a/clang/t

[clang] [Clang] [Sema] Handle `this` in `__restrict`-qualified member functions properly (PR #83187)

2024-02-28 Thread Aaron Ballman via cfe-commits

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

Thank you for the fix! This seems to fix quite a few issues because it also 
addresses:

https://github.com/llvm/llvm-project/issues/42411
https://github.com/llvm/llvm-project/issues/18121
https://github.com/llvm/llvm-project/issues/11039

(which should be added to test cases if there's something unique there, and 
mentioned in the release notes and commit message).

Otherwise, LGTM!

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


[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-02-28 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang updated 
https://github.com/llvm/llvm-project/pull/83136

>From cdc9ee6c322af0ceed162f3f714bcd0a22e020c3 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Tue, 27 Feb 2024 22:16:38 +0800
Subject: [PATCH 1/2] [X86] Add Support for X86 TLSDESC Relocations

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp|   3 +-
 clang/test/Driver/tls-dialect.c   |   2 +-
 .../lib/Target/X86/MCTargetDesc/X86BaseInfo.h |  14 ++
 llvm/lib/Target/X86/X86AsmPrinter.cpp |   2 +
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  98 +++
 llvm/lib/Target/X86/X86MCInstLower.cpp|  30 +++-
 llvm/test/CodeGen/X86/tls-desc.ll | 165 ++
 7 files changed, 273 insertions(+), 41 deletions(-)
 create mode 100644 llvm/test/CodeGen/X86/tls-desc.ll

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index faceee85a2f8dc..c66e3ee12e50c4 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -740,7 +740,8 @@ bool tools::isTLSDESCEnabled(const ToolChain &TC,
 SupportedArgument = V == "desc" || V == "trad";
 EnableTLSDESC = V == "desc";
   } else if (Triple.isX86()) {
-SupportedArgument = V == "gnu";
+SupportedArgument = V == "gnu" || V == "gnu2";
+EnableTLSDESC = V == "gnu2";
   } else {
 Unsupported = true;
   }
diff --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c
index f73915b28ec2a3..a808dd81531ce7 100644
--- a/clang/test/Driver/tls-dialect.c
+++ b/clang/test/Driver/tls-dialect.c
@@ -2,6 +2,7 @@
 // RUN: %clang -### --target=riscv64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
 // RUN: %clang -### --target=x86_64-linux -mtls-dialect=gnu %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
+// RUN: %clang -### --target=x86_64-linux -mtls-dialect=gnu2 %s 2>&1 | 
FileCheck --check-prefix=DESC %s
 
 /// Android supports TLSDESC by default on RISC-V
 /// TLSDESC is not on by default in Linux, even on RISC-V, and is covered above
@@ -18,7 +19,6 @@
 
 /// Unsupported argument
 // RUN: not %clang -### --target=riscv64-linux -mtls-dialect=gnu2 %s 2>&1 | 
FileCheck --check-prefix=UNSUPPORTED-ARG %s
-// RUN: not %clang -### --target=x86_64-linux -mtls-dialect=gnu2 %s 2>&1 | 
FileCheck --check-prefix=UNSUPPORTED-ARG %s
 
 // DESC:   "-cc1" {{.*}}"-enable-tlsdesc"
 // NODESC-NOT: "-enable-tlsdesc"
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h 
b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
index 4442b80861b61a..1877550f8c40bb 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
@@ -431,6 +431,20 @@ enum TOF {
   /// See 'ELF Handling for Thread-Local Storage' for more details.
   ///SYMBOL_LABEL @TLSLDM
   MO_TLSLDM,
+  /// MO_TLSCALL - On a symbol operand this indicates that the immediate is
+  /// the index of the TLS descriptor function for the symbol. Used in both
+  /// the IA32 and x86-64 local dynamic TLS access model.
+  /// See 'RFC-TLSDESC-x86' for more details.
+  ///SYMBOL_LABEL @TLSCALL
+  MO_TLSCALL,
+  /// MO_TLSDESC - On a symbol operand this indicates that the immediate is
+  /// the index of the TLS descriptor argument for the symbol. When this
+  /// argument is passed to a call getting from index@TLSCALL, the function 
will
+  /// return the offset for the symbol. Used in both the IA32 and x86-64 local
+  /// dynamic TLS access model.
+  /// See 'RFC-TLSDESC-x86' for more details.
+  ///SYMBOL_LABEL @TLSDESC
+  MO_TLSDESC,
   /// MO_GOTTPOFF - On a symbol operand this indicates that the immediate is
   /// the offset of the GOT entry with the thread-pointer offset for the
   /// symbol. Used in the x86-64 initial exec TLS access model.
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp 
b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 3395a13545e454..d8e111db1cec42 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -271,6 +271,8 @@ void X86AsmPrinter::PrintSymbolOperand(const MachineOperand 
&MO,
   case X86II::MO_TLSGD: O << "@TLSGD"; break;
   case X86II::MO_TLSLD: O << "@TLSLD"; break;
   case X86II::MO_TLSLDM:O << "@TLSLDM";break;
+  case X86II::MO_TLSDESC:   O << "@TLSDESC";   break;
+  case X86II::MO_TLSCALL:   O << "@TLSCALL";   break;
   case X86II::MO_GOTTPOFF:  O << "@GOTTPOFF";  break;
   case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
   case X86II::MO_TPOFF: O << "@TPOFF"; break;
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index a86f13135173b0..88314bcf510e9a 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -18515,17 +18515,17 @@ X86TargetLowering::LowerGlobalAddress(SDValue Op, 
SelectionDAG &DAG) con

[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-02-28 Thread Phoebe Wang via cfe-commits


@@ -18515,17 +18515,17 @@ X86TargetLowering::LowerGlobalAddress(SDValue Op, 
SelectionDAG &DAG) const {
   return LowerGlobalOrExternal(Op, DAG, /*ForCall=*/false);
 }
 
-static SDValue
-GetTLSADDR(SelectionDAG &DAG, SDValue Chain, GlobalAddressSDNode *GA,
-   SDValue *InGlue, const EVT PtrVT, unsigned ReturnReg,
-   unsigned char OperandFlags, bool LocalDynamic = false) {
+static SDValue GetTLSADDR(SelectionDAG &DAG, SDValue Chain,

phoebewang wrote:

Done.

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


[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-02-28 Thread Phoebe Wang via cfe-commits


@@ -0,0 +1,165 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc < %s -mtriple=i686-unknown-unknown --relocation-model=pic 
-enable-tlsdesc | FileCheck %s --check-prefix=X86

phoebewang wrote:

Done.

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


[clang] a2efb68 - [clang][Interp] Remove now faulty assertion

2024-02-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-28T14:27:25+01:00
New Revision: a2efb68906ec2bf7b55b464060c3713e395e68e5

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

LOG: [clang][Interp] Remove now faulty assertion

We can call getBase() for pointers where Base != Offset as well,
for example when we've added a constant to the Offset.

Added: 


Modified: 
clang/lib/AST/Interp/Pointer.h
clang/test/AST/Interp/cxx11.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index fa2e03d71190f5..34ecdb967960d5 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -215,7 +215,6 @@ class Pointer {
   assert(Offset == PastEndMark && "cannot get base of a block");
   return Pointer(Pointee, Base, 0);
 }
-assert(Offset == Base && "not an inner field");
 unsigned NewBase = Base - getInlineDesc()->Offset;
 return Pointer(Pointee, NewBase, NewBase);
   }

diff  --git a/clang/test/AST/Interp/cxx11.cpp b/clang/test/AST/Interp/cxx11.cpp
index 0a1e0f3fd28e9d..29098ea694c688 100644
--- a/clang/test/AST/Interp/cxx11.cpp
+++ b/clang/test/AST/Interp/cxx11.cpp
@@ -22,3 +22,9 @@ int array2[recurse2]; // both-warning {{variable length 
arrays in C++}} \
   // both-note {{initializer of 'recurse2' is not a 
constant expression}} \
   // expected-error {{variable length array declaration 
not allowed at file scope}} \
   // ref-warning {{variable length array folded to 
constant array as an extension}}
+
+struct S {
+  int m;
+};
+constexpr S s = { 5 };
+constexpr const int *p = &s.m + 1;



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


[clang] [Clang][HTO] Add clang attribute for propagating llvm-level information (PR #83059)

2024-02-28 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Hm actually reopening, the metadata isn't emitted if the defnition isn't 
> available [e.g. for `extern int X;` when given an annotation

That seems like a bug (so long as the declaration is actually emitted to LLVM 
IR at all).

> @AaronBallman @erichkeane, do you have any suggestions for paths forward, for 
> use cases where it is guaranteed that the attribute is valid and the user (or 
> perhaps more specifically, another Clang-tool) needs to provide information 
> to LLVM through Clang AST/source.

If it's a Clang-based tool, that might open up other options. I think it could 
be reasonable to have an internal-use-only Clang attribute (one with no 
`Spelling` so users have no way to access it) that wraps LLVM IR attributes. 
You could use `MySpecialLLVMAttr::CreateImplicit()` to create the attributes 
as-needed from within the tool, rather than modifying source code and feeding 
it in to the compiler. Would that perhaps be workable for you? (No idea what 
@erichkeane thinks of this idea, but if we went this route, I would want a nice 
comment on the attribute definition explaining why it intentionally has no 
spelling so nobody comes along later and adds a spelling for it without 
realizing the concerns.)

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


[clang] [llvm] [AArch64] [SVE] Created intrinsics for DUPQ instr. (PR #83260)

2024-02-28 Thread via cfe-commits

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

This patch adds clang and llvm support for following intrinsic and maps it to 
DUPQ instruction:
```
   // Variants are also available for:
   // _s8, _u16, _s16, _u32, _s32, _u64, _s64
   // _bf16, _f16, _f32, _f64
   svuint8_t svdup_laneq[_u8](svuint8_t zn, uint64_t imm_idx);
```

>From c5bceafca67d15bad05afa17ac8875421e4259a3 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 21 Feb 2024 11:11:45 +
Subject: [PATCH] [AArch64] [SVE] Created intrinsics for DUPQ instr.

This patch adds 'svdup_laneq[_{d}]' intrinsics and maps them to DUPQ 
instruction.
---
 clang/include/clang/Basic/arm_sve.td  |   9 +
 .../acle_sve2p1_dupq.c| 213 ++
 llvm/include/llvm/IR/IntrinsicsAArch64.td |   7 +
 .../lib/Target/AArch64/AArch64SVEInstrInfo.td |   2 +-
 llvm/lib/Target/AArch64/SVEInstrFormats.td|  12 +-
 .../CodeGen/AArch64/sve2p1-intrinsics-dupq.ll |  83 +++
 6 files changed, 324 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dupq.c
 create mode 100644 llvm/test/CodeGen/AArch64/sve2p1-intrinsics-dupq.ll

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 6da30e08e7521e..6cc249837d3f3d 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2215,6 +2215,15 @@ let TargetGuard = "sve2p1" in {
   def SVTBXQ : SInst<"svtbxq[_{d}]", "dddu", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_tbxq">;
   // EXTQ
   def EXTQ : SInst<"svextq[_{d}]", "dddk", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_extq", [], [ImmCheck<2, ImmCheck0_15>]>;
+  // DUPQ
+  def SVDUP_LANEQ_B  : SInst<"svdup_laneq[_{d}]", "ddi",  "cUc", MergeNone, 
"aarch64_sve_dup_laneq", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_15>]>;
+  def SVDUP_LANEQ_H  : SInst<"svdup_laneq[_{d}]", "ddi",  "sUsh", MergeNone, 
"aarch64_sve_dup_laneq", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_7>]>;
+  def SVDUP_LANEQ_S  : SInst<"svdup_laneq[_{d}]", "ddi",  "iUif", MergeNone, 
"aarch64_sve_dup_laneq", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_3>]>;
+  def SVDUP_LANEQ_D  : SInst<"svdup_laneq[_{d}]", "ddi",  "lUld", MergeNone, 
"aarch64_sve_dup_laneq", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_1>]>;
+
+  let TargetGuard = "bf16" in {
+def SVDUP_LANEQ_BF16  : SInst<"svdup_laneq[_{d}]", "ddi",  "b", MergeNone, 
"aarch64_sve_dup_laneq", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_7>]>;
+  }
   // PMOV
   // Move to Pred
   multiclass PMOV_TO_PRED flags=[], ImmCheckType immCh > {
diff --git a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dupq.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dupq.c
new file mode 100644
index 00..587a67aa6b7ca2
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dupq.c
@@ -0,0 +1,213 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +bf16\
+// RUN:   -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +bf16\
+// RUN:   -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +bf16\
+// RUN:   -S -Werror -emit-llvm -disable-O0-optnone -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +bf16\
+// RUN:   -S -Werror -emit-llvm -disable-O0-optnone -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +bf16 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1, A2_UNUSED) A1
+#else
+#define SVE_ACLE_FUNC(A1, A2) A1##A2
+#endif
+
+// CHECK-LABEL: define dso_local  @test_svdup_laneq_s8
+// CHECK-SAME: ( [[ZN:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.dup.laneq.nxv16i8( [[ZN]], i32 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: define dso_local  
@_Z19test_svdup_laneq_s8u10__SVInt8_t
+// CPP-CHECK-SAME: ( [[ZN:%.*]]) #[[ATTR0:[0-9]+]] {
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.dup.laneq.nxv16i8( [[ZN]], i3

[clang] [llvm] [AArch64] [SVE] Created intrinsics for DUPQ instr. (PR #83260)

2024-02-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Lukacma)


Changes

This patch adds clang and llvm support for following intrinsic and maps it to 
DUPQ instruction:
```
   // Variants are also available for:
   // _s8, _u16, _s16, _u32, _s32, _u64, _s64
   // _bf16, _f16, _f32, _f64
   svuint8_t svdup_laneq[_u8](svuint8_t zn, uint64_t imm_idx);
```

---

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


6 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+9) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dupq.c 
(+213) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+7) 
- (modified) llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/SVEInstrFormats.td (+11-1) 
- (added) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-dupq.ll (+83) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 6da30e08e7521e..6cc249837d3f3d 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2215,6 +2215,15 @@ let TargetGuard = "sve2p1" in {
   def SVTBXQ : SInst<"svtbxq[_{d}]", "dddu", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_tbxq">;
   // EXTQ
   def EXTQ : SInst<"svextq[_{d}]", "dddk", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_extq", [], [ImmCheck<2, ImmCheck0_15>]>;
+  // DUPQ
+  def SVDUP_LANEQ_B  : SInst<"svdup_laneq[_{d}]", "ddi",  "cUc", MergeNone, 
"aarch64_sve_dup_laneq", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_15>]>;
+  def SVDUP_LANEQ_H  : SInst<"svdup_laneq[_{d}]", "ddi",  "sUsh", MergeNone, 
"aarch64_sve_dup_laneq", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_7>]>;
+  def SVDUP_LANEQ_S  : SInst<"svdup_laneq[_{d}]", "ddi",  "iUif", MergeNone, 
"aarch64_sve_dup_laneq", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_3>]>;
+  def SVDUP_LANEQ_D  : SInst<"svdup_laneq[_{d}]", "ddi",  "lUld", MergeNone, 
"aarch64_sve_dup_laneq", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_1>]>;
+
+  let TargetGuard = "bf16" in {
+def SVDUP_LANEQ_BF16  : SInst<"svdup_laneq[_{d}]", "ddi",  "b", MergeNone, 
"aarch64_sve_dup_laneq", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_7>]>;
+  }
   // PMOV
   // Move to Pred
   multiclass PMOV_TO_PRED flags=[], ImmCheckType immCh > {
diff --git a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dupq.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dupq.c
new file mode 100644
index 00..587a67aa6b7ca2
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dupq.c
@@ -0,0 +1,213 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +bf16\
+// RUN:   -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +bf16\
+// RUN:   -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +bf16\
+// RUN:   -S -Werror -emit-llvm -disable-O0-optnone -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +bf16\
+// RUN:   -S -Werror -emit-llvm -disable-O0-optnone -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +bf16 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1, A2_UNUSED) A1
+#else
+#define SVE_ACLE_FUNC(A1, A2) A1##A2
+#endif
+
+// CHECK-LABEL: define dso_local  @test_svdup_laneq_s8
+// CHECK-SAME: ( [[ZN:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.dup.laneq.nxv16i8( [[ZN]], i32 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: define dso_local  
@_Z19test_svdup_laneq_s8u10__SVInt8_t
+// CPP-CHECK-SAME: ( [[ZN:%.*]]) #[[ATTR0:[0-9]+]] {
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.dup.laneq.nxv16i8( [[ZN]], i32 0)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint8_t test_svdup_laneq_s8(svint8_t zn) {
+return SVE_ACLE_FUNC(svdup_laneq, _s8)(zn, 0);
+}
+
+// CHECK-LABEL: define dso_local  @test_svdup_laneq_u8
+// CHECK-SAME: ( [[ZN:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[

[clang] [Clang][Sema] placement new initializes typedef array with correct size (PR #83124)

2024-02-28 Thread via cfe-commits

https://github.com/mahtohappy updated 
https://github.com/llvm/llvm-project/pull/83124

>From 991ca334f7efb4a7fc1e184ab6b4603db681b863 Mon Sep 17 00:00:00 2001
From: mahtohappy 
Date: Tue, 27 Feb 2024 03:13:51 -0800
Subject: [PATCH] [Clang][Sema] placement new initializes typedef array with
 correct size

---
 clang/lib/Sema/TreeTransform.h| 14 +-
 .../instantiate-new-placement-size.cpp| 19 +++
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/instantiate-new-placement-size.cpp

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 7389a48fe56fcc..0cda78650fcc83 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -12669,6 +12669,19 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr 
*E) {
 ArraySize = NewArraySize.get();
   }
 
+  // Per C++0x [expr.new]p5, the type being constructed may be a
+  // typedef of an array type.
+  QualType AllocType = AllocTypeInfo->getType();
+  if (ArraySize) {
+if (const ConstantArrayType *Array =
+SemaRef.Context.getAsConstantArrayType(AllocType)) {
+  ArraySize = IntegerLiteral::Create(SemaRef.Context, Array->getSize(),
+ SemaRef.Context.getSizeType(),
+ E->getBeginLoc());
+  AllocType = Array->getElementType();
+}
+  }
+
   // Transform the placement arguments (if any).
   bool ArgumentChanged = false;
   SmallVector PlacementArgs;
@@ -12730,7 +12743,6 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr 
*E) {
 return E;
   }
 
-  QualType AllocType = AllocTypeInfo->getType();
   if (!ArraySize) {
 // If no array size was specified, but the new expression was
 // instantiated with an array type (e.g., "new T" where T is
diff --git a/clang/test/SemaCXX/instantiate-new-placement-size.cpp 
b/clang/test/SemaCXX/instantiate-new-placement-size.cpp
new file mode 100644
index 00..bad162ffe7c42f
--- /dev/null
+++ b/clang/test/SemaCXX/instantiate-new-placement-size.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang -S -fno-discard-value-names -emit-llvm -o - %s | FileCheck %s
+#include 
+
+// CHECK: call void @llvm.memset.p0.i64(ptr align 1 %x, i8 0, i64 8, i1 false)
+// CHECK: call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 32, i1 
false)
+template 
+void f()
+{
+typedef TYPE TArray[8];
+
+TArray x;
+new(&x) TArray();
+}
+
+int main()
+{
+f();
+f();
+}

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


[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-02-28 Thread Phoebe Wang via cfe-commits


@@ -0,0 +1,165 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc < %s -mtriple=i686-unknown-unknown --relocation-model=pic 
-enable-tlsdesc | FileCheck %s --check-prefix=X86
+; RUN: llc < %s -mtriple=x86_64-pc-linux-gnux32 --relocation-model=pic 
-enable-tlsdesc | FileCheck %s --check-prefix=X32
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown --relocation-model=pic 
-enable-tlsdesc | FileCheck %s --check-prefix=X64
+
+@x = thread_local global i32 0, align 4
+@y = internal thread_local global i32 0, align 4

phoebewang wrote:

Thanks for the info! In that way, we need to define a new pseudo instruction 
that only clobbers the two register.
I'll try to do it in the next reversion.

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


[clang] [OpenMP] Clang Codegen Interop : Accept multiple init (PR #82604)

2024-02-28 Thread Alexey Bataev via cfe-commits


@@ -7023,19 +7023,25 @@ void CodeGenFunction::EmitOMPInteropDirective(const 
OMPInteropDirective &S) {
  S.getSingleClause())) &&
  "OMPNowaitClause clause is used separately in OMPInteropDirective.");
 
-  if (const auto *C = S.getSingleClause()) {
-llvm::Value *InteropvarPtr =
-EmitLValue(C->getInteropVar()).getPointer(*this);
-llvm::omp::OMPInteropType InteropType = llvm::omp::OMPInteropType::Unknown;
-if (C->getIsTarget()) {
-  InteropType = llvm::omp::OMPInteropType::Target;
-} else {
-  assert(C->getIsTargetSync() && "Expected interop-type 
target/targetsync");
-  InteropType = llvm::omp::OMPInteropType::TargetSync;
+  auto It = S.getClausesOfKind();
+  if (!It.empty()) {
+// Look at the multiple init clauses
+for (const class OMPInitClause *C : It) {

alexey-bataev wrote:

Drop 'class', it won't compile

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


[clang] [Clang][Sema] Fix missing warning when comparing mismatched enums in … (PR #81418)

2024-02-28 Thread Erich Keane via cfe-commits

erichkeane wrote:

> For what it's worth, this change adds several instances of 
> `-Wenum-enum-conversion` for the Linux kernel: 
> [ClangBuiltLinux/linux#2002](https://github.com/ClangBuiltLinux/linux/issues/2002).
>  I assume this is intentional given the nature of the change as a whole but 
> neither the tests nor the release notes seem to really reflect that. In case 
> it is a bug that this change affected that, consider this a report :)

You're correct, those are intentional.  
`https://github.com/llvm/llvm-project/pull/81418/files#diff-f240d794093a226da48919a27929148597edd1460a1d38b0decbced3fc153ddc`
  specifically covers 'conversions' but arithmetic operations are also covered 
by that warning. 

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


[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)

2024-02-28 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev commented:

One big question - why do we need it in function scope for clang?

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


[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)

2024-02-28 Thread Alexey Bataev via cfe-commits


@@ -23352,6 +23352,15 @@ void Sema::ActOnOpenMPDeclareTargetName(NamedDecl *ND, 
SourceLocation Loc,
   isa(ND)) &&
  "Expected variable, function or function template.");
 
+  if (auto *VD = dyn_cast(ND)) {

alexey-bataev wrote:

checkDeclIsAllowedInOpenMPTarget should handle it

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


[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)

2024-02-28 Thread Alexey Bataev via cfe-commits


@@ -11326,6 +11326,9 @@ def err_omp_device_type_mismatch : Error<
 def err_omp_wrong_device_function_call : Error<
   "function with 'device_type(%0)' is not available on %select{device|host}1">;
 def note_omp_marked_device_type_here : Note<"marked as 'device_type(%0)' 
here">;
+def warn_omp_declare_target_has_local_vars : Warning<
+  "local variable '%0' ignored in 'declare target' directive; ">,
+  InGroup;

alexey-bataev wrote:

I assume this must be the error message, since OpenMP has a restriction that 
the variable declared in the directive must have static storage duration.

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


[clang] [OpenMP] Parse and Sema support for declare target in local scope (PR #83223)

2024-02-28 Thread Alexey Bataev via cfe-commits

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


[clang] [Clang][Sema] Fix the lambda call expression inside of a type alias declaration (PR #82310)

2024-02-28 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

I don't have any concerns, but want @cor3ntin to take a look.  He's under the 
weather at the moment, so he might be a few days.

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


[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Vinayak Dev via cfe-commits

https://github.com/vinayakdsci updated 
https://github.com/llvm/llvm-project/pull/83152

>From 0e9d7e7ed96feb8c32be33ca9b1262bba32ab8b4 Mon Sep 17 00:00:00 2001
From: Vinayak Dev 
Date: Tue, 27 Feb 2024 18:05:29 +0530
Subject: [PATCH] [Clang][Sema]: Diagnose lambda to bool implicit casts

---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/SemaChecking.cpp| 18 ++
 clang/test/CXX/drs/dr18xx.cpp  |  5 +
 .../expr/expr.prim/expr.prim.lambda/blocks.mm  |  9 +
 clang/test/SemaCXX/warn-bool-conversion.cpp| 14 ++
 5 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e16b9f0c67dbd..a5c6b80c4e99e1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -192,6 +192,9 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses declarative nested name specifiers that name alias 
templates.
 
+- Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
+  Fixes `#82512 `_.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0de76ee119cf81..ea0a739af0cca1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16538,6 +16538,24 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
 }
   }
 
+  // Complain if we are converting a lambda expression to a boolean value
+  if (const auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+  if (const auto *MRecordDecl = MCallExpr->getRecordDecl()) {
+if (MRecordDecl->isLambda()) {
+  std::string Str;
+  llvm::raw_string_ostream S(Str);
+
+  E->printPretty(S, nullptr, getPrintingPolicy());
+  Diag(E->getExprLoc(), diag::warn_impcast_pointer_to_bool)
+  << /*FunctionPointerType*/ 1 << S.str() << E->getSourceRange()
+  << Range << IsEqual;
+  return;
+}
+  }
+}
+  }
+
   // Expect to find a single Decl.  Skip anything more complicated.
   ValueDecl *D = nullptr;
   if (DeclRefExpr *R = dyn_cast(E)) {
diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index a7cee4ef8902f9..6fd063e043517b 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -287,6 +287,11 @@ namespace dr1837 { // dr1837: 3.3
   };
 };
   };
+  /* since-cxx11-warning@-6{{address of function '[] {
+struct Local {
+static_assert(sizeof (this->f()) == sizeof(int), "");
+};
+}' will always evaluate to 'true'}} */
 #endif
 }
 
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm 
b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm
index cb56f6816ad036..9041d07e02a5bc 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm
@@ -65,10 +65,10 @@ void nesting() {
 
 namespace overloading {
   void bool_conversion() {
-if ([](){}) {
+if ([](){}) { // expected-warning{{address of function '[]() {\n}' will 
always evaluate to 'true'}}
 }
 
-bool b = []{};
+bool b = []{}; // expected-warning{{address of function '[] {\n}' will 
always evaluate to 'true'}}
 b = (bool)[]{};
   }
 
@@ -108,8 +108,9 @@ void call_with_lambda() {
 using decltype(a)::operator id; // expected-note {{here}}
   } extern d;
 
-  bool r1 = c;
-  bool r2 = d; // expected-error {{private}}
+  bool r1 = c; // expected-warning{{address of function 'c' will always 
evaluate to 'true'}}
+  bool r2 = d; // expected-error {{private}} \
+  expected-warning{{address of function 'd' will always 
evaluate to 'true'}}
 }
 
 namespace PR13117 {
diff --git a/clang/test/SemaCXX/warn-bool-conversion.cpp 
b/clang/test/SemaCXX/warn-bool-conversion.cpp
index c81d52d864f2d2..f95627b8ac0ca5 100644
--- a/clang/test/SemaCXX/warn-bool-conversion.cpp
+++ b/clang/test/SemaCXX/warn-bool-conversion.cpp
@@ -81,6 +81,20 @@ struct S2 {
 
 bool f5();
 bool f6(int);
+#if __cplusplus >= 201103L
+auto f7 = []{};
+auto f8 = [](){};
+
+void foo() {
+  bool b;
+  b = f7; // expected-warning {{address of function 'f7' will always evaluate 
to 'true'}}
+  b = f8; // expected-warning {{address of function 'f8' will always evaluate 
to 'true'}}
+  bool is_true = [](){ return true; };
+/* expected-cxx11-warning@-1{{address of function '[]() {
+return true;
+}' will always evaluate to 'true'}} */
+}
+#endif
 
 void bar() {
   bool b;

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


[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Vinayak Dev via cfe-commits

https://github.com/vinayakdsci updated 
https://github.com/llvm/llvm-project/pull/83152

>From c65c6a379db75eb4bf38578106ba2aa4e894e3d8 Mon Sep 17 00:00:00 2001
From: Vinayak Dev 
Date: Tue, 27 Feb 2024 18:05:29 +0530
Subject: [PATCH] [Clang][Sema]: Diagnose lambda to bool implicit casts

---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/SemaChecking.cpp| 18 ++
 clang/test/CXX/drs/dr18xx.cpp  |  5 +
 .../expr/expr.prim/expr.prim.lambda/blocks.mm  |  9 +
 clang/test/SemaCXX/warn-bool-conversion.cpp| 14 ++
 5 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e16b9f0c67dbd..a5c6b80c4e99e1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -192,6 +192,9 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses declarative nested name specifiers that name alias 
templates.
 
+- Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
+  Fixes `#82512 `_.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0de76ee119cf81..ea0a739af0cca1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16538,6 +16538,24 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
 }
   }
 
+  // Complain if we are converting a lambda expression to a boolean value
+  if (const auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+  if (const auto *MRecordDecl = MCallExpr->getRecordDecl()) {
+if (MRecordDecl->isLambda()) {
+  std::string Str;
+  llvm::raw_string_ostream S(Str);
+
+  E->printPretty(S, nullptr, getPrintingPolicy());
+  Diag(E->getExprLoc(), diag::warn_impcast_pointer_to_bool)
+  << /*FunctionPointerType*/ 1 << S.str() << E->getSourceRange()
+  << Range << IsEqual;
+  return;
+}
+  }
+}
+  }
+
   // Expect to find a single Decl.  Skip anything more complicated.
   ValueDecl *D = nullptr;
   if (DeclRefExpr *R = dyn_cast(E)) {
diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index a7cee4ef8902f9..6fd063e043517b 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -287,6 +287,11 @@ namespace dr1837 { // dr1837: 3.3
   };
 };
   };
+  /* since-cxx11-warning@-6{{address of function '[] {
+struct Local {
+static_assert(sizeof (this->f()) == sizeof(int), "");
+};
+}' will always evaluate to 'true'}} */
 #endif
 }
 
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm 
b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm
index cb56f6816ad036..9041d07e02a5bc 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm
@@ -65,10 +65,10 @@ void nesting() {
 
 namespace overloading {
   void bool_conversion() {
-if ([](){}) {
+if ([](){}) { // expected-warning{{address of function '[]() {\n}' will 
always evaluate to 'true'}}
 }
 
-bool b = []{};
+bool b = []{}; // expected-warning{{address of function '[] {\n}' will 
always evaluate to 'true'}}
 b = (bool)[]{};
   }
 
@@ -108,8 +108,9 @@ void call_with_lambda() {
 using decltype(a)::operator id; // expected-note {{here}}
   } extern d;
 
-  bool r1 = c;
-  bool r2 = d; // expected-error {{private}}
+  bool r1 = c; // expected-warning{{address of function 'c' will always 
evaluate to 'true'}}
+  bool r2 = d; // expected-error {{private}} \
+  expected-warning{{address of function 'd' will always 
evaluate to 'true'}}
 }
 
 namespace PR13117 {
diff --git a/clang/test/SemaCXX/warn-bool-conversion.cpp 
b/clang/test/SemaCXX/warn-bool-conversion.cpp
index c81d52d864f2d2..f95627b8ac0ca5 100644
--- a/clang/test/SemaCXX/warn-bool-conversion.cpp
+++ b/clang/test/SemaCXX/warn-bool-conversion.cpp
@@ -81,6 +81,20 @@ struct S2 {
 
 bool f5();
 bool f6(int);
+#if __cplusplus >= 201103L
+auto f7 = []{};
+auto f8 = [](){};
+
+void foo() {
+  bool b;
+  b = f7; // expected-warning {{address of function 'f7' will always evaluate 
to 'true'}}
+  b = f8; // expected-warning {{address of function 'f8' will always evaluate 
to 'true'}}
+  bool is_true = [](){ return true; };
+/* expected-cxx11-warning@-1{{address of function '[]() {
+return true;
+}' will always evaluate to 'true'}} */
+}
+#endif
 
 void bar() {
   bool b;

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


[clang] [Clang][HTO] Add clang attribute for propagating llvm-level information (PR #83059)

2024-02-28 Thread Erich Keane via cfe-commits

erichkeane wrote:

> > Hm actually reopening, the metadata isn't emitted if the defnition isn't 
> > available [e.g. for `extern int X;` when given an annotation
> 
> That seems like a bug (so long as the declaration is actually emitted to LLVM 
> IR at all).
> 
> > @AaronBallman @erichkeane, do you have any suggestions for paths forward, 
> > for use cases where it is guaranteed that the attribute is valid and the 
> > user (or perhaps more specifically, another Clang-tool) needs to provide 
> > information to LLVM through Clang AST/source.
> 
> If it's a Clang-based tool, that might open up other options. I think it 
> could be reasonable to have an internal-use-only Clang attribute (one with no 
> `Spelling` so users have no way to access it) that wraps LLVM IR attributes. 
> You could use `MySpecialLLVMAttr::CreateImplicit()` to create the attributes 
> as-needed from within the tool, rather than modifying source code and feeding 
> it in to the compiler. Would that perhaps be workable for you? (No idea what 
> @erichkeane thinks of this idea, but if we went this route, I would want a 
> nice comment on the attribute definition explaining why it intentionally has 
> no spelling so nobody comes along later and adds a spelling for it without 
> realizing the concerns.)

I think I'd rather fix the extern declaration issues first, I'm guessing we 
just didn't add it to somewhere.

As far as the 'spelling-less' attribute, I'm not really sure how usable that 
would be, but I've done that trick in the past for a downstream.  Its probably 
OK, though definitely something we need to make sure no one touches.

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


[clang] [analyzer] Removing untrusted buffer size taint warning (PR #68607)

2024-02-28 Thread via cfe-commits

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


[clang] [analyzer] Removing untrusted buffer size taint warning (PR #68607)

2024-02-28 Thread via cfe-commits

https://github.com/NagyDonat commented:

I think this old commit could be merged after some very minor clarifications.

In addition to the changes marked in inline comments, you could also add some 
TODO comments in MallocChecker and CStringChecker to mark the places where we 
want to add the code that would handle these functions.

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


[clang] [analyzer] Removing untrusted buffer size taint warning (PR #68607)

2024-02-28 Thread via cfe-commits


@@ -95,22 +94,23 @@ void testReadStdIn(){
 }
 
 void multipleTaintSources(void) {
-  int x,y,z;
-  scanf("%d", &x); // expected-note {{Taint originated here}}
+  char cmd[2048],file[1024];

NagyDonat wrote:

Bikeshedding: please add a space after the comma (here and elsewhere).

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


[clang] [analyzer] Removing untrusted buffer size taint warning (PR #68607)

2024-02-28 Thread via cfe-commits


@@ -305,15 +305,19 @@ void testGets_s(void) {
 
 void testTaintedBufferSize(void) {
   size_t ts;
+  // malloc, calloc, bcopy, memcpy functions are removed as unconditional sinks
+  // from the GenericTaintChecker's default configuration,
+  // because it generated too many false positives.
+  // We would need more sophisticated handling of these reports to enable
+  // these test-cases again.

NagyDonat wrote:

```suggestion
  // The functions malloc, calloc, bcopy and memcpy are not taint sinks in the
  // default config of GenericTaintChecker (because that would cause too many
  // false positives).
  // FIXME: We should generate warnings when a value passed to these functions
  // is tainted and _can be very large_ (because that's exploitable). This
  // functionality probably belongs to the checkers that do more detailed
  // modeling of these functions (MallocChecker and CStringChecker).
```
The descriptions of changes (like "functions are removed ..., because ...") 
belong to the commit message; in an inline comment you should primarily speak 
about the *current* state of the code (after the commit).

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


[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-28 Thread Erich Keane via cfe-commits


@@ -857,6 +864,36 @@ void AArch64TargetCodeGenInfo::checkFunctionCallABI(
   << Callee->getDeclName();
 }
 
+void AArch64ABIInfo::appendAttributeMangling(TargetClonesAttr *Attr,
+ unsigned Index,
+ raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getFeatureStr(Index), Out);
+}
+
+void AArch64ABIInfo::appendAttributeMangling(StringRef AttrStr,
+ raw_ostream &Out) const {
+  if (AttrStr == "default") {
+Out << ".default";
+return;
+  }
+
+  Out << "._";
+  SmallVector Features;
+  AttrStr.split(Features, "+");
+  for (auto &Feat : Features)
+Feat = Feat.trim();
+
+  // TODO Lexicographical order won't break the ABI if priorities change.

erichkeane wrote:

Usually we do a 'FIXME' if we are going to let this sit a while (allows folks 
to use 'TODO' for personal use).

Also, I don't really get what this is saying, so if this is going to stick 
around, we probably need to clarify it for future visitors.

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


[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Vlad Serebrennikov via cfe-commits


@@ -287,6 +287,11 @@ namespace dr1837 { // dr1837: 3.3
   };
 };
   };
+  /* since-cxx11-warning@-6{{address of function '[] {

Endilll wrote:

Can you convert this to use a marker? We don't want readers to count relative 
offsets. In other words, it should read `since-cxx11-warning@#dr1837-lambda 
{{address of function ...`

You can see an example in the test for 1890.

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


[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Vlad Serebrennikov via cfe-commits

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


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


[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Aaron Ballman via cfe-commits


@@ -16538,6 +16538,24 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
 }
   }
 
+  // Complain if we are converting a lambda expression to a boolean value
+  if (const auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+  if (const auto *MRecordDecl = MCallExpr->getRecordDecl()) {
+if (MRecordDecl->isLambda()) {
+  std::string Str;
+  llvm::raw_string_ostream S(Str);
+
+  E->printPretty(S, nullptr, getPrintingPolicy());
+  Diag(E->getExprLoc(), diag::warn_impcast_pointer_to_bool)
+  << /*FunctionPointerType*/ 1 << S.str() << E->getSourceRange()
+  << Range << IsEqual;
+  return;
+}
+  }
+}
+  }

AaronBallman wrote:

Actually, I'm not convinced we *should* print the entire expression in this 
case. Lambdas usually aren't nearly as trivial as the ones we have in our test 
cases, and can be arbitrarily long. e.g.,
```
C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp:2:7: warning: 
address of function '[]() {
int foo = 0;
return foo;
}' will always evaluate to 'true' [-Wpointer-bool-conversion]
2 |   if ([](){
  |   ~~  ^
3 | // This is a comment
  | 
4 | // intended to make the lambda
  | ~~
5 | // longer so that it shows
  | ~~
6 | // what the diagnostic behavior is
  | ~~
7 | int foo = 0;
  | 
8 | // of really large lambdas, and whether
  | ~~~
9 | // it is worth it to print out the entire
  | ~
   10 | // expression in this case.
  | ~~~
   11 | return foo;
  | ~~~
   12 |   }) {
  |   ~
1 warning generated.
```
This has two problems: 1) it repeats the user's code in both the diagnostic and 
in the highlighting, 2) the amount of context is huge and distracts from the 
diagnostic.

I think we should modify `warn_impcast_pointer_to_bool` to something along 
these lines:
```
def warn_impcast_pointer_to_bool : Warning<
"address of%select{| function| array| lambda function pointer conversion 
operator}0 '%1' will always evaluate to 'true'">, 
InGroup;
```
(Will need to be reformatted for the usual 80-col limits.) And when passing the 
source range for the lambda expression, I think we should pass only the lambda 
introducer as the source range so that we highlight far less code.

WDYT?

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


[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Aaron Ballman via cfe-commits


@@ -16538,6 +16538,24 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
 }
   }
 
+  // Complain if we are converting a lambda expression to a boolean value
+  if (const auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+  if (const auto *MRecordDecl = MCallExpr->getRecordDecl()) {
+if (MRecordDecl->isLambda()) {
+  std::string Str;
+  llvm::raw_string_ostream S(Str);
+
+  E->printPretty(S, nullptr, getPrintingPolicy());
+  Diag(E->getExprLoc(), diag::warn_impcast_pointer_to_bool)
+  << /*FunctionPointerType*/ 1 << S.str() << E->getSourceRange()
+  << Range << IsEqual;
+  return;
+}
+  }
+}
+  }

AaronBallman wrote:

Do you actually need the call to `isRecordType()`? I would have thought this 
was equivalent.
```suggestion
  if (const auto *MCallExpr = dyn_cast(E)) {
if (const auto *MRecordDecl = MCallExpr->getRecordDecl(); MRecordDecl && 
MRecordDecl->isLambda()) {
  std::string Str;
  llvm::raw_string_ostream S(Str);

  E->printPretty(S, nullptr, getPrintingPolicy());
  Diag(E->getExprLoc(), diag::warn_impcast_pointer_to_bool)
  << /*FunctionPointerType*/ 1 << S.str() << E->getSourceRange()
  << Range << IsEqual;
  return;
}
  }
```

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


[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Vinayak Dev via cfe-commits


@@ -16538,6 +16538,24 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
 }
   }
 
+  // Complain if we are converting a lambda expression to a boolean value
+  if (const auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+  if (const auto *MRecordDecl = MCallExpr->getRecordDecl()) {
+if (MRecordDecl->isLambda()) {
+  std::string Str;
+  llvm::raw_string_ostream S(Str);
+
+  E->printPretty(S, nullptr, getPrintingPolicy());
+  Diag(E->getExprLoc(), diag::warn_impcast_pointer_to_bool)
+  << /*FunctionPointerType*/ 1 << S.str() << E->getSourceRange()
+  << Range << IsEqual;
+  return;
+}
+  }
+}
+  }

vinayakdsci wrote:

That is actually a great idea! and then the diagnostic would simply say address 
of lambda function {..} will always evaluate to true. Would actually be more 
informative than printing the entire expression in my opinion. Should I modify 
the code to do this instead??

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


[clang] [llvm] Implement a subset of builtin_cpu_supports() features (PR #82809)

2024-02-28 Thread zhijian lin via cfe-commits

https://github.com/diggerlin updated 
https://github.com/llvm/llvm-project/pull/82809

>From cef79b36bcb3f4b7452d01aafdf111ff0e50605d Mon Sep 17 00:00:00 2001
From: zhijian 
Date: Fri, 23 Feb 2024 13:23:18 -0500
Subject: [PATCH 1/6] Implement a subset of builtin_cpu_supports() features

---
 clang/lib/Basic/Targets/PPC.cpp   |  12 ++
 clang/lib/Basic/Targets/PPC.h |   9 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |  99 ---
 clang/lib/Sema/SemaChecking.cpp   |   6 +-
 clang/test/CodeGen/aix-builtin-cpu-is.c   |   4 +-
 clang/test/CodeGen/aix-builtin-cpu-supports.c | 154 ++
 clang/test/Sema/aix-builtin-cpu-unsupports.c  |  40 -
 .../test/Sema/builtin-cpu-unsupports-AIX-Os.c |   9 +
 .../llvm/TargetParser/PPCTargetParser.def |  73 -
 9 files changed, 369 insertions(+), 37 deletions(-)
 create mode 100644 clang/test/CodeGen/aix-builtin-cpu-supports.c
 create mode 100644 clang/test/Sema/builtin-cpu-unsupports-AIX-Os.c

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index aebe51bfa4daad..17b462c73bfc6a 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -897,6 +897,18 @@ ArrayRef PPCTargetInfo::getTargetBuiltins() 
const {
 }
 
 bool PPCTargetInfo::validateCpuSupports(StringRef FeatureStr) const {
+  llvm::Triple Triple = getTriple();
+  if (Triple.isOSAIX()) {
+#define PPC_AIX_FEATURE(NAME, DESC, SUPPORT_METHOD, INDEX, MASK, OP, VALUE)
\
+  .Case(NAME, true)
+return llvm::StringSwitch(FeatureStr)
+#include "llvm/TargetParser/PPCTargetParser.def"
+.Default(false);
+  }
+
+  assert(Triple.isOSLinux() &&
+ "__builtin_cpu_supports() is only supported for AIX and Linux.");
+
 #define PPC_LNX_FEATURE(NAME, DESC, ENUMNAME, ENUMVAL, HWCAPN) .Case(NAME, 
true)
   return llvm::StringSwitch(FeatureStr)
 #include "llvm/TargetParser/PPCTargetParser.def"
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 70683916a8b04f..39b52d362f36b8 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -364,7 +364,14 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   // have Glibc since it is Glibc that provides the HWCAP[2] in the auxv.
   static constexpr int MINIMUM_AIX_OS_MAJOR = 7;
   static constexpr int MINIMUM_AIX_OS_MINOR = 2;
-  bool supportsCpuSupports() const override { return getTriple().isOSGlibc(); }
+  bool supportsCpuSupports() const override {
+llvm::Triple Triple = getTriple();
+// AIX 7.2 is the minimum requirement to support __builtin_cpu_supports().
+return Triple.isOSGlibc() ||
+   (Triple.isOSAIX() &&
+!Triple.isOSVersionLT(MINIMUM_AIX_OS_MAJOR, MINIMUM_AIX_OS_MINOR));
+  }
+
   bool supportsCpuIs() const override {
 llvm::Triple Triple = getTriple();
 // AIX 7.2 is the minimum requirement to support __builtin_cpu_is().
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 734eb5a035ca49..cf4ddc52ff362a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -16560,7 +16560,7 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 
 #include "llvm/TargetParser/PPCTargetParser.def"
   auto GenAIXPPCBuiltinCpuExpr = [&](unsigned SupportMethod, unsigned FieldIdx,
- unsigned CompOp,
+ unsigned Mask, unsigned CompOp,
  unsigned OpValue) -> Value * {
 if (SupportMethod == AIX_BUILTIN_PPC_FALSE)
   return llvm::ConstantInt::getFalse(ConvertType(E->getType()));
@@ -16568,24 +16568,61 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 if (SupportMethod == AIX_BUILTIN_PPC_TRUE)
   return llvm::ConstantInt::getTrue(ConvertType(E->getType()));
 
-assert(SupportMethod <= USE_SYS_CONF && "Invalid value for 
SupportMethod.");
-assert((CompOp == COMP_EQ) && "Only equal comparisons are supported.");
+assert(SupportMethod <= SYS_CALL && "Invalid value for SupportMethod.");
+
+llvm::Value *FieldValue = nullptr;
+if (SupportMethod == USE_SYS_CONF) {
+  llvm::Type *STy = llvm::StructType::get(PPC_SYSTEMCONFIG_TYPE);
+  llvm::Constant *SysConf =
+  CGM.CreateRuntimeVariable(STy, "_system_configuration");
+
+  // Grab the appropriate field from _system_configuration.
+  llvm::Value *Idxs[] = {ConstantInt::get(Int32Ty, 0),
+ ConstantInt::get(Int32Ty, FieldIdx)};
+
+  FieldValue = Builder.CreateGEP(STy, SysConf, Idxs);
+  FieldValue = Builder.CreateAlignedLoad(Int32Ty, FieldValue,
+ CharUnits::fromQuantity(4));
+} else if (SupportMethod == SYS_CALL) {
+  llvm::FunctionType *FTy =
+  llvm::FunctionType::get(Int64Ty, Int32Ty, false);
+  llvm::FunctionCallee Func =
+  CGM.CreateRuntimeFunc

[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Aaron Ballman via cfe-commits


@@ -16538,6 +16538,24 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
 }
   }
 
+  // Complain if we are converting a lambda expression to a boolean value
+  if (const auto *MCallExpr = dyn_cast(E)) {
+if (MCallExpr->getObjectType()->isRecordType()) {
+  if (const auto *MRecordDecl = MCallExpr->getRecordDecl()) {
+if (MRecordDecl->isLambda()) {
+  std::string Str;
+  llvm::raw_string_ostream S(Str);
+
+  E->printPretty(S, nullptr, getPrintingPolicy());
+  Diag(E->getExprLoc(), diag::warn_impcast_pointer_to_bool)
+  << /*FunctionPointerType*/ 1 << S.str() << E->getSourceRange()
+  << Range << IsEqual;
+  return;
+}
+  }
+}
+  }

AaronBallman wrote:

> Should I modify the code to do this instead??

Yes please!

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


[clang] cb6c0f1 - [clang][Interp] Ignore ArrayDecay ops for null pointers

2024-02-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-28T16:16:03+01:00
New Revision: cb6c0f1d28c0d1915d1ca9a198254e3828af2384

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

LOG: [clang][Interp] Ignore ArrayDecay ops for null pointers

Just don't do anything and let later operations handle the diagnostics.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/cxx11.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index db52f6649c18ba..241d5941e143ee 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1933,7 +1933,7 @@ inline bool ArrayElemPop(InterpState &S, CodePtr OpPC, 
uint32_t Index) {
 inline bool ArrayDecay(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.pop();
 
-  if (Ptr.isDummy()) {
+  if (Ptr.isZero() || Ptr.isDummy()) {
 S.Stk.push(Ptr);
 return true;
   }

diff  --git a/clang/test/AST/Interp/cxx11.cpp b/clang/test/AST/Interp/cxx11.cpp
index 29098ea694c688..993e3618a37848 100644
--- a/clang/test/AST/Interp/cxx11.cpp
+++ b/clang/test/AST/Interp/cxx11.cpp
@@ -28,3 +28,5 @@ struct S {
 };
 constexpr S s = { 5 };
 constexpr const int *p = &s.m + 1;
+
+constexpr const int *np2 = &(*(int(*)[4])nullptr)[0]; // ok



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


[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-28 Thread Alexandros Lamprineas via cfe-commits


@@ -857,6 +864,36 @@ void AArch64TargetCodeGenInfo::checkFunctionCallABI(
   << Callee->getDeclName();
 }
 
+void AArch64ABIInfo::appendAttributeMangling(TargetClonesAttr *Attr,
+ unsigned Index,
+ raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getFeatureStr(Index), Out);
+}
+
+void AArch64ABIInfo::appendAttributeMangling(StringRef AttrStr,
+ raw_ostream &Out) const {
+  if (AttrStr == "default") {
+Out << ".default";
+return;
+  }
+
+  Out << "._";
+  SmallVector Features;
+  AttrStr.split(Features, "+");
+  for (auto &Feat : Features)
+Feat = Feat.trim();
+
+  // TODO Lexicographical order won't break the ABI if priorities change.

labrinea wrote:

I can change this to say FIXME instead and write a more descriptive comment. 
For context please read 
https://github.com/llvm/llvm-project/pull/79316#discussion_r1469932618. It 
shouldn't stick around for long, as soon as we reach a conclusion I can update 
the sorting criteria of this lambda.

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


[clang] [Clang][ARM][AArch64] Add branch protection attributes to the defaults. (PR #83277)

2024-02-28 Thread via cfe-commits

https://github.com/DanielKristofKiss created 
https://github.com/llvm/llvm-project/pull/83277

These attributes are no longer inherited from the module flags, therefore need 
to be added for synthetic functions.

>From 46f0334eb5c5edd15b657429f39f588cc7726072 Mon Sep 17 00:00:00 2001
From: Daniel Kiss 
Date: Wed, 28 Feb 2024 15:18:31 +0100
Subject: [PATCH] Add branch protection attributes to the defaults.

These attributes are no longer inherited from the module flags,
therefore need to be added for synthetic functions.
---
 clang/lib/CodeGen/CGCall.cpp  | 16 ++
 .../CodeGenCXX/arm64-generated-fn-attr.cpp| 30 +++
 2 files changed, 46 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index d05cf1c6e1814e..d677a2e64be77e 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2022,6 +2022,22 @@ static void getTrivialDefaultFunctionAttributes(
 std::tie(Var, Value) = Attr.split('=');
 FuncAttrs.addAttribute(Var, Value);
   }
+
+  TargetInfo::BranchProtectionInfo BPI(LangOpts);
+
+  if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+FuncAttrs.addAttribute("sign-return-address", BPI.getSignReturnAddrStr());
+FuncAttrs.addAttribute(
+"sign-return-address-key",
+BPI.SignKey == LangOptions::SignReturnAddressKeyKind::AKey ? "a_key"
+   : "b_key");
+  }
+  if (BPI.BranchTargetEnforcement)
+FuncAttrs.addAttribute("branch-target-enforcement", "true");
+  if (BPI.BranchProtectionPAuthLR)
+FuncAttrs.addAttribute("branch-protection-pauth-lr", "true");
+  if (BPI.GuardedControlStack)
+FuncAttrs.addAttribute("guarded-control-stack", "true");
 }
 
 /// Merges `target-features` from \TargetOpts and \F, and sets the result in
diff --git a/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp 
b/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp
new file mode 100644
index 00..8daf44abd4f91c
--- /dev/null
+++ b/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple aarch64-none-none -mbranch-target-enforce 
-msign-return-address=all -fcxx-exceptions -fexceptions -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK
+
+// Check that functions generated by clang have the correct attributes
+
+class Example {
+public:
+  Example();
+  int fn();
+};
+
+// Initialization of var1 causes __cxx_global_var_init and __tls_init to be 
generated
+thread_local Example var1;
+extern thread_local Example var2;
+extern void fn();
+
+int testfn() noexcept {
+  // Calling fn in a noexcept function causes __clang_call_terminate to be 
generated
+  fn();
+  // Use of var1 and var2 causes TLS wrapper functions to be generated
+  return var1.fn() + var2.fn();
+}
+
+// CHECK: define {{.*}} @__cxx_global_var_init() [[ATTR1:#[0-9]+]]
+// CHECK: define {{.*}} @__clang_call_terminate({{.*}}) [[ATTR2:#[0-9]+]]
+// CHECK: define {{.*}} @_ZTW4var1() [[ATTR1]]
+// CHECK: define {{.*}} @_ZTW4var2() [[ATTR1]]
+// CHECK: define {{.*}} @__tls_init() [[ATTR1]]
+
+// CHECK: attributes [[ATTR1]] = { 
{{.*}}"branch-target-enforcement"="true"{{.*}}"sign-return-address"="all" 
"sign-return-address-key"="a_key"
+// CHECK: attributes [[ATTR2]] = { 
{{.*}}"branch-target-enforcement"="true"{{.*}}"sign-return-address"="all" 
"sign-return-address-key"="a_key"

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


[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-28 Thread Erich Keane via cfe-commits


@@ -857,6 +864,36 @@ void AArch64TargetCodeGenInfo::checkFunctionCallABI(
   << Callee->getDeclName();
 }
 
+void AArch64ABIInfo::appendAttributeMangling(TargetClonesAttr *Attr,
+ unsigned Index,
+ raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getFeatureStr(Index), Out);
+}
+
+void AArch64ABIInfo::appendAttributeMangling(StringRef AttrStr,
+ raw_ostream &Out) const {
+  if (AttrStr == "default") {
+Out << ".default";
+return;
+  }
+
+  Out << "._";
+  SmallVector Features;
+  AttrStr.split(Features, "+");
+  for (auto &Feat : Features)
+Feat = Feat.trim();
+
+  // TODO Lexicographical order won't break the ABI if priorities change.

erichkeane wrote:

SGTM!

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


[clang] [Clang][ARM][AArch64] Add branch protection attributes to the defaults. (PR #83277)

2024-02-28 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Dani (DanielKristofKiss)


Changes

These attributes are no longer inherited from the module flags, therefore need 
to be added for synthetic functions.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGCall.cpp (+16) 
- (added) clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp (+30) 


``diff
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index d05cf1c6e1814e..d677a2e64be77e 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2022,6 +2022,22 @@ static void getTrivialDefaultFunctionAttributes(
 std::tie(Var, Value) = Attr.split('=');
 FuncAttrs.addAttribute(Var, Value);
   }
+
+  TargetInfo::BranchProtectionInfo BPI(LangOpts);
+
+  if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) {
+FuncAttrs.addAttribute("sign-return-address", BPI.getSignReturnAddrStr());
+FuncAttrs.addAttribute(
+"sign-return-address-key",
+BPI.SignKey == LangOptions::SignReturnAddressKeyKind::AKey ? "a_key"
+   : "b_key");
+  }
+  if (BPI.BranchTargetEnforcement)
+FuncAttrs.addAttribute("branch-target-enforcement", "true");
+  if (BPI.BranchProtectionPAuthLR)
+FuncAttrs.addAttribute("branch-protection-pauth-lr", "true");
+  if (BPI.GuardedControlStack)
+FuncAttrs.addAttribute("guarded-control-stack", "true");
 }
 
 /// Merges `target-features` from \TargetOpts and \F, and sets the result in
diff --git a/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp 
b/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp
new file mode 100644
index 00..8daf44abd4f91c
--- /dev/null
+++ b/clang/test/CodeGenCXX/arm64-generated-fn-attr.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple aarch64-none-none -mbranch-target-enforce 
-msign-return-address=all -fcxx-exceptions -fexceptions -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK
+
+// Check that functions generated by clang have the correct attributes
+
+class Example {
+public:
+  Example();
+  int fn();
+};
+
+// Initialization of var1 causes __cxx_global_var_init and __tls_init to be 
generated
+thread_local Example var1;
+extern thread_local Example var2;
+extern void fn();
+
+int testfn() noexcept {
+  // Calling fn in a noexcept function causes __clang_call_terminate to be 
generated
+  fn();
+  // Use of var1 and var2 causes TLS wrapper functions to be generated
+  return var1.fn() + var2.fn();
+}
+
+// CHECK: define {{.*}} @__cxx_global_var_init() [[ATTR1:#[0-9]+]]
+// CHECK: define {{.*}} @__clang_call_terminate({{.*}}) [[ATTR2:#[0-9]+]]
+// CHECK: define {{.*}} @_ZTW4var1() [[ATTR1]]
+// CHECK: define {{.*}} @_ZTW4var2() [[ATTR1]]
+// CHECK: define {{.*}} @__tls_init() [[ATTR1]]
+
+// CHECK: attributes [[ATTR1]] = { 
{{.*}}"branch-target-enforcement"="true"{{.*}}"sign-return-address"="all" 
"sign-return-address-key"="a_key"
+// CHECK: attributes [[ATTR2]] = { 
{{.*}}"branch-target-enforcement"="true"{{.*}}"sign-return-address"="all" 
"sign-return-address-key"="a_key"

``




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


[clang] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-02-28 Thread via cfe-commits

DanielKristofKiss wrote:

This handles the synthetic function in clang: #83277 

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


[clang] [Clang][ARM][AArch64] Add branch protection attributes to the defaults. (PR #83277)

2024-02-28 Thread Tomas Matheson via cfe-commits

https://github.com/tmatheson-arm approved this pull request.

LGTM

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


[clang] Bugfix for choosing the more specialized overload (PR #83279)

2024-02-28 Thread Botond István Horváth via cfe-commits

https://github.com/HoBoIs created 
https://github.com/llvm/llvm-project/pull/83279

There was a bug in clang where it couldn't choose which overload candidate is 
more specialized if it was comparing a member-function to a non-member 
function. Previously, this was detected as an ambigouity, now clang chooses 
correctly.

This patch fixes the bug by fully implementing CWG2445 and moving the template 
transformation described in [temp.func.order] paragraph 3 from 
isAtLeastAsSpecializedAs to Sema::getMoreSpecializedTemplate so we have the 
transformed parameter list during the whole comperrassion. Also, to be able to 
add the correct type for the implicit object parameter 
Sema::getMoreSpecializedTemplate has new parameters for the object type.

Fixes #74494 and #82509

From 68200ecf3267d1b3940fa73c25c50ee706932a98 Mon Sep 17 00:00:00 2001
From: Botond Istvan Horvath 
Date: Wed, 28 Feb 2024 13:09:15 +0100
Subject: [PATCH] Bugfix for choosing the more specialized overload

There was a bug in clang where it couldn't choose which overload candidate is
more specialized if it was comparing a member-function to a non-member
function. Previously, this was detected as an ambigouity, now clang chooses 
correctly.

This patch fixes the bug by fully implementing CWG2445 and moving the template
transformation described in [temp.func.order] paragraph 3 from
isAtLeastAsSpecializedAs to Sema::getMoreSpecializedTemplate so we have the
transformed parameter list during the whole comperrassion. Also, to be able
to add the correct type for the implicit object parameter
Sema::getMoreSpecializedTemplate has new parameters for the object type.
---
 clang/include/clang/Sema/Sema.h  |   4 +-
 clang/lib/Sema/SemaOverload.cpp  |  12 +-
 clang/lib/Sema/SemaTemplateDeduction.cpp | 263 +++
 3 files changed, 186 insertions(+), 93 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ef4b93fac95ce5..1a2a3a6bebd95e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9463,7 +9463,9 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false);
+  unsigned NumCallArguments2, QualType ObjType1 = {},
+  QualType ObjType2 = {}, bool Reversed = false);
+
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 7d38043890ca20..60138236abf1d8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -10526,14 +10526,24 @@ bool clang::isBetterOverloadCandidate(
   //  according to the partial ordering rules described in 14.5.5.2, or,
   //  if not that,
   if (Cand1IsSpecialization && Cand2IsSpecialization) {
+const auto *ObjContext1 =
+dyn_cast(Cand1.FoundDecl->getDeclContext());
+const auto *ObjContext2 =
+dyn_cast(Cand2.FoundDecl->getDeclContext());
 if (FunctionTemplateDecl *BetterTemplate = S.getMoreSpecializedTemplate(
 Cand1.Function->getPrimaryTemplate(),
 Cand2.Function->getPrimaryTemplate(), Loc,
 isa(Cand1.Function) ? TPOC_Conversion
: TPOC_Call,
 Cand1.ExplicitCallArguments, Cand2.ExplicitCallArguments,
-Cand1.isReversed() ^ Cand2.isReversed()))
+ObjContext1 ? QualType(ObjContext1->getTypeForDecl(), 0)
+: QualType{},
+ObjContext2 ? QualType(ObjContext2->getTypeForDecl(), 0)
+: QualType{},
+Cand1.isReversed() ^ Cand2.isReversed())) {
   return BetterTemplate == Cand1.Function->getPrimaryTemplate();
+}
+
   }
 
   //   -— F1 and F2 are non-template functions with the same
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 563491f76f5478..2af3c29ae1f1c4 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5333,11 +5333,31 @@ bool 
Sema::CheckIfFunctionSpecializationIsImmediate(FunctionDecl *FD,
   return false;
 }
 
+static QualType GetImplicitObjectParameterTypeCXX20(ASTContext &Context,
+const CXXMethodDecl 
*Method,
+QualType rawType,
+bool isOtherRvr) {
+  // C++20 [temp.func.order]p3.1, p3.2:
+  //- The type X(M ) is “rvalue reference to cv A” if the optional 
ref-qualifier
+  //  of M is && or if M has no ref-qualifier and the 
positionally-corresponding
+  //  parameter of th

[clang] [NFC][ARM][AArch64] Deduplicated code. (PR #82785)

2024-02-28 Thread Tomas Matheson via cfe-commits


@@ -1369,13 +1369,20 @@ class TargetInfo : public TransferrableTargetInfo,
   }
 
   struct BranchProtectionInfo {
-LangOptions::SignReturnAddressScopeKind SignReturnAddr =
-LangOptions::SignReturnAddressScopeKind::None;
-LangOptions::SignReturnAddressKeyKind SignKey =
-LangOptions::SignReturnAddressKeyKind::AKey;
-bool BranchTargetEnforcement = false;
-bool BranchProtectionPAuthLR = false;
-bool GuardedControlStack = false;
+LangOptions::SignReturnAddressScopeKind SignReturnAddr;
+LangOptions::SignReturnAddressKeyKind SignKey;
+bool BranchTargetEnforcement;
+bool BranchProtectionPAuthLR;
+bool GuardedControlStack;
+
+BranchProtectionInfo() = default;
+
+const char *getSignReturnAddrStr() const {
+  static const char *SignReturnAddrStr[] = {"none", "non-leaf", "all"};
+  assert(static_cast(SignReturnAddr) <= 2 &&
+ "Unexpected SignReturnAddressScopeKind");
+  return SignReturnAddrStr[static_cast(SignReturnAddr)];
+}

tmatheson-arm wrote:

```suggestion
const char *getSignReturnAddrStr() const {
switch (SignReturnAddr) {
  case None:
return "none";
  case NonLeaf:
return "non-leaf";
  case All:
return "all";
  }
  assert(false && "Unexpected SignReturnAddressScopeKind");
}
```

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


[clang] [clang] Bugfix for choosing the more specialized overload (PR #83279)

2024-02-28 Thread Botond István Horváth via cfe-commits

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


[clang] [clang] Bugfix for choosing the more specialized overload (PR #83279)

2024-02-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Botond István Horváth (HoBoIs)


Changes

There was a bug in clang where it couldn't choose which overload candidate is 
more specialized if it was comparing a member-function to a non-member 
function. Previously, this was detected as an ambigouity, now clang chooses 
correctly.

This patch fixes the bug by fully implementing CWG2445 and moving the template 
transformation described in [temp.func.order] paragraph 3 from 
isAtLeastAsSpecializedAs to Sema::getMoreSpecializedTemplate so we have the 
transformed parameter list during the whole comperrassion. Also, to be able to 
add the correct type for the implicit object parameter 
Sema::getMoreSpecializedTemplate has new parameters for the object type.

Fixes #74494 and #82509

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


3 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+3-1) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+11-1) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+172-91) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ef4b93fac95ce5..1a2a3a6bebd95e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9463,7 +9463,9 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false);
+  unsigned NumCallArguments2, QualType ObjType1 = {},
+  QualType ObjType2 = {}, bool Reversed = false);
+
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 7d38043890ca20..60138236abf1d8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -10526,14 +10526,24 @@ bool clang::isBetterOverloadCandidate(
   //  according to the partial ordering rules described in 14.5.5.2, or,
   //  if not that,
   if (Cand1IsSpecialization && Cand2IsSpecialization) {
+const auto *ObjContext1 =
+dyn_cast(Cand1.FoundDecl->getDeclContext());
+const auto *ObjContext2 =
+dyn_cast(Cand2.FoundDecl->getDeclContext());
 if (FunctionTemplateDecl *BetterTemplate = S.getMoreSpecializedTemplate(
 Cand1.Function->getPrimaryTemplate(),
 Cand2.Function->getPrimaryTemplate(), Loc,
 isa(Cand1.Function) ? TPOC_Conversion
: TPOC_Call,
 Cand1.ExplicitCallArguments, Cand2.ExplicitCallArguments,
-Cand1.isReversed() ^ Cand2.isReversed()))
+ObjContext1 ? QualType(ObjContext1->getTypeForDecl(), 0)
+: QualType{},
+ObjContext2 ? QualType(ObjContext2->getTypeForDecl(), 0)
+: QualType{},
+Cand1.isReversed() ^ Cand2.isReversed())) {
   return BetterTemplate == Cand1.Function->getPrimaryTemplate();
+}
+
   }
 
   //   -— F1 and F2 are non-template functions with the same
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 563491f76f5478..2af3c29ae1f1c4 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5333,11 +5333,31 @@ bool 
Sema::CheckIfFunctionSpecializationIsImmediate(FunctionDecl *FD,
   return false;
 }
 
+static QualType GetImplicitObjectParameterTypeCXX20(ASTContext &Context,
+const CXXMethodDecl 
*Method,
+QualType rawType,
+bool isOtherRvr) {
+  // C++20 [temp.func.order]p3.1, p3.2:
+  //- The type X(M ) is “rvalue reference to cv A” if the optional 
ref-qualifier
+  //  of M is && or if M has no ref-qualifier and the 
positionally-corresponding
+  //  parameter of the other transformed template has rvalue reference type;
+  //  if this determination depends recursively upon whether X(M ) is an rvalue
+  //  reference type, it is not considered to have rvalue reference type.
+  //- Otherwise, X(M ) is “lvalue reference to cv A”.
+  assert(Method && !Method->isExplicitObjectMemberFunction() &&
+ "expected a member function with no explicit object parameter");
+
+  rawType = Context.getQualifiedType(rawType, Method->getMethodQualifiers());
+  if (Method->getRefQualifier() == RQ_RValue ||
+  (isOtherRvr && Method->getRefQualifier() == RQ_None))
+return Context.getRValueReferenceType(rawType);
+  return Context.getLValueReferenceType(rawType);
+}
+
 /// If this is a non-static member function,
-static void
-AddImplicitObjectParameterType(ASTContext &

[clang] [clang][fat-lto-objects] Make module flags match non-FatLTO pipelines (PR #83159)

2024-02-28 Thread Teresa Johnson via cfe-commits

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


[clang] [clang][fat-lto-objects] Make module flags match non-FatLTO pipelines (PR #83159)

2024-02-28 Thread Teresa Johnson via cfe-commits

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


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


[clang] [clang][fat-lto-objects] Make module flags match non-FatLTO pipelines (PR #83159)

2024-02-28 Thread Teresa Johnson via cfe-commits


@@ -1036,7 +1041,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   if (!actionRequiresCodeGen(Action) && CodeGenOpts.VerifyModule)
 MPM.addPass(VerifierPass());
 
-  if (Action == Backend_EmitBC || Action == Backend_EmitLL) {
+  if (Action == Backend_EmitBC || Action == Backend_EmitLL ||
+  CodeGenOpts.FatLTO) {

teresajohnson wrote:

I see, I guess then the check for the CodeGenOpt is needed here to catch this 
case.

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


[clang] [clang] Bugfix for choosing the more specialized overload (PR #83279)

2024-02-28 Thread Botond István Horváth via cfe-commits

HoBoIs wrote:

@zygoloid @erichkeane Could you take a look?

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


[clang] [Clang][Sema]: Diagnose lambda to bool implicit casts (PR #83152)

2024-02-28 Thread Vinayak Dev via cfe-commits

https://github.com/vinayakdsci updated 
https://github.com/llvm/llvm-project/pull/83152

>From 613e7c0698f16292bb408be832c7ab3647f17195 Mon Sep 17 00:00:00 2001
From: Vinayak Dev 
Date: Tue, 27 Feb 2024 18:05:29 +0530
Subject: [PATCH] [Clang][Sema]: Diagnose lambda to bool implicit casts

---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/include/clang/Basic/DiagnosticSemaKinds.td  |  4 ++--
 clang/lib/Sema/SemaChecking.cpp   | 15 +++
 clang/test/CXX/drs/dr18xx.cpp |  7 ++-
 .../CXX/expr/expr.prim/expr.prim.lambda/blocks.mm |  9 +
 clang/test/SemaCXX/warn-bool-conversion.cpp   | 14 ++
 6 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e16b9f0c67dbd..a5c6b80c4e99e1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -192,6 +192,9 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses declarative nested name specifiers that name alias 
templates.
 
+- Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
+  Fixes `#82512 `_.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c8141fefb8edba..1fd450237e0266 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4127,8 +4127,8 @@ def ext_ms_impcast_fn_obj : ExtWarn<
   "Microsoft extension">, InGroup;
 
 def warn_impcast_pointer_to_bool : Warning<
-"address of%select{| function| array}0 '%1' will always evaluate to "
-"'true'">,
+"address of%select{| function| array| lambda function pointer conversion 
operator}0 '%1' "
+"will always evaluate to 'true'">,
 InGroup;
 def warn_cast_nonnull_to_bool : Warning<
 "nonnull %select{function call|parameter}0 '%1' will evaluate to "
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0de76ee119cf81..1ce7f0044103fc 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16538,6 +16538,21 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
 }
   }
 
+  // Complain if we are converting a lambda expression to a boolean value
+  if (const auto *MCallExpr = dyn_cast(E)) {
+if (const auto *MRecordDecl = MCallExpr->getRecordDecl();
+MRecordDecl && MRecordDecl->isLambda()) {
+  std::string Str;
+  llvm::raw_string_ostream S(Str);
+
+  E->printPretty(S, nullptr, getPrintingPolicy());
+  Diag(E->getExprLoc(), diag::warn_impcast_pointer_to_bool)
+  << /*LambdaPointerConversionOperatorType*/ 3 << S.str()
+  << MRecordDecl->getSourceRange() << Range << IsEqual;
+  return;
+}
+  }
+
   // Expect to find a single Decl.  Skip anything more complicated.
   ValueDecl *D = nullptr;
   if (DeclRefExpr *R = dyn_cast(E)) {
diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index a7cee4ef8902f9..d69698c5e27fdb 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -281,12 +281,17 @@ namespace dr1837 { // dr1837: 3.3
 
   struct A {
 int f();
-bool b = [] {
+bool b = [] { // #dr1837-a
   struct Local {
 static_assert(sizeof(this->f()) == sizeof(int), "");
   };
 };
   };
+  /* since-cxx11-warning@#dr1837-a{{address of lambda function pointer 
conversion operator '[] {
+struct Local {
+static_assert(sizeof (this->f()) == sizeof(int), "");
+};
+}' will always evaluate to 'true'}} */
 #endif
 }
 
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm 
b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm
index cb56f6816ad036..0e27075a2a2597 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm
@@ -65,10 +65,10 @@ void nesting() {
 
 namespace overloading {
   void bool_conversion() {
-if ([](){}) {
+if ([](){}) { // expected-warning{{address of lambda function pointer 
conversion operator '[]() {\n}' will always evaluate to 'true'}}
 }
 
-bool b = []{};
+bool b = []{}; // expected-warning{{address of lambda function pointer 
conversion operator '[] {\n}' will always evaluate to 'true'}}
 b = (bool)[]{};
   }
 
@@ -108,8 +108,9 @@ void call_with_lambda() {
 using decltype(a)::operator id; // expected-note {{here}}
   } extern d;
 
-  bool r1 = c;
-  bool r2 = d; // expected-error {{private}}
+  bool r1 = c; // expected-warning{{address of lambda function pointer 
conversion operator 'c' will always evaluate to 'true'}}
+  bool r2 = d; // expected-error {{private}} \
+  expected-warning{{address of lambda function pointer 
conversion op

[clang] [clang] Bugfix for choosing the more specialized overload (PR #83279)

2024-02-28 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 8e51b22ce21b01ae0be8267c5da3703ffd3b2c5b 
68200ecf3267d1b3940fa73c25c50ee706932a98 -- clang/include/clang/Sema/Sema.h 
clang/lib/Sema/SemaOverload.cpp clang/lib/Sema/SemaTemplateDeduction.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 60138236ab..74d714ad30 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -10543,7 +10543,6 @@ bool clang::isBetterOverloadCandidate(
 Cand1.isReversed() ^ Cand2.isReversed())) {
   return BetterTemplate == Cand1.Function->getPrimaryTemplate();
 }
-
   }
 
   //   -— F1 and F2 are non-template functions with the same

``




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


[clang] Reapply "[clang][analyzer] StreamChecker: Model getc, vfscanf, putc, … (PR #83281)

2024-02-28 Thread Alejandro Álvarez Ayllón via cfe-commits

https://github.com/alejandro-alvarez-sonarsource created 
https://github.com/llvm/llvm-project/pull/83281

…vfprintf (#82476)"

`va_list` is a platform-specific type. On some, it is a struct instead of a 
pointer to a struct, so `lookupFn` was ignoring calls to `vfprintf` and 
`vfscanf`.

`stream.c` now runs in four different platforms to make sure the logic works 
across targets.

This reverts commit 570bc5d291f92e19f6264262b02ddff1a2f2e09b.



From ddbe895e3d2893060ac54bc6c984eea22e09b460 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 
Date: Wed, 28 Feb 2024 16:43:25 +0100
Subject: [PATCH] Reapply "[clang][analyzer] StreamChecker: Model getc,
 vfscanf, putc, vfprintf (#82476)"

This reverts commit 570bc5d291f92e19f6264262b02ddff1a2f2e09b.
---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp |  34 +-
 ...ystem-header-simulator-for-simple-stream.h |   2 +-
 .../system-header-simulator-for-valist.h  |   6 +
 .../Analysis/Inputs/system-header-simulator.h |   3 +
 clang/test/Analysis/stream-invalidate.c   |  42 +++
 clang/test/Analysis/stream.c  | 341 +-
 6 files changed, 91 insertions(+), 337 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 65bdc4cac30940..f9928e1325c53d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -348,18 +348,30 @@ class StreamChecker : public CheckergetType();
-  if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
+  if (!T->isIntegralOrEnumerationType() && !T->isPointerType() &&
+  T.getCanonicalType() != VaListType)
 return nullptr;
 }
 
@@ -600,6 +615,11 @@ class StreamChecker : public CheckerPreFn)
@@ -1038,10 +1059,13 @@ void StreamChecker::evalFscanf(const FnDescription 
*Desc, const CallEvent &Call,
 if (!StateNotFailed)
   return;
 
-SmallVector EscArgs;
-for (auto EscArg : llvm::seq(2u, Call.getNumArgs()))
-  EscArgs.push_back(EscArg);
-StateNotFailed = escapeArgs(StateNotFailed, C, Call, EscArgs);
+if (auto const *Callee = Call.getCalleeIdentifier();
+!Callee || !Callee->getName().equals("vfscanf")) {
+  SmallVector EscArgs;
+  for (auto EscArg : llvm::seq(2u, Call.getNumArgs()))
+EscArgs.push_back(EscArg);
+  StateNotFailed = escapeArgs(StateNotFailed, C, Call, EscArgs);
+}
 
 if (StateNotFailed)
   C.addTransition(StateNotFailed);
diff --git 
a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h 
b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
index 098a2208fecbe9..c26d3582149120 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
@@ -5,7 +5,7 @@
 // suppressed.
 #pragma clang system_header
 
-typedef struct __sFILE {
+typedef struct _FILE {
   unsigned char *_p;
 } FILE;
 FILE *fopen(const char *restrict, const char *restrict) __asm("_" "fopen" );
diff --git a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h 
b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
index 7299b61353d460..720944abb8ad47 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
@@ -10,6 +10,8 @@
 #define restrict /*restrict*/
 #endif
 
+typedef struct _FILE FILE;
+
 typedef __builtin_va_list va_list;
 
 #define va_start(ap, param) __builtin_va_start(ap, param)
@@ -21,6 +23,10 @@ int vprintf (const char *restrict format, va_list arg);
 
 int vsprintf (char *restrict s, const char *restrict format, va_list arg);
 
+int vfprintf(FILE *stream, const char *format, va_list ap);
+
+int vfscanf(FILE *stream, const char *format, va_list ap);
+
 int some_library_function(int n, va_list arg);
 
 // No warning from system header.
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index 15986984802c0e..8fd51449ecc0a4 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -73,6 +73,9 @@ int ferror(FILE *stream);
 int fileno(FILE *stream);
 int fflush(FILE *stream);
 
+
+int getc(FILE *stream);
+
 size_t strlen(const char *);
 
 char *strcpy(char *restrict, const char *restrict);
diff --git a/clang/test/Analysis/stream-invalidate.c 
b/clang/test/Analysis/stream-invalidate.c
index 6745d11a2fe701..5046a356d0583d 100644
--- a/clang/test/Analysis/stream-invalidate.c
+++ b/clang/test/Analysis/stream-invalidate.c
@@ -4,6 +4,7 @@
 // RUN: -analyzer-checker=debug.ExprInspection
 
 #include "Inputs/system-header-simulator.h"
+#include "Inputs/system-header-simulator-for-valist.h"
 
 void clang_analyzer_eval(int);
 void clang_analyzer_dump(int);
@@ -145,3 +146,44 @@ void 

[clang] Reapply "[clang][analyzer] StreamChecker: Model getc, vfscanf, putc, … (PR #83281)

2024-02-28 Thread via cfe-commits

llvmbot wrote:




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

Author: Alejandro Álvarez Ayllón (alejandro-alvarez-sonarsource)


Changes

…vfprintf (#82476)"

`va_list` is a platform-specific type. On some, it is a struct instead of a 
pointer to a struct, so `lookupFn` was ignoring calls to `vfprintf` and 
`vfscanf`.

`stream.c` now runs in four different platforms to make sure the logic works 
across targets.

This reverts commit 570bc5d291f92e19f6264262b02ddff1a2f2e09b.



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


6 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+29-5) 
- (modified) 
clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h (+1-1) 
- (modified) clang/test/Analysis/Inputs/system-header-simulator-for-valist.h 
(+6) 
- (modified) clang/test/Analysis/Inputs/system-header-simulator.h (+3) 
- (modified) clang/test/Analysis/stream-invalidate.c (+42) 
- (modified) clang/test/Analysis/stream.c (+10-331) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 65bdc4cac30940..f9928e1325c53d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -348,18 +348,30 @@ class StreamChecker : public CheckergetType();
-  if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
+  if (!T->isIntegralOrEnumerationType() && !T->isPointerType() &&
+  T.getCanonicalType() != VaListType)
 return nullptr;
 }
 
@@ -600,6 +615,11 @@ class StreamChecker : public CheckerPreFn)
@@ -1038,10 +1059,13 @@ void StreamChecker::evalFscanf(const FnDescription 
*Desc, const CallEvent &Call,
 if (!StateNotFailed)
   return;
 
-SmallVector EscArgs;
-for (auto EscArg : llvm::seq(2u, Call.getNumArgs()))
-  EscArgs.push_back(EscArg);
-StateNotFailed = escapeArgs(StateNotFailed, C, Call, EscArgs);
+if (auto const *Callee = Call.getCalleeIdentifier();
+!Callee || !Callee->getName().equals("vfscanf")) {
+  SmallVector EscArgs;
+  for (auto EscArg : llvm::seq(2u, Call.getNumArgs()))
+EscArgs.push_back(EscArg);
+  StateNotFailed = escapeArgs(StateNotFailed, C, Call, EscArgs);
+}
 
 if (StateNotFailed)
   C.addTransition(StateNotFailed);
diff --git 
a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h 
b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
index 098a2208fecbe9..c26d3582149120 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h
@@ -5,7 +5,7 @@
 // suppressed.
 #pragma clang system_header
 
-typedef struct __sFILE {
+typedef struct _FILE {
   unsigned char *_p;
 } FILE;
 FILE *fopen(const char *restrict, const char *restrict) __asm("_" "fopen" );
diff --git a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h 
b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
index 7299b61353d460..720944abb8ad47 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-for-valist.h
@@ -10,6 +10,8 @@
 #define restrict /*restrict*/
 #endif
 
+typedef struct _FILE FILE;
+
 typedef __builtin_va_list va_list;
 
 #define va_start(ap, param) __builtin_va_start(ap, param)
@@ -21,6 +23,10 @@ int vprintf (const char *restrict format, va_list arg);
 
 int vsprintf (char *restrict s, const char *restrict format, va_list arg);
 
+int vfprintf(FILE *stream, const char *format, va_list ap);
+
+int vfscanf(FILE *stream, const char *format, va_list ap);
+
 int some_library_function(int n, va_list arg);
 
 // No warning from system header.
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index 15986984802c0e..8fd51449ecc0a4 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -73,6 +73,9 @@ int ferror(FILE *stream);
 int fileno(FILE *stream);
 int fflush(FILE *stream);
 
+
+int getc(FILE *stream);
+
 size_t strlen(const char *);
 
 char *strcpy(char *restrict, const char *restrict);
diff --git a/clang/test/Analysis/stream-invalidate.c 
b/clang/test/Analysis/stream-invalidate.c
index 6745d11a2fe701..5046a356d0583d 100644
--- a/clang/test/Analysis/stream-invalidate.c
+++ b/clang/test/Analysis/stream-invalidate.c
@@ -4,6 +4,7 @@
 // RUN: -analyzer-checker=debug.ExprInspection
 
 #include "Inputs/system-header-simulator.h"
+#include "Inputs/system-header-simulator-for-valist.h"
 
 void clang_analyzer_eval(int);
 void clang_analyzer_dump(int);
@@ -145,3 +146,44 @@ void test_fgetpos() {
 
   fclose(F);
 }
+
+void test_fprintf() {
+  FILE *F1 = tmpfile();
+  if (!F1)
+return;
+
+  unsigned a = 42;
+  char *output = "HELLO";
+  int r =

[clang] Reapply "[clang][analyzer] StreamChecker: Model getc, vfscanf, putc, … (PR #83281)

2024-02-28 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 680c780a367bfe1c0cdf786250fd7f565ef6d23d 
ddbe895e3d2893060ac54bc6c984eea22e09b460 -- 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
clang/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h 
clang/test/Analysis/Inputs/system-header-simulator-for-valist.h 
clang/test/Analysis/Inputs/system-header-simulator.h 
clang/test/Analysis/stream-invalidate.c clang/test/Analysis/stream.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index f9928e1325..f2f7a0f83b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -616,8 +616,7 @@ private:
   }
 
   void initVaListType(CheckerContext &C) const {
-VaListType =
-C.getASTContext().getBuiltinVaListType().getCanonicalType();
+VaListType = C.getASTContext().getBuiltinVaListType().getCanonicalType();
   }
 
   /// Searches for the ExplodedNode where the file descriptor was acquired for

``




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


[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-28 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/81893

>From ed8c2af0e301885101097c23cc96c872e8650529 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Thu, 15 Feb 2024 15:53:51 +
Subject: [PATCH] [clang] Refactor target attribute mangling.

Before this patch all of the 'target', 'target_version' and 'target_clones'
attributes were sharing a common mangling logic across different targets.
However we would like to differenciate this logic, therefore I have moved
the default path to ABIInfo and provided overrides for AArch64. This
way we can resolve feature aliases without affecting the name mangling
The PR #80540 demonstrates a motivating case.
---
 clang/lib/CodeGen/ABIInfo.cpp |  52 
 clang/lib/CodeGen/ABIInfo.h   |  10 +++
 clang/lib/CodeGen/CodeGenModule.cpp   | 111 --
 clang/lib/CodeGen/Targets/AArch64.cpp |  40 ++
 4 files changed, 118 insertions(+), 95 deletions(-)

diff --git a/clang/lib/CodeGen/ABIInfo.cpp b/clang/lib/CodeGen/ABIInfo.cpp
index 1b56cf7c596d06..efcff958ce5452 100644
--- a/clang/lib/CodeGen/ABIInfo.cpp
+++ b/clang/lib/CodeGen/ABIInfo.cpp
@@ -184,6 +184,58 @@ ABIArgInfo ABIInfo::getNaturalAlignIndirectInReg(QualType 
Ty,
   /*ByVal*/ false, Realign);
 }
 
+void ABIInfo::appendAttributeMangling(TargetAttr *Attr,
+  raw_ostream &Out) const {
+  if (Attr->isDefaultVersion())
+return;
+  appendAttributeMangling(Attr->getFeaturesStr(), Out);
+}
+
+void ABIInfo::appendAttributeMangling(TargetVersionAttr *Attr,
+  raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getNamesStr(), Out);
+}
+
+void ABIInfo::appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
+  raw_ostream &Out) const {
+  appendAttributeMangling(Attr->getFeatureStr(Index), Out);
+  Out << '.' << Attr->getMangledIndex(Index);
+}
+
+void ABIInfo::appendAttributeMangling(StringRef AttrStr,
+  raw_ostream &Out) const {
+  if (AttrStr == "default") {
+Out << ".default";
+return;
+  }
+
+  Out << '.';
+  const TargetInfo &TI = CGT.getTarget();
+  ParsedTargetAttr Info = TI.parseTargetAttr(AttrStr);
+
+  llvm::sort(Info.Features, [&TI](StringRef LHS, StringRef RHS) {
+// Multiversioning doesn't allow "no-${feature}", so we can
+// only have "+" prefixes here.
+assert(LHS.starts_with("+") && RHS.starts_with("+") &&
+   "Features should always have a prefix.");
+return TI.multiVersionSortPriority(LHS.substr(1)) >
+   TI.multiVersionSortPriority(RHS.substr(1));
+  });
+
+  bool IsFirst = true;
+  if (!Info.CPU.empty()) {
+IsFirst = false;
+Out << "arch_" << Info.CPU;
+  }
+
+  for (StringRef Feat : Info.Features) {
+if (!IsFirst)
+  Out << '_';
+IsFirst = false;
+Out << Feat.substr(1);
+  }
+}
+
 // Pin the vtable to this file.
 SwiftABIInfo::~SwiftABIInfo() = default;
 
diff --git a/clang/lib/CodeGen/ABIInfo.h b/clang/lib/CodeGen/ABIInfo.h
index b9a5ef6e436693..ff4ae44a42c332 100644
--- a/clang/lib/CodeGen/ABIInfo.h
+++ b/clang/lib/CodeGen/ABIInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
 #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
 
+#include "clang/AST/Attr.h"
 #include "clang/AST/CharUnits.h"
 #include "clang/AST/Type.h"
 #include "llvm/IR/CallingConv.h"
@@ -111,6 +112,15 @@ class ABIInfo {
 
   CodeGen::ABIArgInfo getNaturalAlignIndirectInReg(QualType Ty,
bool Realign = false) const;
+
+  virtual void appendAttributeMangling(TargetAttr *Attr,
+   raw_ostream &Out) const;
+  virtual void appendAttributeMangling(TargetVersionAttr *Attr,
+   raw_ostream &Out) const;
+  virtual void appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
+   raw_ostream &Out) const;
+  virtual void appendAttributeMangling(StringRef AttrStr,
+   raw_ostream &Out) const;
 };
 
 /// Target specific hooks for defining how a type should be passed or returned
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 95e457bef28ed3..160917d47da1f3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1726,59 +1726,6 @@ static void AppendCPUSpecificCPUDispatchMangling(const 
CodeGenModule &CGM,
 Out << ".resolver";
 }
 
-static void AppendTargetVersionMangling(const CodeGenModule &CGM,
-const TargetVersionAttr *Attr,
-raw_ostream &Out) {
-  if (Attr->isDefaultVersion()) {
-Out << ".default";
-return;
-  }
-  Out << "._";
-  const TargetInfo &TI = CGM.getTarget();
-  llvm::SmallVector Feats;
-  Attr->getFeatures(F

[clang] [clang] Refactor target attribute mangling. (PR #81893)

2024-02-28 Thread Erich Keane via cfe-commits

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


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


  1   2   3   4   >