[clang] [analyzer] Fix crash on dereference invalid return value of getAdjustedParameterIndex() (PR #83585)

2024-03-04 Thread via cfe-commits

tomasz-kaminski-sonarsource wrote:

Thank you for creating the ticket, and fixing the issue. I am a bit concerned 
that the fix is hiding the symptoms and not the actual bug. After a bit of 
checking, I think the issue is caused by the fact that for the explicit object 
functions, we are creating a `CXXMemberOperatorCall` event, that performs 
parameter adjustment.
The corresponding code can be [found 
here](https://github.com/llvm/llvm-project/blob/c7fdd8c11e54585dc9d15d63de9742067e0506b9/clang/lib/StaticAnalyzer/Core/CallEvent.cpp#L1412):
```c++
 if (const auto *OpCE = dyn_cast(CE)) {
const FunctionDecl *DirectCallee = OpCE->getDirectCallee();
if (const auto *MD = dyn_cast(DirectCallee))
  if (MD->isInstance())  // <-- The root of the issue
return create(OpCE, State, LCtx, ElemRef);
  }
```
I think it would be fixed by replacing `MD->isInstance()` with  
`isImplicitObjectMemberFunction()`. This will make use fallback to 
`SimpleFunctionCall`.

That would make the behavior consistent with the behavior for other explicit 
object functions (deducing this). 
To illustrate we have the following code, the AST and produce call event are 
different:
```c++
struct Foo {
  void foo();
  void bar(this Foo&);
};

void test(Foo f) {
f.foo(); // represented as `CXXMemberCallExpr`, and creates`CXXMemberCall` 
event
f.bar(); // represented as `CallExpr`, and creates `SimpleFunctionCall` ente
}
```
Live link here: https://godbolt.org/z/sjEbb6rMe.

Would you be willing to adjust PR to implement suggested change? 

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


[clang] 7af4e8b - [clang][analyzer] Change default value of checker option in unix.StdCLibraryFunctions. (#80457)

2024-03-04 Thread via cfe-commits

Author: Balázs Kéri
Date: 2024-03-04T09:29:18+01:00
New Revision: 7af4e8bcc354d2bd7e46ecf547172b1f19ddde3e

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

LOG: [clang][analyzer] Change default value of checker option in 
unix.StdCLibraryFunctions. (#80457)

Default value of checker option `ModelPOSIX` is changed to `true`.
Documentation is updated.

Added: 


Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/test/Analysis/analyzer-config.c

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 899622ae283b17..fe211514914272 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1320,10 +1320,23 @@ range of the argument.
 
 **Parameters**
 
-The checker models functions (and emits diagnostics) from the C standard by
-default. The ``ModelPOSIX`` option enables modeling (and emit diagnostics) of
-additional functions that are defined in the POSIX standard. This option is
-disabled by default.
+The ``ModelPOSIX`` option controls if functions from the POSIX standard are
+recognized by the checker.
+
+With ``ModelPOSIX=true``, many POSIX functions are modeled according to the
+`POSIX standard`_. This includes ranges of parameters and possible return
+values. Furthermore the behavior related to ``errno`` in the POSIX case is
+often that ``errno`` is set only if a function call fails, and it becomes
+undefined after a successful function call.
+
+With ``ModelPOSIX=false``, this checker follows the C99 language standard and
+only models the functions that are described there. It is possible that the
+same functions are modeled 
diff erently in the two cases because 
diff erences in
+the standards. The C standard specifies less aspects of the functions, for
+example exact ``errno`` behavior is often unspecified (and not modeled by the
+checker).
+
+Default value of the option is ``true``.
 
 .. _osx-checkers:
 

diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index e7774e5a9392d2..a224b81c33a624 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -578,7 +578,7 @@ def StdCLibraryFunctionsChecker : 
Checker<"StdCLibraryFunctions">,
   "ModelPOSIX",
   "If set to true, the checker models additional functions "
   "from the POSIX standard.",
-  "false",
+  "true",
   InAlpha>
   ]>,
   WeakDependencies<[CallAndMessageChecker, NonNullParamChecker]>,

diff  --git a/clang/test/Analysis/analyzer-config.c 
b/clang/test/Analysis/analyzer-config.c
index 373017f4b18bfc..2167a2b32f5962 100644
--- a/clang/test/Analysis/analyzer-config.c
+++ b/clang/test/Analysis/analyzer-config.c
@@ -129,7 +129,7 @@
 // CHECK-NEXT: unix.DynamicMemoryModeling:Optimistic = false
 // CHECK-NEXT: unix.Errno:AllowErrnoReadOutsideConditionExpressions = true
 // CHECK-NEXT: unix.StdCLibraryFunctions:DisplayLoadedSummaries = false
-// CHECK-NEXT: unix.StdCLibraryFunctions:ModelPOSIX = false
+// CHECK-NEXT: unix.StdCLibraryFunctions:ModelPOSIX = true
 // CHECK-NEXT: unroll-loops = false
 // CHECK-NEXT: verbose-report-filename = false
 // CHECK-NEXT: widen-loops = false



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


[clang] [clang][analyzer] Change default value of checker option in unix.StdCLibraryFunctions. (PR #80457)

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

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


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

2024-03-04 Thread Fangrui Song via cfe-commits


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

MaskRay wrote:

Thanks for the update. We need at least 2 `internal thread_local` to trigger 
general dynamic => local dynamic optimization, and demonstrate that TLSDESC 
optimizes

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


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

2024-03-04 Thread Fangrui Song via cfe-commits

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


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

2024-03-04 Thread Fangrui Song via cfe-commits

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


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

2024-03-04 Thread Fangrui Song via cfe-commits

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


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

2024-03-04 Thread Fangrui Song via cfe-commits

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


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


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

2024-03-04 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple aarch64-none-none -mbranch-target-enforce 
-msign-return-address=all -fcxx-exceptions -fexceptions -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK

MaskRay wrote:

perhaps it's time to add CodeGenCXX/AArch64/ ? We have more target-specific 
directories under CodeGen.

Then the weird `arm64-` prefix (not recommended for ELF/Arm official) can be 
removed.

You can remove `-fcxx-exceptions -fexceptions` since they are unused`. `-triple 
aarch64-none-none` can just be `-triple aarch64`.

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


[clang] da5966e - Revert "[clang][analyzer] Change default value of checker option in unix.StdCLibraryFunctions. (#80457)"

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

Author: Balázs Kéri
Date: 2024-03-04T09:50:36+01:00
New Revision: da5966e0c102f03ab853b906377814675db3623c

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

LOG: Revert "[clang][analyzer] Change default value of checker option in 
unix.StdCLibraryFunctions. (#80457)"

This reverts commit 7af4e8bcc354d2bd7e46ecf547172b1f19ddde3e.

Added: 


Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/test/Analysis/analyzer-config.c

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index fe211514914272..899622ae283b17 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1320,23 +1320,10 @@ range of the argument.
 
 **Parameters**
 
-The ``ModelPOSIX`` option controls if functions from the POSIX standard are
-recognized by the checker.
-
-With ``ModelPOSIX=true``, many POSIX functions are modeled according to the
-`POSIX standard`_. This includes ranges of parameters and possible return
-values. Furthermore the behavior related to ``errno`` in the POSIX case is
-often that ``errno`` is set only if a function call fails, and it becomes
-undefined after a successful function call.
-
-With ``ModelPOSIX=false``, this checker follows the C99 language standard and
-only models the functions that are described there. It is possible that the
-same functions are modeled 
diff erently in the two cases because 
diff erences in
-the standards. The C standard specifies less aspects of the functions, for
-example exact ``errno`` behavior is often unspecified (and not modeled by the
-checker).
-
-Default value of the option is ``true``.
+The checker models functions (and emits diagnostics) from the C standard by
+default. The ``ModelPOSIX`` option enables modeling (and emit diagnostics) of
+additional functions that are defined in the POSIX standard. This option is
+disabled by default.
 
 .. _osx-checkers:
 

diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index a224b81c33a624..e7774e5a9392d2 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -578,7 +578,7 @@ def StdCLibraryFunctionsChecker : 
Checker<"StdCLibraryFunctions">,
   "ModelPOSIX",
   "If set to true, the checker models additional functions "
   "from the POSIX standard.",
-  "true",
+  "false",
   InAlpha>
   ]>,
   WeakDependencies<[CallAndMessageChecker, NonNullParamChecker]>,

diff  --git a/clang/test/Analysis/analyzer-config.c 
b/clang/test/Analysis/analyzer-config.c
index 2167a2b32f5962..373017f4b18bfc 100644
--- a/clang/test/Analysis/analyzer-config.c
+++ b/clang/test/Analysis/analyzer-config.c
@@ -129,7 +129,7 @@
 // CHECK-NEXT: unix.DynamicMemoryModeling:Optimistic = false
 // CHECK-NEXT: unix.Errno:AllowErrnoReadOutsideConditionExpressions = true
 // CHECK-NEXT: unix.StdCLibraryFunctions:DisplayLoadedSummaries = false
-// CHECK-NEXT: unix.StdCLibraryFunctions:ModelPOSIX = true
+// CHECK-NEXT: unix.StdCLibraryFunctions:ModelPOSIX = false
 // CHECK-NEXT: unroll-loops = false
 // CHECK-NEXT: verbose-report-filename = false
 // CHECK-NEXT: widen-loops = false



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


[clang] 5dc9e87 - [analyzer] Improve some comments in ArrayBoundCheckerV2 (NFC) (#83545)

2024-03-04 Thread via cfe-commits

Author: NagyDonat
Date: 2024-03-04T10:37:57+01:00
New Revision: 5dc9e87c8cae7842edcaa4dd01308873109208da

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

LOG:  [analyzer] Improve some comments in ArrayBoundCheckerV2 (NFC) (#83545)

This comment-only change fixes a typo, clarifies some comments and
includes some thoughts about the difficulties in resolving a certain
FIXME.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
index fdcc46e58580b4..29eb932584027d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -301,21 +301,27 @@ compareValueToThreshold(ProgramStateRef State, NonLoc 
Value, NonLoc Threshold,
   // calling `evalBinOpNN`:
   if (isNegative(SVB, State, Value) && isUnsigned(SVB, Threshold)) {
 if (CheckEquality) {
-  // negative_value == unsigned_value is always false
+  // negative_value == unsigned_threshold is always false
   return {nullptr, State};
 }
-// negative_value < unsigned_value is always false
+// negative_value < unsigned_threshold is always true
 return {State, nullptr};
   }
   if (isUnsigned(SVB, Value) && isNegative(SVB, State, Threshold)) {
-// unsigned_value == negative_value and unsigned_value < negative_value are
-// both always false
+// unsigned_value == negative_threshold and
+// unsigned_value < negative_threshold are both always false
 return {nullptr, State};
   }
-  // FIXME: these special cases are sufficient for handling real-world
+  // FIXME: These special cases are sufficient for handling real-world
   // comparisons, but in theory there could be contrived situations where
   // automatic conversion of a symbolic value (which can be negative and can be
   // positive) leads to incorrect results.
+  // NOTE: We NEED to use the `evalBinOpNN` call in the "common" case, because
+  // we want to ensure that assumptions coming from this precondition and
+  // assumptions coming from regular C/C++ operator calls are represented by
+  // constraints on the same symbolic expression. A solution that would
+  // evaluate these "mathematical" compariosns through a separate pathway would
+  // be a step backwards in this sense.
 
   const BinaryOperatorKind OpKind = CheckEquality ? BO_EQ : BO_LT;
   auto BelowThreshold =



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


[clang] [analyzer] Improve some comments in ArrayBoundCheckerV2 (NFC) (PR #83545)

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


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


[clang] [clang-format][doc] fix documentation for clang-format (PR #83415)

2024-03-04 Thread via cfe-commits

https://github.com/PeterChou1 updated 
https://github.com/llvm/llvm-project/pull/83415

>From 67154ff4388447ff78b2912e5635231778ed23d4 Mon Sep 17 00:00:00 2001
From: PeterChou1 <4355+peterch...@users.noreply.github.com>
Date: Thu, 29 Feb 2024 06:55:18 -0500
Subject: [PATCH 1/3] [clang][Documentation] fix documentation for clang-format

Fixes typo related to clang-format

see: https://github.com/llvm/llvm-project/issues/83207
---
 clang/docs/ClangFormatStyleOptions.rst | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index df399a229d8d4f..5b00a8f4c00fb8 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -318,9 +318,9 @@ the configuration (without a prefix: ``Auto``).
 
   .. code-block:: c++
 
-AlignConsecutiveMacros: AcrossEmptyLines
+AlignConsecutiveAssignments: AcrossEmptyLines
 
-AlignConsecutiveMacros:
+AlignConsecutiveAssignments:
   Enabled: true
   AcrossEmptyLines: true
   AcrossComments: false
@@ -460,9 +460,9 @@ the configuration (without a prefix: ``Auto``).
 
   .. code-block:: c++
 
-AlignConsecutiveMacros: AcrossEmptyLines
+AlignConsecutiveBitFields: AcrossEmptyLines
 
-AlignConsecutiveMacros:
+AlignConsecutiveBitFields:
   Enabled: true
   AcrossEmptyLines: true
   AcrossComments: false
@@ -602,9 +602,9 @@ the configuration (without a prefix: ``Auto``).
 
   .. code-block:: c++
 
-AlignConsecutiveMacros: AcrossEmptyLines
+AlignConsecutiveDeclarations: AcrossEmptyLines
 
-AlignConsecutiveMacros:
+AlignConsecutiveDeclarations:
   Enabled: true
   AcrossEmptyLines: true
   AcrossComments: false
@@ -983,9 +983,9 @@ the configuration (without a prefix: ``Auto``).
 
   .. code-block:: c++
 
-AlignConsecutiveMacros: AcrossEmptyLines
+AlignConsecutiveTableGenCondOperatorColons: AcrossEmptyLines
 
-AlignConsecutiveMacros:
+AlignConsecutiveTableGenCondOperatorColons:
   Enabled: true
   AcrossEmptyLines: true
   AcrossComments: false
@@ -1123,9 +1123,9 @@ the configuration (without a prefix: ``Auto``).
 
   .. code-block:: c++
 
-AlignConsecutiveMacros: AcrossEmptyLines
+AlignConsecutiveTableGenDefinitionColons: AcrossEmptyLines
 
-AlignConsecutiveMacros:
+AlignConsecutiveTableGenDefinitionColons:
   Enabled: true
   AcrossEmptyLines: true
   AcrossComments: false

>From 8a18ecf65497070ddced018fae39e330019b482f Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 1 Mar 2024 13:31:13 -0500
Subject: [PATCH 2/3] [clang-format][doc] fix typo in doc generation for
 clang-format docs

---
 clang/docs/tools/dump_format_style.py | 1 +
 clang/include/clang/Format/Format.h   | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index af0124b94ecaf1..f45e83d432b117 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -129,6 +129,7 @@ def __str__(self):
 s += indent(
 "\n\nNested configuration flags:\n\n%s\n" % 
self.nested_struct, 2
 )
+s = s.replace("[[[NAME]]]", self.name)
 return s
 
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 613f1fd168465d..4c5728264bf658 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -154,9 +154,9 @@ struct FormatStyle {
   /// For example, to align across empty lines and not across comments, either
   /// of these work.
   /// \code
-  ///   AlignConsecutiveMacros: AcrossEmptyLines
+  ///   [[[NAME]]]: AcrossEmptyLines
   ///
-  ///   AlignConsecutiveMacros:
+  ///   [[[NAME]]]:
   /// Enabled: true
   /// AcrossEmptyLines: true
   /// AcrossComments: false

>From b64e732f00832740ff34bd9327e8cd6358ebc400 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Mon, 4 Mar 2024 04:38:24 -0500
Subject: [PATCH 3/3] [clang-format][doc] rename doc generation script name

---
 clang/docs/tools/dump_format_style.py | 2 +-
 clang/include/clang/Format/Format.h   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index f45e83d432b117..af0e658fcdc55d 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -129,7 +129,7 @@ def __str__(self):
 s += indent(
 "\n\nNested configuration flags:\n\n%s\n" % 
self.nested_struct, 2
 )
-s = s.replace("[[[NAME]]]", self.name)
+s = s.replace("", self.name)
 return s
 
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4c5728264bf658..590297fd89a398 100644
--- a/clang/include/clang/Format/Format.h

[clang] [clang-format][doc] fix documentation for clang-format (PR #83415)

2024-03-04 Thread via cfe-commits

PeterChou1 wrote:

> > So I did added a simple search and replace to the generating script so now 
> > every time [[[NAME]]] is reference it will use the members name.
> 
> Nice! Though why `[[[NAME]]]` in particular? Can we use `` 
> instead?

done

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


[clang] [clang] Add -Wmissing-designated-field-initializers (PR #81364)

2024-03-04 Thread Vadim D. via cfe-commits

https://github.com/vvd170501 updated 
https://github.com/llvm/llvm-project/pull/81364

>From f73060f7f09a747c90fa559641abd8c72f4ee66f Mon Sep 17 00:00:00 2001
From: vvd170501 <36827317+vvd170...@users.noreply.github.com>
Date: Sat, 10 Feb 2024 19:19:52 +0300
Subject: [PATCH 1/4] Add -Wmissing-designated-field-initializers, decide
 whether to skip m-f-i check only when needed

---
 clang/include/clang/Basic/DiagnosticGroups.td | 10 +++-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/Sema/SemaInit.cpp   | 50 ++-
 .../SemaCXX/cxx2a-initializer-aggregates.cpp  | 11 ++--
 4 files changed, 45 insertions(+), 30 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index e8b4139d7893ce..0791a0002319de 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -517,7 +517,15 @@ def MethodSignatures : DiagGroup<"method-signatures">;
 def MismatchedParameterTypes : DiagGroup<"mismatched-parameter-types">;
 def MismatchedReturnTypes : DiagGroup<"mismatched-return-types">;
 def MismatchedTags : DiagGroup<"mismatched-tags">;
-def MissingFieldInitializers : DiagGroup<"missing-field-initializers">;
+def MissingDesignatedFieldInitializers : 
DiagGroup<"missing-designated-field-initializers">{
+  code Documentation = [{
+Warn about designated initializers with some fields missing (only in C++).
+  }];
+}
+// Default -Wmissing-field-initializers matches gcc behavior,
+// but missing-designated-field-initializers can be turned off to match old 
clang behavior.
+def MissingFieldInitializers : DiagGroup<"missing-field-initializers",
+ [MissingDesignatedFieldInitializers]>;
 def ModuleLock : DiagGroup<"module-lock">;
 def ModuleBuild : DiagGroup<"module-build">;
 def ModuleImport : DiagGroup<"module-import">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 91105d4231f06a..8cf58299602ec7 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6167,6 +6167,10 @@ def ext_initializer_string_for_char_array_too_long : 
ExtWarn<
 def warn_missing_field_initializers : Warning<
   "missing field %0 initializer">,
   InGroup, DefaultIgnore;
+// The same warning, but another group is needed to disable it separately.
+def warn_missing_designated_field_initializers : Warning<
+  "missing field %0 initializer">,
+  InGroup, DefaultIgnore;
 def warn_braces_around_init : Warning<
   "braces around %select{scalar |}0initializer">,
   InGroup>;
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 0fd458837163e5..3227f16dd0c1ce 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -2227,8 +2227,6 @@ void InitListChecker::CheckStructUnionTypes(
   size_t NumRecordDecls = llvm::count_if(RD->decls(), [&](const Decl *D) {
 return isa(D) || isa(D);
   });
-  bool CheckForMissingFields =
-!IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
   bool HasDesignatedInit = false;
 
   llvm::SmallPtrSet InitializedFields;
@@ -2269,11 +2267,6 @@ void InitListChecker::CheckStructUnionTypes(
   }
 
   InitializedSomething = true;
-
-  // Disable check for missing fields when designators are used.
-  // This matches gcc behaviour.
-  if (!SemaRef.getLangOpts().CPlusPlus)
-CheckForMissingFields = false;
   continue;
 }
 
@@ -2285,7 +2278,7 @@ void InitListChecker::CheckStructUnionTypes(
 // These are okay for randomized structures. [C99 6.7.8p19]
 //
 // Also, if there is only one element in the structure, we allow something
-// like this, because it's really not randomized in the tranditional sense.
+// like this, because it's really not randomized in the traditional sense.
 //
 //   struct foo h = {bar};
 auto IsZeroInitializer = [&](const Expr *I) {
@@ -2363,23 +2356,32 @@ void InitListChecker::CheckStructUnionTypes(
   }
 
   // Emit warnings for missing struct field initializers.
-  if (!VerifyOnly && InitializedSomething && CheckForMissingFields &&
-  !RD->isUnion()) {
-// It is possible we have one or more unnamed bitfields remaining.
-// Find first (if any) named field and emit warning.
-for (RecordDecl::field_iterator it = HasDesignatedInit ? RD->field_begin()
-   : Field,
-end = RD->field_end();
- it != end; ++it) {
-  if (HasDesignatedInit && InitializedFields.count(*it))
-continue;
+  if (!VerifyOnly && InitializedSomething && !RD->isUnion()) {
+// Disable missing fields check for:
+// - Zero initializers
+// - Designated initializers (only in C). This matches gcc behaviour.
+bool DisableCheck =
+IList->isIdiomaticZeroInitializer(

[clang] [llvm] [AArch64][PAC] Support ptrauth builtins and -fptrauth-intrinsics. (PR #65996)

2024-03-04 Thread Kristof Beyls via cfe-commits

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

I just read through the documentation parts of this PR again.
I think that the quality is more than good enough to land, even though there 
are a few very minor remarks by myself and @DavidSpickett seemingly still open.

I haven't looked again at the details of the implementation, but remember 
having gone through it quite a long time ago. I'm happy for this PR to land.

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


[clang] [llvm] [AArch64][PAC] Support ptrauth builtins and -fptrauth-intrinsics. (PR #65996)

2024-03-04 Thread Kristof Beyls via cfe-commits


@@ -0,0 +1,485 @@
+Pointer Authentication
+==
+
+.. contents::
+   :local:
+
+Introduction
+
+
+Pointer authentication is a technology which offers strong probabilistic
+protection against exploiting a broad class of memory bugs to take control of
+program execution.  When adopted consistently in a language ABI, it provides
+a form of relatively fine-grained control flow integrity (CFI) check that
+resists both return-oriented programming (ROP) and jump-oriented programming
+(JOP) attacks.
+
+While pointer authentication can be implemented purely in software, direct
+hardware support (e.g. as provided by Armv8.3 PAuth) can dramatically improve
+performance and code size.  Similarly, while pointer authentication
+can be implemented on any architecture, taking advantage of the (typically)
+excess addressing range of a target with 64-bit pointers minimizes the impact
+on memory performance and can allow interoperation with existing code (by
+disabling pointer authentication dynamically).  This document will generally
+attempt to present the pointer authentication feature independent of any
+hardware implementation or ABI.  Considerations that are
+implementation-specific are clearly identified throughout.
+
+Note that there are several different terms in use:
+
+- **Pointer authentication** is a target-independent language technology.
+
+- **PAuth** (sometimes referred to as **PAC**, for Pointer Authentication
+  Codes) is an AArch64 architecture extension that provides hardware support
+  for pointer authentication.  Additional extensions either modify some of the
+  PAuth instruction behavior (notably FPAC), or provide new instruction
+  variants (PAuth_LR).
+
+- **Armv8.3** is an AArch64 architecture revision that makes PAuth mandatory.
+
+- **arm64e** is a specific ABI (not yet fully stable) for implementing pointer
+  authentication using PAuth on certain Apple operating systems.
+
+This document serves four purposes:
+
+- It describes the basic ideas of pointer authentication.
+
+- It documents several language extensions that are useful on targets using
+  pointer authentication.
+
+- It will eventually present a theory of operation for the security mitigation,
+  describing the basic requirements for correctness, various weaknesses in the
+  mechanism, and ways in which programmers can strengthen its protections
+  (including recommendations for language implementors).
+
+- It will eventually document the language ABIs currently used for C, C++,
+  Objective-C, and Swift on arm64e, although these are not yet stable on any
+  target.
+
+Basic Concepts
+--
+
+The simple address of an object or function is a **raw pointer**.  A raw
+pointer can be **signed** to produce a **signed pointer**.  A signed pointer
+can be then **authenticated** in order to verify that it was **validly signed**
+and extract the original raw pointer.  These terms reflect the most likely
+implementation technique: computing and storing a cryptographic signature along
+with the pointer.
+
+An **abstract signing key** is a name which refers to a secret key which can
+used to sign and authenticate pointers.  The concrete key value for a

kbeyls wrote:

s/can used/is used/?

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


[clang] [llvm] [AArch64][PAC] Support ptrauth builtins and -fptrauth-intrinsics. (PR #65996)

2024-03-04 Thread Kristof Beyls via cfe-commits

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


[clang] [clang][RISCV] Support function attribute __attribute__((target("+attr"))) (PR #83674)

2024-03-04 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/83674

>From f14c54cb7c3c31e84a78ddf33b932c4c74e20365 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Fri, 1 Mar 2024 09:52:35 -0800
Subject: [PATCH 1/2] [clang][RISCV] Enable RVV with function attribute
 __attribute__((target("arch=+v")))

It is currently not possible to use "RVV type" and "RVV intrinsics" if
the "zve32x" is not enabled globally. However in some cases we may want
to use them only in some functions, for instance:
```
#include 

__attribute__((target("+zve32x")))
vint32m1_t rvv_add(vint32m1_t v1, vint32m1_t v2, size_t vl) {
  return __riscv_vadd(v1, v2, vl);
}

int other_add(int i1, int i2) {
  return i1 + i2;
}
```
, it is supposed to be compilable even the vector is not specified, e.g.
`clang -target riscv64 -march=rv64gc -S test.c`.
---
 clang/include/clang/Sema/Sema.h   |  3 +-
 clang/lib/Basic/Targets/RISCV.cpp |  3 +-
 clang/lib/Sema/Sema.cpp   |  7 +-
 clang/lib/Sema/SemaChecking.cpp   | 70 +++
 clang/lib/Sema/SemaDecl.cpp   |  9 ++-
 .../RISCV/rvb-intrinsics/riscv32-zbb-error.c  |  4 +-
 .../RISCV/rvb-intrinsics/riscv64-zbkb-error.c | 12 ++--
 .../rvv-intrinsics-handcrafted/rvv-error.c|  2 +-
 clang/test/Sema/riscv-function-target-attr.c  | 41 +++
 clang/utils/TableGen/RISCVVEmitter.cpp|  4 --
 10 files changed, 73 insertions(+), 82 deletions(-)
 create mode 100644 clang/test/Sema/riscv-function-target-attr.c

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ef4b93fac95ce5..932b76c82af0ee 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14067,7 +14067,8 @@ class Sema final {
   bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum);
   bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
  CallExpr *TheCall);
-  void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D);
+  void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D,
+   const llvm::StringMap &FeatureMap);
   bool CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI,
  unsigned BuiltinID, CallExpr 
*TheCall);
   bool CheckWebAssemblyBuiltinFunctionCall(const TargetInfo &TI,
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index a6d4af2b88111a..6991caa21d23b4 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -463,7 +463,8 @@ ParsedTargetAttr RISCVTargetInfo::parseTargetAttr(StringRef 
Features) const {
 Ret.Duplicate = "tune=";
 
   Ret.Tune = AttrString;
-}
+} else if (Feature.starts_with("+"))
+  Ret.Features.push_back(Feature.str());
   }
   return Ret;
 }
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index cfb653e665ea03..41c7bfb25a7921 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2077,8 +2077,11 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 targetDiag(D->getLocation(), diag::note_defined_here, FD) << D;
 }
 
-if (TI.hasRISCVVTypes() && Ty->isRVVSizelessBuiltinType())
-  checkRVVTypeSupport(Ty, Loc, D);
+if (TI.hasRISCVVTypes() && Ty->isRVVSizelessBuiltinType() && FD) {
+  llvm::StringMap CallerFeatureMap;
+  Context.getFunctionFeatureMap(CallerFeatureMap, FD);
+  checkRVVTypeSupport(Ty, Loc, D, CallerFeatureMap);
+}
 
 // Don't allow SVE types in functions without a SVE target.
 if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) {
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0d4d57db01c93a..50afb56ae09eac 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5415,57 +5415,6 @@ static bool CheckInvalidVLENandLMUL(const TargetInfo 
&TI, CallExpr *TheCall,
 bool Sema::CheckRISCVBuiltinFunctionCall(const TargetInfo &TI,
  unsigned BuiltinID,
  CallExpr *TheCall) {
-  // CodeGenFunction can also detect this, but this gives a better error
-  // message.
-  bool FeatureMissing = false;
-  SmallVector ReqFeatures;
-  StringRef Features = Context.BuiltinInfo.getRequiredFeatures(BuiltinID);
-  Features.split(ReqFeatures, ',', -1, false);
-
-  // Check if each required feature is included
-  for (StringRef F : ReqFeatures) {
-SmallVector ReqOpFeatures;
-F.split(ReqOpFeatures, '|');
-
-if (llvm::none_of(ReqOpFeatures,
-  [&TI](StringRef OF) { return TI.hasFeature(OF); })) {
-  std::string FeatureStrs;
-  bool IsExtension = true;
-  for (StringRef OF : ReqOpFeatures) {
-// If the feature is 64bit, alter the string so it will print better in
-// the diagnostic.
-if (OF == "64bit") {
-

[clang] [clang][RISCV] Enable RVV with function attribute __attribute__((target("+attr"))) (PR #83674)

2024-03-04 Thread Brandon Wu via cfe-commits

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


[clang] [clang][RISCV] Enable RVV with function attribute __attribute__((target("arch=+v"))) (PR #83674)

2024-03-04 Thread Brandon Wu via cfe-commits

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


[clang] [clang][RISCV] Enable RVV with function attribute __attribute__((target("arch=+v"))) (PR #83674)

2024-03-04 Thread Brandon Wu via cfe-commits


@@ -0,0 +1,41 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple riscv64 -S -verify %s
+
+// REQUIRES: riscv-registered-target
+#include 
+
+void test_builtin() {
+  __riscv_vsetvl_e8m8(1); // expected-error {{'__builtin_rvv_vsetvli' needs 
target feature zve32x}}
+}
+
+__attribute__((target("+zve32x")))

4vtomat wrote:

Updated thanks!

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


[clang] [clang][RISCV] Enable RVV with function attribute __attribute__((target("arch=+v"))) (PR #83674)

2024-03-04 Thread Brandon Wu via cfe-commits


@@ -463,7 +463,8 @@ ParsedTargetAttr RISCVTargetInfo::parseTargetAttr(StringRef 
Features) const {
 Ret.Duplicate = "tune=";
 
   Ret.Tune = AttrString;
-}
+} else if (Feature.starts_with("+"))

4vtomat wrote:

Updated!

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


[clang-tools-extra] [clangd] Allow "move function body out-of-line" in non-header files (PR #69704)

2024-03-04 Thread Christian Kandeler via cfe-commits

ckandeler wrote:

ping

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


[clang] [llvm] [HLSL] implement `mad` intrinsic (PR #83826)

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

https://github.com/farzonl created 
https://github.com/llvm/llvm-project/pull/83826

This change implements #83736
The dot product lowering needs a tertiary multipy add operation. DXIL has three 
mad opcodes for `fmad`(46), `imad`(48), and `umad`(49). Dot product in DXIL 
only uses `imad`\ `umad`, but for completeness and because the hlsl `mad` 
intrinsic requires it `fmad` was also included. Two new intrinsics were needed 
to be created to complete this change. the `fmad` case already supported by 
llvm via `fmuladd` intrinsic.

- `hlsl_intrinsics.h` - exposed mad api call.
- `Builtins.td` - exposed a `mad` builtin.
- `Sema.h` - make `tertiary` calls check for float types optional. 
- `CGBuiltin.cpp` - pick the intrinsic for singed\unsigned & float also reuse 
`int_fmuladd`. 
- `SemaChecking.cpp` - type checks for `__builtin_hlsl_mad`. 
- `IntrinsicsDirectX.td` create the two new intrinsics for `imad`\`umad`/ 
- `DXIL.td` - create the llvm intrinsic to  `DXIL` opcode mapping.

>From 410a00aa96f23e99727b2d6b8aa0fa02441d5ecc Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Sat, 2 Mar 2024 16:40:39 -0500
Subject: [PATCH] [HLSL] implement mad intrinsic This change implements #83736
 The dot product lowering needs a tertiary multipy addoperation. DXIL has
 three mad opcodes for fmad(46), imad(48), and umad(49). Dot product in DXIL
 only uses imad\umad, but for completeness fmad was also included. Two new
 intrinsics needed to be created to complete this change. the fmad case
 already existed.

hlsl_intrinsics.h - exposed mad api call.
Builtins.td - exposed a mad builtin.
Sema.h - make tertiary calls check for float types optional.
CGBuiltin.cpp - pick the intrinsic for singed\unsigned & float also reuse 
int_fmuladd.
SemaChecking.cpp - type checks for __builtin_hlsl_mad.
IntrinsicsDirectX.td create the two new intrinsics for imad\umad/
DXIL.td - create the llvm intrinsic to  DXIL opcode mapping.
---
 clang/include/clang/Basic/Builtins.td|   6 +
 clang/include/clang/Sema/Sema.h  |   2 +-
 clang/lib/CodeGen/CGBuiltin.cpp  |  19 ++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h | 105 ++
 clang/lib/Sema/SemaChecking.cpp  |  22 ++-
 clang/test/CodeGenHLSL/builtins/mad.hlsl | 197 +++
 clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl |  86 
 llvm/include/llvm/IR/IntrinsicsDirectX.td|   4 +
 llvm/lib/Target/DirectX/DXIL.td  |   6 +
 llvm/test/CodeGen/DirectX/fmad.ll|  67 +++
 llvm/test/CodeGen/DirectX/imad.ll|  65 ++
 llvm/test/CodeGen/DirectX/umad.ll|  65 ++
 12 files changed, 637 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/mad.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/fmad.ll
 create mode 100644 llvm/test/CodeGen/DirectX/imad.ll
 create mode 100644 llvm/test/CodeGen/DirectX/umad.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 2c83dca248fb7d..c4f466208793ea 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4548,6 +4548,12 @@ def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLMad : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_mad"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ef4b93fac95ce5..88be7dd90d21bc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14132,7 +14132,7 @@ class Sema final {
   bool SemaBuiltinVectorMath(CallExpr *TheCall, QualType &Res);
   bool SemaBuiltinVectorToScalarMath(CallExpr *TheCall);
   bool SemaBuiltinElementwiseMath(CallExpr *TheCall);
-  bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall);
+  bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall, bool 
enforceFloatingPointCheck = true);
   bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall);
   bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall);
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e90014261217bc..5cb1dd07aab999 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18057,6 +18057,25 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType*/ Op0->getType(), Intrinsic::dx_frac,
 ArrayRef{Op0}, nullptr, "dx.frac");
   }
