[clang] [Clang] Allow all address spaces to be converted to the default (PR #112248)

2024-10-15 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> They should not "just work" if you're compiling for vanilla C/C++ (so not 
> CUDA C++, or SYCL, or OpenCL C/C++ etc.) because neither of those defines 
> such a notion.

a6a237f2046ad8993db30481c8b61aeb2f73a5ad added an explicit addrspace_cast 
operator. It would be better to use something like this rather than just freely 
enabling any implicit cast 

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


[clang] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (PR #112378)

2024-10-15 Thread via cfe-commits


@@ -215,8 +215,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2015)) {
   if (Opts.CPlusPlus23)
-// TODO update to the proper value.
-Builder.defineMacro("_MSVC_LANG", "202004L");
+Builder.defineMacro("_MSVC_LANG", "202302L");

cor3ntin wrote:

STL mention setting _MSVC_LANG to 202600 in C++26, we should probably follow 
suite 

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


[clang] [Clang] Allow all address spaces to be converted to the default (PR #112248)

2024-10-15 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> > They should not "just work" if you're compiling for vanilla C/C++ (so not 
> > CUDA C++, or SYCL, or OpenCL C/C++ etc.) because neither of those defines 
> > such a notion.
> 
> [a6a237f](https://github.com/llvm/llvm-project/commit/a6a237f2046ad8993db30481c8b61aeb2f73a5ad)
>  added an explicit addrspace_cast operator. It would be better to use 
> something like this rather than just freely enabling any implicit cast

That's only enabled in OpenCLC++ I think? We could probably make a patch to 
enable it in C++. (Guessing we'd need to call it `__addrspace_cast` or 
`__builtin_addrspace_cast`. However it's still a huge pain to work with.

I tried adding an option to relax the rules but it's much more difficult than I 
anticipated because it requires forwarding  the language options to every 100 
or so places that Sema wants to check if the types are legal. OpenCL3.0 lets 
you enable it for convenience so I'd like that kind of behavior (We probably 
also do want addrspace cast in general). But it seems like it might be really, 
really annoying to enable that without becoming beholden to OpenCL rules. The 
only way I could thing to change these rules optionally would be to introduce a 
ton of new addrspace rules which are basically just OpenCL but not.

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


[clang] [clang][bytecode] Diagnose reference to non-constexpr variable of const type in C23 constexpr (PR #112211)

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

tbaederr wrote:

Yup, you can ignore that failure

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits


@@ -302,27 +312,38 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, 
unsigned DiagID) {
 if (const Decl *FD = CE->getCalleeDecl()) {
   if (ShouldSuppress)
 return;
-  if (FD->hasAttr()) {
+  if (const auto *A = FD->getAttr()) {
 Diag(Loc, diag::warn_unused_call) << R1 << R2 << "pure";
+if (OffendingDecl && !OffendingDecl->getIdentifier()->getBuiltinID())

Mick235711 wrote:

That check on builtin is actually added after the test `Seme/enable-if.c` fails:
```cpp
int isdigit(int c) __attribute__((overloadable));
int isdigit(int c) __attribute__((overloadable)) // expected-note {{'isdigit' 
has been explicitly marked unavailable here}}
  __attribute__((enable_if(c <= -1 || c > 255, "'c' must have the value of an 
unsigned char or EOF")))
  __attribute__((unavailable("'c' must have the value of an unsigned char or 
EOF")));

void test3(int c) {
  isdigit(c); // expected-warning{{ignoring return value of function declared 
with pure attribute}}
  isdigit(10); // expected-warning{{ignoring return value of function declared 
with pure attribute}}
#ifndef CODEGEN
  isdigit(-10);  // expected-error{{'isdigit' is unavailable: 'c' must have the 
value of an unsigned char or EOF}}
#endif
}
```
In this part of the test, without the builtin test a note will be generated on 
the first line ("`isdigit` has been explicitly marked pure here"), which is the 
result of isdigit been assigned pure attribute as a builtin.

Though despite this, thinking it over now, it is still debatable on whether 
generating note here on builtin is meaningful/useful... Do you think I should 
remove the test?

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits

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


[clang] 8079a2c - [clang][bytecode] Diagnose reference to non-constexpr variable of const type in C23 constexpr (#112211)

2024-10-15 Thread via cfe-commits

Author: yronglin
Date: 2024-10-16T00:11:12+08:00
New Revision: 8079a2c57862115f7fe4dbe72f07cf944a7f6aed

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

LOG: [clang][bytecode] Diagnose reference to non-constexpr variable of const 
type in C23 constexpr (#112211)

```cpp
const int V33 = 4;
const int V34 = 0;
const int V35 = 2;

constexpr int V36 = V33 / V34;
// expected-error@-1 {{constexpr variable 'V36' must be initialized by a 
constant expression}}
constexpr int V37 = V33 / V35;
// expected-error@-1 {{constexpr variable 'V37' must be initialized by a 
constant expression}}
```

-

Signed-off-by: yronglin 

Added: 
clang/test/AST/ByteCode/constexpr.c

Modified: 
clang/lib/AST/ByteCode/Interp.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 95715655cc9bbd..40137de19c4e1b 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -348,6 +348,13 @@ bool CheckConstant(InterpState &S, CodePtr OpPC, const 
Descriptor *Desc) {
   if (D->isConstexpr())
 return true;
 
+  // If we're evaluating the initializer for a constexpr variable in C23, we 
may
+  // only read other contexpr variables. Abort here since this one isn't
+  // constexpr.
+  if (const auto *VD = dyn_cast_if_present(S.EvaluatingDecl);
+  VD && VD->isConstexpr() && S.getLangOpts().C23)
+return Invalid(S, OpPC);
+
   QualType T = D->getType();
   bool IsConstant = T.isConstant(S.getASTContext());
   if (T->isIntegralOrEnumerationType()) {

diff  --git a/clang/test/AST/ByteCode/constexpr.c 
b/clang/test/AST/ByteCode/constexpr.c
new file mode 100644
index 00..fed24fa72b2541
--- /dev/null
+++ b/clang/test/AST/ByteCode/constexpr.c
@@ -0,0 +1,370 @@
+// RUN: %clang_cc1 -std=c23 -verify=ref,both -triple x86_64 -pedantic 
-Wno-conversion -Wno-constant-conversion -Wno-div-by-zero %s
+// RUN: %clang_cc1 -std=c23 -verify=expected,both -triple x86_64 -pedantic 
-Wno-conversion -Wno-constant-conversion -Wno-div-by-zero 
-fexperimental-new-constant-interpreter %s
+
+// Check that constexpr only applies to variables.
+constexpr void f0() {} // both-error {{'constexpr' can only be used in 
variable declarations}}
+constexpr const int f1() { return 0; } // both-error {{'constexpr' can only be 
used in variable declarations}}
+
+constexpr struct S1 { int f; }; //both-error {{struct cannot be marked 
constexpr}}
+constexpr struct S2 ; // both-error {{struct cannot be marked constexpr}}
+constexpr union U1; // both-error {{union cannot be marked constexpr}}
+constexpr union U2 {int a; float b;}; // both-error {{union cannot be marked 
constexpr}}
+constexpr enum E1 {A = 1, B = 2} ; // both-error {{enum cannot be marked 
constexpr}}
+struct S3 {
+  static constexpr int f = 0; // both-error {{type name does not allow storage 
class}}
+  // both-error@-1 {{type name does not allow constexpr}}
+  // both-error@-2 {{expected ';' at end}}
+  constexpr int f1 = 0;
+  // both-error@-1 {{type name does not allow constexpr}}
+  // both-error@-2 {{expected ';' at end}}
+};
+
+constexpr; // both-error {{'constexpr' can only be used in variable 
declarations}}
+constexpr int V1 = 3;
+constexpr float V2 = 7.0;
+int V3 = (constexpr)3; // both-error {{expected expression}}
+
+void f2() {
+  constexpr int a = 0;
+  constexpr float b = 1.7f;
+}
+
+// Check how constexpr works with other storage-class specifiers.
+constexpr auto V4 = 1;
+constexpr static auto V5 = 1;
+constexpr static const auto V6 = 1;
+constexpr static const int V7 = 1;
+constexpr static int V8 = 1;
+constexpr auto Ulong = 1L;
+constexpr auto CompoundLiteral = (int){13};
+constexpr auto DoubleCast = (double)(1 / 3);
+constexpr auto String = "this is a string"; // both-error {{constexpr pointer 
initializer is not null}}
+constexpr signed auto Long = 1L; // both-error {{'auto' cannot be signed or 
unsigned}}
+_Static_assert(_Generic(Ulong, long : 1));
+_Static_assert(_Generic(CompoundLiteral, int : 1));
+_Static_assert(_Generic(DoubleCast, double : 1));
+_Static_assert(_Generic(String, char* : 1));
+
+typedef constexpr int Foo; // both-error {{typedef cannot be constexpr}}
+constexpr typedef int Bar; // both-error {{typedef cannot be constexpr}}
+
+void f3(constexpr register int P1) { // both-error {{function parameter cannot 
be constexpr}}
+  constexpr register int V9 = 0;
+  constexpr register auto V10 = 0.0;
+}
+
+constexpr thread_local int V11 = 38; // both-error {{cannot combine with 
previous '_Thread_local' declaration specifier}}
+constexpr static thread_local double V12 = 38; // both-error {{cannot combine 
with previous '_Thread_local' declaration specifier}}
+constexpr extern thread_local char V13; // both-error {{cannot combine with 
previous '_Thread_lo

