[clang] [Modules] No transitive source location change (PR #86912)

2024-03-28 Thread Chuanqi Xu via cfe-commits

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


[clang] [clang][analyzer] Change modeling of `fseek` in StreamChecker. (PR #86919)

2024-03-28 Thread Balázs Kéri via cfe-commits

https://github.com/balazske created 
https://github.com/llvm/llvm-project/pull/86919

Until now function `fseek` returned nonzero on error, this is changed to -1 
only. And it does not produce EOF error any more.
This complies better with the POSIX standard.

From b6c76404c2f0b0e960adcadd7f089ecc59dbba38 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Wed, 27 Mar 2024 18:09:20 +0100
Subject: [PATCH] [clang][analyzer] Change modeling of `fseek` in
 StreamChecker.

Until now function `fseek` returned nonzero on error, this is changed to -1 
only.
And it does not produce EOF error any more.
This complies better with the POSIX standard.
---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 21 +++--
 clang/test/Analysis/stream-error.c| 43 ---
 clang/test/Analysis/stream-note.c | 31 -
 3 files changed, 55 insertions(+), 40 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 902c42a2799be4..069e3a633c1214 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -1264,15 +1264,10 @@ void StreamChecker::evalFseek(const FnDescription 
*Desc, const CallEvent &Call,
   if (!E.Init(Desc, Call, C, State))
 return;
 
-  const llvm::APSInt *PosV =
-  C.getSValBuilder().getKnownValue(State, Call.getArgSVal(1));
-  const llvm::APSInt *WhenceV =
-  C.getSValBuilder().getKnownValue(State, Call.getArgSVal(2));
-
   // Bifurcate the state into failed and non-failed.
-  // Return zero on success, nonzero on error.
-  ProgramStateRef StateNotFailed, StateFailed;
-  std::tie(StateFailed, StateNotFailed) = E.makeRetValAndAssumeDual(State, C);
+  // Return zero on success, -1 on error.
+  ProgramStateRef StateNotFailed = E.bindReturnValue(State, C, 0);
+  ProgramStateRef StateFailed = E.bindReturnValue(State, C, -1);
 
   // No failure: Reset the state to opened with no error.
   StateNotFailed =
@@ -1282,12 +1277,10 @@ void StreamChecker::evalFseek(const FnDescription 
*Desc, const CallEvent &Call,
   // At error it is possible that fseek fails but sets none of the error flags.
   // If fseek failed, assume that the file position becomes indeterminate in 
any
   // case.
-  StreamErrorState NewErrS = ErrorNone | ErrorFError;
-  // Setting the position to start of file never produces EOF error.
-  if (!(PosV && *PosV == 0 && WhenceV && *WhenceV == SeekSetVal))
-NewErrS = NewErrS | ErrorFEof;
-  StateFailed = E.setStreamState(StateFailed,
- StreamState::getOpened(Desc, NewErrS, true));
+  // It is allowed to set the position beyond the end of the file. EOF error
+  // should not occur.
+  StateFailed = E.setStreamState(
+  StateFailed, StreamState::getOpened(Desc, ErrorNone | ErrorFError, 
true));
   C.addTransition(StateFailed, E.getFailureNoteTag(this, C));
 }
 
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 88f7de4234ffb4..7f9116ff401445 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -365,27 +365,22 @@ void error_fseek(void) {
 return;
   int rc = fseek(F, 1, SEEK_SET);
   if (rc) {
+clang_analyzer_eval(rc == -1); // expected-warning {{TRUE}}
 int IsFEof = feof(F), IsFError = ferror(F);
-// Get feof or ferror or no error.
-clang_analyzer_eval(IsFEof || IsFError);
-// expected-warning@-1 {{FALSE}}
-// expected-warning@-2 {{TRUE}}
-clang_analyzer_eval(IsFEof && IsFError); // expected-warning {{FALSE}}
+// Get ferror or no error.
+clang_analyzer_eval(IsFError); // expected-warning {{FALSE}} \
+   // expected-warning {{TRUE}}
+clang_analyzer_eval(IsFEof);   // expected-warning {{FALSE}}
 // Error flags should not change.
-if (IsFEof)
-  clang_analyzer_eval(feof(F)); // expected-warning {{TRUE}}
-else
-  clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
+clang_analyzer_eval(feof(F));  // expected-warning {{FALSE}}
 if (IsFError)
-  clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
-else
-  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  clang_analyzer_eval(ferror(F));  // expected-warning {{TRUE}}
   } else {
-clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
-clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+clang_analyzer_eval(feof(F));  // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F));// expected-warning {{FALSE}}
 // Error flags should not change.
-clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
-clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+clang_analyzer_eval(feof(F));  // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F));// expected-warning {{FALSE}}
  

[clang] [clang][analyzer] Change modeling of `fseek` in StreamChecker. (PR #86919)

2024-03-28 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

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

Author: Balázs Kéri (balazske)


Changes

Until now function `fseek` returned nonzero on error, this is changed to -1 
only. And it does not produce EOF error any more.
This complies better with the POSIX standard.

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


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+7-14) 
- (modified) clang/test/Analysis/stream-error.c (+18-25) 
- (modified) clang/test/Analysis/stream-note.c (+30-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 902c42a2799be4..069e3a633c1214 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -1264,15 +1264,10 @@ void StreamChecker::evalFseek(const FnDescription 
*Desc, const CallEvent &Call,
   if (!E.Init(Desc, Call, C, State))
 return;
 
-  const llvm::APSInt *PosV =
-  C.getSValBuilder().getKnownValue(State, Call.getArgSVal(1));
-  const llvm::APSInt *WhenceV =
-  C.getSValBuilder().getKnownValue(State, Call.getArgSVal(2));
-
   // Bifurcate the state into failed and non-failed.
-  // Return zero on success, nonzero on error.
-  ProgramStateRef StateNotFailed, StateFailed;
-  std::tie(StateFailed, StateNotFailed) = E.makeRetValAndAssumeDual(State, C);
+  // Return zero on success, -1 on error.
+  ProgramStateRef StateNotFailed = E.bindReturnValue(State, C, 0);
+  ProgramStateRef StateFailed = E.bindReturnValue(State, C, -1);
 
   // No failure: Reset the state to opened with no error.
   StateNotFailed =
@@ -1282,12 +1277,10 @@ void StreamChecker::evalFseek(const FnDescription 
*Desc, const CallEvent &Call,
   // At error it is possible that fseek fails but sets none of the error flags.
   // If fseek failed, assume that the file position becomes indeterminate in 
any
   // case.
-  StreamErrorState NewErrS = ErrorNone | ErrorFError;
-  // Setting the position to start of file never produces EOF error.
-  if (!(PosV && *PosV == 0 && WhenceV && *WhenceV == SeekSetVal))
-NewErrS = NewErrS | ErrorFEof;
-  StateFailed = E.setStreamState(StateFailed,
- StreamState::getOpened(Desc, NewErrS, true));
+  // It is allowed to set the position beyond the end of the file. EOF error
+  // should not occur.
+  StateFailed = E.setStreamState(
+  StateFailed, StreamState::getOpened(Desc, ErrorNone | ErrorFError, 
true));
   C.addTransition(StateFailed, E.getFailureNoteTag(this, C));
 }
 
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 88f7de4234ffb4..7f9116ff401445 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -365,27 +365,22 @@ void error_fseek(void) {
 return;
   int rc = fseek(F, 1, SEEK_SET);
   if (rc) {
+clang_analyzer_eval(rc == -1); // expected-warning {{TRUE}}
 int IsFEof = feof(F), IsFError = ferror(F);
-// Get feof or ferror or no error.
-clang_analyzer_eval(IsFEof || IsFError);
-// expected-warning@-1 {{FALSE}}
-// expected-warning@-2 {{TRUE}}
-clang_analyzer_eval(IsFEof && IsFError); // expected-warning {{FALSE}}
+// Get ferror or no error.
+clang_analyzer_eval(IsFError); // expected-warning {{FALSE}} \
+   // expected-warning {{TRUE}}
+clang_analyzer_eval(IsFEof);   // expected-warning {{FALSE}}
 // Error flags should not change.
-if (IsFEof)
-  clang_analyzer_eval(feof(F)); // expected-warning {{TRUE}}
-else
-  clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
+clang_analyzer_eval(feof(F));  // expected-warning {{FALSE}}
 if (IsFError)
-  clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
-else
-  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  clang_analyzer_eval(ferror(F));  // expected-warning {{TRUE}}
   } else {
-clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
-clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+clang_analyzer_eval(feof(F));  // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F));// expected-warning {{FALSE}}
 // Error flags should not change.
-clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
-clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+clang_analyzer_eval(feof(F));  // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F));// expected-warning {{FALSE}}
   }
   fclose(F);
 }
@@ -396,15 +391,13 @@ void error_fseeko(void) {
 return;
   int rc = fseeko(F, 1, SEEK_SET);
   if (rc) {
-int IsFEof = feof(F), IsFError = ferror(F);
-// Get feof or ferror or no error.
-clang_analyzer_eval(IsFEof || IsFError);
-// expected-warning@-1 {{FALSE}}
-// expected-wa

[clang] [Modules] No transitive source location change (PR #86912)

2024-03-28 Thread Chuanqi Xu via cfe-commits

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-03-28 Thread Chuanqi Xu via cfe-commits

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-03-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Chuanqi Xu (ChuanqiXu9)


Changes

This is part of "no transitive change" patch series, "no transitive source 
location change". I talked this with @Bigcheese in the tokyo's WG21 
meeting.

The idea comes from @jyknight posted on LLVM discourse. That for:

```
// A.cppm
export module A;
...

// B.cppm
export module B;
import A;
...

//--- C.cppm
export module C;
import C;
```

Almost every time A.cppm changes, we need to recompile `C`. Due to we think the 
source location is significant to the semantics.  But it may be good if we can 
avoid recompiling `C` if the change from `A` wouldn't change the BMI of B.

# Motivation Example

This patch only cares source locations. So let's focus on source location's 
example. We can see the full example from the attached test.

```
//--- A.cppm
export module A;
export template 
struct C {
T func() {
return T(43);
}
};
export int funcA() {
return 43;
}

//--- A.v1.cppm
export module A;

export template 
struct C {
T func() {
return T(43);
}
};
export int funcA() {
return 43;
}

//--- B.cppm
export module B;
import A;

export int funcB() {
return funcA();
}

//--- C.cppm
export module C;
import A;
export void testD() {
C c;
c.func();
}
```

Here the only difference between `A.cppm` and `A.v1.cppm` is that `A.v1.cppm` 
has an additional blank line. Then the test shows that two BMI of `B.cppm`, one 
specified `-fmodule-file=A=A.pcm` and the other specified 
`-fmodule-file=A=A.v1.pcm`, should have the bit-wise same contents. 

However, it is a different story for C, since C instantiates templates from A, 
and the instantiation records the source information from module A, which is 
different from `A` and `A.v1`, so it is expected that the BMI `C.pcm` and 
`C.v1.pcm` can and should differ.

# Internal perspective of status quo

To fully understand the patch, we need to understand how we encodes source 
locations and how we serialize and deserialize them.

For source locations, we encoded them as:

```
|
|
| _ base offset of an imported module
|
|
|
|_ base offset of another imported module
|
|
|
|
| ___ 0
```

As the diagram shows, we encode the local (unloaded) source location from 0 to 
higher bits. And we allocate the space for source locations from the loaded 
modules from high bits to 0. Then the source locations from the loaded modules 
will be mapped to our source location space according to the allocated offset.

For example, for,

```
// a.cppm
export module a;
...

// b.cppm
export module b;
import a;
...
```

Assuming the offset of a source location (let's name the location as `S`) in 
a.cppm is 45 and we will record the value `45` into the BMI `a.pcm`. Then in 
b.cppm, when we import a, the source manager will allocate a space for module 
'a' (according to the recorded number of source locations) as the base offset 
of module 'a' in the current source location spaces. Let's assume the allocated 
base offset as 90 in this example.  Then when we want to get the location in 
the current source location space for `S`, we can get it simply by adding `45` 
to `90` to `135`. Finally we can get the source location for `S` in module B as 
`135`.

And when we want to write module `b`, we would also write the source location 
of `S` as `135` directly in the BMI. And to clarify the location `S` comes from 
module `a`, we also need to record the base offset of  module `a`, 90 in the 
BMI of `b`.

Then the problem comes. Since the base offset of module 'a' is computed by the 
number source locations in module 'a'. In module 'b', the recorded base offset 
of module 'a' will change every time the number of source locations in module 
'a' increase or decrease. In other words, the contents of BMI of B will change 
every time the number of locations in module 'a' changes. This is pretty 
sensitive. Almost every change will change the number of locations. So this is 
the problem this patch want to solve.

Let's continue with the existing design to understand what's going on. Another 
interesting case is:

```
// c.cppm
export module c;
import a;
import b;
...
```

In `c.cppm`, when we import `a`, we still need to allocate a base location 
offset for it, let's say the value becomes to `200` somehow. Then when we reach 
the location `S` recorded in module `b`, we need to translate it into the 
current source location space. The solution is quite simple, we can get it by 
`135 + (200 - 90) = 245`. In another word, the offset of a source location in 
current module can be computed as `Recorded Offset + Base Offset of the its 
module file - Recorded Base Offset`.

Then we're almost done about how we handle the offset of source locations in 
serializers.

# The high level design of current patch

>From the abstract level, what we want to do  is to remove the hardcoded base 
>offset of imported modules and remain the ability to calculate the source 
>

[clang] [clang] Fix an out-of-bound crash when checking template partial specializations. (PR #86794)

2024-03-28 Thread Haojian Wu via cfe-commits


@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++20 -verify %s
+// RUN: %clang_cc1 -std=c++20 -ferror-limit 0 -verify %s

hokein wrote:

This file contains many errors, the number of the errors exceeds the default 
number (19) in clang, which affects the clang behavior (clang will stop parsing 
when it reaches the error limit). 

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-03-28 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@sam-mccall any updates?

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


[clang] [AST] Print the "aggregate" for aggregate deduction guide decl. (PR #84018)

2024-03-28 Thread Haojian Wu via cfe-commits


@@ -1990,6 +1990,18 @@ void TextNodeDumper::VisitFunctionDecl(const 
FunctionDecl *D) {
   }
 }
 
+void TextNodeDumper::VisitCXXDeductionGuideDecl(const CXXDeductionGuideDecl 
*D) {
+  VisitFunctionDecl(D);
+  switch (D->getDeductionCandidateKind()) {
+  case DeductionCandidate::Normal:
+  case DeductionCandidate::Copy:

hokein wrote:

Maybe, but I don't have this business need for the "copy" case at the moment, 
so I'm inclined to leave it as is for now.

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


[clang] 63ea5a4 - [clang] Invalidate the alias template decl if it has multiple written template parameter lists. (#85413)

2024-03-28 Thread via cfe-commits

Author: Haojian Wu
Date: 2024-03-28T09:13:26+01:00
New Revision: 63ea5a4088ff73a47cd3411fad3b42c92a3c64f0

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

LOG: [clang] Invalidate the alias template decl if it has multiple written 
template parameter lists. (#85413)

Fixes #85406.

- Set the invalid bit for alias template decl where it has multiple
written template parameter lists (as the AST node is ill-formed)
- don't perform CTAD for invalid alias template decls

Added: 


Modified: 
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/AST/ast-dump-invalid.cpp
clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e9fecaea84b021..f32ff396f8a543 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -13589,6 +13589,7 @@ Decl *Sema::ActOnAliasDeclaration(Scope *S, 
AccessSpecifier AS,
   Diag(UsingLoc, diag::err_alias_template_extra_headers)
 << SourceRange(TemplateParamLists[1]->getTemplateLoc(),
  TemplateParamLists[TemplateParamLists.size()-1]->getRAngleLoc());
+  Invalid = true;
 }
 TemplateParameterList *TemplateParams = TemplateParamLists[0];
 

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index aab72dbaf48c46..e575bb2df97f05 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2731,6 +2731,8 @@ bool hasDeclaredDeductionGuides(DeclarationName Name, 
DeclContext *DC) {
 // Build deduction guides for a type alias template.
 void DeclareImplicitDeductionGuidesForTypeAlias(
 Sema &SemaRef, TypeAliasTemplateDecl *AliasTemplate, SourceLocation Loc) {
+  if (AliasTemplate->isInvalidDecl())
+return;
   auto &Context = SemaRef.Context;
   // FIXME: if there is an explicit deduction guide after the first use of the
   // type alias usage, we will not cover this explicit deduction guide. fix 
this

diff  --git a/clang/test/AST/ast-dump-invalid.cpp 
b/clang/test/AST/ast-dump-invalid.cpp
index 0a301dba51d288..5b6d74194b989d 100644
--- a/clang/test/AST/ast-dump-invalid.cpp
+++ b/clang/test/AST/ast-dump-invalid.cpp
@@ -60,3 +60,12 @@ double Str::foo1(double, invalid_type)
 // CHECK-NEXT: `-ReturnStmt {{.*}} 
 // CHECK-NEXT:   `-ImplicitCastExpr {{.*}}  'double' 

 // CHECK-NEXT: `-IntegerLiteral {{.*}}  'int' 45
+
+namespace TestAliasTemplateDecl {
+template class A;
+
+template
+template using InvalidAlias = A;
+// CHECK:  TypeAliasTemplateDecl {{.*}} invalid InvalidAlias
+// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T
+}

diff  --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index 3ce26c8fcd984e..ce403285b0f531 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -247,3 +247,15 @@ using Bar = Foo; // expected-note {{could not match 
'Foo'
 
 Bar s = {1}; // expected-error {{no viable constructor or deduction guide for 
deduction of template arguments}}
 } // namespace test18
+
+// GH85406, verify no crash on invalid alias templates.
+namespace test19 {
+template 
+class Foo {};
+
+template 
+template 
+using Bar2 = Foo; // expected-error {{extraneous template parameter list in 
alias template declaration}}
+
+Bar2 b = 1; // expected-error {{no viable constructor or deduction guide for 
deduction of template arguments}}
+} // namespace test19



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


[clang] [clang] Invalidate the alias template decl if it has multiple written (PR #85413)

2024-03-28 Thread Haojian Wu via cfe-commits

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


[clang] [clang][Sema] Fix a CTAD regression after 42239d2e9 (PR #86914)

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

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


[clang] [clang][Sema] Fix a CTAD regression after 42239d2e9 (PR #86914)

2024-03-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

The most recent declaration of a template as a friend can introduce a different 
template parameter depth compared to what we anticipate from a CTAD guide.

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

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+13-1) 
- (modified) clang/test/SemaTemplate/concepts-friends.cpp (+24) 
- (modified) clang/test/SemaTemplate/ctad.cpp (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..ed0996bd3d30c0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -345,6 +345,9 @@ Bug Fixes in This Version
 - Fixes an assertion failure on invalid code when trying to define member
   functions in lambdas.
 
+- Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
+  incorrect constraint substitution. (#GH86769).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 005529a53270c3..14fabe36eee794 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1836,7 +1836,19 @@ static TemplateParameterList 
*GetTemplateParameterList(TemplateDecl *TD) {
   // Make sure we get the template parameter list from the most
   // recent declaration, since that is the only one that is guaranteed to
   // have all the default template argument information.
-  return cast(TD->getMostRecentDecl())->getTemplateParameters();
+  Decl *ND = TD->getMostRecentDecl();
+  // Skip past friend Decls because they are not supposed to contain default
+  // template arguments. Moreover, these declarations may introduce template
+  // parameters living in different template depths than the corresponding
+  // template parameters in TD, causing unmatched constraint substitution.
+  //
+  // C++23 N4950 [temp.param]p12
+  // A default template argument shall not be specified in a friend class
+  // template declaration.
+  while (ND->getFriendObjectKind() != Decl::FriendObjectKind::FOK_None &&
+ ND->getPreviousDecl())
+ND = ND->getPreviousDecl();
+  return cast(ND)->getTemplateParameters();
 }
 
 DeclResult Sema::CheckClassTemplate(
diff --git a/clang/test/SemaTemplate/concepts-friends.cpp 
b/clang/test/SemaTemplate/concepts-friends.cpp
index 255b0858917fb6..31840309f1ec86 100644
--- a/clang/test/SemaTemplate/concepts-friends.cpp
+++ b/clang/test/SemaTemplate/concepts-friends.cpp
@@ -478,3 +478,27 @@ template  class Foo {
 };
 
 } // namespace FriendOfFriend
+
+namespace GH86769 {
+
+template 
+concept X = true;
+
+template  struct Y {
+  Y(T) {}
+  template  friend struct Y;
+  template  friend struct Y;
+  template  friend struct Y;
+};
+
+template 
+struct Z {
+  // FIXME: This is ill-formed per N4950 [temp.param]p12.
+  template  friend struct Y;
+};
+
+template struct Y;
+template struct Z;
+Y y(1);
+
+}
diff --git a/clang/test/SemaTemplate/ctad.cpp b/clang/test/SemaTemplate/ctad.cpp
index 388ed7d4cced18..ec144d4f44ba8c 100644
--- a/clang/test/SemaTemplate/ctad.cpp
+++ b/clang/test/SemaTemplate/ctad.cpp
@@ -53,4 +53,4 @@ X x;
 template struct Y { Y(T); };
 template struct Y ;
 Y y(1);
-};
+}

``




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


[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)

2024-03-28 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@rjmccall @dwblaikie ping

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


[clang] [clang] Bailout when the substitution of template parameter mapping is invalid. (PR #86869)

2024-03-28 Thread Haojian Wu via cfe-commits

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-03-28 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

 BTW, after this patch, with reduced BMI 
(https://github.com/llvm/llvm-project/pull/85050), we can already do something 
more interesting than reformating:

```
//--- A.cppm
export module A;
int funcA0();
int funcA1();
export int funcA() {
return funcA0();
}

//--- A.v1.cppm
export module A;

int funcA0();
int funcA1();
export int funcA() {
return funcA0() + funcA1();
}

//--- B.cppm
export module B;
import A;

export int funcB() {
return funcA();
}
```

Now the B.pcm will keep unchanged  with `A.pcm` from `A.cppm` and `A.v1.pcm` 
from `A.v1.cppm`. We changed the implementation of `funcA()` from `return 
funcA0();` to `return funcA0() + funcA1();`. And the `B.pcm` can still get the 
same content.

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


[clang] [clang][Sema] Fix a CTAD regression after 42239d2e9 (PR #86914)

2024-03-28 Thread Haojian Wu via cfe-commits

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


[clang] [clang][Sema] Fix a CTAD regression after 42239d2e9 (PR #86914)

2024-03-28 Thread Haojian Wu via cfe-commits

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

thanks, this looks good from my side.

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


[clang] [clang][Sema] Fix a CTAD regression after 42239d2e9 (PR #86914)

2024-03-28 Thread Haojian Wu via cfe-commits


@@ -1836,7 +1836,19 @@ static TemplateParameterList 
*GetTemplateParameterList(TemplateDecl *TD) {
   // Make sure we get the template parameter list from the most
   // recent declaration, since that is the only one that is guaranteed to
   // have all the default template argument information.
-  return cast(TD->getMostRecentDecl())->getTemplateParameters();
+  Decl *ND = TD->getMostRecentDecl();
+  // Skip past friend Decls because they are not supposed to contain default
+  // template arguments. Moreover, these declarations may introduce template
+  // parameters living in different template depths than the corresponding
+  // template parameters in TD, causing unmatched constraint substitution.
+  //
+  // C++23 N4950 [temp.param]p12

hokein wrote:

nit: this is not a new thing in C++23, I also find it in the C++20 spec N4860. 
I'd remove the `C++23 N4950`.

And I think this is also a FIXME, clang should diagnose this error case, maybe 
add the `FIXME` in the comment.

I think this function is not only used for class templates, but also for 
function templates. For function templates, there is an exception per the 
standard (temp.param 12): `If a friend function template declaration specifies 
a default template-argument, that declaration shall be a definition and shall 
be the only declaration of the function template in the translation unit.`


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


[clang] [Modules] No transitive source location change (PR #86912)

2024-03-28 Thread Chuanqi Xu via cfe-commits

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


[clang] [llvm] [CodeGen][arm64e] Add methods and data members to Address, which are needed to authenticate signed pointers (PR #86923)

2024-03-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-powerpc

Author: Akira Hatanaka (ahatanak)


Changes

To authenticate pointers, CodeGen needs access to the key and discriminators 
that were used to sign the pointer. That information is sometimes known from 
the context, but not always, which is why `Address` needs to hold that 
information.

This patch adds methods and data members to `Address`, which will be needed in 
subsequent patches to authenticate signed pointers, and uses the newly added 
methods throughout CodeGen. Although this patch isn't strictly NFC as it causes 
CodeGen to use different code paths in some cases (e.g., 
`mergeAddressesInConditionalExpr`), it doesn't cause any changes in 
functionality as it doesn't add any information needed for authentication.

In addition to the changes mentioned above, this patch introduces class 
`RawAddress`, which contains a pointer that we know is unsigned, and adds 
several new functions for creating `Address` and `LValue` objects.

This reapplies d9a685a9dd589486e882b722e513ee7b8c84870c, which was reverted 
because it broke ubsan bots. There seems to be a bug in coroutine code-gen, 
which is causing EmitTypeCheck to use the wrong alignment. For now, pass 
alignment zero to EmitTypeCheck so that it can compute the correct alignment 
based on the passed type (see function EmitCXXMemberOrOperatorMemberCallExpr).

---

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


50 Files Affected:

- (modified) clang/lib/CodeGen/ABIInfoImpl.cpp (+5-5) 
- (modified) clang/lib/CodeGen/Address.h (+167-28) 
- (modified) clang/lib/CodeGen/CGAtomic.cpp (+28-25) 
- (modified) clang/lib/CodeGen/CGBlocks.cpp (+19-15) 
- (modified) clang/lib/CodeGen/CGBlocks.h (+2-1) 
- (modified) clang/lib/CodeGen/CGBuilder.h (+160-74) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+90-83) 
- (modified) clang/lib/CodeGen/CGCUDANV.cpp (+10-9) 
- (modified) clang/lib/CodeGen/CGCXXABI.cpp (+15-6) 
- (modified) clang/lib/CodeGen/CGCXXABI.h (+2-12) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+97-74) 
- (modified) clang/lib/CodeGen/CGCall.h (+1) 
- (modified) clang/lib/CodeGen/CGClass.cpp (+45-31) 
- (modified) clang/lib/CodeGen/CGCleanup.cpp (+41-69) 
- (modified) clang/lib/CodeGen/CGCleanup.h (+1-1) 
- (modified) clang/lib/CodeGen/CGCoroutine.cpp (+2-2) 
- (modified) clang/lib/CodeGen/CGDecl.cpp (+16-12) 
- (modified) clang/lib/CodeGen/CGException.cpp (+11-8) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+119-108) 
- (modified) clang/lib/CodeGen/CGExprAgg.cpp (+16-13) 
- (modified) clang/lib/CodeGen/CGExprCXX.cpp (+55-60) 
- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+2-2) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+19-4) 
- (modified) clang/lib/CodeGen/CGNonTrivialStruct.cpp (+4-4) 
- (modified) clang/lib/CodeGen/CGObjC.cpp (+19-24) 
- (modified) clang/lib/CodeGen/CGObjCGNU.cpp (+22-20) 
- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+48-47) 
- (modified) clang/lib/CodeGen/CGObjCRuntime.cpp (+3-3) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+102-92) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.h (+2-3) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+39-37) 
- (modified) clang/lib/CodeGen/CGStmt.cpp (+4-4) 
- (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+45-42) 
- (modified) clang/lib/CodeGen/CGVTables.cpp (+4-5) 
- (modified) clang/lib/CodeGen/CGValue.h (+125-125) 
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+42-29) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+186-71) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CodeGenPGO.cpp (+6-4) 
- (modified) clang/lib/CodeGen/CodeGenPGO.h (+4-2) 
- (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+22-30) 
- (modified) clang/lib/CodeGen/MicrosoftCXXABI.cpp (+23-35) 
- (modified) clang/lib/CodeGen/TargetInfo.h (+5) 
- (modified) clang/lib/CodeGen/Targets/NVPTX.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/PPC.cpp (+6-5) 
- (modified) clang/lib/CodeGen/Targets/Sparc.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/SystemZ.cpp (+4-5) 
- (modified) clang/lib/CodeGen/Targets/XCore.cpp (+1-1) 
- (modified) clang/utils/TableGen/MveEmitter.cpp (+1-1) 
- (modified) llvm/include/llvm/IR/IRBuilder.h (+1) 


``diff
diff --git a/clang/lib/CodeGen/ABIInfoImpl.cpp 
b/clang/lib/CodeGen/ABIInfoImpl.cpp
index dd59101ecc81b8..3e34d82cb399ba 100644
--- a/clang/lib/CodeGen/ABIInfoImpl.cpp
+++ b/clang/lib/CodeGen/ABIInfoImpl.cpp
@@ -187,7 +187,7 @@ CodeGen::emitVoidPtrDirectVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   CharUnits FullDirectSize = DirectSize.alignTo(SlotSize);
   Address NextPtr =
   CGF.Builder.CreateConstInBoundsByteGEP(Addr, FullDirectSize, 
"argp.next");
-  CGF.Builder.CreateStore(NextPtr.getPointer(), VAListAddr);
+  CGF.Builder.CreateStore(NextPtr.emitRawPointer(CGF), VAListAddr);
 
   // If the argument is smaller than a slot, and this is a big-endian
   // target, the ar

[clang] 8d77d36 - [clang][dataflow] Introduce a helper class for handling record initializer lists. (#86675)

2024-03-28 Thread via cfe-commits

Author: martinboehme
Date: 2024-03-28T10:12:45+01:00
New Revision: 8d77d362af6ade32f087c051fe4774a3891f6ec9

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

LOG: [clang][dataflow] Introduce a helper class for handling record initializer 
lists. (#86675)

This is currently only used in one place, but I'm working on a patch
that will
use this from a second place. And I think this already improves the
readability
of the one place this is used so far.

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/Transfer.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 2330697299fdd7..c30bccd06674a4 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -744,6 +744,35 @@ RecordStorageLocation *getBaseObjectLocation(const 
MemberExpr &ME,
 std::vector
 getFieldsForInitListExpr(const InitListExpr *InitList);
 
+/// Helper class for initialization of a record with an `InitListExpr`.
+/// `InitListExpr::inits()` contains the initializers for both the base classes
+/// and the fields of the record; this helper class separates these out into 
two
+/// 
diff erent lists. In addition, it deals with special cases associated with
+/// unions.
+class RecordInitListHelper {
+public:
+  // `InitList` must have record type.
+  RecordInitListHelper(const InitListExpr *InitList);
+
+  // Base classes with their associated initializer expressions.
+  ArrayRef> base_inits() const {
+return BaseInits;
+  }
+
+  // Fields with their associated initializer expressions.
+  ArrayRef> field_inits() const {
+return FieldInits;
+  }
+
+private:
+  SmallVector> BaseInits;
+  SmallVector> FieldInits;
+
+  // We potentially synthesize an `ImplicitValueInitExpr` for unions. It's a
+  // member variable because we store a pointer to it in `FieldInits`.
+  std::optional ImplicitValueInitForUnion;
+};
+
 /// Associates a new `RecordValue` with `Loc` and returns the new value.
 RecordValue &refreshRecordValue(RecordStorageLocation &Loc, Environment &Env);
 

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 70e0623805a8cf..f729d676dd0de8 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -1169,6 +1169,42 @@ getFieldsForInitListExpr(const InitListExpr *InitList) {
   return Fields;
 }
 
+RecordInitListHelper::RecordInitListHelper(const InitListExpr *InitList) {
+  auto *RD = InitList->getType()->getAsCXXRecordDecl();
+  assert(RD != nullptr);
+
+  std::vector Fields = getFieldsForInitListExpr(InitList);
+  ArrayRef Inits = InitList->inits();
+
+  // Unions initialized with an empty initializer list need special treatment.
+  // For structs/classes initialized with an empty initializer list, Clang
+  // puts `ImplicitValueInitExpr`s in `InitListExpr::inits()`, but for unions,
+  // it doesn't do this -- so we create an `ImplicitValueInitExpr` ourselves.
+  SmallVector InitsForUnion;
+  if (InitList->getType()->isUnionType() && Inits.empty()) {
+assert(Fields.size() == 1);
+ImplicitValueInitForUnion.emplace(Fields.front()->getType());
+InitsForUnion.push_back(&*ImplicitValueInitForUnion);
+Inits = InitsForUnion;
+  }
+
+  size_t InitIdx = 0;
+
+  assert(Fields.size() + RD->getNumBases() == Inits.size());
+  for (const CXXBaseSpecifier &Base : RD->bases()) {
+assert(InitIdx < Inits.size());
+Expr *Init = Inits[InitIdx++];
+BaseInits.emplace_back(&Base, Init);
+  }
+
+  assert(Fields.size() == Inits.size() - InitIdx);
+  for (const FieldDecl *Field : Fields) {
+assert(InitIdx < Inits.size());
+Expr *Init = Inits[InitIdx++];
+FieldInits.emplace_back(Field, Init);
+  }
+}
+
 RecordValue &refreshRecordValue(RecordStorageLocation &Loc, Environment &Env) {
   auto &NewVal = Env.create(Loc);
   Env.setValue(Loc, NewVal);

diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 960e9688ffb725..0a2e8368d541dd 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -689,51 +689,22 @@ class TransferVisitor : public 
ConstStmtVisitor {
 }
 
 llvm::DenseMap FieldLocs;
-
-// This only contains the direct fields for the given type.
-std::vector FieldsForInit = getFieldsForInitListExpr(S);
-
-// `S->inits()` contains all the initializer expression

[clang] [clang][dataflow] Introduce a helper class for handling record initializer lists. (PR #86675)

2024-03-28 Thread via cfe-commits

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


[clang] [clang-tools-extra] [compiler-rt] [libcxx] [lld] [lldb] [llvm] [mlir] Fix SyntaxWarning messages from python 3.12 (PR #86806)

2024-03-28 Thread via cfe-commits


@@ -101,7 +101,7 @@ def extract_result_types(comment):
 
 
 def strip_doxygen(comment):
-"""Returns the given comment without \-escaped words."""
+"""Returns the given comment without \\-escaped words."""

AngryLoki wrote:

No, `'''\-'''` is still SyntaxWarning in Python 3.12. It is possible to not 
escape with raw literals, but raw literals are used mostly to indicate that 
string is actually _raw_ (I've never seen raw docblocks). Also there is some 
consensus between highlighting tools that raw literals use regexp highlighting 
(in vscode, dandavison/delta, sharkdp/bat), that's why I escaped some strings 
selectively (e. g. in runCmd I did not use raw literals).
https://github.com/llvm/llvm-project/assets/108563/deb36005-b0e5-459d-b936-cf644243774f";>


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


[clang] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

2024-03-28 Thread Daniil Kovalev via cfe-commits

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/84387

>From 728f5644aebfafd2114e7e47a9b83ef057423997 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 20 Feb 2024 10:57:54 -0800
Subject: [PATCH 01/10] Upstream ptrauth changes to DWARFASTParserClang

---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 57 +++
 1 file changed, 57 insertions(+)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 54d06b1115a229..67fe830e1aa70d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -495,6 +495,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const 
SymbolContext &sc,
   case DW_TAG_const_type:
   case DW_TAG_restrict_type:
   case DW_TAG_volatile_type:
+  case DW_TAG_LLVM_ptrauth_type:
   case DW_TAG_atomic_type:
   case DW_TAG_unspecified_type: {
 type_sp = ParseTypeModifier(sc, die, attrs);
@@ -676,6 +677,62 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext 
&sc,
   case DW_TAG_volatile_type:
 encoding_data_type = Type::eEncodingIsVolatileUID;
 break;
+  case DW_TAG_LLVM_ptrauth_type: {
+DWARFDIE ptr_die = die.GetReferencedDIE(DW_AT_type);
+// FIXME: Fully resolving the type here may affect performance.
+Type *res_type = dwarf->ResolveType(ptr_die);
+if (!res_type)
+  break;
+attrs.type.Clear();
+encoding_data_type = Type::eEncodingIsUID;
+resolve_state = Type::ResolveState::Full;
+
+// Apply the ptrauth qualifier to the resolved type.
+auto *ptr_type =
+(clang::Type *)res_type->GetForwardCompilerType().GetOpaqueQualType();
+auto getAttr = [&](llvm::dwarf::Attribute Attr, unsigned defaultValue = 0) 
{
+  return die.GetAttributeValueAsUnsigned(Attr, defaultValue);
+};
+const unsigned key = getAttr(DW_AT_LLVM_ptrauth_key);
+const bool addr_disc = getAttr(DW_AT_LLVM_ptrauth_address_discriminated);
+const unsigned extra = getAttr(DW_AT_LLVM_ptrauth_extra_discriminator);
+const bool isapointer = getAttr(DW_AT_LLVM_ptrauth_isa_pointer);
+const bool authenticates_null_values =
+getAttr(DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
+const bool is_restricted_integral = !ptr_type->isPointerType();
+const unsigned authentication_mode_int = getAttr(
+DW_AT_LLVM_ptrauth_authentication_mode,
+static_cast(clang::PointerAuthenticationMode::SignAndAuth));
+clang::PointerAuthenticationMode authentication_mode =
+clang::PointerAuthenticationMode::SignAndAuth;
+if (authentication_mode_int >=
+static_cast(clang::PointerAuthenticationMode::None) &&
+authentication_mode_int <=
+static_cast(
+clang::PointerAuthenticationMode::SignAndAuth)) {
+  authentication_mode = static_cast(
+  authentication_mode_int);
+} else {
+  dwarf->GetObjectFile()->GetModule()->ReportError(
+  "[{0:x16}]: invalid pointer authentication mode method {1:x4}",
+  die.GetOffset(), authentication_mode_int);
+}
+
+// FIXME: Use these variables when PointerAuthQualifier is more complete
+// upstream.
+(void)is_restricted_integral;
+
+clang::Qualifiers qualifiers;
+auto ptr_auth = clang::PointerAuthQualifier::Create(
+key, addr_disc, extra, authentication_mode, isapointer,
+authenticates_null_values);
+qualifiers.setPointerAuth(ptr_auth);
+auto &ctx = m_ast.getASTContext();
+auto qual_type = ctx.getQualifiedType(ptr_type, qualifiers);
+clang_type =
+CompilerType(m_ast.weak_from_this(), qual_type.getAsOpaquePtr());
+break;
+  }
   case DW_TAG_atomic_type:
 encoding_data_type = Type::eEncodingIsAtomicUID;
 break;

>From 8aa1ba0b05362b8960faac1945bb25c68ecb4b98 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Thu, 7 Mar 2024 16:34:09 +0300
Subject: [PATCH 02/10] [PAC][lldb] Use `eEncodingIsLLVMPtrAuthUID` for
 `__ptrauth`-qualified types

---
 lldb/include/lldb/Symbol/Type.h   | 4 +++-
 .../Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp  | 2 +-
 lldb/source/Symbol/Type.cpp   | 8 +++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index acd1a769f13cd6..d55280b58bc4f7 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -401,7 +401,9 @@ class Type : public std::enable_shared_from_this, 
public UserID {
 /// This type is the type whose UID is m_encoding_uid as an atomic type.
 eEncodingIsAtomicUID,
 /// This type is the synthetic type whose UID is m_encoding_uid.
-eEncodingIsSyntheticUID
+eEncodingIsSyntheticUID,
+/// This type is a signed pointer.
+eEncodingIsLLVMPtrAuthUID
   };
 
   enum class ResolveState : 

[clang] [libclang/python] export libclang version to the bindings (PR #86931)

2024-03-28 Thread via cfe-commits

https://github.com/efferre79 created 
https://github.com/llvm/llvm-project/pull/86931

it's useful to know which clang library the python byndings are running

>From 05a882b276e6e6f3c8502c9e1102d575f4c49018 Mon Sep 17 00:00:00 2001
From: efferre79 
Date: Thu, 28 Mar 2024 11:11:21 +0100
Subject: [PATCH] [libclang/python] export libclang version to the bindings

---
 clang/bindings/python/clang/cindex.py | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 302d99dccd77b5..a98fa9ee70569d 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3846,6 +3846,7 @@ def write_main_file_to_stdout(self):
 ("clang_getCanonicalCursor", [Cursor], Cursor, Cursor.from_cursor_result),
 ("clang_getCanonicalType", [Type], Type, Type.from_result),
 ("clang_getChildDiagnostics", [Diagnostic], c_object_p),
+("clang_getClangVersion", [], _CXString, _CXString.from_result),
 ("clang_getCompletionAvailability", [c_void_p], c_int),
 ("clang_getCompletionBriefComment", [c_void_p], _CXString, 
_CXString.from_result),
 ("clang_getCompletionChunkCompletionString", [c_void_p, c_int], 
c_object_p),
@@ -4178,6 +4179,9 @@ def function_exists(self, name):
 return False
 
 return True
+ 
+def get_version(self):
+return self.lib.clang_getClangVersion()
 
 
 def register_enumerations():

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


[clang] [libclang/python] export libclang version to the bindings (PR #86931)

2024-03-28 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [HLSL] prevent generation of double intrinsics. (PR #86930)

2024-03-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Andrii Levitskiy (aabysswalker)


Changes

As #86555, we should cover all of non-double builtins.

Closes #86818 

---

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


5 Files Affected:

- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (-18) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+1425-1177) 
- (modified) clang/test/CodeGenHLSL/builtins/ceil.hlsl (-13) 
- (modified) clang/test/CodeGenHLSL/builtins/floor.hlsl (-13) 
- (modified) clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl (+5-3) 


``diff
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d47eab453f8747..82e2cff2cb95c5 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -243,15 +243,6 @@ float3 ceil(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 float4 ceil(float4);
 
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double ceil(double);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double2 ceil(double2);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double3 ceil(double3);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double4 ceil(double4);
-
 
//===--===//
 // clamp builtins
 
//===--===//
@@ -585,15 +576,6 @@ float3 floor(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
 float4 floor(float4);
 
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double floor(double);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double2 floor(double2);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double3 floor(double3);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double4 floor(double4);
-
 
//===--===//
 // frac builtins
 
//===--===//
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f5c0c761da75af..c0856325633513 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -371,35 +371,37 @@ static bool SemaBuiltinOverflow(Sema &S, CallExpr 
*TheCall,
 return true;
 
   std::pair Builtins[] = {
-{ Builtin::BI__builtin_add_overflow, "ckd_add" },
-{ Builtin::BI__builtin_sub_overflow, "ckd_sub" },
-{ Builtin::BI__builtin_mul_overflow, "ckd_mul" },
+  {Builtin::BI__builtin_add_overflow, "ckd_add"},
+  {Builtin::BI__builtin_sub_overflow, "ckd_sub"},
+  {Builtin::BI__builtin_mul_overflow, "ckd_mul"},
   };
 
-  bool CkdOperation = llvm::any_of(Builtins, [&](const std::pair &P) {
-return BuiltinID == P.first && TheCall->getExprLoc().isMacroID() &&
- Lexer::getImmediateMacroName(TheCall->getExprLoc(),
- S.getSourceManager(), S.getLangOpts()) == P.second;
-  });
+  bool CkdOperation =
+  llvm::any_of(Builtins, [&](const std::pair &P) {
+return BuiltinID == P.first && TheCall->getExprLoc().isMacroID() &&
+   Lexer::getImmediateMacroName(TheCall->getExprLoc(),
+S.getSourceManager(),
+S.getLangOpts()) == P.second;
+  });
 
   auto ValidCkdIntType = [](QualType QT) {
 // A valid checked integer type is an integer type other than a plain char,
 // bool, a bit-precise type, or an enumeration type.
 if (const auto *BT = QT.getCanonicalType()->getAs())
   return (BT->getKind() >= BuiltinType::Short &&
-   BT->getKind() <= BuiltinType::Int128) || (
-   BT->getKind() >= BuiltinType::UShort &&
-   BT->getKind() <= BuiltinType::UInt128) ||
-   BT->getKind() == BuiltinType::UChar ||
-   BT->getKind() == BuiltinType::SChar;
+  BT->getKind() <= BuiltinType::Int128) ||
+ (BT->getKind() >= BuiltinType::UShort &&
+  BT->getKind() <= BuiltinType::UInt128) ||
+ BT->getKind() == BuiltinType::UChar ||
+ BT->getKind() == BuiltinType::SChar;
 return false;
   };
 
   // First two arguments should be integers.
   for (unsigned I = 0; I < 2; ++I) {
 ExprResult Arg = 
S.DefaultFunctionArrayLvalueConversion(TheCall->getArg(I));
-if (Arg.isInvalid()) return true;
+if (Arg.isInvalid())
+  return true;
 TheCall->setArg(I, Arg.get());
 
 QualType Ty = Arg.get()->getType();
@@ -416,18 +418,18 @@ static bool SemaBuiltinOverflow(Sema &S, CallExpr 
*TheCall,
   // the other qualifiers aren't possible.
   {
 ExprResult Arg = 
S.DefaultFunctionArrayLvalueConversion(TheCall->getArg(2));
-if (Arg.isInvalid()) return true;
+if (Arg.isInvalid())
+  return true;
 TheCall->setArg(2, Arg.get());
 
 QualType Ty = Arg.get()->getType();
 const auto *PtrTy = 

[clang] [libclang/python] export libclang version to the bindings (PR #86931)

2024-03-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (efferre79)


Changes

it's useful to know which clang library the python byndings are running

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


1 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+4) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 302d99dccd77b5..a98fa9ee70569d 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -3846,6 +3846,7 @@ def write_main_file_to_stdout(self):
 ("clang_getCanonicalCursor", [Cursor], Cursor, Cursor.from_cursor_result),
 ("clang_getCanonicalType", [Type], Type, Type.from_result),
 ("clang_getChildDiagnostics", [Diagnostic], c_object_p),
+("clang_getClangVersion", [], _CXString, _CXString.from_result),
 ("clang_getCompletionAvailability", [c_void_p], c_int),
 ("clang_getCompletionBriefComment", [c_void_p], _CXString, 
_CXString.from_result),
 ("clang_getCompletionChunkCompletionString", [c_void_p, c_int], 
c_object_p),
@@ -4178,6 +4179,9 @@ def function_exists(self, name):
 return False
 
 return True
+ 
+def get_version(self):
+return self.lib.clang_getClangVersion()
 
 
 def register_enumerations():

``




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


[clang] [HLSL] prevent generation of double intrinsics. (PR #86930)

2024-03-28 Thread Andrii Levitskiy via cfe-commits

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


[clang] [flang] [FLANG] allow -fopenmp= (PR #86816)

2024-03-28 Thread Tom Eccles via cfe-commits


@@ -764,6 +762,32 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // Add other compile options
   addOtherOptions(Args, CmdArgs);
 
+  // Forward flags for OpenMP. We don't do this if the current action is an
+  // device offloading action other than OpenMP.
+  if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
+   options::OPT_fno_openmp, false) &&
+  (JA.isDeviceOffloading(Action::OFK_None) ||
+   JA.isDeviceOffloading(Action::OFK_OpenMP))) {
+switch (D.getOpenMPRuntime(Args)) {
+case Driver::OMPRT_OMP:
+case Driver::OMPRT_IOMP5:
+  // Clang can generate useful OpenMP code for these two runtime libraries.
+  CmdArgs.push_back("-fopenmp");
+  Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
+
+  // FIXME: Clang supports a whole bunch more flags here.
+  break;
+default:

tblah wrote:

Clang might work differently internally. If we don't pass -fopenmp to the flang 
frontend driver, the parser will treat the openmp directives as comments. Which 
in many programs won't lead to any compilation errors but the program could 
produce different results (e.g. reductions won't happen)

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


[clang] [clang][StaticAnalyzer] Adding getentropy to CStringChecker. (PR #83675)

2024-03-28 Thread Balázs Kéri via cfe-commits


@@ -2515,6 +2517,53 @@ void CStringChecker::evalSprintfCommon(CheckerContext 
&C, const CallEvent &Call,
   C.addTransition(State);
 }
 
+void CStringChecker::evalGetentropy(CheckerContext &C, const CallEvent &Call) 
const {
+  DestinationArgExpr Buffer = {{Call.getArgExpr(0), 0}};
+  SizeArgExpr Size = {{Call.getArgExpr(1), 1}};
+  ProgramStateRef State = C.getState();
+  SValBuilder &SVB = C.getSValBuilder();
+  SVal MaxLength = SVB.makeIntVal(256, C.getASTContext().IntTy);
+
+  SVal SizeVal = C.getSVal(Size.Expression);
+  QualType SizeTy = Size.Expression->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+  assumeZero(C, State, SizeVal, SizeTy);
+
+  if (StateZeroSize) {
+StateZeroSize = State->BindExpr(Call.getOriginExpr(), 
C.getLocationContext(),
+  SVB.makeZeroVal(C.getASTContext().IntTy));
+C.addTransition(StateZeroSize);
+return;
+  }
+
+  SVal Buff = C.getSVal(Buffer.Expression);
+  State = checkNonNull(C, StateNonZeroSize, Buffer, Buff);
+  if (!State)
+return;
+
+  QualType cmpTy = C.getSValBuilder().getConditionType();
+  ProgramStateRef sizeAboveLimit, sizeNotAboveLimit;
+  std::tie(sizeAboveLimit, sizeNotAboveLimit) = State->assume(
+SVB
+   .evalBinOpNN(State, BO_GT, *SizeVal.getAs(), 
*MaxLength.getAs(), cmpTy)
+   .castAs());
+  if (sizeAboveLimit) {
+ErrorMessage Message;
+emitOutOfBoundsBug(C, sizeAboveLimit, Buffer.Expression, "must be smaller 
than or equal to 256");
+  } else {
+State = CheckBufferAccess(C, State, Buffer, Size, AccessKind::write);
+if (!State)
+  return;
+
+State = invalidateDestinationBufferBySize(C, State, Buffer.Expression,
+Buff,
+SizeVal, SizeTy);
+C.addTransition(State);

balazske wrote:

This branch separation and setting of `errno` can be done with 
`StdLibraryFunctionsChecker`. If in this checker the return value is not 
important it is enough to assume it is in the correct range. The other checker 
runs in `postCall` and can change the state further.

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


[clang] [HLSL] prevent generation of double intrinsics. (PR #86932)

2024-03-28 Thread Andrii Levitskiy via cfe-commits

https://github.com/aabysswalker created 
https://github.com/llvm/llvm-project/pull/86932

As #86555, we should cover all of non-double builtins.

Closes #86818 

>From caec748f3f0ab16b829f7765c5c2d87ed7f7b73f Mon Sep 17 00:00:00 2001
From: aabysswalker 
Date: Thu, 28 Mar 2024 12:50:25 +0200
Subject: [PATCH] Prevent generating double of ceil, exp, exp2, floor. Removed
 accompanying ceil, floor double type tests.

---
 clang/lib/Headers/hlsl/hlsl_intrinsics.h   | 18 --
 clang/lib/Sema/SemaChecking.cpp|  6 +-
 clang/test/CodeGenHLSL/builtins/ceil.hlsl  | 13 -
 clang/test/CodeGenHLSL/builtins/floor.hlsl | 13 -
 .../BuiltIns/half-float-only-errors.hlsl   |  7 ---
 5 files changed, 9 insertions(+), 48 deletions(-)

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d47eab453f8747..82e2cff2cb95c5 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -243,15 +243,6 @@ float3 ceil(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 float4 ceil(float4);
 
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double ceil(double);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double2 ceil(double2);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double3 ceil(double3);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double4 ceil(double4);
-
 
//===--===//
 // clamp builtins
 
//===--===//
@@ -585,15 +576,6 @@ float3 floor(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
 float4 floor(float4);
 
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double floor(double);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double2 floor(double2);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double3 floor(double3);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double4 floor(double4);
-
 
//===--===//
 // frac builtins
 
//===--===//
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f5c0c761da75af..2e4e18a3ebf759 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5641,12 +5641,16 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   return true;
 break;
   }
+  case Builtin::BI__builtin_elementwise_ceil:
   case Builtin::BI__builtin_elementwise_cos:
-  case Builtin::BI__builtin_elementwise_sin:
+  case Builtin::BI__builtin_elementwise_exp:
+  case Builtin::BI__builtin_elementwise_exp2:
+  case Builtin::BI__builtin_elementwise_floor:
   case Builtin::BI__builtin_elementwise_log:
   case Builtin::BI__builtin_elementwise_log2:
   case Builtin::BI__builtin_elementwise_log10:
   case Builtin::BI__builtin_elementwise_pow:
+  case Builtin::BI__builtin_elementwise_sin:
   case Builtin::BI__builtin_elementwise_sqrt:
   case Builtin::BI__builtin_elementwise_trunc: {
 if (CheckFloatOrHalfRepresentations(this, TheCall))
diff --git a/clang/test/CodeGenHLSL/builtins/ceil.hlsl 
b/clang/test/CodeGenHLSL/builtins/ceil.hlsl
index 06d0d4c2cf546d..be7725cd4d66c1 100644
--- a/clang/test/CodeGenHLSL/builtins/ceil.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/ceil.hlsl
@@ -41,16 +41,3 @@ float3 test_ceil_float3(float3 p0) { return ceil(p0); }
 // CHECK: define noundef <4 x float> @
 // CHECK: call <4 x float> @llvm.ceil.v4f32(
 float4 test_ceil_float4(float4 p0) { return ceil(p0); }
-
-// CHECK: define noundef double @
-// CHECK: call double @llvm.ceil.f64(
-double test_ceil_double(double p0) { return ceil(p0); }
-// CHECK: define noundef <2 x double> @
-// CHECK: call <2 x double> @llvm.ceil.v2f64(
-double2 test_ceil_double2(double2 p0) { return ceil(p0); }
-// CHECK: define noundef <3 x double> @
-// CHECK: call <3 x double> @llvm.ceil.v3f64(
-double3 test_ceil_double3(double3 p0) { return ceil(p0); }
-// CHECK: define noundef <4 x double> @
-// CHECK: call <4 x double> @llvm.ceil.v4f64(
-double4 test_ceil_double4(double4 p0) { return ceil(p0); }
diff --git a/clang/test/CodeGenHLSL/builtins/floor.hlsl 
b/clang/test/CodeGenHLSL/builtins/floor.hlsl
index d2a2f6e52f1ec3..07803bfae3be68 100644
--- a/clang/test/CodeGenHLSL/builtins/floor.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/floor.hlsl
@@ -41,16 +41,3 @@ float3 test_floor_float3(float3 p0) { return floor(p0); }
 // CHECK: define noundef <4 x float> @
 // CHECK: call <4 x float> @llvm.floor.v4f32(
 float4 test_floor_float4(float4 p0) { return floor(p0); }
-
-// CHECK: define noundef double @
-// CHECK: call double @llvm.floor.f64(
-double test_floor_double(double p0) { return floor(p0); }
-// CHECK: define noundef <2 x double> @
-// CHECK: call <2 x double> @llvm.floor.v2f64(
-double2 test_floor_double2(doubl

[clang] [HLSL] prevent generation of double intrinsics. (PR #86932)

2024-03-28 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-clang

Author: Andrii Levitskiy (aabysswalker)


Changes

As #86555, we should cover all of non-double builtins.

Closes #86818 

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


5 Files Affected:

- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (-18) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+5-1) 
- (modified) clang/test/CodeGenHLSL/builtins/ceil.hlsl (-13) 
- (modified) clang/test/CodeGenHLSL/builtins/floor.hlsl (-13) 
- (modified) clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl (+4-3) 


``diff
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d47eab453f8747..82e2cff2cb95c5 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -243,15 +243,6 @@ float3 ceil(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 float4 ceil(float4);
 
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double ceil(double);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double2 ceil(double2);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double3 ceil(double3);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double4 ceil(double4);
-
 
//===--===//
 // clamp builtins
 
//===--===//
@@ -585,15 +576,6 @@ float3 floor(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
 float4 floor(float4);
 
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double floor(double);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double2 floor(double2);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double3 floor(double3);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double4 floor(double4);
-
 
//===--===//
 // frac builtins
 
//===--===//
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f5c0c761da75af..2e4e18a3ebf759 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5641,12 +5641,16 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   return true;
 break;
   }
+  case Builtin::BI__builtin_elementwise_ceil:
   case Builtin::BI__builtin_elementwise_cos:
-  case Builtin::BI__builtin_elementwise_sin:
+  case Builtin::BI__builtin_elementwise_exp:
+  case Builtin::BI__builtin_elementwise_exp2:
+  case Builtin::BI__builtin_elementwise_floor:
   case Builtin::BI__builtin_elementwise_log:
   case Builtin::BI__builtin_elementwise_log2:
   case Builtin::BI__builtin_elementwise_log10:
   case Builtin::BI__builtin_elementwise_pow:
+  case Builtin::BI__builtin_elementwise_sin:
   case Builtin::BI__builtin_elementwise_sqrt:
   case Builtin::BI__builtin_elementwise_trunc: {
 if (CheckFloatOrHalfRepresentations(this, TheCall))
diff --git a/clang/test/CodeGenHLSL/builtins/ceil.hlsl 
b/clang/test/CodeGenHLSL/builtins/ceil.hlsl
index 06d0d4c2cf546d..be7725cd4d66c1 100644
--- a/clang/test/CodeGenHLSL/builtins/ceil.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/ceil.hlsl
@@ -41,16 +41,3 @@ float3 test_ceil_float3(float3 p0) { return ceil(p0); }
 // CHECK: define noundef <4 x float> @
 // CHECK: call <4 x float> @llvm.ceil.v4f32(
 float4 test_ceil_float4(float4 p0) { return ceil(p0); }
-
-// CHECK: define noundef double @
-// CHECK: call double @llvm.ceil.f64(
-double test_ceil_double(double p0) { return ceil(p0); }
-// CHECK: define noundef <2 x double> @
-// CHECK: call <2 x double> @llvm.ceil.v2f64(
-double2 test_ceil_double2(double2 p0) { return ceil(p0); }
-// CHECK: define noundef <3 x double> @
-// CHECK: call <3 x double> @llvm.ceil.v3f64(
-double3 test_ceil_double3(double3 p0) { return ceil(p0); }
-// CHECK: define noundef <4 x double> @
-// CHECK: call <4 x double> @llvm.ceil.v4f64(
-double4 test_ceil_double4(double4 p0) { return ceil(p0); }
diff --git a/clang/test/CodeGenHLSL/builtins/floor.hlsl 
b/clang/test/CodeGenHLSL/builtins/floor.hlsl
index d2a2f6e52f1ec3..07803bfae3be68 100644
--- a/clang/test/CodeGenHLSL/builtins/floor.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/floor.hlsl
@@ -41,16 +41,3 @@ float3 test_floor_float3(float3 p0) { return floor(p0); }
 // CHECK: define noundef <4 x float> @
 // CHECK: call <4 x float> @llvm.floor.v4f32(
 float4 test_floor_float4(float4 p0) { return floor(p0); }
-
-// CHECK: define noundef double @
-// CHECK: call double @llvm.floor.f64(
-double test_floor_double(double p0) { return floor(p0); }
-// CHECK: define noundef <2 x double> @
-// CHECK: call <2 x double> @llvm.floor.v2f64(
-double2 test_floor_double2(double2 p0) { return floor(p0); }
-// CHECK: define noundef <3 x double> @
-// CHECK: call <3 x double> @llvm.floor.v3f64(
-double3 test_floor_double3(double3 p0) { return floor(p0); }

[clang] [clang][analyzer] Change modeling of `fseek` in StreamChecker. (PR #86919)

2024-03-28 Thread Ben Shi via cfe-commits

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

LGTM

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


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

2024-03-28 Thread Dinar Temirbulatov via cfe-commits


@@ -1390,6 +1390,9 @@ def MultiGPU: DiagGroup<"multi-gpu">;
 // libc and the CRT to be skipped.
 def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">;
 
+// A warning group AArch64 related to SME function attribues.

dtemirbulatov wrote:

Done.

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


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

2024-03-28 Thread Dinar Temirbulatov via cfe-commits


@@ -3717,6 +3717,16 @@ def err_sme_definition_using_za_in_non_sme_target : 
Error<
   "function using ZA state requires 'sme'">;
 def err_sme_definition_using_zt0_in_non_sme2_target : Error<
   "function using ZT0 state requires 'sme2'">;
+def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning<
+  "passing a VL-dependent argument to/from a function that has a different"
+  " streaming-mode. The streaming and non-streaming vector lengths may be"
+  " different">,
+  InGroup, DefaultIgnore;
+def warn_sme_locally_streaming_has_vl_args_returns : Warning<
+  "passing/returning a VL-dependent argument from a __arm_locally_streaming"

dtemirbulatov wrote:

Done.

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


[clang-tools-extra] [clangd][trace] Fix comment to mention that trace spans are measured … (PR #86938)

2024-03-28 Thread via cfe-commits

https://github.com/VitaNuo created 
https://github.com/llvm/llvm-project/pull/86938

…in milliseconds rather than seconds.

>From a30c86bf1769b4c5603ec49022e24c6fcf88f199 Mon Sep 17 00:00:00 2001
From: Viktoriia Bakalova 
Date: Thu, 28 Mar 2024 11:38:38 +
Subject: [PATCH] [clangd][trace] Fix comment to mention that trace spans are
 measured in milliseconds rather than seconds.

---
 clang-tools-extra/clangd/support/Trace.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/support/Trace.h 
b/clang-tools-extra/clangd/support/Trace.h
index 1bfc75b874d8a9..36c3745a41e969 100644
--- a/clang-tools-extra/clangd/support/Trace.h
+++ b/clang-tools-extra/clangd/support/Trace.h
@@ -143,8 +143,8 @@ bool enabled();
 class Span {
 public:
   Span(llvm::Twine Name);
-  /// Records span's duration in seconds to \p LatencyMetric with \p Name as 
the
-  /// label.
+  /// Records span's duration in milliseconds to \p LatencyMetric with \p Name
+  /// as the label.
   Span(llvm::Twine Name, const Metric &LatencyMetric);
   ~Span();
 

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


[clang-tools-extra] [clangd][trace] Fix comment to mention that trace spans are measured … (PR #86938)

2024-03-28 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clangd

Author: None (VitaNuo)


Changes

…in milliseconds rather than seconds.

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


1 Files Affected:

- (modified) clang-tools-extra/clangd/support/Trace.h (+2-2) 


``diff
diff --git a/clang-tools-extra/clangd/support/Trace.h 
b/clang-tools-extra/clangd/support/Trace.h
index 1bfc75b874d8a9..36c3745a41e969 100644
--- a/clang-tools-extra/clangd/support/Trace.h
+++ b/clang-tools-extra/clangd/support/Trace.h
@@ -143,8 +143,8 @@ bool enabled();
 class Span {
 public:
   Span(llvm::Twine Name);
-  /// Records span's duration in seconds to \p LatencyMetric with \p Name as 
the
-  /// label.
+  /// Records span's duration in milliseconds to \p LatencyMetric with \p Name
+  /// as the label.
   Span(llvm::Twine Name, const Metric &LatencyMetric);
   ~Span();
 

``




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


[clang] [AST] Print the "aggregate" for aggregate deduction guide decl. (PR #84018)

2024-03-28 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/84018

>From 63e1f39e9580f4b33fcd86572aea70bf46edb264 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Tue, 5 Mar 2024 14:50:23 +0100
Subject: [PATCH 1/2] [AST] Print the "aggregate" kind for aggregate deduction
 guide decl.

I found this is useful for debugging purpose to identify different kind of 
deduction guide decl.
---
 clang/include/clang/AST/TextNodeDumper.h|  1 +
 clang/lib/AST/TextNodeDumper.cpp| 12 
 clang/test/SemaTemplate/deduction-guide.cpp |  9 +
 3 files changed, 22 insertions(+)

diff --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index de67f0b5714846..efb5bfe7f83d40 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -352,6 +352,7 @@ class TextNodeDumper
   void VisitEnumConstantDecl(const EnumConstantDecl *D);
   void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
   void VisitFunctionDecl(const FunctionDecl *D);
+  void VisitCXXDeductionGuideDecl(const CXXDeductionGuideDecl *D);
   void VisitFieldDecl(const FieldDecl *D);
   void VisitVarDecl(const VarDecl *D);
   void VisitBindingDecl(const BindingDecl *D);
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index b683eb1edd8f13..347a1ede3d1123 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1990,6 +1990,18 @@ void TextNodeDumper::VisitFunctionDecl(const 
FunctionDecl *D) {
   }
 }
 
+void TextNodeDumper::VisitCXXDeductionGuideDecl(const CXXDeductionGuideDecl 
*D) {
+  VisitFunctionDecl(D);
+  switch (D->getDeductionCandidateKind()) {
+  case DeductionCandidate::Normal:
+  case DeductionCandidate::Copy:
+return;
+  case DeductionCandidate::Aggregate:
+OS << " aggregate ";
+break;
+  }
+}
+
 void TextNodeDumper::VisitLifetimeExtendedTemporaryDecl(
 const LifetimeExtendedTemporaryDecl *D) {
   OS << " extended by ";
diff --git a/clang/test/SemaTemplate/deduction-guide.cpp 
b/clang/test/SemaTemplate/deduction-guide.cpp
index 16c7083df29d0c..0caef78fedbfd9 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -239,3 +239,12 @@ F s(0);
 // CHECK: |-InjectedClassNameType {{.*}} 'F<>' dependent
 // CHECK: | `-CXXRecord {{.*}} 'F'
 // CHECK: `-TemplateTypeParmType {{.*}} 'type-parameter-0-1' dependent depth 0 
index 1
+
+template
+struct G { T t; };
+
+G g = {1};
+// CHECK-LABEL: Dumping :
+// CHECK: FunctionTemplateDecl
+// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (T) -> G' aggregate
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  
'auto (int) -> G' implicit_instantiation aggregate

>From 7e6f1759735888dafce2c2b8ddba0b732700e4c8 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Thu, 28 Mar 2024 12:55:38 +0100
Subject: [PATCH 2/2] Fix format.

---
 clang/lib/AST/TextNodeDumper.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 347a1ede3d1123..413e452146bdb2 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1990,7 +1990,8 @@ void TextNodeDumper::VisitFunctionDecl(const FunctionDecl 
*D) {
   }
 }
 
-void TextNodeDumper::VisitCXXDeductionGuideDecl(const CXXDeductionGuideDecl 
*D) {
+void TextNodeDumper::VisitCXXDeductionGuideDecl(
+const CXXDeductionGuideDecl *D) {
   VisitFunctionDecl(D);
   switch (D->getDeductionCandidateKind()) {
   case DeductionCandidate::Normal:

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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-28 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot updated 
https://github.com/llvm/llvm-project/pull/77732

>From 3c5fcb03ee7871a93d3163beb51133c836f58ca6 Mon Sep 17 00:00:00 2001
From: Kishan Parmar 
Date: Thu, 28 Mar 2024 17:26:48 +0530
Subject: [PATCH] [clang][PowerPC] Add flag to enable compatibility with GNU
 for complex arguments

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

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for 
PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.
---
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   6 +
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/CodeGen/Targets/PPC.cpp |  94 -
 clang/lib/Driver/ToolChains/Clang.cpp |   9 +
 clang/lib/Frontend/CompilerInvocation.cpp |   8 +
 .../CodeGen/PowerPC/ppc32-complex-gnu-abi.c   | 394 ++
 .../ppc32-complex-soft-float-gnu-abi.c| 350 
 8 files changed, 861 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c
 create mode 100644 
clang/test/CodeGen/PowerPC/ppc32-complex-soft-float-gnu-abi.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 340b08dd7e2a33..f4845e9e424c67 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -225,6 +225,8 @@ CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code 
coverage criteria.
 
   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
+  /// If -fcomplex-ppc-gnu-abi is specified on ppc32.
+ENUM_CODEGENOPT(ComplexInRegABI, ComplexArgumentConventionKind, 2, 
CMPLX_OnStack)
 
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 9469a424045bb0..1c9424f65623dd 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -78,6 +78,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
 SRCK_InRegs// Small structs in registers (-freg-struct-return).
   };
 
+  enum ComplexArgumentConventionKind {
+CMPLX_OnStack,
+CMPLX_InGPR, // If -fcomplex-ppc-gnu-abi is specified on ppc32
+CMPLX_InFPR
+  };
+
   enum ProfileInstrKind {
 ProfileNone,   // Profile instrumentation is turned off.
 ProfileClangInstr, // Clang instrumentation to generate execution counts
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 29066ea14280c2..4a5cfc988b8c18 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2577,6 +2577,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, 
Group,
   HelpText<"Form fused FP ops (e.g. FMAs)">,
   Values<"fast,on,off,fast-honor-pragmas">;
 
+def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, 
Group, Visibility<[ClangOption, CC1Option]>,
+  DocBrief<"Follow the GNU ABI, pass Complex values in GPRs instead of the 
stack for PowerPC-32">,
+  HelpText<"Pass Complex values in GPR instead of stack for PowerPC-32">;
+
 defm strict_float_cast_overflow : BoolFOption<"strict-float-cast-overflow",
   CodeGenOpts<"StrictFloatCastOverflow">, DefaultTrue,
   NegFlaghttps://reviews.llvm.org/D146942 and the related LLVM pull
+  // request: #77732
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+RegsNeeded = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+RegsNeeded = TypeSize >> 5;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int &ArgGPRsLeft) const {
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  if (!(getCodeGenOpts().getComplexInRegABI() == CodeGenOptions::CMPLX_InGPR) 
||
+  !ArgGPRsLeft)
+return DefaultABIInfo::classifyArgumentType(Ty);
+
+  assert(ArgGPRsLeft >= 0 && "Arg GPR must be large or equal than zero");
+  ASTContext &Context = getContext();
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (Ty->isAnyComplexType()) {
+// If gr is even set gr = gr + 1 for TypeSize=64.
+if (TypeSize == 64 && ArgGPRsLeft % 2 == 1)
+  --ArgGPRsLeft;
+
+if (TypeSize <= RegLen * ArgGPRsLeft) {
+  ArgGPRsLeft -= TypeSize / RegLen;
+  return handleComplex(TypeSize);
+}
+  }
+
+  // Records with non-trivial destructors/copy-constructors should not be
+  // passed by value.
+  if (isAggregateTypeForA

[clang] fb8cccf - [AST] Print the "aggregate" for aggregate deduction guide decl. (#84018)

2024-03-28 Thread via cfe-commits

Author: Haojian Wu
Date: 2024-03-28T13:07:58+01:00
New Revision: fb8cccf88c5d04f36148ff336b6dc7c25746b1de

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

LOG: [AST] Print the "aggregate" for aggregate deduction guide decl. (#84018)

I found this is useful for debugging purpose to identify different kind
of deduction guide decl.

Added: 


Modified: 
clang/include/clang/AST/TextNodeDumper.h
clang/lib/AST/TextNodeDumper.cpp
clang/test/SemaTemplate/deduction-guide.cpp

Removed: 




diff  --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index de67f0b5714846..efb5bfe7f83d40 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -352,6 +352,7 @@ class TextNodeDumper
   void VisitEnumConstantDecl(const EnumConstantDecl *D);
   void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
   void VisitFunctionDecl(const FunctionDecl *D);
+  void VisitCXXDeductionGuideDecl(const CXXDeductionGuideDecl *D);
   void VisitFieldDecl(const FieldDecl *D);
   void VisitVarDecl(const VarDecl *D);
   void VisitBindingDecl(const BindingDecl *D);

diff  --git a/clang/lib/AST/TextNodeDumper.cpp 
b/clang/lib/AST/TextNodeDumper.cpp
index b683eb1edd8f13..413e452146bdb2 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1990,6 +1990,19 @@ void TextNodeDumper::VisitFunctionDecl(const 
FunctionDecl *D) {
   }
 }
 
+void TextNodeDumper::VisitCXXDeductionGuideDecl(
+const CXXDeductionGuideDecl *D) {
+  VisitFunctionDecl(D);
+  switch (D->getDeductionCandidateKind()) {
+  case DeductionCandidate::Normal:
+  case DeductionCandidate::Copy:
+return;
+  case DeductionCandidate::Aggregate:
+OS << " aggregate ";
+break;
+  }
+}
+
 void TextNodeDumper::VisitLifetimeExtendedTemporaryDecl(
 const LifetimeExtendedTemporaryDecl *D) {
   OS << " extended by ";

diff  --git a/clang/test/SemaTemplate/deduction-guide.cpp 
b/clang/test/SemaTemplate/deduction-guide.cpp
index 16c7083df29d0c..0caef78fedbfd9 100644
--- a/clang/test/SemaTemplate/deduction-guide.cpp
+++ b/clang/test/SemaTemplate/deduction-guide.cpp
@@ -239,3 +239,12 @@ F s(0);
 // CHECK: |-InjectedClassNameType {{.*}} 'F<>' dependent
 // CHECK: | `-CXXRecord {{.*}} 'F'
 // CHECK: `-TemplateTypeParmType {{.*}} 'type-parameter-0-1' dependent depth 0 
index 1
+
+template
+struct G { T t; };
+
+G g = {1};
+// CHECK-LABEL: Dumping :
+// CHECK: FunctionTemplateDecl
+// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (T) -> G' aggregate
+// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  
'auto (int) -> G' implicit_instantiation aggregate



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


[clang] [AST] Print the "aggregate" for aggregate deduction guide decl. (PR #84018)

2024-03-28 Thread Haojian Wu via cfe-commits

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


[clang] [RFC][Clang] Enable custom type checking for printf (PR #86801)

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

https://github.com/AaronBallman commented:

I'm not keen on reimplementing the checking logic manually; I worry this is 
going to be a slippery slope where we start with `printf` today, but then need 
to do the same thing for the rest of the family at some point in the future.

Would it make sense for us to define a `LibBuiltin` specific to OpenCL 
languages to expose a different signature for OpenCL? And change 
`BuiltinPrintf` from `Builtin` to `LangBuiltin` to do similar for the builtin 
form?

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


[clang] a042fcb - [clang] Bailout when the substitution of template parameter mapping is invalid. (#86869)

2024-03-28 Thread via cfe-commits

Author: Haojian Wu
Date: 2024-03-28T13:10:02+01:00
New Revision: a042fcbe45d1ae64acc5d818db90e26e16e1aab3

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

LOG: [clang] Bailout when the substitution of template parameter mapping is 
invalid. (#86869)

Fixes #86757

We missed to handle the invalid case when substituting into the
parameter mapping of an constraint during normalization.
The constructor of `InstantiatingTemplate` will bail out (no
`CodeSynthesisContext` will be added to the instantiation stack) if
there was a fatal error, consequently we should stop doing any further
template instantiations.

Added: 
clang/test/SemaTemplate/concepts-GH86757.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaConcept.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ccc399d36dbb54..232de0d7d8bb73 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -458,6 +458,7 @@ Bug Fixes to C++ Support
 - Fix an issue where a namespace alias could be defined using a qualified name 
(all name components
   following the first `::` were ignored).
 - Fix an out-of-bounds crash when checking the validity of template partial 
specializations. (part of #GH86757).
+- Fix an issue caused by not handling invalid cases when substituting into the 
parameter mapping of a constraint. Fixes (#GH86757).
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index b6c4d3d540ef50..a2d8ba9a96d7a4 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1281,6 +1281,8 @@ substituteParameterMappings(Sema &S, NormalizedConstraint 
&N,
   S, InstLocBegin,
   Sema::InstantiatingTemplate::ParameterMappingSubstitution{}, Concept,
   {InstLocBegin, InstLocEnd});
+  if (Inst.isInvalid())
+return true;
   if (S.SubstTemplateArguments(*Atomic.ParameterMapping, MLTAL, SubstArgs))
 return true;
 

diff  --git a/clang/test/SemaTemplate/concepts-GH86757.cpp 
b/clang/test/SemaTemplate/concepts-GH86757.cpp
new file mode 100644
index 00..3122381b20359e
--- /dev/null
+++ b/clang/test/SemaTemplate/concepts-GH86757.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++20 -Wfatal-errors -verify %s
+
+template  int a;
+template  concept c = a;
+template  concept e = c<>;
+
+// must be a fatal error to trigger the crash
+undefined; // expected-error {{a type specifier is required for all 
declarations}}
+
+template  concept g = e;
+template  struct h
+template 
+struct h;



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


[clang] [clang] Bailout when the substitution of template parameter mapping is invalid. (PR #86869)

2024-03-28 Thread Haojian Wu via cfe-commits

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


[clang] [clang] Bailout when the substitution of template parameter mapping is invalid. (PR #86869)

2024-03-28 Thread Haojian Wu via cfe-commits

hokein wrote:

> LGTM, interesting it looks like we don't do this check in fromContraintExpr 
> either.

Yes, I think it is an oversight, we should do the check for it as well.

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


[clang-tools-extra] [clangd][trace] Fix comment to mention that trace spans are measured … (PR #86938)

2024-03-28 Thread kadir çetinkaya via cfe-commits

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


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


[clang] [clang][dataflow] Fix for value constructor in class derived from optional. (PR #86942)

2024-03-28 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/86942

The constructor `Derived(int)` in the newly added test
`ClassDerivedFromOptionalValueConstructor` is not a template, and this used to
cause an assertion failure in `valueOrConversionHasValue()` because
`F.getTemplateSpecializationArgs()` returns null.

(This is modeled after the `MaybeAlign(Align Value)` constructor, which
similarly causes an assertion failure in the analysis when assigning an `Align`
to a `MaybeAlign`.)

To fix this, we can simply look at the type of the destination type which we're
constructing or assigning to (instead of the function template argument), and
this not only fixes this specific case but actually simplifies the
implementation.

I've added some additional tests for the case of assigning to a nested optional
because we didn't have coverage for these and I wanted to make sure I didn't
break anything.


>From 28e942051cea2bd8a0df6b9b26596f60ea53fe96 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Thu, 28 Mar 2024 12:20:08 +
Subject: [PATCH] [clang][dataflow] Fix for value constructor in class derived
 from optional.

The constructor `Derived(int)` in the newly added test
`ClassDerivedFromOptionalValueConstructor` is not a template, and this used to
cause an assertion failure in `valueOrConversionHasValue()` because
`F.getTemplateSpecializationArgs()` returns null.

(This is modeled after the `MaybeAlign(Align Value)` constructor, which
similarly causes an assertion failure in the analysis when assigning an `Align`
to a `MaybeAlign`.)

To fix this, we can simply look at the type of the destination type which we're
constructing or assigning to (instead of the function template argument), and
this not only fixes this specific case but actually simplifies the
implementation.

I've added some additional tests for the case of assigning to a nested optional
because we didn't have coverage for these and I wanted to make sure I didn't
break anything.
---
 .../Models/UncheckedOptionalAccessModel.cpp   | 45 ++--
 .../UncheckedOptionalAccessModelTest.cpp  | 69 +++
 2 files changed, 92 insertions(+), 22 deletions(-)

diff --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index dbf4878622eba9..cadb1ceb2d8507 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -512,27 +512,26 @@ void constructOptionalValue(const Expr &E, Environment 
&Env,
 /// Returns a symbolic value for the "has_value" property of an `optional`
 /// value that is constructed/assigned from a value of type `U` or 
`optional`
 /// where `T` is constructible from `U`.
-BoolValue &valueOrConversionHasValue(const FunctionDecl &F, const Expr &E,
+BoolValue &valueOrConversionHasValue(QualType DestType, const Expr &E,
  const MatchFinder::MatchResult &MatchRes,
  LatticeTransferState &State) {
-  assert(F.getTemplateSpecializationArgs() != nullptr);
-  assert(F.getTemplateSpecializationArgs()->size() > 0);
-
-  const int TemplateParamOptionalWrappersCount =
-  countOptionalWrappers(*MatchRes.Context, 
F.getTemplateSpecializationArgs()
-   ->get(0)
-   .getAsType()
-   .getNonReferenceType());
+  const int DestTypeOptionalWrappersCount =
+  countOptionalWrappers(*MatchRes.Context, DestType);
   const int ArgTypeOptionalWrappersCount = countOptionalWrappers(
   *MatchRes.Context, E.getType().getNonReferenceType());
 
-  // Check if this is a constructor/assignment call for `optional` with
-  // argument of type `U` such that `T` is constructible from `U`.
-  if (TemplateParamOptionalWrappersCount == ArgTypeOptionalWrappersCount)
+  // Is this an constructor of the form `template optional(U &&)` /
+  // assignment of the form `template optional& operator=(U &&)`
+  // (where `T` is assignable / constructible from `U`)?
+  // We recognize this because the number of optionals in the optional being
+  // assigned to is different from the function argument type.
+  if (DestTypeOptionalWrappersCount != ArgTypeOptionalWrappersCount)
 return State.Env.getBoolLiteralValue(true);
 
-  // This is a constructor/assignment call for `optional` with argument of
-  // type `optional` such that `T` is constructible from `U`.
+  // Otherwise, this must be a constructor of the form
+  // `template  optional &&)` / assignment of the form
+  // `template  optional& operator=(optional &&)
+  // (where, again, `T` is assignable / constructible from `U`).
   auto *Loc = State.Env.get(E);
   if (auto *HasValueVal = getHasValue(State.Env, Loc))
 return *HasValueVal;
@@ -544,10 +543,1

[clang] [clang][dataflow] Fix for value constructor in class derived from optional. (PR #86942)

2024-03-28 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-analysis

Author: None (martinboehme)


Changes

The constructor `Derived(int)` in the newly added test
`ClassDerivedFromOptionalValueConstructor` is not a template, and this used to
cause an assertion failure in `valueOrConversionHasValue()` because
`F.getTemplateSpecializationArgs()` returns null.

(This is modeled after the `MaybeAlign(Align Value)` constructor, which
similarly causes an assertion failure in the analysis when assigning an `Align`
to a `MaybeAlign`.)

To fix this, we can simply look at the type of the destination type which we're
constructing or assigning to (instead of the function template argument), and
this not only fixes this specific case but actually simplifies the
implementation.

I've added some additional tests for the case of assigning to a nested optional
because we didn't have coverage for these and I wanted to make sure I didn't
break anything.


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


2 Files Affected:

- (modified) 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
(+23-22) 
- (modified) 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp 
(+69) 


``diff
diff --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index dbf4878622eba9..cadb1ceb2d8507 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -512,27 +512,26 @@ void constructOptionalValue(const Expr &E, Environment 
&Env,
 /// Returns a symbolic value for the "has_value" property of an `optional`
 /// value that is constructed/assigned from a value of type `U` or 
`optional`
 /// where `T` is constructible from `U`.
-BoolValue &valueOrConversionHasValue(const FunctionDecl &F, const Expr &E,
+BoolValue &valueOrConversionHasValue(QualType DestType, const Expr &E,
  const MatchFinder::MatchResult &MatchRes,
  LatticeTransferState &State) {
-  assert(F.getTemplateSpecializationArgs() != nullptr);
-  assert(F.getTemplateSpecializationArgs()->size() > 0);
-
-  const int TemplateParamOptionalWrappersCount =
-  countOptionalWrappers(*MatchRes.Context, 
F.getTemplateSpecializationArgs()
-   ->get(0)
-   .getAsType()
-   .getNonReferenceType());
+  const int DestTypeOptionalWrappersCount =
+  countOptionalWrappers(*MatchRes.Context, DestType);
   const int ArgTypeOptionalWrappersCount = countOptionalWrappers(
   *MatchRes.Context, E.getType().getNonReferenceType());
 
-  // Check if this is a constructor/assignment call for `optional` with
-  // argument of type `U` such that `T` is constructible from `U`.
-  if (TemplateParamOptionalWrappersCount == ArgTypeOptionalWrappersCount)
+  // Is this an constructor of the form `template optional(U &&)` /
+  // assignment of the form `template optional& operator=(U &&)`
+  // (where `T` is assignable / constructible from `U`)?
+  // We recognize this because the number of optionals in the optional being
+  // assigned to is different from the function argument type.
+  if (DestTypeOptionalWrappersCount != ArgTypeOptionalWrappersCount)
 return State.Env.getBoolLiteralValue(true);
 
-  // This is a constructor/assignment call for `optional` with argument of
-  // type `optional` such that `T` is constructible from `U`.
+  // Otherwise, this must be a constructor of the form
+  // `template  optional &&)` / assignment of the form
+  // `template  optional& operator=(optional &&)
+  // (where, again, `T` is assignable / constructible from `U`).
   auto *Loc = State.Env.get(E);
   if (auto *HasValueVal = getHasValue(State.Env, Loc))
 return *HasValueVal;
@@ -544,10 +543,11 @@ void transferValueOrConversionConstructor(
 LatticeTransferState &State) {
   assert(E->getNumArgs() > 0);
 
-  constructOptionalValue(*E, State.Env,
- valueOrConversionHasValue(*E->getConstructor(),
-   *E->getArg(0), MatchRes,
-   State));
+  constructOptionalValue(
+  *E, State.Env,
+  valueOrConversionHasValue(
+  E->getConstructor()->getThisType()->getPointeeType(), *E->getArg(0),
+  MatchRes, State));
 }
 
 void transferAssignment(const CXXOperatorCallExpr *E, BoolValue &HasValueVal,
@@ -566,10 +566,11 @@ void transferValueOrConversionAssignment(
 const CXXOperatorCallExpr *E, const MatchFinder::MatchResult &MatchRes,
 LatticeTransferState &State) {
   assert(E->getNumArgs() > 1);
-  transferAssignment(E,
- valueOrConversionHasValu

[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-28 Thread Sameer Sahasrabuddhe via cfe-commits
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= 
Message-ID:
In-Reply-To: 


https://github.com/ssahasra commented:

LGTM, with a few nits.

For the record, I did not have the bandwidth to comment on the translation from 
HLSL to SPIR-V. But given that the generated IR passes the verifier, this seems 
like a correct and very interesting first use of convergence control.

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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-28 Thread Sameer Sahasrabuddhe via cfe-commits
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= 
Message-ID:
In-Reply-To: 



@@ -1130,8 +1130,92 @@ struct BitTest {
 
   static BitTest decodeBitTestBuiltin(unsigned BuiltinID);
 };
+
+// Returns the first convergence entry/loop/anchor instruction found in |BB|.
+// std::nullptr otherwise.
+llvm::IntrinsicInst *getConvergenceToken(llvm::BasicBlock *BB) {
+  for (auto &I : *BB) {
+auto *II = dyn_cast(&I);
+if (II && isConvergenceControlIntrinsic(II->getIntrinsicID()))
+  return II;
+  }
+  return nullptr;
+}
+
 } // namespace
 
+llvm::CallBase *
+CodeGenFunction::AddConvergenceControlAttr(llvm::CallBase *Input,

ssahasra wrote:

In this and other places, "ConvergenceControlToken" is a better name than 
"Attr" ... it's not really an attribute.

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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-28 Thread Sameer Sahasrabuddhe via cfe-commits
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= 
Message-ID:
In-Reply-To: 



@@ -1130,8 +1130,92 @@ struct BitTest {
 
   static BitTest decodeBitTestBuiltin(unsigned BuiltinID);
 };
+
+// Returns the first convergence entry/loop/anchor instruction found in |BB|.
+// std::nullptr otherwise.
+llvm::IntrinsicInst *getConvergenceToken(llvm::BasicBlock *BB) {
+  for (auto &I : *BB) {
+auto *II = dyn_cast(&I);
+if (II && isConvergenceControlIntrinsic(II->getIntrinsicID()))
+  return II;
+  }
+  return nullptr;
+}
+
 } // namespace
 
+llvm::CallBase *
+CodeGenFunction::AddConvergenceControlAttr(llvm::CallBase *Input,

ssahasra wrote:

Also function names need to start with lower case.

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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-28 Thread Sameer Sahasrabuddhe via cfe-commits
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= 
Message-ID:
In-Reply-To: 



@@ -1130,8 +1130,92 @@ struct BitTest {
 
   static BitTest decodeBitTestBuiltin(unsigned BuiltinID);
 };
+
+// Returns the first convergence entry/loop/anchor instruction found in |BB|.
+// std::nullptr otherwise.
+llvm::IntrinsicInst *getConvergenceToken(llvm::BasicBlock *BB) {
+  for (auto &I : *BB) {
+auto *II = dyn_cast(&I);
+if (II && isConvergenceControlIntrinsic(II->getIntrinsicID()))
+  return II;
+  }
+  return nullptr;
+}
+
 } // namespace
 
+llvm::CallBase *
+CodeGenFunction::AddConvergenceControlAttr(llvm::CallBase *Input,
+   llvm::Value *ParentToken) {
+  llvm::Value *bundleArgs[] = {ParentToken};
+  llvm::OperandBundleDef OB("convergencectrl", bundleArgs);
+  auto Output = llvm::CallBase::addOperandBundle(
+  Input, llvm::LLVMContext::OB_convergencectrl, OB, Input);
+  Input->replaceAllUsesWith(Output);
+  Input->eraseFromParent();
+  return Output;
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::EmitConvergenceLoop(llvm::BasicBlock *BB,

ssahasra wrote:

Other places use "LoopToken". Ending with "Token" certainly feels more 
consistent.

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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-28 Thread Sameer Sahasrabuddhe via cfe-commits
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= 
Message-ID:
In-Reply-To: 


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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-28 Thread Sameer Sahasrabuddhe via cfe-commits
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= ,
Nathan =?utf-8?q?Gau=C3=ABr?= 
Message-ID:
In-Reply-To: 


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


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


[clang] [clang] Add invalid check in NormalizedConstraint::fromConstraintExpr. (PR #86943)

2024-03-28 Thread Haojian Wu via cfe-commits

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/86943

This is an oversight spot in #86869, we should always check the invalid bit 
after constructing the `Sema::InstantiatingTemplate` RAII object.

>From cb863750a7c57e76bbb8d63cc88975f5adaa65aa Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Thu, 28 Mar 2024 13:23:51 +0100
Subject: [PATCH] [clang] Add invalid check in
 NormalizedConstraint::fromConstraintExpr.

This is an oversight spot in #86869, we should always check the invalid bit 
after
constructing the `Sema::InstantiatingTemplate` RAII object.
---
 clang/lib/Sema/SemaConcept.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index a2d8ba9a96d7a4..61979816bf4e3c 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1356,6 +1356,8 @@ NormalizedConstraint::fromConstraintExpr(Sema &S, 
NamedDecl *D, const Expr *E) {
   S, CSE->getExprLoc(),
   Sema::InstantiatingTemplate::ConstraintNormalization{}, D,
   CSE->getSourceRange());
+  if (Inst.isInvalid())
+return std::nullptr;
   // C++ [temp.constr.normal]p1.1
   // [...]
   // The normal form of an id-expression of the form C,

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


[clang] [clang] Add invalid check in NormalizedConstraint::fromConstraintExpr. (PR #86943)

2024-03-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

This is an oversight spot in #86869, we should always check the invalid 
bit after constructing the `Sema::InstantiatingTemplate` RAII object.

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaConcept.cpp (+2) 


``diff
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index a2d8ba9a96d7a4..61979816bf4e3c 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1356,6 +1356,8 @@ NormalizedConstraint::fromConstraintExpr(Sema &S, 
NamedDecl *D, const Expr *E) {
   S, CSE->getExprLoc(),
   Sema::InstantiatingTemplate::ConstraintNormalization{}, D,
   CSE->getSourceRange());
+  if (Inst.isInvalid())
+return std::nullptr;
   // C++ [temp.constr.normal]p1.1
   // [...]
   // The normal form of an id-expression of the form C,

``




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


[clang] [libclc] [llvm] [openmp] [Clang] `__attribute__((assume))` refactor (PR #84934)

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

https://github.com/AaronBallman commented:

Thank you for working on this, it's definitely a complicated situation!

> However, libclc appears to be using __attribute__((assume)) internally, 
> specifically, in one header that defines a macro that is then used throughout 
> the codebase. I’m not familiar with libclc or OpenCL, so I’ve added 
> omp_assume as an alternative spelling for the OpenMP attribute and replaced 
> the attribute in the header in question with __attribute__((__omp_assume__)).

Added @AnastasiaStulova for help with the OpenCL questions. I would love to 
avoid adding `omp_assume` if possible.

> It should be noted that, without the omp_assume spelling, it would be 
> impossible to use this attribute in C without running into -pedantic 
> warnings; we could consider supporting [[omp::assume]] in C23, though.

My guess is that the OpenMP folks haven't gotten around to rebasing on top of 
C23 yet and that's really the only thing holding back supporting `[[]]` 
spellings in C with OpenMP. @alexey-bataev, should we enable OpenMP attribute 
spellings whenever double square bracket attributes are enabled?

> From what I can tell, no-one except libclc is actually using this attribute? 
> At least on github, the only matches I’ve found for 
> __attribute__((assume("omp are in LLVM and various forks thereof. Given that 
> it’s not particularly widely used, I don’t think removal without deprecation 
> would be that big of a deal in this case, though if you think that that’s a 
> non-option, then I’d instead suggest deprecating it and removing it in a 
> later version of Clang.

This matches my searching around on 
https://sourcegraph.com/search?q=context:global+__attribute__%28%28assume%28%22omp+-file:.*test.*+-file:.*llvm.*+-file:.*%5C.rst&patternType=keyword&sm=0
 so I think removal without deprecation may be reasonable unless @alexey-bataev 
knows of something we're missing.

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


[clang] 4ddd4ed - [AIX][TOC] -mtocdata/-mno-tocdata fix non deterministic iteration order (#86840)

2024-03-28 Thread via cfe-commits

Author: Zaara Syeda
Date: 2024-03-28T08:37:25-04:00
New Revision: 4ddd4ed7fe15a356dace649e18492dd01071f475

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

LOG: [AIX][TOC] -mtocdata/-mno-tocdata fix non deterministic iteration order 
(#86840)

Failure with testcase toc-conf.c observed when building with
LLVM_REVERSE_ITERATION=ON.
Changing from using llvm::StringSet to std::set to
ensure iteration order is deterministic. Note: the functionality of the
feature does not require a specific iteration order, however, this will
allow testing to be consistent.
>From llvm docs:
The advantages of std::set are that its iterators are stable (deleting
or inserting an element from the set does not affect iterators or
pointers to other elements) and that iteration over the set is
guaranteed to be in sorted order.

Added: 


Modified: 
clang/lib/Driver/ToolChains/AIX.cpp
clang/test/Driver/toc-conf.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index 6e089903a3158a..7a62b0f9aec419 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -471,7 +471,7 @@ static void addTocDataOptions(const llvm::opt::ArgList 
&Args,
   // the global setting of tocdata in TOCDataGloballyinEffect.
   // Those that have the opposite setting to TOCDataGloballyinEffect, are added
   // to ExplicitlySpecifiedGlobals.
-  llvm::StringSet<> ExplicitlySpecifiedGlobals;
+  std::set ExplicitlySpecifiedGlobals;
   for (const auto Arg :
Args.filtered(options::OPT_mtocdata_EQ, options::OPT_mno_tocdata_EQ)) {
 TOCDataSetting ArgTocDataSetting =
@@ -486,7 +486,7 @@ static void addTocDataOptions(const llvm::opt::ArgList 
&Args,
 ExplicitlySpecifiedGlobals.erase(Val);
   }
 
-  auto buildExceptionList = [](const llvm::StringSet<> &ExplicitValues,
+  auto buildExceptionList = [](const std::set &ExplicitValues,
const char *OptionSpelling) {
 std::string Option(OptionSpelling);
 bool IsFirst = true;
@@ -495,7 +495,7 @@ static void addTocDataOptions(const llvm::opt::ArgList 
&Args,
 Option += ",";
 
   IsFirst = false;
-  Option += E.first();
+  Option += E.str();
 }
 return Option;
   };

diff  --git a/clang/test/Driver/toc-conf.c b/clang/test/Driver/toc-conf.c
index 80d92ee1a90b4b..7b2d5122ebc6ce 100644
--- a/clang/test/Driver/toc-conf.c
+++ b/clang/test/Driver/toc-conf.c
@@ -23,7 +23,7 @@ void func() {
 
 // CHECK-CONF1-NOT: warning:
 // CHECK-CONF1: "-cc1"{{.*}}" "-mno-tocdata"
-// CHECK-CONF1: "-mtocdata=g2,g1"
+// CHECK-CONF1: "-mtocdata=g1,g2"
 
 // CHECK-CONF2-NOT: warning:
 // CHECK-CONF2: "-cc1"{{.*}}" "-mtocdata"



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


[clang] [AIX][TOC] -mtocdata/-mno-tocdata fix non deterministic iteration order (PR #86840)

2024-03-28 Thread Zaara Syeda via cfe-commits

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


[clang] [clang][dataflow] Fix for value constructor in class derived from optional. (PR #86942)

2024-03-28 Thread Yitzhak Mandelbaum via cfe-commits

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


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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

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


@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (PossibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s[1] == '_') {

AaronBallman wrote:

This looks like it will read off the end of the buffer if `s + 1 >= 
ThisTokEnd`, so that should be guarded (and a test case added for that 
situation).

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

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


@@ -1127,9 +1148,9 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   // wb and WB are allowed, but a mixture of cases like Wb or wB is not. We
   // explicitly do not support the suffix in C++ as an extension because a
   // library-based UDL that resolves to a library type may be more
-  // appropriate there.
-  if (!LangOpts.CPlusPlus && ((s[0] == 'w' && s[1] == 'b') ||
-  (s[0] == 'W' && s[1] == 'B'))) {
+  // appropriate there. The same rules apply for __wb/__WB.
+  if ((!LangOpts.CPlusPlus || PossibleBitInt) &&
+  ((s[0] == 'w' && s[1] == 'b') || (s[0] == 'W' && s[1] == 'B'))) {

AaronBallman wrote:

I think there's an existing bug here when `s + 1 >= ThisTokEnd` that should be 
guarded for (and a test case added).

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


[libclc] [libclc] Make CMake messages better fit into LLVM (PR #86945)

2024-03-28 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/86945

The libclc project is currently only properly supported as an external project. 
However, when trying to get it to also build in-tree, the CMake configuration 
messages it outputs stand out amongst the rest of the LLVM projects and 
sub-projects.

This commit makes all messages clear that they belong to the libclc project, as 
well as turning them into 'STATUS' messages where appropriate.

>From 45e1aca14d23784d53b8b2689c87916a26355d4b Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Thu, 28 Mar 2024 12:37:37 +
Subject: [PATCH] [libclc] Make CMake messages better fit into LLVM

The libclc project is currently only properly supported as an external
project. However, when trying to get it to also build in-tree, the CMake
configuration messages it outputs stand out amongst the rest of the LLVM
projects and sub-projects.

This commit makes all messages clear that they belong to the libclc
project, as well as turning them into 'STATUS' messages where
appropriate.
---
 libclc/CMakeLists.txt | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 745b848fba4901..9236f09d366782 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -45,7 +45,7 @@ option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of 
subnormal support."
 find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
 include(AddLLVM)
 
-message( "LLVM version: ${LLVM_PACKAGE_VERSION}" )
+message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" )
 
 if( ${LLVM_PACKAGE_VERSION} VERSION_LESS ${LIBCLC_MIN_LLVM} )
   message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" )
@@ -67,14 +67,13 @@ find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
 find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} 
NO_DEFAULT_PATH )
 
 # Print toolchain
-message( "clang: ${LLVM_CLANG}" )
-message( "llvm-as: ${LLVM_AS}" )
-message( "llvm-link: ${LLVM_LINK}" )
-message( "opt: ${LLVM_OPT}" )
-message( "llvm-spirv: ${LLVM_SPIRV}" )
-message( "" )
+message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" )
+message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" )
+message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" )
+message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" )
+message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" )
 if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT LLVM_LINK )
-  message( FATAL_ERROR "toolchain incomplete!" )
+  message( FATAL_ERROR "libclc toolchain incomplete!" )
 endif()
 
 list( SORT LIBCLC_TARGETS_TO_BUILD )
@@ -182,7 +181,7 @@ add_custom_target( "clspv-generate_convert.cl" DEPENDS 
clspv-convert.cl )
 enable_testing()
 
 foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
-  message( "BUILDING ${t}" )
+  message( STATUS "libclc target '${t}' is enabled" )
   string( REPLACE "-" ";" TRIPLE  ${t} )
   list( GET TRIPLE 0 ARCH )
   list( GET TRIPLE 1 VENDOR )
@@ -265,7 +264,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
   set( mcpu "-mcpu=${d}" )
   set( arch_suffix "${d}-${t}" )
 endif()
-message( "  DEVICE: ${d} ( ${${d}_aliases} )" )
+message( STATUS "  device: ${d} ( ${${d}_aliases} )" )
 
 if ( ${ARCH} STREQUAL "spirv" OR ${ARCH} STREQUAL "spirv64" )
   if( ${ARCH} STREQUAL "spirv" )

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


[libclc] [libclc] Make CMake messages better fit into LLVM (PR #86945)

2024-03-28 Thread Matt Arsenault via cfe-commits

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


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


[clang-tools-extra] 56a10a3 - [clangd][trace] Fix comment to mention that trace spans are measured … (#86938)

2024-03-28 Thread via cfe-commits

Author: VitaNuo
Date: 2024-03-28T13:48:09+01:00
New Revision: 56a10a3c7930164a875db7c34da8c2a8b8abfbee

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

LOG: [clangd][trace] Fix comment to mention that trace spans are measured … 
(#86938)

…in milliseconds rather than seconds.

Added: 


Modified: 
clang-tools-extra/clangd/support/Trace.h

Removed: 




diff  --git a/clang-tools-extra/clangd/support/Trace.h 
b/clang-tools-extra/clangd/support/Trace.h
index 1bfc75b874d8a9..36c3745a41e969 100644
--- a/clang-tools-extra/clangd/support/Trace.h
+++ b/clang-tools-extra/clangd/support/Trace.h
@@ -143,8 +143,8 @@ bool enabled();
 class Span {
 public:
   Span(llvm::Twine Name);
-  /// Records span's duration in seconds to \p LatencyMetric with \p Name as 
the
-  /// label.
+  /// Records span's duration in milliseconds to \p LatencyMetric with \p Name
+  /// as the label.
   Span(llvm::Twine Name, const Metric &LatencyMetric);
   ~Span();
 



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


[clang-tools-extra] [clangd][trace] Fix comment to mention that trace spans are measured … (PR #86938)

2024-03-28 Thread via cfe-commits

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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-28 Thread Nathan Gauër via cfe-commits

https://github.com/Keenuts updated 
https://github.com/llvm/llvm-project/pull/80680

From afbe709931942b3970f92884022e250c1e7eb84f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= 
Date: Fri, 2 Feb 2024 16:38:46 +0100
Subject: [PATCH 1/9] [clang][HLSL][SPRI-V] Add convergence intrinsics
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

HLSL has wave operations and other kind of function which required the
control flow to either be converged, or respect certain constraints as
where and how to re-converge.

At the HLSL level, the convergence are mostly obvious: the control flow
is expected to re-converge at the end of a scope.
Once translated to IR, HLSL scopes disapear. This means we need a way to
communicate convergence restrictions down to the backend.

For this, the SPIR-V backend uses convergence intrinsics. So this commit
adds some code to generate convergence intrinsics when required.

This commit is not to be submitted as-is (lacks testing), but
should serve as a basis for an upcoming RFC.

Signed-off-by: Nathan Gauër 
---
 clang/lib/CodeGen/CGBuiltin.cpp  | 102 +++
 clang/lib/CodeGen/CGCall.cpp |   4 ++
 clang/lib/CodeGen/CGLoopInfo.h   |   8 ++-
 clang/lib/CodeGen/CodeGenFunction.h  |  19 +
 llvm/include/llvm/IR/IntrinsicInst.h |  13 
 5 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2eaceeba617700..9cc630cd05785a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1130,8 +1130,97 @@ struct BitTest {
 
   static BitTest decodeBitTestBuiltin(unsigned BuiltinID);
 };
+
+// Returns the first convergence entry/loop/anchor instruction found in |BB|.
+// std::nullopt otherwise.
+std::optional getConvergenceToken(llvm::BasicBlock *BB) 
{
+  for (auto &I : *BB) {
+auto *II = dyn_cast(&I);
+if (II && isConvergenceControlIntrinsic(II->getIntrinsicID()))
+  return II;
+  }
+  return std::nullopt;
+}
+
 } // namespace
 
+llvm::CallBase *
+CodeGenFunction::AddConvergenceControlAttr(llvm::CallBase *Input,
+   llvm::Value *ParentToken) {
+  llvm::Value *bundleArgs[] = {ParentToken};
+  llvm::OperandBundleDef OB("convergencectrl", bundleArgs);
+  auto Output = llvm::CallBase::addOperandBundle(
+  Input, llvm::LLVMContext::OB_convergencectrl, OB, Input);
+  Input->replaceAllUsesWith(Output);
+  Input->eraseFromParent();
+  return Output;
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::EmitConvergenceLoop(llvm::BasicBlock *BB,
+ llvm::Value *ParentToken) {
+  CGBuilderTy::InsertPoint IP = Builder.saveIP();
+  Builder.SetInsertPoint(&BB->front());
+  auto CB = Builder.CreateIntrinsic(
+  llvm::Intrinsic::experimental_convergence_loop, {}, {});
+  Builder.restoreIP(IP);
+
+  auto I = AddConvergenceControlAttr(CB, ParentToken);
+  // Controlled convergence is incompatible with uncontrolled convergence.
+  // Removing any old attributes.
+  I->setNotConvergent();
+
+  assert(isa(I));
+  return dyn_cast(I);
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::getOrEmitConvergenceEntryToken(llvm::Function *F) {
+  auto *BB = &F->getEntryBlock();
+  auto token = getConvergenceToken(BB);
+  if (token.has_value())
+return token.value();
+
+  // Adding a convergence token requires the function to be marked as
+  // convergent.
+  F->setConvergent();
+
+  CGBuilderTy::InsertPoint IP = Builder.saveIP();
+  Builder.SetInsertPoint(&BB->front());
+  auto I = Builder.CreateIntrinsic(
+  llvm::Intrinsic::experimental_convergence_entry, {}, {});
+  assert(isa(I));
+  Builder.restoreIP(IP);
+
+  return dyn_cast(I);
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::getOrEmitConvergenceLoopToken(const LoopInfo *LI) {
+  assert(LI != nullptr);
+
+  auto token = getConvergenceToken(LI->getHeader());
+  if (token.has_value())
+return *token;
+
+  llvm::IntrinsicInst *PII =
+  LI->getParent()
+  ? EmitConvergenceLoop(LI->getHeader(),
+getOrEmitConvergenceLoopToken(LI->getParent()))
+  : getOrEmitConvergenceEntryToken(LI->getHeader()->getParent());
+
+  return EmitConvergenceLoop(LI->getHeader(), PII);
+}
+
+llvm::CallBase *
+CodeGenFunction::AddControlledConvergenceAttr(llvm::CallBase *Input) {
+  llvm::Value *ParentToken =
+  LoopStack.hasInfo()
+  ? getOrEmitConvergenceLoopToken(&LoopStack.getInfo())
+  : getOrEmitConvergenceEntryToken(Input->getFunction());
+  return AddConvergenceControlAttr(Input, ParentToken);
+}
+
 BitTest BitTest::decodeBitTestBuiltin(unsigned BuiltinID) {
   switch (BuiltinID) {
 // Main portable variants.
@@ -5801,6 +5890,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 {NDRange, Kernel, Block}));
   }
 
+  case Builtin::BI__builtin_hlsl_wave_active_count_bits: {
+llvm::Typ

[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-28 Thread Nathan Gauër via cfe-commits


@@ -1130,8 +1130,92 @@ struct BitTest {
 
   static BitTest decodeBitTestBuiltin(unsigned BuiltinID);
 };
+
+// Returns the first convergence entry/loop/anchor instruction found in |BB|.
+// std::nullptr otherwise.
+llvm::IntrinsicInst *getConvergenceToken(llvm::BasicBlock *BB) {
+  for (auto &I : *BB) {
+auto *II = dyn_cast(&I);
+if (II && isConvergenceControlIntrinsic(II->getIntrinsicID()))
+  return II;
+  }
+  return nullptr;
+}
+
 } // namespace
 
+llvm::CallBase *
+CodeGenFunction::AddConvergenceControlAttr(llvm::CallBase *Input,

Keenuts wrote:

Thanks, done, Added `Token` to function name end, changed `Attr` to `Token`, 
and fixed case the first letters.

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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-28 Thread Nathan Gauër via cfe-commits

Keenuts wrote:

Thanks all the the reviews! We have 3 LGTMs and an ack from Arsenm, so I'm 
going to rebase on main, wait for the bots & tests, and if all is green, merge 
this.

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


[clang] 96c8e2e - [APINotes] For a re-exported module, look for APINotes in the re-exporting module's apinotes file

2024-03-28 Thread via cfe-commits

Author: Egor Zhdan
Date: 2024-03-28T12:59:57Z
New Revision: 96c8e2e88cc68416ddce4a9bf1a9221387b6d4b3

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

LOG: [APINotes] For a re-exported module, look for APINotes in the re-exporting 
module's apinotes file

This upstreams https://github.com/apple/llvm-project/pull/8063.

If module FooCore is re-exported through module Foo (by using
`export_as` in the modulemap), look for attributes of FooCore symbols in
Foo.apinotes file.

Swift bundles `std.apinotes` file that adds Swift-specific attributes to
the C++ stdlib symbols. In recent versions of libc++, module std got
split into multiple top-level modules, each of them is re-exported
through std. This change allows us to keep using a single modulemap file
for all supported C++ stdlibs.

rdar://121680760

Added: 
clang/test/APINotes/Inputs/Headers/ExportAs.apinotes
clang/test/APINotes/Inputs/Headers/ExportAs.h
clang/test/APINotes/Inputs/Headers/ExportAsCore.h
clang/test/APINotes/export-as.c

Modified: 
clang/lib/APINotes/APINotesManager.cpp
clang/test/APINotes/Inputs/Headers/module.modulemap

Removed: 




diff  --git a/clang/lib/APINotes/APINotesManager.cpp 
b/clang/lib/APINotes/APINotesManager.cpp
index f60f09e2b3c231..789bb97d81de00 100644
--- a/clang/lib/APINotes/APINotesManager.cpp
+++ b/clang/lib/APINotes/APINotesManager.cpp
@@ -221,6 +221,7 @@ APINotesManager::getCurrentModuleAPINotes(Module *M, bool 
LookInModule,
   ArrayRef SearchPaths) {
   FileManager &FM = SM.getFileManager();
   auto ModuleName = M->getTopLevelModuleName();
+  auto ExportedModuleName = M->getTopLevelModule()->ExportAsModule;
   llvm::SmallVector APINotes;
 
   // First, look relative to the module itself.
@@ -233,6 +234,10 @@ APINotesManager::getCurrentModuleAPINotes(Module *M, bool 
LookInModule,
 
 APINotes.push_back(*File);
   }
+  // If module FooCore is re-exported through module Foo, try Foo.apinotes.
+  if (!ExportedModuleName.empty())
+if (auto File = findAPINotesFile(Dir, ExportedModuleName, WantPublic))
+  APINotes.push_back(*File);
 };
 
 if (M->IsFramework) {

diff  --git a/clang/test/APINotes/Inputs/Headers/ExportAs.apinotes 
b/clang/test/APINotes/Inputs/Headers/ExportAs.apinotes
new file mode 100644
index 00..14c77afd8c30a1
--- /dev/null
+++ b/clang/test/APINotes/Inputs/Headers/ExportAs.apinotes
@@ -0,0 +1,5 @@
+Name: ExportAs
+Globals:
+  - Name: globalInt
+Availability: none
+AvailabilityMsg: "oh no"

diff  --git a/clang/test/APINotes/Inputs/Headers/ExportAs.h 
b/clang/test/APINotes/Inputs/Headers/ExportAs.h
new file mode 100644
index 00..ff490e09641760
--- /dev/null
+++ b/clang/test/APINotes/Inputs/Headers/ExportAs.h
@@ -0,0 +1 @@
+#include "ExportAsCore.h"

diff  --git a/clang/test/APINotes/Inputs/Headers/ExportAsCore.h 
b/clang/test/APINotes/Inputs/Headers/ExportAsCore.h
new file mode 100644
index 00..f7674c19935d64
--- /dev/null
+++ b/clang/test/APINotes/Inputs/Headers/ExportAsCore.h
@@ -0,0 +1 @@
+static int globalInt = 123;

diff  --git a/clang/test/APINotes/Inputs/Headers/module.modulemap 
b/clang/test/APINotes/Inputs/Headers/module.modulemap
index 98b4ee3e96cfe7..99fb1aec86481a 100644
--- a/clang/test/APINotes/Inputs/Headers/module.modulemap
+++ b/clang/test/APINotes/Inputs/Headers/module.modulemap
@@ -2,6 +2,16 @@ module ExternCtx {
   header "ExternCtx.h"
 }
 
+module ExportAsCore {
+  header "ExportAsCore.h"
+  export_as ExportAs
+}
+
+module ExportAs {
+  header "ExportAs.h"
+  export *
+}
+
 module HeaderLib {
   header "HeaderLib.h"
 }

diff  --git a/clang/test/APINotes/export-as.c b/clang/test/APINotes/export-as.c
new file mode 100644
index 00..7a8a652ab75575
--- /dev/null
+++ b/clang/test/APINotes/export-as.c
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/ModulesCache -fdisable-module-hash -fapinotes-modules 
-fsyntax-only -I %S/Inputs/Headers %s -ast-dump -ast-dump-filter globalInt -x c 
| FileCheck %s
+
+#include "ExportAs.h"
+
+// CHECK: Dumping globalInt:
+// CHECK: VarDecl {{.+}} imported in ExportAsCore globalInt 'int'
+// CHECK: UnavailableAttr {{.+}} <> "oh no"



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


[clang] [APINotes] For a re-exported module, look for APINotes in the re-exporting module's apinotes file (PR #86820)

2024-03-28 Thread Egor Zhdan via cfe-commits

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


[libclc] [libclc] Make CMake messages better fit into LLVM (PR #86945)

2024-03-28 Thread Tom Stellard via cfe-commits

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


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


[clang] [HLSL] prevent generation of double intrinsics. (PR #86932)

2024-03-28 Thread Farzon Lotfi via cfe-commits

farzonl wrote:

I was writing up a ticket for floor and ceil. Nice catch! 
https://godbolt.org/z/q9a644e6W. 

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


[clang] [HLSL] prevent generation of double intrinsics. (PR #86932)

2024-03-28 Thread Farzon Lotfi via cfe-commits


@@ -1,12 +1,13 @@
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_cos 
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sin 
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_ceil
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_cos
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_floor 
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log 
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log2 
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log10
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sin
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sqrt
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_trunc
 

farzonl wrote:

in semaChecking You added `__builtin_elementwise_exp` and 
`__builtin_elementwise_exp2` you should add them to the tests

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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-28 Thread Nathan Gauër via cfe-commits

https://github.com/Keenuts updated 
https://github.com/llvm/llvm-project/pull/80680

From dc008167980ca0a479d2cdceeeb1ab6cd4983ec3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= 
Date: Fri, 2 Feb 2024 16:38:46 +0100
Subject: [PATCH 1/9] [clang][HLSL][SPRI-V] Add convergence intrinsics
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

HLSL has wave operations and other kind of function which required the
control flow to either be converged, or respect certain constraints as
where and how to re-converge.

At the HLSL level, the convergence are mostly obvious: the control flow
is expected to re-converge at the end of a scope.
Once translated to IR, HLSL scopes disapear. This means we need a way to
communicate convergence restrictions down to the backend.

For this, the SPIR-V backend uses convergence intrinsics. So this commit
adds some code to generate convergence intrinsics when required.

This commit is not to be submitted as-is (lacks testing), but
should serve as a basis for an upcoming RFC.

Signed-off-by: Nathan Gauër 
---
 clang/lib/CodeGen/CGBuiltin.cpp  | 102 +++
 clang/lib/CodeGen/CGCall.cpp |   4 ++
 clang/lib/CodeGen/CGLoopInfo.h   |   8 ++-
 clang/lib/CodeGen/CodeGenFunction.h  |  19 +
 llvm/include/llvm/IR/IntrinsicInst.h |  13 
 5 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index fdb517eb254d3b..76fe8c1d40a419 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1131,8 +1131,97 @@ struct BitTest {
 
   static BitTest decodeBitTestBuiltin(unsigned BuiltinID);
 };
+
+// Returns the first convergence entry/loop/anchor instruction found in |BB|.
+// std::nullopt otherwise.
+std::optional getConvergenceToken(llvm::BasicBlock *BB) 
{
+  for (auto &I : *BB) {
+auto *II = dyn_cast(&I);
+if (II && isConvergenceControlIntrinsic(II->getIntrinsicID()))
+  return II;
+  }
+  return std::nullopt;
+}
+
 } // namespace
 
+llvm::CallBase *
+CodeGenFunction::AddConvergenceControlAttr(llvm::CallBase *Input,
+   llvm::Value *ParentToken) {
+  llvm::Value *bundleArgs[] = {ParentToken};
+  llvm::OperandBundleDef OB("convergencectrl", bundleArgs);
+  auto Output = llvm::CallBase::addOperandBundle(
+  Input, llvm::LLVMContext::OB_convergencectrl, OB, Input);
+  Input->replaceAllUsesWith(Output);
+  Input->eraseFromParent();
+  return Output;
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::EmitConvergenceLoop(llvm::BasicBlock *BB,
+ llvm::Value *ParentToken) {
+  CGBuilderTy::InsertPoint IP = Builder.saveIP();
+  Builder.SetInsertPoint(&BB->front());
+  auto CB = Builder.CreateIntrinsic(
+  llvm::Intrinsic::experimental_convergence_loop, {}, {});
+  Builder.restoreIP(IP);
+
+  auto I = AddConvergenceControlAttr(CB, ParentToken);
+  // Controlled convergence is incompatible with uncontrolled convergence.
+  // Removing any old attributes.
+  I->setNotConvergent();
+
+  assert(isa(I));
+  return dyn_cast(I);
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::getOrEmitConvergenceEntryToken(llvm::Function *F) {
+  auto *BB = &F->getEntryBlock();
+  auto token = getConvergenceToken(BB);
+  if (token.has_value())
+return token.value();
+
+  // Adding a convergence token requires the function to be marked as
+  // convergent.
+  F->setConvergent();
+
+  CGBuilderTy::InsertPoint IP = Builder.saveIP();
+  Builder.SetInsertPoint(&BB->front());
+  auto I = Builder.CreateIntrinsic(
+  llvm::Intrinsic::experimental_convergence_entry, {}, {});
+  assert(isa(I));
+  Builder.restoreIP(IP);
+
+  return dyn_cast(I);
+}
+
+llvm::IntrinsicInst *
+CodeGenFunction::getOrEmitConvergenceLoopToken(const LoopInfo *LI) {
+  assert(LI != nullptr);
+
+  auto token = getConvergenceToken(LI->getHeader());
+  if (token.has_value())
+return *token;
+
+  llvm::IntrinsicInst *PII =
+  LI->getParent()
+  ? EmitConvergenceLoop(LI->getHeader(),
+getOrEmitConvergenceLoopToken(LI->getParent()))
+  : getOrEmitConvergenceEntryToken(LI->getHeader()->getParent());
+
+  return EmitConvergenceLoop(LI->getHeader(), PII);
+}
+
+llvm::CallBase *
+CodeGenFunction::AddControlledConvergenceAttr(llvm::CallBase *Input) {
+  llvm::Value *ParentToken =
+  LoopStack.hasInfo()
+  ? getOrEmitConvergenceLoopToken(&LoopStack.getInfo())
+  : getOrEmitConvergenceEntryToken(Input->getFunction());
+  return AddConvergenceControlAttr(Input, ParentToken);
+}
+
 BitTest BitTest::decodeBitTestBuiltin(unsigned BuiltinID) {
   switch (BuiltinID) {
 // Main portable variants.
@@ -5803,6 +5892,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 {NDRange, Kernel, Block}));
   }
 
+  case Builtin::BI__builtin_hlsl_wave_active_count_bits: {
+llvm::Typ

[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-28 Thread Nathan Gauër via cfe-commits

Keenuts wrote:

Local tests for SPIR-V & DXIL pass

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


[clang] [HLSL] prevent generation of double intrinsics. (PR #86932)

2024-03-28 Thread Farzon Lotfi via cfe-commits

farzonl wrote:

So keep in mind there are some double cases that are valid for hlsl. so always 
check via dxc  which can be easily used via 
[hlsl.godbolt](https://hlsl.godbolt.org/).

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


[clang] [HLSL] prevent generation of double intrinsics. (PR #86932)

2024-03-28 Thread Andrii Levitskiy via cfe-commits


@@ -1,12 +1,13 @@
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_cos 
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sin 
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_ceil
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_cos
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_floor 
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log 
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log2 
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log10
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sin
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sqrt
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_trunc
 

aabysswalker wrote:

i though 
https://github.com/llvm/llvm-project/blob/main/clang/test/SemaHLSL/BuiltIns/exp-errors.hlsl#L1-L27
would cover that, but seems like it miss double type check, should i add test 
to half-float-only-errors.hlsl?

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


[clang] [clang][Sema] Fix a CTAD regression after 42239d2e9 (PR #86914)

2024-03-28 Thread via cfe-commits


@@ -1836,7 +1836,19 @@ static TemplateParameterList 
*GetTemplateParameterList(TemplateDecl *TD) {
   // Make sure we get the template parameter list from the most
   // recent declaration, since that is the only one that is guaranteed to
   // have all the default template argument information.
-  return cast(TD->getMostRecentDecl())->getTemplateParameters();
+  Decl *ND = TD->getMostRecentDecl();
+  // Skip past friend Decls because they are not supposed to contain default
+  // template arguments. Moreover, these declarations may introduce template
+  // parameters living in different template depths than the corresponding
+  // template parameters in TD, causing unmatched constraint substitution.
+  //
+  // C++23 N4950 [temp.param]p12

Sirraide wrote:

> I think this function is not only used for class templates, but also for 
> function templates. For function templates, there is an exception per the 
> standard (temp.param 12): If a friend function template declaration specifies 
> a default template-argument, that declaration shall be a definition and shall 
> be the only declaration of the function template in the translation unit.

In that case it’d make sense to add a test for a friend function template as 
well if there isn’t already one to make sure this change doesn’t break that.

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


[clang] [clang] Add invalid check in NormalizedConstraint::fromConstraintExpr. (PR #86943)

2024-03-28 Thread via cfe-commits

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


[clang] [clang] Add invalid check in NormalizedConstraint::fromConstraintExpr. (PR #86943)

2024-03-28 Thread via cfe-commits


@@ -1356,6 +1356,8 @@ NormalizedConstraint::fromConstraintExpr(Sema &S, 
NamedDecl *D, const Expr *E) {
   S, CSE->getExprLoc(),
   Sema::InstantiatingTemplate::ConstraintNormalization{}, D,
   CSE->getSourceRange());
+  if (Inst.isInvalid())
+return std::nullptr;

Sirraide wrote:

```suggestion
return std::nullopt;
```
Typo.

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


[clang] [clang] Add invalid check in NormalizedConstraint::fromConstraintExpr. (PR #86943)

2024-03-28 Thread via cfe-commits

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

There’s a typo, but LGTM otherwise.

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


[clang] [libclc] [llvm] [openmp] [Clang] `__attribute__((assume))` refactor (PR #84934)

2024-03-28 Thread via cfe-commits

Sirraide wrote:

> Added @AnastasiaStulova for help with the OpenCL questions. I would love to 
> avoid adding `omp_assume` if possible.

Thanks, I didn’t know who to ping about that, and yeah, same.

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


[clang] [HLSL] prevent generation of double intrinsics. (PR #86932)

2024-03-28 Thread Farzon Lotfi via cfe-commits


@@ -1,12 +1,13 @@
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_cos 
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sin 
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_ceil
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_cos
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_floor 
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log 
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log2 
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log10
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sin
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sqrt
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_trunc
 

farzonl wrote:

`exp-errors.hlsl` covers clangs behavior of exp elementwise builtins.  The 
`CheckHLSLBuiltinFunctionCall`  function you added `exp` \ `exp2` is used to 
apply hlsl specific behaviors. Since this is a deviation from normal behvaior 
of the elementwise builtin it would be better to add the tests to 
`half-float-only-errors.hlsl`

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


[clang] [HLSL] prevent generation of double intrinsics. (PR #86932)

2024-03-28 Thread Farzon Lotfi via cfe-commits


@@ -1,12 +1,13 @@
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_cos 
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sin 
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_ceil
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_cos
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_floor 
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log 
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log2 
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log10
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sin
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sqrt
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm 
-disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_trunc
 

farzonl wrote:

There are a few expections to this rule `half-float-only-errors.hlsl` only 
covers unary functions.  Since there weren't enough binary cases pow got its 
own file.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-28 Thread via cfe-commits


@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (PossibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s[1] == '_') {

Sirraide wrote:

I recall reading somewhere that one character of overscan is allowed in 
`NumericLiteralParser`, but I’m not sure if that applies here.

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


[clang] [HLSL] prevent generation of double intrinsics. (PR #86932)

2024-03-28 Thread Andrii Levitskiy via cfe-commits

https://github.com/aabysswalker updated 
https://github.com/llvm/llvm-project/pull/86932

>From caec748f3f0ab16b829f7765c5c2d87ed7f7b73f Mon Sep 17 00:00:00 2001
From: aabysswalker 
Date: Thu, 28 Mar 2024 12:50:25 +0200
Subject: [PATCH 1/2] Prevent generating double of ceil, exp, exp2, floor.
 Removed accompanying ceil, floor double type tests.

---
 clang/lib/Headers/hlsl/hlsl_intrinsics.h   | 18 --
 clang/lib/Sema/SemaChecking.cpp|  6 +-
 clang/test/CodeGenHLSL/builtins/ceil.hlsl  | 13 -
 clang/test/CodeGenHLSL/builtins/floor.hlsl | 13 -
 .../BuiltIns/half-float-only-errors.hlsl   |  7 ---
 5 files changed, 9 insertions(+), 48 deletions(-)

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d47eab453f8747..82e2cff2cb95c5 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -243,15 +243,6 @@ float3 ceil(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 float4 ceil(float4);
 
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double ceil(double);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double2 ceil(double2);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double3 ceil(double3);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
-double4 ceil(double4);
-
 
//===--===//
 // clamp builtins
 
//===--===//
@@ -585,15 +576,6 @@ float3 floor(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
 float4 floor(float4);
 
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double floor(double);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double2 floor(double2);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double3 floor(double3);
-_HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor)
-double4 floor(double4);
-
 
//===--===//
 // frac builtins
 
//===--===//
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f5c0c761da75af..2e4e18a3ebf759 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5641,12 +5641,16 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   return true;
 break;
   }
+  case Builtin::BI__builtin_elementwise_ceil:
   case Builtin::BI__builtin_elementwise_cos:
-  case Builtin::BI__builtin_elementwise_sin:
+  case Builtin::BI__builtin_elementwise_exp:
+  case Builtin::BI__builtin_elementwise_exp2:
+  case Builtin::BI__builtin_elementwise_floor:
   case Builtin::BI__builtin_elementwise_log:
   case Builtin::BI__builtin_elementwise_log2:
   case Builtin::BI__builtin_elementwise_log10:
   case Builtin::BI__builtin_elementwise_pow:
+  case Builtin::BI__builtin_elementwise_sin:
   case Builtin::BI__builtin_elementwise_sqrt:
   case Builtin::BI__builtin_elementwise_trunc: {
 if (CheckFloatOrHalfRepresentations(this, TheCall))
diff --git a/clang/test/CodeGenHLSL/builtins/ceil.hlsl 
b/clang/test/CodeGenHLSL/builtins/ceil.hlsl
index 06d0d4c2cf546d..be7725cd4d66c1 100644
--- a/clang/test/CodeGenHLSL/builtins/ceil.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/ceil.hlsl
@@ -41,16 +41,3 @@ float3 test_ceil_float3(float3 p0) { return ceil(p0); }
 // CHECK: define noundef <4 x float> @
 // CHECK: call <4 x float> @llvm.ceil.v4f32(
 float4 test_ceil_float4(float4 p0) { return ceil(p0); }
-
-// CHECK: define noundef double @
-// CHECK: call double @llvm.ceil.f64(
-double test_ceil_double(double p0) { return ceil(p0); }
-// CHECK: define noundef <2 x double> @
-// CHECK: call <2 x double> @llvm.ceil.v2f64(
-double2 test_ceil_double2(double2 p0) { return ceil(p0); }
-// CHECK: define noundef <3 x double> @
-// CHECK: call <3 x double> @llvm.ceil.v3f64(
-double3 test_ceil_double3(double3 p0) { return ceil(p0); }
-// CHECK: define noundef <4 x double> @
-// CHECK: call <4 x double> @llvm.ceil.v4f64(
-double4 test_ceil_double4(double4 p0) { return ceil(p0); }
diff --git a/clang/test/CodeGenHLSL/builtins/floor.hlsl 
b/clang/test/CodeGenHLSL/builtins/floor.hlsl
index d2a2f6e52f1ec3..07803bfae3be68 100644
--- a/clang/test/CodeGenHLSL/builtins/floor.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/floor.hlsl
@@ -41,16 +41,3 @@ float3 test_floor_float3(float3 p0) { return floor(p0); }
 // CHECK: define noundef <4 x float> @
 // CHECK: call <4 x float> @llvm.floor.v4f32(
 float4 test_floor_float4(float4 p0) { return floor(p0); }
-
-// CHECK: define noundef double @
-// CHECK: call double @llvm.floor.f64(
-double test_floor_double(double p0) { return floor(p0); }
-// CHECK: define noundef <2 x double> @
-// CHECK: call <2 x double> @llvm.floor.v2f64(
-double2 test_floor_double2(double2 p0) { return floor(p0); }
-// CHECK: define noundef <3 x double> 

[clang] [libclc] [llvm] [openmp] [Clang] `__attribute__((assume))` refactor (PR #84934)

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

alexey-bataev wrote:

> Thank you for working on this, it's definitely a complicated situation!
> 
> > However, libclc appears to be using **attribute**((assume)) internally, 
> > specifically, in one header that defines a macro that is then used 
> > throughout the codebase. I’m not familiar with libclc or OpenCL, so I’ve 
> > added omp_assume as an alternative spelling for the OpenMP attribute and 
> > replaced the attribute in the header in question with 
> > **attribute**((**omp_assume**)).
> 
> Added @AnastasiaStulova for help with the OpenCL questions. I would love to 
> avoid adding `omp_assume` if possible.
> 
> > It should be noted that, without the omp_assume spelling, it would be 
> > impossible to use this attribute in C without running into -pedantic 
> > warnings; we could consider supporting [[omp::assume]] in C23, though.
> 
> My guess is that the OpenMP folks haven't gotten around to rebasing on top of 
> C23 yet and that's really the only thing holding back supporting `[[]]` 
> spellings in C with OpenMP. @alexey-bataev, should we enable OpenMP attribute 
> spellings whenever double square bracket attributes are enabled?
> 
> > From what I can tell, no-one except libclc is actually using this 
> > attribute? At least on github, the only matches I’ve found for 
> > **attribute**((assume("omp are in LLVM and various forks thereof. Given 
> > that it’s not particularly widely used, I don’t think removal without 
> > deprecation would be that big of a deal in this case, though if you think 
> > that that’s a non-option, then I’d instead suggest deprecating it and 
> > removing it in a later version of Clang.
> 
> This matches my searching around on 
> https://sourcegraph.com/search?q=context:global+__attribute__%28%28assume%28%22omp+-file:.*test.*+-file:.*llvm.*+-file:.*%5C.rst&patternType=keyword&sm=0
>  so I think removal without deprecation may be reasonable unless 
> @alexey-bataev knows of something we're missing.

Idon'think there are any. @jdoerfert thoughts?

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

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


@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (PossibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s[1] == '_') {

AaronBallman wrote:

I think you might be remembering this comment:
```
  // This routine assumes that the range begin/end matches the regex for integer
  // and FP constants (specifically, the 'pp-number' regex), and assumes that
  // the byte at "*end" is both valid and not part of the regex.  Because of
  // this, it doesn't have to check for 'overscan' in various places.
  // Note: For HLSL, the end token is allowed to be '.' which would be in the
  // 'pp-number' regex. This is required to support vector swizzles on numeric
  // constants (i.e. 1.xx or 1.5f.rrr).
```
but I took that to be about pp-number and not the suffix (suffixes are not part 
of pp-number because suffixes are about types and the preprocessor is 
type-agnostic).

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


[clang] [llvm] [CodeGen][arm64e] Add methods and data members to Address, which are needed to authenticate signed pointers (PR #86923)

2024-03-28 Thread Akira Hatanaka via cfe-commits

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-28 Thread via cfe-commits


@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (PossibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s[1] == '_') {

Sirraide wrote:

Ah, I see, makes sense.

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


[clang] [analyzer] Remove barely used class 'KnownSVal' (NFC) (PR #86953)

2024-03-28 Thread via cfe-commits

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

The class `KnownSVal` was very magical abstract class within the `SVal` class 
hierarchy: with a hacky `classof` method it acted as if it was the common 
ancestor of the classes `UndefinedSVal` and `DefinedSVal`.

However, it was only used in two `getAs()` calls and the signatures 
of two methods, which does not "pay for" its weird behavior, so I created this 
commit that removes it and replaces its use with more straightforward solutions.

>From 638497ef227cf6f3e8d558618a186a3c45935dfc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Thu, 28 Mar 2024 14:49:15 +0100
Subject: [PATCH] [analyzer] Remove barely used class 'KnownSVal' (NFC)

The class `KnownSVal` was very magical abstract class within the `SVal`
class hierarchy: with a hacky `classof` method it acted as if it was the
common ancestor of the classes `UndefinedSVal` and `DefinedSVal`.

However, it was only used in two `getAs()` calls and the
signatures of two methods, which does not "pay for" its weird behavior,
so I created this commit that removes it and replaces its use with more
straightforward solutions.
---
 .../Core/BugReporter/BugReporterVisitors.h |  3 ++-
 .../StaticAnalyzer/Core/PathSensitive/SVals.h  |  8 
 .../RetainCountChecker/RetainCountDiagnostics.cpp  |  2 +-
 .../StaticAnalyzer/Core/BugReporterVisitors.cpp| 14 +++---
 4 files changed, 10 insertions(+), 17 deletions(-)

diff --git 
a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
index d9b3d9352d3224..cc3d93aabafda4 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
@@ -374,6 +374,7 @@ bool trackExpressionValue(const ExplodedNode *N, const Expr 
*E,
 /// from.
 ///
 /// \param V We're searching for the store where \c R received this value.
+///It may be either defined or undefined, but should not be unknown.
 /// \param R The region we're tracking.
 /// \param Opts Tracking options specifying how we want to track the value.
 /// \param Origin Only adds notes when the last store happened in a
@@ -383,7 +384,7 @@ bool trackExpressionValue(const ExplodedNode *N, const Expr 
*E,
 ///changes to its value in a nested stackframe could be pruned, and
 ///this visitor can prevent that without polluting the bugpath too
 ///much.
-void trackStoredValue(KnownSVal V, const MemRegion *R,
+void trackStoredValue(SVal V, const MemRegion *R,
   PathSensitiveBugReport &Report, TrackingOptions Opts = 
{},
   const StackFrameContext *Origin = nullptr);
 
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
index c60528b7685fe8..3a4b0872571494 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -232,14 +232,6 @@ class DefinedSVal : public DefinedOrUnknownSVal {
   : DefinedOrUnknownSVal(Kind, Data) {}
 };
 
-/// Represents an SVal that is guaranteed to not be UnknownVal.
-class KnownSVal : public SVal {
-public:
-  /*implicit*/ KnownSVal(DefinedSVal V) : SVal(V) {}
-  /*implicit*/ KnownSVal(UndefinedVal V) : SVal(V) {}
-  static bool classof(SVal V) { return !V.isUnknown(); }
-};
-
 class NonLoc : public DefinedSVal {
 protected:
   NonLoc(SValKind Kind, const void *Data) : DefinedSVal(Kind, Data) {}
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
index c3acb73ba7175b..086c3e5e49b770 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -977,7 +977,7 @@ void RefLeakReport::findBindingToReport(CheckerContext &Ctx,
 //   something like derived regions if we want to construct SVal from
 //   Sym. Instead, we take the value that is definitely stored in that
 //   region, thus guaranteeing that trackStoredValue will work.
-bugreporter::trackStoredValue(AllVarBindings[0].second.castAs(),
+bugreporter::trackStoredValue(AllVarBindings[0].second,
   AllocBindingToReport, *this);
   } else {
 AllocBindingToReport = AllocFirstBinding;
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index a0822513a6d02e..ce167d979d5761 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1238,12 +1238,12 @@ class StoreSiteFinder final : public 
Tracking

[clang] [analyzer] Remove barely used class 'KnownSVal' (NFC) (PR #86953)

2024-03-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (NagyDonat)


Changes

The class `KnownSVal` was very magical abstract class within the `SVal` class 
hierarchy: with a hacky `classof` method it acted as if it was the common 
ancestor of the classes `UndefinedSVal` and `DefinedSVal`.

However, it was only used in two `getAs()` calls and the 
signatures of two methods, which does not "pay for" its weird behavior, so I 
created this commit that removes it and replaces its use with more 
straightforward solutions.

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


4 Files Affected:

- (modified) 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
(+2-1) 
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h (-8) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp 
(+1-1) 
- (modified) clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (+7-7) 


``diff
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
index d9b3d9352d3224..cc3d93aabafda4 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
@@ -374,6 +374,7 @@ bool trackExpressionValue(const ExplodedNode *N, const Expr 
*E,
 /// from.
 ///
 /// \param V We're searching for the store where \c R received this value.
+///It may be either defined or undefined, but should not be unknown.
 /// \param R The region we're tracking.
 /// \param Opts Tracking options specifying how we want to track the value.
 /// \param Origin Only adds notes when the last store happened in a
@@ -383,7 +384,7 @@ bool trackExpressionValue(const ExplodedNode *N, const Expr 
*E,
 ///changes to its value in a nested stackframe could be pruned, and
 ///this visitor can prevent that without polluting the bugpath too
 ///much.
-void trackStoredValue(KnownSVal V, const MemRegion *R,
+void trackStoredValue(SVal V, const MemRegion *R,
   PathSensitiveBugReport &Report, TrackingOptions Opts = 
{},
   const StackFrameContext *Origin = nullptr);
 
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
index c60528b7685fe8..3a4b0872571494 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -232,14 +232,6 @@ class DefinedSVal : public DefinedOrUnknownSVal {
   : DefinedOrUnknownSVal(Kind, Data) {}
 };
 
-/// Represents an SVal that is guaranteed to not be UnknownVal.
-class KnownSVal : public SVal {
-public:
-  /*implicit*/ KnownSVal(DefinedSVal V) : SVal(V) {}
-  /*implicit*/ KnownSVal(UndefinedVal V) : SVal(V) {}
-  static bool classof(SVal V) { return !V.isUnknown(); }
-};
-
 class NonLoc : public DefinedSVal {
 protected:
   NonLoc(SValKind Kind, const void *Data) : DefinedSVal(Kind, Data) {}
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
index c3acb73ba7175b..086c3e5e49b770 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -977,7 +977,7 @@ void RefLeakReport::findBindingToReport(CheckerContext &Ctx,
 //   something like derived regions if we want to construct SVal from
 //   Sym. Instead, we take the value that is definitely stored in that
 //   region, thus guaranteeing that trackStoredValue will work.
-bugreporter::trackStoredValue(AllVarBindings[0].second.castAs(),
+bugreporter::trackStoredValue(AllVarBindings[0].second,
   AllocBindingToReport, *this);
   } else {
 AllocBindingToReport = AllocFirstBinding;
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index a0822513a6d02e..ce167d979d5761 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1238,12 +1238,12 @@ class StoreSiteFinder final : public 
TrackingBugReporterVisitor {
   ///changes to its value in a nested stackframe could be pruned, and
   ///this visitor can prevent that without polluting the bugpath too
   ///much.
-  StoreSiteFinder(bugreporter::TrackerRef ParentTracker, KnownSVal V,
+  StoreSiteFinder(bugreporter::TrackerRef ParentTracker, SVal V,
   const MemRegion *R, TrackingOptions Options,
   const StackFrameContext *OriginSFC = nullptr)
   : TrackingBugReporterVisitor(Paren

[clang] [clang][c++20] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-03-28 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -2177,7 +2177,8 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
-Visit(OVE->getSourceExpr());
+if (const Expr *SE = OVE->getSourceExpr())

bolshakov-a wrote:

Not all `OpaqueValueExpr`s having a source expression are marked as "unique". 
Checking `isUnique()` instead of `getSourceExpr()` breaks at least handling of 
the GNU extension of the `?:` operator:
```
1|  1|int main() {
2|  1|int i = 1;
3|  1|return (i ? 1 : 0)
  ^0<-- disappears if isUnique() is used
  --
  |  Branch (3:12): [True: 1, False: 0]
  |  Branch (3:13): [True: 1, False: 0] <-- disappears if isUnique() is used
  --
4|  1|?: 10;
 ^0
5|  1|}
```

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-28 Thread via cfe-commits

https://github.com/js324 updated https://github.com/llvm/llvm-project/pull/86586

>From 1b0902aa9f8a07771f29fb21d7b4cdea9e966118 Mon Sep 17 00:00:00 2001
From: Jin S 
Date: Mon, 25 Mar 2024 17:19:41 -0400
Subject: [PATCH] [BitInt] Expose a _BitInt literal suffix in C++

---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticCommonKinds.td  |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +-
 clang/include/clang/Lex/LiteralSupport.h  |   3 +-
 clang/lib/Lex/LiteralSupport.cpp  |  31 ++-
 clang/lib/Lex/PPExpressions.cpp   |   8 +-
 clang/lib/Sema/SemaExpr.cpp   |  12 +-
 clang/test/AST/bitint-suffix.cpp  |  32 
 clang/test/Lexer/bitint-constants-compat.c|  11 +-
 clang/test/Lexer/bitint-constants.cpp | 177 ++
 11 files changed, 266 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/AST/bitint-suffix.cpp
 create mode 100644 clang/test/Lexer/bitint-constants.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..d40c86a15ac2da 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented ``_BitInt`` literal suffixes ``__wb`` or ``__WB`` as a Clang 
extension with ``unsigned`` modifiers also allowed. (#GH85223).
 
 C++20 Feature Support
 ^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index a52bf62e24202c..0738f43ca555c8 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -234,6 +234,9 @@ def err_cxx23_size_t_suffix: Error<
 def err_size_t_literal_too_large: Error<
   "%select{signed |}0'size_t' literal is out of range of possible "
   "%select{signed |}0'size_t' values">;
+def ext_cxx_bitint_suffix : Extension<
+  "'_BitInt' suffix for literals is a Clang extension">,
+  InGroup;
 def ext_c23_bitint_suffix : ExtWarn<
   "'_BitInt' suffix for literals is a C23 extension">,
   InGroup;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 44035e2fd16f2e..37f56ed6289d27 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension
+def BitIntExtension : DiagGroup<"bit-int-extension">;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 46a44418a3153b..6759f923564adf 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1646,7 +1646,7 @@ def warn_ext_int_deprecated : Warning<
   "'_ExtInt' is deprecated; use '_BitInt' instead">, InGroup;
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
-  InGroup>;
+  InGroup;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 643ddbdad8c87d..e7a2ccc9bb0bb3 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -80,7 +80,8 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  bool isBitInt : 1; // 1wb, 1uwb (C23) or 1__wb, 1__uwb (Clang extension in 
C++
+ // mode)
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
 
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 438c6d772e6e04..01ff2e2df8465e 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -974,6 +974,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   bool isFixedPointConstant = isFixedPointLiteral();
   bool isFPConstant = isFloatingLiteral();
   bool HasSize = false;
+  bool PossibleBitInt = false;
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+ 

[clang] [Modules] No transitive source location change (PR #86912)

2024-03-28 Thread James Y Knight via cfe-commits

jyknight wrote:

+1 on the high-level plan. Switching from a linear offset to a 
{local-module-index, offset-within-module} pair sounds great!

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


[clang] [clang][Driver] Pass -machine argument to the linker explicitly for ARM64EC targets. (PR #86835)

2024-03-28 Thread Jacek Caban via cfe-commits

https://github.com/cjacek updated 
https://github.com/llvm/llvm-project/pull/86835

>From 7a4a69076b2172e50ce305f97e0f97f67d00aa32 Mon Sep 17 00:00:00 2001
From: Jacek Caban 
Date: Thu, 28 Mar 2024 14:58:48 +0100
Subject: [PATCH] [clang][Driver] Pass -machine argument to the linker
 explicitly for ARM64EC targets.

---
 clang/include/clang/Driver/Options.td |  3 +++
 clang/lib/Driver/ToolChains/MSVC.cpp  |  8 
 clang/test/Driver/msvc-link.c | 20 
 3 files changed, 31 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 29066ea14280c2..39c932e72fdefd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4507,6 +4507,9 @@ def mwindows : Joined<["-"], "mwindows">, Group;
 def mdll : Joined<["-"], "mdll">, Group;
 def municode : Joined<["-"], "municode">, Group;
 def mthreads : Joined<["-"], "mthreads">, Group;
+def marm64x : Joined<["-"], "marm64x">, Group,
+  Visibility<[ClangOption, CLOption]>,
+  HelpText<"Link as a hybrid ARM64X image">;
 def mguard_EQ : Joined<["-"], "mguard=">, Group,
   HelpText<"Enable or disable Control Flow Guard checks and guard tables 
emission">,
   Values<"none,cf,cf-nochecks">;
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index dc534a33e6d0ef..fbf2f45b543844 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -79,6 +79,11 @@ void visualstudio::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(
 Args.MakeArgString(std::string("-out:") + Output.getFilename()));
 
+  if (Args.hasArg(options::OPT_marm64x))
+CmdArgs.push_back("-machine:arm64x");
+  else if (TC.getTriple().isWindowsArm64EC())
+CmdArgs.push_back("-machine:arm64ec");
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
   !C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
 CmdArgs.push_back("-defaultlib:libcmt");
@@ -1017,4 +1022,7 @@ void MSVCToolChain::addClangTargetOptions(
   if (DriverArgs.hasFlag(options::OPT_fno_rtti, options::OPT_frtti,
  /*Default=*/false))
 CC1Args.push_back("-D_HAS_STATIC_RTTI=0");
+
+  if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_marm64x))
+A->ignoreTargetSpecific();
 }
diff --git a/clang/test/Driver/msvc-link.c b/clang/test/Driver/msvc-link.c
index 64e099ea63042f..f80b043c6cfce2 100644
--- a/clang/test/Driver/msvc-link.c
+++ b/clang/test/Driver/msvc-link.c
@@ -36,3 +36,23 @@
 // VFSOVERLAY: "--vfsoverlay"
 // VFSOVERLAY: lld-link
 // VFSOVERLAY: "/vfsoverlay:{{.*}}" "{{.*}}.obj"
+
+// RUN: %clang -target arm64ec-pc-windows-msvc -fuse-ld=link -### %s 2>&1 | 
FileCheck --check-prefix=ARM64EC %s
+// RUN: %clang_cl -target arm64ec-pc-windows-msvc -fuse-ld=link -### %s 2>&1 | 
FileCheck --check-prefix=ARM64EC %s
+// RUN: %clang_cl -arm64EC -fuse-ld=link -### %s 2>&1 | FileCheck 
--check-prefix=ARM64EC %s
+// ARM64EC: "-machine:arm64ec"
+
+// RUN: %clang -target arm64ec-pc-windows-msvc -fuse-ld=link -marm64x -### %s 
2>&1 | \
+// RUN:FileCheck --check-prefix=ARM64X %s
+// RUN: %clang -target aarch64-pc-windows-msvc -fuse-ld=link -marm64x -### %s 
2>&1 | \
+// RUN:FileCheck --check-prefix=ARM64X %s
+// RUN: %clang_cl -marm64x -fuse-ld=link -### %s 2>&1 | FileCheck 
--check-prefix=ARM64X %s
+// RUN: %clang_cl -arm64EC -marm64x -fuse-ld=link -### %s 2>&1 | FileCheck 
--check-prefix=ARM64X %s
+// ARM64X: "-machine:arm64x"
+
+// RUN: not %clang -target x86_64-linux-gnu -marm64x -### %s 2>&1 | FileCheck 
--check-prefix=HYBRID-ERR %s
+// HYBRID-ERR: error: unsupported option '-marm64x' for target 
'x86_64-linux-gnu'
+
+// RUN: %clang -c -marm64x  -target arm64ec-pc-windows-msvc -fuse-ld=link -### 
%s 2>&1 | \
+// RUN:FileCheck --check-prefix=HYBRID-WARN %s
+// HYBRID-WARN: warning: argument unused during compilation: '-marm64x' 
[-Wunused-command-line-argument]

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-28 Thread via cfe-commits


@@ -1127,9 +1148,9 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   // wb and WB are allowed, but a mixture of cases like Wb or wB is not. We
   // explicitly do not support the suffix in C++ as an extension because a
   // library-based UDL that resolves to a library type may be more
-  // appropriate there.
-  if (!LangOpts.CPlusPlus && ((s[0] == 'w' && s[1] == 'b') ||
-  (s[0] == 'W' && s[1] == 'B'))) {
+  // appropriate there. The same rules apply for __wb/__WB.
+  if ((!LangOpts.CPlusPlus || PossibleBitInt) &&
+  ((s[0] == 'w' && s[1] == 'b') || (s[0] == 'W' && s[1] == 'B'))) {

js324 wrote:

Would the existing test cases of `1__w` and `1.0_` in `bitint-constants.cpp` be 
enough to test this and the similar above comment?

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


  1   2   3   4   >