+  case Builtin::BI__builtin_hlsl_mad: {
+Value *M = EmitScalarExpr(E->getArg(0));
+Value *A = EmitScalarExpr(E->getArg(1));
+Value *B = EmitScalarExpr(E->getArg(2));
+if (E->getArg(0)->getType()->hasFloatingRepresentation()) {
+  return Builder.CreateIntrinsic(
+  /*ReturnType*/ M->getType(),

[clang] [llvm] [HLSL] implement `mad` intrinsic (PR #83826)

2024-03-04 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-x86
@llvm/pr-subscribers-backend-directx
@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-clang

Author: Farzon Lotfi (farzonl)


Changes

This change implements #83736
The dot product lowering needs a tertiary multipy add operation. DXIL has three 
mad opcodes for `fmad`(46), `imad`(48), and `umad`(49). Dot product in DXIL 
only uses `imad`\ `umad`, but for completeness and because the hlsl `mad` 
intrinsic requires it `fmad` was also included. Two new intrinsics were needed 
to be created to complete this change. the `fmad` case already supported by 
llvm via `fmuladd` intrinsic.

- `hlsl_intrinsics.h` - exposed mad api call.
- `Builtins.td` - exposed a `mad` builtin.
- `Sema.h` - make `tertiary` calls check for float types optional. 
- `CGBuiltin.cpp` - pick the intrinsic for singed\unsigned & float also 
reuse `int_fmuladd`. 
- `SemaChecking.cpp` - type checks for `__builtin_hlsl_mad`. 
- `IntrinsicsDirectX.td` create the two new intrinsics for `imad`\`umad`/ 
- `DXIL.td` - create the llvm intrinsic to  `DXIL` opcode mapping.

---

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


12 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+6) 
- (modified) clang/include/clang/Sema/Sema.h (+1-1) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+19) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+105) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+16-6) 
- (added) clang/test/CodeGenHLSL/builtins/mad.hlsl (+197) 
- (added) clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl (+86) 
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+4) 
- (modified) llvm/lib/Target/DirectX/DXIL.td (+6) 
- (added) llvm/test/CodeGen/DirectX/fmad.ll (+67) 
- (added) llvm/test/CodeGen/DirectX/imad.ll (+65) 
- (added) llvm/test/CodeGen/DirectX/umad.ll (+65) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 2c83dca248fb7d..c4f466208793ea 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4548,6 +4548,12 @@ def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLMad : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_mad"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ef4b93fac95ce5..88be7dd90d21bc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14132,7 +14132,7 @@ class Sema final {
   bool SemaBuiltinVectorMath(CallExpr *TheCall, QualType &Res);
   bool SemaBuiltinVectorToScalarMath(CallExpr *TheCall);
   bool SemaBuiltinElementwiseMath(CallExpr *TheCall);
-  bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall);
+  bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall, bool 
enforceFloatingPointCheck = true);
   bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall);
   bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall);
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e90014261217bc..5cb1dd07aab999 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18057,6 +18057,25 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType*/ Op0->getType(), Intrinsic::dx_frac,
 ArrayRef{Op0}, nullptr, "dx.frac");
   }
+  case Builtin::BI__builtin_hlsl_mad: {
+Value *M = EmitScalarExpr(E->getArg(0));
+Value *A = EmitScalarExpr(E->getArg(1));
+Value *B = EmitScalarExpr(E->getArg(2));
+if (E->getArg(0)->getType()->hasFloatingRepresentation()) {
+  return Builder.CreateIntrinsic(
+  /*ReturnType*/ M->getType(), Intrinsic::fmuladd,
+  ArrayRef{M, A, B}, nullptr, "dx.fmad");
+}
+if (E->getArg(0)->getType()->hasSignedIntegerRepresentation()) {
+  return Builder.CreateIntrinsic(
+  /*ReturnType*/ M->getType(), Intrinsic::dx_imad,
+  ArrayRef{M, A, B}, nullptr, "dx.imad");
+}
+assert(E->getArg(0)->getType()->hasUnsignedIntegerRepresentation());
+return Builder.CreateIntrinsic(
+/*ReturnType*/ M->getType(), Intrinsic::dx_umad,
+ArrayRef{M, A, B}, nullptr, "dx.umad");
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 5180530363889f..b5bef78fae72fe 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -511,6 +511,111 @@ double3 log2(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_log2)
 double4 log2(double4);
 
+//===--===//
+// mad builtins
+//===

[clang] [llvm] [HLSL] implement `mad` intrinsic (PR #83826)

2024-03-04 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff e6e53ca8470d719882539359ebe3ad8b442a8cb0 
410a00aa96f23e99727b2d6b8aa0fa02441d5ecc -- clang/include/clang/Sema/Sema.h 
clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Headers/hlsl/hlsl_intrinsics.h 
clang/lib/Sema/SemaChecking.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 88be7dd90d..f44ded4481 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14132,7 +14132,8 @@ private:
   bool SemaBuiltinVectorMath(CallExpr *TheCall, QualType &Res);
   bool SemaBuiltinVectorToScalarMath(CallExpr *TheCall);
   bool SemaBuiltinElementwiseMath(CallExpr *TheCall);
-  bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall, bool 
enforceFloatingPointCheck = true);
+  bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall,
+ bool enforceFloatingPointCheck = 
true);
   bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall);
   bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall);
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 795d59ed5f..f5f6617fb2 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -19808,7 +19808,8 @@ bool Sema::SemaBuiltinVectorMath(CallExpr *TheCall, 
QualType &Res) {
   return false;
 }
 
-bool Sema::SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall, bool 
enforceFloatingPointCheck) {
+bool Sema::SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall,
+ bool enforceFloatingPointCheck) {
   if (checkArgCount(*this, TheCall, 3))
 return true;
 
@@ -19820,11 +19821,11 @@ bool Sema::SemaBuiltinElementwiseTernaryMath(CallExpr 
*TheCall, bool enforceFloa
 Args[I] = Converted.get();
   }
 
-  if(enforceFloatingPointCheck) {
+  if (enforceFloatingPointCheck) {
 int ArgOrdinal = 1;
 for (Expr *Arg : Args) {
-  if (checkFPMathBuiltinElementType(*this, Arg->getBeginLoc(), 
Arg->getType(),
-ArgOrdinal++))
+  if (checkFPMathBuiltinElementType(*this, Arg->getBeginLoc(),
+Arg->getType(), ArgOrdinal++))
 return true;
 }
   }

``




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


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-04 Thread Sergio Afonso via cfe-commits


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

skatrak wrote:

> Leafs is an accepted form.

Could you point to some source where that's described? After a quick search, I 
find that "leaves" is the widely accepted plural of "leaf", and that "leafs" is 
only recognized by certain dictionaries. One instance where it's not: 
https://dictionary.cambridge.org/dictionary/english/leaf.

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


[clang] [llvm] [HLSL] implement `mad` intrinsic (PR #83826)

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

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/83826

>From 410a00aa96f23e99727b2d6b8aa0fa02441d5ecc Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Sat, 2 Mar 2024 16:40:39 -0500
Subject: [PATCH 1/2] [HLSL] implement mad intrinsic This change implements
 #83736 The dot product lowering needs a tertiary multipy addoperation. DXIL
 has three mad opcodes for fmad(46), imad(48), and umad(49). Dot product in
 DXIL only uses imad\umad, but for completeness fmad was also included. Two
 new intrinsics needed to be created to complete this change. the fmad case
 already existed.

hlsl_intrinsics.h - exposed mad api call.
Builtins.td - exposed a mad builtin.
Sema.h - make tertiary calls check for float types optional.
CGBuiltin.cpp - pick the intrinsic for singed\unsigned & float also reuse 
int_fmuladd.
SemaChecking.cpp - type checks for __builtin_hlsl_mad.
IntrinsicsDirectX.td create the two new intrinsics for imad\umad/
DXIL.td - create the llvm intrinsic to  DXIL opcode mapping.
---
 clang/include/clang/Basic/Builtins.td|   6 +
 clang/include/clang/Sema/Sema.h  |   2 +-
 clang/lib/CodeGen/CGBuiltin.cpp  |  19 ++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h | 105 ++
 clang/lib/Sema/SemaChecking.cpp  |  22 ++-
 clang/test/CodeGenHLSL/builtins/mad.hlsl | 197 +++
 clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl |  86 
 llvm/include/llvm/IR/IntrinsicsDirectX.td|   4 +
 llvm/lib/Target/DirectX/DXIL.td  |   6 +
 llvm/test/CodeGen/DirectX/fmad.ll|  67 +++
 llvm/test/CodeGen/DirectX/imad.ll|  65 ++
 llvm/test/CodeGen/DirectX/umad.ll|  65 ++
 12 files changed, 637 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/mad.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/mad-errors.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/fmad.ll
 create mode 100644 llvm/test/CodeGen/DirectX/imad.ll
 create mode 100644 llvm/test/CodeGen/DirectX/umad.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 2c83dca248fb7d..c4f466208793ea 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4548,6 +4548,12 @@ def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLMad : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_mad"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ef4b93fac95ce5..88be7dd90d21bc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14132,7 +14132,7 @@ class Sema final {
   bool SemaBuiltinVectorMath(CallExpr *TheCall, QualType &Res);
   bool SemaBuiltinVectorToScalarMath(CallExpr *TheCall);
   bool SemaBuiltinElementwiseMath(CallExpr *TheCall);
-  bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall);
+  bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall, bool 
enforceFloatingPointCheck = true);
   bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall);
   bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall);
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e90014261217bc..5cb1dd07aab999 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18057,6 +18057,25 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType*/ Op0->getType(), Intrinsic::dx_frac,
 ArrayRef{Op0}, nullptr, "dx.frac");
   }