[clang] [clang] Check null TypeSourceInfo in CreateUnaryExprOrTypeTraitExpr (PR #112111)

2024-10-15 Thread Andrew Sukach via cfe-commits

https://github.com/sookach updated 
https://github.com/llvm/llvm-project/pull/112111

>From 59537c2005e30d2ac8410822cb2804c63f2ae73b Mon Sep 17 00:00:00 2001
From: Andrew Sukach 
Date: Sat, 12 Oct 2024 19:47:30 -0400
Subject: [PATCH] [clang] Check for null TypeSourceInfo in
 Sema::CreateUnaryExprOrTypeTraitExpr

---
 clang/docs/ReleaseNotes.rst | 2 ++
 clang/lib/Sema/SemaExpr.cpp | 3 +++
 clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp | 3 +++
 3 files changed, 8 insertions(+)
 create mode 100644 clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 763bc3ac159322..f2f6988a1f5c13 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -505,6 +505,8 @@ Bug Fixes to C++ Support
 - Fix a crash when parsing a pseudo destructor involving an invalid type. 
(#GH111460)
 - Fixed an assertion failure when invoking recovery call expressions with 
explicit attributes
   and undeclared templates. (#GH107047, #GH49093)
+- Fixed a compiler crash that occurred when processing malformed code 
involving `sizeof` with
+  an invalid type argument. (#GH111594)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4e37385710af5e..b0bd216c5dc101 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4629,6 +4629,9 @@ ExprResult 
Sema::CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
   TInfo->getType()->isVariablyModifiedType())
 TInfo = TransformToPotentiallyEvaluated(TInfo);
 
+  if (!TInfo)
+return ExprError();
+
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
diff --git a/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp 
b/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp
new file mode 100644
index 00..005dbb0ddbfc2c
--- /dev/null
+++ b/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp
@@ -0,0 +1,3 @@
+// RUN: not %clang_cc1 -fsyntax-only %s -fno-crash-diagnostics
+
+a() {struct b c (sizeof(b * [({ {tree->d* next)} 0

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


[clang] [clang][bytecode] Diagnose reference to non-constexpr variable of const type in C23 constexpr (PR #112211)

2024-10-15 Thread via cfe-commits

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

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

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/111499

>From 4951a7b9b87f9800bc3629bd44f65141ba98c6b0 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 8 Oct 2024 08:19:56 +
Subject: [PATCH 1/9] start working on lifetime capture

---
 clang/include/clang/Basic/Attr.td |  40 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  16 +++
 clang/include/clang/Sema/Sema.h   |   7 ++
 clang/lib/AST/TypePrinter.cpp |  21 
 clang/lib/Sema/CheckExprLifetime.cpp  |  54 +++---
 clang/lib/Sema/CheckExprLifetime.h|  26 +++--
 clang/lib/Sema/SemaChecking.cpp   |  27 +
 clang/lib/Sema/SemaDecl.cpp   |   1 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 102 ++
 clang/lib/Sema/SemaExpr.cpp   |   4 +-
 clang/lib/Sema/SemaInit.cpp   |   2 +-
 clang/lib/Sema/SemaOverload.cpp   |   4 +-
 clang/lib/Sema/SemaType.cpp   |  13 +++
 clang/test/SemaCXX/attr-lifetimebound.cpp |  94 
 14 files changed, 387 insertions(+), 24 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 35b9716e13ff21..4dcb143b91f84f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1869,6 +1869,46 @@ def LifetimeBound : DeclOrTypeAttr {
   let SimpleHandler = 1;
 }
 
+def LifetimeCaptureBy : DeclOrTypeAttr {
+  let Spellings = [Clang<"lifetime_capture_by", 0>];
+  let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
+  let Args = [VariadicParamOrParamIdxArgument<"Params">];
+  let Documentation = [LifetimeBoundDocs];
+  let LangOpts = [CPlusPlus];
+
+  // let SimpleHandler = 1;
+  // let LateParsed = LateAttrParseStandard;
+  // let HasCustomParsing = 1;
+  // let ParseArgumentsAsUnevaluated = 1;
+
+  let AdditionalMembers = [{
+private:
+  SmallVector ArgIdents;
+  SmallVector ArgLocs;
+
+public:
+  static const int INVALID = -2;
+  static const int UNKNOWN = -1;
+  static const int GLOBAL = -1;
+  static const int THIS = 0;
+
+  void setArgs(SmallVector Idents,
+   SmallVector Locs) { 
+assert(Idents.size() == Locs.size());
+assert(Idents.size() == params_Size);
+ArgIdents = std::move(Idents);
+ArgLocs = std::move(Locs);
+  }
+  
+  const SmallVector& getArgIdents() const { return 
ArgIdents; }
+  const SmallVector& getArgLocs() const { return ArgLocs; }
+  void setParamIdx(size_t Idx, int Val) { 
+assert(Idx < params_Size);
+params_[Idx] = Val;
+  }
+}];
+}
+
 def TrivialABI : InheritableAttr {
   // This attribute does not have a C [[]] spelling because it requires the
   // CPlusPlus language option.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e8b64f3c5a0187..ea034af77c3dbe 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3382,6 +3382,18 @@ def err_callback_callee_is_variadic : Error<
   "'callback' attribute callee may not be variadic">;
 def err_callback_implicit_this_not_available : Error<
   "'callback' argument at position %0 references unavailable implicit 'this'">;
+
+def err_capture_by_attribute_multiple : Error<
+  "multiple 'lifetime_capture' attributes specified">;
+def err_capture_by_attribute_no_entity : Error<
+  "'lifetime_capture_by' attribute specifies no capturing entity">;
+def err_capture_by_implicit_this_not_available : Error<
+  "'lifetime_capture_by' argument references unavailable implicit 'this'">;
+def err_capture_by_attribute_argument_unknown : Error<
+  "'lifetime_capture_by' attribute argument %0 is not a known function 
parameter"
+  ". Must be a function parameter of one of 'this', 'global' or 'unknown'">;
+def err_capture_by_references_itself : Error<"'lifetime_capture_by' argument 
references itself">;
+
 def err_init_method_bad_return_type : Error<
   "init methods must return an object pointer type, not %0">;
 def err_attribute_invalid_size : Error<
@@ -10185,6 +10197,10 @@ def warn_dangling_pointer_assignment : Warning<
"object backing the pointer %0 "
"will be destroyed at the end of the full-expression">,
InGroup;
+def warn_dangling_reference_captured : Warning<
+   "object captured by the '%0' "
+   "will be destroyed at the end of the full-expression">,
+   InGroup;
 
 // For non-floating point, expressions of the form x == x or x != x
 // should result in a warning, since these always evaluate to a constant.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0809ac1b144ef6..a26b3fa8755161 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1830,6 +1830,10 @@ class Sema final : public SemaBase {
   /// Add [[gsl::Pointer]] attributes for std:: types.
   void inferGslPointerAttribute(TypedefNameDecl *TD);
 

[clang] [clang] Check null TypeSourceInfo in CreateUnaryExprOrTypeTraitExpr (PR #112111)

2024-10-15 Thread via cfe-commits


@@ -683,6 +683,9 @@ New features
 Crash and bug fixes
 ^^^
 
+- Check for a null ``TypeSourceInfo *`` when creating a 
``UnaryExprOrTypeTraitExpr``.
+  Fixes (#GH111594)
+

Sirraide wrote:

The release note is in the wrong place; I’m pretty sure this is the static 
analyser section. It should instead be in the ‘bug fixes to C++ support’ or a 
similar section above. 

Also, users of Clang will have no idea what a TypeSourceInfo or 
UnaryExprOrTypeTraitExpr is supposed to be; it’s better to give a more concrete 
example (e.g. ‘fixed a crash when the type of the operand to `sizeof` is 
invalid’ or sth like that).

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


[clang] [clang] Check null TypeSourceInfo in CreateUnaryExprOrTypeTraitExpr (PR #112111)

2024-10-15 Thread via cfe-commits


@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+a() {struct b c (sizeof(b * [({ {tree->d* next)} 0
+
+// expected-error@3 {{a type specifier is required for all declarations}}
+// expected-error@3 {{use of undeclared identifier 'tree'; did you mean 
'true'?}}
+// expected-error@3 {{member reference type 'bool' is not a pointer}}
+// expected-error@3 {{expected ';' after expression}}
+// expected-error@3 {{use of undeclared identifier 'next'; did you mean 
'new'?}}
+// expected-error@3 {{expected expression}}
+// expected-error@3 {{expected ';' after expression}}
+// expected-error@26 {{expected '}'}}
+// expected-note@3 {{to match this '{'}}
+// expected-error@26 {{expected ')'}}
+// expected-note@3 {{to match this '('}}
+// expected-error@26 {{expected ']'}}
+// expected-note@3 {{to match this '['}}
+// expected-error@26 {{expected ')'}}
+// expected-note@3 {{to match this '('}}
+// expected-error@3 {{using declaration 'exp' instantiates to an empty pack}}
+// expected-error@3 {{variable has incomplete type 'struct b'}}
+// expected-note@3 {{forward declaration of 'b'}}
+// expected-error@3 {{expected ';' at end of declaration}}
+// expected-error@26 {{expected '}'}}
+// expected-note@3 {{to match this '{'}}
+// expected-warning@3 {{expression result unused}}

Sirraide wrote:

CC @Endilll @erichkeane  Do we have a cleaner way of writing fuzzer tests? 
Because this is rather atrocious to look at.

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


[clang] [clang] Check null TypeSourceInfo in CreateUnaryExprOrTypeTraitExpr (PR #112111)

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


@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+a() {struct b c (sizeof(b * [({ {tree->d* next)} 0
+
+// expected-error@3 {{a type specifier is required for all declarations}}
+// expected-error@3 {{use of undeclared identifier 'tree'; did you mean 
'true'?}}
+// expected-error@3 {{member reference type 'bool' is not a pointer}}
+// expected-error@3 {{expected ';' after expression}}
+// expected-error@3 {{use of undeclared identifier 'next'; did you mean 
'new'?}}
+// expected-error@3 {{expected expression}}
+// expected-error@3 {{expected ';' after expression}}
+// expected-error@26 {{expected '}'}}
+// expected-note@3 {{to match this '{'}}
+// expected-error@26 {{expected ')'}}
+// expected-note@3 {{to match this '('}}
+// expected-error@26 {{expected ']'}}
+// expected-note@3 {{to match this '['}}
+// expected-error@26 {{expected ')'}}
+// expected-note@3 {{to match this '('}}
+// expected-error@3 {{using declaration 'exp' instantiates to an empty pack}}
+// expected-error@3 {{variable has incomplete type 'struct b'}}
+// expected-note@3 {{forward declaration of 'b'}}
+// expected-error@3 {{expected ';' at end of declaration}}
+// expected-error@26 {{expected '}'}}
+// expected-note@3 {{to match this '{'}}
+// expected-warning@3 {{expression result unused}}

zyn0217 wrote:

Instead of running `-verify` on the test, can we just run `FileCheck` and 
ensure there are no strings like `PLEASE submit a bug report` or something?

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


[clang] [clang] Check null TypeSourceInfo in CreateUnaryExprOrTypeTraitExpr (PR #112111)

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


@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+a() {struct b c (sizeof(b * [({ {tree->d* next)} 0
+
+// expected-error@3 {{a type specifier is required for all declarations}}
+// expected-error@3 {{use of undeclared identifier 'tree'; did you mean 
'true'?}}
+// expected-error@3 {{member reference type 'bool' is not a pointer}}
+// expected-error@3 {{expected ';' after expression}}
+// expected-error@3 {{use of undeclared identifier 'next'; did you mean 
'new'?}}
+// expected-error@3 {{expected expression}}
+// expected-error@3 {{expected ';' after expression}}
+// expected-error@26 {{expected '}'}}
+// expected-note@3 {{to match this '{'}}
+// expected-error@26 {{expected ')'}}
+// expected-note@3 {{to match this '('}}
+// expected-error@26 {{expected ']'}}
+// expected-note@3 {{to match this '['}}
+// expected-error@26 {{expected ')'}}
+// expected-note@3 {{to match this '('}}
+// expected-error@3 {{using declaration 'exp' instantiates to an empty pack}}
+// expected-error@3 {{variable has incomplete type 'struct b'}}
+// expected-note@3 {{forward declaration of 'b'}}
+// expected-error@3 {{expected ';' at end of declaration}}
+// expected-error@26 {{expected '}'}}
+// expected-note@3 {{to match this '{'}}
+// expected-warning@3 {{expression result unused}}

erichkeane wrote:

Not really, not all of the test configurations use the normal crash handler... 
I would hope the author could use the test as an example to come up with a 
minimal example that does the bare minimum to cause this issue rather than 
using the fuzz itself: I don't think the fuzz generated code should actually be 
in our test suite, just the actual use case that is required to get into this 
situation.

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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


@@ -9290,6 +9290,8 @@ def warn_unused_result_typedef_unsupported_spelling : 
Warning<
 def warn_unused_volatile : Warning<
   "expression result unused; assign into a variable to force a volatile load">,
   InGroup>;
+def note_nodiscard_specified_here : Note<

erichkeane wrote:

this should probably just re-use an existing note, perhaps the one we have for 
deprecated?

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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


@@ -290,9 +297,12 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, 
unsigned DiagID) {
 if (E->getType()->isVoidType())
   return;
 
-if (DiagnoseNoDiscard(*this, cast_or_null(
- CE->getUnusedResultAttr(Context)),
-  Loc, R1, R2, /*isCtor=*/false))
+const NamedDecl *OffendingDecl;
+const Attr *A;
+std::tie(OffendingDecl, A) = CE->getUnusedResultAttr(Context);

erichkeane wrote:

```suggestion
auto &[OffendingDecl, A] = CE->getUnusedResultAttr(Context);
```

Then you can do away with the declarations.

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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


@@ -204,23 +205,29 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr 
*E) {
   return true;
 }
 
-static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A,
-  SourceLocation Loc, SourceRange R1,
-  SourceRange R2, bool IsCtor) {
+static bool DiagnoseNoDiscard(Sema &S, const NamedDecl *OffendingDecl,
+  const WarnUnusedResultAttr *A, SourceLocation 
Loc,
+  SourceRange R1, SourceRange R2, bool IsCtor) {
   if (!A)
 return false;
   StringRef Msg = A->getMessage();
 
+  bool result;
   if (Msg.empty()) {
 if (IsCtor)
-  return S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
-return S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
-  }
+  result = S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;

erichkeane wrote:

I'm a bit confused about this section here... We don't really need all of this, 
right?  All you want to do is add the diag at the bottom, right?

Also, 'result' is always going to be true.  `Diag` always returns true, it is 
just a shortcut to return early with a common pattern we have.

So I think this is the wrong way of doing a refactor here.

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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


@@ -302,27 +312,38 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, 
unsigned DiagID) {
 if (const Decl *FD = CE->getCalleeDecl()) {
   if (ShouldSuppress)
 return;
-  if (FD->hasAttr()) {
+  if (const auto *A = FD->getAttr()) {
 Diag(Loc, diag::warn_unused_call) << R1 << R2 << "pure";
+if (OffendingDecl && !OffendingDecl->getIdentifier()->getBuiltinID())

erichkeane wrote:

This situation of an offending decl not being always present is, imo, not 
really something we should be ok with.  As far as skipping on builtins, I don't 
know if we SHOULD, I would think the note there is still meaningful.

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


[clang] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (PR #112378)

2024-10-15 Thread via cfe-commits

https://github.com/zmodem created 
https://github.com/llvm/llvm-project/pull/112378

As discussed in 
https://discourse.llvm.org/t/clang-cl-adding-std-c-23preview/82553

>From f44ba22a8e5232b3f1e4a680565acd5604a7016c Mon Sep 17 00:00:00 2001
From: Hans Wennborg 
Date: Tue, 15 Oct 2024 17:18:45 +0200
Subject: [PATCH] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for
 C++23

---
 clang/include/clang/Driver/Options.td   | 2 +-
 clang/lib/Basic/Targets/OSTargets.cpp   | 3 +--
 clang/lib/Driver/ToolChains/Clang.cpp   | 1 +
 clang/test/Driver/cl-options.c  | 3 +++
 clang/test/Preprocessor/predefined-win-macros.c | 2 +-
 5 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6491e9ac73ce99..3390367173a29d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8526,7 +8526,7 @@ def _SLASH_execution_charset : 
CLCompileJoined<"execution-charset:">,
   HelpText<"Set runtime encoding, supports only UTF-8">,
   Alias;
 def _SLASH_std : CLCompileJoined<"std:">,
-  HelpText<"Set language version (c++14,c++17,c++20,c++latest,c11,c17)">;
+  HelpText<"Set language version 
(c++14,c++17,c++20,c++23preview,c++latest,c11,c17)">;
 def _SLASH_U : CLJoinedOrSeparate<"U">, HelpText<"Undefine macro">,
   MetaVarName<"">, Alias;
 def _SLASH_validate_charset : CLFlag<"validate-charset">,
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b56e2c7ca9c494..ff4d2df163e613 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -215,8 +215,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2015)) {
   if (Opts.CPlusPlus23)
-// TODO update to the proper value.
-Builder.defineMacro("_MSVC_LANG", "202004L");
+Builder.defineMacro("_MSVC_LANG", "202302L");
   else if (Opts.CPlusPlus20)
 Builder.defineMacro("_MSVC_LANG", "202002L");
   else if (Opts.CPlusPlus17)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 9d2f7a8960b45f..ca8f10c337e1e9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7217,6 +7217,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
  .Case("c++17", "-std=c++17")
  .Case("c++20", "-std=c++20")
  // TODO add c++23 and c++26 when MSVC supports it.
+ .Case("c++23preview", "-std=c++23")
  .Case("c++latest", "-std=c++26")
  .Default("");
   if (LanguageStandard.empty())
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 48d281bcd447e7..8191fda97788c1 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -605,6 +605,9 @@
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++20 -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXX20 %s
 // STDCXX20: -std=c++20
 
+// RUN: %clang_cl -fmsc-version=1900 -TP -std:c++23preview -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXX23PREVIEW %s
+// STDCXX23PREVIEW: -std=c++23
+
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++latest -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXXLATEST %s
 // STDCXXLATEST: -std=c++26
 
diff --git a/clang/test/Preprocessor/predefined-win-macros.c 
b/clang/test/Preprocessor/predefined-win-macros.c
index 7d29e45c7d5ac6..e7988501afa689 100644
--- a/clang/test/Preprocessor/predefined-win-macros.c
+++ b/clang/test/Preprocessor/predefined-win-macros.c
@@ -56,7 +56,7 @@
 // RUN: %clang_cc1 %s -x c++ -E -dM -triple i686-pc-win32 -fms-extensions 
-fms-compatibility \
 // RUN: -fms-compatibility-version=19.00 -std=c++23 -o - | FileCheck 
-match-full-lines %s --check-prefix=CHECK-MS-CPP2B
 // CHECK-MS-CPP2B: #define _MSC_VER 1900
-// CHECK-MS-CPP2B: #define _MSVC_LANG 202004L
+// CHECK-MS-CPP2B: #define _MSVC_LANG 202302L
 
 // RUN: %clang_cc1 -triple i386-windows %s -E -dM -o - \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-WIN

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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


@@ -204,23 +205,29 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr 
*E) {
   return true;
 }
 
-static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A,
-  SourceLocation Loc, SourceRange R1,
-  SourceRange R2, bool IsCtor) {
+static bool DiagnoseNoDiscard(Sema &S, const NamedDecl *OffendingDecl,
+  const WarnUnusedResultAttr *A, SourceLocation 
Loc,
+  SourceRange R1, SourceRange R2, bool IsCtor) {
   if (!A)
 return false;
   StringRef Msg = A->getMessage();
 
+  bool result;
   if (Msg.empty()) {
 if (IsCtor)
-  return S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
-return S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
-  }
+  result = S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
+else
+  result = S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
+  } else if (IsCtor)
+result = S.Diag(Loc, diag::warn_unused_constructor_msg)
+ << A << Msg << R1 << R2;
+  else
+result = S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
 
-  if (IsCtor)
-return S.Diag(Loc, diag::warn_unused_constructor_msg) << A << Msg << R1
-  << R2;
-  return S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
+  if (OffendingDecl)

erichkeane wrote:

Why is this allowed to be null?  What cases do we have where this doesn't have 
a declaration?

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


[clang] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (PR #112378)

2024-10-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-platform-windows

Author: Hans (zmodem)


Changes

As discussed in 
https://discourse.llvm.org/t/clang-cl-adding-std-c-23preview/82553

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


5 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1-1) 
- (modified) clang/lib/Basic/Targets/OSTargets.cpp (+1-2) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1) 
- (modified) clang/test/Driver/cl-options.c (+3) 
- (modified) clang/test/Preprocessor/predefined-win-macros.c (+1-1) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6491e9ac73ce99..3390367173a29d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8526,7 +8526,7 @@ def _SLASH_execution_charset : 
CLCompileJoined<"execution-charset:">,
   HelpText<"Set runtime encoding, supports only UTF-8">,
   Alias;
 def _SLASH_std : CLCompileJoined<"std:">,
-  HelpText<"Set language version (c++14,c++17,c++20,c++latest,c11,c17)">;
+  HelpText<"Set language version 
(c++14,c++17,c++20,c++23preview,c++latest,c11,c17)">;
 def _SLASH_U : CLJoinedOrSeparate<"U">, HelpText<"Undefine macro">,
   MetaVarName<"">, Alias;
 def _SLASH_validate_charset : CLFlag<"validate-charset">,
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b56e2c7ca9c494..ff4d2df163e613 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -215,8 +215,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2015)) {
   if (Opts.CPlusPlus23)
-// TODO update to the proper value.
-Builder.defineMacro("_MSVC_LANG", "202004L");
+Builder.defineMacro("_MSVC_LANG", "202302L");
   else if (Opts.CPlusPlus20)
 Builder.defineMacro("_MSVC_LANG", "202002L");
   else if (Opts.CPlusPlus17)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 9d2f7a8960b45f..ca8f10c337e1e9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7217,6 +7217,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
  .Case("c++17", "-std=c++17")
  .Case("c++20", "-std=c++20")
  // TODO add c++23 and c++26 when MSVC supports it.
+ .Case("c++23preview", "-std=c++23")
  .Case("c++latest", "-std=c++26")
  .Default("");
   if (LanguageStandard.empty())
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 48d281bcd447e7..8191fda97788c1 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -605,6 +605,9 @@
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++20 -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXX20 %s
 // STDCXX20: -std=c++20
 
+// RUN: %clang_cl -fmsc-version=1900 -TP -std:c++23preview -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXX23PREVIEW %s
+// STDCXX23PREVIEW: -std=c++23
+
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++latest -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXXLATEST %s
 // STDCXXLATEST: -std=c++26
 
diff --git a/clang/test/Preprocessor/predefined-win-macros.c 
b/clang/test/Preprocessor/predefined-win-macros.c
index 7d29e45c7d5ac6..e7988501afa689 100644
--- a/clang/test/Preprocessor/predefined-win-macros.c
+++ b/clang/test/Preprocessor/predefined-win-macros.c
@@ -56,7 +56,7 @@
 // RUN: %clang_cc1 %s -x c++ -E -dM -triple i686-pc-win32 -fms-extensions 
-fms-compatibility \
 // RUN: -fms-compatibility-version=19.00 -std=c++23 -o - | FileCheck 
-match-full-lines %s --check-prefix=CHECK-MS-CPP2B
 // CHECK-MS-CPP2B: #define _MSC_VER 1900
-// CHECK-MS-CPP2B: #define _MSVC_LANG 202004L
+// CHECK-MS-CPP2B: #define _MSVC_LANG 202302L
 
 // RUN: %clang_cc1 -triple i386-windows %s -E -dM -o - \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-WIN

``




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


[clang] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (PR #112378)

2024-10-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Hans (zmodem)


Changes

As discussed in 
https://discourse.llvm.org/t/clang-cl-adding-std-c-23preview/82553

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


5 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1-1) 
- (modified) clang/lib/Basic/Targets/OSTargets.cpp (+1-2) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1) 
- (modified) clang/test/Driver/cl-options.c (+3) 
- (modified) clang/test/Preprocessor/predefined-win-macros.c (+1-1) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6491e9ac73ce99..3390367173a29d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8526,7 +8526,7 @@ def _SLASH_execution_charset : 
CLCompileJoined<"execution-charset:">,
   HelpText<"Set runtime encoding, supports only UTF-8">,
   Alias;
 def _SLASH_std : CLCompileJoined<"std:">,
-  HelpText<"Set language version (c++14,c++17,c++20,c++latest,c11,c17)">;
+  HelpText<"Set language version 
(c++14,c++17,c++20,c++23preview,c++latest,c11,c17)">;
 def _SLASH_U : CLJoinedOrSeparate<"U">, HelpText<"Undefine macro">,
   MetaVarName<"">, Alias;
 def _SLASH_validate_charset : CLFlag<"validate-charset">,
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b56e2c7ca9c494..ff4d2df163e613 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -215,8 +215,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2015)) {
   if (Opts.CPlusPlus23)
-// TODO update to the proper value.
-Builder.defineMacro("_MSVC_LANG", "202004L");
+Builder.defineMacro("_MSVC_LANG", "202302L");
   else if (Opts.CPlusPlus20)
 Builder.defineMacro("_MSVC_LANG", "202002L");
   else if (Opts.CPlusPlus17)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 9d2f7a8960b45f..ca8f10c337e1e9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7217,6 +7217,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
  .Case("c++17", "-std=c++17")
  .Case("c++20", "-std=c++20")
  // TODO add c++23 and c++26 when MSVC supports it.
+ .Case("c++23preview", "-std=c++23")
  .Case("c++latest", "-std=c++26")
  .Default("");
   if (LanguageStandard.empty())
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 48d281bcd447e7..8191fda97788c1 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -605,6 +605,9 @@
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++20 -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXX20 %s
 // STDCXX20: -std=c++20
 
+// RUN: %clang_cl -fmsc-version=1900 -TP -std:c++23preview -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXX23PREVIEW %s
+// STDCXX23PREVIEW: -std=c++23
+
 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++latest -### -- %s 2>&1 | 
FileCheck -check-prefix=STDCXXLATEST %s
 // STDCXXLATEST: -std=c++26
 
diff --git a/clang/test/Preprocessor/predefined-win-macros.c 
b/clang/test/Preprocessor/predefined-win-macros.c
index 7d29e45c7d5ac6..e7988501afa689 100644
--- a/clang/test/Preprocessor/predefined-win-macros.c
+++ b/clang/test/Preprocessor/predefined-win-macros.c
@@ -56,7 +56,7 @@
 // RUN: %clang_cc1 %s -x c++ -E -dM -triple i686-pc-win32 -fms-extensions 
-fms-compatibility \
 // RUN: -fms-compatibility-version=19.00 -std=c++23 -o - | FileCheck 
-match-full-lines %s --check-prefix=CHECK-MS-CPP2B
 // CHECK-MS-CPP2B: #define _MSC_VER 1900
-// CHECK-MS-CPP2B: #define _MSVC_LANG 202004L
+// CHECK-MS-CPP2B: #define _MSVC_LANG 202302L
 
 // RUN: %clang_cc1 -triple i386-windows %s -E -dM -o - \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-WIN

``




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


[clang] [Modules][NFC] Rewrite friend-definition-2.cpp with split-file (PR #112380)

2024-10-15 Thread Dmitry Polukhin via cfe-commits

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

LGTM

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


[clang] [Modules][NFC] Rewrite friend-definition-2.cpp with split-file (PR #112380)

2024-10-15 Thread Dmitry Polukhin via cfe-commits

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


[clang] [Modules][NFC] Rewrite friend-definition-2.cpp with split-file (PR #112380)

2024-10-15 Thread Dmitry Polukhin via cfe-commits


@@ -1,32 +1,53 @@
-// RUN: %clang_cc1 -std=c++14 -fmodules %s -verify
-// RUN: %clang_cc1 -std=c++14 -fmodules %s -verify -triple i686-windows
-// expected-no-diagnostics
-#pragma clang module build A
-module A {}
-#pragma clang module contents
-#pragma clang module begin A
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules -fmodule-name=A -emit-module 
%t/a.modulemap -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules -fmodule-name=B -emit-module 
%t/b.modulemap -o %t/b.pcm
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules 
-fmodule-map-file=%t/a.modulemap -fmodule-map-file=%t/b.modulemap \
+// RUN:   -fmodule-file=%t/a.pcm -fmodule-file=%t/b.pcm \
+// RUN:   %t/use.cc -verify
+
+// RUN: rm -f %t/*.pcm
+
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules -fmodule-name=A -emit-module 
%t/a.modulemap -o %t/a.pcm -triple i686-windows
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules -fmodule-name=B -emit-module 
%t/b.modulemap -o %t/b.pcm -triple i686-windows
+// RUN: %clang_cc1 -std=c++14 -x c++ -fmodules 
-fmodule-map-file=%t/a.modulemap -fmodule-map-file=%t/b.modulemap \
+// RUN:   -fmodule-file=%t/a.pcm -fmodule-file=%t/b.pcm \
+// RUN:   %t/use.cc -verify -triple i686-windows
+
+//--- a.modulemap
+module A {
+  header "a.h"
+}
+
+//--- a.h
+#ifndef A_H
+#define A_H
+template struct ct { friend auto operator-(ct, ct) { struct X {}; 
return X(); } void x(); };
+#endif
+
+//--- b.modulemap
+module B {
+  header "b.h"
+}
+
+//--- b.h
+#ifndef B_H
+#define B_H
 template struct ct { friend auto operator-(ct, ct) { struct X {}; 
return X(); } void x(); };

dmpolukhin wrote:

I think it is better to replace it with `#include "a.h"` and it will have 
exactly the same issue with  #111992 

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


[clang] [llvm] [HLSL] Add handle initialization for simple resource declarations (PR #111207)

2024-10-15 Thread Justin Bogner via cfe-commits


@@ -1,19 +1,21 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-SPIRV
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
+// RUN-DISABLED: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV

bogner wrote:

It's easy to overlook `RUN-DISABLED` in these things - please put a `TODO:` or 
`FIXME:` comment on the preceding line.

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


[clang] [llvm] [HLSL] Add handle initialization for simple resource declarations (PR #111207)

2024-10-15 Thread Justin Bogner via cfe-commits


@@ -489,3 +494,100 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
   GV->eraseFromParent();
   }
 }
+
+// Returns handle type of a resource, if the type is a resource
+// or an array of resources
+static const HLSLAttributedResourceType *findHandleTypeOnResource(QualType QT) 
{
+  // If the type is a resource class, the first field must
+  // be the resource handle of type HLSLAttributedResourceType
+  const clang::Type *Ty = QT->getUnqualifiedDesugaredType();
+  if (RecordDecl *RD = Ty->getAsCXXRecordDecl()) {
+if (!RD->fields().empty()) {
+  const auto &FirstFD = RD->fields().begin();
+  return dyn_cast(
+  FirstFD->getType().getTypePtr());
+}
+  }
+  return nullptr;
+}
+
+void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
+  llvm::GlobalVariable *Var) {
+  // If the global variable has resource binding, add it to the list of globals
+  // that need resource binding initialization.
+  const HLSLResourceBindingAttr *RBA = VD->getAttr();
+  if (!RBA)
+return;
+
+  if (!findHandleTypeOnResource(VD->getType()))
+// FIXME: Only simple declarations of resources are supported for now.
+// Arrays of resources or resources in user defined classes are
+// not implemented yet.
+return;
+
+  ResourcesToBind.emplace_back(std::make_pair(VD, Var));

bogner wrote:

This probably isn't doing what you intended - the constructor that emplace_back 
is calling is pair's copy constructor since we're feeding it with make_pair.

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


[clang] [llvm] [HLSL] Add handle initialization for simple resource declarations (PR #111207)

2024-10-15 Thread Justin Bogner via cfe-commits


@@ -489,3 +494,100 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
   GV->eraseFromParent();
   }
 }
+
+// Returns handle type of a resource, if the type is a resource
+// or an array of resources
+static const HLSLAttributedResourceType *findHandleTypeOnResource(QualType QT) 
{
+  // If the type is a resource class, the first field must
+  // be the resource handle of type HLSLAttributedResourceType
+  const clang::Type *Ty = QT->getUnqualifiedDesugaredType();
+  if (RecordDecl *RD = Ty->getAsCXXRecordDecl()) {
+if (!RD->fields().empty()) {
+  const auto &FirstFD = RD->fields().begin();
+  return dyn_cast(
+  FirstFD->getType().getTypePtr());
+}
+  }
+  return nullptr;
+}
+
+void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
+  llvm::GlobalVariable *Var) {
+  // If the global variable has resource binding, add it to the list of globals
+  // that need resource binding initialization.
+  const HLSLResourceBindingAttr *RBA = VD->getAttr();
+  if (!RBA)
+return;
+
+  if (!findHandleTypeOnResource(VD->getType()))
+// FIXME: Only simple declarations of resources are supported for now.
+// Arrays of resources or resources in user defined classes are
+// not implemented yet.
+return;
+
+  ResourcesToBind.emplace_back(std::make_pair(VD, Var));
+}
+
+llvm::Function *CGHLSLRuntime::createResourceBindingInitFn() {
+  // No resources to bind
+  if (ResourcesToBind.empty())
+return nullptr;
+
+  LLVMContext &Ctx = CGM.getLLVMContext();
+
+  llvm::Function *InitResBindingsFunc =
+  llvm::Function::Create(llvm::FunctionType::get(CGM.VoidTy, false),
+ llvm::GlobalValue::InternalLinkage,
+ "_init_resource_bindings", CGM.getModule());
+
+  llvm::BasicBlock *EntryBB =
+  llvm::BasicBlock::Create(Ctx, "entry", InitResBindingsFunc);
+  CGBuilderTy Builder(CGM, Ctx);
+  const DataLayout &DL = CGM.getModule().getDataLayout();
+  Builder.SetInsertPoint(EntryBB);
+
+  for (auto I : ResourcesToBind) {

bogner wrote:

Could arguably use structured bindings here with `const auto &[VD, GV]`

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


[clang] [llvm] [HLSL] Add handle initialization for simple resource declarations (PR #111207)

2024-10-15 Thread Justin Bogner via cfe-commits


@@ -489,3 +494,100 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
   GV->eraseFromParent();
   }
 }
+
+// Returns handle type of a resource, if the type is a resource
+// or an array of resources
+static const HLSLAttributedResourceType *findHandleTypeOnResource(QualType QT) 
{
+  // If the type is a resource class, the first field must
+  // be the resource handle of type HLSLAttributedResourceType
+  const clang::Type *Ty = QT->getUnqualifiedDesugaredType();
+  if (RecordDecl *RD = Ty->getAsCXXRecordDecl()) {
+if (!RD->fields().empty()) {
+  const auto &FirstFD = RD->fields().begin();
+  return dyn_cast(
+  FirstFD->getType().getTypePtr());
+}
+  }
+  return nullptr;
+}
+
+void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
+  llvm::GlobalVariable *Var) {
+  // If the global variable has resource binding, add it to the list of globals
+  // that need resource binding initialization.
+  const HLSLResourceBindingAttr *RBA = VD->getAttr();
+  if (!RBA)
+return;
+
+  if (!findHandleTypeOnResource(VD->getType()))
+// FIXME: Only simple declarations of resources are supported for now.
+// Arrays of resources or resources in user defined classes are
+// not implemented yet.
+return;
+
+  ResourcesToBind.emplace_back(std::make_pair(VD, Var));
+}
+
+llvm::Function *CGHLSLRuntime::createResourceBindingInitFn() {
+  // No resources to bind
+  if (ResourcesToBind.empty())
+return nullptr;
+
+  LLVMContext &Ctx = CGM.getLLVMContext();
+
+  llvm::Function *InitResBindingsFunc =
+  llvm::Function::Create(llvm::FunctionType::get(CGM.VoidTy, false),
+ llvm::GlobalValue::InternalLinkage,
+ "_init_resource_bindings", CGM.getModule());
+
+  llvm::BasicBlock *EntryBB =
+  llvm::BasicBlock::Create(Ctx, "entry", InitResBindingsFunc);
+  CGBuilderTy Builder(CGM, Ctx);
+  const DataLayout &DL = CGM.getModule().getDataLayout();
+  Builder.SetInsertPoint(EntryBB);
+
+  for (auto I : ResourcesToBind) {
+const VarDecl *VD = I.first;
+llvm::GlobalVariable *Var = I.second;
+
+for (Attr *A : VD->getAttrs()) {
+  HLSLResourceBindingAttr *RBA = dyn_cast(A);
+  if (!RBA)
+continue;
+
+  const HLSLAttributedResourceType *AttrResType =
+  findHandleTypeOnResource(VD->getType());
+  assert(AttrResType != nullptr &&
+ "Resource class must have a handle of 
HLSLAttributedResourceType");
+
+  llvm::Type *TargetTy =
+  CGM.getTargetCodeGenInfo().getHLSLType(CGM, AttrResType);
+  assert(TargetTy != nullptr &&
+ "Failed to convert resource handle to target type");
+
+  llvm::Value *Args[] = {
+  llvm::ConstantInt::get(CGM.IntTy,
+ RBA->getSpaceNumber()), /*RegisterSpace*/
+  llvm::ConstantInt::get(CGM.IntTy,
+ RBA->getSlotNumber()), /*RegisterSlot*/
+  // FIXME: resource arrays are not yet implemented
+  llvm::ConstantInt::get(CGM.IntTy, 1), /*Range*/
+  llvm::ConstantInt::get(CGM.IntTy, 0), /*Index*/
+  // FIXME: NonUniformResourceIndex bit is not yet implemented
+  llvm::ConstantInt::get(llvm::Type::getInt1Ty(Ctx),

bogner wrote:

Better to instantiate the Int1Ty outside of the loop

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


[clang] [llvm] [HLSL] Add handle initialization for simple resource declarations (PR #111207)

2024-10-15 Thread Justin Bogner via cfe-commits


@@ -489,3 +494,100 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
   GV->eraseFromParent();
   }
 }
+
+// Returns handle type of a resource, if the type is a resource
+// or an array of resources
+static const HLSLAttributedResourceType *findHandleTypeOnResource(QualType QT) 
{
+  // If the type is a resource class, the first field must
+  // be the resource handle of type HLSLAttributedResourceType
+  const clang::Type *Ty = QT->getUnqualifiedDesugaredType();
+  if (RecordDecl *RD = Ty->getAsCXXRecordDecl()) {
+if (!RD->fields().empty()) {
+  const auto &FirstFD = RD->fields().begin();
+  return dyn_cast(
+  FirstFD->getType().getTypePtr());
+}
+  }
+  return nullptr;
+}

bogner wrote:

This overlaps with the similar static function in #111203 - how do we plan to 
share logic here?

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


[clang] [clang] Check null TypeSourceInfo in CreateUnaryExprOrTypeTraitExpr (PR #112111)

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


@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+a() {struct b c (sizeof(b * [({ {tree->d* next)} 0
+
+// expected-error@3 {{a type specifier is required for all declarations}}
+// expected-error@3 {{use of undeclared identifier 'tree'; did you mean 
'true'?}}
+// expected-error@3 {{member reference type 'bool' is not a pointer}}
+// expected-error@3 {{expected ';' after expression}}
+// expected-error@3 {{use of undeclared identifier 'next'; did you mean 
'new'?}}
+// expected-error@3 {{expected expression}}
+// expected-error@3 {{expected ';' after expression}}
+// expected-error@26 {{expected '}'}}
+// expected-note@3 {{to match this '{'}}
+// expected-error@26 {{expected ')'}}
+// expected-note@3 {{to match this '('}}
+// expected-error@26 {{expected ']'}}
+// expected-note@3 {{to match this '['}}
+// expected-error@26 {{expected ')'}}
+// expected-note@3 {{to match this '('}}
+// expected-error@3 {{using declaration 'exp' instantiates to an empty pack}}
+// expected-error@3 {{variable has incomplete type 'struct b'}}
+// expected-note@3 {{forward declaration of 'b'}}
+// expected-error@3 {{expected ';' at end of declaration}}
+// expected-error@26 {{expected '}'}}
+// expected-note@3 {{to match this '{'}}
+// expected-warning@3 {{expression result unused}}

erichkeane wrote:

OOof, that is awful.  Is that really the minimal example that causes the crash? 
 I don't really have a great idea.  I might disable the warning with a `-Wno` 
flag, but most of those are not actually important to what we want to do here.  
The whole point is to ensure it doesn't crash/assert, not to make sure we emit 
all those diagnostics.  

We should come up with a way to test "did not crash" instead of this.


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


[clang] [llvm] [HLSL] Add handle initialization for simple resource declarations (PR #111207)

2024-10-15 Thread Justin Bogner via cfe-commits


@@ -489,3 +494,100 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
   GV->eraseFromParent();
   }
 }
+
+// Returns handle type of a resource, if the type is a resource
+// or an array of resources
+static const HLSLAttributedResourceType *findHandleTypeOnResource(QualType QT) 
{
+  // If the type is a resource class, the first field must
+  // be the resource handle of type HLSLAttributedResourceType
+  const clang::Type *Ty = QT->getUnqualifiedDesugaredType();
+  if (RecordDecl *RD = Ty->getAsCXXRecordDecl()) {
+if (!RD->fields().empty()) {
+  const auto &FirstFD = RD->fields().begin();
+  return dyn_cast(
+  FirstFD->getType().getTypePtr());
+}
+  }
+  return nullptr;
+}
+
+void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
+  llvm::GlobalVariable *Var) {
+  // If the global variable has resource binding, add it to the list of globals
+  // that need resource binding initialization.
+  const HLSLResourceBindingAttr *RBA = VD->getAttr();
+  if (!RBA)
+return;
+
+  if (!findHandleTypeOnResource(VD->getType()))
+// FIXME: Only simple declarations of resources are supported for now.
+// Arrays of resources or resources in user defined classes are
+// not implemented yet.
+return;
+
+  ResourcesToBind.emplace_back(std::make_pair(VD, Var));
+}
+
+llvm::Function *CGHLSLRuntime::createResourceBindingInitFn() {
+  // No resources to bind
+  if (ResourcesToBind.empty())
+return nullptr;
+
+  LLVMContext &Ctx = CGM.getLLVMContext();
+
+  llvm::Function *InitResBindingsFunc =
+  llvm::Function::Create(llvm::FunctionType::get(CGM.VoidTy, false),
+ llvm::GlobalValue::InternalLinkage,
+ "_init_resource_bindings", CGM.getModule());
+
+  llvm::BasicBlock *EntryBB =
+  llvm::BasicBlock::Create(Ctx, "entry", InitResBindingsFunc);
+  CGBuilderTy Builder(CGM, Ctx);
+  const DataLayout &DL = CGM.getModule().getDataLayout();
+  Builder.SetInsertPoint(EntryBB);
+
+  for (auto I : ResourcesToBind) {
+const VarDecl *VD = I.first;
+llvm::GlobalVariable *Var = I.second;
+
+for (Attr *A : VD->getAttrs()) {
+  HLSLResourceBindingAttr *RBA = dyn_cast(A);
+  if (!RBA)
+continue;
+
+  const HLSLAttributedResourceType *AttrResType =
+  findHandleTypeOnResource(VD->getType());
+  assert(AttrResType != nullptr &&
+ "Resource class must have a handle of 
HLSLAttributedResourceType");
+
+  llvm::Type *TargetTy =
+  CGM.getTargetCodeGenInfo().getHLSLType(CGM, AttrResType);
+  assert(TargetTy != nullptr &&
+ "Failed to convert resource handle to target type");
+
+  llvm::Value *Args[] = {
+  llvm::ConstantInt::get(CGM.IntTy,
+ RBA->getSpaceNumber()), /*RegisterSpace*/
+  llvm::ConstantInt::get(CGM.IntTy,
+ RBA->getSlotNumber()), /*RegisterSlot*/
+  // FIXME: resource arrays are not yet implemented
+  llvm::ConstantInt::get(CGM.IntTy, 1), /*Range*/
+  llvm::ConstantInt::get(CGM.IntTy, 0), /*Index*/
+  // FIXME: NonUniformResourceIndex bit is not yet implemented
+  llvm::ConstantInt::get(llvm::Type::getInt1Ty(Ctx),
+ false) /*Non-uniform*/
+  };

bogner wrote:

I think this would probably be more readable if we create named temporaries for 
each of these instead of documenting what they are in the comments:
```suggestion
  auto *Space = llvm::ConstantInt::get(CGM.IntTy, RBA->getSpaceNumber());
  auto *Slot = llvm::ConstantInt::get(CGM.IntTy, RBA->getSlotNumber());

  // FIXME: resource arrays are not yet implemented
  auto *Range = llvm::ConstantInt::get(CGM.IntTy, 1);
  auto *Index = llvm::ConstantInt::get(CGM.IntTy, 0);

  // FIXME: NonUniformResourceIndex bit is not yet implemented
  auto *NonUniform = llvm::ConstantInt::get(Int1Ty, false);

  llvm::Value *Args[] = {Space, Slot, Range, Index, NonUniform};
```

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


[clang] [llvm] [AArch64] Introduce new armv9.6 features (PR #111677)

2024-10-15 Thread via cfe-commits


@@ -6,14 +6,50 @@
 // RUN: %clang -target aarch64 -mlittle-endian -march=armv9.6-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV96A %s
 // RUN: %clang -target aarch64_be -mlittle-endian -march=armv9.6a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV96A %s
 // RUN: %clang -target aarch64_be -mlittle-endian -march=armv9.6-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV96A %s
-// GENERICV96A: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.6a"
+// GENERICV96A: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.6a"{{.*}} "-target-feature" "+cmpbr"{{.*}} 
"-target-feature" "+fprcvt"{{.*}} "-target-feature" "+sve2p2"
 
 // RUN: %clang -target aarch64_be -march=armv9.6a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV96A-BE %s
 // RUN: %clang -target aarch64_be -march=armv9.6-a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV96A-BE %s
 // RUN: %clang -target aarch64 -mbig-endian -march=armv9.6a -### -c %s 2>&1 | 
FileCheck -check-prefix=GENERICV96A-BE %s
 // RUN: %clang -target aarch64 -mbig-endian -march=armv9.6-a -### -c %s 2>&1 | 
FileCheck -check-prefix=GENERICV96A-BE %s
 // RUN: %clang -target aarch64_be -mbig-endian -march=armv9.6a -### -c %s 2>&1 
| FileCheck -check-prefix=GENERICV96A-BE %s
 // RUN: %clang -target aarch64_be -mbig-endian -march=armv9.6-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV96A-BE %s
-// GENERICV96A-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.6a"
-//
+// GENERICV96A-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.6a"{{.*}} "-target-feature" "+cmpbr"{{.*}} 
"-target-feature" "+fprcvt"{{.*}} "-target-feature" "+sve2p2"
+
 // = Features supported on aarch64 =
+
+// RUN: %clang -target aarch64 -march=armv9.6a+f8f16mm -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-F8F16MM %s
+// RUN: %clang -target aarch64 -march=armv9.6-a+f8f16mm -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-F8F16MM %s
+// V96A-F8F16MM: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.6a"{{.*}} "-target-feature" "+f8f16mm"
+
+// RUN: %clang -target aarch64 -march=armv9.6a+f8f32mm -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-F8F32MM %s
+// RUN: %clang -target aarch64 -march=armv9.6-a+f8f32mm -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-F8F32MM %s
+// V96A-F8F32MM: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.6a"{{.*}} "-target-feature" "+f8f32mm"
+
+// RUN: %clang -target aarch64 -march=armv9.6a+lsfe -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-LSFE %s
+// RUN: %clang -target aarch64 -march=armv9.6-a+lsfe -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-LSFE %s
+// V96A-LSFE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.6a"{{.*}} "-target-feature" "+lsfe"
+
+// RUN: %clang -target aarch64 -march=armv9.6a+sme2p2 -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-SME2p2 %s
+// RUN: %clang -target aarch64 -march=armv9.6-a+sme2p2 -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-SME2p2 %s
+// V96A-SME2p2: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.6a"{{.*}} "-target-feature" "+sme2p2"

CarolineConcatto wrote:

Does this also adds as well "-target-feature" "+sme2p1"

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


[clang] [llvm] [AArch64] Introduce new armv9.6 features (PR #111677)

2024-10-15 Thread via cfe-commits


@@ -6,14 +6,50 @@
 // RUN: %clang -target aarch64 -mlittle-endian -march=armv9.6-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV96A %s
 // RUN: %clang -target aarch64_be -mlittle-endian -march=armv9.6a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV96A %s
 // RUN: %clang -target aarch64_be -mlittle-endian -march=armv9.6-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV96A %s
-// GENERICV96A: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.6a"
+// GENERICV96A: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.6a"{{.*}} "-target-feature" "+cmpbr"{{.*}} 
"-target-feature" "+fprcvt"{{.*}} "-target-feature" "+sve2p2"
 
 // RUN: %clang -target aarch64_be -march=armv9.6a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV96A-BE %s
 // RUN: %clang -target aarch64_be -march=armv9.6-a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV96A-BE %s
 // RUN: %clang -target aarch64 -mbig-endian -march=armv9.6a -### -c %s 2>&1 | 
FileCheck -check-prefix=GENERICV96A-BE %s
 // RUN: %clang -target aarch64 -mbig-endian -march=armv9.6-a -### -c %s 2>&1 | 
FileCheck -check-prefix=GENERICV96A-BE %s
 // RUN: %clang -target aarch64_be -mbig-endian -march=armv9.6a -### -c %s 2>&1 
| FileCheck -check-prefix=GENERICV96A-BE %s
 // RUN: %clang -target aarch64_be -mbig-endian -march=armv9.6-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV96A-BE %s
-// GENERICV96A-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.6a"
-//
+// GENERICV96A-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.6a"{{.*}} "-target-feature" "+cmpbr"{{.*}} 
"-target-feature" "+fprcvt"{{.*}} "-target-feature" "+sve2p2"
+
 // = Features supported on aarch64 =
+
+// RUN: %clang -target aarch64 -march=armv9.6a+f8f16mm -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-F8F16MM %s
+// RUN: %clang -target aarch64 -march=armv9.6-a+f8f16mm -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-F8F16MM %s
+// V96A-F8F16MM: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.6a"{{.*}} "-target-feature" "+f8f16mm"
+
+// RUN: %clang -target aarch64 -march=armv9.6a+f8f32mm -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-F8F32MM %s
+// RUN: %clang -target aarch64 -march=armv9.6-a+f8f32mm -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-F8F32MM %s
+// V96A-F8F32MM: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.6a"{{.*}} "-target-feature" "+f8f32mm"
+
+// RUN: %clang -target aarch64 -march=armv9.6a+lsfe -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-LSFE %s
+// RUN: %clang -target aarch64 -march=armv9.6-a+lsfe -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-LSFE %s
+// V96A-LSFE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.6a"{{.*}} "-target-feature" "+lsfe"
+
+// RUN: %clang -target aarch64 -march=armv9.6a+sme2p2 -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-SME2p2 %s
+// RUN: %clang -target aarch64 -march=armv9.6-a+sme2p2 -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-SME2p2 %s
+// V96A-SME2p2: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.6a"{{.*}} "-target-feature" "+sme2p2"
+
+// RUN: %clang -target aarch64 -march=armv9.6a+ssve-aes -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-SSVE-AES %s
+// RUN: %clang -target aarch64 -march=armv9.6-a+ssve-aes -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-SSVE-AES %s
+// V96A-SSVE-AES: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.6a"{{.*}} "-target-feature" "+ssve-aes"
+
+// RUN: %clang -target aarch64 -march=armv9.6a+sve2p2 -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-SVE2p2 %s
+// RUN: %clang -target aarch64 -march=armv9.6-a+sve2p2 -### -c %s 2>&1 | 
FileCheck -check-prefix=V96A-SVE2p2 %s
+// V96A-SVE2p2: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.6a"{{.*}} "-target-feature" "+sve2p2"

CarolineConcatto wrote:

Does this also adds "-target-feature" "+sme2p1"?

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


[clang] [compiler-rt] [llvm] [PGO] Initialize GCOV Writeout and Reset Functions in the Runtime on AIX (PR #108570)

2024-10-15 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu updated 
https://github.com/llvm/llvm-project/pull/108570

>From e1b5e886f3f7642ec691a08378a1f2cdc9e2465f Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Wed, 11 Sep 2024 14:56:58 -0400
Subject: [PATCH 1/7] Initial commit.

---
 clang/test/CodeGen/attr-function-return.c |  5 +-
 clang/test/CodeGen/code-coverage.c|  5 +-
 clang/test/CodeGen/coverage-target-attr.c |  5 +-
 compiler-rt/include/profile/InstrProfData.inc | 22 
 compiler-rt/lib/profile/GCDAProfiling.c   | 17 ++
 compiler-rt/lib/profile/InstrProfiling.h  | 11 
 .../lib/profile/InstrProfilingPlatformAIX.c   |  5 +-
 .../lib/profile/InstrProfilingPlatformLinux.c | 16 ++
 .../test/profile/AIX/gcov-undef-sym.test  | 52 +++
 .../llvm/ProfileData/InstrProfData.inc| 22 
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 23 
 .../Instrumentation/GCOVProfiling.cpp | 48 ++---
 .../GCOVProfiling/kcfi-normalize.ll   |  7 +--
 llvm/test/Transforms/GCOVProfiling/kcfi.ll|  7 +--
 .../Transforms/GCOVProfiling/module-flags.ll  |  4 +-
 15 files changed, 218 insertions(+), 31 deletions(-)
 create mode 100644 compiler-rt/test/profile/AIX/gcov-undef-sym.test

diff --git a/clang/test/CodeGen/attr-function-return.c 
b/clang/test/CodeGen/attr-function-return.c
index df2cabf28693a3..9c5cbca5640843 100644
--- a/clang/test/CodeGen/attr-function-return.c
+++ b/clang/test/CodeGen/attr-function-return.c
@@ -17,6 +17,9 @@
 // RUN:  -mfunction-return=thunk-extern -fsanitize=thread \
 // RUN:   | FileCheck %s --check-prefix=CHECK-TSAN
 
+// Check for gcov initialization function pointers.
+// CHECK-GCOV: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr 
@__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"
+
 #if !__has_attribute(function_return)
 #error "missing attribute support for function_return"
 #endif
@@ -104,7 +107,7 @@ void no_attrs(void) {}
 // Test synthetic functions.
 // CHECK-GCOV: @__llvm_gcov_writeout() unnamed_addr [[EXTERNGCOV:#[0-9]+]]
 // CHECK-GCOV: @__llvm_gcov_reset() unnamed_addr [[EXTERNGCOV]]
-// CHECK-GCOV: @__llvm_gcov_init() unnamed_addr [[EXTERNGCOV]]
+// CHECK-GCOV-NOT: @__llvm_gcov_init() unnamed_addr [[EXTERNGCOV]]
 // CHECK-ASAN: @asan.module_ctor() [[EXTERNASAN:#[0-9]+]]
 // CHECK-TSAN: @tsan.module_ctor() [[EXTERNTSAN:#[0-9]+]]
 
diff --git a/clang/test/CodeGen/code-coverage.c 
b/clang/test/CodeGen/code-coverage.c
index d7994bab35d81a..4e3f0aba8c4098 100644
--- a/clang/test/CodeGen/code-coverage.c
+++ b/clang/test/CodeGen/code-coverage.c
@@ -49,10 +49,13 @@ int test2(int b) {
 /// 0x3430382a '4' '0' '8' '*'
 // 408-SAME: i32 875575338
 
+// Check for gcov initialization function pointers.
+// CHECK: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr 
@__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"
+
 // Check that the noredzone flag is set on the generated functions.
 
 // CHECK: void @__llvm_gcov_writeout() unnamed_addr [[NRZ:#[0-9]+]]
-// CHECK: void @__llvm_gcov_init() unnamed_addr [[NRZ]]
+// CHECK-NOT: void @__llvm_gcov_init() unnamed_addr [[NRZ]]
 
 // CHECK: attributes [[NRZ]] = { {{.*}}noredzone{{.*}} }
 
diff --git a/clang/test/CodeGen/coverage-target-attr.c 
b/clang/test/CodeGen/coverage-target-attr.c
index d46299f5bee223..156e48ba6a31a2 100644
--- a/clang/test/CodeGen/coverage-target-attr.c
+++ b/clang/test/CodeGen/coverage-target-attr.c
@@ -1,9 +1,12 @@
 // RUN: %clang_cc1 -emit-llvm -coverage-notes-file=/dev/null 
-coverage-data-file=/dev/null -triple aarch64-linux-android30 -target-cpu 
generic -target-feature +tagged-globals -fsanitize=hwaddress %s -o %t
 // RUN: FileCheck %s < %t
 
+// Check for gcov initialization function pointers.
+// CHECK: @__llvm_covinit_functions = private constant { ptr, ptr } { ptr 
@__llvm_gcov_writeout, ptr @__llvm_gcov_reset }, section "__llvm_covinit"
+
 // CHECK: define internal void @__llvm_gcov_writeout() unnamed_addr 
[[ATTR:#[0-9]+]]
 // CHECK: define internal void @__llvm_gcov_reset() unnamed_addr [[ATTR]]
-// CHECK: define internal void @__llvm_gcov_init() unnamed_addr [[ATTR]]
+// CHECK-NOT: define internal void @__llvm_gcov_init() unnamed_addr [[ATTR]]
 // CHECK: define internal void @hwasan.module_ctor() [[ATTR2:#[0-9]+]]
 // CHECK: attributes [[ATTR]] = {{.*}} "target-cpu"="generic" 
"target-features"="+tagged-globals"
 // CHECK: attributes [[ATTR2]] = {{.*}} "target-cpu"="generic" 
"target-features"="+tagged-globals"
diff --git a/compiler-rt/include/profile/InstrProfData.inc 
b/compiler-rt/include/profile/InstrProfData.inc
index b9df3266fbcf8f..591fc1401e1aab 100644
--- a/compiler-rt/include/profile/InstrProfData.inc
+++ b/compiler-rt/include/profile/InstrProfData.inc
@@ -303,6 +303,18 @@ COVMAP_HEADER(uint32_t, Int32Ty, Version, \
 #undef COVMAP_HEADER
 /* COVMAP_HEADER end.  */
 
+/* COVINIT_FUNC start */
+#ifndef COVINIT_FUNC
+#define COVINIT_FUNC(Type, LLVMT

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

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

https://github.com/budimirarandjelovichtec updated 
https://github.com/llvm/llvm-project/pull/105479

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

---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Sema/Attr.h   |   7 +
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/Sema/SemaDecl.cpp   |   2 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 220 +-
 clang/test/Sema/attr-format-missing.c | 217 +
 clang/test/Sema/attr-format-missing.cpp   | 180 ++
 9 files changed, 631 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 817e3abef8d566..03a64b9238e2bc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -403,6 +403,8 @@ Improvements to Clang's diagnostics
   name was a reserved name, which we improperly allowed to suppress the
   diagnostic.
 
+- Clang now diagnoses missing format attributes for non-template functions and 
class/struct/union members. (#GH60718)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 8273701e7b0963..417f2dbdc6a68a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -529,7 +529,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def MissingIncludeDirs : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e78acc8dc8c57b..1fd5a455a1a205 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1051,6 +1051,9 @@ def err_opencl_invalid_param : Error<
   "declaring function parameter of type %0 is not allowed%select{; did you 
forget * ?|}1">;
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Attr.h b/clang/include/clang/Sema/Attr.h
index 3f0b10212789a4..37c124ca7b454a 100644
--- a/clang/include/clang/Sema/Attr.h
+++ b/clang/include/clang/Sema/Attr.h
@@ -123,6 +123,13 @@ inline bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+inline bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 /// Diagnose mutually exclusive attributes when present on a given
 /// declaration. Returns true if diagnosed.
 template 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0faa5aed4eec3b..44e52c6d81c7c2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4576,6 +4576,8 @@ class Sema final : public SemaBase {
 
   enum class RetainOwnershipKind { NS, CF, OS };
 
+  void DiagnoseMissingFormatAttributes(Stmt *Body, const FunctionDecl *FDecl);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fece22c663d00c..e69ffe8f729fde 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16034,6 +16034,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 }
   }
 
+  DiagnoseMissingFormatAttributes(Body, FD);
+
   // We might not have found a prototype because we didn't wish to warn on
   // the lack of a missing prototype. Try again without the checks for
   // whether we want to warn on the missing prototype.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 6759aae37afac1..cfd0be6534d02c 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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

erichkeane wrote:

> Hmm, I can’t really think of a situation when this note would actually 
> help... at least for `deprecated`, you could _maybe_ argue that you might 
> want to know what part of the codebase marked it as deprecated in case there 
> are multiple declarations, but for `nodiscard`, I don’t think you really care 
> that much, so I feel like this might just be adding noise instead of helping. 
> Imo just the error is enough, but that’s just my opinion.

The one use case I could see is that the `nodiscard` is on the TYPE instead of 
the function itself (which, as you said before, is goofy for an overload set 
with this only partially applied).  But I don't really see value besides "this 
should not be discarded", and the actual location of the attribute isn't 
particularly valuable.  What IS important is the 'reason', which we already 
have.

So this is definitely causing me troubles with 'motivation'.

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


[clang] [llvm] [Inliner] Propagate more attributes to params when inlining (PR #91101)

2024-10-15 Thread via cfe-commits

https://github.com/goldsteinn updated 
https://github.com/llvm/llvm-project/pull/91101

>From 98dd7c653c3b15987d8dbc516c30ea1c6cae6593 Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Sat, 4 May 2024 18:12:34 -0500
Subject: [PATCH 1/3] [Inliner] Add tests for propagating more parameter
 attributes; NFC

---
 .../Inline/access-attributes-prop.ll  | 154 +-
 1 file changed, 152 insertions(+), 2 deletions(-)

diff --git a/llvm/test/Transforms/Inline/access-attributes-prop.ll 
b/llvm/test/Transforms/Inline/access-attributes-prop.ll
index 5051c92345ec75..90da1c4d4cb31b 100644
--- a/llvm/test/Transforms/Inline/access-attributes-prop.ll
+++ b/llvm/test/Transforms/Inline/access-attributes-prop.ll
@@ -47,7 +47,6 @@ define dso_local void @foo3_writable(ptr %p) {
   ret void
 }
 
-
 define dso_local void @foo1_bar_aligned64_deref512(ptr %p) {
 ; CHECK-LABEL: define {{[^@]+}}@foo1_bar_aligned64_deref512
 ; CHECK-SAME: (ptr [[P:%.*]]) {
@@ -333,6 +332,16 @@ define void @prop_param_nonnull_and_align(ptr %p) {
   ret void
 }
 
+define void @prop_param_nofree_and_align(ptr %p) {
+; CHECK-LABEL: define {{[^@]+}}@prop_param_nofree_and_align
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:call void @bar1(ptr [[P]])
+; CHECK-NEXT:ret void
+;
+  call void @foo1(ptr nofree align 32 %p)
+  ret void
+}
+
 define void @prop_param_deref_align_no_update(ptr %p) {
 ; CHECK-LABEL: define {{[^@]+}}@prop_param_deref_align_no_update
 ; CHECK-SAME: (ptr [[P:%.*]]) {
@@ -539,7 +548,6 @@ define void @prop_no_conflict_writable(ptr %p) {
   ret void
 }
 
-
 define void @prop_no_conflict_writable2(ptr %p) {
 ; CHECK-LABEL: define {{[^@]+}}@prop_no_conflict_writable2
 ; CHECK-SAME: (ptr [[P:%.*]]) {
@@ -600,3 +608,145 @@ define void @prop_byval_readonly2(ptr %p) {
   call void @foo_byval_readonly2(ptr %p)
   ret void
 }
+
+declare void @bar5(i32)
+
+define dso_local void @foo4_range_0_10(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@foo4_range_0_10
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar5(i32 range(i32 0, 10) [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @bar5(i32 range(i32 0, 10) %v)
+  ret void
+}
+
+define dso_local void @foo4_range_10_40(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@foo4_range_10_40
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar5(i32 range(i32 10, 40) [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @bar5(i32 range(i32 10, 40) %v)
+  ret void
+}
+
+define dso_local void @foo4_2_range_0_10(i32 range(i32 0, 10) %v) {
+; CHECK-LABEL: define {{[^@]+}}@foo4_2_range_0_10
+; CHECK-SAME: (i32 range(i32 0, 10) [[V:%.*]]) {
+; CHECK-NEXT:call void @bar5(i32 [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @bar5(i32 %v)
+  ret void
+}
+
+define dso_local void @foo4(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@foo4
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar5(i32 [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @bar5(i32 %v)
+  ret void
+}
+
+define void @prop_range_empty_intersect(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_empty_intersect
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar5(i32 range(i32 0, 10) [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4_range_0_10(i32 range(i32 11, 50) %v)
+  ret void
+}
+
+define void @prop_range_empty(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_empty
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar5(i32 [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4(i32 range(i32 1, 0) %v)
+  ret void
+}
+
+define void @prop_range_empty_with_intersect(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_empty_with_intersect
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar5(i32 range(i32 0, 10) [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4_range_0_10(i32 range(i32 1, 0) %v)
+  ret void
+}
+
+define void @prop_range_intersect1(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_intersect1
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar5(i32 range(i32 0, 10) [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4_range_0_10(i32 range(i32 0, 9) %v)
+  ret void
+}
+
+define void @prop_range_intersect2(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_intersect2
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar5(i32 range(i32 0, 10) [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4_range_0_10(i32 range(i32 1, 9) %v)
+  ret void
+}
+
+define void @prop_range_intersect3(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_intersect3
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar5(i32 [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4_2_range_0_10(i32 range(i32 0, 11) %v)
+  ret void
+}
+
+define void @prop_range_intersect4(i32 %v) {
+; CHECK-LABEL: define {{[^@]+}}@prop_range_intersect4
+; CHECK-SAME: (i32 [[V:%.*]]) {
+; CHECK-NEXT:call void @bar5(i32 range(i32 0, 10) [[V]])
+; CHECK-NEXT:ret void
+;
+  call void @foo4_range_0_10(i32 range(i3

[clang] [compiler-rt] [llvm] [PGO] Initialize GCOV Writeout and Reset Functions in the Runtime on AIX (PR #108570)

2024-10-15 Thread Qiongsi Wu via cfe-commits


@@ -0,0 +1,129 @@
+; Tests if the __llvm_gcov_ctr section contains a .ref pseudo-op
+; referring to the __llvm_covinit section.
+; RUN: llc < %s | FileCheck --check-prefixes=CHECK,CHECK-RW %s
+; RUN: llc -mxcoff-roptr < %s | FileCheck --check-prefixes=CHECK,CHECK-RO %s
+
+target datalayout = "E-m:a-p:32:32-Fi32-i64:64-n32"
+target triple = "powerpc-ibm-aix"
+
+; CHECK-RW: .csect __llvm_covinit[RW],3
+; CHECK-RO: .csect __llvm_covinit[RO],3
+; CHECK: .vbyte  4, __llvm_gcov_writeout[DS]
+; CHECK-NEXT:.vbyte  4, __llvm_gcov_reset[DS]
+; CHECK: __llvm_gcov_ctr.1:
+; CHECK-NEXT: .extern .llvm_gcda_start_file[PR]
+; CHECK-NEXT:.extern .llvm_gcda_emit_function[PR]
+; CHECK-NEXT:.extern .llvm_gcda_emit_arcs[PR]
+; CHECK-NEXT:.extern .llvm_gcda_summary_info[PR]
+; CHECK-NEXT:.extern .llvm_gcda_end_file[PR]
+; CHECK-RW-NEXT:.ref __llvm_covinit[RW]
+; CHECK-RO-NEXT:.ref __llvm_covinit[RO]

qiongsiwu wrote:

Fixed. I think this is because of the global merge that happens in `llc`. 

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


[clang] [compiler-rt] [llvm] [PGO] Initialize GCOV Writeout and Reset Functions in the Runtime on AIX (PR #108570)

2024-10-15 Thread Qiongsi Wu via cfe-commits


@@ -0,0 +1,129 @@
+; Tests if the __llvm_gcov_ctr section contains a .ref pseudo-op
+; referring to the __llvm_covinit section.
+; RUN: llc < %s | FileCheck --check-prefixes=CHECK,CHECK-RW %s
+; RUN: llc -mxcoff-roptr < %s | FileCheck --check-prefixes=CHECK,CHECK-RO %s
+
+target datalayout = "E-m:a-p:32:32-Fi32-i64:64-n32"
+target triple = "powerpc-ibm-aix"
+
+; CHECK-RW: .csect __llvm_covinit[RW],3
+; CHECK-RO: .csect __llvm_covinit[RO],3
+; CHECK: .vbyte  4, __llvm_gcov_writeout[DS]
+; CHECK-NEXT:.vbyte  4, __llvm_gcov_reset[DS]

qiongsiwu wrote:

The test is modified to make sure we use `CHECK-NEXT`s after the csect changing 
directive. 

> It is important that no active-csect changing directives are present.

Could you help me understand why this is the case? The intention of the test is 
to make sure that the `__llvm_covinit` csect has the correct storage mapping 
class and contents. That's why the test includes the `csect` directive. 

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


[clang] [CLANG][AArch64] Add the modal 8 bit floating-point scalar type (PR #97277)

2024-10-15 Thread via cfe-commits

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

>From edf2f6c977d06627f7a752a0128ffcb04c082c38 Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Mon, 24 Jun 2024 09:59:24 +
Subject: [PATCH 1/3] [CLANG][AArch64] Add the  modal 8 bit floating-point
 scalar type

ARM ACLE PR#323[1] adds new modal types for 8-bit floating point intrinsic.

>From the PR#323:
```
ACLE defines the `__mfp8` type, which can be used for the E5M2 and E4M3
8-bit floating-point formats. It is a storage and interchange only type
with no arithmetic operations other than intrinsic calls.


The type should be an opaque type and its format in undefined in Clang.
Only defined in the backend by a status/format register, for AArch64 the FPMR.

This patch is an attempt to the add the MFloat8_t scalar type.
It has a parser and codegen for the new scalar type.

The patch it is lowering to and 8bit unsigned as it has no format.
But maybe we should add another opaque type.

[1]  https://github.com/ARM-software/acle/pull/323
---
 clang/include/clang/AST/Type.h|  7 ++
 .../clang/Basic/AArch64SVEACLETypes.def   |  9 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/include/clang/Basic/Specifiers.h|  1 +
 clang/include/clang/Basic/TargetInfo.h|  4 +
 clang/include/clang/Basic/TokenKinds.def  |  1 +
 clang/include/clang/Sema/DeclSpec.h   |  2 +
 .../include/clang/Serialization/ASTBitCodes.h |  2 +-
 clang/lib/AST/ASTContext.cpp  | 13 ++-
 clang/lib/AST/ItaniumMangle.cpp   |  6 ++
 clang/lib/AST/Type.cpp| 25 -
 clang/lib/Basic/TargetInfo.cpp|  1 +
 clang/lib/Basic/Targets/AArch64.cpp   |  6 ++
 clang/lib/Basic/Targets/AArch64.h |  3 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  7 ++
 clang/lib/CodeGen/CodeGenTypes.cpp|  6 +-
 clang/lib/Parse/ParseDecl.cpp |  7 ++
 clang/lib/Parse/ParseExpr.cpp |  1 +
 clang/lib/Parse/ParseExprCXX.cpp  |  4 +
 clang/lib/Parse/ParseTentative.cpp|  2 +
 clang/lib/Sema/DeclSpec.cpp   |  3 +
 clang/lib/Sema/SemaCast.cpp   |  8 ++
 clang/lib/Sema/SemaExpr.cpp   |  6 ++
 clang/lib/Sema/SemaTemplateVariadic.cpp   |  1 +
 clang/lib/Sema/SemaType.cpp   |  6 +-
 clang/test/AST/arm-mfp8.cpp   | 94 +++
 clang/test/CodeGen/arm-mfp8.c | 26 +
 clang/test/Modules/no-external-type-id.cppm   |  2 +-
 clang/test/Sema/arm-mfp8.c| 11 +++
 clang/test/Sema/arm-mfp8.cpp  | 35 +++
 30 files changed, 293 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/AST/arm-mfp8.cpp
 create mode 100644 clang/test/CodeGen/arm-mfp8.c
 create mode 100644 clang/test/Sema/arm-mfp8.c
 create mode 100644 clang/test/Sema/arm-mfp8.cpp

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..195d471bb155fb 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2644,6 +2644,8 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isQueueT() const;// OpenCL queue_t
   bool isReserveIDT() const;// OpenCL reserve_id_t
 
+  bool isArmMFloat8Type() const; // AARCH64_OPAQUE_TYPE
+
 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
   bool is##Id##Type() const;
 #include "clang/Basic/OpenCLExtensionTypes.def"
@@ -8312,6 +8314,11 @@ inline bool Type::isBitIntType() const {
   return isa(CanonicalType);
 }
 
+// AARCH64_OPAQUE_TYPE
+inline bool Type::isArmMFloat8Type() const {
+  return isSpecificBuiltinType(BuiltinType::ArmMFloat8);
+}
+
 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
   inline bool Type::is##Id##Type() const { \
 return isSpecificBuiltinType(BuiltinType::Id); \
diff --git a/clang/include/clang/Basic/AArch64SVEACLETypes.def 
b/clang/include/clang/Basic/AArch64SVEACLETypes.def
index 55ed9c36f6c5cd..53644905b789b7 100644
--- a/clang/include/clang/Basic/AArch64SVEACLETypes.def
+++ b/clang/include/clang/Basic/AArch64SVEACLETypes.def
@@ -97,6 +97,12 @@
   SVE_TYPE(Name, Id, SingletonId)
 #endif
 
+#ifndef AARCH64_OPAQUE_TYPE
+#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
+ElBits, NF) \
+  SVE_TYPE(Name, Id, SingletonId)
+#endif
+
 //===- Vector point types ---===//
 
 SVE_VECTOR_TYPE_INT("__SVInt8_t",  "__SVInt8_t",  SveInt8,  SveInt8Ty, 16,  8, 
1, true)
@@ -181,6 +187,8 @@ SVE_PREDICATE_TYPE_ALL("__clang_svboolx4_t", "svboolx4_t", 
SveBoolx4, SveBoolx4T
 
 SVE_OPAQUE_TYPE("__SVCount_t", "__SVCount_t", SveCount, SveCountTy)
 
+AARCH64_OPAQUE_TYPE("__MFloat8_t", "__MFloat8_t", ArmMFloat8, ArmMFloat8Ty, 1, 
8, 1)
+
 #undef SVE_VECTOR_TYPE
 #undef SVE_VECTOR_TYPE_BFLOAT
 #undef SVE_VEC

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits


@@ -204,23 +205,29 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr 
*E) {
   return true;
 }
 
-static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A,
-  SourceLocation Loc, SourceRange R1,
-  SourceRange R2, bool IsCtor) {
+static bool DiagnoseNoDiscard(Sema &S, const NamedDecl *OffendingDecl,
+  const WarnUnusedResultAttr *A, SourceLocation 
Loc,
+  SourceRange R1, SourceRange R2, bool IsCtor) {
   if (!A)
 return false;
   StringRef Msg = A->getMessage();
 
+  bool result;
   if (Msg.empty()) {
 if (IsCtor)
-  return S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
-return S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
-  }
+  result = S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
+else
+  result = S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
+  } else if (IsCtor)
+result = S.Diag(Loc, diag::warn_unused_constructor_msg)
+ << A << Msg << R1 << R2;
+  else
+result = S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
 
-  if (IsCtor)
-return S.Diag(Loc, diag::warn_unused_constructor_msg) << A << Msg << R1
-  << R2;
-  return S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
+  if (OffendingDecl)

Mick235711 wrote:

Well, the initial motivation for that if is the following call site:
```cpp
const NamedDecl *OffendingDecl;
const Attr *A;
std::tie(OffendingDecl, A) = CE->getUnusedResultAttr(Context);
if (DiagnoseNoDiscard(*this, OffendingDecl,
  cast_or_null(A), Loc, R1, R2,
  /*isCtor=*/false))
  return;
```
In `CallExpr::getUnusedResultAttr` we tried to see if the callee is marked 
nodiscard and if so, returns that instead. However `getCalleeDecl()` returns a 
`const Decl *`, but the diagnostic requires a `const NamedDecl *`, so I 
dyn_cast it down. If the actual dynamic type is always NamedDecl or its 
subclass, maybe here the return value cannot ever be `nullptr` to begin with? I 
was not sure about this so I added the check.

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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


@@ -204,23 +205,29 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr 
*E) {
   return true;
 }
 
-static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A,
-  SourceLocation Loc, SourceRange R1,
-  SourceRange R2, bool IsCtor) {
+static bool DiagnoseNoDiscard(Sema &S, const NamedDecl *OffendingDecl,
+  const WarnUnusedResultAttr *A, SourceLocation 
Loc,
+  SourceRange R1, SourceRange R2, bool IsCtor) {
   if (!A)
 return false;
   StringRef Msg = A->getMessage();
 
+  bool result;
   if (Msg.empty()) {
 if (IsCtor)
-  return S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
-return S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
-  }
+  result = S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
+else
+  result = S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
+  } else if (IsCtor)
+result = S.Diag(Loc, diag::warn_unused_constructor_msg)
+ << A << Msg << R1 << R2;
+  else
+result = S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
 
-  if (IsCtor)
-return S.Diag(Loc, diag::warn_unused_constructor_msg) << A << Msg << R1
-  << R2;
-  return S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
+  if (OffendingDecl)

erichkeane wrote:

I can't imagine anything that would not be a `NamedDecl` that one could put the 
`nodiscard` on.  Also though, WHY dose it have to be a `NamedDecl`?  We only 
need the location for the diagnostic anyway, so having `getUnusedResultAttr` 
return just a `Decl` is probably sufficient.

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


[clang] [CLANG][AArch64] Add the modal 8 bit floating-point scalar type (PR #97277)

2024-10-15 Thread via cfe-commits

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

>From edf2f6c977d06627f7a752a0128ffcb04c082c38 Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Mon, 24 Jun 2024 09:59:24 +
Subject: [PATCH 1/4] [CLANG][AArch64] Add the  modal 8 bit floating-point
 scalar type

ARM ACLE PR#323[1] adds new modal types for 8-bit floating point intrinsic.

>From the PR#323:
```
ACLE defines the `__mfp8` type, which can be used for the E5M2 and E4M3
8-bit floating-point formats. It is a storage and interchange only type
with no arithmetic operations other than intrinsic calls.


The type should be an opaque type and its format in undefined in Clang.
Only defined in the backend by a status/format register, for AArch64 the FPMR.

This patch is an attempt to the add the MFloat8_t scalar type.
It has a parser and codegen for the new scalar type.

The patch it is lowering to and 8bit unsigned as it has no format.
But maybe we should add another opaque type.

[1]  https://github.com/ARM-software/acle/pull/323
---
 clang/include/clang/AST/Type.h|  7 ++
 .../clang/Basic/AArch64SVEACLETypes.def   |  9 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/include/clang/Basic/Specifiers.h|  1 +
 clang/include/clang/Basic/TargetInfo.h|  4 +
 clang/include/clang/Basic/TokenKinds.def  |  1 +
 clang/include/clang/Sema/DeclSpec.h   |  2 +
 .../include/clang/Serialization/ASTBitCodes.h |  2 +-
 clang/lib/AST/ASTContext.cpp  | 13 ++-
 clang/lib/AST/ItaniumMangle.cpp   |  6 ++
 clang/lib/AST/Type.cpp| 25 -
 clang/lib/Basic/TargetInfo.cpp|  1 +
 clang/lib/Basic/Targets/AArch64.cpp   |  6 ++
 clang/lib/Basic/Targets/AArch64.h |  3 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  7 ++
 clang/lib/CodeGen/CodeGenTypes.cpp|  6 +-
 clang/lib/Parse/ParseDecl.cpp |  7 ++
 clang/lib/Parse/ParseExpr.cpp |  1 +
 clang/lib/Parse/ParseExprCXX.cpp  |  4 +
 clang/lib/Parse/ParseTentative.cpp|  2 +
 clang/lib/Sema/DeclSpec.cpp   |  3 +
 clang/lib/Sema/SemaCast.cpp   |  8 ++
 clang/lib/Sema/SemaExpr.cpp   |  6 ++
 clang/lib/Sema/SemaTemplateVariadic.cpp   |  1 +
 clang/lib/Sema/SemaType.cpp   |  6 +-
 clang/test/AST/arm-mfp8.cpp   | 94 +++
 clang/test/CodeGen/arm-mfp8.c | 26 +
 clang/test/Modules/no-external-type-id.cppm   |  2 +-
 clang/test/Sema/arm-mfp8.c| 11 +++
 clang/test/Sema/arm-mfp8.cpp  | 35 +++
 30 files changed, 293 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/AST/arm-mfp8.cpp
 create mode 100644 clang/test/CodeGen/arm-mfp8.c
 create mode 100644 clang/test/Sema/arm-mfp8.c
 create mode 100644 clang/test/Sema/arm-mfp8.cpp

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index dc87b84153e74a..195d471bb155fb 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2644,6 +2644,8 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isQueueT() const;// OpenCL queue_t
   bool isReserveIDT() const;// OpenCL reserve_id_t
 
+  bool isArmMFloat8Type() const; // AARCH64_OPAQUE_TYPE
+
 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
   bool is##Id##Type() const;
 #include "clang/Basic/OpenCLExtensionTypes.def"
@@ -8312,6 +8314,11 @@ inline bool Type::isBitIntType() const {
   return isa(CanonicalType);
 }
 
+// AARCH64_OPAQUE_TYPE
+inline bool Type::isArmMFloat8Type() const {
+  return isSpecificBuiltinType(BuiltinType::ArmMFloat8);
+}
+
 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
   inline bool Type::is##Id##Type() const { \
 return isSpecificBuiltinType(BuiltinType::Id); \
diff --git a/clang/include/clang/Basic/AArch64SVEACLETypes.def 
b/clang/include/clang/Basic/AArch64SVEACLETypes.def
index 55ed9c36f6c5cd..53644905b789b7 100644
--- a/clang/include/clang/Basic/AArch64SVEACLETypes.def
+++ b/clang/include/clang/Basic/AArch64SVEACLETypes.def
@@ -97,6 +97,12 @@
   SVE_TYPE(Name, Id, SingletonId)
 #endif
 
+#ifndef AARCH64_OPAQUE_TYPE
+#define AARCH64_OPAQUE_TYPE(Name, MangledName, Id, SingletonId, NumEls, \
+ElBits, NF) \
+  SVE_TYPE(Name, Id, SingletonId)
+#endif
+
 //===- Vector point types ---===//
 
 SVE_VECTOR_TYPE_INT("__SVInt8_t",  "__SVInt8_t",  SveInt8,  SveInt8Ty, 16,  8, 
1, true)
@@ -181,6 +187,8 @@ SVE_PREDICATE_TYPE_ALL("__clang_svboolx4_t", "svboolx4_t", 
SveBoolx4, SveBoolx4T
 
 SVE_OPAQUE_TYPE("__SVCount_t", "__SVCount_t", SveCount, SveCountTy)
 
+AARCH64_OPAQUE_TYPE("__MFloat8_t", "__MFloat8_t", ArmMFloat8, ArmMFloat8Ty, 1, 
8, 1)
+
 #undef SVE_VECTOR_TYPE
 #undef SVE_VECTOR_TYPE_BFLOAT
 #undef SVE_VEC

[clang] [Clang][Sema] Use the correct injected template arguments for partial specializations when collecting multi-level template argument lists (PR #112381)

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

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

Change itself seems reasonable, so approve, pending a good couple of tests.

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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


@@ -9290,6 +9290,8 @@ def warn_unused_result_typedef_unsupported_spelling : 
Warning<
 def warn_unused_volatile : Warning<
   "expression result unused; assign into a variable to force a volatile load">,
   InGroup>;
+def note_nodiscard_specified_here : Note<

erichkeane wrote:

Either a string parameter, or add another select entry/ies.  Thats easy enough. 
An alternative is to add an enum for them with an operator << overload 
available.

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits


@@ -290,9 +297,12 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, 
unsigned DiagID) {
 if (E->getType()->isVoidType())
   return;
 
-if (DiagnoseNoDiscard(*this, cast_or_null(
- CE->getUnusedResultAttr(Context)),
-  Loc, R1, R2, /*isCtor=*/false))
+const NamedDecl *OffendingDecl;
+const Attr *A;
+std::tie(OffendingDecl, A) = CE->getUnusedResultAttr(Context);

Mick235711 wrote:

Oh I don't see structured binding used in this file, so I just copied the 
existing usage of `tie`. Will be fixed in the next push.

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


[clang] [compiler-rt] [lld] [llvm] [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (PR #111332)

2024-10-15 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`bolt-aarch64-ubuntu-clang-shared` running on `bolt-worker-aarch64` while 
building `clang,compiler-rt,lld,llvm` at step 8 "test-build-bolt-check-bolt".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/126/builds/809


Here is the relevant piece of the build log for the reference

```
Step 8 (test-build-bolt-check-bolt) failure: test (failure)
...
55.081 [644/6/959] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaLoongArch.cpp.o
55.082 [643/6/960] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaInit.cpp.o
55.115 [642/6/961] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaMSP430.cpp.o
55.122 [641/6/962] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaM68k.cpp.o
55.134 [640/6/963] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaMIPS.cpp.o
55.198 [639/6/964] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaNVPTX.cpp.o
55.241 [638/6/965] Building CXX object 
tools/lld/wasm/CMakeFiles/lldWasm.dir/Writer.cpp.o
55.295 [637/6/966] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaOpenACC.cpp.o
55.416 [636/6/967] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaOpenCL.cpp.o
55.430 [635/6/968] Linking CXX shared library lib/liblldWasm.so.20.0git
FAILED: lib/liblldWasm.so.20.0git 
: && /usr/bin/clang++ -fPIC -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -O3 -DNDEBUG  -Wl,-z,defs -Wl,-z,nodelete 
-fuse-ld=mold -Wl,--color-diagnostics   -Wl,--gc-sections -shared 
-Wl,-soname,liblldWasm.so.20.0git -o lib/liblldWasm.so.20.0git 
tools/lld/wasm/CMakeFiles/lldWasm.dir/Driver.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/InputChunks.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/InputFiles.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/LTO.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/MapFile.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/MarkLive.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/OutputSections.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/OutputSegment.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/Relocations.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/SymbolTable.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/Symbols.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/SyntheticSections.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/Writer.cpp.o 
tools/lld/wasm/CMakeFiles/lldWasm.dir/WriterUtils.cpp.o  
-Wl,-rpath,"\$ORIGIN/../lib:/home/worker/buildbot-aarch64/bolt-aarch64-ubuntu-clang-shared/build/lib:"
  lib/liblldCommon.so.20.0git  lib/libLLVMX86CodeGen.so.20.0git  
lib/libLLVMX86AsmParser.so.20.0git  lib/libLLVMX86Desc.so.20.0git  
lib/libLLVMX86Disassembler.so.20.0git  lib/libLLVMX86Info.so.20.0git  
lib/libLLVMAArch64CodeGen.so.20.0git  lib/libLLVMAArch64AsmParser.so.20.0git  
lib/libLLVMAArch64Disassembler.so.20.0git  lib/libLLVMRISCVCodeGen.so.20.0git  
lib/libLLVMRISCVAsmParser.so.20.0git  lib/libLLVMRISCVDisassembler.so.20.0git  
lib/libLLVMLTO.so.20.0git  lib/libLLVMOption.so.20.0git  
lib/libLLVMPasses.so.20.0git  lib/libLLVMAArch64Desc.so.20.0git  
lib/libLLVMAArch64Info.so.20.0git  lib/libLLVMAArch64Utils.so.20.0git  
lib/libLLVMRISCVDesc.so.20.0git  lib/libLLVMRISCVInfo.so.20.0git  
lib/libLLVMObject.so.20.0git  lib/libLLVMMC.so.20.0git  
lib/libLLVMCore.so.20.0git  lib/libLLVMBinaryFormat.so.20.0git  
lib/libLLVMTargetParser.so.20.0git  lib/libLLVMSupport.so.20.0git  
lib/libLLVMDemangle.so.20.0git  
-Wl,-rpath-link,/home/worker/buildbot-aarch64/bolt-aarch64-ubuntu-clang-shared/build/lib
 && :
mold: error: undefined symbol: 
llvm::getInstrProfSectionName[abi:cxx11](llvm::InstrProfSectKind, 
llvm::Triple::ObjectFormatType, bool)
>>> referenced by InputFiles.cpp
>>>   
>>> tools/lld/wasm/CMakeFiles/lldWasm.dir/InputFiles.cpp.o:(lld::wasm::ObjFile::parse(bool))>>>
>>>  referenced by InputFiles.cpp
>>>   
>>> tools/lld/wasm/CMakeFiles/lldWasm.dir/InputFiles.cpp.o:(lld::wasm::ObjFile::parse(bool))
clang++: error: linker command failed with exit code 1 (use -v to see 
invocation)
55.544 [635/5/969] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaLookup.cpp.o
55.631 [635/4/970] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaModule.cpp.o
55.696 [635/3/971] Building CXX object 
tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaObjC.cpp.o
55.705 [635/2/972] Building CXX obje

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits


@@ -204,23 +205,29 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr 
*E) {
   return true;
 }
 
-static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A,
-  SourceLocation Loc, SourceRange R1,
-  SourceRange R2, bool IsCtor) {
+static bool DiagnoseNoDiscard(Sema &S, const NamedDecl *OffendingDecl,
+  const WarnUnusedResultAttr *A, SourceLocation 
Loc,
+  SourceRange R1, SourceRange R2, bool IsCtor) {
   if (!A)
 return false;
   StringRef Msg = A->getMessage();
 
+  bool result;
   if (Msg.empty()) {
 if (IsCtor)
-  return S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
-return S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
-  }
+  result = S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
+else
+  result = S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
+  } else if (IsCtor)
+result = S.Diag(Loc, diag::warn_unused_constructor_msg)
+ << A << Msg << R1 << R2;
+  else
+result = S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
 
-  if (IsCtor)
-return S.Diag(Loc, diag::warn_unused_constructor_msg) << A << Msg << R1
-  << R2;
-  return S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
+  if (OffendingDecl)

Mick235711 wrote:

Well, `S.Diag(...) << [a const Decl *]` just gives me an error that no such 
operator<< exists. Is there some different syntax needed to pass a Decl as 
parameter to the diagnostics builder?

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits


@@ -9290,6 +9290,8 @@ def warn_unused_result_typedef_unsupported_spelling : 
Warning<
 def warn_unused_volatile : Warning<
   "expression result unused; assign into a variable to force a volatile load">,
   InGroup>;
+def note_nodiscard_specified_here : Note<

Mick235711 wrote:

Sure, will be combined in the next push.

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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


@@ -204,23 +205,29 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr 
*E) {
   return true;
 }
 
-static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A,
-  SourceLocation Loc, SourceRange R1,
-  SourceRange R2, bool IsCtor) {
+static bool DiagnoseNoDiscard(Sema &S, const NamedDecl *OffendingDecl,
+  const WarnUnusedResultAttr *A, SourceLocation 
Loc,
+  SourceRange R1, SourceRange R2, bool IsCtor) {
   if (!A)
 return false;
   StringRef Msg = A->getMessage();
 
+  bool result;
   if (Msg.empty()) {
 if (IsCtor)
-  return S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
-return S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
-  }
+  result = S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
+else
+  result = S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
+  } else if (IsCtor)
+result = S.Diag(Loc, diag::warn_unused_constructor_msg)
+ << A << Msg << R1 << R2;
+  else
+result = S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
 
-  if (IsCtor)
-return S.Diag(Loc, diag::warn_unused_constructor_msg) << A << Msg << R1
-  << R2;
-  return S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
+  if (OffendingDecl)

erichkeane wrote:

Ah, woops!  I missed that you were doing a print of the name in the note.  I'd 
suggest doing a `select` and a dyn-cast kind of thing, such that the diagnostic 
doesn't print the name if one doesn't exist:

`S.Diag(...) << /*The select:*/isa(OffendingDecl) << /*the name: 
*/dyn_cast(OffendingDecl)`

It has to be a dyn-cast even though we know it won't be null, because we don't 
have a way of short-circuiting via 'select'.

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits

Mick235711 wrote:

> That is, keep the current wording if the function is nodiscard, but change it 
> to mention the type instead if the type is marked nodiscard—provided there is 
> a relatively straight-forward way of doing this.

I think this should be okay-ish to implement since we basically already have 
that information when implementing the note anyway. Will try to implement this 
tomorrow, if I can find some time...

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


[clang] [clang][bytecode] Diagnose reference to non-constexpr variable of const type in C23 constexpr (PR #112211)

2024-10-15 Thread via cfe-commits

yronglin wrote:

Thanks for the review! IIUC, seems the failed test `Clang :: 
Driver/hip-partial-link.hip (10952 of 21294)` was not caused by this PR. It's 
looks strange.

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


[clang] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (PR #112378)

2024-10-15 Thread via cfe-commits

zmodem wrote:

With STL's test program from the thread on Discourse, this outputs:

```
C:\src\llvm-project>build\bin\clang-cl /EHsc /nologo /W4 /std:c++23preview 
meow.cpp && meow
Clang; __cplusplus: 202302; _MSVC_LANG: 202302; detected C++23
```

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

2024-10-15 Thread Yihe Li via cfe-commits


@@ -204,23 +205,29 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr 
*E) {
   return true;
 }
 
-static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A,
-  SourceLocation Loc, SourceRange R1,
-  SourceRange R2, bool IsCtor) {
+static bool DiagnoseNoDiscard(Sema &S, const NamedDecl *OffendingDecl,
+  const WarnUnusedResultAttr *A, SourceLocation 
Loc,
+  SourceRange R1, SourceRange R2, bool IsCtor) {
   if (!A)
 return false;
   StringRef Msg = A->getMessage();
 
+  bool result;
   if (Msg.empty()) {
 if (IsCtor)
-  return S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
-return S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
-  }
+  result = S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
+else
+  result = S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
+  } else if (IsCtor)
+result = S.Diag(Loc, diag::warn_unused_constructor_msg)
+ << A << Msg << R1 << R2;
+  else
+result = S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
 
-  if (IsCtor)
-return S.Diag(Loc, diag::warn_unused_constructor_msg) << A << Msg << R1
-  << R2;
-  return S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
+  if (OffendingDecl)

Mick235711 wrote:

That is a good idea, will implement this in the next push.

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


[clang] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (PR #112378)

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


@@ -215,8 +215,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2015)) {
   if (Opts.CPlusPlus23)
-// TODO update to the proper value.
-Builder.defineMacro("_MSVC_LANG", "202004L");
+Builder.defineMacro("_MSVC_LANG", "202302L");

AaronBallman wrote:

Clang and GCC both use `202400L`: https://godbolt.org/z/7er4doE6h -- maybe 
Microsoft wants to consider using the same value?

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


[clang] [llvm] [HLSL] Implement `WaveActiveSum` intrinsic (PR #112400)

2024-10-15 Thread Finn Plummer via cfe-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/112400

- add clang builtin to Builtins.td
- link builtin in hlsl_intrinsics
- add codegen for spirv intrinsic and two directx intrinsics to retain 
signedness information of the operands in CGBuiltin.cpp
- add semantic analysis in SemaHLSL.cpp
- add lowering of spirv intrinsic to spirv backend in 
SPIRVInstructionSelector.cpp
- add directx intrinsic expansion to WaveActiveOp in 
DXILIntrinsicExpansion.cpp

- add test cases to illustrate passes

>From 952271bd348f9d695a1c655a4fe3d3d37b192da4 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Fri, 11 Oct 2024 15:06:15 -0700
Subject: [PATCH] [HLSL] Implement `WaveActiveSum` intrinsic

- add clang builtin to Builtins.td
- link builtin in hlsl_intrinsics
- add codegen for spirv intrinsic and two directx intrinsics to
  retain signedness information of the operands in CGBuiltin.cpp
- add semantic analysis in SemaHLSL.cpp
- add lowering of spirv intrinsic to spirv backend in
  SPIRVInstructionSelector.cpp
- add directx intrinsic expansion to WaveActiveOp in
  DXILIntrinsicExpansion.cpp

- add test cases to illustrate passes
---
 clang/include/clang/Basic/Builtins.td |  6 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/lib/CodeGen/CGBuiltin.cpp   | 34 +++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 99 +++
 clang/lib/Sema/SemaHLSL.cpp   | 32 ++
 .../CodeGenHLSL/builtins/WaveActiveSum.hlsl   | 48 +
 .../BuiltIns/WaveActiveSum-errors.hlsl| 28 ++
 llvm/include/llvm/IR/IntrinsicsDirectX.td |  3 +
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 .../Target/DirectX/DXILIntrinsicExpansion.cpp | 21 
 .../Target/SPIRV/SPIRVInstructionSelector.cpp | 34 +++
 llvm/test/CodeGen/DirectX/WaveActiveSum.ll| 78 +++
 .../SPIRV/hlsl-intrinsics/WaveActiveSum.ll| 41 
 13 files changed, 428 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/WaveActiveSum.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/WaveActiveSum-errors.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/WaveActiveSum.ll
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveSum.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 9ebee81fcb0d3d..2b4fb25c97504a 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4721,6 +4721,12 @@ def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "unsigned int(bool)";
 }
 
+def HLSLWaveActiveSum : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_wave_active_sum"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void (...)";
+}
+
 def HLSLWaveGetLaneIndex : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_wave_get_lane_index"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f4a2d4a3f0656a..e2f7384fb632a6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9232,6 +9232,9 @@ def err_typecheck_cond_incompatible_operands : Error<
 def err_typecheck_expect_scalar_or_vector : Error<
   "invalid operand of type %0 where %1 or "
   "a vector of such type is required">;
+def err_typecheck_expect_scalar_or_vector_not_type : Error<
+  "invalid operand of type %0 where %1 or "
+  "a vector of such type is not allowed">;
 def err_typecheck_expect_flt_or_vector : Error<
   "invalid operand of type %0 where floating, complex or "
   "a vector of such types is required">;
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2449b90a0e7902..4da012418cf902 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18631,6 +18631,23 @@ static Intrinsic::ID 
getDotProductIntrinsic(CGHLSLRuntime &RT, QualType QT) {
   return RT.getUDotIntrinsic();
 }
 
+// Return wave active sum that corresponds to the QT scalar type
+static Intrinsic::ID getWaveActiveSumIntrinsic(llvm::Triple::ArchType Arch,
+   CGHLSLRuntime &RT, QualType QT) 
{
+  switch (Arch) {
+  case llvm::Triple::spirv:
+return llvm::Intrinsic::spv_wave_active_sum;
+  case llvm::Triple::dxil: {
+if (QT->isUnsignedIntegerType())
+  return llvm::Intrinsic::dx_wave_active_usum;
+return llvm::Intrinsic::dx_wave_active_sum;
+  }
+  default:
+llvm_unreachable("Intrinsic WaveActiveSum"
+ " not supported by target architecture");
+  }
+}
+
 Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
 const CallExpr *E,
 ReturnValueSlot ReturnValue) {
@@ -18866,6 +18883

[clang] [llvm] [AArch64] Introduce new armv9.6 features (PR #111677)

2024-10-15 Thread via cfe-commits

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


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


[clang] [llvm] [HLSL] Implement `WaveActiveSum` intrinsic (PR #112400)

2024-10-15 Thread Finn Plummer via cfe-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/112400

>From c541955941a11b57efc624b87f50ce61f1b4c26a Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Fri, 11 Oct 2024 15:06:15 -0700
Subject: [PATCH] [HLSL] Implement `WaveActiveSum` intrinsic

- add clang builtin to Builtins.td
- link builtin in hlsl_intrinsics
- add codegen for spirv intrinsic and two directx intrinsics to
  retain signedness information of the operands in CGBuiltin.cpp
- add semantic analysis in SemaHLSL.cpp
- add lowering of spirv intrinsic to spirv backend in
  SPIRVInstructionSelector.cpp
- add directx intrinsic expansion to WaveActiveOp in
  DXILIntrinsicExpansion.cpp

- add test cases to illustrate passes
---
 clang/include/clang/Basic/Builtins.td |  6 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/lib/CodeGen/CGBuiltin.cpp   | 34 +++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 99 +++
 clang/lib/Sema/SemaHLSL.cpp   | 32 ++
 .../CodeGenHLSL/builtins/WaveActiveSum.hlsl   | 48 +
 .../BuiltIns/WaveActiveSum-errors.hlsl| 28 ++
 llvm/include/llvm/IR/IntrinsicsDirectX.td |  2 +
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 .../Target/DirectX/DXILIntrinsicExpansion.cpp | 21 
 .../Target/SPIRV/SPIRVInstructionSelector.cpp | 34 +++
 llvm/test/CodeGen/DirectX/WaveActiveSum.ll| 78 +++
 .../SPIRV/hlsl-intrinsics/WaveActiveSum.ll| 41 
 13 files changed, 427 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/WaveActiveSum.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/WaveActiveSum-errors.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/WaveActiveSum.ll
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveSum.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 9ebee81fcb0d3d..2b4fb25c97504a 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4721,6 +4721,12 @@ def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "unsigned int(bool)";
 }
 
+def HLSLWaveActiveSum : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_wave_active_sum"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void (...)";
+}
+
 def HLSLWaveGetLaneIndex : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_wave_get_lane_index"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f4a2d4a3f0656a..e2f7384fb632a6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9232,6 +9232,9 @@ def err_typecheck_cond_incompatible_operands : Error<
 def err_typecheck_expect_scalar_or_vector : Error<
   "invalid operand of type %0 where %1 or "
   "a vector of such type is required">;
+def err_typecheck_expect_scalar_or_vector_not_type : Error<
+  "invalid operand of type %0 where %1 or "
+  "a vector of such type is not allowed">;
 def err_typecheck_expect_flt_or_vector : Error<
   "invalid operand of type %0 where floating, complex or "
   "a vector of such types is required">;
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2449b90a0e7902..4da012418cf902 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18631,6 +18631,23 @@ static Intrinsic::ID 
getDotProductIntrinsic(CGHLSLRuntime &RT, QualType QT) {
   return RT.getUDotIntrinsic();
 }
 
+// Return wave active sum that corresponds to the QT scalar type
+static Intrinsic::ID getWaveActiveSumIntrinsic(llvm::Triple::ArchType Arch,
+   CGHLSLRuntime &RT, QualType QT) 
{
+  switch (Arch) {
+  case llvm::Triple::spirv:
+return llvm::Intrinsic::spv_wave_active_sum;
+  case llvm::Triple::dxil: {
+if (QT->isUnsignedIntegerType())
+  return llvm::Intrinsic::dx_wave_active_usum;
+return llvm::Intrinsic::dx_wave_active_sum;
+  }
+  default:
+llvm_unreachable("Intrinsic WaveActiveSum"
+ " not supported by target architecture");
+  }
+}
+
 Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
 const CallExpr *E,
 ReturnValueSlot ReturnValue) {
@@ -18866,6 +18883,23 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 /*ReturnType=*/Op0->getType(), CGM.getHLSLRuntime().getStepIntrinsic(),
 ArrayRef{Op0, Op1}, nullptr, "hlsl.step");
   }
+  case Builtin::BI__builtin_hlsl_wave_active_sum: {
+// Due to the use of variadic arguments, explicitly retreive argument
+Value *OpExpr = EmitScalarExpr(E->getArg(0));
+llvm::FunctionType *FT = llvm::FunctionType::get(
+OpExpr->getType(), ArrayRef{Op

[clang] [CLANG]Add Scalable vectors for mfloat8_t (PR #101644)

2024-10-15 Thread via cfe-commits

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

>From 7134302c7e1054021af36a207dbfd0c40c9e8c51 Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Fri, 2 Aug 2024 08:47:18 +
Subject: [PATCH 1/3] [CLANG]Add Scalable vectors for mfloat8_t

This patch adds these new vector sizes for sve:
svmfloat8_t

According to the ARM ACLE PR#323[1].

[1] ARM-software/acle#323
---
 .../clang/Basic/AArch64SVEACLETypes.def   |  7 
 clang/include/clang/Basic/arm_sve_sme_incl.td |  1 +
 .../include/clang/Serialization/ASTBitCodes.h |  2 +-
 clang/lib/AST/ASTContext.cpp  | 14 ++--
 clang/test/CodeGen/arm-mfp8.c | 28 
 clang/test/Modules/no-external-type-id.cppm   |  2 +-
 clang/test/Sema/arm-mfp8.cpp  | 13 
 clang/utils/TableGen/SveEmitter.cpp   | 33 ---
 8 files changed, 91 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/CodeGen/arm-mfp8.c
 create mode 100644 clang/test/Sema/arm-mfp8.cpp

diff --git a/clang/include/clang/Basic/AArch64SVEACLETypes.def 
b/clang/include/clang/Basic/AArch64SVEACLETypes.def
index 55ed9c36f6c5cd..b72327af61844a 100644
--- a/clang/include/clang/Basic/AArch64SVEACLETypes.def
+++ b/clang/include/clang/Basic/AArch64SVEACLETypes.def
@@ -69,6 +69,11 @@
 
 #ifndef SVE_VECTOR_TYPE_BFLOAT
 #define SVE_VECTOR_TYPE_BFLOAT(Name, MangledName, Id, SingletonId, NumEls, 
ElBits, NF) \
+  SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, 
NF, true, false, true)
+#endif
+
+#ifndef SVE_VECTOR_TYPE_MFLOAT
+#define SVE_VECTOR_TYPE_MFLOAT(Name, MangledName, Id, SingletonId, NumEls, 
ElBits, NF) \
   SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, 
NF, false, false, true)
 #endif
 
@@ -114,6 +119,7 @@ SVE_VECTOR_TYPE_FLOAT("__SVFloat32_t", "__SVFloat32_t", 
SveFloat32, SveFloat32Ty
 SVE_VECTOR_TYPE_FLOAT("__SVFloat64_t", "__SVFloat64_t", SveFloat64, 
SveFloat64Ty, 2, 64, 1)
 
 SVE_VECTOR_TYPE_BFLOAT("__SVBfloat16_t", "__SVBfloat16_t", SveBFloat16, 
SveBFloat16Ty, 8, 16, 1)
+SVE_VECTOR_TYPE_MFLOAT("__SVMfloat8_t", "__SVMfloat8_t",  SveMFloat8, 
SveMFloat8Ty, 16, 8, 1)
 
 //
 // x2
@@ -183,6 +189,7 @@ SVE_OPAQUE_TYPE("__SVCount_t", "__SVCount_t", SveCount, 
SveCountTy)
 
 #undef SVE_VECTOR_TYPE
 #undef SVE_VECTOR_TYPE_BFLOAT
+#undef SVE_VECTOR_TYPE_MFLOAT
 #undef SVE_VECTOR_TYPE_FLOAT
 #undef SVE_VECTOR_TYPE_INT
 #undef SVE_PREDICATE_TYPE
diff --git a/clang/include/clang/Basic/arm_sve_sme_incl.td 
b/clang/include/clang/Basic/arm_sve_sme_incl.td
index fdf4ba55fe9382..50911fb63e818e 100644
--- a/clang/include/clang/Basic/arm_sve_sme_incl.td
+++ b/clang/include/clang/Basic/arm_sve_sme_incl.td
@@ -162,6 +162,7 @@ def EltTyBool16  : EltType<10>;
 def EltTyBool32  : EltType<11>;
 def EltTyBool64  : EltType<12>;
 def EltTyBFloat16 : EltType<13>;
+def EltTyMFloat8  : EltType<14>;
 
 class MemEltType {
   int Value = val;
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 5be33ae0ed1b98..d468d49e1e632f 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1145,7 +1145,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 505;
+const unsigned NUM_PREDEF_TYPE_IDS = 506;
 
 // Ensure we do not overrun the predefined types we reserved
 // in the enum PredefinedTypeIDs above.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index fd8aa8de79b49f..7c11fec02a3f60 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4304,7 +4304,6 @@ ASTContext::getBuiltinVectorTypeInfo(const BuiltinType 
*Ty) const {
   switch (Ty->getKind()) {
   default:
 llvm_unreachable("Unsupported builtin vector type");
-
 #define SVE_VECTOR_TYPE_INT(Name, MangledName, Id, SingletonId, NumEls,
\
 ElBits, NF, IsSigned)  
\
   case BuiltinType::Id:
\
@@ -4319,12 +4318,16 @@ ASTContext::getBuiltinVectorTypeInfo(const BuiltinType 
*Ty) const {
ElBits, NF) 
\
   case BuiltinType::Id:
\
 return {BFloat16Ty, llvm::ElementCount::getScalable(NumEls), NF};
+#define SVE_VECTOR_TYPE_MFLOAT(Name, MangledName, Id, SingletonId, NumEls, 
\
+   ElBits, NF) 
\
+  case BuiltinType::Id:
\
+return {getIntTypeForBitwidth(ElBits, false),  
\
+llvm::ElementCount::getScalable(NumEls), NF};
 #define SVE_PREDICATE_TYPE_ALL(Name, MangledName, Id, SingletonId, NumEls, NF) 
\
   cas

[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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


@@ -9290,6 +9290,8 @@ def warn_unused_result_typedef_unsupported_spelling : 
Warning<
 def warn_unused_volatile : Warning<
   "expression result unused; assign into a variable to force a volatile load">,
   InGroup>;
+def note_nodiscard_specified_here : Note<

erichkeane wrote:

Still want this combined/generalized.  These are incredibly similar in both use 
and content.

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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


@@ -204,23 +205,26 @@ static bool DiagnoseUnusedComparison(Sema &S, const Expr 
*E) {
   return true;
 }
 
-static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A,
-  SourceLocation Loc, SourceRange R1,
-  SourceRange R2, bool IsCtor) {
+static bool DiagnoseNoDiscard(Sema &S, const Decl *OffendingDecl,
+  const WarnUnusedResultAttr *A, SourceLocation 
Loc,
+  SourceRange R1, SourceRange R2, bool IsCtor) {
   if (!A)
 return false;
   StringRef Msg = A->getMessage();
 
   if (Msg.empty()) {
 if (IsCtor)
-  return S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
-return S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
-  }
+  S.Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
+else
+  S.Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
+  } else if (IsCtor)

erichkeane wrote:

This needs curleys on it per coding standard (as the previous thing has them).  

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


[clang-tools-extra] Add option to exclude headers from clang-tidy analysis (PR #91400)

2024-10-15 Thread Julian Schmidt via cfe-commits

5chmidti wrote:

> I have read the issues in detail and it doesn't look like it has been 
> resolved? But just want to filter out the content not interested in, even if 
> you don't use `exclude-header-filter` The output is the same as above,It will 
> not expand the contents(`Supppressed 3386 warnings...`).

Sadly no, this does not exist yet and the linked issue is for tracking that 
feature.

The option implemented in this PR allows to filter out from the generated 
diagnostics those, that have been generated and their file name matched the 
regex, but not to ignore the code in those headers all together. This means 
that we still analyze that code and diagnose it, we just don't show the 
diagnostic for it.

Most likely, the reason you are not seeing a difference in the number of 
suppressed diagnostics, is that the QT headers are already marked as system 
includes by your build system, which are automatically excluded from analysis 
unless the `--system-headers` flag is set.

(In case this does not answer your question or the issue I linked is not what 
you're after, please file an issue so that it will be more searchable for 
others and so that the conversation gets scoped to that issue and not in a PR 
conversation, which will likely not be searched for by others.)

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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


@@ -302,27 +307,43 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, 
unsigned DiagID) {
 if (const Decl *FD = CE->getCalleeDecl()) {
   if (ShouldSuppress)
 return;
-  if (FD->hasAttr()) {
-Diag(Loc, diag::warn_unused_call) << R1 << R2 << "pure";
-return;
-  }
-  if (FD->hasAttr()) {
-Diag(Loc, diag::warn_unused_call) << R1 << R2 << "const";
+
+  const InheritableAttr *A = nullptr;
+  if (const auto *PA = FD->getAttr())
+A = PA;
+  else if (const auto *CA = FD->getAttr())
+A = CA;
+
+  if (A) {
+StringRef type = (isa(A) ? "pure" : "const");
+Diag(Loc, diag::warn_unused_call) << R1 << R2 << type;
+if (const auto *ND = dyn_cast(OffendingDecl)) {
+  if (!ND->getIdentifier()->getBuiltinID())

erichkeane wrote:

I still didn't get the justification for skipping if this is a builtin?  It 
seems sensible to do so, even if the source location is a builtin.

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


[clang] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (PR #112378)

2024-10-15 Thread Casey Carter via cfe-commits


@@ -215,8 +215,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2015)) {
   if (Opts.CPlusPlus23)
-// TODO update to the proper value.
-Builder.defineMacro("_MSVC_LANG", "202004L");
+Builder.defineMacro("_MSVC_LANG", "202302L");

CaseyCarter wrote:

This seems perfectly reasonable. I'll throw it over the fence.

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


[clang] [clang-cl]: Add /std:c++23preview and update _MSVC_LANG for C++23 (PR #112378)

2024-10-15 Thread Casey Carter via cfe-commits

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


[clang] [clang] LazyOffsetPtr: Use native pointer width (PR #111995)

2024-10-15 Thread John Paul Adrian Glaubitz via cfe-commits

glaubitz wrote:

> cc @glaubitz (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113341)

I can confirm that the patch from this PR fixes the GCC bootstrap on 32-bit 
PowerPC on Linux for me (GCC pr/target 113341).

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


[clang] Fieldregion descript name (PR #112313)

2024-10-15 Thread via cfe-commits


@@ -751,12 +751,27 @@ std::string MemRegion::getDescriptiveName(bool UseQuotes) 
const {
   }
 
   // Get variable name.
-  if (R && R->canPrintPrettyAsExpr()) {
-R->printPrettyAsExpr(os);
-if (UseQuotes)
-  return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str();
-else
+  if (R) {
+// MemRegion can be pretty printed.
+if (R->canPrintPrettyAsExpr()) {
+  R->printPrettyAsExpr(os);
+  if (UseQuotes)
+return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str();
   return (llvm::Twine(os.str()) + ArrayIndices).str();
+}
+
+// FieldRegion may have ElementRegion as SuperRegion.
+if (const clang::ento::FieldRegion *FR =
+R->getAs()) {
+  std::string Super = FR->getSuperRegion()->getDescriptiveName(false);

T-Gruber wrote:

I completely agree with you. It really is a bit messy and confusing. I'm 
currently working with a workaround that looks like this:

```Cpp
std::string getDescriptiveNameFixed(const clang::ento::MemRegion *R) {

  if (const auto *ER = R->getAs()) {
std::string ArrayIndices;

// Index is a ConcreteInt.
if (auto CI = ER->getIndex().getAs()) {
  llvm::SmallString<2> Idx;
  CI->getValue().toString(Idx);
  ArrayIndices = (llvm::Twine("[") + Idx.str() + "]" + ArrayIndices).str();
}
// Index is symbolic, but may have a descriptive name.
else {
  auto SI = ER->getIndex().getAs();
  if (!SI)
return "";

  const clang::ento::MemRegion *OR = SI->getAsSymbol()->getOriginRegion();
  if (!OR)
return "";

  std::string Idx = OR->getDescriptiveName(false);
  if (Idx.empty())
return "";

  ArrayIndices = (llvm::Twine("[") + Idx + "]" + ArrayIndices).str();
}

// Get descriptive name of SuperRegion.
std::string Super = getDescriptiveNameFixed(ER->getSuperRegion());
if (Super.empty())
  return "";
return Super + ArrayIndices;
  }

  if (const auto *FR = R->getAs()) {
// Get descriptive name of SuperRegion.
std::string Super = getDescriptiveNameFixed(FR->getSuperRegion());
if (Super.empty())
  return "";
return Super + "." + FR->getDecl()->getNameAsString();
  }

  // MemRegion is one of: NonParamVarRegion, ParamVarRegion, ObjCIvarRegion,
  // CXXBaseObjectRegion or CXXDerivedObjectRegion.
  if (R && R->canPrintPrettyAsExpr()) {
llvm::SmallString<50> buf;
llvm::raw_svector_ostream os(buf);
R->printPrettyAsExpr(os);
return os.str().str();
  }

  return "";
}
```

In my opinion it's much clearer and easier to understand. What do you think?

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


[clang] Fieldregion descript name (PR #112313)

2024-10-15 Thread via cfe-commits

https://github.com/T-Gruber updated 
https://github.com/llvm/llvm-project/pull/112313

>From dd562bb3d505c43070ceb8af51359cc66860a0ea Mon Sep 17 00:00:00 2001
From: "tobias.gruber" 
Date: Tue, 15 Oct 2024 07:19:12 +0200
Subject: [PATCH 1/4] Handle FieldRegions with ElementRegions as SuperRegions
 in getDescriptiveName

---
 clang/lib/StaticAnalyzer/Core/MemRegion.cpp   | 25 +++
 .../MemRegionDescriptiveNameTest.cpp  | 14 +++
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp 
b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
index 693791c3aee8b9..4144cff8607926 100644
--- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -751,12 +751,27 @@ std::string MemRegion::getDescriptiveName(bool UseQuotes) 
const {
   }
 
   // Get variable name.
-  if (R && R->canPrintPrettyAsExpr()) {
-R->printPrettyAsExpr(os);
-if (UseQuotes)
-  return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str();
-else
+  if (R) {
+// MemRegion can be pretty printed.
+if (R->canPrintPrettyAsExpr()) {
+  R->printPrettyAsExpr(os);
+  if (UseQuotes)
+return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str();
   return (llvm::Twine(os.str()) + ArrayIndices).str();
+}
+
+// FieldRegion may have ElementRegion as SuperRegion.
+if (const clang::ento::FieldRegion *FR =
+R->getAs()) {
+  std::string Super = FR->getSuperRegion()->getDescriptiveName(false);
+  if (Super.empty())
+return "";
+
+  if (UseQuotes)
+return (llvm::Twine("'") + Super + "." + FR->getDecl()->getName() + 
"'")
+.str();
+  return (llvm::Twine(Super) + "." + FR->getDecl()->getName()).str();
+}
   }
 
   return VariableName;
diff --git a/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp 
b/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp
index b13e7123ee524d..fe5defd1d47915 100644
--- a/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp
+++ b/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp
@@ -143,4 +143,18 @@ void top() {
   EXPECT_EQ(Output, "DescriptiveNameChecker: array[x]\n");
 }
 
+TEST(MemRegionDescriptiveNameTest, FieldRegWithSuperElementReg) {
+  StringRef Code = R"cpp(
+void reportDescriptiveName(int *p);
+struct val_struct { int val; };
+extern struct val_struct val_struct_array[3];
+void top() {
+  reportDescriptiveName(&val_struct_array[0].val);
+})cpp";
+
+  std::string Output;
+  ASSERT_TRUE(runChecker(Code, Output));
+  EXPECT_EQ(Output, "DescriptiveNameChecker: val_struct_array[0].val\n");
+}
+
 } // namespace

>From d8837ca3427e04d0d8a070ddce93da1485f2835f Mon Sep 17 00:00:00 2001
From: "tobias.gruber" 
Date: Tue, 15 Oct 2024 07:20:21 +0200
Subject: [PATCH 2/4] Remove unneeded include

---
 clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp 
b/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp
index fe5defd1d47915..966e5c0e9a6124 100644
--- a/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp
+++ b/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp
@@ -12,7 +12,6 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
 #include "gtest/gtest.h"
-#include 
 
 using namespace clang;
 using namespace ento;

>From b2b269fbc479751dafa5aa85a58a0a6756f442bf Mon Sep 17 00:00:00 2001
From: "tobias.gruber" 
Date: Tue, 15 Oct 2024 12:37:46 +0200
Subject: [PATCH 3/4] Include test case with multi-dim array

---
 .../MemRegionDescriptiveNameTest.cpp   | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp 
b/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp
index 966e5c0e9a6124..0f6e49bf42f4ac 100644
--- a/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp
+++ b/clang/unittests/StaticAnalyzer/MemRegionDescriptiveNameTest.cpp
@@ -156,4 +156,18 @@ void top() {
   EXPECT_EQ(Output, "DescriptiveNameChecker: val_struct_array[0].val\n");
 }
 
+TEST(MemRegionDescriptiveNameTest, FieldRegWithSuperMultidimElementReg) {
+  StringRef Code = R"cpp(
+void reportDescriptiveName(int *p);
+struct val_struct { int val; };
+extern struct val_struct val_struct_array[3][4];
+void top() {
+  reportDescriptiveName(&val_struct_array[1][2].val);
+})cpp";
+
+  std::string Output;
+  ASSERT_TRUE(runChecker(Code, Output));
+  EXPECT_EQ(Output, "DescriptiveNameChecker: val_struct_array[1][2].val\n");
+}
+
 } // namespace

>From 565de601620ee7dfe7156302f4169e6d46588a5d Mon Sep 17 00:00:00 2001
From: "tobias.gruber" 
Date: Tue, 15 Oct 2024 13:53:18 +0200
Subject: [PATCH 4/4] Function to enclose in quotes if needed

---
 clang/lib/Stati

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-15 Thread Pavel Skripkin via cfe-commits

pskrgag wrote:

> I think APINotes support attributes on param declarations

Hm, cannot find it, but anyway will check if it's possible to extend APINotes. 
Thanks!

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


[clang] [llvm] [llvm] Support llvm::Any across shared libraries on windows (PR #108051)

2024-10-15 Thread Yitzhak Mandelbaum via cfe-commits


@@ -28,12 +28,24 @@
 #include "clang/Analysis/FlowSensitive/MatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
+#include "clang/Support/Compiler.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 
+namespace clang {
+namespace dataflow {
+class NoopLattice;

ymand wrote:

Sorry -- I was asking about the whole block, not just the forward decl. Yes, 
please move it the NoopLattice header. Thanks!

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


[clang-tools-extra] 1c38c46 - [clang-tidy] Make `P +- BS / sizeof(*P)` opt-outable in `bugprone-sizeof-expression` (#111178)

2024-10-15 Thread via cfe-commits

Author: whisperity
Date: 2024-10-15T14:42:57+02:00
New Revision: 1c38c46b083315e3a621267c9a90e8a7750f3700

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

LOG: [clang-tidy] Make `P +- BS / sizeof(*P)` opt-outable in 
`bugprone-sizeof-expression` (#78)

In some cases and for projects that deal with a lot of low-level buffers, a
pattern often emerges that an array and its full size, not in the number of
"elements" but in "bytes", are known with no syntax-level connection between
the two values.
To access the array elements, the pointer arithmetic involved will have
to divide 'SizeInBytes' (a numeric value) with `sizeof(*Buffer)`.
Since the previous patch introduced this new warning, potential
false-positives were triggered from `bugprone-sizeof-expression`, as `sizeof`
appeared in pointer arithmetic where integers are scaled.

This patch adds a new check option, `WarnOnOffsetDividedBySizeOf`, which allows
users to opt out of warning about the division case.
In arbitrary projects, it might still be worthwhile to get these warnings until
an opt-out from the detection of scaling issues, especially if a project
might not be using low-level buffers intensively.

Added: 

clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-pointer-arithmetics-no-division.c

Modified: 
clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-pointer-arithmetics.c

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index a30e63f9b0fd6a..628d30ce7f73fe 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -70,7 +70,9 @@ SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
   Options.get("WarnOnSizeOfCompareToConstant", true)),
   WarnOnSizeOfPointerToAggregate(
   Options.get("WarnOnSizeOfPointerToAggregate", true)),
-  WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)) {}
+  WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)),
+  WarnOnOffsetDividedBySizeOf(
+  Options.get("WarnOnOffsetDividedBySizeOf", true)) {}
 
 void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfConstant", WarnOnSizeOfConstant);
@@ -82,6 +84,8 @@ void 
SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfPointerToAggregate",
 WarnOnSizeOfPointerToAggregate);
   Options.store(Opts, "WarnOnSizeOfPointer", WarnOnSizeOfPointer);
+  Options.store(Opts, "WarnOnOffsetDividedBySizeOf",
+WarnOnOffsetDividedBySizeOf);
 }
 
 void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
@@ -307,7 +311,8 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder 
*Finder) {
  offsetOfExpr()))
   .bind("sizeof-in-ptr-arithmetic-scale-expr");
   const auto PtrArithmeticIntegerScaleExpr = binaryOperator(
-  hasAnyOperatorName("*", "/"),
+  WarnOnOffsetDividedBySizeOf ? binaryOperator(hasAnyOperatorName("*", 
"/"))
+  : binaryOperator(hasOperatorName("*")),
   // sizeof(...) * sizeof(...) and sizeof(...) / sizeof(...) is handled
   // by this check on another path.
   hasOperands(expr(hasType(isInteger()), unless(SizeofLikeScaleExpr)),

diff  --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
index 66d7c34cc9e940..fbd62cb80fb2d0 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
@@ -31,6 +31,7 @@ class SizeofExpressionCheck : public ClangTidyCheck {
   const bool WarnOnSizeOfCompareToConstant;
   const bool WarnOnSizeOfPointerToAggregate;
   const bool WarnOnSizeOfPointer;
+  const bool WarnOnOffsetDividedBySizeOf;
 };
 
 } // namespace clang::tidy::bugprone

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6196b9e15d3fc5..95be0a89cd6c93 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -158,7 +158,7 @@ Changes in existing checks
 - Improved :doc:`bugprone-sizeof-expression
   ` check to find suspicious
   usages of ``sizeof()``, ``alignof()``, and ``offsetof()`` when adding or
-  subtract

[clang-tools-extra] [clang-tidy] Make `P +- BS / sizeof(*P)` opt-outable in `bugprone-sizeof-expression` (PR #111178)

2024-10-15 Thread via cfe-commits

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


[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)

2024-10-15 Thread Donát Nagy via cfe-commits


@@ -212,6 +212,25 @@ typedef llvm::ImmutableMap
 REGISTER_TRAIT_WITH_PROGRAMSTATE(PendingArrayDestruction,
  PendingArrayDestructionMap)
 
+// This trait is used to heuristically filter out results produced from
+// execution paths that took "weak" assumptions within a loop.
+REGISTER_TRAIT_WITH_PROGRAMSTATE(SeenWeakLoopAssumption, bool)
+
+ProgramStateRef clang::ento::recordWeakLoopAssumption(ProgramStateRef State) {
+  return State->set(true);
+}
+
+bool clang::ento::seenWeakLoopAssumption(ProgramStateRef State) {
+  return State->get();
+}

NagyDonat wrote:

The example
```cpp
void foo(int x, int y) {
  for (unsigned i = 0; i < x; i++) ; // split the state and set 
SeenWeakLoopAssumption to 'true'
  if (x != 0) return;// drop the 'true' branch

  // no warnings are reported from this point on
}
```
is a very good point and I'll probably add it to the tests to highlight this 
limitation of the heuristic.

However, I've seen {{ArrayBoundV2}} reports where lots of stuff happens between 
the point where we assume that a loop can have 0 iterations (i.e. some 
length/size variable is equal to 0) and the point where this triggers an 
unwanted report; so I don't think that we can have a natural cutoff where the 
"SeenWeakLoopAssumption" bit may be safely cleared.

I don't see a way to avoid these kinds of false negatives without a completely 
different loop handling approach, so I think we should accept them in the 
foreseeable future. (There are already lots of precedents for losing coverage 
after loops.)

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


[clang] Make [[clang::lifetimebound]] work for expressions coming from default arguments (PR #112047)

2024-10-15 Thread Gábor Horváth via cfe-commits


@@ -107,6 +107,39 @@ namespace std {
 using std::operator""s;
 using std::operator""sv;
 
+namespace default_args {
+  using IntArray = int[];
+  const int *defaultparam1(const int &def1 [[clang::lifetimebound]] = 0); // 
#def1

Xazax-hun wrote:

Ah, my bad. Totally missed that. 

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


[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)

2024-10-15 Thread Donát Nagy via cfe-commits


@@ -121,6 +121,34 @@ struct EvalCallOptions {
   EvalCallOptions() {}
 };
 
+/// Simple control flow statements like `if` can only produce a single two-way
+/// state split, so when the analyzer cannot determine the value of the
+/// condition, it can assume either of the two options, because the fact that
+/// they are in the source code implies that the programmer thought that they
+/// are possible (at least under some conditions).
+/// (Note that this heuristic is not entirely correct when there are _several_
+/// `if` statements with unmarked logical connections between them, but it's
+/// still good enough and the analyzer heavily relies on it.)
+/// In contrast with this, a single loop statement can produce multiple state
+/// splits, and we cannot always single out safe assumptions where we can say
+/// that "the programmer included this loop in the source code, so they clearly
+/// thought that this execution path is possible".
+/// However, the analyzer wants to explore the code in and after the loop, so
+/// it makes assumptions about the loop condition (to get a concrete execution
+/// path) even when they are not justified.
+/// This function is called by the engine to mark the `State` when it makes an
+/// assumption which is "weak". Checkers may use this heuristical mark to
+/// discard the result and reduce the amount of false positives.
+/// TODO: Instead of just marking these branches for checker-specific handling,
+/// we could discard them completely. I suspect that this could eliminate some
+/// false positives without suppressing too many true positives, but I didn't
+/// have time to measure its effects.
+ProgramStateRef recordWeakLoopAssumption(ProgramStateRef State);
+
+/// Returns true if `recordWeakLoopAssumption()` was called on the execution
+/// path which produced `State`.
+bool seenWeakLoopAssumption(ProgramStateRef State);

NagyDonat wrote:

Personally I prefer plain functions instead of `static` methods that are only 
vaguely connected to a class, but I can move them to `ExprEngine` to follow the 
precedents.

Making `recordWeakLoopAssumption()` private is also a good point -- I'll either 
do so or just inline its short one-line definition at the few locations where 
it's called. (I think the transparent `State->set<>` would be clearer than just 
calling some random method. If we need more complex logic later, we can 
reintroduce a method like it.)

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


[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-15 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 



@@ -3767,28 +3764,26 @@ void 
ExprEngine::evalEagerlyAssumeBinOpBifurcation(ExplodedNodeSet &Dst,
   continue;
 }
 
-ProgramStateRef state = Pred->getState();
-SVal V = state->getSVal(Ex, Pred->getLocationContext());
+ProgramStateRef State = Pred->getState();
+SVal V = State->getSVal(Ex, Pred->getLocationContext());
 std::optional SEV = V.getAs();
 if (SEV && SEV->isExpression()) {
-  const std::pair &tags =
-geteagerlyAssumeBinOpBifurcationTags();
+  auto [TrueTag, FalseTag] = getEagerlyAssumeBifurcationTags();
 
-  ProgramStateRef StateTrue, StateFalse;
-  std::tie(StateTrue, StateFalse) = state->assume(*SEV);
+  auto [StateTrue, StateFalse] = State->assume(*SEV);
 
   // First assume that the condition is true.
   if (StateTrue) {
 SVal Val = svalBuilder.makeIntVal(1U, Ex->getType());
 StateTrue = StateTrue->BindExpr(Ex, Pred->getLocationContext(), Val);
-Bldr.generateNode(Ex, Pred, StateTrue, tags.first);
+Bldr.generateNode(Ex, Pred, StateTrue, TrueTag);
   }
 
   // Next, assume that the condition is false.
   if (StateFalse) {
 SVal Val = svalBuilder.makeIntVal(0U, Ex->getType());
 StateFalse = StateFalse->BindExpr(Ex, Pred->getLocationContext(), Val);
-Bldr.generateNode(Ex, Pred, StateFalse, tags.second);
+Bldr.generateNode(Ex, Pred, StateFalse, FalseTag);

isuckatcs wrote:

I don't think that passing the tag here is an issue. The process for creating 
the node is "eager assumption" and in this case it only creates one branch. 

The tags in the egraph tell the user how the analyzer reached the conclusion to 
create that node and they are also useful for serving logging/debugging 
purposes. For example if the egraph is wrong at the node with this tag, you 
immediately know where the issue is. If there is no tag and the analyzer only 
creates one branch, it might be difficult to figure out where the node was 
created.

The only issue might be the wording, which says "Eagerly Assume" even though 
the analyzer _knows_ the value of the condition, but once again the creation of 
the node is the result of "eager assumption", so I guess it's fine to leave it 
like this.

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


[clang] [llvm] [LoongArch] Add options for annotate tablejump (PR #102411)

2024-10-15 Thread via cfe-commits


@@ -601,6 +612,44 @@ bool LoongArchPreRAExpandPseudo::expandFunctionCALL(
   return true;
 }
 
+void LoongArchPreRAExpandPseudo::annotateTableJump(
+MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) {
+  MachineFunction *MF = MBB.getParent();
+  MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
+
+  bool IsFinded = false;

heiher wrote:

IsFound

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


[clang] [llvm] [LoongArch] Add options for annotate tablejump (PR #102411)

2024-10-15 Thread via cfe-commits


@@ -601,6 +612,44 @@ bool LoongArchPreRAExpandPseudo::expandFunctionCALL(
   return true;
 }
 
+void LoongArchPreRAExpandPseudo::annotateTableJump(
+MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) {
+  MachineFunction *MF = MBB.getParent();
+  MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
+
+  bool IsFinded = false;
+
+  std::function FindJTIMI = [&](MachineInstr *MInst,
+   int FindDepth) {
+if (FindDepth < 0)
+  return;
+for (auto &MO : MInst->all_uses()) {
+  if (IsFinded)
+return;
+  Register Reg = MO.getReg();
+  if (!Reg.isVirtual())
+continue;
+  MachineInstr *DefMI = MRI.getVRegDef(Reg);
+  if (!DefMI)
+continue;
+  for (unsigned Idx = 0; Idx < DefMI->getNumOperands(); ++Idx) {
+if (DefMI->getOperand(Idx).isJTI()) {
+  MBBI->setPreInstrSymbol(
+  *MF, MF->getContext().createNamedTempSymbol("jrtb_"));
+  MF->getInfo()->setJumpInfo(&*MBBI,
+   DefMI);

heiher wrote:

Record the JTI operand or symbol here to avoid further traversal in the asm 
printer.

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


[clang] Fieldregion descript name (PR #112313)

2024-10-15 Thread via cfe-commits


@@ -751,12 +751,27 @@ std::string MemRegion::getDescriptiveName(bool UseQuotes) 
const {
   }
 
   // Get variable name.
-  if (R && R->canPrintPrettyAsExpr()) {
-R->printPrettyAsExpr(os);
-if (UseQuotes)
-  return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str();
-else
+  if (R) {
+// MemRegion can be pretty printed.
+if (R->canPrintPrettyAsExpr()) {
+  R->printPrettyAsExpr(os);
+  if (UseQuotes)
+return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str();
   return (llvm::Twine(os.str()) + ArrayIndices).str();
+}
+
+// FieldRegion may have ElementRegion as SuperRegion.
+if (const clang::ento::FieldRegion *FR =
+R->getAs()) {
+  std::string Super = FR->getSuperRegion()->getDescriptiveName(false);
+  if (Super.empty())
+return "";
+
+  if (UseQuotes)
+return (llvm::Twine("'") + Super + "." + FR->getDecl()->getName() + 
"'")
+.str();
+  return (llvm::Twine(Super) + "." + FR->getDecl()->getName()).str();

T-Gruber wrote:

That's a good idea. QuoteIfNeeded is added to the getDescriptiveName 
implementation.

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


[clang] [llvm] [LoongArch] Add options for annotate tablejump (PR #102411)

2024-10-15 Thread via cfe-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/102411

>From 7bcf5ebc9444e7cb98746ef0d182cbd4b60196e2 Mon Sep 17 00:00:00 2001
From: wanglei 
Date: Thu, 8 Aug 2024 09:41:25 +0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/Driver/ToolChains/Clang.cpp |   8 ++
 .../Target/LoongArch/LoongArchAsmPrinter.cpp  |  49 +
 .../Target/LoongArch/LoongArchAsmPrinter.h|   1 +
 .../LoongArch/LoongArchExpandPseudoInsts.cpp  |  17 +++
 .../CodeGen/LoongArch/annotate-tablejump.ll   | 102 ++
 6 files changed, 181 insertions(+)
 create mode 100644 llvm/test/CodeGen/LoongArch/annotate-tablejump.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 51ec29f1dc3212..18ad7f5868e48f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5319,6 +5319,10 @@ def mno_lasx : Flag<["-"], "mno-lasx">, 
Group,
 def msimd_EQ : Joined<["-"], "msimd=">, Group,
   Flags<[TargetSpecific]>,
   HelpText<"Select the SIMD extension(s) to be enabled in LoongArch either 
'none', 'lsx', 'lasx'.">;
+def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, 
Group,
+  HelpText<"Enable annotate table jump instruction to correlate it with the 
jump table.">;
+def mno_annotate_tablejump : Flag<["-"], "mno-annotate-tablejump">, 
Group,
+  HelpText<"Disable annotate table jump instruction to correlate it with the 
jump table.">;
 def mnop_mcount : Flag<["-"], "mnop-mcount">, HelpText<"Generate 
mcount/__fentry__ calls as nops. To activate they need to be patched in.">,
   Visibility<[ClangOption, CC1Option]>, Group,
   MarshallingInfoFlag>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 2054c8fe928e2e..342c083b01101e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1876,6 +1876,14 @@ void Clang::AddLoongArchTargetArgs(const ArgList &Args,
 CmdArgs.push_back("-tune-cpu");
 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
   }
+
+  if (Arg *A = Args.getLastArg(options::OPT_mannotate_tablejump,
+   options::OPT_mno_annotate_tablejump)) {
+if (A->getOption().matches(options::OPT_mannotate_tablejump)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-loongarch-annotate-tablejump");
+}
+  }
 }
 
 void Clang::AddMIPSTargetArgs(const ArgList &Args,
diff --git a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp 
b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
index f478870217ec60..b4c5be194bff52 100644
--- a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
@@ -15,16 +15,26 @@
 #include "LoongArch.h"
 #include "LoongArchTargetMachine.h"
 #include "MCTargetDesc/LoongArchInstPrinter.h"
+#include "MCTargetDesc/LoongArchMCTargetDesc.h"
 #include "TargetInfo/LoongArchTargetInfo.h"
 #include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/CodeGen/MachineJumpTableInfo.h"
+#include "llvm/CodeGen/MachineModuleInfoImpls.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCInstBuilder.h"
+#include "llvm/MC/MCSectionELF.h"
 #include "llvm/MC/TargetRegistry.h"
 
 using namespace llvm;
 
 #define DEBUG_TYPE "loongarch-asm-printer"
 
+cl::opt LArchAnnotateTableJump(
+"loongarch-annotate-tablejump", cl::Hidden,
+cl::desc(
+"Annotate table jump instruction to correlate it with the jump 
table."),
+cl::init(false));
+
 // Simple pseudo-instructions have their lowering (with expansion to real
 // instructions) auto-generated.
 #include "LoongArchGenMCPseudoLowering.inc"
@@ -189,6 +199,45 @@ void LoongArchAsmPrinter::emitSled(const MachineInstr &MI, 
SledKind Kind) {
   recordSled(BeginOfSled, MI, Kind, 2);
 }
 
+void LoongArchAsmPrinter::emitJumpTableInfo() {
+  AsmPrinter::emitJumpTableInfo();
+
+  if (!LArchAnnotateTableJump)
+return;
+
+  assert(TM.getTargetTriple().isOSBinFormatELF());
+
+  const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
+  if (!MJTI)
+return;
+
+  const std::vector &JT = MJTI->getJumpTables();
+  if (JT.empty())
+return;
+
+  OutStreamer->switchSection(MMI->getContext().getELFSection(
+  ".discard.tablejump_annotate", ELF::SHT_PROGBITS, 0));
+
+  unsigned Size = getDataLayout().getPointerSize();
+
+  for (unsigned JTI = 0, e = JT.size(); JTI != e; ++JTI) {
+const std::vector &JTBBs = JT[JTI].MBBs;
+if (JTBBs.empty())
+  continue;
+for (auto *Pred : JTBBs[0]->predecessors()) {
+  for (auto &MI : Pred->instrs()) {
+if (MI.getOpcode() != LoongArch::PseudoBRIND || 
!MI.getPreInstrSymbol())
+  continue;
+OutStreamer->emitValue(
+MCSymbolRefE

[clang] [llvm] [LoongArch] Add options for annotate tablejump (PR #102411)

2024-10-15 Thread via cfe-commits


@@ -601,6 +612,44 @@ bool LoongArchPreRAExpandPseudo::expandFunctionCALL(
   return true;
 }
 
+void LoongArchPreRAExpandPseudo::annotateTableJump(
+MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) {
+  MachineFunction *MF = MBB.getParent();
+  MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
+
+  bool IsFinded = false;

wangleiat wrote:

haha, Thanks.

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


[clang] [llvm] [LoongArch] Add options for annotate tablejump (PR #102411)

2024-10-15 Thread via cfe-commits


@@ -601,6 +612,44 @@ bool LoongArchPreRAExpandPseudo::expandFunctionCALL(
   return true;
 }
 
+void LoongArchPreRAExpandPseudo::annotateTableJump(
+MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) {
+  MachineFunction *MF = MBB.getParent();
+  MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
+
+  bool IsFinded = false;
+
+  std::function FindJTIMI = [&](MachineInstr *MInst,
+   int FindDepth) {
+if (FindDepth < 0)
+  return;
+for (auto &MO : MInst->all_uses()) {
+  if (IsFinded)
+return;
+  Register Reg = MO.getReg();
+  if (!Reg.isVirtual())
+continue;
+  MachineInstr *DefMI = MRI.getVRegDef(Reg);
+  if (!DefMI)
+continue;
+  for (unsigned Idx = 0; Idx < DefMI->getNumOperands(); ++Idx) {
+if (DefMI->getOperand(Idx).isJTI()) {
+  MBBI->setPreInstrSymbol(
+  *MF, MF->getContext().createNamedTempSymbol("jrtb_"));
+  MF->getInfo()->setJumpInfo(&*MBBI,
+   DefMI);

wangleiat wrote:

Thanks.

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


[clang] [clang][dataflow] Add a lattice to help cache const accessor methods (PR #111006)

2024-10-15 Thread Jan Voung via cfe-commits

jvoung wrote:

Friendly ping =)

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


[clang] Make [[clang::lifetimebound]] work for expressions coming from default arguments (PR #112047)

2024-10-15 Thread via cfe-commits


@@ -1370,7 +1381,7 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
 break;
   }
 
-  case IndirectLocalPathEntry::LambdaCaptureInit:
+  case IndirectLocalPathEntry::LambdaCaptureInit: {

higher-performance wrote:

It's not unrelated. If I take out the braces then the code won't compile due to 
the `case` skipping the declaration inside.

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

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

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/111499

>From 4951a7b9b87f9800bc3629bd44f65141ba98c6b0 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 8 Oct 2024 08:19:56 +
Subject: [PATCH 1/8] start working on lifetime capture

---
 clang/include/clang/Basic/Attr.td |  40 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  16 +++
 clang/include/clang/Sema/Sema.h   |   7 ++
 clang/lib/AST/TypePrinter.cpp |  21 
 clang/lib/Sema/CheckExprLifetime.cpp  |  54 +++---
 clang/lib/Sema/CheckExprLifetime.h|  26 +++--
 clang/lib/Sema/SemaChecking.cpp   |  27 +
 clang/lib/Sema/SemaDecl.cpp   |   1 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 102 ++
 clang/lib/Sema/SemaExpr.cpp   |   4 +-
 clang/lib/Sema/SemaInit.cpp   |   2 +-
 clang/lib/Sema/SemaOverload.cpp   |   4 +-
 clang/lib/Sema/SemaType.cpp   |  13 +++
 clang/test/SemaCXX/attr-lifetimebound.cpp |  94 
 14 files changed, 387 insertions(+), 24 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 35b9716e13ff21..4dcb143b91f84f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1869,6 +1869,46 @@ def LifetimeBound : DeclOrTypeAttr {
   let SimpleHandler = 1;
 }
 
+def LifetimeCaptureBy : DeclOrTypeAttr {
+  let Spellings = [Clang<"lifetime_capture_by", 0>];
+  let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
+  let Args = [VariadicParamOrParamIdxArgument<"Params">];
+  let Documentation = [LifetimeBoundDocs];
+  let LangOpts = [CPlusPlus];
+
+  // let SimpleHandler = 1;
+  // let LateParsed = LateAttrParseStandard;
+  // let HasCustomParsing = 1;
+  // let ParseArgumentsAsUnevaluated = 1;
+
+  let AdditionalMembers = [{
+private:
+  SmallVector ArgIdents;
+  SmallVector ArgLocs;
+
+public:
+  static const int INVALID = -2;
+  static const int UNKNOWN = -1;
+  static const int GLOBAL = -1;
+  static const int THIS = 0;
+
+  void setArgs(SmallVector Idents,
+   SmallVector Locs) { 
+assert(Idents.size() == Locs.size());
+assert(Idents.size() == params_Size);
+ArgIdents = std::move(Idents);
+ArgLocs = std::move(Locs);
+  }
+  
+  const SmallVector& getArgIdents() const { return 
ArgIdents; }
+  const SmallVector& getArgLocs() const { return ArgLocs; }
+  void setParamIdx(size_t Idx, int Val) { 
+assert(Idx < params_Size);
+params_[Idx] = Val;
+  }
+}];
+}
+
 def TrivialABI : InheritableAttr {
   // This attribute does not have a C [[]] spelling because it requires the
   // CPlusPlus language option.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e8b64f3c5a0187..ea034af77c3dbe 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3382,6 +3382,18 @@ def err_callback_callee_is_variadic : Error<
   "'callback' attribute callee may not be variadic">;
 def err_callback_implicit_this_not_available : Error<
   "'callback' argument at position %0 references unavailable implicit 'this'">;
+
+def err_capture_by_attribute_multiple : Error<
+  "multiple 'lifetime_capture' attributes specified">;
+def err_capture_by_attribute_no_entity : Error<
+  "'lifetime_capture_by' attribute specifies no capturing entity">;
+def err_capture_by_implicit_this_not_available : Error<
+  "'lifetime_capture_by' argument references unavailable implicit 'this'">;
+def err_capture_by_attribute_argument_unknown : Error<
+  "'lifetime_capture_by' attribute argument %0 is not a known function 
parameter"
+  ". Must be a function parameter of one of 'this', 'global' or 'unknown'">;
+def err_capture_by_references_itself : Error<"'lifetime_capture_by' argument 
references itself">;
+
 def err_init_method_bad_return_type : Error<
   "init methods must return an object pointer type, not %0">;
 def err_attribute_invalid_size : Error<
@@ -10185,6 +10197,10 @@ def warn_dangling_pointer_assignment : Warning<
"object backing the pointer %0 "
"will be destroyed at the end of the full-expression">,
InGroup;
+def warn_dangling_reference_captured : Warning<
+   "object captured by the '%0' "
+   "will be destroyed at the end of the full-expression">,
+   InGroup;
 
 // For non-floating point, expressions of the form x == x or x != x
 // should result in a warning, since these always evaluate to a constant.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0809ac1b144ef6..a26b3fa8755161 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1830,6 +1830,10 @@ class Sema final : public SemaBase {
   /// Add [[gsl::Pointer]] attributes for std:: types.
   void inferGslPointerAttribute(TypedefNameDecl *TD);
 

[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)

2024-10-15 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 



@@ -121,6 +121,34 @@ struct EvalCallOptions {
   EvalCallOptions() {}
 };
 
+/// Simple control flow statements like `if` can only produce a single two-way
+/// state split, so when the analyzer cannot determine the value of the
+/// condition, it can assume either of the two options, because the fact that
+/// they are in the source code implies that the programmer thought that they
+/// are possible (at least under some conditions).
+/// (Note that this heuristic is not entirely correct when there are _several_
+/// `if` statements with unmarked logical connections between them, but it's
+/// still good enough and the analyzer heavily relies on it.)
+/// In contrast with this, a single loop statement can produce multiple state
+/// splits, and we cannot always single out safe assumptions where we can say
+/// that "the programmer included this loop in the source code, so they clearly
+/// thought that this execution path is possible".
+/// However, the analyzer wants to explore the code in and after the loop, so
+/// it makes assumptions about the loop condition (to get a concrete execution
+/// path) even when they are not justified.
+/// This function is called by the engine to mark the `State` when it makes an
+/// assumption which is "weak". Checkers may use this heuristical mark to
+/// discard the result and reduce the amount of false positives.
+/// TODO: Instead of just marking these branches for checker-specific handling,
+/// we could discard them completely. I suspect that this could eliminate some
+/// false positives without suppressing too many true positives, but I didn't
+/// have time to measure its effects.
+ProgramStateRef recordWeakLoopAssumption(ProgramStateRef State);
+
+/// Returns true if `recordWeakLoopAssumption()` was called on the execution
+/// path which produced `State`.
+bool seenWeakLoopAssumption(ProgramStateRef State);

isuckatcs wrote:

> methods that are only vaguely connected to a class

I think these methods are strongly connected to this class, as they only make 
sense in the context of `ExprEngine`, which is also indicated by them being in 
`ExprEngine.h`. Also `ExprEngine` is the only class that can set this trait, as 
no one else has access to the required information to do so.

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


[clang] clang/AMDGPU: Set noalias.addrspace metadata on atomicrmw (PR #102462)

2024-10-15 Thread Shilei Tian via cfe-commits

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


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


[clang] [HLSL][Docs] Update function calls docs (PR #106860)

2024-10-15 Thread Justin Bogner via cfe-commits

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


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


[clang] [HLSL] Make HLSLAttributedResourceType canonical and add code paths to convert HLSL types to DirectX target types (PR #110327)

2024-10-15 Thread Justin Bogner via cfe-commits

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


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


[clang] clang: Remove requires system-linux from some driver tests (PR #111976)

2024-10-15 Thread Sean Perry via cfe-commits

https://github.com/perry-ca approved this pull request.

LGTM.  Thanks Matt.

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


[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

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


@@ -302,27 +307,43 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, 
unsigned DiagID) {
 if (const Decl *FD = CE->getCalleeDecl()) {
   if (ShouldSuppress)
 return;
-  if (FD->hasAttr()) {
-Diag(Loc, diag::warn_unused_call) << R1 << R2 << "pure";
-return;
-  }
-  if (FD->hasAttr()) {
-Diag(Loc, diag::warn_unused_call) << R1 << R2 << "const";
+
+  const InheritableAttr *A = nullptr;
+  if (const auto *PA = FD->getAttr())
+A = PA;
+  else if (const auto *CA = FD->getAttr())
+A = CA;
+
+  if (A) {
+StringRef type = (isa(A) ? "pure" : "const");
+Diag(Loc, diag::warn_unused_call) << R1 << R2 << type;
+if (const auto *ND = dyn_cast(OffendingDecl)) {
+  if (!ND->getIdentifier()->getBuiltinID())

erichkeane wrote:

Hmm... thats actually pretty strange: https://godbolt.org/z/q6EMMs6fa
If you make it NOT an error for the first declaration, it does what I suspect 
it SHOULD be doing in all cases, creating the overload set without a location: 
https://godbolt.org/z/4zeq99bne

So there is perhaps a bug in the builtin recovery we need to understand before 
we can move on.

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


[clang] [clang] Check null TypeSourceInfo in CreateUnaryExprOrTypeTraitExpr (PR #112111)

2024-10-15 Thread Andrew Sukach via cfe-commits

https://github.com/sookach updated 
https://github.com/llvm/llvm-project/pull/112111

>From d3b9b6ed8ffa8bad473a415ae4cc9f8748d7c2c2 Mon Sep 17 00:00:00 2001
From: Andrew Sukach 
Date: Sat, 12 Oct 2024 19:47:30 -0400
Subject: [PATCH] [clang] Check for null TypeSourceInfo in
 Sema::CreateUnaryExprOrTypeTraitExpr

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Sema/SemaExpr.cpp   |  3 +++
 .../test/SemaCXX/unary-expr-or-type-trait-invalid.cpp | 11 +++
 3 files changed, 16 insertions(+)
 create mode 100644 clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 763bc3ac159322..f2f6988a1f5c13 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -505,6 +505,8 @@ Bug Fixes to C++ Support
 - Fix a crash when parsing a pseudo destructor involving an invalid type. 
(#GH111460)
 - Fixed an assertion failure when invoking recovery call expressions with 
explicit attributes
   and undeclared templates. (#GH107047, #GH49093)
+- Fixed a compiler crash that occurred when processing malformed code 
involving `sizeof` with
+  an invalid type argument. (#GH111594)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4e37385710af5e..b0bd216c5dc101 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4629,6 +4629,9 @@ ExprResult 
Sema::CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
   TInfo->getType()->isVariablyModifiedType())
 TInfo = TransformToPotentiallyEvaluated(TInfo);
 
+  if (!TInfo)
+return ExprError();
+
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
diff --git a/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp 
b/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp
new file mode 100644
index 00..900fb8aa332f5b
--- /dev/null
+++ b/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value %s
+//
+// Note: This test is ensure the code does not cause a crash as previously
+// reported in (#GH111594). The specific diagnostics are unimportant.
+
+a() {struct b c (sizeof(b * [({ {tree->d* next)} 0
+
+// expected-error@6 0+{{}}
+// expected-error@11 0+{{}}
+// expected-note@6 0+{{}}
+

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


[clang] [clang] Check null TypeSourceInfo in CreateUnaryExprOrTypeTraitExpr (PR #112111)

2024-10-15 Thread Andrew Sukach via cfe-commits

https://github.com/sookach updated 
https://github.com/llvm/llvm-project/pull/112111

>From a478b5e0d91b7246ed145af0febd86daf1e2 Mon Sep 17 00:00:00 2001
From: Andrew Sukach 
Date: Sat, 12 Oct 2024 19:47:30 -0400
Subject: [PATCH] [clang] Check for null TypeSourceInfo in
 Sema::CreateUnaryExprOrTypeTraitExpr

---
 clang/docs/ReleaseNotes.rst | 2 ++
 clang/lib/Sema/SemaExpr.cpp | 3 +++
 clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp | 8 
 3 files changed, 13 insertions(+)
 create mode 100644 clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 763bc3ac159322..f2f6988a1f5c13 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -505,6 +505,8 @@ Bug Fixes to C++ Support
 - Fix a crash when parsing a pseudo destructor involving an invalid type. 
(#GH111460)
 - Fixed an assertion failure when invoking recovery call expressions with 
explicit attributes
   and undeclared templates. (#GH107047, #GH49093)
+- Fixed a compiler crash that occurred when processing malformed code 
involving `sizeof` with
+  an invalid type argument. (#GH111594)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4e37385710af5e..b0bd216c5dc101 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4629,6 +4629,9 @@ ExprResult 
Sema::CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
   TInfo->getType()->isVariablyModifiedType())
 TInfo = TransformToPotentiallyEvaluated(TInfo);
 
+  if (!TInfo)
+return ExprError();
+
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
diff --git a/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp 
b/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp
new file mode 100644
index 00..c0c8284c107d95
--- /dev/null
+++ b/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value %s
+
+a() {struct b c (sizeof(b * [({ {tree->d* next)} 0
+
+// expected-error@3 0+{{}}
+// expected-error@8 0+{{}}
+// expected-note@3 0+{{}}
+

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


[clang] [clang] Check null TypeSourceInfo in CreateUnaryExprOrTypeTraitExpr (PR #112111)

2024-10-15 Thread Andrew Sukach via cfe-commits

https://github.com/sookach updated 
https://github.com/llvm/llvm-project/pull/112111

>From 384e4eba4c3a587f0645e5f037b81acff786e39e Mon Sep 17 00:00:00 2001
From: Andrew Sukach 
Date: Sat, 12 Oct 2024 19:47:30 -0400
Subject: [PATCH] [clang] Check for null TypeSourceInfo in
 Sema::CreateUnaryExprOrTypeTraitExpr

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Sema/SemaExpr.cpp   |  3 +++
 .../test/SemaCXX/unary-expr-or-type-trait-invalid.cpp | 11 +++
 3 files changed, 16 insertions(+)
 create mode 100644 clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 763bc3ac159322..f2f6988a1f5c13 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -505,6 +505,8 @@ Bug Fixes to C++ Support
 - Fix a crash when parsing a pseudo destructor involving an invalid type. 
(#GH111460)
 - Fixed an assertion failure when invoking recovery call expressions with 
explicit attributes
   and undeclared templates. (#GH107047, #GH49093)
+- Fixed a compiler crash that occurred when processing malformed code 
involving `sizeof` with
+  an invalid type argument. (#GH111594)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4e37385710af5e..b0bd216c5dc101 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4629,6 +4629,9 @@ ExprResult 
Sema::CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo,
   TInfo->getType()->isVariablyModifiedType())
 TInfo = TransformToPotentiallyEvaluated(TInfo);
 
+  if (!TInfo)
+return ExprError();
+
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
diff --git a/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp 
b/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp
new file mode 100644
index 00..ffb9e3df1e5843
--- /dev/null
+++ b/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value %s
+//
+// Note: This test is ensure that code does not cause a crash as previously
+// reported in (#GH111594). The specific diagnostics are unimportant.
+
+a() {struct b c (sizeof(b * [({ {tree->d* next)} 0
+
+// expected-error@6 0+{{}}
+// expected-error@11 0+{{}}
+// expected-note@6 0+{{}}
+

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


[clang] [Clang][SYCL] Introduce clang-sycl-link-wrapper to link SYCL offloading device code (Part 1 of many) (PR #112245)

2024-10-15 Thread Joseph Huber via cfe-commits


@@ -0,0 +1,82 @@
+===
+Clang SYCL Linker
+===
+
+.. contents::
+   :local:
+
+.. _clang-sycl-linker:
+
+Introduction
+
+
+This tool works as a wrapper around the SYCL device code linking process.
+The purpose of this tool is to provide an interface to link SYCL device bitcode
+in LLVM IR format, SYCL device bitcode in SPIR-V IR format, and native binary
+objects, and then use the SPIR-V LLVM Translator tool on fully linked device
+objects to produce the final output.
+After the linking stage, the fully linked device code in LLVM IR format may
+undergo several SYCL-specific finalization steps before the SPIR-V code
+generation step.
+The tool will also support the Ahead-Of-Time (AOT) compilation flow. AOT
+compilation is the process of invoking the back-end at compile time to produce
+the final binary, as opposed to just-in-time (JIT) compilation when final code
+generation is deferred until application runtime.
+
+Device code linking for SYCL offloading has several known quirks that
+make it difficult to use in a unified offloading setting. Two of the primary
+issues are:
+1. Several finalization steps are required to be run on the fully linked LLVM
+IR bitcode to guarantee conformance to SYCL standards. This step is unique to
+the SYCL offloading compilation flow.
+2. The SPIR-V LLVM Translator tool is an external tool and hence SPIR-V IR code
+generation cannot be done as part of LTO. This limitation can be lifted once
+the SPIR-V backend is available as a viable LLVM backend.
+
+This tool has been proposed to work around these issues.
+
+Usage
+=
+
+This tool can be used with the following options. Several of these options will
+be passed down to downstream tools like 'llvm-link', 'llvm-spirv', etc.
+
+.. code-block:: console
+
+  OVERVIEW: A utility that wraps around the SYCL device code linking process.
+  This enables linking and code generation for SPIR-V JIT targets and AOT
+  targets.
+
+  USAGE: clang-sycl-linker [options]
+
+  OPTIONS:
+--arch Specify the name of the target architecture.
+--dry-run Print generated commands without running.
+-gSpecify that this was a debug compile.
+-help-hidden  Display all available options
+-help Display available options (--help-hidden for 
more)
+--library-path=  Set the library path for SYCL device 
libraries
+--device-libs= A comma separated list of device libraries 
that are linked during the device link

jhuber6 wrote:

Why are device libs and regular input distinct?

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


[clang] 84ee629 - clang: Remove some pointer bitcasts (#112324)

2024-10-15 Thread via cfe-commits

Author: Matt Arsenault
Date: 2024-10-15T22:46:24+04:00
New Revision: 84ee629bc515e5a2247043c668c7da38447c20e9

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

LOG: clang: Remove some pointer bitcasts (#112324)

Obsolete since opaque pointers.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGExprCXX.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c563f2618b42c8..157e743a39bfbc 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1288,9 +1288,8 @@ static llvm::Value *EmitBitTestIntrinsic(CodeGenFunction 
&CGF,
   // Bit = BitBaseI8[BitPos >> 3] & (1 << (BitPos & 0x7)) != 0;
   Value *ByteIndex = CGF.Builder.CreateAShr(
   BitPos, llvm::ConstantInt::get(BitPos->getType(), 3), "bittest.byteidx");
-  Value *BitBaseI8 = CGF.Builder.CreatePointerCast(BitBase, CGF.Int8PtrTy);
-  Address ByteAddr(CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, BitBaseI8,
- ByteIndex, 
"bittest.byteaddr"),
+  Address ByteAddr(CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, BitBase, 
ByteIndex,
+ "bittest.byteaddr"),
CGF.Int8Ty, CharUnits::One());
   Value *PosLow =
   CGF.Builder.CreateAnd(CGF.Builder.CreateTrunc(BitPos, CGF.Int8Ty),
@@ -5658,14 +5657,13 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 *Arg3 = EmitScalarExpr(E->getArg(3));
   llvm::FunctionType *FTy = llvm::FunctionType::get(
   Int32Ty, llvm::ArrayRef(ArgTys), false);
-  Value *BCast = Builder.CreatePointerCast(Arg3, I8PTy);
   // We know the third argument is an integer type, but we may need to cast
   // it to i32.
   if (Arg2->getType() != Int32Ty)
 Arg2 = Builder.CreateZExtOrTrunc(Arg2, Int32Ty);
   return RValue::get(
   EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name),
-  {Arg0, Arg1, Arg2, BCast, PacketSize, PacketAlign}));
+  {Arg0, Arg1, Arg2, Arg3, PacketSize, PacketAlign}));
 }
   }
   // OpenCL v2.0 s6.13.16 ,s9.17.3.5 - Built-in pipe reserve read and write
@@ -11317,7 +11315,6 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned 
BuiltinID,
 Value *Dst = EmitScalarExpr(E->getArg(0));
 Value *Val = EmitScalarExpr(E->getArg(1));
 Value *Size = EmitScalarExpr(E->getArg(2));
-Dst = Builder.CreatePointerCast(Dst, Int8PtrTy);
 Val = Builder.CreateTrunc(Val, Int8Ty);
 Size = Builder.CreateIntCast(Size, Int64Ty, false);
 return Builder.CreateCall(
@@ -11342,34 +11339,27 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
   }
 
   if (MTEIntrinsicID != Intrinsic::not_intrinsic) {
-llvm::Type *T = ConvertType(E->getType());
-
 if (MTEIntrinsicID == Intrinsic::aarch64_irg) {
   Value *Pointer = EmitScalarExpr(E->getArg(0));
   Value *Mask = EmitScalarExpr(E->getArg(1));
 
-  Pointer = Builder.CreatePointerCast(Pointer, Int8PtrTy);
   Mask = Builder.CreateZExt(Mask, Int64Ty);
-  Value *RV = Builder.CreateCall(
-   CGM.getIntrinsic(MTEIntrinsicID), {Pointer, Mask});
-   return Builder.CreatePointerCast(RV, T);
+  return Builder.CreateCall(CGM.getIntrinsic(MTEIntrinsicID),
+{Pointer, Mask});
 }
 if (MTEIntrinsicID == Intrinsic::aarch64_addg) {
   Value *Pointer = EmitScalarExpr(E->getArg(0));
   Value *TagOffset = EmitScalarExpr(E->getArg(1));
 
-  Pointer = Builder.CreatePointerCast(Pointer, Int8PtrTy);
   TagOffset = Builder.CreateZExt(TagOffset, Int64Ty);
-  Value *RV = Builder.CreateCall(
-   CGM.getIntrinsic(MTEIntrinsicID), {Pointer, TagOffset});
-  return Builder.CreatePointerCast(RV, T);
+  return Builder.CreateCall(CGM.getIntrinsic(MTEIntrinsicID),
+{Pointer, TagOffset});
 }
 if (MTEIntrinsicID == Intrinsic::aarch64_gmi) {
   Value *Pointer = EmitScalarExpr(E->getArg(0));
   Value *ExcludedMask = EmitScalarExpr(E->getArg(1));
 
   ExcludedMask = Builder.CreateZExt(ExcludedMask, Int64Ty);
-  Pointer = Builder.CreatePointerCast(Pointer, Int8PtrTy);
   return Builder.CreateCall(
CGM.getIntrinsic(MTEIntrinsicID), {Pointer, 
ExcludedMask});
 }
@@ -11378,25 +11368,20 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 // return address same as input address.
 if (MTEIntrinsicID == Intrinsic::aarch64_ldg) {
   Value *TagAddress = EmitScalarExpr(E->getArg(0));
-  TagAddress = Builder.CreatePointerCast(TagAddress, Int8PtrTy);
-  Value *RV 

[clang] clang: Remove some pointer bitcasts (PR #112324)

2024-10-15 Thread Matt Arsenault via cfe-commits

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


[clang] [llvm] [HLSL] Implement `WaveActiveSum` intrinsic (PR #112400)

2024-10-15 Thread Finn Plummer via cfe-commits

inbelic wrote:

Dependent on https://github.com/llvm/llvm-project/pull/112058 and 
https://github.com/llvm/llvm-project/pull/111010.

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


[clang] [Clang][Sema] Use the correct injected template arguments for partial specializations when collecting multi-level template argument lists (PR #112381)

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

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/112381

>From 146b209c90a5ced513ec886882ed57ce09ca2f56 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Tue, 15 Oct 2024 09:52:43 -0400
Subject: [PATCH 1/2] [Clang][Sema] Use the correct injected template arguments
 for partial specializations when collecting multi-level template argument
 lists

---
 clang/include/clang/AST/DeclTemplate.h | 14 ++-
 clang/lib/AST/DeclTemplate.cpp | 28 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  4 ++--
 3 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 141f58c4600af0..6c7f47cd5204c2 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -2085,7 +2085,9 @@ class ClassTemplateSpecializationDecl : public 
CXXRecordDecl,
 class ClassTemplatePartialSpecializationDecl
   : public ClassTemplateSpecializationDecl {
   /// The list of template parameters
-  TemplateParameterList* TemplateParams = nullptr;
+  TemplateParameterList *TemplateParams = nullptr;
+
+  TemplateArgument *InjectedArgs = nullptr;
 
   /// The class template partial specialization from which this
   /// class template partial specialization was instantiated.
@@ -2132,6 +2134,10 @@ class ClassTemplatePartialSpecializationDecl
 return TemplateParams;
   }
 
+  /// Retrieve the template arguments list of the template parameter list
+  /// of this template.
+  ArrayRef getInjectedTemplateArgs();
+
   /// \brief All associated constraints of this partial specialization,
   /// including the requires clause and any constraints derived from
   /// constrained-parameters.
@@ -2856,6 +2862,8 @@ class VarTemplatePartialSpecializationDecl
   /// The list of template parameters
   TemplateParameterList *TemplateParams = nullptr;
 
+  TemplateArgument *InjectedArgs = nullptr;
+
   /// The variable template partial specialization from which this
   /// variable template partial specialization was instantiated.
   ///
@@ -2902,6 +2910,10 @@ class VarTemplatePartialSpecializationDecl
 return TemplateParams;
   }
 
+  /// Retrieve the template arguments list of the template parameter list
+  /// of this template.
+  ArrayRef getInjectedTemplateArgs();
+
   /// \brief All associated constraints of this partial specialization,
   /// including the requires clause and any constraints derived from
   /// constrained-parameters.
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index d9b67b7bedf5a5..d2d8907b884ec8 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -1185,6 +1185,20 @@ SourceRange 
ClassTemplatePartialSpecializationDecl::getSourceRange() const {
   return Range;
 }
 
+ArrayRef
+ClassTemplatePartialSpecializationDecl::getInjectedTemplateArgs() {
+  TemplateParameterList *Params = getTemplateParameters();
+  auto *First = cast(getFirstDecl());
+  if (!First->InjectedArgs) {
+auto &Context = getASTContext();
+SmallVector TemplateArgs;
+Context.getInjectedTemplateArgs(Params, TemplateArgs);
+First->InjectedArgs = new (Context) TemplateArgument[TemplateArgs.size()];
+std::copy(TemplateArgs.begin(), TemplateArgs.end(), First->InjectedArgs);
+  }
+  return llvm::ArrayRef(First->InjectedArgs, Params->size());
+}
+
 
//===--===//
 // FriendTemplateDecl Implementation
 
//===--===//
@@ -1535,6 +1549,20 @@ SourceRange 
VarTemplatePartialSpecializationDecl::getSourceRange() const {
   return Range;
 }
 
+ArrayRef
+VarTemplatePartialSpecializationDecl::getInjectedTemplateArgs() {
+  TemplateParameterList *Params = getTemplateParameters();
+  auto *First = cast(getFirstDecl());
+  if (!First->InjectedArgs) {
+auto &Context = getASTContext();
+SmallVector TemplateArgs;
+Context.getInjectedTemplateArgs(Params, TemplateArgs);
+First->InjectedArgs = new (Context) TemplateArgument[TemplateArgs.size()];
+std::copy(TemplateArgs.begin(), TemplateArgs.end(), First->InjectedArgs);
+  }
+  return llvm::ArrayRef(First->InjectedArgs, Params->size());
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC) {
   // typename T
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 8c7f694c09042e..8665c099903dc3 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -237,7 +237,7 @@ struct TemplateInstantiationArgumentCollecter
 if (Innermost)
   AddInnermostTemplateArguments(VTPSD);
 else if (ForConstraintInstantiation)
-  AddOuterTemplateArguments(VTPSD, VTPSD->getTemplateArgs().asArray(),
+  AddOuterTemplateArguments(VTPSD, VTPSD->getInjectedTempla

  1   2   3   4   5   6   >