+  case Builtin::BI__builtin_hlsl_mad: {
+Value *M = EmitScalarExpr(E->getArg(0));
+Value *A = EmitScalarExpr(E->getArg(1));
+Value *B = EmitScalarExpr(E->getArg(2));
+if (E->getArg(0)->getType()->hasFloatingRepresentation()) {
+  return Builder.CreateIntrinsic(
+  /*ReturnType*/ M->getType(), Intrinsic::fmuladd,
+  ArrayRef{M, A, B}, nullptr, "dx.fmad");
+}
+if (E->getArg(0)->getType()->hasSignedIntegerRepresentation()) {
+  return Builder.CreateIntrinsic(
+  /*ReturnType*/ M->getType(), Intrinsic::dx_imad,
+  ArrayRef{M, A, B}, nullptr, "dx.imad");
+}
+assert(E->getArg(0)->getType()->hasUnsignedIntegerRepresentation());
+return Builder.CreateIntrinsic(
+/*ReturnType*/ M->getType(), Intrinsic::dx_umad,
+ArrayRef{M, A, B}, nullptr, "dx.umad");
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 5180530363889f..b5bef78fae72fe 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -511,6 +511,111 @@ double3 log2(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_log2)
 double4 log2(doub

[clang] [Clang][Docs] Simpler syntax for Github links. (PR #82746)

2024-03-04 Thread via cfe-commits

cor3ntin wrote:

@AaronBallman ping

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


[clang] [flang] [llvm] [Docs] Allow building man pages without myst_parser (PR #82402)

2024-03-04 Thread via cfe-commits

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

>From 0cb108fa6552b112d5eeb9b82e4f57711fac4a35 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Tue, 20 Feb 2024 19:44:06 +0100
Subject: [PATCH 1/2] [Docs] Allow building man pages without myst_parser

The pan pages do not depend on the doc present in markdown files,
so they can be built without myst_parser.
Doing so might allow llvm distributions to have less development
dependencies.

As we do not have the ennvironment to test these configuration, this
capability is provided on a best-effort basis.

This restores a capability accidentally lost in #65664.
---
 clang/docs/conf.py | 12 ++--
 flang/docs/conf.py | 12 +++-
 llvm/docs/conf.py  | 12 +++-
 3 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/clang/docs/conf.py b/clang/docs/conf.py
index 31a4daa39d5b8e..44fd743dc0173f 100644
--- a/clang/docs/conf.py
+++ b/clang/docs/conf.py
@@ -35,8 +35,16 @@
 
 import sphinx
 
-if sphinx.version_info >= (3, 0):
-extensions.append("myst_parser")
+# When building man pages, we do not use the markdown pages,
+# So, we can continue without the myst_parser dependencies.
+# Doing so reduces dependencies of some packaged llvm distributions.
+try:
+  import myst_parser
+  extensions.append("myst_parser")
+except ImportError:
+  if not tags.has("builder-man"):
+raise
+
 
 # The encoding of source files.
 # source_encoding = 'utf-8-sig'
diff --git a/flang/docs/conf.py b/flang/docs/conf.py
index a34f7bf4a2100b..121c8f34a1ec61 100644
--- a/flang/docs/conf.py
+++ b/flang/docs/conf.py
@@ -22,13 +22,23 @@
 # Add any Sphinx extension module names here, as strings. They can be 
extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
 extensions = [
-"myst_parser",
 "sphinx.ext.todo",
 "sphinx.ext.mathjax",
 "sphinx.ext.intersphinx",
 "sphinx.ext.autodoc",
 ]
 
+# When building man pages, we do not use the markdown pages,
+# So, we can continue without the myst_parser dependencies.
+# Doing so reduces dependencies of some packaged llvm distributions.
+try:
+  import myst_parser
+  extensions.append("myst_parser")
+except ImportError:
+  if not tags.has("builder-man"):
+raise
+
+
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ["_templates"]
 myst_heading_anchors = 6
diff --git a/llvm/docs/conf.py b/llvm/docs/conf.py
index 0a3905201c8592..54e45badff79df 100644
--- a/llvm/docs/conf.py
+++ b/llvm/docs/conf.py
@@ -26,7 +26,17 @@
 
 # Add any Sphinx extension module names here, as strings. They can be 
extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = ["myst_parser", "sphinx.ext.intersphinx", "sphinx.ext.todo"]
+extensions = ["sphinx.ext.intersphinx", "sphinx.ext.todo"]
+
+# When building man pages, we do not use the markdown pages,
+# So, we can continue without the myst_parser dependencies.
+# Doing so reduces dependencies of some packaged llvm distributions.
+try:
+  import myst_parser
+  extensions.append("myst_parser")
+except ImportError:
+  if not tags.has("builder-man"):
+raise
 
 # Automatic anchors for markdown titles
 from llvm_slug import make_slug

>From f7b8b4e7735eff63bb413ba2ff9e36b5aac9dbc8 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Mon, 4 Mar 2024 12:33:35 +0100
Subject: [PATCH 2/2] Run darker

---
 clang/docs/conf.py | 9 +
 flang/docs/conf.py | 9 +
 llvm/docs/conf.py  | 9 +
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/clang/docs/conf.py b/clang/docs/conf.py
index 44fd743dc0173f..3c373c4b255118 100644
--- a/clang/docs/conf.py
+++ b/clang/docs/conf.py
@@ -39,11 +39,12 @@
 # So, we can continue without the myst_parser dependencies.
 # Doing so reduces dependencies of some packaged llvm distributions.
 try:
-  import myst_parser
-  extensions.append("myst_parser")
+import myst_parser
+
+extensions.append("myst_parser")
 except ImportError:
-  if not tags.has("builder-man"):
-raise
+if not tags.has("builder-man"):
+raise
 
 
 # The encoding of source files.
diff --git a/flang/docs/conf.py b/flang/docs/conf.py
index 121c8f34a1ec61..48f7b69f5d7505 100644
--- a/flang/docs/conf.py
+++ b/flang/docs/conf.py
@@ -32,11 +32,12 @@
 # So, we can continue without the myst_parser dependencies.
 # Doing so reduces dependencies of some packaged llvm distributions.
 try:
-  import myst_parser
-  extensions.append("myst_parser")
+import myst_parser
+
+extensions.append("myst_parser")
 except ImportError:
-  if not tags.has("builder-man"):
-raise
+if not tags.has("builder-man"):
+raise
 
 
 # Add any paths that contain templates here, relative to this directory.
diff --git a/llvm/docs/conf.py b/llvm/docs/conf.py
index 54e45badff79df..acbddc7b2f12b4 100644
--- a/llvm/docs/conf.py
+++ b/llvm/docs/conf.py
@@ -32,11 +32,12 @@
 # So, we can continue without the myst_parser depende

[clang] [llvm] [RISCV] Add support of Sscofpmf (PR #83831)

2024-03-04 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp created 
https://github.com/llvm/llvm-project/pull/83831

This is used in profile, but somehow we missed it.

>From 7e0815dda185c635448bf08c150fc54d9f9d4b5f Mon Sep 17 00:00:00 2001
From: Wang Pengcheng 
Date: Mon, 4 Mar 2024 19:51:15 +0800
Subject: [PATCH] [RISCV] Add support of Sscofpmf

This is used in profile, but somehow we missed it.
---
 clang/test/Preprocessor/riscv-target-features.c | 9 +
 llvm/docs/RISCVUsage.rst| 3 ++-
 llvm/lib/Support/RISCVISAInfo.cpp   | 1 +
 llvm/lib/Target/RISCV/RISCVFeatures.td  | 3 +++
 llvm/test/CodeGen/RISCV/attributes.ll   | 4 
 llvm/test/MC/RISCV/attribute-arch.s | 3 +++
 llvm/unittests/Support/RISCVISAInfoTest.cpp | 1 +
 7 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 664279cb123949..1a15be1c6e4dc1 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -29,6 +29,7 @@
 // CHECK-NOT: __riscv_smepmp {{.*$}}
 // CHECK-NOT: __riscv_ssaia {{.*$}}
 // CHECK-NOT: __riscv_ssccptr {{.*$}}
+// CHECK-NOT: __riscv_sscofpmf {{.*$}}
 // CHECK-NOT: __riscv_sscounterenw {{.*$}}
 // CHECK-NOT: __riscv_ssstateen {{.*$}}
 // CHECK-NOT: __riscv_ssstrict {{.*$}}
@@ -351,6 +352,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSCCPTR-EXT %s
 // CHECK-SSCCPTR-EXT: __riscv_ssccptr 100{{$}}
 
+// RUN: %clang --target=riscv32-unknown-linux-gnu \
+// RUN:   -march=rv32isscofpmf -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSCOFPMF-EXT %s
+// RUN: %clang --target=riscv64-unknown-linux-gnu \
+// RUN:   -march=rv64isscofpmf -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSCOFPMF-EXT %s
+// CHECK-SSCOFPMF-EXT: __riscv_sscofpmf 100{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32isscounterenw -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSCOUNTERENW-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 8d293b02144307..2595af598f1ee5 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -101,6 +101,7 @@ on support follow.
  ``Smepmp``Supported
  ``Ssaia`` Supported
  ``Ssccptr``   Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
+ ``Sscofpmf``  Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Sscounterenw``  Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Ssstateen`` Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Ssstrict``  Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
@@ -234,7 +235,7 @@ Supported
 
 .. _riscv-profiles-extensions-note:
 
-``Za128rs``, ``Za64rs``, ``Zic64b``, ``Ziccamoa``, ``Ziccif``, ``Zicclsm``, 
``Ziccrse``, ``Shcounterenvw``, ``Shgatpa``, ``Shtvala``, ``Shvsatpa``, 
``Shvstvala``, ``Shvstvecd``, ``Ssccptr``, ``Sscounterenw``, ``Ssstateen``, 
``Ssstrict``, ``Sstvala``, ``Sstvecd``, ``Ssu64xl``, ``Svade``, ``Svbare``
+``Za128rs``, ``Za64rs``, ``Zic64b``, ``Ziccamoa``, ``Ziccif``, ``Zicclsm``, 
``Ziccrse``, ``Shcounterenvw``, ``Shgatpa``, ``Shtvala``, ``Shvsatpa``, 
``Shvstvala``, ``Shvstvecd``, ``Ssccptr``, ``Sscofpmf``, ``Sscounterenw``, 
``Ssstateen``, ``Ssstrict``, ``Sstvala``, ``Sstvecd``, ``Ssu64xl``, ``Svade``, 
``Svbare``
   These extensions are defined as part of the `RISC-V Profiles specification 
`__.  They do not 
introduce any new features themselves, but instead describe existing hardware 
features.
 
   .. _riscv-zacas-note:
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 68f5c36e8fafc6..54b4dcb22de8e0 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -65,6 +65,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
 {"smepmp", {1, 0}},
 {"ssaia", {1, 0}},
 {"ssccptr", {1, 0}},
+{"sscofpmf", {1, 0}},
 {"sscounterenw", {1, 0}},
 {"ssstateen", {1, 0}},
 {"ssstrict", {1, 0}},
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 9773b2998c7dc4..78f3a82d66df2b 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -807,6 +807,9 @@ def FeatureStdExtSsccptr
 : SubtargetFeature<"ssccptr", "HasStdExtSsccptr", "true",
"'Ssccptr' (Main memory supports page table reads)", 
[]>;
 
+def FeatureStdExtSscofpmf
+: SubtargetFeature<"sscofpmf", "HasStdExtSscofpmf", "true",
+   "'Sscofpmf' (Count Overflow and Mode-Based Filtering)", 
[]>;
 def FeatureStdExtShcounterenw
 : SubtargetFeature<"shcounterenw", "HasStdExtShcounterenw", "true",
"'Shcounterenw' (S

[clang] [llvm] [RISCV] Add support of Sscofpmf (PR #83831)

2024-03-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Wang Pengcheng (wangpc-pp)


Changes

This is used in profile, but somehow we missed it.

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


7 Files Affected:

- (modified) clang/test/Preprocessor/riscv-target-features.c (+9) 
- (modified) llvm/docs/RISCVUsage.rst (+2-1) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+1) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+3) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+4) 
- (modified) llvm/test/MC/RISCV/attribute-arch.s (+3) 
- (modified) llvm/unittests/Support/RISCVISAInfoTest.cpp (+1) 


``diff
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 664279cb123949..1a15be1c6e4dc1 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -29,6 +29,7 @@
 // CHECK-NOT: __riscv_smepmp {{.*$}}
 // CHECK-NOT: __riscv_ssaia {{.*$}}
 // CHECK-NOT: __riscv_ssccptr {{.*$}}
+// CHECK-NOT: __riscv_sscofpmf {{.*$}}
 // CHECK-NOT: __riscv_sscounterenw {{.*$}}
 // CHECK-NOT: __riscv_ssstateen {{.*$}}
 // CHECK-NOT: __riscv_ssstrict {{.*$}}
@@ -351,6 +352,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSCCPTR-EXT %s
 // CHECK-SSCCPTR-EXT: __riscv_ssccptr 100{{$}}
 
+// RUN: %clang --target=riscv32-unknown-linux-gnu \
+// RUN:   -march=rv32isscofpmf -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSCOFPMF-EXT %s
+// RUN: %clang --target=riscv64-unknown-linux-gnu \
+// RUN:   -march=rv64isscofpmf -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSCOFPMF-EXT %s
+// CHECK-SSCOFPMF-EXT: __riscv_sscofpmf 100{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32isscounterenw -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSCOUNTERENW-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 8d293b02144307..2595af598f1ee5 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -101,6 +101,7 @@ on support follow.
  ``Smepmp``Supported
  ``Ssaia`` Supported
  ``Ssccptr``   Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
+ ``Sscofpmf``  Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Sscounterenw``  Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Ssstateen`` Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Ssstrict``  Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
@@ -234,7 +235,7 @@ Supported
 
 .. _riscv-profiles-extensions-note:
 
-``Za128rs``, ``Za64rs``, ``Zic64b``, ``Ziccamoa``, ``Ziccif``, ``Zicclsm``, 
``Ziccrse``, ``Shcounterenvw``, ``Shgatpa``, ``Shtvala``, ``Shvsatpa``, 
``Shvstvala``, ``Shvstvecd``, ``Ssccptr``, ``Sscounterenw``, ``Ssstateen``, 
``Ssstrict``, ``Sstvala``, ``Sstvecd``, ``Ssu64xl``, ``Svade``, ``Svbare``
+``Za128rs``, ``Za64rs``, ``Zic64b``, ``Ziccamoa``, ``Ziccif``, ``Zicclsm``, 
``Ziccrse``, ``Shcounterenvw``, ``Shgatpa``, ``Shtvala``, ``Shvsatpa``, 
``Shvstvala``, ``Shvstvecd``, ``Ssccptr``, ``Sscofpmf``, ``Sscounterenw``, 
``Ssstateen``, ``Ssstrict``, ``Sstvala``, ``Sstvecd``, ``Ssu64xl``, ``Svade``, 
``Svbare``
   These extensions are defined as part of the `RISC-V Profiles specification 
`__.  They do not 
introduce any new features themselves, but instead describe existing hardware 
features.
 
   .. _riscv-zacas-note:
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 68f5c36e8fafc6..54b4dcb22de8e0 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -65,6 +65,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
 {"smepmp", {1, 0}},
 {"ssaia", {1, 0}},
 {"ssccptr", {1, 0}},
+{"sscofpmf", {1, 0}},
 {"sscounterenw", {1, 0}},
 {"ssstateen", {1, 0}},
 {"ssstrict", {1, 0}},
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 9773b2998c7dc4..78f3a82d66df2b 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -807,6 +807,9 @@ def FeatureStdExtSsccptr
 : SubtargetFeature<"ssccptr", "HasStdExtSsccptr", "true",
"'Ssccptr' (Main memory supports page table reads)", 
[]>;
 
+def FeatureStdExtSscofpmf
+: SubtargetFeature<"sscofpmf", "HasStdExtSscofpmf", "true",
+   "'Sscofpmf' (Count Overflow and Mode-Based Filtering)", 
[]>;
 def FeatureStdExtShcounterenw
 : SubtargetFeature<"shcounterenw", "HasStdExtShcounterenw", "true",
"'Shcounterenw' (Support writeable hcounteren enable "
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 561b0f21dc3770..cc332df271043f 100644
--- a

[clang] [llvm] [HLSL] implement exp intrinsic (PR #83832)

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

https://github.com/farzonl created 
https://github.com/llvm/llvm-project/pull/83832

 This change implements: #70072

- `hlsl_intrinsics.h` - add the `exp` api
- `DXIL.td` - add the llvm intrinsic to DXIL opcode lowering mapping.
- This change reuses llvm's existing intrinsic `__builtin_elementwise_exp` \ 
`int_exp`

>From 9f894dc93d69e39b01639b2263eafd6421535ebf Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Mon, 4 Mar 2024 00:19:51 -0500
Subject: [PATCH] [HLSL] implement exp intrinsic  This change implements:
 #70072

hlsl_intrinsics.h - add the exp api
DXIL.td add the llvm intrinsic to DXIL opcode lowering mapping
This change reuses llvm's existing intrinsic __builtin_elementwise_exp\ int_exp
---
 clang/lib/Headers/hlsl/hlsl_intrinsics.h | 32 
 clang/test/CodeGenHLSL/builtins/exp.hlsl | 53 
 clang/test/SemaHLSL/BuiltIns/exp-errors.hlsl | 27 ++
 llvm/lib/Target/DirectX/DXIL.td  |  3 ++
 llvm/test/CodeGen/DirectX/exp.ll | 31 
 5 files changed, 146 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/exp.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/exp-errors.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/exp.ll

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 5180530363889f..acbc21ba548bc4 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -277,6 +277,38 @@ uint64_t dot(uint64_t3, uint64_t3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
 uint64_t dot(uint64_t4, uint64_t4);
 
+//===--===//
+// exp builtins
+//===--===//
+
+/// \fn T exp(T x)
+/// \brief Returns the base-e exponential, or \a e**x, of the specified value.
+/// \param x The specified input value.
+///
+/// The return value is the base-e exponential of the \a x parameter.
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+half exp(half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+half2 exp(half2);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+half3 exp(half3);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+half4 exp(half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+float exp(float);
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+float2 exp(float2);
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+float3 exp(float3);
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+float4 exp(float4);
+
 
//===--===//
 // floor builtins
 
//===--===//
diff --git a/clang/test/CodeGenHLSL/builtins/exp.hlsl 
b/clang/test/CodeGenHLSL/builtins/exp.hlsl
new file mode 100644
index 00..773edbe3364fd2
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/exp.hlsl
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ 
+// RUN:   --check-prefixes=CHECK,NATIVE_HALF
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
+
+// NATIVE_HALF: define noundef half @
+// NATIVE_HALF: %elt.exp = call half @llvm.exp.f16(
+// NATIVE_HALF: ret half %elt.exp
+// NO_HALF: define noundef float @"?test_exp_half@@YA$halff@$halff@@Z"(
+// NO_HALF: %elt.exp = call float @llvm.exp.f32(
+// NO_HALF: ret float %elt.exp
+half test_exp_half(half p0) { return exp(p0); }
+// NATIVE_HALF: define noundef <2 x half> @
+// NATIVE_HALF: %elt.exp = call <2 x half> @llvm.exp.v2f16
+// NATIVE_HALF: ret <2 x half> %elt.exp
+// NO_HALF: define noundef <2 x float> @
+// NO_HALF: %elt.exp = call <2 x float> @llvm.exp.v2f32(
+// NO_HALF: ret <2 x float> %elt.exp
+half2 test_exp_half2(half2 p0) { return exp(p0); }
+// NATIVE_HALF: define noundef <3 x half> @
+// NATIVE_HALF: %elt.exp = call <3 x half> @llvm.exp.v3f16
+// NATIVE_HALF: ret <3 x half> %elt.exp
+// NO_HALF: define noundef <3 x float> @
+// NO_HALF: %elt.exp = call <3 x float> @llvm.exp.v3f32(
+// NO_HALF: ret <3 x float> %elt.exp
+half3 test_exp_half3(half3 p0) { return exp(p0); }
+// NATIVE_HALF: define noundef <4 x half> @
+// NATIVE_HALF: %elt.exp = call <4 x half> @llvm.exp.v4f16
+// NATIVE_HALF: ret <4 x half> %elt.exp
+// NO_HALF: define noundef <4 x float> @
+// NO_HALF: %elt.exp = call <4 x float> @llvm.exp.v4f32(
+// NO_HALF: ret <4 x float> %elt.exp
+half4 test_exp_half4(half4 p0) { return exp(p0); }
+
+// CHECK: define noundef float @
+// CHECK: %elt.e

[clang] [llvm] [HLSL] implement exp intrinsic (PR #83832)

2024-03-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Farzon Lotfi (farzonl)


Changes

 This change implements: #70072

- `hlsl_intrinsics.h` - add the `exp` api
- `DXIL.td` - add the llvm intrinsic to DXIL opcode lowering mapping.
- This change reuses llvm's existing intrinsic `__builtin_elementwise_exp` \ 
`int_exp`

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


5 Files Affected:

- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+32) 
- (added) clang/test/CodeGenHLSL/builtins/exp.hlsl (+53) 
- (added) clang/test/SemaHLSL/BuiltIns/exp-errors.hlsl (+27) 
- (modified) llvm/lib/Target/DirectX/DXIL.td (+3) 
- (added) llvm/test/CodeGen/DirectX/exp.ll (+31) 


``diff
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 5180530363889f..acbc21ba548bc4 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -277,6 +277,38 @@ uint64_t dot(uint64_t3, uint64_t3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot)
 uint64_t dot(uint64_t4, uint64_t4);
 
+//===--===//
+// exp builtins
+//===--===//
+
+/// \fn T exp(T x)
+/// \brief Returns the base-e exponential, or \a e**x, of the specified value.
+/// \param x The specified input value.
+///
+/// The return value is the base-e exponential of the \a x parameter.
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+half exp(half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+half2 exp(half2);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+half3 exp(half3);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+half4 exp(half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+float exp(float);
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+float2 exp(float2);
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+float3 exp(float3);
+_HLSL_BUILTIN_ALIAS(__builtin_elementwise_exp)
+float4 exp(float4);
+
 
//===--===//
 // floor builtins
 
//===--===//
diff --git a/clang/test/CodeGenHLSL/builtins/exp.hlsl 
b/clang/test/CodeGenHLSL/builtins/exp.hlsl
new file mode 100644
index 00..773edbe3364fd2
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/exp.hlsl
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ 
+// RUN:   --check-prefixes=CHECK,NATIVE_HALF
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
+
+// NATIVE_HALF: define noundef half @
+// NATIVE_HALF: %elt.exp = call half @llvm.exp.f16(
+// NATIVE_HALF: ret half %elt.exp
+// NO_HALF: define noundef float @"?test_exp_half@@YA$halff@$halff@@Z"(
+// NO_HALF: %elt.exp = call float @llvm.exp.f32(
+// NO_HALF: ret float %elt.exp
+half test_exp_half(half p0) { return exp(p0); }
+// NATIVE_HALF: define noundef <2 x half> @
+// NATIVE_HALF: %elt.exp = call <2 x half> @llvm.exp.v2f16
+// NATIVE_HALF: ret <2 x half> %elt.exp
+// NO_HALF: define noundef <2 x float> @
+// NO_HALF: %elt.exp = call <2 x float> @llvm.exp.v2f32(
+// NO_HALF: ret <2 x float> %elt.exp
+half2 test_exp_half2(half2 p0) { return exp(p0); }
+// NATIVE_HALF: define noundef <3 x half> @
+// NATIVE_HALF: %elt.exp = call <3 x half> @llvm.exp.v3f16
+// NATIVE_HALF: ret <3 x half> %elt.exp
+// NO_HALF: define noundef <3 x float> @
+// NO_HALF: %elt.exp = call <3 x float> @llvm.exp.v3f32(
+// NO_HALF: ret <3 x float> %elt.exp
+half3 test_exp_half3(half3 p0) { return exp(p0); }
+// NATIVE_HALF: define noundef <4 x half> @
+// NATIVE_HALF: %elt.exp = call <4 x half> @llvm.exp.v4f16
+// NATIVE_HALF: ret <4 x half> %elt.exp
+// NO_HALF: define noundef <4 x float> @
+// NO_HALF: %elt.exp = call <4 x float> @llvm.exp.v4f32(
+// NO_HALF: ret <4 x float> %elt.exp
+half4 test_exp_half4(half4 p0) { return exp(p0); }
+
+// CHECK: define noundef float @
+// CHECK: %elt.exp = call float @llvm.exp.f32(
+// CHECK: ret float %elt.exp
+float test_exp_float(float p0) { return exp(p0); }
+// CHECK: define noundef <2 x float> @
+// CHECK: %elt.exp = call <2 x float> @llvm.exp.v2f32
+// CHECK: ret <2 x float> %elt.exp
+float2 test_exp_float2(float2 p0) { return exp(p0); }
+// CHECK: define noundef <3 x float> @
+// CHECK: %elt.exp = call <3 x float> @llvm.exp.v3f32
+// CHECK: ret <3 x float> %elt.exp
+float3 test_exp_float3(float3 p0) { return exp(p0); }
+// CHECK: define noundef <4 x float> @
+//

[clang] [Clang] Fixes of builtin definitions after PR #68324. (PR #81022)

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

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

LGTM, thank you for the fix!

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


[clang] [llvm] [RISCV] Add support of Sscofpmf (PR #83831)

2024-03-04 Thread Yingwei Zheng via cfe-commits

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

LGTM. Nice catch!
Related patch: https://github.com/llvm/llvm-project/pull/79399

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


[clang] Reapply "[Clang][Sema] Diagnose function/variable templates that shadow their own template parameters (#78274)" (PR #79683)

2024-03-04 Thread via cfe-commits

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

LGTM

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


[clang] [Clang][Docs] Simpler syntax for Github links. (PR #82746)

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

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

LGTM, thank you, this is a nice usability improvement!

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


[clang] 7d55a3b - [Docs] Allow building man pages without myst_parser (#82402)

2024-03-04 Thread via cfe-commits

Author: cor3ntin
Date: 2024-03-04T13:31:26+01:00
New Revision: 7d55a3ba92368be55b392c20d623fde6ac82d86d

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

LOG: [Docs] Allow building man pages without myst_parser (#82402)

The man pages do not depend on the doc present in markdown files, so
they can be built without myst_parser.
Doing so might allow llvm distributions to have less development
dependencies.

As we do not have the ennvironment to test these configuration, this
capability is provided on a best-effort basis.

This restores a capability accidentally lost in #65664.

Added: 


Modified: 
clang/docs/conf.py
flang/docs/conf.py
llvm/docs/conf.py

Removed: 




diff  --git a/clang/docs/conf.py b/clang/docs/conf.py
index 31a4daa39d5b8e..3c373c4b255118 100644
--- a/clang/docs/conf.py
+++ b/clang/docs/conf.py
@@ -35,8 +35,17 @@
 
 import sphinx
 
-if sphinx.version_info >= (3, 0):
+# When building man pages, we do not use the markdown pages,
+# So, we can continue without the myst_parser dependencies.
+# Doing so reduces dependencies of some packaged llvm distributions.
+try:
+import myst_parser
+
 extensions.append("myst_parser")
+except ImportError:
+if not tags.has("builder-man"):
+raise
+
 
 # The encoding of source files.
 # source_encoding = 'utf-8-sig'

diff  --git a/flang/docs/conf.py b/flang/docs/conf.py
index a34f7bf4a2100b..48f7b69f5d7505 100644
--- a/flang/docs/conf.py
+++ b/flang/docs/conf.py
@@ -22,13 +22,24 @@
 # Add any Sphinx extension module names here, as strings. They can be 
extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
 extensions = [
-"myst_parser",
 "sphinx.ext.todo",
 "sphinx.ext.mathjax",
 "sphinx.ext.intersphinx",
 "sphinx.ext.autodoc",
 ]
 
+# When building man pages, we do not use the markdown pages,
+# So, we can continue without the myst_parser dependencies.
+# Doing so reduces dependencies of some packaged llvm distributions.
+try:
+import myst_parser
+
+extensions.append("myst_parser")
+except ImportError:
+if not tags.has("builder-man"):
+raise
+
+
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ["_templates"]
 myst_heading_anchors = 6

diff  --git a/llvm/docs/conf.py b/llvm/docs/conf.py
index 0a3905201c8592..acbddc7b2f12b4 100644
--- a/llvm/docs/conf.py
+++ b/llvm/docs/conf.py
@@ -26,7 +26,18 @@
 
 # Add any Sphinx extension module names here, as strings. They can be 
extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = ["myst_parser", "sphinx.ext.intersphinx", "sphinx.ext.todo"]
+extensions = ["sphinx.ext.intersphinx", "sphinx.ext.todo"]
+
+# When building man pages, we do not use the markdown pages,
+# So, we can continue without the myst_parser dependencies.
+# Doing so reduces dependencies of some packaged llvm distributions.
+try:
+import myst_parser
+
+extensions.append("myst_parser")
+except ImportError:
+if not tags.has("builder-man"):
+raise
 
 # Automatic anchors for markdown titles
 from llvm_slug import make_slug



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


[clang] [flang] [llvm] [Docs] Allow building man pages without myst_parser (PR #82402)

2024-03-04 Thread via cfe-commits

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


[clang] c089fa5 - [clang][Interp] Fix assertion in InitElem{, Pop} ops

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

Author: Timm Bäder
Date: 2024-03-04T13:31:36+01:00
New Revision: c089fa5a729e217d0c0d4647656386dac1a1b135

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

LOG: [clang][Interp] Fix assertion in InitElem{,Pop} ops

... when the pointer is an unknown size array.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 84f65a33bef361..3d49f73a567621 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1448,6 +1448,8 @@ template ::T>
 bool InitElem(InterpState &S, CodePtr OpPC, uint32_t Idx) {
   const T &Value = S.Stk.pop();
   const Pointer &Ptr = S.Stk.peek().atIndex(Idx);
+  if (Ptr.isUnknownSizeArray())
+return false;
   if (!CheckInit(S, OpPC, Ptr))
 return false;
   Ptr.initialize();
@@ -1460,6 +1462,8 @@ template ::T>
 bool InitElemPop(InterpState &S, CodePtr OpPC, uint32_t Idx) {
   const T &Value = S.Stk.pop();
   const Pointer &Ptr = S.Stk.pop().atIndex(Idx);
+  if (Ptr.isUnknownSizeArray())
+return false;
   if (!CheckInit(S, OpPC, Ptr))
 return false;
   Ptr.initialize();

diff  --git a/clang/test/AST/Interp/arrays.cpp 
b/clang/test/AST/Interp/arrays.cpp
index 2bf6e9ef35119f..4b112d7fdddfdb 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -138,6 +138,8 @@ constexpr int dependent[4] = {
 static_assert(dependent[2] == dependent[0], "");
 static_assert(dependent[3] == dependent[1], "");
 
+union { char x[]; } r = {0};
+
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wc99-extensions"
 #pragma clang diagnostic ignored "-Winitializer-overrides"



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


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

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


@@ -665,60 +619,44 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto leafs = getLeafConstructs(DKind);

kparzysz wrote:

Merriam-Webster is more oriented towards American English.  The [entry for 
leaf](https://www.merriam-webster.com/dictionary/leaf) shows "leafs" as an 
alternative plural form.

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


[clang] [Clang][Docs] Simpler syntax for Github links. (PR #82746)

2024-03-04 Thread via cfe-commits

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

>From 2e37c94e37aa367b77a61fc0ab62aa0845a7f8f0 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Fri, 23 Feb 2024 10:39:46 +0100
Subject: [PATCH] [Clang][Docs] Simpler syntax for Github links.

Github links in release notes are often invalid rST,
clutter the release notes and are annoying to write.

This introduces a sphynx plugin that rewrites
 `#GH` to a link to the corresponding issue.

While this could be introduced globally on all of LLVM,
the PR only modifies Clang for now.
---
 clang/docs/ReleaseNotes.rst | 91 +++--
 clang/docs/conf.py  |  4 +-
 clang/docs/ghlinks.py   | 19 
 3 files changed, 58 insertions(+), 56 deletions(-)
 create mode 100644 clang/docs/ghlinks.py

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6f6ce7c68a7a71..b5f4c10068798f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -79,7 +79,7 @@ C++20 Feature Support
   more to ease the implementation and improve the user's using experience.
   This follows the MSVC's behavior. Users interested in testing the more strict
   behavior can use the flag '-Xclang -fno-skip-odr-check-in-gmf'.
-  (`#79240 `_).
+  (#GH79240).
 
 - Implemented the `__is_layout_compatible` intrinsic to support
   `P0466R5: Layout-compatibility and Pointer-interconvertibility Traits 
`_.
@@ -116,7 +116,7 @@ C Language Changes
 C23 Feature Support
 ^^^
 - No longer diagnose use of binary literals as an extension in C23 mode. Fixes
-  `#72017 `_.
+  #GH72017.
 
 - Corrected parsing behavior for the ``alignas`` specifier/qualifier in C23. We
   previously handled it as an attribute as in C++, but there are parsing
@@ -129,7 +129,7 @@ C23 Feature Support
  };
  int i alignas(8) /* was accepted, now rejected */ ;
 
-  Fixes (`#81472 `_).
+  Fixes (#GH81472).
 
 - Clang now generates predefined macros of the form ``__TYPE_FMTB__`` and
   ``__TYPE_FMTb__`` (e.g., ``__UINT_FAST64_FMTB__``) in C23 mode for use with
@@ -173,7 +173,7 @@ Improvements to Clang's diagnostics
   name specifiers.
 
 - The ``-Wshorten-64-to-32`` diagnostic is now grouped under 
``-Wimplicit-int-conversion`` instead
-   of ``-Wconversion``. Fixes `#69444 
`_.
+   of ``-Wconversion``. Fixes #GH69444.
 
 - Clang now diagnoses friend declarations with an ``enum`` 
elaborated-type-specifier in language modes after C++98.
 
@@ -186,14 +186,14 @@ Improvements to Clang's diagnostics
   ``unsigned long long``, but this behavior may change in the future when Clang
   implements
   `WG14 N3029 `_.
-  Fixes `#69352 `_.
+  (#GH69352).
 
 - Clang now diagnoses extraneous template parameter lists as a language 
extension.
 
 - Clang now diagnoses declarative nested name specifiers that name alias 
templates.
 
 - Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
-  Fixes `#82512 `_.
+  Fixes #GH82512.
 
 Improvements to Clang's time-trace
 --
@@ -206,21 +206,21 @@ Bug Fixes in This Version
 - Clang now accepts elaborated-type-specifiers that explicitly specialize
   a member class template for an implicit instantiation of a class template.
 
-- Fixed missing warnings when doing bool-like conversions in C23 (`#79435 
`_).
+- Fixed missing warnings when doing bool-like conversions in C23 (#GH79435).
 - Clang's ``-Wshadow`` no longer warns when an init-capture is named the same 
as
   a class field unless the lambda can capture this.
-  Fixes (`#71976 `_)
+  Fixes (#GH71976)
 
 - Clang now accepts qualified partial/explicit specializations of variable 
templates that
   are not nominable in the lookup context of the specialization.
 
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
-  Fixes (`#64356 `_).
+  Fixes (#GH64356).
 
 - Clang no longer produces a false-positive `-Wunused-variable` warning
   for variables created through copy initialization having side-effects in 
C++17 and later.
-  Fixes (`#79518 `_).
+  Fixes (#GH64356) (#GH79518).
 
 Bug Fixes to Compiler Builtins
 ^^
@@ -232,84 +232,67 @@ Bug Fixes to C++ Support
 
 
 - Fix crash when calling the constructor of an invalid c

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

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

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


[clang] [clang][Builtins] Parse clang extended vectors types. (PR #83584)

2024-03-04 Thread Francesco Petrogalli via cfe-commits

https://github.com/fpetrogalli updated 
https://github.com/llvm/llvm-project/pull/83584

>From 53d9fe77500a18884f200c49db57336324305620 Mon Sep 17 00:00:00 2001
From: Francesco Petrogalli 
Date: Fri, 1 Mar 2024 16:23:57 +0100
Subject: [PATCH] [clang][Builtins] Parse clang extended vectors types.

Clang extended vector types are mangled as follows:

   '_ExtVector<'  ','  '>'

This is used to defetmine the builtins signature for builtins that
use parameters defined as

typedef  ext_vector_type__ 
__attribute__((ext_vector_type()))

For example:

typedef double ext_vector_type_4_double __attribute__((ext_vector_type(4)))
---
 .../target-builtins-prototype-parser.td   | 79 +++
 clang/utils/TableGen/ClangBuiltinsEmitter.cpp | 61 +-
 2 files changed, 137 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/TableGen/target-builtins-prototype-parser.td

diff --git a/clang/test/TableGen/target-builtins-prototype-parser.td 
b/clang/test/TableGen/target-builtins-prototype-parser.td
new file mode 100644
index 00..a6d0c98fa8bca2
--- /dev/null
+++ b/clang/test/TableGen/target-builtins-prototype-parser.td
@@ -0,0 +1,79 @@
+// RUN: clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins | 
FileCheck %s
+// RUN: not clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins 
-DERROR_EXPECTED_LANES 2>&1 | FileCheck %s --check-prefix=ERROR_EXPECTED_LANES
+// RUN: not clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins 
-DERROR_EXPECTED_COMMA 2>&1 | FileCheck %s --check-prefix=ERROR_EXPECTED_COMMA
+// RUN: not clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins 
-DERROR_EXPECTED_TYPE 2>&1 | FileCheck %s --check-prefix=ERROR_EXPECTED_TYPE
+
+include "clang/Basic/BuiltinsBase.td"
+
+def : Builtin {
+// CHECK: BUILTIN(__builtin_01, "E8idE4b", "")
+  let Prototype = "_ExtVector<8,int>(double, _ExtVector<4,bool>)";
+  let Spellings = ["__builtin_01"];
+}
+
+def : Builtin {
+// CHECK: BUILTIN(__builtin_02, "E8UiE4s", "")
+  let Prototype = "_ExtVector<8,unsigned int>(_ExtVector<4, short>)";
+  let Spellings = ["__builtin_02"];
+}
+
+def : Builtin {
+// CHECK: BUILTIN(__builtin_03, "di", "")
+  let Prototype = "double(int)";
+  let Spellings = ["__builtin_03"];
+}
+
+def : Builtin {
+// CHECK: BUILTIN(__builtin_04, "diIUi", "")
+ let Prototype = "double(int, _Constant unsigned int)";
+  let Spellings = ["__builtin_04"];
+}
+
+def : Builtin {
+// CHECK: BUILTIN(__builtin_05, "v&v&", "")
+ let Prototype = "void&(void&)";
+  let Spellings = ["__builtin_05"];
+}
+
+def : Builtin {
+// CHECK: BUILTIN(__builtin_06, "v*v*cC*.", "")
+ let Prototype = "void*(void*, char const*, ...)";
+  let Spellings = ["__builtin_06"];
+}
+
+def : Builtin {
+// CHECK: BUILTIN(__builtin_07, "E8iE4dE4b.", "")
+  let Prototype = "_ExtVector<8, int>(_ExtVector<4,double>, _ExtVector<4, 
bool>, ...)";
+  let Spellings = ["__builtin_07"];
+}
+
+def : Builtin {
+// CHECK: BUILTIN(__builtin_08, "di*R", "")
+  let Prototype = "double(int * restrict)";
+  let Spellings = ["__builtin_08"];
+}
+
+#ifdef ERROR_EXPECTED_LANES
+def : Builtin {
+// ERROR_EXPECTED_LANES: :[[# @LINE + 1]]:7: error: Expected number of lanes 
after '_ExtVector<'
+  let Prototype = "_ExtVector(double)";
+  let Spellings = ["__builtin_test_use_clang_extended_vectors"];
+}
+#endif
+
+#ifdef ERROR_EXPECTED_COMMA
+def : Builtin {
+// ERROR_EXPECTED_COMMA: :[[# @LINE + 1]]:7: error: Expected ',' after number 
of lanes in '_ExtVector<'
+  let Prototype = "_ExtVector<8 int>(double)";
+  let Spellings = ["__builtin_test_use_clang_extended_vectors"];
+}
+#endif
+
+#ifdef ERROR_EXPECTED_TYPE
+def : Builtin {
+// ERROR_EXPECTED_TYPE: :[[# @LINE + 1]]:7: error: Expected '>' after scalar 
type in '_ExtVector'
+  let Prototype = "_ExtVector<8, int (double)";
+  let Spellings = ["__builtin_test_use_clang_extended_vectors"];
+}
+#endif
+
diff --git a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp 
b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
index 48f55b8af97e4e..8790101c4a44e2 100644
--- a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
+++ b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
@@ -47,9 +47,47 @@ class PrototypeParser {
 if (!Prototype.ends_with(")"))
   PrintFatalError(Loc, "Expected closing brace at end of prototype");
 Prototype = Prototype.drop_back();
-for (auto T = Prototype.split(','); !T.first.empty();
- Prototype = T.second, T = Prototype.split(','))
-  ParseType(T.first);
+
+// Look through the input parameters.
+const size_t end = Prototype.size();
+for (size_t I = 0; I != end;) {
+  const StringRef Current = Prototype.substr(I, end);
+  // Skip any leading space or commas
+  if (Current.starts_with(" ") || Current.starts_with(",")) {
+++I;
+continue;
+  }
+
+  // Check if we are in _ExtVector. We do this first because
+  // extended vectors are written in template form with the syntax
+  

[clang] [clang][Builtins] Parse clang extended vectors types. (PR #83584)

2024-03-04 Thread Francesco Petrogalli via cfe-commits

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


[clang] [clang][Builtins] Parse clang extended vectors types. (PR #83584)

2024-03-04 Thread Francesco Petrogalli via cfe-commits

fpetrogalli wrote:

@francisvm / @philnik777 - I have opted for:

'_ExtVector<'  ','  '>'

The reason for specifying  first is due to the fact that it makes it 
simpler to build the final string, because the `ParseType` function is 
recursive.

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


[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

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

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

LGTM, thank you!

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


[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-03-04 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/81298

>From d59c262b31937fdd2b907ec11d7f08e4a385007c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Fri, 9 Feb 2024 21:55:03 +0330
Subject: [PATCH 1/6] [clang] Support `__is_trivially_copyable(int()&)==false`

IMHO it would be productive to make a similar change for `typeid`,
in `ParseCXXTypeid`, in order to improve Clang's error message for
https://godbolt.org/z/oKKWxeYra
But that might be better done by adding a new DeclaratorContext
specifically for TypeidArg, instead of pretending that the argument
to `typeid` is a template argument, because I don't know what else
that change might affect.

Fixes https://github.com/llvm/llvm-project/issues/77585
---
 clang/lib/Parse/ParseExprCXX.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..746a8b2286ac4c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3899,7 +3899,9 @@ ExprResult Parser::ParseTypeTrait() {
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName();
+TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus
+   ? DeclaratorContext::TemplateArg
+   : DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3941,7 +3943,7 @@ ExprResult Parser::ParseArrayTypeTrait() {
   if (T.expectAndConsume())
 return ExprError();
 
-  TypeResult Ty = ParseTypeName();
+  TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg);
   if (Ty.isInvalid()) {
 SkipUntil(tok::comma, StopAtSemi);
 SkipUntil(tok::r_paren, StopAtSemi);

>From 4c58f4f351a17cf4bf3c9d0ccfa118d0fe3a52de Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 11 Feb 2024 20:35:04 +0330
Subject: [PATCH 2/6] [clang] Fix the failing test in #81298

---
 clang/test/Sema/static-assert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index 4e9e6b7ee558bd..7e1ce135cbd995 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -57,7 +57,7 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // 
ext-warning 3 {{'_Static_
 typedef UNION(char, short) U3; // expected-error {{static assertion failed due 
to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
-typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
+typedef UNION(float, 0.5f) U4; // expected-error-re type name requires a 
specifier or qualifier|expected a type \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
 
 // After defining the assert macro in MS-compatibility mode, we should

>From 03c2cfb73fc291ecfc5318077b295a6e38cd9869 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Mon, 12 Feb 2024 23:47:33 +0330
Subject: [PATCH 3/6] Add a release note.

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32440ee64e3ebe..0beb10af709804 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,8 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
+- Fix parsing of abominable function types inside type traits. 
+  Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling
 ^

>From 0de0aa09fb5f45fcde688d988377582b9257b6b8 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Tue, 13 Feb 2024 01:19:27 +0330
Subject: [PATCH 4/6] Remove trailing white space in ReleaseNotes.rst.

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0beb10af709804..55f3faea365a07 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,7 +217,7 @@ Bug Fixes to C++ Support
   Fixes (`#80971 ICE when explicit object parameter be a function parameter 
pack`)
 - Fixed a bug where abbreviated function templates would append their invented 
template parameters to
   an empty template parameter lists.
-- Fix parsing of abominable function types inside type traits. 
+- Fix parsing of abominable function types inside type traits.
   Fixes (`#77585 `_)
 
 Bug Fixes to AST Handling

>

[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

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

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

LGTM!

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


[clang] e4882d8 - [Clang] [Sema] Do not crash on dependent or invalid record decls when `-fdump-record-layouts-complete` is passed (#83688)

2024-03-04 Thread via cfe-commits

Author: Sirraide
Date: 2024-03-04T14:04:35+01:00
New Revision: e4882d83d77f9d6a5198ecb7faabd5bf2ce4b730

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

LOG: [Clang] [Sema] Do not crash on dependent or invalid record decls when 
`-fdump-record-layouts-complete` is passed (#83688)

We no longer try to compute and dump the layout of types in cases where that 
isn’t possible.

This fixes #83684 and #83671.

Added: 
clang/test/Layout/dump-complete-invalid.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/Decl.cpp
clang/test/Layout/dump-complete.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6f6ce7c68a7a71..045bcd16d62a27 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -321,6 +321,10 @@ Miscellaneous Bug Fixes
 Miscellaneous Clang Crashes Fixed
 ^
 
+- Do not attempt to dump the layout of dependent types or invalid declarations
+  when ``-fdump-record-layouts-complete`` is passed.
+  Fixes (`#83684 `_).
+
 OpenACC Specific Changes
 
 

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 5d6bb72a208a1a..57a92357f6e5ba 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5042,7 +5042,13 @@ void RecordDecl::completeDefinition() {
 
   // Layouts are dumped when computed, so if we are dumping for all complete
   // types, we need to force usage to get types that wouldn't be used 
elsewhere.
-  if (Ctx.getLangOpts().DumpRecordLayoutsComplete)
+  //
+  // If the type is dependent, then we can't compute its layout because there
+  // is no way for us to know the size or alignment of a dependent type. Also
+  // ignore declarations marked as invalid since 'getASTRecordLayout()' asserts
+  // on that.
+  if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType() &&
+  !isInvalidDecl())
 (void)Ctx.getASTRecordLayout(this);
 }
 

diff  --git a/clang/test/Layout/dump-complete-invalid.cpp 
b/clang/test/Layout/dump-complete-invalid.cpp
new file mode 100644
index 00..d3ec1b382ce7c6
--- /dev/null
+++ b/clang/test/Layout/dump-complete-invalid.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fdump-record-layouts-complete %s
+
+struct Incomplete; // expected-note {{forward declaration}}
+
+// Check we don't crash on trying to print out an invalid declaration.
+struct Invalid : Incomplete {}; // expected-error {{base class has incomplete 
type}}

diff  --git a/clang/test/Layout/dump-complete.cpp 
b/clang/test/Layout/dump-complete.cpp
index 9ccbf477c7052e..728f133a0eb640 100644
--- a/clang/test/Layout/dump-complete.cpp
+++ b/clang/test/Layout/dump-complete.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm-only -fdump-record-layouts-complete %s | 
FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fdump-record-layouts-complete %s | FileCheck 
%s
 
 struct a {
   int x;
@@ -12,7 +12,62 @@ class c {};
 
 class d;
 
+template 
+struct s {
+  int x;
+};
+
+template 
+struct ts {
+  T x;
+};
+
+template <>
+struct ts {
+  float f;
+};
+
+void f() {
+  ts a;
+  ts b;
+  ts c;
+}
+
+namespace gh83671 {
+template 
+struct integral_constant {
+  static constexpr const _Tp value = __v;
+  typedef integral_constant type;
+};
+
+template 
+using _BoolConstant = integral_constant;
+
+template 
+struct is_same : _BoolConstant<__is_same(_Tp, _Up)> {};
+
+template < class _Tp >
+class numeric_limits {};
+
+template < class _Tp >
+class numeric_limits< const _Tp > : public numeric_limits< _Tp > {};
+}
+
+namespace gh83684 {
+template 
+struct AllocationResult {
+  Pointer ptr = nullptr;
+  int count = 0;
+};
+}
+
 // CHECK:  0 | struct a
 // CHECK:  0 | struct b
 // CHECK:  0 | class c
+// CHECK:  0 | struct ts
+// CHECK-NEXT: 0 |   float
+// CHECK:  0 | struct ts
+// CHECK:  0 | struct ts
 // CHECK-NOT:  0 | class d
+// CHECK-NOT:  0 | struct s
+// CHECK-NOT:  0 | struct AllocationResult



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


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-04 Thread via cfe-commits

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


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

2024-03-04 Thread Botond István Horváth via cfe-commits

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

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

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

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

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

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

2024-03-04 Thread Botond István Horváth via cfe-commits


@@ -68,3 +68,35 @@ template struct X {};
 X<1> x;
 #endif
 }
+namespace dr2445 { // dr2445: 19

HoBoIs wrote:

done

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


[clang] 906580b - [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (#82968)

2024-03-04 Thread via cfe-commits

Author: Qiu Chaofan
Date: 2024-03-04T21:13:59+08:00
New Revision: 906580bad3a68e3877f4ff7ac2b7fc1b7ee84fd5

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

LOG: [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (#82968)

These builtins are already there in Clang, however current codegen may
produce suboptimal results due to their complex behavior. Implement them
as intrinsics to ensure expected instructions are emitted.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
llvm/include/llvm/IR/IntrinsicsPowerPC.td
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/test/CodeGen/PowerPC/rldimi.ll
llvm/test/CodeGen/PowerPC/rlwimi.ll
llvm/test/CodeGen/PowerPC/rlwinm.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e90014261217bc..9ee51ca7142c77 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17091,37 +17091,24 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 }
 return Builder.CreateCall(CGM.getIntrinsic(ID), Ops, "");
   }
-  // Rotate and insert under mask operation.
-  // __rldimi(rs, is, shift, mask)
-  // (rotl64(rs, shift) & mask) | (is & ~mask)
-  // __rlwimi(rs, is, shift, mask)
-  // (rotl(rs, shift) & mask) | (is & ~mask)
   case PPC::BI__builtin_ppc_rldimi:
   case PPC::BI__builtin_ppc_rlwimi: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Op1 = EmitScalarExpr(E->getArg(1));
 Value *Op2 = EmitScalarExpr(E->getArg(2));
 Value *Op3 = EmitScalarExpr(E->getArg(3));
-llvm::Type *Ty = Op0->getType();
-Function *F = CGM.getIntrinsic(Intrinsic::fshl, Ty);
-if (BuiltinID == PPC::BI__builtin_ppc_rldimi)
-  Op2 = Builder.CreateZExt(Op2, Int64Ty);
-Value *Shift = Builder.CreateCall(F, {Op0, Op0, Op2});
-Value *X = Builder.CreateAnd(Shift, Op3);
-Value *Y = Builder.CreateAnd(Op1, Builder.CreateNot(Op3));
-return Builder.CreateOr(X, Y);
-  }
-  // Rotate and insert under mask operation.
-  // __rlwnm(rs, shift, mask)
-  // rotl(rs, shift) & mask
+return Builder.CreateCall(
+CGM.getIntrinsic(BuiltinID == PPC::BI__builtin_ppc_rldimi
+ ? Intrinsic::ppc_rldimi
+ : Intrinsic::ppc_rlwimi),
+{Op0, Op1, Op2, Op3});
+  }
   case PPC::BI__builtin_ppc_rlwnm: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Op1 = EmitScalarExpr(E->getArg(1));
 Value *Op2 = EmitScalarExpr(E->getArg(2));
-llvm::Type *Ty = Op0->getType();
-Function *F = CGM.getIntrinsic(Intrinsic::fshl, Ty);
-Value *Shift = Builder.CreateCall(F, {Op0, Op0, Op1});
-return Builder.CreateAnd(Shift, Op2);
+return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::ppc_rlwnm),
+  {Op0, Op1, Op2});
   }
   case PPC::BI__builtin_ppc_poppar4:
   case PPC::BI__builtin_ppc_poppar8: {

diff  --git a/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
index d96bfb4621421e..b218547c00d931 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
@@ -16,11 +16,8 @@ void test_builtin_ppc_rldimi() {
   // CHECK:   %res = alloca i64, align 8
   // CHECK-NEXT:  [[RA:%[0-9]+]] = load i64, ptr @ull, align 8
   // CHECK-NEXT:  [[RB:%[0-9]+]] = load i64, ptr @ull, align 8
-  // CHECK-NEXT:  [[RC:%[0-9]+]] = call i64 @llvm.fshl.i64(i64 [[RA]], i64 
[[RA]], i64 63)
-  // CHECK-NEXT:  [[RD:%[0-9]+]] = and i64 [[RC]], 72057593769492480
-  // CHECK-NEXT:  [[RE:%[0-9]+]] = and i64 [[RB]], -72057593769492481
-  // CHECK-NEXT:  [[RF:%[0-9]+]] = or i64 [[RD]], [[RE]]
-  // CHECK-NEXT:  store i64 [[RF]], ptr %res, align 8
+  // CHECK-NEXT:  [[RC:%[0-9]+]] = call i64 @llvm.ppc.rldimi(i64 [[RA]], i64 
[[RB]], i32 63, i64 72057593769492480)
+  // CHECK-NEXT:  store i64 [[RC]], ptr %res, align 8
   // CHECK-NEXT:  ret void
 
   /*shift = 63, mask = 0x00FFF000 = 72057593769492480, ~mask = 
0xFF000FFF = -72057593769492481*/
@@ -32,11 +29,8 @@ void test_builtin_ppc_rlwimi() {
   // CHECK:   %res = alloca i32, align 4
   // CHECK-NEXT:  [[RA:%[0-9]+]] = load i32, ptr @ui, align 4
   // CHECK-NEXT:  [[RB:%[0-9]+]] = load i32, ptr @ui, align 4
-  // CHECK-NEXT:  [[RC:%[0-9]+]] = call i32 @llvm.fshl.i32(i32 [[RA]], i32 
[[RA]], i32 31)
-  // CHECK-NEXT:  [[RD:%[0-9]+]] = and i32 [[RC]], 16776960
-  // CHECK-NEXT:  [[RE:%[0-9]+]] = and i32 [[RB]], -16776961
-  // CHECK-NEXT:  [[RF:%[0-9]+]] = or i32 [[RD]], [[RE]]
-  // CHECK-NEXT:  store i32 [[RF]], ptr %res, align 4
+  // CHECK-NEXT:  [[RC:%[0-9]+]] = call i32 @llvm.ppc.rlwim

[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-04 Thread Qiu Chaofan via cfe-commits

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


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

2024-03-04 Thread Botond István Horváth via cfe-commits

HoBoIs wrote:

I have added tests for rvalref-s and `volatile`-s.

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


[clang] [Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (PR #81102)

2024-03-04 Thread via cfe-commits


@@ -8480,6 +8480,54 @@ class LValueExprEvaluator
 };
 } // end anonymous namespace
 
+/// Get an lvalue to a field of a lambda's closure type.
+static bool GetLambdaCaptureAsLValue(EvalInfo &Info, const Expr *E,
+ LValue &Result, const CXXMethodDecl *MD,
+ const FieldDecl *FD,
+ bool LValueToRValueConversion) {
+  // Static lambda function call operators can't have captures. We already
+  // diagnosed this, so bail out here.
+  if (MD->isStatic()) {
+assert(Info.CurrentCall->This == nullptr &&
+   "This should not be set for a static call operator");
+return false;
+  }
+
+  // Start with 'Result' referring to the complete closure object...
+  if (MD->isExplicitObjectMemberFunction()) {
+// Self may be passed by reference or by value.
+auto *Self = MD->getParamDecl(0);
+if (Self->getType()->isReferenceType()) {
+  APValue *RefValue = Info.getParamSlot(Info.CurrentCall->Arguments, Self);
+  Result.setFrom(Info.Ctx, *RefValue);
+} else {
+  auto *VD = Info.CurrentCall->Arguments.getOrigParam(Self);
+  auto *Frame =
+  Info.getCallFrameAndDepth(Info.CurrentCall->Arguments.CallIndex)
+  .first;
+  auto Version = Info.CurrentCall->Arguments.Version;
+  Result.set({VD, Frame->Index, Version});
+}
+  } else
+Result = *Info.CurrentCall->This;
+
+  // ... then update it to refer to the field of the closure object
+  // that represents the capture.
+  if (!HandleLValueMember(Info, E, Result, FD))
+return false;
+
+  // And if the field is of reference type (or if we captured '*this' by
+  // reference if this is a lambda), update 'Result' to refer to what
+  // the field refers to.

cor3ntin wrote:

```suggestion
  // And if the field is of reference type (or if we captured '*this' by
  // reference), update 'Result' to refer to what
  // the field refers to.
```

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


[clang] [Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (PR #81102)

2024-03-04 Thread via cfe-commits


@@ -8480,6 +8480,54 @@ class LValueExprEvaluator
 };
 } // end anonymous namespace
 
+/// Get an lvalue to a field of a lambda's closure type.
+static bool GetLambdaCaptureAsLValue(EvalInfo &Info, const Expr *E,

cor3ntin wrote:

```suggestion
static bool HandleLambdaCapture(EvalInfo &Info, const Expr *E,
```

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


[clang] [Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (PR #81102)

2024-03-04 Thread via cfe-commits


@@ -8480,6 +8480,54 @@ class LValueExprEvaluator
 };
 } // end anonymous namespace
 
+/// Get an lvalue to a field of a lambda's closure type.
+static bool GetLambdaCaptureAsLValue(EvalInfo &Info, const Expr *E,
+ LValue &Result, const CXXMethodDecl *MD,
+ const FieldDecl *FD,
+ bool LValueToRValueConversion) {
+  // Static lambda function call operators can't have captures. We already
+  // diagnosed this, so bail out here.
+  if (MD->isStatic()) {
+assert(Info.CurrentCall->This == nullptr &&
+   "This should not be set for a static call operator");
+return false;
+  }
+
+  // Start with 'Result' referring to the complete closure object...
+  if (MD->isExplicitObjectMemberFunction()) {
+// Self may be passed by reference or by value.
+auto *Self = MD->getParamDecl(0);
+if (Self->getType()->isReferenceType()) {
+  APValue *RefValue = Info.getParamSlot(Info.CurrentCall->Arguments, Self);
+  Result.setFrom(Info.Ctx, *RefValue);
+} else {
+  auto *VD = Info.CurrentCall->Arguments.getOrigParam(Self);
+  auto *Frame =
+  Info.getCallFrameAndDepth(Info.CurrentCall->Arguments.CallIndex)
+  .first;
+  auto Version = Info.CurrentCall->Arguments.Version;
+  Result.set({VD, Frame->Index, Version});

cor3ntin wrote:

@AaronBallman 

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


[clang] [clang][Interp] Merge ByteCodeExprGen and ByteCodeStmtGen (PR #83683)

2024-03-04 Thread Aaron Ballman via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


AaronBallman wrote:

> When implementing support for `StmtExpr`, I ran into a problem: there is no 
> way for `ByteCodeExprGen` to visit a statement. Previously, `ByteCodeStmtGen` 
> inherited from `ByteCodeExprGen`, so the former could visit expressions, but 
> the latter couldn't visit statements.

I'm a bit confused.
```
class ByteCodeExprGen : public ConstStmtVisitor, bool>,
public Emitter {
```
So `ByteCodeExprGen` can definitely visit statements and expressions.

Can't `ByteCodeStmtGen` call `ByteCodeExprGen::VisitBlah()` so that the base 
class could also handle situations the subclass wasn't prepared to handle?

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


[clang] [Clang] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-04 Thread via cfe-commits

Sirraide wrote:

Apparently, buildbot is mad at me 
()?

I’m not entirely sure how a fix that affects only 
`-fdump-record-layouts-complete` could have caused this. Is this a spurious 
failure or due to something unrelated, or is it worth investigating this?

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


[clang] [Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (PR #81102)

2024-03-04 Thread via cfe-commits


@@ -8480,6 +8480,54 @@ class LValueExprEvaluator
 };
 } // end anonymous namespace
 
+/// Get an lvalue to a field of a lambda's closure type.
+static bool GetLambdaCaptureAsLValue(EvalInfo &Info, const Expr *E,

Sirraide wrote:

That’s probably a better name, yeah; `GetLambdaCaptureAsLValue` is rather 
clumsy, but I couldn’t think of anything better myself.

https://github.com/llvm/llvm-project/pull/81102
___
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-04 Thread Kishan Parmar via cfe-commits

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

>From a89cd20615f3649e2a625eb8da851f9cbdd2d863 Mon Sep 17 00:00:00 2001
From: Kishan Parmar 
Date: Mon, 4 Mar 2024 18:04:20 +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 |  87 +++--
 clang/lib/Driver/ToolChains/Clang.cpp |   9 +
 clang/lib/Frontend/CompilerInvocation.cpp |   8 +
 .../CodeGen/PowerPC/ppc32-complex-gnu-abi.c   | 177 ++
 7 files changed, 281 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 6ad05031962562..64f938dd01 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -224,6 +224,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 3f8fe385fef3df..af22bc00797655 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 3e857f4e6faf87..82d8ab087fe6a5 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2574,6 +2574,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,
   NegFlag(
-CGT, SoftFloatABI, RetSmallStructInRegABI)) {}
+CGT, SoftFloatABI, RetSmallStructInRegABI, ComplexInRegABI)) {}
 
   static bool isStructReturnInRegABI(const llvm::Triple &Triple,
  const CodeGenOptions &Opts);
@@ -337,12 +347,58 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(uint64_t &TypeSize) const {
+  llvm::Type *ElemTy;
+  unsigned RegsNeeded; // Registers Needed for Complex.
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+RegsNeeded = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+RegsNeeded = (TypeSize + 31) / 32;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int &ArgGPRsLeft) const {
+  assert(ArgGPRsLeft <= NumArgGPRs && "Arg GPR tracking underflow");
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+
+  ASTContext &Context = getContext();
+
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  if (IsComplexInRegABI && Ty->isAnyComplexType() &&
+  TypeSize <= RegLen * ArgGPRsLeft) {
+assert(Ty->isAnyComplexType() && "Ty must be Complex type.");
+ArgGPRsLeft -= TypeSize / RegLen;
+return handleComplex(TypeSize);
+  

[clang] [Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (PR #81102)

2024-03-04 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81102

>From d489acbd3cfb656d203e1f05b74c238351c5428a Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Thu, 8 Feb 2024 08:33:03 +0100
Subject: [PATCH 1/3] [Clang] Properly get captured 'this' pointer in lambdas
 with an explicit object parameter in constant evaluator

---
 clang/lib/AST/ExprConstant.cpp| 130 ++
 .../constexpr-explicit-object-lambda.cpp  |  34 +
 2 files changed, 109 insertions(+), 55 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-explicit-object-lambda.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..8dc6348bc7eedb 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8480,6 +8480,54 @@ class LValueExprEvaluator
 };
 } // end anonymous namespace
 
+/// Get an lvalue to a field of a lambda's closure type.
+static bool GetLambdaCaptureAsLValue(EvalInfo &Info, const Expr *E,
+ LValue &Result, const CXXMethodDecl *MD,
+ const FieldDecl *FD,
+ bool LValueToRValueConversion) {
+  // Static lambda function call operators can't have captures. We already
+  // diagnosed this, so bail out here.
+  if (MD->isStatic()) {
+assert(Info.CurrentCall->This == nullptr &&
+   "This should not be set for a static call operator");
+return false;
+  }
+
+  // Start with 'Result' referring to the complete closure object...
+  if (MD->isExplicitObjectMemberFunction()) {
+// Self may be passed by reference or by value.
+auto *Self = MD->getParamDecl(0);
+if (Self->getType()->isReferenceType()) {
+  APValue *RefValue = Info.getParamSlot(Info.CurrentCall->Arguments, Self);
+  Result.setFrom(Info.Ctx, *RefValue);
+} else {
+  auto *VD = Info.CurrentCall->Arguments.getOrigParam(Self);
+  auto *Frame =
+  Info.getCallFrameAndDepth(Info.CurrentCall->Arguments.CallIndex)
+  .first;
+  auto Version = Info.CurrentCall->Arguments.Version;
+  Result.set({VD, Frame->Index, Version});
+}
+  } else
+Result = *Info.CurrentCall->This;
+
+  // ... then update it to refer to the field of the closure object
+  // that represents the capture.
+  if (!HandleLValueMember(Info, E, Result, FD))
+return false;
+
+  // And if the field is of reference type (or if we captured '*this' by
+  // reference if this is a lambda), update 'Result' to refer to what
+  // the field refers to.
+  if (LValueToRValueConversion) {
+APValue RVal;
+if (!handleLValueToRValueConversion(Info, E, FD->getType(), Result, RVal))
+  return false;
+Result.setFrom(Info.Ctx, RVal);
+  }
+  return true;
+}
+
 /// Evaluate an expression as an lvalue. This can be legitimately called on
 /// expressions which are not glvalues, in three cases:
 ///  * function designators in C, and
@@ -8524,37 +8572,8 @@ bool LValueExprEvaluator::VisitVarDecl(const Expr *E, 
const VarDecl *VD) {
 
 if (auto *FD = Info.CurrentCall->LambdaCaptureFields.lookup(VD)) {
   const auto *MD = cast(Info.CurrentCall->Callee);
-
-  // Static lambda function call operators can't have captures. We already
-  // diagnosed this, so bail out here.
-  if (MD->isStatic()) {
-assert(Info.CurrentCall->This == nullptr &&
-   "This should not be set for a static call operator");
-return false;
-  }
-
-  // Start with 'Result' referring to the complete closure object...
-  if (MD->isExplicitObjectMemberFunction()) {
-APValue *RefValue =
-Info.getParamSlot(Info.CurrentCall->Arguments, 
MD->getParamDecl(0));
-Result.setFrom(Info.Ctx, *RefValue);
-  } else
-Result = *Info.CurrentCall->This;
-
-  // ... then update it to refer to the field of the closure object
-  // that represents the capture.
-  if (!HandleLValueMember(Info, E, Result, FD))
-return false;
-  // And if the field is of reference type, update 'Result' to refer to 
what
-  // the field refers to.
-  if (FD->getType()->isReferenceType()) {
-APValue RVal;
-if (!handleLValueToRValueConversion(Info, E, FD->getType(), Result,
-RVal))
-  return false;
-Result.setFrom(Info.Ctx, RVal);
-  }
-  return true;
+  return GetLambdaCaptureAsLValue(Info, E, Result, MD, FD,
+  FD->getType()->isReferenceType());
 }
   }
 
@@ -9032,45 +9051,46 @@ class PointerExprEvaluator
 return Error(E);
   }
   bool VisitCXXThisExpr(const CXXThisExpr *E) {
-// Can't look at 'this' when checking a potential constant expression.
-if (Info.checkingPotentialConstantExpression())
-  return false;
-if (!Info.CurrentCall->This) {
+auto DiagnoseInvalidUseOfThis = [&] {
   if (Info.get

[clang] Reland "[clang][modules] Print library module manifest path." (PR #82160)

2024-03-04 Thread Kazushi Marukawa via cfe-commits

kaz7 wrote:

Unfortunately, this is breaking VE buildbot again.  I'll check the source of 
your problem, but can you revert your patch once?

https://lab.llvm.org/buildbot/#/builders/91/builds/23291

https://github.com/llvm/llvm-project/pull/82160
___
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-04 Thread Kishan Parmar via cfe-commits


@@ -271,22 +271,33 @@ namespace {
 class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
+  bool isComplexInRegABI;
+  // Size of GPR in bits
+  unsigned RLen;
+  static const int NumArgGPRs = 8;
 
   CharUnits getParamTypeAlignment(QualType Ty) const;
+  ABIArgInfo handleComplex(QualType Ty, uint64_t &TypeSize) const;
 
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, bool SoftFloatABI,
- bool RetSmallStructInRegABI)
+ bool RetSmallStructInRegABI, unsigned RLen,
+ bool ComplexInRegABI)
   : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI),
-IsRetSmallStructInRegABI(RetSmallStructInRegABI) {}
+IsRetSmallStructInRegABI(RetSmallStructInRegABI),
+isComplexInRegABI(ComplexInRegABI), RLen(RLen) {}
 
   ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType Ty, int &ArgGPRsLeft) const;
 
   void computeInfo(CGFunctionInfo &FI) const override {
+
+int ArgGPRsLeft = NumArgGPRs;

Long5hot wrote:

Couldn't understand what you mean here..

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


[clang] [Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (PR #81102)

2024-03-04 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81102

>From d489acbd3cfb656d203e1f05b74c238351c5428a Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Thu, 8 Feb 2024 08:33:03 +0100
Subject: [PATCH 1/4] [Clang] Properly get captured 'this' pointer in lambdas
 with an explicit object parameter in constant evaluator

---
 clang/lib/AST/ExprConstant.cpp| 130 ++
 .../constexpr-explicit-object-lambda.cpp  |  34 +
 2 files changed, 109 insertions(+), 55 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-explicit-object-lambda.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..8dc6348bc7eedb 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8480,6 +8480,54 @@ class LValueExprEvaluator
 };
 } // end anonymous namespace
 
+/// Get an lvalue to a field of a lambda's closure type.
+static bool GetLambdaCaptureAsLValue(EvalInfo &Info, const Expr *E,
+ LValue &Result, const CXXMethodDecl *MD,
+ const FieldDecl *FD,
+ bool LValueToRValueConversion) {
+  // Static lambda function call operators can't have captures. We already
+  // diagnosed this, so bail out here.
+  if (MD->isStatic()) {
+assert(Info.CurrentCall->This == nullptr &&
+   "This should not be set for a static call operator");
+return false;
+  }
+
+  // Start with 'Result' referring to the complete closure object...
+  if (MD->isExplicitObjectMemberFunction()) {
+// Self may be passed by reference or by value.
+auto *Self = MD->getParamDecl(0);
+if (Self->getType()->isReferenceType()) {
+  APValue *RefValue = Info.getParamSlot(Info.CurrentCall->Arguments, Self);
+  Result.setFrom(Info.Ctx, *RefValue);
+} else {
+  auto *VD = Info.CurrentCall->Arguments.getOrigParam(Self);
+  auto *Frame =
+  Info.getCallFrameAndDepth(Info.CurrentCall->Arguments.CallIndex)
+  .first;
+  auto Version = Info.CurrentCall->Arguments.Version;
+  Result.set({VD, Frame->Index, Version});
+}
+  } else
+Result = *Info.CurrentCall->This;
+
+  // ... then update it to refer to the field of the closure object
+  // that represents the capture.
+  if (!HandleLValueMember(Info, E, Result, FD))
+return false;
+
+  // And if the field is of reference type (or if we captured '*this' by
+  // reference if this is a lambda), update 'Result' to refer to what
+  // the field refers to.
+  if (LValueToRValueConversion) {
+APValue RVal;
+if (!handleLValueToRValueConversion(Info, E, FD->getType(), Result, RVal))
+  return false;
+Result.setFrom(Info.Ctx, RVal);
+  }
+  return true;
+}
+
 /// Evaluate an expression as an lvalue. This can be legitimately called on
 /// expressions which are not glvalues, in three cases:
 ///  * function designators in C, and
@@ -8524,37 +8572,8 @@ bool LValueExprEvaluator::VisitVarDecl(const Expr *E, 
const VarDecl *VD) {
 
 if (auto *FD = Info.CurrentCall->LambdaCaptureFields.lookup(VD)) {
   const auto *MD = cast(Info.CurrentCall->Callee);
-
-  // Static lambda function call operators can't have captures. We already
-  // diagnosed this, so bail out here.
-  if (MD->isStatic()) {
-assert(Info.CurrentCall->This == nullptr &&
-   "This should not be set for a static call operator");
-return false;
-  }
-
-  // Start with 'Result' referring to the complete closure object...
-  if (MD->isExplicitObjectMemberFunction()) {
-APValue *RefValue =
-Info.getParamSlot(Info.CurrentCall->Arguments, 
MD->getParamDecl(0));
-Result.setFrom(Info.Ctx, *RefValue);
-  } else
-Result = *Info.CurrentCall->This;
-
-  // ... then update it to refer to the field of the closure object
-  // that represents the capture.
-  if (!HandleLValueMember(Info, E, Result, FD))
-return false;
-  // And if the field is of reference type, update 'Result' to refer to 
what
-  // the field refers to.
-  if (FD->getType()->isReferenceType()) {
-APValue RVal;
-if (!handleLValueToRValueConversion(Info, E, FD->getType(), Result,
-RVal))
-  return false;
-Result.setFrom(Info.Ctx, RVal);
-  }
-  return true;
+  return GetLambdaCaptureAsLValue(Info, E, Result, MD, FD,
+  FD->getType()->isReferenceType());
 }
   }
 
@@ -9032,45 +9051,46 @@ class PointerExprEvaluator
 return Error(E);
   }
   bool VisitCXXThisExpr(const CXXThisExpr *E) {
-// Can't look at 'this' when checking a potential constant expression.
-if (Info.checkingPotentialConstantExpression())
-  return false;
-if (!Info.CurrentCall->This) {
+auto DiagnoseInvalidUseOfThis = [&] {
   if (Info.get

[clang] 6e36ceb - [Clang][Docs] Simpler syntax for Github links. (#82746)

2024-03-04 Thread via cfe-commits

Author: cor3ntin
Date: 2024-03-04T14:22:51+01:00
New Revision: 6e36cebc17417f88e70b4e87c9f177036b1443f4

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

LOG: [Clang][Docs] Simpler syntax for Github links. (#82746)

Github links in release notes are often invalid rST, clutter the release
notes and are annoying to write.

This introduces a sphynx plugin that rewrites
 `#GH` to a link to the corresponding issue.

Added: 
clang/docs/ghlinks.py

Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/conf.py

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 045bcd16d62a27..c239c97f7afc91 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -79,7 +79,7 @@ C++20 Feature Support
   more to ease the implementation and improve the user's using experience.
   This follows the MSVC's behavior. Users interested in testing the more strict
   behavior can use the flag '-Xclang -fno-skip-odr-check-in-gmf'.
-  (`#79240 `_).
+  (#GH79240).
 
 - Implemented the `__is_layout_compatible` intrinsic to support
   `P0466R5: Layout-compatibility and Pointer-interconvertibility Traits 
`_.
@@ -116,7 +116,7 @@ C Language Changes
 C23 Feature Support
 ^^^
 - No longer diagnose use of binary literals as an extension in C23 mode. Fixes
-  `#72017 `_.
+  #GH72017.
 
 - Corrected parsing behavior for the ``alignas`` specifier/qualifier in C23. We
   previously handled it as an attribute as in C++, but there are parsing
@@ -129,7 +129,7 @@ C23 Feature Support
  };
  int i alignas(8) /* was accepted, now rejected */ ;
 
-  Fixes (`#81472 `_).
+  Fixes (#GH81472).
 
 - Clang now generates predefined macros of the form ``__TYPE_FMTB__`` and
   ``__TYPE_FMTb__`` (e.g., ``__UINT_FAST64_FMTB__``) in C23 mode for use with
@@ -173,7 +173,7 @@ Improvements to Clang's diagnostics
   name specifiers.
 
 - The ``-Wshorten-64-to-32`` diagnostic is now grouped under 
``-Wimplicit-int-conversion`` instead
-   of ``-Wconversion``. Fixes `#69444 
`_.
+   of ``-Wconversion``. Fixes #GH69444.
 
 - Clang now diagnoses friend declarations with an ``enum`` 
elaborated-type-specifier in language modes after C++98.
 
@@ -186,14 +186,14 @@ Improvements to Clang's diagnostics
   ``unsigned long long``, but this behavior may change in the future when Clang
   implements
   `WG14 N3029 `_.
-  Fixes `#69352 `_.
+  (#GH69352).
 
 - Clang now diagnoses extraneous template parameter lists as a language 
extension.
 
 - Clang now diagnoses declarative nested name specifiers that name alias 
templates.
 
 - Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
-  Fixes `#82512 `_.
+  Fixes #GH82512.
 
 Improvements to Clang's time-trace
 --
@@ -206,21 +206,21 @@ Bug Fixes in This Version
 - Clang now accepts elaborated-type-specifiers that explicitly specialize
   a member class template for an implicit instantiation of a class template.
 
-- Fixed missing warnings when doing bool-like conversions in C23 (`#79435 
`_).
+- Fixed missing warnings when doing bool-like conversions in C23 (#GH79435).
 - Clang's ``-Wshadow`` no longer warns when an init-capture is named the same 
as
   a class field unless the lambda can capture this.
-  Fixes (`#71976 `_)
+  Fixes (#GH71976)
 
 - Clang now accepts qualified partial/explicit specializations of variable 
templates that
   are not nominable in the lookup context of the specialization.
 
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
-  Fixes (`#64356 `_).
+  Fixes (#GH64356).
 
 - Clang no longer produces a false-positive `-Wunused-variable` warning
   for variables created through copy initialization having side-effects in 
C++17 and later.
-  Fixes (`#79518 `_).
+  Fixes (#GH64356) (#GH79518).
 
 Bug Fixes to Compiler Builtins
 ^^
@@ -232,84 +232,67 @@ Bug Fixes to C++ Support
 
 
 - Fix crash when calling the constructor of an invalid class.
-  Fixes (`#10518 

[clang] [Clang][Docs] Simpler syntax for Github links. (PR #82746)

2024-03-04 Thread via cfe-commits

https://github.com/cor3ntin closed 
https://github.com/llvm/llvm-project/pull/82746
___
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-04 Thread Kishan Parmar via cfe-commits


@@ -0,0 +1,177 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+
+// RUN: %clang_cc1 -triple powerpc-unknown-linux-gnu \
+// RUN:   -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-DEF
+// RUN: %clang_cc1 -triple powerpc-unknown-linux-gnu -fcomplex-ppc-gnu-abi \
+// RUN:   -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-GNU
+
+// CHECK-DEF-LABEL: define dso_local void @foo1
+// CHECK-DEF-SAME: (ptr dead_on_unwind noalias writable sret({ float, float }) 
align 4 [[AGG_RESULT:%.*]], ptr noundef byval({ float, float }) align 4 
[[X:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-DEF-NEXT:  entry:
+// CHECK-DEF-NEXT:[[X_REALP:%.*]] = getelementptr inbounds { float, float 
}, ptr [[X]], i32 0, i32 0
+// CHECK-DEF-NEXT:[[X_REAL:%.*]] = load float, ptr [[X_REALP]], align 4
+// CHECK-DEF-NEXT:[[X_IMAGP:%.*]] = getelementptr inbounds { float, float 
}, ptr [[X]], i32 0, i32 1
+// CHECK-DEF-NEXT:[[X_IMAG:%.*]] = load float, ptr [[X_IMAGP]], align 4
+// CHECK-DEF-NEXT:[[AGG_RESULT_REALP:%.*]] = getelementptr inbounds { 
float, float }, ptr [[AGG_RESULT]], i32 0, i32 0
+// CHECK-DEF-NEXT:[[AGG_RESULT_IMAGP:%.*]] = getelementptr inbounds { 
float, float }, ptr [[AGG_RESULT]], i32 0, i32 1
+// CHECK-DEF-NEXT:store float [[X_REAL]], ptr [[AGG_RESULT_REALP]], align 4
+// CHECK-DEF-NEXT:store float [[X_IMAG]], ptr [[AGG_RESULT_IMAGP]], align 4
+// CHECK-DEF-NEXT:[[AGG_RESULT_REALP1:%.*]] = getelementptr inbounds { 
float, float }, ptr [[AGG_RESULT]], i32 0, i32 0
+// CHECK-DEF-NEXT:[[AGG_RESULT_REAL:%.*]] = load float, ptr 
[[AGG_RESULT_REALP1]], align 4
+// CHECK-DEF-NEXT:[[AGG_RESULT_IMAGP2:%.*]] = getelementptr inbounds { 
float, float }, ptr [[AGG_RESULT]], i32 0, i32 1
+// CHECK-DEF-NEXT:[[AGG_RESULT_IMAG:%.*]] = load float, ptr 
[[AGG_RESULT_IMAGP2]], align 4
+// CHECK-DEF-NEXT:[[AGG_RESULT_REALP3:%.*]] = getelementptr inbounds { 
float, float }, ptr [[AGG_RESULT]], i32 0, i32 0
+// CHECK-DEF-NEXT:[[AGG_RESULT_IMAGP4:%.*]] = getelementptr inbounds { 
float, float }, ptr [[AGG_RESULT]], i32 0, i32 1
+// CHECK-DEF-NEXT:store float [[AGG_RESULT_REAL]], ptr 
[[AGG_RESULT_REALP3]], align 4
+// CHECK-DEF-NEXT:store float [[AGG_RESULT_IMAG]], ptr 
[[AGG_RESULT_IMAGP4]], align 4
+// CHECK-DEF-NEXT:ret void
+//
+// CHECK-GNU-LABEL: define dso_local [1 x i64] @foo1
+// CHECK-GNU-SAME: ([1 x i64] noundef [[X_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-GNU-NEXT:  entry:
+// CHECK-GNU-NEXT:[[RETVAL:%.*]] = alloca { float, float }, align 4
+// CHECK-GNU-NEXT:[[X:%.*]] = alloca { float, float }, align 4
+// CHECK-GNU-NEXT:store [1 x i64] [[X_COERCE]], ptr [[X]], align 4
+// CHECK-GNU-NEXT:[[X_REALP:%.*]] = getelementptr inbounds { float, float 
}, ptr [[X]], i32 0, i32 0
+// CHECK-GNU-NEXT:[[X_REAL:%.*]] = load float, ptr [[X_REALP]], align 4
+// CHECK-GNU-NEXT:[[X_IMAGP:%.*]] = getelementptr inbounds { float, float 
}, ptr [[X]], i32 0, i32 1
+// CHECK-GNU-NEXT:[[X_IMAG:%.*]] = load float, ptr [[X_IMAGP]], align 4
+// CHECK-GNU-NEXT:[[RETVAL_REALP:%.*]] = getelementptr inbounds { float, 
float }, ptr [[RETVAL]], i32 0, i32 0
+// CHECK-GNU-NEXT:[[RETVAL_IMAGP:%.*]] = getelementptr inbounds { float, 
float }, ptr [[RETVAL]], i32 0, i32 1
+// CHECK-GNU-NEXT:store float [[X_REAL]], ptr [[RETVAL_REALP]], align 4
+// CHECK-GNU-NEXT:store float [[X_IMAG]], ptr [[RETVAL_IMAGP]], align 4
+// CHECK-GNU-NEXT:[[TMP0:%.*]] = load [1 x i64], ptr [[RETVAL]], align 4
+// CHECK-GNU-NEXT:ret [1 x i64] [[TMP0]]
+//
+_Complex float foo1(_Complex float x) {
+  return x;
+}
+
+// CHECK-DEF-LABEL: define dso_local void @foo2
+// CHECK-DEF-SAME: (ptr dead_on_unwind noalias writable sret({ double, double 
}) align 8 [[AGG_RESULT:%.*]], ptr noundef byval({ double, double }) align 8 
[[X:%.*]]) #[[ATTR0]] {
+// CHECK-DEF-NEXT:  entry:
+// CHECK-DEF-NEXT:[[X_REALP:%.*]] = getelementptr inbounds { double, 
double }, ptr [[X]], i32 0, i32 0
+// CHECK-DEF-NEXT:[[X_REAL:%.*]] = load double, ptr [[X_REALP]], align 8
+// CHECK-DEF-NEXT:[[X_IMAGP:%.*]] = getelementptr inbounds { double, 
double }, ptr [[X]], i32 0, i32 1
+// CHECK-DEF-NEXT:[[X_IMAG:%.*]] = load double, ptr [[X_IMAGP]], align 8
+// CHECK-DEF-NEXT:[[AGG_RESULT_REALP:%.*]] = getelementptr inbounds { 
double, double }, ptr [[AGG_RESULT]], i32 0, i32 0
+// CHECK-DEF-NEXT:[[AGG_RESULT_IMAGP:%.*]] = getelementptr inbounds { 
double, double }, ptr [[AGG_RESULT]], i32 0, i32 1
+// CHECK-DEF-NEXT:store double [[X_REAL]], ptr [[AGG_RESULT_REALP]], align 
8
+// CHECK-DEF-NEXT:store double [[X_IMAG]], ptr [[AGG_RESULT_IMAGP]], align 
8
+// CHECK-DEF-NEXT:[[AGG_RESULT_REALP1:%.*]] = getelementptr inbounds { 
double, double }, ptr [[AGG_RESULT]], i32 0, i32 0
+// CHECK-DEF-NEXT:[[AGG_RESULT_REAL:%.*]] = load double, ptr 
[[AGG_RESULT_REALP1]], align 8
+// CHECK-DEF-NEXT:[[AGG_

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

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


@@ -337,12 +350,77 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(QualType Ty,
+ uint64_t &TypeSize) const {
+
+  assert(Ty->isAnyComplexType());
+  llvm::Type *ElemTy;
+  unsigned SizeRegs;
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+SizeRegs = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());

Long5hot wrote:

Reason for using llvm::Type::getInt64Ty(getVMContext()) for floats here was to 
follow ABI ATR-PASS-COMPLEX-IN-GPRS

> complex single-precision float : If gr is even, set gr = gr + 1. Load the 
> lower-addressed word of the
> argument into gr and the higher-addressed word into gr + 1, set gr = gr + 2.
> 
> complex double-precision float: Load the words of the argument, in 
> memory-address order, into gr, gr + 1,
> gr + 2 and gr + 3, set gr = gr + 4.

You can check the previous discussion here. : https://reviews.llvm.org/D146942

https://github.com/llvm/llvm-project/pull/77732
___
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-04 Thread Kishan Parmar via cfe-commits


@@ -337,12 +350,77 @@ CharUnits 
PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   return CharUnits::fromQuantity(4);
 }
 
+ABIArgInfo PPC32_SVR4_ABIInfo::handleComplex(QualType Ty,
+ uint64_t &TypeSize) const {
+
+  assert(Ty->isAnyComplexType());
+  llvm::Type *ElemTy;
+  unsigned SizeRegs;
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+SizeRegs = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());

Long5hot wrote:

> llvm::Type *ElemTy = llvm::Type::getInt64Ty(getVMContext());
> unsigned SizeRegs = TypeSize/64;


Since Typesize will be 64, in if is it necessary to replace 1 to TypeSize/64?

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


[clang] [clang] Implement __builtin_{clzg,ctzg} (PR #83431)

2024-03-04 Thread via cfe-commits

https://github.com/overmighty updated 
https://github.com/llvm/llvm-project/pull/83431

>From 5e37b3b2f57c7683686b8ac64aa1566855826a9f Mon Sep 17 00:00:00 2001
From: OverMighty 
Date: Thu, 29 Feb 2024 14:23:40 +
Subject: [PATCH 1/2] [clang] Implement __builtin_{clzg,ctzg}

Fixes #83075, fixes #83076.
---
 clang/docs/LanguageExtensions.rst |  41 
 clang/include/clang/Basic/Builtins.td |  12 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  15 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |  40 +++-
 clang/lib/Sema/SemaChecking.cpp   |  53 +
 clang/test/CodeGen/builtins.c | 204 ++
 clang/test/CodeGen/ubsan-builtin-checks.c |   6 +
 clang/test/Sema/builtin-popcountg.c   |  23 --
 clang/test/Sema/count-builtins.c  |  87 
 9 files changed, 445 insertions(+), 36 deletions(-)
 delete mode 100644 clang/test/Sema/builtin-popcountg.c
 create mode 100644 clang/test/Sema/count-builtins.c

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index bcd69198eafdbe..3d73d772f698ba 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3504,6 +3504,47 @@ argument can be of any unsigned integer type.
 ``__builtin_popcount{,l,ll}`` builtins, with support for other integer types,
 such as ``unsigned __int128`` and C23 ``unsigned _BitInt(N)``.
 
+``__builtin_clzg`` and ``__builtin_ctzg``
+-
+
+``__builtin_clzg`` (respectively ``__builtin_ctzg``) returns the number of
+leading (respectively trailing) 0 bits in the first argument. The first 
argument
+can be of any unsigned integer type.
+
+If the first argument is 0 and an optional second argument of ``int`` type is
+provided, then the second argument is returned. If the first argument is 0, but
+only one argument is provided, then the returned value is undefined.
+
+**Syntax**:
+
+.. code-block:: c++
+
+  int __builtin_clzg(type x[, int fallback])
+  int __builtin_ctzg(type x[, int fallback])
+
+**Examples**:
+
+.. code-block:: c++
+
+  unsigned int x = 1;
+  int x_lz = __builtin_clzg(x);
+  int x_tz = __builtin_ctzg(x);
+
+  unsigned long y = 2;
+  int y_lz = __builtin_clzg(y);
+  int y_tz = __builtin_ctzg(y);
+
+  unsigned _BitInt(128) z = 4;
+  int z_lz = __builtin_clzg(z);
+  int z_tz = __builtin_ctzg(z);
+
+**Description**:
+
+``__builtin_clzg`` (respectively ``__builtin_ctzg``) is meant to be a
+type-generic alternative to the ``__builtin_clz{,l,ll}`` (respectively
+``__builtin_ctz{,l,ll}``) builtins, with support for other integer types, such
+as ``unsigned __int128`` and C23 ``unsigned _BitInt(N)``.
+
 Multiprecision Arithmetic Builtins
 --
 
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 2c83dca248fb7d..206ccaf1bdaa13 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -662,6 +662,12 @@ def Clz : Builtin, BitShort_Int_Long_LongLongTemplate {
 
 // FIXME: Add int clzimax(uintmax_t)
 
+def Clzg : Builtin {
+  let Spellings = ["__builtin_clzg"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "int(...)";
+}
+
 def Ctz : Builtin, BitShort_Int_Long_LongLongTemplate {
   let Spellings = ["__builtin_ctz"];
   let Attributes = [NoThrow, Const, Constexpr];
@@ -670,6 +676,12 @@ def Ctz : Builtin, BitShort_Int_Long_LongLongTemplate {
 
 // FIXME: Add int ctzimax(uintmax_t)
 
+def Ctzg : Builtin {
+  let Spellings = ["__builtin_ctzg"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "int(...)";
+}
+
 def FFS : Builtin, BitInt_Long_LongLongTemplate {
   let Spellings = ["__builtin_ffs"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const, Constexpr];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 91105d4231f06a..a65052e2b54f29 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11978,13 +11978,14 @@ def err_builtin_launder_invalid_arg : Error<
   "'__builtin_launder' is not allowed">;
 
 def err_builtin_invalid_arg_type: Error <
-  "%ordinal0 argument must be a "
-  "%select{vector, integer or floating point type|matrix|"
-  "pointer to a valid matrix element type|"
-  "signed integer or floating point type|vector type|"
-  "floating point type|"
-  "vector of integers|"
-  "type of unsigned integer}1 (was %2)">;
+  "%ordinal0 argument must be "
+  "%select{a vector, integer or floating point type|a matrix|"
+  "a pointer to a valid matrix element type|"
+  "a signed integer or floating point type|a vector type|"
+  "a floating point type|"
+  "a vector of integers|"
+  "an unsigned integer|"
+  "an 'int'}1 (was %2)">;
 
 def err_builtin_matrix_disabled: Error<
   "matrix types extension is disabled. Pass -fenable-matrix to ena

[clang] [Clang] Fix looking for immediate calls in default arguments. (PR #80690)

2024-03-04 Thread via cfe-commits

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

>From 690a251c4d8df2099b213ba63e9836c2752b5ac1 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Mon, 5 Feb 2024 15:42:21 +0100
Subject: [PATCH 1/2] [Clang] Fix looking for immediate calls in default
 arguments.

Due to improper use of RecursiveASTVisitor.

Fixes #80630
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaExpr.cpp|  6 +++---
 .../SemaCXX/cxx2a-consteval-default-params.cpp | 15 +++
 clang/test/SemaCXX/source_location.cpp | 18 ++
 4 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c239c97f7afc91..9ebff537e11079 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -294,6 +294,8 @@ Bug Fixes to C++ Support
   instead of only on class, alias, and variable templates, as last updated by
   CWG2032. Fixes (#GH#83461)
 
+- Fix evaluation of some immediate calls in default arguments.
+  Fixes (#GH80630)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 0a449fc1082bd4..9b4c3440448ba8 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6199,7 +6199,7 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
   bool VisitCallExpr(CallExpr *E) {
 if (const FunctionDecl *FD = E->getDirectCallee())
   HasImmediateCalls |= FD->isImmediateFunction();
-return RecursiveASTVisitor::VisitStmt(E);
+return RecursiveASTVisitor::VisitCallExpr(E);
   }
 
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
@@ -6229,9 +6229,9 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
 
   // Blocks don't support default parameters, and, as for lambdas,
   // we don't consider their body a subexpression.
-  bool VisitBlockDecl(BlockDecl *B) { return false; }
+  bool VisitBlockDecl(BlockDecl *B) { return true; }
 
-  bool VisitCompoundStmt(CompoundStmt *B) { return false; }
+  bool VisitCompoundStmt(CompoundStmt *B) { return true; }
 
   bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
 return TraverseStmt(E->getExpr());
diff --git a/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp 
b/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
index be8f7cc788589f..e4b13725b2dacd 100644
--- a/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -82,3 +82,18 @@ namespace GH62224 {
   C<> Val; // No error since fwd is defined already.
   static_assert(Val.get() == 42);
 }
+
+namespace GH80630 {
+
+consteval const char* ce() { return "Hello"; }
+
+auto f2(const char* loc = []( char const* fn )
+{ return fn; }  ( ce() ) ) {
+return loc;
+}
+
+auto g() {
+return f2();
+}
+
+}
diff --git a/clang/test/SemaCXX/source_location.cpp 
b/clang/test/SemaCXX/source_location.cpp
index 7414fbce7828d1..b151fc45fdad62 100644
--- a/clang/test/SemaCXX/source_location.cpp
+++ b/clang/test/SemaCXX/source_location.cpp
@@ -832,3 +832,21 @@ void test() {
 }
 
 }
+
+namespace GH80630 {
+
+#define GH80630_LAMBDA \
+[]( char const* fn ) { \
+static constexpr std::source_location loc = 
std::source_location::current(); \
+return &loc; \
+}( std::source_location::current().function() )
+
+auto f( std::source_location const* loc = GH80630_LAMBDA ) {
+return loc;
+}
+
+auto g() {
+return f();
+}
+
+}

>From 077db5232f786b1298ae01edc4f8e2b165aef80a Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Sun, 18 Feb 2024 14:45:22 +0100
Subject: [PATCH 2/2] Address Aaron's feedback

---
 clang/lib/Sema/SemaExpr.cpp | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9b4c3440448ba8..47bb263f56aade 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6199,7 +6199,7 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
   bool VisitCallExpr(CallExpr *E) {
 if (const FunctionDecl *FD = E->getDirectCallee())
   HasImmediateCalls |= FD->isImmediateFunction();
-return RecursiveASTVisitor::VisitCallExpr(E);
+return RecursiveASTVisitor::VisitStmt(E);
   }
 
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
@@ -6227,12 +6227,6 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
 return VisitCXXMethodDecl(E->getCallOperator());
   }
 
-  // Blocks don't support default parameters, and, as for lambdas,
-  // we don't consider their body a subexpression.
-  bool VisitBlockDecl(BlockDecl *B) { return true; }
-
-  bool VisitCompoundStmt(CompoundStmt *B) { return true; }
-
   bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
 return TraverseStmt(E->getExpr());
   }

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

[clang] [clang] Implement __builtin_{clzg,ctzg} (PR #83431)

2024-03-04 Thread via cfe-commits


@@ -2212,6 +2212,54 @@ static bool SemaBuiltinPopcountg(Sema &S, CallExpr 
*TheCall) {
   return false;
 }
 
+/// Checks that __builtin_{clzg,ctzg} was called with a first argument, which 
is
+/// an unsigned integer, and an optional second argument, which is promoted to
+/// an 'int'.
+static bool SemaBuiltinCountZeroBitsGeneric(Sema &S, CallExpr *TheCall) {
+  if (checkArgCountRange(S, TheCall, 1, 2))
+return true;
+
+  ExprResult Arg0Res = S.DefaultLvalueConversion(TheCall->getArg(0));
+  if (Arg0Res.isInvalid())
+return true;
+
+  Expr *Arg0 = Arg0Res.get();
+  TheCall->setArg(0, Arg0);
+
+  QualType Arg0Ty = Arg0->getType();
+
+  if (!Arg0Ty->isUnsignedIntegerType()) {
+S.Diag(Arg0->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+<< 1 << /*unsigned integer ty*/ 7 << Arg0Ty;
+return true;
+  }
+
+  if (TheCall->getNumArgs() > 1) {
+ExprResult Arg1Res = S.DefaultLvalueConversion(TheCall->getArg(1));
+if (Arg1Res.isInvalid())
+  return true;
+
+Expr *Arg1 = Arg1Res.get();
+TheCall->setArg(1, Arg1);
+
+QualType Arg1Ty = Arg1->getType();
+
+if (S.Context.isPromotableIntegerType(Arg1Ty)) {

overmighty wrote:

I had forgotten about `Sema::UsualUnaryConversions`, I think that's what I want.

https://github.com/llvm/llvm-project/pull/83431
___
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-04 Thread Kishan Parmar via cfe-commits


@@ -78,6 +78,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 SRCK_InRegs// Small structs in registers (-freg-struct-return).
   };
 
+  enum ComplexArgumentConventionKind {
+CMPLX_Default,
+CMPLX_OnStack,

Long5hot wrote:

This was for future reference, if any arch wants to use this.

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


[clang] [clang] Implement __builtin_{clzg,ctzg} (PR #83431)

2024-03-04 Thread via cfe-commits


@@ -3157,7 +3177,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 if (Result->getType() != ResultType)

overmighty wrote:

Right. Is it worth making tests for this with a target where 
`isCLZForZeroUndef()` is false?

https://github.com/llvm/llvm-project/pull/83431
___
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-04 Thread Kishan Parmar via cfe-commits


@@ -271,22 +271,32 @@ namespace {
 class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
   bool IsSoftFloatABI;
   bool IsRetSmallStructInRegABI;
+  bool IsComplexInRegABI;
+  // Size of GPR in bits.
+  static const unsigned RegLen = 32;
+  static const int NumArgGPRs = 8;

Long5hot wrote:

The purpose of NumArgGPRs or ArgGPRsLeft is limited to complex types.

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


[clang] [clang] Add -Wmissing-designated-field-initializers (PR #81364)

2024-03-04 Thread Vadim D. via cfe-commits

vvd170501 wrote:

Ping

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


[clang] [clang-tools-extra] clangd: Show argument names for function pointer struct fields (PR #69011)

2024-03-04 Thread via cfe-commits

https://github.com/Qwinci updated 
https://github.com/llvm/llvm-project/pull/69011

>From a7e8d6cf9d8339ce49494b1889e3099d313b1b0f Mon Sep 17 00:00:00 2001
From: Qwinci <32550582+qwi...@users.noreply.github.com>
Date: Fri, 13 Oct 2023 19:38:19 +0300
Subject: [PATCH] clangd: Show argument names for function pointer struct
 fields

---
 .../clangd/unittests/CodeCompleteTests.cpp  | 17 +
 clang/lib/Sema/SemaCodeComplete.cpp |  6 ++
 2 files changed, 23 insertions(+)

diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp 
b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 766998eb4f3c71..bd88a0912b537d 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1462,6 +1462,23 @@ TEST(SignatureHelpTest, FunctionPointers) {
 typedef void (__stdcall *fn)(int x, int y);
 fn foo;
 int main() { foo(^); }
+  )cpp",
+  // Field of function pointer type
+  R"cpp(
+struct S {
+  void (*foo)(int x, int y);
+};
+S s;
+int main() { s.foo(^); }
+  )cpp",
+  // Field of function pointer typedef type
+  R"cpp(
+typedef void (*fn)(int x, int y);
+struct S {
+  fn foo;
+};
+S s;
+int main() { s.foo(^); }
   )cpp"};
   for (auto Test : Tests)
 EXPECT_THAT(signatures(Test).signatures,
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index adb82d3f6d176a..c4c169da78f257 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -6133,6 +6133,7 @@ ProduceSignatureHelp(Sema &SemaRef, 
MutableArrayRef Candidates,
 // so that we can recover argument names from it.
 static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
   TypeLoc Target;
+
   if (const auto *T = Fn->getType().getTypePtr()->getAs()) {
 Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
 
@@ -6141,6 +6142,11 @@ static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
 if (const auto *const VD = dyn_cast(D)) {
   Target = VD->getTypeSourceInfo()->getTypeLoc();
 }
+  } else if (const auto *ME = dyn_cast(Fn)) {
+const auto *MD = ME->getMemberDecl();
+if (const auto *FD = dyn_cast(MD)) {
+  Target = FD->getTypeSourceInfo()->getTypeLoc();
+}
   }
 
   if (!Target)

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


[clang] [clang-tools-extra] clangd: Show argument names for function pointer struct fields (PR #69011)

2024-03-04 Thread via cfe-commits


@@ -6143,6 +6144,13 @@ static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
 }
   }
 
+  if (const auto *ME = dyn_cast(Fn)) {

Qwinci wrote:

Done.

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


[clang] [Clang][Sema] Fix crash when using name of UnresolvedUsingValueDecl with template arguments (PR #83842)

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

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

The following snippet causes a crash ([godbolt 
link](https://godbolt.org/z/E17sYfYrY)):
```cpp
template
struct A : T {
  using T::f;
  void f();

  void g() {
f(); // crash here
  }
};
```
This happens because we cast the result of `getAsTemplateNameDecl` as a 
`TemplateDecl` in `Sema::ClassifyName`, which we cannot do for an 
`UnresolvedUsingValueDecl`. I believe the correct thing to do here is to create 
an `OverloadedTemplateName`.

>From aeeb445a9e52a8011a008a5ee3438709f835034c Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Mon, 4 Mar 2024 08:10:35 -0500
Subject: [PATCH] [Clang][Sema] Fix crash when using name of
 UnresolvedUsingValueDecl with template arguments

---
 clang/lib/AST/ASTContext.cpp  |  3 ++-
 clang/lib/Sema/SemaDecl.cpp   |  3 ++-
 .../unqual-unresolved-using-value.cpp | 24 +++
 3 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/unqual-unresolved-using-value.cpp

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5a8fae76a43a4d..28dd69b8e45758 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -9200,7 +9200,8 @@ TemplateName
 ASTContext::getOverloadedTemplateName(UnresolvedSetIterator Begin,
   UnresolvedSetIterator End) const {
   unsigned size = End - Begin;
-  assert(size > 1 && "set is not overloaded!");
+  assert((size == 1 && isa(*Begin)) ||
+ size > 1 && "set is not overloaded!");
 
   void *memory = Allocate(sizeof(OverloadedTemplateStorage) +
   size * sizeof(FunctionTemplateDecl*));
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9fdd8eb236d1ee..c62e4ce7d0f9c4 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1115,7 +1115,8 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, 
CXXScopeSpec &SS,
 bool IsFunctionTemplate;
 bool IsVarTemplate;
 TemplateName Template;
-if (Result.end() - Result.begin() > 1) {
+
+if ((Result.end() - Result.begin() > 1) || Result.isUnresolvableResult()) {
   IsFunctionTemplate = true;
   Template = Context.getOverloadedTemplateName(Result.begin(),
Result.end());
diff --git a/clang/test/SemaTemplate/unqual-unresolved-using-value.cpp 
b/clang/test/SemaTemplate/unqual-unresolved-using-value.cpp
new file mode 100644
index 00..7c45342adce783
--- /dev/null
+++ b/clang/test/SemaTemplate/unqual-unresolved-using-value.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+template
+struct A : T {
+  using T::f;
+  using T::g;
+
+  void f();
+  void g();
+
+  void h() {
+f();
+g(); // expected-error{{no member named 'g' in 'A'}}
+  }
+};
+
+struct B {
+  template
+  void f();
+
+  void g();
+};
+
+template struct A; // expected-note{{in instantiation of member function 
'A::h' requested here}}

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


[clang] [Clang][Sema] Fix crash when using name of UnresolvedUsingValueDecl with template arguments (PR #83842)

2024-03-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krystian Stasiowski (sdkrystian)


Changes

The following snippet causes a crash ([godbolt 
link](https://godbolt.org/z/E17sYfYrY)):
```cpp
template
struct A : T {
  using T::f;
  void f();

  void g() {
f(); // crash here
  }
};
```
This happens because we cast the result of `getAsTemplateNameDecl` as a 
`TemplateDecl` in `Sema::ClassifyName`, which we cannot do for an 
`UnresolvedUsingValueDecl`. I believe the correct thing to do here is to create 
an `OverloadedTemplateName`.

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


3 Files Affected:

- (modified) clang/lib/AST/ASTContext.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+2-1) 
- (added) clang/test/SemaTemplate/unqual-unresolved-using-value.cpp (+24) 


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5a8fae76a43a4d..28dd69b8e45758 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -9200,7 +9200,8 @@ TemplateName
 ASTContext::getOverloadedTemplateName(UnresolvedSetIterator Begin,
   UnresolvedSetIterator End) const {
   unsigned size = End - Begin;
-  assert(size > 1 && "set is not overloaded!");
+  assert((size == 1 && isa(*Begin)) ||
+ size > 1 && "set is not overloaded!");
 
   void *memory = Allocate(sizeof(OverloadedTemplateStorage) +
   size * sizeof(FunctionTemplateDecl*));
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9fdd8eb236d1ee..c62e4ce7d0f9c4 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1115,7 +1115,8 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, 
CXXScopeSpec &SS,
 bool IsFunctionTemplate;
 bool IsVarTemplate;
 TemplateName Template;
-if (Result.end() - Result.begin() > 1) {
+
+if ((Result.end() - Result.begin() > 1) || Result.isUnresolvableResult()) {
   IsFunctionTemplate = true;
   Template = Context.getOverloadedTemplateName(Result.begin(),
Result.end());
diff --git a/clang/test/SemaTemplate/unqual-unresolved-using-value.cpp 
b/clang/test/SemaTemplate/unqual-unresolved-using-value.cpp
new file mode 100644
index 00..7c45342adce783
--- /dev/null
+++ b/clang/test/SemaTemplate/unqual-unresolved-using-value.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+template
+struct A : T {
+  using T::f;
+  using T::g;
+
+  void f();
+  void g();
+
+  void h() {
+f();
+g(); // expected-error{{no member named 'g' in 'A'}}
+  }
+};
+
+struct B {
+  template
+  void f();
+
+  void g();
+};
+
+template struct A; // expected-note{{in instantiation of member function 
'A::h' requested here}}

``




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


[clang] [Clang][Sema] Fix crash when using name of UnresolvedUsingValueDecl with template arguments (PR #83842)

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

https://github.com/sdkrystian edited 
https://github.com/llvm/llvm-project/pull/83842
___
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-04 Thread Dinar Temirbulatov via cfe-commits


@@ -7513,6 +7516,36 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
+auto *CallerFD = dyn_cast(CurContext);
+bool IsCalleeStreaming =
+(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask);
+bool IsCalleeStreamingCompatible =
+(ExtInfo.AArch64SMEAttributes &
+ FunctionType::SME_PStateSMCompatibleMask);
+bool IsBuiltin = (FD && FD->getBuiltinID());
+AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType();
+
+// If the caller is a function and the callee has a different
+// non-compitable streaming attribute. If it passed any VL-based arguments
+// or return VL-based value, then warn that the streaming and non-streaming
+// vector lengths may be different.
+if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) {

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-04 Thread Dinar Temirbulatov via cfe-commits


@@ -7513,6 +7516,36 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
+auto *CallerFD = dyn_cast(CurContext);
+bool IsCalleeStreaming =
+(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask);
+bool IsCalleeStreamingCompatible =
+(ExtInfo.AArch64SMEAttributes &
+ FunctionType::SME_PStateSMCompatibleMask);
+bool IsBuiltin = (FD && FD->getBuiltinID());
+AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType();
+
+// If the caller is a function and the callee has a different
+// non-compitable streaming attribute. If it passed any VL-based arguments
+// or return VL-based value, then warn that the streaming and non-streaming
+// vector lengths may be different.
+if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) {
+  ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD);
+  if (CallerFnType != ArmStreaming &&
+  CallerFnType != ArmStreamingCompatible) {
+if (IsCalleeStreaming && AnyScalableArgsOrRet)
+  Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming);
+  } else if (CallerFnType == ArmStreaming && !IsCalleeStreaming &&
+ !IsCalleeStreamingCompatible) {
+if (AnyScalableArgsOrRet)
+  Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming);
+  } else if (CallerFnType == ArmStreamingCompatible) {
+if ((IsCalleeStreaming || !IsCalleeStreamingCompatible) &&
+AnyScalableArgsOrRet)
+  Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_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] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)

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


@@ -12230,12 +12230,22 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   }
 
   // Check if the function definition uses any AArch64 SME features without
-  // having the '+sme' feature enabled.
+  // having the '+sme' feature enabled and warn user if sme locally streaming
+  // function returns or uses arguments with VL-based types.
   if (DeclIsDefn) {
 const auto *Attr = NewFD->getAttr();
 bool UsesSM = NewFD->hasAttr();
 bool UsesZA = Attr && Attr->isNewZA();
 bool UsesZT0 = Attr && Attr->isNewZT0();
+
+if (UsesSM) {

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] [Sema] Do not attempt to dump the layout of dependent types when `-fdump-record-layouts-complete` is passed (PR #83688)

2024-03-04 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> Apparently, buildbot is mad at me 
> (https://lab.llvm.org/buildbot/#/builders/165/builds/49741)?
>
> I’m not entirely sure how a fix that affects only 
> -fdump-record-layouts-complete could have caused this. Is this a spurious 
> failure or due to something unrelated, or is it worth investigating this?

That builder seems happy testing main after your commit: 
https://lab.llvm.org/buildbot/#/builders/165, so I'd write it off as spurious.

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


[clang] [Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (PR #81102)

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


@@ -8480,6 +8480,54 @@ class LValueExprEvaluator
 };
 } // end anonymous namespace
 
+/// Get an lvalue to a field of a lambda's closure type.
+static bool GetLambdaCaptureAsLValue(EvalInfo &Info, const Expr *E,
+ LValue &Result, const CXXMethodDecl *MD,
+ const FieldDecl *FD,
+ bool LValueToRValueConversion) {
+  // Static lambda function call operators can't have captures. We already
+  // diagnosed this, so bail out here.
+  if (MD->isStatic()) {
+assert(Info.CurrentCall->This == nullptr &&
+   "This should not be set for a static call operator");
+return false;
+  }
+
+  // Start with 'Result' referring to the complete closure object...
+  if (MD->isExplicitObjectMemberFunction()) {
+// Self may be passed by reference or by value.
+auto *Self = MD->getParamDecl(0);
+if (Self->getType()->isReferenceType()) {
+  APValue *RefValue = Info.getParamSlot(Info.CurrentCall->Arguments, Self);
+  Result.setFrom(Info.Ctx, *RefValue);
+} else {
+  auto *VD = Info.CurrentCall->Arguments.getOrigParam(Self);
+  auto *Frame =
+  Info.getCallFrameAndDepth(Info.CurrentCall->Arguments.CallIndex)
+  .first;
+  auto Version = Info.CurrentCall->Arguments.Version;
+  Result.set({VD, Frame->Index, Version});

AaronBallman wrote:

I don't know of a helper to do this (I couldn't spot one when I went looking), 
so it's good that you factored this out.

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


[clang] Issue #63106: [сlang] Representation of ellipsis in AST (PR #80976)

2024-03-04 Thread Shahid Iqbal via cfe-commits

shahidiqbal13 wrote:

Hi @AaronBallman 
Can you pls explain me your previous response _"It would be better for us to 
associate the data with catch statements specifically because there's a lot 
fewer of those than there are variable declarations in general."_

I mean storing the ellipsis's location in catch stmt is not going to work, we 
need to add certain flags/function in VarDecl. Can you please review which I 
have raised currently one more time?

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


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

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

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

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/6] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == OMPD_pa

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

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


@@ -435,6 +450,213 @@ static void GenerateIsAllowedClause(const 
DirectiveLanguage &DirLang,
   OS << "}\n"; // End of function isAllowedClauseForDirective
 }
 
+// Generate the getLeafConstructs function implementation.
+static void GenerateGetLeafConstructs(const DirectiveLanguage &DirLang,
+  raw_ostream &OS) {
+  auto getQualifiedName = [&](StringRef Formatted) -> std::string {
+return (llvm::Twine("llvm::") + DirLang.getCppNamespace() +
+"::Directive::" + DirLang.getDirectivePrefix() + Formatted)
+.str();
+  };
+
+  // For each list of leafs, generate a static local object, then
+  // return a reference to that object for a given directive, e.g.
+  //
+  //   static ListTy leafConstructs_A_B = { A, B };

kparzysz wrote:

Done.

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


[clang] [Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (PR #81102)

2024-03-04 Thread via cfe-commits


@@ -8480,6 +8480,54 @@ class LValueExprEvaluator
 };
 } // end anonymous namespace
 
+/// Get an lvalue to a field of a lambda's closure type.
+static bool GetLambdaCaptureAsLValue(EvalInfo &Info, const Expr *E,
+ LValue &Result, const CXXMethodDecl *MD,
+ const FieldDecl *FD,
+ bool LValueToRValueConversion) {
+  // Static lambda function call operators can't have captures. We already
+  // diagnosed this, so bail out here.
+  if (MD->isStatic()) {
+assert(Info.CurrentCall->This == nullptr &&
+   "This should not be set for a static call operator");
+return false;
+  }
+
+  // Start with 'Result' referring to the complete closure object...
+  if (MD->isExplicitObjectMemberFunction()) {
+// Self may be passed by reference or by value.
+auto *Self = MD->getParamDecl(0);
+if (Self->getType()->isReferenceType()) {
+  APValue *RefValue = Info.getParamSlot(Info.CurrentCall->Arguments, Self);
+  Result.setFrom(Info.Ctx, *RefValue);
+} else {
+  auto *VD = Info.CurrentCall->Arguments.getOrigParam(Self);
+  auto *Frame =
+  Info.getCallFrameAndDepth(Info.CurrentCall->Arguments.CallIndex)
+  .first;
+  auto Version = Info.CurrentCall->Arguments.Version;
+  Result.set({VD, Frame->Index, Version});

Sirraide wrote:

I could make this a separate helper function, but it’s only used here from what 
I can tell (the code in `LValueExprEvaluator::VisitVarDecl` where I apparently 
got this from is quite a bit more complicated and does more iirc), so I 
personally don’t think it’s really necessary.

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


[clang] [Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (PR #81102)

2024-03-04 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81102

>From d489acbd3cfb656d203e1f05b74c238351c5428a Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Thu, 8 Feb 2024 08:33:03 +0100
Subject: [PATCH 1/5] [Clang] Properly get captured 'this' pointer in lambdas
 with an explicit object parameter in constant evaluator

---
 clang/lib/AST/ExprConstant.cpp| 130 ++
 .../constexpr-explicit-object-lambda.cpp  |  34 +
 2 files changed, 109 insertions(+), 55 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-explicit-object-lambda.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..8dc6348bc7eedb 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8480,6 +8480,54 @@ class LValueExprEvaluator
 };
 } // end anonymous namespace
 
+/// Get an lvalue to a field of a lambda's closure type.
+static bool GetLambdaCaptureAsLValue(EvalInfo &Info, const Expr *E,
+ LValue &Result, const CXXMethodDecl *MD,
+ const FieldDecl *FD,
+ bool LValueToRValueConversion) {
+  // Static lambda function call operators can't have captures. We already
+  // diagnosed this, so bail out here.
+  if (MD->isStatic()) {
+assert(Info.CurrentCall->This == nullptr &&
+   "This should not be set for a static call operator");
+return false;
+  }
+
+  // Start with 'Result' referring to the complete closure object...
+  if (MD->isExplicitObjectMemberFunction()) {
+// Self may be passed by reference or by value.
+auto *Self = MD->getParamDecl(0);
+if (Self->getType()->isReferenceType()) {
+  APValue *RefValue = Info.getParamSlot(Info.CurrentCall->Arguments, Self);
+  Result.setFrom(Info.Ctx, *RefValue);
+} else {
+  auto *VD = Info.CurrentCall->Arguments.getOrigParam(Self);
+  auto *Frame =
+  Info.getCallFrameAndDepth(Info.CurrentCall->Arguments.CallIndex)
+  .first;
+  auto Version = Info.CurrentCall->Arguments.Version;
+  Result.set({VD, Frame->Index, Version});
+}
+  } else
+Result = *Info.CurrentCall->This;
+
+  // ... then update it to refer to the field of the closure object
+  // that represents the capture.
+  if (!HandleLValueMember(Info, E, Result, FD))
+return false;
+
+  // And if the field is of reference type (or if we captured '*this' by
+  // reference if this is a lambda), update 'Result' to refer to what
+  // the field refers to.
+  if (LValueToRValueConversion) {
+APValue RVal;
+if (!handleLValueToRValueConversion(Info, E, FD->getType(), Result, RVal))
+  return false;
+Result.setFrom(Info.Ctx, RVal);
+  }
+  return true;
+}
+
 /// Evaluate an expression as an lvalue. This can be legitimately called on
 /// expressions which are not glvalues, in three cases:
 ///  * function designators in C, and
@@ -8524,37 +8572,8 @@ bool LValueExprEvaluator::VisitVarDecl(const Expr *E, 
const VarDecl *VD) {
 
 if (auto *FD = Info.CurrentCall->LambdaCaptureFields.lookup(VD)) {
   const auto *MD = cast(Info.CurrentCall->Callee);
-
-  // Static lambda function call operators can't have captures. We already
-  // diagnosed this, so bail out here.
-  if (MD->isStatic()) {
-assert(Info.CurrentCall->This == nullptr &&
-   "This should not be set for a static call operator");
-return false;
-  }
-
-  // Start with 'Result' referring to the complete closure object...
-  if (MD->isExplicitObjectMemberFunction()) {
-APValue *RefValue =
-Info.getParamSlot(Info.CurrentCall->Arguments, 
MD->getParamDecl(0));
-Result.setFrom(Info.Ctx, *RefValue);
-  } else
-Result = *Info.CurrentCall->This;
-
-  // ... then update it to refer to the field of the closure object
-  // that represents the capture.
-  if (!HandleLValueMember(Info, E, Result, FD))
-return false;
-  // And if the field is of reference type, update 'Result' to refer to 
what
-  // the field refers to.
-  if (FD->getType()->isReferenceType()) {
-APValue RVal;
-if (!handleLValueToRValueConversion(Info, E, FD->getType(), Result,
-RVal))
-  return false;
-Result.setFrom(Info.Ctx, RVal);
-  }
-  return true;
+  return GetLambdaCaptureAsLValue(Info, E, Result, MD, FD,
+  FD->getType()->isReferenceType());
 }
   }
 
@@ -9032,45 +9051,46 @@ class PointerExprEvaluator
 return Error(E);
   }
   bool VisitCXXThisExpr(const CXXThisExpr *E) {
-// Can't look at 'this' when checking a potential constant expression.
-if (Info.checkingPotentialConstantExpression())
-  return false;
-if (!Info.CurrentCall->This) {
+auto DiagnoseInvalidUseOfThis = [&] {
   if (Info.get

[clang] [Clang][Sema] Allow access to a public template alias declaration that refers to friend's private nested type (PR #83847)

2024-03-04 Thread Qizhi Hu via cfe-commits

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

None

>From 6eed79fbcff40b308815cec4d1223e024040674d Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Mon, 4 Mar 2024 21:51:07 +0800
Subject: [PATCH] [Clang][Sema] Allow access to a public template alias
 declaration that refers to friend's private nested type

---
 clang/include/clang/Sema/Lookup.h   |  5 +
 clang/lib/Sema/SemaAccess.cpp   | 19 +++
 clang/lib/Sema/SemaTemplate.cpp |  1 +
 clang/test/SemaTemplate/PR25708.cpp | 23 +++
 4 files changed, 48 insertions(+)
 create mode 100644 clang/test/SemaTemplate/PR25708.cpp

diff --git a/clang/include/clang/Sema/Lookup.h 
b/clang/include/clang/Sema/Lookup.h
index 2f2f2607a937fe..a07609bfb7c9bc 100644
--- a/clang/include/clang/Sema/Lookup.h
+++ b/clang/include/clang/Sema/Lookup.h
@@ -752,6 +752,10 @@ class LookupResult {
   IDNS &= ~Decl::IDNS_LocalExtern;
   }
 
+  void setNestedNameSpecifier(NestedNameSpecifier *Q) { Qualifier = Q; }
+
+  NestedNameSpecifier *getNestedNameSpecifier() const { return Qualifier; }
+
 private:
   void diagnoseAccess() {
 if (!isAmbiguous() && isClassLookup() &&
@@ -792,6 +796,7 @@ class LookupResult {
   CXXBasePaths *Paths = nullptr;
   CXXRecordDecl *NamingClass = nullptr;
   QualType BaseObjectType;
+  NestedNameSpecifier *Qualifier = nullptr;
 
   // Parameters.
   Sema *SemaPtr;
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index 4af3c0f30a8e8a..9077066da29d61 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -254,6 +254,9 @@ struct AccessTarget : public AccessedEntity {
   namingClass = cast(namingClass->getParent());
 return namingClass->getCanonicalDecl();
   }
+  void setNestedNameSpecifier(NestedNameSpecifier *Q) { Qualifier = Q; }
+
+  NestedNameSpecifier *getNestedNameSpecifier() const { return Qualifier; }
 
 private:
   void initialize() {
@@ -274,6 +277,7 @@ struct AccessTarget : public AccessedEntity {
   mutable bool CalculatedInstanceContext : 1;
   mutable const CXXRecordDecl *InstanceContext;
   const CXXRecordDecl *DeclaringClass;
+  NestedNameSpecifier *Qualifier = nullptr;
 };
 
 }
@@ -1481,6 +1485,20 @@ static Sema::AccessResult CheckAccess(Sema &S, 
SourceLocation Loc,
   }
 
   EffectiveContext EC(S.CurContext);
+  if (Entity.getNestedNameSpecifier())
+if (const Type *Ty = Entity.getNestedNameSpecifier()->getAsType())
+  switch (Ty->getTypeClass()) {
+  case Type::TypeClass::SubstTemplateTypeParm:
+if (auto *SubstTemplateTy = Ty->getAs())
+  if (auto *D = SubstTemplateTy->getAssociatedDecl())
+if (auto *RD = 
dyn_cast_or_null(D->getDeclContext()))
+  EC.Records.push_back(RD);
+
+break;
+  default:
+break;
+  }
+
   switch (CheckEffectiveAccess(S, EC, Loc, Entity)) {
   case AR_accessible: return Sema::AR_accessible;
   case AR_inaccessible: return Sema::AR_inaccessible;
@@ -1916,6 +1934,7 @@ void Sema::CheckLookupAccess(const LookupResult &R) {
   AccessTarget Entity(Context, AccessedEntity::Member,
   R.getNamingClass(), I.getPair(),
   R.getBaseObjectType());
+  Entity.setNestedNameSpecifier(R.getNestedNameSpecifier());
   Entity.setDiag(diag::err_access);
   CheckAccess(*this, R.getNameLoc(), Entity);
 }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index a7910bda874c8d..d1555cfeb03e15 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -11275,6 +11275,7 @@ Sema::CheckTypenameType(ElaboratedTypeKeyword Keyword,
 
   DeclarationName Name(&II);
   LookupResult Result(*this, Name, IILoc, LookupOrdinaryName);
+  Result.setNestedNameSpecifier(QualifierLoc.getNestedNameSpecifier());
   if (Ctx)
 LookupQualifiedName(Result, Ctx, SS);
   else
diff --git a/clang/test/SemaTemplate/PR25708.cpp 
b/clang/test/SemaTemplate/PR25708.cpp
new file mode 100644
index 00..e9e96ebd015e04
--- /dev/null
+++ b/clang/test/SemaTemplate/PR25708.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+// RUN: %clang_cc1 -std=c++14 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20 %s
+// expected-no-diagnostics
+
+struct FooAccessor
+{
+template 
+using Foo = typename T::Foo;
+};
+
+class Type
+{
+friend struct FooAccessor;
+
+using Foo = int;
+};
+
+int main()
+{
+FooAccessor::Foo t;
+}
\ No newline at end of file

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


[clang] [Clang][Sema] Allow access to a public template alias declaration that refers to friend's private nested type (PR #83847)

2024-03-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qizhi Hu (jcsxky)


Changes



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


4 Files Affected:

- (modified) clang/include/clang/Sema/Lookup.h (+5) 
- (modified) clang/lib/Sema/SemaAccess.cpp (+19) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+1) 
- (added) clang/test/SemaTemplate/PR25708.cpp (+23) 


``diff
diff --git a/clang/include/clang/Sema/Lookup.h 
b/clang/include/clang/Sema/Lookup.h
index 2f2f2607a937fe..a07609bfb7c9bc 100644
--- a/clang/include/clang/Sema/Lookup.h
+++ b/clang/include/clang/Sema/Lookup.h
@@ -752,6 +752,10 @@ class LookupResult {
   IDNS &= ~Decl::IDNS_LocalExtern;
   }
 
+  void setNestedNameSpecifier(NestedNameSpecifier *Q) { Qualifier = Q; }
+
+  NestedNameSpecifier *getNestedNameSpecifier() const { return Qualifier; }
+
 private:
   void diagnoseAccess() {
 if (!isAmbiguous() && isClassLookup() &&
@@ -792,6 +796,7 @@ class LookupResult {
   CXXBasePaths *Paths = nullptr;
   CXXRecordDecl *NamingClass = nullptr;
   QualType BaseObjectType;
+  NestedNameSpecifier *Qualifier = nullptr;
 
   // Parameters.
   Sema *SemaPtr;
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index 4af3c0f30a8e8a..9077066da29d61 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -254,6 +254,9 @@ struct AccessTarget : public AccessedEntity {
   namingClass = cast(namingClass->getParent());
 return namingClass->getCanonicalDecl();
   }
+  void setNestedNameSpecifier(NestedNameSpecifier *Q) { Qualifier = Q; }
+
+  NestedNameSpecifier *getNestedNameSpecifier() const { return Qualifier; }
 
 private:
   void initialize() {
@@ -274,6 +277,7 @@ struct AccessTarget : public AccessedEntity {
   mutable bool CalculatedInstanceContext : 1;
   mutable const CXXRecordDecl *InstanceContext;
   const CXXRecordDecl *DeclaringClass;
+  NestedNameSpecifier *Qualifier = nullptr;
 };
 
 }
@@ -1481,6 +1485,20 @@ static Sema::AccessResult CheckAccess(Sema &S, 
SourceLocation Loc,
   }
 
   EffectiveContext EC(S.CurContext);
+  if (Entity.getNestedNameSpecifier())
+if (const Type *Ty = Entity.getNestedNameSpecifier()->getAsType())
+  switch (Ty->getTypeClass()) {
+  case Type::TypeClass::SubstTemplateTypeParm:
+if (auto *SubstTemplateTy = Ty->getAs())
+  if (auto *D = SubstTemplateTy->getAssociatedDecl())
+if (auto *RD = 
dyn_cast_or_null(D->getDeclContext()))
+  EC.Records.push_back(RD);
+
+break;
+  default:
+break;
+  }
+
   switch (CheckEffectiveAccess(S, EC, Loc, Entity)) {
   case AR_accessible: return Sema::AR_accessible;
   case AR_inaccessible: return Sema::AR_inaccessible;
@@ -1916,6 +1934,7 @@ void Sema::CheckLookupAccess(const LookupResult &R) {
   AccessTarget Entity(Context, AccessedEntity::Member,
   R.getNamingClass(), I.getPair(),
   R.getBaseObjectType());
+  Entity.setNestedNameSpecifier(R.getNestedNameSpecifier());
   Entity.setDiag(diag::err_access);
   CheckAccess(*this, R.getNameLoc(), Entity);
 }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index a7910bda874c8d..d1555cfeb03e15 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -11275,6 +11275,7 @@ Sema::CheckTypenameType(ElaboratedTypeKeyword Keyword,
 
   DeclarationName Name(&II);
   LookupResult Result(*this, Name, IILoc, LookupOrdinaryName);
+  Result.setNestedNameSpecifier(QualifierLoc.getNestedNameSpecifier());
   if (Ctx)
 LookupQualifiedName(Result, Ctx, SS);
   else
diff --git a/clang/test/SemaTemplate/PR25708.cpp 
b/clang/test/SemaTemplate/PR25708.cpp
new file mode 100644
index 00..e9e96ebd015e04
--- /dev/null
+++ b/clang/test/SemaTemplate/PR25708.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+// RUN: %clang_cc1 -std=c++14 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20 %s
+// expected-no-diagnostics
+
+struct FooAccessor
+{
+template 
+using Foo = typename T::Foo;
+};
+
+class Type
+{
+friend struct FooAccessor;
+
+using Foo = int;
+};
+
+int main()
+{
+FooAccessor::Foo t;
+}
\ No newline at end of file

``




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


[clang] [Clang][Sema] Properly get captured 'this' pointer in lambdas with an explicit object parameter in constant evaluator (PR #81102)

2024-03-04 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81102

>From d489acbd3cfb656d203e1f05b74c238351c5428a Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Thu, 8 Feb 2024 08:33:03 +0100
Subject: [PATCH 1/5] [Clang] Properly get captured 'this' pointer in lambdas
 with an explicit object parameter in constant evaluator

---
 clang/lib/AST/ExprConstant.cpp| 130 ++
 .../constexpr-explicit-object-lambda.cpp  |  34 +
 2 files changed, 109 insertions(+), 55 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-explicit-object-lambda.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..8dc6348bc7eedb 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8480,6 +8480,54 @@ class LValueExprEvaluator
 };
 } // end anonymous namespace
 
+/// Get an lvalue to a field of a lambda's closure type.
+static bool GetLambdaCaptureAsLValue(EvalInfo &Info, const Expr *E,
+ LValue &Result, const CXXMethodDecl *MD,
+ const FieldDecl *FD,
+ bool LValueToRValueConversion) {
+  // Static lambda function call operators can't have captures. We already
+  // diagnosed this, so bail out here.
+  if (MD->isStatic()) {
+assert(Info.CurrentCall->This == nullptr &&
+   "This should not be set for a static call operator");
+return false;
+  }
+
+  // Start with 'Result' referring to the complete closure object...
+  if (MD->isExplicitObjectMemberFunction()) {
+// Self may be passed by reference or by value.
+auto *Self = MD->getParamDecl(0);
+if (Self->getType()->isReferenceType()) {
+  APValue *RefValue = Info.getParamSlot(Info.CurrentCall->Arguments, Self);
+  Result.setFrom(Info.Ctx, *RefValue);
+} else {
+  auto *VD = Info.CurrentCall->Arguments.getOrigParam(Self);
+  auto *Frame =
+  Info.getCallFrameAndDepth(Info.CurrentCall->Arguments.CallIndex)
+  .first;
+  auto Version = Info.CurrentCall->Arguments.Version;
+  Result.set({VD, Frame->Index, Version});
+}
+  } else
+Result = *Info.CurrentCall->This;
+
+  // ... then update it to refer to the field of the closure object
+  // that represents the capture.
+  if (!HandleLValueMember(Info, E, Result, FD))
+return false;
+
+  // And if the field is of reference type (or if we captured '*this' by
+  // reference if this is a lambda), update 'Result' to refer to what
+  // the field refers to.
+  if (LValueToRValueConversion) {
+APValue RVal;
+if (!handleLValueToRValueConversion(Info, E, FD->getType(), Result, RVal))
+  return false;
+Result.setFrom(Info.Ctx, RVal);
+  }
+  return true;
+}
+
 /// Evaluate an expression as an lvalue. This can be legitimately called on
 /// expressions which are not glvalues, in three cases:
 ///  * function designators in C, and
@@ -8524,37 +8572,8 @@ bool LValueExprEvaluator::VisitVarDecl(const Expr *E, 
const VarDecl *VD) {
 
 if (auto *FD = Info.CurrentCall->LambdaCaptureFields.lookup(VD)) {
   const auto *MD = cast(Info.CurrentCall->Callee);
-
-  // Static lambda function call operators can't have captures. We already
-  // diagnosed this, so bail out here.
-  if (MD->isStatic()) {
-assert(Info.CurrentCall->This == nullptr &&
-   "This should not be set for a static call operator");
-return false;
-  }
-
-  // Start with 'Result' referring to the complete closure object...
-  if (MD->isExplicitObjectMemberFunction()) {
-APValue *RefValue =
-Info.getParamSlot(Info.CurrentCall->Arguments, 
MD->getParamDecl(0));
-Result.setFrom(Info.Ctx, *RefValue);
-  } else
-Result = *Info.CurrentCall->This;
-
-  // ... then update it to refer to the field of the closure object
-  // that represents the capture.
-  if (!HandleLValueMember(Info, E, Result, FD))
-return false;
-  // And if the field is of reference type, update 'Result' to refer to 
what
-  // the field refers to.
-  if (FD->getType()->isReferenceType()) {
-APValue RVal;
-if (!handleLValueToRValueConversion(Info, E, FD->getType(), Result,
-RVal))
-  return false;
-Result.setFrom(Info.Ctx, RVal);
-  }
-  return true;
+  return GetLambdaCaptureAsLValue(Info, E, Result, MD, FD,
+  FD->getType()->isReferenceType());
 }
   }
 
@@ -9032,45 +9051,46 @@ class PointerExprEvaluator
 return Error(E);
   }
   bool VisitCXXThisExpr(const CXXThisExpr *E) {
-// Can't look at 'this' when checking a potential constant expression.
-if (Info.checkingPotentialConstantExpression())
-  return false;
-if (!Info.CurrentCall->This) {
+auto DiagnoseInvalidUseOfThis = [&] {
   if (Info.get

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

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

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

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

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

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

  1   2   3   4   5   6   >