[clang] [Clang][Sema] improve sema check of clang::musttail attribute (PR #77727)

2024-01-17 Thread Qizhi Hu via cfe-commits

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

>From 17e2f6d329a457cef4580b8f8415d10150b648ec Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Thu, 11 Jan 2024 13:02:21 +0800
Subject: [PATCH] [Clang][SemaCXX] improve sema check of clang::musttail
 attribute

---
 clang/docs/ReleaseNotes.rst  | 3 +++
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaStmt.cpp  | 6 ++
 clang/test/SemaCXX/PR76631.cpp   | 9 +
 4 files changed, 20 insertions(+)
 create mode 100644 clang/test/SemaCXX/PR76631.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 73730252002451..83fe442dbc15fb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -768,6 +768,9 @@ Bug Fixes in This Version
 - Fix crashes when using the binding decl from an invalid structured binding.
   Fixes (`#67495 `_) and
   (`#72198 `_)
+- Fix assertion failure when call noreturn-attribute function with musttail
+  attribute.
+  Fixes (`#76631 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 991c72cad33cad..03b0122d1c08f7 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3113,6 +3113,8 @@ def err_musttail_scope : Error<
   "cannot perform a tail call from this return statement">;
 def err_musttail_no_variadic : Error<
   "%0 attribute may not be used with variadic functions">;
+def err_musttail_no_return : Error<
+  "%0 attribute may not be used with no-return-attribute functions">;
 
 def err_nsobject_attribute : Error<
   "'NSObject' attribute is for pointer types only">;
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 21efe25ed84a3d..9e7c8c7e4e8c12 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -786,6 +786,12 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr 
&MTA) {
 return false;
   }
 
+  const auto *CalleeDecl = CE->getCalleeDecl();
+  if (CalleeDecl && CalleeDecl->hasAttr()) {
+Diag(St->getBeginLoc(), diag::err_musttail_no_return) << &MTA;
+return false;
+  }
+
   // Caller and callee must match in whether they have a "this" parameter.
   if (CallerType.This.isNull() != CalleeType.This.isNull()) {
 if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl())) {
diff --git a/clang/test/SemaCXX/PR76631.cpp b/clang/test/SemaCXX/PR76631.cpp
new file mode 100644
index 00..947fa3fc2635e6
--- /dev/null
+++ b/clang/test/SemaCXX/PR76631.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -std=c++11 -fsyntax-only %s
+
+[[noreturn]] void throw_int() {
+  throw int(); // expected-error {{cannot use 'throw' with exceptions 
disabled}}
+}
+
+void throw_int_wrapper() {
+  [[clang::musttail]] return throw_int(); // expected-error {{'musttail' 
attribute may not be used with no-return-attribute functions}}
+}

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


[llvm] [clang] [AMDGPU][NFC] Rename feature FP8Insts to FP8ConversionInsts (PR #78439)

2024-01-17 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 2db9244b6f66a4fd4c937de7b33a5b6dda4a06a8 
5bd1644ec60996fed50c843e13e68f7c2c6dda81 -- 
llvm/lib/Target/AMDGPU/GCNSubtarget.h llvm/lib/TargetParser/TargetParser.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/AMDGPU/GCNSubtarget.h 
b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
index 3a18bdfb93..157d6f409a 100644
--- a/llvm/lib/Target/AMDGPU/GCNSubtarget.h
+++ b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
@@ -781,9 +781,7 @@ public:
 return HasFP8Insts;
   }
 
-  bool hasFP8ConversionInsts() const {
-return HasFP8ConversionInsts;
-  }
+  bool hasFP8ConversionInsts() const { return HasFP8ConversionInsts; }
 
   bool hasPkFmacF16Inst() const {
 return HasPkFmacF16Inst;

``




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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-17 Thread Mariya Podchishchaeva via cfe-commits

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


[llvm] [clang] [AMDGPU][NFC] Rename feature FP8Insts to FP8ConversionInsts (PR #78439)

2024-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mariusz Sikora (mariusz-sikora-at-amd)


Changes



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


7 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsAMDGPU.def (+8-8) 
- (modified) clang/test/CodeGenOpenCL/amdgpu-features.cl (+3-3) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPU.td (+10) 
- (modified) llvm/lib/Target/AMDGPU/GCNSubtarget.h (+5) 
- (modified) llvm/lib/Target/AMDGPU/VOP1Instructions.td (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/VOP3Instructions.td (+2-2) 
- (modified) llvm/lib/TargetParser/TargetParser.cpp (+1) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index e562ef04a30194e..f02b4d321328fe2 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -397,14 +397,14 @@ 
TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_32x32x32_bf8_fp8, "V16fV2iV4iV16fiIiI
 TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_32x32x32_fp8_bf8, 
"V16fV2iV4iV16fiIiIi", "nc", "fp8-insts")
 TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_32x32x32_fp8_fp8, 
"V16fV2iV4iV16fiIiIi", "nc", "fp8-insts")
 
-TARGET_BUILTIN(__builtin_amdgcn_cvt_f32_bf8, "fiIi", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_f32_fp8, "fiIi", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f32_bf8, "V2fiIb", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f32_fp8, "V2fiIb", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_bf8_f32, "iffiIb", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_fp8_f32, "iffiIb", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_bf8_f32, "ifiiIi", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", "nc", "fp8-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_f32_bf8, "fiIi", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_f32_fp8, "fiIi", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f32_bf8, "V2fiIb", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f32_fp8, "V2fiIb", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_bf8_f32, "iffiIb", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_fp8_f32, "iffiIb", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_bf8_f32, "ifiiIi", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", "nc", 
"fp8-conversion-insts")
 
 
//===--===//
 // GFX12+ only builtins.
diff --git a/clang/test/CodeGenOpenCL/amdgpu-features.cl 
b/clang/test/CodeGenOpenCL/amdgpu-features.cl
index 8959634572b44e9..df58cd7b62006da 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-features.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-features.cl
@@ -80,9 +80,9 @@
 // GFX909: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 // GFX90A: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 // GFX90C: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
-// GFX940: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+fp8-insts,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gfx940-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
-// GFX941: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+fp8-insts,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gfx940-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
-// GFX942: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+fp8-insts,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gfx940-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
+// GFX940: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+a

[llvm] [clang] [AMDGPU][NFC] Rename feature FP8Insts to FP8ConversionInsts (PR #78439)

2024-01-17 Thread Mariusz Sikora via cfe-commits

https://github.com/mariusz-sikora-at-amd created 
https://github.com/llvm/llvm-project/pull/78439

None

>From 5bd1644ec60996fed50c843e13e68f7c2c6dda81 Mon Sep 17 00:00:00 2001
From: Mariusz Sikora 
Date: Wed, 17 Jan 2024 13:19:55 +0100
Subject: [PATCH] [AMDGPU][NFC] Rename feature FP8Insts to FP8ConversionInsts

---
 clang/include/clang/Basic/BuiltinsAMDGPU.def | 16 
 clang/test/CodeGenOpenCL/amdgpu-features.cl  |  6 +++---
 llvm/lib/Target/AMDGPU/AMDGPU.td | 10 ++
 llvm/lib/Target/AMDGPU/GCNSubtarget.h|  5 +
 llvm/lib/Target/AMDGPU/VOP1Instructions.td   |  4 ++--
 llvm/lib/Target/AMDGPU/VOP3Instructions.td   |  4 ++--
 llvm/lib/TargetParser/TargetParser.cpp   |  1 +
 7 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index e562ef04a30194e..f02b4d321328fe2 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -397,14 +397,14 @@ 
TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_32x32x32_bf8_fp8, "V16fV2iV4iV16fiIiI
 TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_32x32x32_fp8_bf8, 
"V16fV2iV4iV16fiIiIi", "nc", "fp8-insts")
 TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_32x32x32_fp8_fp8, 
"V16fV2iV4iV16fiIiIi", "nc", "fp8-insts")
 
-TARGET_BUILTIN(__builtin_amdgcn_cvt_f32_bf8, "fiIi", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_f32_fp8, "fiIi", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f32_bf8, "V2fiIb", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f32_fp8, "V2fiIb", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_bf8_f32, "iffiIb", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_fp8_f32, "iffiIb", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_bf8_f32, "ifiiIi", "nc", "fp8-insts")
-TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", "nc", "fp8-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_f32_bf8, "fiIi", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_f32_fp8, "fiIi", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f32_bf8, "V2fiIb", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f32_fp8, "V2fiIb", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_bf8_f32, "iffiIb", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_fp8_f32, "iffiIb", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_bf8_f32, "ifiiIi", "nc", 
"fp8-conversion-insts")
+TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", "nc", 
"fp8-conversion-insts")
 
 
//===--===//
 // GFX12+ only builtins.
diff --git a/clang/test/CodeGenOpenCL/amdgpu-features.cl 
b/clang/test/CodeGenOpenCL/amdgpu-features.cl
index 8959634572b44e9..df58cd7b62006da 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-features.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-features.cl
@@ -80,9 +80,9 @@
 // GFX909: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 // GFX90A: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 // GFX90C: 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
-// GFX940: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+fp8-insts,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gfx940-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
-// GFX941: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+fp8-insts,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gfx940-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
-// GFX942: 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+fp8-insts,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gfx940-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
+// GFX940: 
"target-fea

[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-17 Thread Mariya Podchishchaeva via cfe-commits


@@ -1731,11 +1731,7 @@ static bool CheckConstexprDestructorSubobjects(Sema 
&SemaRef,
   SemaRef.Diag(Loc, diag::note_constexpr_dtor_subobject)
   << !FD << (FD ? FD->getDeclName() : DeclarationName()) << T;
 }
-
-if (SemaRef.getLangOpts().CPlusPlus23)
-  return true;
-
-return false;
+return !!SemaRef.getLangOpts().CPlusPlus23;

Fznamznon wrote:

It doesn't let me do so because lambda has deduced type and 
`SemaRef.getLangOpts().CPlusPlus23` is an `int` but intended return type is 
`bool`. `!!` is a dirty hack to convert to bool then return the right value.

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


[clang] [Clang] Fix dependency of SourceLocExpr. (PR #78436)

2024-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

SourceLocExpr that may produce a function name
are marked dependent so that the non-instantiated
name of a function does not get evaluated.

In GH78128, the name('s size) is used as
template argument to a `DeclRef` that is not otherwise
dependent, and therefore cached and not transformed when the function is 
instantiated, leading
to 2 different values existing at the same time for the same function.

Fixes #78128

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


5 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/include/clang/AST/Expr.h (+11) 
- (modified) clang/lib/AST/Expr.cpp (+4-1) 
- (modified) clang/lib/Sema/TreeTransform.h (+1-1) 
- (modified) clang/test/SemaCXX/source_location.cpp (+27) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 174392da17551ea..a18596097ecd4df 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -913,6 +913,10 @@ Bug Fixes to C++ Support
   (`#57410 `_) and
   (`#76604 `_)
 
+- Fix a bug where clang would produce inconsistent values when
+  std::source_location::current was used in function templates.
+  Fixes  (`#78128 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index a41f2d66b37b69d..8bce87fa7a46eb2 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -4806,6 +4806,17 @@ class SourceLocExpr final : public Expr {
 return T->getStmtClass() == SourceLocExprClass;
   }
 
+  static bool MayBeDependent(SourceLocIdentKind Kind) {
+switch (Kind) {
+case SourceLocIdentKind::Function:
+case SourceLocIdentKind::FuncSig:
+case SourceLocIdentKind::SourceLocStruct:
+  return true;
+default:
+  return false;
+}
+  }
+
 private:
   friend class ASTStmtReader;
 };
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index a90f92d07f86d26..11697a07b0e3228 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -2282,7 +2282,10 @@ SourceLocExpr::SourceLocExpr(const ASTContext &Ctx, 
SourceLocIdentKind Kind,
 : Expr(SourceLocExprClass, ResultTy, VK_PRValue, OK_Ordinary),
   BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext) {
   SourceLocExprBits.Kind = llvm::to_underlying(Kind);
-  setDependence(ExprDependence::None);
+  // In dependent contexts, function names may change.
+  setDependence(MayBeDependent(Kind) && ParentContext->isDependentContext()
+? ExprDependence::Value
+: ExprDependence::None);
 }
 
 StringRef SourceLocExpr::getBuiltinStr() const {
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 1a1bc87d2b3203c..4463904b07211bd 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -12148,7 +12148,7 @@ 
TreeTransform::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
 
 template 
 ExprResult TreeTransform::TransformSourceLocExpr(SourceLocExpr *E) {
-  bool NeedRebuildFunc = E->getIdentKind() == SourceLocIdentKind::Function &&
+  bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
  getSema().CurContext != E->getParentContext();
 
   if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
diff --git a/clang/test/SemaCXX/source_location.cpp 
b/clang/test/SemaCXX/source_location.cpp
index e92fb35b653a8f3..7414fbce7828d15 100644
--- a/clang/test/SemaCXX/source_location.cpp
+++ b/clang/test/SemaCXX/source_location.cpp
@@ -805,3 +805,30 @@ static_assert(S(0).j == S{0}.j);
 static_assert(S(0).j == S{0}.i);
 }
 #endif
+
+namespace GH78128 {
+
+template
+constexpr int f() {
+  return N;
+}
+
+template
+void foo() {
+  constexpr auto* F1 = std::source_location::current().function();
+  static_assert(__builtin_strlen(F1) == f<__builtin_strlen(F1)>());
+
+  constexpr auto* F2 = __builtin_FUNCTION();
+  static_assert(__builtin_strlen(F2) == f<__builtin_strlen(F2)>());
+
+#ifdef MS
+  constexpr auto* F3 = __builtin_FUNCSIG();
+  static_assert(__builtin_strlen(F3) == f<__builtin_strlen(F3)>());
+#endif
+}
+
+void test() {
+  foo();
+}
+
+}

``




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


[clang] [Clang] Fix dependency of SourceLocExpr. (PR #78436)

2024-01-17 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/78436

SourceLocExpr that may produce a function name
are marked dependent so that the non-instantiated
name of a function does not get evaluated.

In GH78128, the name('s size) is used as
template argument to a `DeclRef` that is not otherwise
dependent, and therefore cached and not transformed when the function is 
instantiated, leading
to 2 different values existing at the same time for the same function.

Fixes #78128

>From ec8e4ad567daa15ddef6c90380f5b6877009b354 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 17 Jan 2024 13:26:01 +0100
Subject: [PATCH] [Clang] Fix dependency of SourceLocExpr.

SourceLocExpr that may produce a function name
are marked dependent so that the non-instantiated
name of a function does not get evaluated.

In GH78128, the name('s size) is used as
template argument to a Declref that is not
dependent, and therefore not transformed and cached
when the function is instantiated, leading
to 2 different values existing at the same time
for the same function.

Fixes #78128
---
 clang/docs/ReleaseNotes.rst|  4 
 clang/include/clang/AST/Expr.h | 11 +++
 clang/lib/AST/Expr.cpp |  5 -
 clang/lib/Sema/TreeTransform.h |  2 +-
 clang/test/SemaCXX/source_location.cpp | 27 ++
 5 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 174392da17551e..a18596097ecd4d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -913,6 +913,10 @@ Bug Fixes to C++ Support
   (`#57410 `_) and
   (`#76604 `_)
 
+- Fix a bug where clang would produce inconsistent values when
+  std::source_location::current was used in function templates.
+  Fixes  (`#78128 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index a41f2d66b37b69..8bce87fa7a46eb 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -4806,6 +4806,17 @@ class SourceLocExpr final : public Expr {
 return T->getStmtClass() == SourceLocExprClass;
   }
 
+  static bool MayBeDependent(SourceLocIdentKind Kind) {
+switch (Kind) {
+case SourceLocIdentKind::Function:
+case SourceLocIdentKind::FuncSig:
+case SourceLocIdentKind::SourceLocStruct:
+  return true;
+default:
+  return false;
+}
+  }
+
 private:
   friend class ASTStmtReader;
 };
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index a90f92d07f86d2..11697a07b0e322 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -2282,7 +2282,10 @@ SourceLocExpr::SourceLocExpr(const ASTContext &Ctx, 
SourceLocIdentKind Kind,
 : Expr(SourceLocExprClass, ResultTy, VK_PRValue, OK_Ordinary),
   BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext) {
   SourceLocExprBits.Kind = llvm::to_underlying(Kind);
-  setDependence(ExprDependence::None);
+  // In dependent contexts, function names may change.
+  setDependence(MayBeDependent(Kind) && ParentContext->isDependentContext()
+? ExprDependence::Value
+: ExprDependence::None);
 }
 
 StringRef SourceLocExpr::getBuiltinStr() const {
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 1a1bc87d2b3203..4463904b07211b 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -12148,7 +12148,7 @@ 
TreeTransform::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
 
 template 
 ExprResult TreeTransform::TransformSourceLocExpr(SourceLocExpr *E) {
-  bool NeedRebuildFunc = E->getIdentKind() == SourceLocIdentKind::Function &&
+  bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
  getSema().CurContext != E->getParentContext();
 
   if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
diff --git a/clang/test/SemaCXX/source_location.cpp 
b/clang/test/SemaCXX/source_location.cpp
index e92fb35b653a8f..7414fbce7828d1 100644
--- a/clang/test/SemaCXX/source_location.cpp
+++ b/clang/test/SemaCXX/source_location.cpp
@@ -805,3 +805,30 @@ static_assert(S(0).j == S{0}.j);
 static_assert(S(0).j == S{0}.i);
 }
 #endif
+
+namespace GH78128 {
+
+template
+constexpr int f() {
+  return N;
+}
+
+template
+void foo() {
+  constexpr auto* F1 = std::source_location::current().function();
+  static_assert(__builtin_strlen(F1) == f<__builtin_strlen(F1)>());
+
+  constexpr auto* F2 = __builtin_FUNCTION();
+  static_assert(__builtin_strlen(F2) == f<__builtin_strlen(F2)>());
+
+#ifdef MS
+  constexpr auto* F3 = __builtin_FUNCSIG();
+  static_assert(__builtin_strlen(F3) == f<__builtin_s

[clang] [llvm] LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-analysis

Author: Paschalis Mpeis (paschalis-mpeis)


Changes

Teach LAA to consider safe specific math lib calls which are known to
 have set the memory write-only attribute. Those attributes are set to
 calls by `inferNonMandatoryLibFuncAttrs`, in BuildLibCalls.cpp, and the
 current ones are `modf`/`modff` and `frexp`/`frexpf`.

 This happens only when the calls are found through TLI to have
 vectorized counterparts.

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


2 Files Affected:

- (added) clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c (+54) 
- (modified) llvm/lib/Analysis/LoopAccessAnalysis.cpp (+19) 


``diff
diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
new file mode 100644
index 000..957b3f5cb235d31
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -0,0 +1,54 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --filter "call.*(frexp|modf)" --version 4
+// RUN: %clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -mllvm 
-vector-library=ArmPL -mllvm -force-vector-interleave=1 -mllvm 
-prefer-predicate-over-epilogue=predicate-dont-vectorize -emit-llvm -S -o - %s 
| FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+/*
+Testing vectorization of math functions that have the attribute write-only to
+memory set. Given they have vectorized counterparts, they should be able to
+vectorize.
+*/
+
+// The following define is required to access some math functions.
+#define _GNU_SOURCE
+#include 
+
+// frexp/frexpf have no TLI mappings yet.
+
+// CHECK-LABEL: define dso_local void @frexp_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK:[[CALL:%.*]] = tail call double @frexp(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR5:[0-9]+]]
+//
+void frexp_f64(double *in, double *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexp(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @frexp_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @frexpf(float noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR5]]
+//
+void frexp_f32(float *in, float *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexpf(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @modf_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[TMP11:%.*]] = tail call  
@armpl_svmodf_f64_x( [[WIDE_MASKED_LOAD:%.*]], ptr 
[[TMP10:%.*]],  [[ACTIVE_LANE_MASK:%.*]])
+// CHECK:[[CALL:%.*]] = tail call double @modf(double noundef 
[[TMP14:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR6:[0-9]+]]
+//
+void modf_f64(double *in, double *out1, double *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modf(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @modf_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[TMP11:%.*]] = tail call  
@armpl_svmodf_f32_x( [[WIDE_MASKED_LOAD:%.*]], ptr 
[[TMP10:%.*]],  [[ACTIVE_LANE_MASK:%.*]])
+// CHECK:[[CALL:%.*]] = tail call float @modff(float noundef 
[[TMP14:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR7:[0-9]+]]
+//
+void modf_f32(float *in, float *out1, float *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modff(in[i], out2+i);
+}
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp 
b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index aed60cc5a3f5ef0..0c8b4e51fcf5c16 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -2274,6 +2274,20 @@ bool LoopAccessInfo::canAnalyzeLoop() {
   return true;
 }
 
+/// Returns whether \p I is a known math library call that has memory 
write-only
+/// attribute set.
+static bool isMathLibCallMemWriteOnly(const TargetLibraryInfo *TLI,
+  const Instruction &I) {
+  auto *Call = dyn_cast(&I);
+  if (!Call)
+return false;
+
+  LibFunc Func;
+  TLI->getLibFunc(*Call, Func);
+  return Func == LibFunc::LibFunc_modf || Func == LibFunc::LibFunc_modff ||
+ Func == LibFunc::LibFunc_frexp || Func == LibFunc::LibFunc_frexpf;
+}
+
 void LoopAccessInfo::analyzeLoop(

[clang] [llvm] LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-01-17 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis created 
https://github.com/llvm/llvm-project/pull/78432

Teach LAA to consider safe specific math lib calls which are known to
 have set the memory write-only attribute. Those attributes are set to
 calls by `inferNonMandatoryLibFuncAttrs`, in BuildLibCalls.cpp, and the
 current ones are `modf`/`modff` and `frexp`/`frexpf`.

 This happens only when the calls are found through TLI to have
 vectorized counterparts.

>From ff9557fe913fd7901cd5a18757a2a41bffbe5c0e Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Tue, 16 Jan 2024 10:53:09 +
Subject: [PATCH 1/2] LAA cannot vectorize lib calls like modf/modff

Functions like modf/modff are math lib calls that set memory write-only
attribute. Given that a target has vectorized mappings, LAA should allow
vectorization.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 57 +++
 1 file changed, 57 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
new file mode 100644
index 00..a449fac147058a
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --filter "call.*(frexp|modf)" --version 4
+// RUN: %clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -mllvm 
-vector-library=ArmPL -mllvm -force-vector-interleave=1 -mllvm 
-prefer-predicate-over-epilogue=predicate-dont-vectorize -emit-llvm -S -o - %s 
| FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+/*
+Testing vectorization of math functions that have the attribute write-only to
+memory set. Given they have vectorized counterparts, they should be able to
+vectorize.
+*/
+
+// The following define is required to access some math functions.
+#define _GNU_SOURCE
+#include 
+
+// frexp/frexpf have no TLI mappings yet.
+
+// CHECK-LABEL: define dso_local void @frexp_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK:[[CALL:%.*]] = tail call double @frexp(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2:[0-9]+]]
+//
+void frexp_f64(double *in, double *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexp(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @frexp_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @frexpf(float noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2]]
+//
+void frexp_f32(float *in, float *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexpf(in[i], out2+i);
+}
+
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call double @modf(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR3:[0-9]+]]
+//
+void modf_f64(double *in, double *out1, double *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modf(in[i], out2+i);
+}
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @modff(float noundef [[TMP0:%.*]], 
ptr noundef [[ADD_PTR:%.*]]) #[[ATTR4:[0-9]+]]
+//
+void modf_f32(float *in, float *out1, float *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modff(in[i], out2+i);
+}

>From 2a3b1e60c3f68c2f823a42bcd6e67111a0b8a529 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Wed, 17 Jan 2024 09:44:45 +
Subject: [PATCH 2/2] [LV][LAA] Vectorize math lib calls with mem write-only
 attribute

Teach LAA to consider safe specific math lib calls which are known to
have set the memory write-only attribute. Those attributes are set to
calls by inferNonMandatoryLibFuncAttrs, in BuildLibCalls.cpp, and the
current ones are modf/modff and frexp/frexpf.

This happens only when the calls are found through TLI to have
vectorized counterparts.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 15 ++-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp  | 19 +++
 2 files changed, 25 insertions(+), 9 deletions(-

[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-17 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-17 Thread Mariya Podchishchaeva via cfe-commits


@@ -165,6 +165,8 @@ C++23 Feature Support
 - Added a separate warning to warn the use of attributes on lambdas as a C++23 
extension
   in previous language versions: ``-Wc++23-lambda-attributes``.
 
+- Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
+

Fznamznon wrote:

Okay, done. I'm not sure I updated `LanguageExtensions.rst`, please take a look.
I also added some testing for enabling extension in earlier language modes.

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


[clang] e6bd983 - [clang][CodeGen] Fix gcc warning about unused variable [NFC]

2024-01-17 Thread Mikael Holmen via cfe-commits

Author: Mikael Holmen
Date: 2024-01-17T13:23:08+01:00
New Revision: e6bd9835d90c8c30ceeb05338e80d75cf41a3b84

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

LOG: [clang][CodeGen] Fix gcc warning about unused variable [NFC]

Without the fix gcc warned with
 ../../clang/lib/CodeGen/CGBuiltin.cpp:1022:19: warning: unused variable 'DRE' 
[-Wunused-variable]
  1022 |   if (const auto *DRE = dyn_cast(Base)) {
   |   ^~~

Fix the warning by removing the unused variable and change the "dyn_cast"
to "isa".

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index de48b15645b1ab..f4246c5e8f68e8 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1019,7 +1019,7 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr 
*E, unsigned Type,
   FAMSize = Builder.CreateIntCast(FAMSize, ResType, IsSigned);
   Value *Res = FAMSize;
 
-  if (const auto *DRE = dyn_cast(Base)) {
+  if (isa(Base)) {
 // The whole struct is specificed in the __bdos.
 const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(OuterRD);
 



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


[clang] [clang-tools-extra] [llvm] [clang-format] TableGen multi line string support. (PR #78032)

2024-01-17 Thread Hirofumi Nakamura via cfe-commits

hnakamura5 wrote:

Thank you very much!

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


[clang] [clang-tools-extra] [llvm] [clang-format] TableGen multi line string support. (PR #78032)

2024-01-17 Thread Hirofumi Nakamura via cfe-commits

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


[clang] e3702f6 - [clang-format] TableGen multi line string support. (#78032)

2024-01-17 Thread via cfe-commits

Author: Hirofumi Nakamura
Date: 2024-01-17T21:20:35+09:00
New Revision: e3702f6225fe4438ccffcac3f612e902c7b3db22

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

LOG: [clang-format] TableGen multi line string support. (#78032)

Support the handling of TableGen's multiline string (code) literal.
That has the form, 
[{ this is the string possibly with multi line... }]

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 102504182c4505..e6eaaa9ab45706 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1591,6 +1591,9 @@ unsigned 
ContinuationIndenter::moveStateToNextToken(LineState &State,
 State.StartOfStringLiteral = State.Column + 1;
   if (Current.is(TT_CSharpStringLiteral) && State.StartOfStringLiteral == 0) {
 State.StartOfStringLiteral = State.Column + 1;
+  } else if (Current.is(TT_TableGenMultiLineString) &&
+ State.StartOfStringLiteral == 0) {
+State.StartOfStringLiteral = State.Column + 1;
   } else if (Current.isStringLiteral() && State.StartOfStringLiteral == 0) {
 State.StartOfStringLiteral = State.Column;
   } else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index d5ef627f1348d3..dede89f2600150 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -148,6 +148,7 @@ namespace format {
   TYPE(StructLBrace)   
\
   TYPE(StructRBrace)   
\
   TYPE(StructuredBindingLSquare)   
\
+  TYPE(TableGenMultiLineString)
\
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
   TYPE(TemplateString) 
\

diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a1fd6dd6effe6c..25ac9be57c81a9 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -93,6 +93,8 @@ ArrayRef FormatTokenLexer::lex() {
   // string literals are correctly identified.
   handleCSharpVerbatimAndInterpolatedStrings();
 }
+if (Style.isTableGen())
+  handleTableGenMultilineString();
 if (Tokens.back()->NewlinesBefore > 0 || Tokens.back()->IsMultiline)
   FirstInLineIndex = Tokens.size() - 1;
   } while (Tokens.back()->isNot(tok::eof));
@@ -272,6 +274,14 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   return;
 }
   }
+  // TableGen's Multi line string starts with [{
+  if (Style.isTableGen() && tryMergeTokens({tok::l_square, tok::l_brace},
+   TT_TableGenMultiLineString)) {
+// Set again with finalizing. This must never be annotated as other types.
+Tokens.back()->setFinalizedType(TT_TableGenMultiLineString);
+Tokens.back()->Tok.setKind(tok::string_literal);
+return;
+  }
 }
 
 bool FormatTokenLexer::tryMergeNSStringLiteral() {
@@ -763,6 +773,37 @@ void 
FormatTokenLexer::handleCSharpVerbatimAndInterpolatedStrings() {
   resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Offset + 1)));
 }
 
+void FormatTokenLexer::handleTableGenMultilineString() {
+  FormatToken *MultiLineString = Tokens.back();
+  if (MultiLineString->isNot(TT_TableGenMultiLineString))
+return;
+
+  auto OpenOffset = Lex->getCurrentBufferOffset() - 2 /* "[{" */;
+  // "}]" is the end of multi line string.
+  auto CloseOffset = Lex->getBuffer().find("}]", OpenOffset);
+  if (CloseOffset == StringRef::npos)
+return;
+  auto Text = Lex->getBuffer().substr(OpenOffset, CloseOffset + 2);
+  MultiLineString->TokenText = Text;
+  resetLexer(SourceMgr.getFileOffset(
+  Lex->getSourceLocation(Lex->getBufferLocation() - 2 + Text.size(;
+  auto FirstLineText = Text;
+  auto FirstBreak = Text.find('\n');
+  // Set ColumnWidth and LastLineColumnWidth when it has multiple lines.
+  if (FirstBreak != StringRef::npos) {
+MultiLineString->IsMultiline = true;
+FirstLineText = Text.substr(0, FirstBreak + 1);
+// LastLineColumnWidth holds the width of the last line.
+auto LastBreak = Text.rfind('\n');
+MultiLineString->LastLineColumnWidth = encoding::columnWidthWithTabs(
+ 

[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78305)

2024-01-17 Thread David Spickett via cfe-commits

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

LGTM

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


[llvm] [clang-tools-extra] [clang] [clang-format] TableGen multi line string support. (PR #78032)

2024-01-17 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/78032

>From d0767350f26215e86dee039427183630b3f02668 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Sat, 13 Jan 2024 21:44:34 +0900
Subject: [PATCH 1/4] [clang-format] TableGen multi line string support.

---
 clang/lib/Format/ContinuationIndenter.cpp |  3 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/FormatTokenLexer.cpp | 57 +++
 clang/lib/Format/FormatTokenLexer.h   |  3 +
 clang/lib/Format/TokenAnnotator.cpp   |  2 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp |  5 ++
 6 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 102504182c4505..e6eaaa9ab45706 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1591,6 +1591,9 @@ unsigned 
ContinuationIndenter::moveStateToNextToken(LineState &State,
 State.StartOfStringLiteral = State.Column + 1;
   if (Current.is(TT_CSharpStringLiteral) && State.StartOfStringLiteral == 0) {
 State.StartOfStringLiteral = State.Column + 1;
+  } else if (Current.is(TT_TableGenMultiLineString) &&
+ State.StartOfStringLiteral == 0) {
+State.StartOfStringLiteral = State.Column + 1;
   } else if (Current.isStringLiteral() && State.StartOfStringLiteral == 0) {
 State.StartOfStringLiteral = State.Column;
   } else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index d5ef627f1348d3..dede89f2600150 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -148,6 +148,7 @@ namespace format {
   TYPE(StructLBrace)   
\
   TYPE(StructRBrace)   
\
   TYPE(StructuredBindingLSquare)   
\
+  TYPE(TableGenMultiLineString)
\
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
   TYPE(TemplateString) 
\
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a1fd6dd6effe6c..1060009bdcf131 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -93,6 +93,8 @@ ArrayRef FormatTokenLexer::lex() {
   // string literals are correctly identified.
   handleCSharpVerbatimAndInterpolatedStrings();
 }
+if (Style.isTableGen())
+  handleTableGenMultilineString();
 if (Tokens.back()->NewlinesBefore > 0 || Tokens.back()->IsMultiline)
   FirstInLineIndex = Tokens.size() - 1;
   } while (Tokens.back()->isNot(tok::eof));
@@ -272,6 +274,14 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   return;
 }
   }
+  if (Style.isTableGen()) {
+if (tryMergeTokens({tok::l_square, tok::l_brace},
+   TT_TableGenMultiLineString)) {
+  // Multi line string starts with [{
+  Tokens.back()->Tok.setKind(tok::string_literal);
+  return;
+}
+  }
 }
 
 bool FormatTokenLexer::tryMergeNSStringLiteral() {
@@ -763,6 +773,53 @@ void 
FormatTokenLexer::handleCSharpVerbatimAndInterpolatedStrings() {
   resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Offset + 1)));
 }
 
+void FormatTokenLexer::handleTableGenMultilineString() {
+  FormatToken *MultiLineString = Tokens.back();
+  if (MultiLineString->isNot(TT_TableGenMultiLineString))
+return;
+
+  bool PrevIsRBrace = false;
+  const char *FirstBreak = nullptr;
+  const char *LastBreak = nullptr;
+  const char *Begin = MultiLineString->TokenText.begin();
+  // Skip until }], the closer of multi line string found.
+  for (const char *Current = Begin, *End = Lex->getBuffer().end();
+   Current != End; ++Current) {
+if (PrevIsRBrace && *Current == ']') {
+  // }] is the end of multi line string.
+  if (!FirstBreak)
+FirstBreak = Current;
+  MultiLineString->TokenText = StringRef(Begin, Current - Begin + 1);
+  // ColumnWidth is only the width of the first line.
+  MultiLineString->ColumnWidth = encoding::columnWidthWithTabs(
+  StringRef(Begin, FirstBreak - Begin + 1),
+  MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
+  if (LastBreak) {
+// Set LastLineColumnWidth if multi line string has multiple lines.
+MultiLineString->LastLineColumnWidth = encoding::columnWidthWithTabs(
+StringRef(LastBreak + 1, Current - LastBreak),
+MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
+  }
+  resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Current + 1)));
+  return;
+}

[clang] [flang] [llvm] [AArch64][Driver] Better handling of target feature dependencies (PR #78270)

2024-01-17 Thread Sjoerd Meijer via cfe-commits

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

This is a very big patch, but it makes a lot of sense. The idea to do it in 
this way is clearly an improvement. There are quite a number of (new) moving 
parts involved here, but look reasonable to me so let's give this is a try.  

Thanks for cleaning up the mess (also my mess). 

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


[libcxxabi] [flang] [llvm] [libc] [libunwind] [clang-tools-extra] [lld] [clang] [lldb] [compiler-rt] [mlir] [libcxx] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-17 Thread Hristo Hristov via cfe-commits

H-G-Hristov wrote:

How do I fix the following generated files check error:

```diff
[8/9] cd 
/home/runner/work/llvm-project/llvm-project/build/check-generated-output/libcxx/utils
 && /usr/bin/python3.10 
/home/runner/work/llvm-project/llvm-project/libcxx/utils/generate_iwyu_mapping.py
[9/9] cd 
/home/runner/work/llvm-project/llvm-project/build/check-generated-output/libcxx/utils
 && /usr/bin/python3.10 
/home/runner/work/llvm-project/llvm-project/libcxx/utils/generate_escaped_output_table.py
 
/home/runner/work/llvm-project/llvm-project/libcxx/include/__format/escaped_output_table.h
diff --git a/libcxx/include/libcxx.imp b/libcxx/include/libcxx.imp
index 8616f9639..45fa4a954 100644
--- a/libcxx/include/libcxx.imp
+++ b/libcxx/include/libcxx.imp
@@ -559,6 +559,7 @@
   { include: [ "<__numeric/pstl_reduce.h>", "private", "", "public" ] 
},
   { include: [ "<__numeric/pstl_transform_reduce.h>", "private", "", 
"public" ] },
   { include: [ "<__numeric/reduce.h>", "private", "", "public" ] },
+  { include: [ "<__numeric/saturation_arithmetic.h>", "private", "", 
"public" ] },
   { include: [ "<__numeric/transform_exclusive_scan.h>", "private", 
"", "public" ] },
   { include: [ "<__numeric/transform_inclusive_scan.h>", "private", 
"", "public" ] },
   { include: [ "<__numeric/transform_reduce.h>", "private", "", 
"public" ] },
```

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


[clang] [coroutines][coro_lifetimebound] Detect lifetime issues with lambda captures (PR #77066)

2024-01-17 Thread Utkarsh Saxena via cfe-commits

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


[clang] [coroutines][coro_lifetimebound] Detect lifetime issues with lambda captures (PR #77066)

2024-01-17 Thread Utkarsh Saxena via cfe-commits

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


[clang] [coroutines][coro_lifetimebound] Detect lifetime issues with lambda captures (PR #77066)

2024-01-17 Thread Utkarsh Saxena via cfe-commits

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

>From 3e0d0ab6c4fc6cba68285816a95e423bc18e8e55 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Fri, 5 Jan 2024 10:11:20 +0100
Subject: [PATCH 01/15] [coroutines] Detect lifetime issues with coroutine
 lambda captures

---
 clang/lib/Sema/SemaInit.cpp   | 20 +--
 clang/test/SemaCXX/coro-lifetimebound.cpp | 64 +--
 2 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 60c0e3e74204ecd..c100bf114547869 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -12,6 +12,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
@@ -33,6 +34,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -7575,15 +7577,27 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call,
 Path.pop_back();
   };
 
-  if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
-VisitLifetimeBoundArg(Callee, ObjectArg);
-
   bool CheckCoroCall = false;
   if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
 CheckCoroCall = RD->hasAttr() &&
 RD->hasAttr() &&
 !Callee->hasAttr();
   }
+
+  if (ObjectArg) {
+bool CheckCoroObjArg = CheckCoroCall;
+// Ignore `__promise.get_return_object()` as it not lifetimebound.
+if (Callee->getDeclName().isIdentifier() &&
+Callee->getName() == "get_return_object")
+  CheckCoroObjArg = false;
+// Coroutine lambda objects with empty capture list are not lifetimebound.
+if (auto *LE = dyn_cast(ObjectArg->IgnoreImplicit());
+LE && LE->captures().empty())
+  CheckCoroObjArg = false;
+if (implicitObjectParamIsLifetimeBound(Callee) || CheckCoroObjArg)
+  VisitLifetimeBoundArg(Callee, ObjectArg);
+  }
+
   for (unsigned I = 0,
 N = std::min(Callee->getNumParams(), Args.size());
I != N; ++I) {
diff --git a/clang/test/SemaCXX/coro-lifetimebound.cpp 
b/clang/test/SemaCXX/coro-lifetimebound.cpp
index 3fc7ca70a14a124..319134450e4b6f7 100644
--- a/clang/test/SemaCXX/coro-lifetimebound.cpp
+++ b/clang/test/SemaCXX/coro-lifetimebound.cpp
@@ -64,6 +64,10 @@ Co bar_coro(const int &b, int c) {
   : bar_coro(0, 1); // expected-warning {{returning address of local 
temporary object}}
 }
 
+// 
=
+// Lambdas
+// 
=
+namespace lambdas {
 void lambdas() {
   auto unsafe_lambda = [] [[clang::coro_wrapper]] (int b) {
 return foo_coro(b); // expected-warning {{address of stack memory 
associated with parameter}}
@@ -84,15 +88,47 @@ void lambdas() {
 co_return x + co_await foo_coro(b);
   };
 }
+
+Co lambda_captures() {
+  int a = 1;
+  // Temporary lambda object dies.
+  auto lamb = [a](int x, const int& y) -> Co { // expected-warning 
{{temporary whose address is used as value of local variable 'lamb'}}
+co_return x + y + a;
+  }(1, a);
+  // Object dies but it has no capture.
+  auto no_capture = []() -> Co { co_return 1; }();
+  auto bad_no_capture = [](const int& a) -> Co { co_return a; }(1); // 
expected-warning {{temporary}}
+  // Temporary lambda object with lifetime extension under co_await.
+  int res = co_await [a](int x, const int& y) -> Co {
+co_return x + y + a;
+  }(1, a);
+  co_return 1;
+}
+} // namespace lambdas
+
 // 
=
-// Safe usage when parameters are value
+// Member coroutines
 // 
=
-namespace by_value {
-Co value_coro(int b) { co_return co_await foo_coro(b); }
-[[clang::coro_wrapper]] Co wrapper1(int b) { return value_coro(b); }
-[[clang::coro_wrapper]] Co wrapper2(const int& b) { return value_coro(b); 
}
+namespace member_coroutines{
+struct S {
+  Co member(const int& a) { co_return a; }  
+};
+
+Co use() {
+  S s;
+  int a = 1;
+  auto test1 = s.member(1);  // expected-warning {{temporary whose address is 
used as value of local variable}}
+  auto test2 = s.member(a);
+  auto test3 = S{}.member(a);  // expected-warning {{temporary whose address 
is used as value of local variable}}
+  co_return 1;
 }
 
+[[clang::coro_wrapper]] Co wrapper(const int& a) {
+  S s;
+  return s.member(a); // expected-warning {{address of stack memory}}
+}
+} // member_coroutines
+
 // 
=
 // Lifetime bound but not a Coroutine Return Type

[flang] [libc] [llvm] [clang-tools-extra] [clang] [compiler-rt] [libcxx] [AMDGPU] Fix llvm.amdgcn.s.wait.event.export.ready for GFX12 (PR #78191)

2024-01-17 Thread Jay Foad via cfe-commits

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


[clang-tools-extra] [clang] [llvm] [AMDGPU] Disable V_MAD_U64_U32/V_MAD_I64_I32 workaround for GFX12 (PR #77927)

2024-01-17 Thread Jay Foad via cfe-commits

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


[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78305)

2024-01-17 Thread Volodymyr Turanskyy via cfe-commits

https://github.com/voltur01 commented:

Looks good to me, thank you for picking it up!

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


[clang] [Clang][SME] Add missing IsStreamingCompatible flag to svget, svcreate & svset (PR #78430)

2024-01-17 Thread Sander de Smalen via cfe-commits

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

LGTM, thanks!

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


[clang] [clang][dataflow] Treat comma operator correctly in `getResultObjectLocation()`. (PR #78427)

2024-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (martinboehme)


Changes



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


2 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+7-2) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+16-6) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index a50ee57a3c11b4..99ed55fee779a3 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -781,8 +781,13 @@ Environment::getResultObjectLocation(const Expr 
&RecordPRValue) const {
 return Val->getLoc();
   }
 
-  // Expression nodes that propagate a record prvalue should have exactly one
-  // child.
+  if (auto *Op = dyn_cast(&RecordPRValue);
+  Op && Op->isCommaOp()) {
+return getResultObjectLocation(*Op->getRHS());
+  }
+
+  // All other expression nodes that propagate a record prvalue should have
+  // exactly one child.
   llvm::SmallVector children(RecordPRValue.child_begin(),
RecordPRValue.child_end());
   assert(children.size() == 1);
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 056c4f3383d832..9eabbdfb423a1f 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2642,14 +2642,17 @@ TEST(TransferTest, ResultObjectLocation) {
 };
 
 void target() {
-  A();
+  0, A();
   (void)0; // [[p]]
 }
   )";
+  using ast_matchers::binaryOperator;
   using ast_matchers::cxxBindTemporaryExpr;
   using ast_matchers::cxxTemporaryObjectExpr;
   using ast_matchers::exprWithCleanups;
   using ast_matchers::has;
+  using ast_matchers::hasOperatorName;
+  using ast_matchers::hasRHS;
   using ast_matchers::match;
   using ast_matchers::selectFirst;
   using ast_matchers::traverse;
@@ -2659,26 +2662,33 @@ TEST(TransferTest, ResultObjectLocation) {
  ASTContext &ASTCtx) {
 const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
 
-// The expresssion `A()` in the code above produces the following
-// structure, consisting of three prvalues of record type.
+// The expression `0, A()` in the code above produces the following
+// structure, consisting of four prvalues of record type.
 // `Env.getResultObjectLocation()` should return the same location for
 // all of these.
 auto MatchResult = match(
 traverse(TK_AsIs,
  exprWithCleanups(
- has(cxxBindTemporaryExpr(
- has(cxxTemporaryObjectExpr().bind("toe")))
- .bind("bte")))
+ has(binaryOperator(
+ hasOperatorName(","),
+ hasRHS(cxxBindTemporaryExpr(
+has(cxxTemporaryObjectExpr().bind(
+"toe")))
+.bind("bte")))
+ .bind("comma")))
  .bind("ewc")),
 ASTCtx);
 auto *TOE = selectFirst("toe", MatchResult);
 ASSERT_NE(TOE, nullptr);
+auto *Comma = selectFirst("comma", MatchResult);
+ASSERT_NE(Comma, nullptr);
 auto *EWC = selectFirst("ewc", MatchResult);
 ASSERT_NE(EWC, nullptr);
 auto *BTE = selectFirst("bte", MatchResult);
 ASSERT_NE(BTE, nullptr);
 
 RecordStorageLocation &Loc = Env.getResultObjectLocation(*TOE);
+EXPECT_EQ(&Loc, &Env.getResultObjectLocation(*Comma));
 EXPECT_EQ(&Loc, &Env.getResultObjectLocation(*EWC));
 EXPECT_EQ(&Loc, &Env.getResultObjectLocation(*BTE));
   });

``




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


[clang] [clang][dataflow] Treat comma operator correctly in `getResultObjectLocation()`. (PR #78427)

2024-01-17 Thread via cfe-commits

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

None

>From 5b4c241d1c5b07690400660f154f3d50d42bdd07 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Wed, 17 Jan 2024 11:27:20 +
Subject: [PATCH] [clang][dataflow] Treat comma operator correctly in
 `getResultObjectLocation()`.

---
 .../FlowSensitive/DataflowEnvironment.cpp |  9 ++--
 .../Analysis/FlowSensitive/TransferTest.cpp   | 22 ++-
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index a50ee57a3c11b4..99ed55fee779a3 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -781,8 +781,13 @@ Environment::getResultObjectLocation(const Expr 
&RecordPRValue) const {
 return Val->getLoc();
   }
 
-  // Expression nodes that propagate a record prvalue should have exactly one
-  // child.
+  if (auto *Op = dyn_cast(&RecordPRValue);
+  Op && Op->isCommaOp()) {
+return getResultObjectLocation(*Op->getRHS());
+  }
+
+  // All other expression nodes that propagate a record prvalue should have
+  // exactly one child.
   llvm::SmallVector children(RecordPRValue.child_begin(),
RecordPRValue.child_end());
   assert(children.size() == 1);
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 056c4f3383d832..9eabbdfb423a1f 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2642,14 +2642,17 @@ TEST(TransferTest, ResultObjectLocation) {
 };
 
 void target() {
-  A();
+  0, A();
   (void)0; // [[p]]
 }
   )";
+  using ast_matchers::binaryOperator;
   using ast_matchers::cxxBindTemporaryExpr;
   using ast_matchers::cxxTemporaryObjectExpr;
   using ast_matchers::exprWithCleanups;
   using ast_matchers::has;
+  using ast_matchers::hasOperatorName;
+  using ast_matchers::hasRHS;
   using ast_matchers::match;
   using ast_matchers::selectFirst;
   using ast_matchers::traverse;
@@ -2659,26 +2662,33 @@ TEST(TransferTest, ResultObjectLocation) {
  ASTContext &ASTCtx) {
 const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
 
-// The expresssion `A()` in the code above produces the following
-// structure, consisting of three prvalues of record type.
+// The expression `0, A()` in the code above produces the following
+// structure, consisting of four prvalues of record type.
 // `Env.getResultObjectLocation()` should return the same location for
 // all of these.
 auto MatchResult = match(
 traverse(TK_AsIs,
  exprWithCleanups(
- has(cxxBindTemporaryExpr(
- has(cxxTemporaryObjectExpr().bind("toe")))
- .bind("bte")))
+ has(binaryOperator(
+ hasOperatorName(","),
+ hasRHS(cxxBindTemporaryExpr(
+has(cxxTemporaryObjectExpr().bind(
+"toe")))
+.bind("bte")))
+ .bind("comma")))
  .bind("ewc")),
 ASTCtx);
 auto *TOE = selectFirst("toe", MatchResult);
 ASSERT_NE(TOE, nullptr);
+auto *Comma = selectFirst("comma", MatchResult);
+ASSERT_NE(Comma, nullptr);
 auto *EWC = selectFirst("ewc", MatchResult);
 ASSERT_NE(EWC, nullptr);
 auto *BTE = selectFirst("bte", MatchResult);
 ASSERT_NE(BTE, nullptr);
 
 RecordStorageLocation &Loc = Env.getResultObjectLocation(*TOE);
+EXPECT_EQ(&Loc, &Env.getResultObjectLocation(*Comma));
 EXPECT_EQ(&Loc, &Env.getResultObjectLocation(*EWC));
 EXPECT_EQ(&Loc, &Env.getResultObjectLocation(*BTE));
   });

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


[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-17 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

> @11happy what are you trying to achieve exactly and what is not working ? Is 
> this related to the example that you provided above?
> 
> > ```
> > auto lhsVar1Str = Lexer::getSourceText( 
> > >CharSourceRange::getTokenRange(Source.getSpellingLoc(lhsVar1->getBeginLoc()),Source.getSpellingLoc(lhsVar1->getEn>dLoc())),
> >  Context.getSourceManager(), Context.getLangOpts());
> > ```
> > 
> > 
> > 
> >   
> > 
> > 
> >   
> > 
> > 
> > 
> >   
> > it outputs this :
> > ```
> > //
> > -  if (MY_MIN(value1, value2) < value3)
> > -value3 = MY_MIN(value1, value2); //
> > +  value3 = std::min((a) < (b) ? (a) : (b), value3); //
> > }
> > ```
> 
> If that's the case I'm guessing that you simply forgot to update the begin 
> and end location of the if/then stmt with the spelling loc ?
> 
> Regarding the request for a test case with macros, my intention was to 
> understand how your check handles them. I believe updating a macro is risk 
> free, but there might be use cases that I'm overlooking. One potential issue 
> could arise if someone is using the macro in another translation unit without 
> directly importing it. In that case, updating the macro without the necessary 
> include might cause compilation failures. However, I'm unsure if this is a 
> use case that needs consideration.
> 
> It might be worth to look if other checks are currently updating macros. This 
> might be a decent indicator of the risk of doing so (If a few checks are 
> already doing it then I might be overthinking it). Also, @PiotrZSL might be 
> able to give us some insight on this since he has more experience with 
> clang-tidy.

thanks , got it working 

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


[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-17 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

**Here's the update for recent commit :**
- Modified the RegisterMatcher to support the `If` statement with brackets by 
adding this ```compoundStmt(has(binaryOperator(
hasOperatorName("="), hasLHS(expr().bind("lhsVar2")),
hasRHS(expr().bind("rhsVar2")``` as AST matchers 
for If statement with brackets looked like this:
   
![Screenshot from 2024-01-17 
14-08-48](https://github.com/llvm/llvm-project/assets/76656712/8721f3ea-0e23-46e8-b446-06b8e04c95f9)

- Formatted by placing the `CHECK-FIXES` on a new line below `CHECK-MESSAGES`
- Added Test for Macro Functions & If statemnt with brackets
- Changed ```Lexer::getSourceText(
  CharSourceRange::getTokenRange(rhsVar1->getSourceRange()),
  Context.getSourceManager(), Context.getLangOpts())``` to ```
  Lexer::getSourceText(Source.getExpansionRange(lhsVar1->getSourceRange()),
   Context.getSourceManager(), 
Context.getLangOpts());```
- I have kept the options for `AlgorithmHeader` instead of hardcoding to keep 
modularity also fixed the typo.


 


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


[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread via cfe-commits

https://github.com/kelbon updated 
https://github.com/llvm/llvm-project/pull/78200

>From b080d04eb30254502ccd5d59d76b5197db1fa88d Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Mon, 15 Jan 2024 22:24:34 +0400
Subject: [PATCH 1/7] add warning and test

---
 clang/include/clang/Basic/DiagnosticGroups.td| 1 +
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 7 +++
 clang/lib/Sema/SemaDecl.cpp  | 7 +++
 clang/test/Sema/incorrect_pure.cpp   | 7 +++
 4 files changed, 22 insertions(+)
 create mode 100644 clang/test/Sema/incorrect_pure.cpp

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c1..9fcf2be2e45458e 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -414,6 +414,7 @@ def : DiagGroup<"c++2a-compat", [CXX20Compat]>;
 def : DiagGroup<"c++2a-compat-pedantic", [CXX20CompatPedantic]>;
 
 def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
+def IncorrectAttributeUsage : DiagGroup<"incorrect-attribute-usage">;
 def FlexibleArrayExtensions : DiagGroup<"flexible-array-extensions">;
 def FourByteMultiChar : DiagGroup<"four-char-constants">;
 def GlobalConstructors : DiagGroup<"global-constructors"> {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 414779a7970ab8e..0ad3ea64503d81e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -692,6 +692,13 @@ def warn_maybe_falloff_nonvoid_function : Warning<
 def warn_falloff_nonvoid_function : Warning<
   "non-void function does not return a value">,
   InGroup;
+def warn_pure_attr_on_cxx_constructor : Warning<
+  "constructor cannot be 'pure' (undefined behavior)">,
+  InGroup;
+def warn_pure_function_returns_void : Warning<
+  "'pure' attribute on function returning 'void'">,
+  InGroup;
+
 def err_maybe_falloff_nonvoid_block : Error<
   "non-void block does not return a value in all control paths">;
 def err_falloff_nonvoid_block : Error<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4e7049571eeb7a3..e340028703b3b31 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11889,6 +11889,13 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 NewFD->setInvalidDecl();
   }
 
+  if (NewFD->hasAttr() || NewFD->hasAttr()) {
+if (isa_and_nonnull(NewFD))
+  Diag(NewFD->getLocation(), diag::warn_pure_attr_on_cxx_constructor);
+else if (NewFD->getReturnType()->isVoidType())
+  Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void);
+  }
+
   // C++11 [dcl.constexpr]p8:
   //   A constexpr specifier for a non-static member function that is not
   //   a constructor declares that member function to be const.
diff --git a/clang/test/Sema/incorrect_pure.cpp 
b/clang/test/Sema/incorrect_pure.cpp
new file mode 100644
index 000..ce02309f0863863
--- /dev/null
+++ b/clang/test/Sema/incorrect_pure.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+[[gnu::pure]] void foo(); // expected-warning{{'pure' attribute on function 
returning 'void'}}
+
+struct A {
+[[gnu::pure]] A(); // expected-warning{{constructor cannot be 'pure' 
(undefined behavior)}}
+};

>From d43afccb027ea0e02c97ab9fbe55a1ad6c9d71dd Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Mon, 15 Jan 2024 22:52:23 +0400
Subject: [PATCH 2/7] use precondition: NewFD is not null

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

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e340028703b3b31..dcbc5c3c842cca3 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11890,7 +11890,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   }
 
   if (NewFD->hasAttr() || NewFD->hasAttr()) {
-if (isa_and_nonnull(NewFD))
+if (isa(NewFD))
   Diag(NewFD->getLocation(), diag::warn_pure_attr_on_cxx_constructor);
 else if (NewFD->getReturnType()->isVoidType())
   Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void);

>From 950ca9de1c05d561a1123c088455a3e21bd9795b Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Tue, 16 Jan 2024 00:03:47 +0400
Subject: [PATCH 3/7] fix old incorrect test

---
 clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp 
b/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp
index 9d68a0e5d358f67..6ae146f0d08c7d3 100644
--- a/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp
+++ b/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp
@@ -194,7 +194,7 @@ struct except_spec_d_match : except_spec_a, except_spec_b {
 // gcc-compatibility: allow attributes on default definitions
 // (but not normal defini

[llvm] [clang] [AMDGPU] Add InstCombine rule for ballot.i64 intrinsic in wave32 mode. (PR #71556)

2024-01-17 Thread via cfe-commits

dyung wrote:

@vpykhtin the test you modified builtins-amdgcn-wave32.cl seems to be failing 
on a few bots. Can you take a look?

https://lab.llvm.org/buildbot/#/builders/188/builds/40541
https://lab.llvm.org/buildbot/#/builders/91/builds/21847
https://lab.llvm.org/buildbot/#/builders/98/builds/31671
https://lab.llvm.org/buildbot/#/builders/139/builds/57289


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


[llvm] [clang-tools-extra] [clang] [CLANG] Fix : More Detailed "No expected directives found" (PR #78338)

2024-01-17 Thread Shourya Goel via cfe-commits


@@ -9,7 +9,7 @@
 /// \file
 /// Defines the Diagnostic-related interfaces.
 //
-//===--===//
+//===--===//]

Sh0g0-1758 wrote:

done

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


[llvm] [clang-tools-extra] [clang] [CLANG] Fix : More Detailed "No expected directives found" (PR #78338)

2024-01-17 Thread Shourya Goel via cfe-commits

Sh0g0-1758 wrote:

@asl, I have checked all the files I changed and I have removed the unrelated 
changes and the changes related to another issue. Really sorry for this, I hope 
you can overlook it since this is my very first PR in LLVM. 

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


[clang] [clang][AST] Invalidate DecompositionDecl if it has invalid initializer. (PR #72428)

2024-01-17 Thread Haojian Wu via cfe-commits

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


[clang] 8f7fdd9 - [clang][AST] Invalidate DecompositionDecl if it has invalid initializer. (#72428)

2024-01-17 Thread via cfe-commits

Author: Haojian Wu
Date: 2024-01-17T12:11:16+01:00
New Revision: 8f7fdd94ef19af7b4905b316c253a78219a6038f

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

LOG: [clang][AST] Invalidate DecompositionDecl if it has invalid initializer. 
(#72428)

Fix #67495, #72198

We build ill-formed AST nodes for invalid structured binding. For case
`int [_, b] = {0, 0};`, the `DecompositionDecl` is valid, and its
children `BindingDecl`s are valid but with a NULL type, this breaks
clang invariants in many places, and using these `BindingDecl`s can lead
to crashes. This patch fixes them by marking the DecompositionDecl and
its children invalid.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/AST/ast-dump-invalid-initialized.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e45e016b3d66bd1..737302520024515 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -765,6 +765,9 @@ Bug Fixes in This Version
   Fixes (`#77583 `_)
 - Fix an issue where CTAD fails for function-type/array-type arguments.
   Fixes (`#51710 `_)
+- Fix crashes when using the binding decl from an invalid structured binding.
+  Fixes (`#67495 `_) and
+  (`#72198 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b642f38fa628ace..b74ff0b9bfe4c83 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13602,6 +13602,15 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
   CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), Args);
   if (RecoveryExpr.get())
 VDecl->setInit(RecoveryExpr.get());
+  // In general, for error recovery purposes, the initalizer doesn't play
+  // part in the valid bit of the declaration. There are a few exceptions:
+  //  1) if the var decl has a deduced auto type, and the type cannot be
+  // deduced by an invalid initializer;
+  //  2) if the var decl is decompsition decl with a non-deduced type, and
+  // the initialization fails (e.g. `int [a] = {1, 2};`);
+  // Case 1) was already handled elsewhere.
+  if (isa(VDecl)) // Case 2)
+VDecl->setInvalidDecl();
   return;
 }
 

diff  --git a/clang/test/AST/ast-dump-invalid-initialized.cpp 
b/clang/test/AST/ast-dump-invalid-initialized.cpp
index 1c374ae716a9db5..7fcbc41a7be4001 100644
--- a/clang/test/AST/ast-dump-invalid-initialized.cpp
+++ b/clang/test/AST/ast-dump-invalid-initialized.cpp
@@ -24,4 +24,19 @@ void test() {
   auto b4 = A(1);
   // CHECK: `-VarDecl {{.*}} invalid b5 'auto'
   auto b5 = A{1};
-}
\ No newline at end of file
+}
+
+void GH72198() {
+  // CHECK: DecompositionDecl {{.*}} invalid 'int'
+  int [_, b] = {0, 0};
+  [b]{};
+}
+
+namespace GH67495 {
+int get_point();
+void f() {
+  // CHECK: DecompositionDecl {{.*}} invalid 'int &'
+  auto& [x, y] = get_point();
+  [x, y] {};
+}
+}



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


[llvm] [clang-tools-extra] [clang] [CLANG] Fix : More Detailed "No expected directives found" (PR #78338)

2024-01-17 Thread Shourya Goel via cfe-commits

https://github.com/Sh0g0-1758 updated 
https://github.com/llvm/llvm-project/pull/78338

>From b98f02d4c155b5be9bd4f5b2e4bf73720a81f39a Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 
Date: Wed, 17 Jan 2024 01:24:17 +0530
Subject: [PATCH 1/5] Fix : more detailed no expected directive message

---
 clang-tools-extra/clangd/test/indexer.test   | 2 +-
 clang/include/clang/Basic/Diagnostic.h   | 4 +++-
 clang/include/clang/Basic/DiagnosticFrontendKinds.td | 2 +-
 clang/lib/AST/ASTContext.cpp | 2 +-
 clang/lib/Frontend/VerifyDiagnosticConsumer.cpp  | 4 +++-
 clang/test/ARCMT/verify.m| 2 +-
 clang/test/Frontend/verify.c | 2 +-
 clang/test/Frontend/verify2.c| 2 +-
 clang/test/Frontend/verify3.c| 4 ++--
 9 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/clang-tools-extra/clangd/test/indexer.test 
b/clang-tools-extra/clangd/test/indexer.test
index 2f01f6c557a7de7..213d33f8e2d6a56 100644
--- a/clang-tools-extra/clangd/test/indexer.test
+++ b/clang-tools-extra/clangd/test/indexer.test
@@ -5,5 +5,5 @@
 # `.ii` file and `-verify` triggers extra diagnostics generation. Clangd should
 # strip those.
 # RUN: clangd-indexer %t.cpp -- -Xclang -verify --save-temps -- 2>&1 | 
FileCheck %s
-# CHECK-NOT: error: no expected directives found: consider use of 
'expected-no-diagnostics'
+# CHECK-NOT: error: no expected directives found: consider use of 
{{.*}}-no-diagnostics
 # RUN: not ls %t.ii
diff --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index 0c7836c2ea569cc..a185c75e418b58b 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -9,7 +9,9 @@
 /// \file
 /// Defines the Diagnostic-related interfaces.
 //
-//===--===//
+//===--===//]
+
+// look into this file as well
 
 #ifndef LLVM_CLANG_BASIC_DIAGNOSTIC_H
 #define LLVM_CLANG_BASIC_DIAGNOSTIC_H
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 568000106a84dc7..42d2767af6b7081 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -179,7 +179,7 @@ def err_verify_invalid_no_diags : Error<
 "%select{expected|'expected-no-diagnostics'}0 directive cannot follow "
 "%select{'expected-no-diagnostics' directive|other expected directives}0">;
 def err_verify_no_directives : Error<
-"no expected directives found: consider use of 'expected-no-diagnostics'">;
+"no expected directives found: consider use of '%0'-no-diagnostics">;
 def err_verify_nonconst_addrspace : Error<
   "qualifier 'const' is needed for variables in address space '%0'">;
 
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index b60dcfaabfd1a4b..0997ac9fa7df042 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1404,7 +1404,7 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
 getTranslationUnitDecl()->addDecl(MSGuidTagDecl);
   }
 }
-
+// maybe change here also. 
 DiagnosticsEngine &ASTContext::getDiagnostics() const {
   return SourceMgr.getDiagnostics();
 }
diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp 
b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
index 8a3d2286cd168c3..9a26905a76d46bb 100644
--- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -1098,7 +1098,9 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() {
 // Produce an error if no expected-* directives could be found in the
 // source file(s) processed.
 if (Status == HasNoDirectives) {
-  Diags.Report(diag::err_verify_no_directives).setForceEmit();
+  // change here
+  std::string directives = 
*Diags.getDiagnosticOptions().VerifyPrefixes.begin();
+  Diags.Report(diag::err_verify_no_directives).setForceEmit() << 
directives;
   ++NumErrors;
   Status = HasNoDirectivesReported;
 }
diff --git a/clang/test/ARCMT/verify.m b/clang/test/ARCMT/verify.m
index 7d245fe80575e5b..13fd599f530fbec 100644
--- a/clang/test/ARCMT/verify.m
+++ b/clang/test/ARCMT/verify.m
@@ -11,7 +11,7 @@
 #error
 // expected-error@-1 {{}}
 
-//  CHECK: error: no expected directives found: consider use of 
'expected-no-diagnostics'
+//  CHECK: error: no expected directives found: consider use of 
{{.*}}-no-diagnostics
 // CHECK-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK-NEXT:   (frontend): error reading '{{.*}}verify.m.tmp.invalid'
 // CHECK-NEXT: 2 errors generated.
diff --git a/clang/test/Frontend/verify.c b/clang/test/Frontend/verify.c
index 221b715c19e416e..657a9d3f2bf6bb7 100644
--- a/clang/test/Frontend/verify.c
+++ b/

[libcxx] [clang] [libc] [llvm] [clang-tools-extra] [flang] [compiler-rt] [AMDGPU] Fix llvm.amdgcn.s.wait.event.export.ready for GFX12 (PR #78191)

2024-01-17 Thread Jay Foad via cfe-commits

https://github.com/jayfoad updated 
https://github.com/llvm/llvm-project/pull/78191

>From 9990fbc26ed3dc245a5127345326050acac49d66 Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Fri, 21 Apr 2023 10:46:43 +0100
Subject: [PATCH] [AMDGPU] Fix llvm.amdgcn.s.wait.event.export.ready for GFX12

The meaning of bit 0 of the immediate operand of S_WAIT_EVENT has been
flipped from GFX11.
---
 llvm/lib/Target/AMDGPU/SOPInstructions.td| 8 
 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.wait.event.ll | 9 ++---
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/SOPInstructions.td 
b/llvm/lib/Target/AMDGPU/SOPInstructions.td
index 46fa3d57a21cb2..b78d900c9bbf42 100644
--- a/llvm/lib/Target/AMDGPU/SOPInstructions.td
+++ b/llvm/lib/Target/AMDGPU/SOPInstructions.td
@@ -1768,10 +1768,10 @@ def : GCNPat<
   (S_SEXT_I32_I16 $src)
 >;
 
-def : GCNPat <
-  (int_amdgcn_s_wait_event_export_ready),
-(S_WAIT_EVENT (i16 0))
->;
+let SubtargetPredicate = isNotGFX12Plus in
+  def : GCNPat <(int_amdgcn_s_wait_event_export_ready), (S_WAIT_EVENT (i16 
0))>;
+let SubtargetPredicate = isGFX12Plus in
+  def : GCNPat <(int_amdgcn_s_wait_event_export_ready), (S_WAIT_EVENT (i16 
1))>;
 
 // The first 10 bits of the mode register are the core FP mode on all
 // subtargets.
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.wait.event.ll 
b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.wait.event.ll
index 3e95e4dec67a2b..25b5ddcf946b35 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.wait.event.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.wait.event.ll
@@ -1,8 +1,11 @@
-; RUN: llc -global-isel=0 -march=amdgcn -verify-machineinstrs -mcpu=gfx1100 < 
%s | FileCheck -check-prefix=GCN %s
-; RUN: llc -global-isel -march=amdgcn -verify-machineinstrs -mcpu=gfx1100 < %s 
| FileCheck -check-prefix=GCN %s
+; RUN: llc -global-isel=0 -march=amdgcn -verify-machineinstrs -mcpu=gfx1100 < 
%s | FileCheck -check-prefixes=GCN,GFX11 %s
+; RUN: llc -global-isel=1 -march=amdgcn -verify-machineinstrs -mcpu=gfx1100 < 
%s | FileCheck -check-prefixes=GCN,GFX11 %s
+; RUN: llc -global-isel=0 -march=amdgcn -verify-machineinstrs -mcpu=gfx1200 < 
%s | FileCheck -check-prefixes=GCN,GFX12 %s
+; RUN: llc -global-isel=1 -march=amdgcn -verify-machineinstrs -mcpu=gfx1200 < 
%s | FileCheck -check-prefixes=GCN,GFX12 %s
 
 ; GCN-LABEL: {{^}}test_wait_event:
-; GCN: s_wait_event 0x0
+; GFX11: s_wait_event 0x0
+; GFX12: s_wait_event 0x1
 
 define amdgpu_ps void @test_wait_event() #0 {
 entry:

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


[clang] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

2024-01-17 Thread Sam Tebbs via cfe-commits


@@ -279,6 +279,8 @@ def err_builtin_needs_feature : Error<"%0 needs target 
feature %1">;
 def err_function_needs_feature : Error<
   "always_inline function %1 requires target feature '%2', but would "
   "be inlined into function %0 that is compiled without support for '%2'">;
+def err_function_alwaysinline_attribute_mismatch : Error<

SamTebbs33 wrote:

Done

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


[clang] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

2024-01-17 Thread Sam Tebbs via cfe-commits


@@ -0,0 +1,12 @@
+// RUN: %clang --target=aarch64-none-linux-gnu -march=armv9-a+sme -O3 -S 
-Xclang -verify %s
+
+// Conflicting attributes when using always_inline
+__attribute__((always_inline)) __arm_locally_streaming
+int inlined_fn_local(void) {
+return 42;
+}

SamTebbs33 wrote:

Done

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


[clang] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

2024-01-17 Thread Sam Tebbs via cfe-commits

https://github.com/SamTebbs33 updated 
https://github.com/llvm/llvm-project/pull/77936

>From bbc6c11cd3def5acbb2ba2f2ddc45df2c399f9d6 Mon Sep 17 00:00:00 2001
From: Samuel Tebbs 
Date: Wed, 10 Jan 2024 14:57:04 +
Subject: [PATCH 1/5] [Clang][SME] Detect always_inline used with mismatched
 streaming attributes

This patch adds an error that is emitted when a streaming function is
marked as always_inline and is called from a non-streaming function.
---
 .../clang/Basic/DiagnosticFrontendKinds.td|  2 ++
 clang/include/clang/Sema/Sema.h   |  9 +++
 clang/lib/CodeGen/CMakeLists.txt  |  1 +
 clang/lib/CodeGen/Targets/AArch64.cpp | 20 ++
 clang/lib/Sema/SemaChecking.cpp   | 27 +++
 ...-sme-func-attrs-inline-locally-streaming.c | 12 +
 .../aarch64-sme-func-attrs-inline-streaming.c | 12 +
 7 files changed, 66 insertions(+), 17 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme-func-attrs-inline-locally-streaming.c
 create mode 100644 clang/test/CodeGen/aarch64-sme-func-attrs-inline-streaming.c

diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 568000106a84dc..dbd92b600a936e 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -279,6 +279,8 @@ def err_builtin_needs_feature : Error<"%0 needs target 
feature %1">;
 def err_function_needs_feature : Error<
   "always_inline function %1 requires target feature '%2', but would "
   "be inlined into function %0 that is compiled without support for '%2'">;
+def err_function_alwaysinline_attribute_mismatch : Error<
+  "always_inline function %1 and its caller %0 have mismatched %2 attributes">;
 
 def warn_avx_calling_convention
 : Warning<"AVX vector %select{return|argument}0 of type %1 without '%2' "
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4c464a1ae4c67f..0fed60103c9a2c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13803,8 +13803,17 @@ class Sema final {
 FormatArgumentPassingKind ArgPassingKind;
   };
 
+enum ArmStreamingType {
+  ArmNonStreaming,
+  ArmStreaming,
+  ArmStreamingCompatible,
+  ArmStreamingOrSVE2p1
+};
+
+
   static bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember,
   bool IsVariadic, FormatStringInfo *FSI);
+  static ArmStreamingType getArmStreamingFnType(const FunctionDecl *FD);
 
 private:
   void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index 52216d93a302bb..03a6f2f1d7a9d2 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -151,4 +151,5 @@ add_clang_library(clangCodeGen
   clangFrontend
   clangLex
   clangSerialization
+  clangSema
   )
diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index 7102d190fe008b..ea3d5a97605f1c 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -8,6 +8,8 @@
 
 #include "ABIInfoImpl.h"
 #include "TargetInfo.h"
+#include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Sema/Sema.h"
 
 using namespace clang;
 using namespace clang::CodeGen;
@@ -153,6 +155,11 @@ class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {
 }
 return TargetCodeGenInfo::isScalarizableAsmOperand(CGF, Ty);
   }
+
+  void checkFunctionCallABI(CodeGenModule &CGM, SourceLocation CallLoc,
+const FunctionDecl *Caller,
+const FunctionDecl *Callee,
+const CallArgList &Args) const override;
 };
 
 class WindowsAArch64TargetCodeGenInfo : public AArch64TargetCodeGenInfo {
@@ -812,6 +819,19 @@ Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   /*allowHigherAlign*/ false);
 }
 
+void AArch64TargetCodeGenInfo::checkFunctionCallABI(
+CodeGenModule &CGM, SourceLocation CallLoc, const FunctionDecl *Caller,
+const FunctionDecl *Callee, const CallArgList &Args) const {
+if (!Callee->hasAttr())
+  return;
+
+auto CalleeIsStreaming = Sema::getArmStreamingFnType(Callee) == 
Sema::ArmStreaming;
+auto CallerIsStreaming = Sema::getArmStreamingFnType(Caller) == 
Sema::ArmStreaming;
+
+if (CalleeIsStreaming && !CallerIsStreaming)
+CGM.getDiags().Report(CallLoc, 
diag::err_function_alwaysinline_attribute_mismatch) << Caller->getDeclName() << 
Callee->getDeclName() << "streaming";
+}
+
 std::unique_ptr
 CodeGen::createAArch64TargetCodeGenInfo(CodeGenModule &CGM,
 AArch64ABIKind Kind) {
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 74f8f626fb1637..160637dde448e4 100644
--- a/clang/lib/Sem

[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-17 Thread Sander de Smalen via cfe-commits


@@ -4253,7 +4260,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;

sdesmalen-arm wrote:

Thanks for both your input! The Arm attributes will probably be used reasonably 
sparsely in the sense that they particularly target code to optimise using SME 
intrinsics/state. By not adding the attribute it will be a normal function that 
does not share any SME state. So I agree it makes sense to refactor the code a 
bit such that these attributes don't affect code that does not use any of these 
attributes.

I've created #78424 to do this, so that the Arm SME attributes will have their 
own TrailingObject and are therefore only allocated when a function uses the 
attributes. I hope that addresses the concerns! (When that patch lands, I'll 
rebase this one)

It will be more difficult to do something for ExtProtoInfo, given how this is 
designed, but as @AaronBallman says the struct is already huge and is allocated 
as-needed. My experiment showed that adding more bits didn't make a practical 
difference to the size of the ExtProtoInfo. Not sure if this can differ between 
compilers, but I didn't see it expanding the struct by a byte.

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


[llvm] [clang] [clang-tools-extra] [AMDGPU] Disable V_MAD_U64_U32/V_MAD_I64_I32 workaround for GFX12 (PR #77927)

2024-01-17 Thread Jay Foad via cfe-commits

https://github.com/jayfoad updated 
https://github.com/llvm/llvm-project/pull/77927

>From 3f3bcdb89adf032e26c95807abf5e3b23ff50e4a Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Fri, 12 Jan 2024 12:24:28 +
Subject: [PATCH 1/3] Precommit extra GFX12 test coverage

---
 .../GlobalISel/inst-select-mad_64_32.mir  |  21 ++
 llvm/test/CodeGen/AMDGPU/llvm.mulo.ll | 163 ++
 llvm/test/CodeGen/AMDGPU/mad_64_32.ll | 211 ++
 3 files changed, 395 insertions(+)

diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-mad_64_32.mir 
b/llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-mad_64_32.mir
index 698281caca245e..6e33ef37397d6b 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-mad_64_32.mir
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-mad_64_32.mir
@@ -1,6 +1,7 @@
 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
 # RUN: llc -march=amdgcn -mcpu=gfx1030 -run-pass=instruction-select 
-global-isel-abort=2 -pass-remarks-missed='gisel*' -verify-machineinstrs %s -o 
- 2>%t | FileCheck -check-prefix=GFX10 %s
 # RUN: llc -march=amdgcn -mcpu=gfx1100 -run-pass=instruction-select 
-global-isel-abort=2 -pass-remarks-missed='gisel*' -verify-machineinstrs %s -o 
- 2>%t | FileCheck -check-prefix=GFX11 %s
+# RUN: llc -march=amdgcn -mcpu=gfx1200 -run-pass=instruction-select 
-global-isel-abort=2 -pass-remarks-missed='gisel*' -verify-machineinstrs %s -o 
- 2>%t | FileCheck -check-prefix=GFX12 %s
 
 ---
 name: mad_u64_u32_vvv
@@ -18,6 +19,7 @@ body: |
 ; GFX10-NEXT: [[COPY2:%[0-9]+]]:vreg_64 = COPY $vgpr3
 ; GFX10-NEXT: [[V_MAD_U64_U32_e64_:%[0-9]+]]:vreg_64, 
[[V_MAD_U64_U32_e64_1:%[0-9]+]]:sreg_32_xm0_xexec = V_MAD_U64_U32_e64 [[COPY]], 
[[COPY1]], [[COPY2]], 0, implicit $exec
 ; GFX10-NEXT: S_ENDPGM 0, implicit [[V_MAD_U64_U32_e64_]], implicit 
[[V_MAD_U64_U32_e64_1]]
+;
 ; GFX11-LABEL: name: mad_u64_u32_vvv
 ; GFX11: liveins: $vgpr0, $vgpr1, $vgpr2, $vgpr3
 ; GFX11-NEXT: {{  $}}
@@ -26,6 +28,15 @@ body: |
 ; GFX11-NEXT: [[COPY2:%[0-9]+]]:vreg_64 = COPY $vgpr3
 ; GFX11-NEXT: [[V_MAD_U64_U32_gfx11_e64_:%[0-9]+]]:vreg_64, 
[[V_MAD_U64_U32_gfx11_e64_1:%[0-9]+]]:sreg_32_xm0_xexec = 
V_MAD_U64_U32_gfx11_e64 [[COPY]], [[COPY1]], [[COPY2]], 0, implicit $exec
 ; GFX11-NEXT: S_ENDPGM 0, implicit [[V_MAD_U64_U32_gfx11_e64_]], implicit 
[[V_MAD_U64_U32_gfx11_e64_1]]
+;
+; GFX12-LABEL: name: mad_u64_u32_vvv
+; GFX12: liveins: $vgpr0, $vgpr1, $vgpr2, $vgpr3
+; GFX12-NEXT: {{  $}}
+; GFX12-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY $vgpr0
+; GFX12-NEXT: [[COPY1:%[0-9]+]]:vgpr_32 = COPY $vgpr1
+; GFX12-NEXT: [[COPY2:%[0-9]+]]:vreg_64 = COPY $vgpr3
+; GFX12-NEXT: [[V_MAD_U64_U32_gfx11_e64_:%[0-9]+]]:vreg_64, 
[[V_MAD_U64_U32_gfx11_e64_1:%[0-9]+]]:sreg_32_xm0_xexec = 
V_MAD_U64_U32_gfx11_e64 [[COPY]], [[COPY1]], [[COPY2]], 0, implicit $exec
+; GFX12-NEXT: S_ENDPGM 0, implicit [[V_MAD_U64_U32_gfx11_e64_]], implicit 
[[V_MAD_U64_U32_gfx11_e64_1]]
 %0:vgpr(s32) = COPY $vgpr0
 %1:vgpr(s32) = COPY $vgpr1
 %2:vgpr(s32) = COPY $vgpr2
@@ -51,6 +62,7 @@ body: |
 ; GFX10-NEXT: [[COPY2:%[0-9]+]]:vreg_64 = COPY $vgpr3
 ; GFX10-NEXT: [[V_MAD_I64_I32_e64_:%[0-9]+]]:vreg_64, 
[[V_MAD_I64_I32_e64_1:%[0-9]+]]:sreg_32_xm0_xexec = V_MAD_I64_I32_e64 [[COPY]], 
[[COPY1]], [[COPY2]], 0, implicit $exec
 ; GFX10-NEXT: S_ENDPGM 0, implicit [[V_MAD_I64_I32_e64_]], implicit 
[[V_MAD_I64_I32_e64_1]]
+;
 ; GFX11-LABEL: name: mad_i64_i32_vvv
 ; GFX11: liveins: $vgpr0, $vgpr1, $vgpr2, $vgpr3
 ; GFX11-NEXT: {{  $}}
@@ -59,6 +71,15 @@ body: |
 ; GFX11-NEXT: [[COPY2:%[0-9]+]]:vreg_64 = COPY $vgpr3
 ; GFX11-NEXT: [[V_MAD_I64_I32_gfx11_e64_:%[0-9]+]]:vreg_64, 
[[V_MAD_I64_I32_gfx11_e64_1:%[0-9]+]]:sreg_32_xm0_xexec = 
V_MAD_I64_I32_gfx11_e64 [[COPY]], [[COPY1]], [[COPY2]], 0, implicit $exec
 ; GFX11-NEXT: S_ENDPGM 0, implicit [[V_MAD_I64_I32_gfx11_e64_]], implicit 
[[V_MAD_I64_I32_gfx11_e64_1]]
+;
+; GFX12-LABEL: name: mad_i64_i32_vvv
+; GFX12: liveins: $vgpr0, $vgpr1, $vgpr2, $vgpr3
+; GFX12-NEXT: {{  $}}
+; GFX12-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY $vgpr0
+; GFX12-NEXT: [[COPY1:%[0-9]+]]:vgpr_32 = COPY $vgpr1
+; GFX12-NEXT: [[COPY2:%[0-9]+]]:vreg_64 = COPY $vgpr3
+; GFX12-NEXT: [[V_MAD_I64_I32_gfx11_e64_:%[0-9]+]]:vreg_64, 
[[V_MAD_I64_I32_gfx11_e64_1:%[0-9]+]]:sreg_32_xm0_xexec = 
V_MAD_I64_I32_gfx11_e64 [[COPY]], [[COPY1]], [[COPY2]], 0, implicit $exec
+; GFX12-NEXT: S_ENDPGM 0, implicit [[V_MAD_I64_I32_gfx11_e64_]], implicit 
[[V_MAD_I64_I32_gfx11_e64_1]]
 %0:vgpr(s32) = COPY $vgpr0
 %1:vgpr(s32) = COPY $vgpr1
 %2:vgpr(s32) = COPY $vgpr2
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.mulo.ll 
b/llvm/test/CodeGen/AMDGPU/llvm.mulo.ll
index 249acec639540b..b9b03e52ec865c 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.mulo.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.mulo.ll
@@ -3,6 +3,7 @@
 ; RUN: llc -march=amdgcn -mcpu

[clang] [coroutines][coro_lifetimebound] Detect lifetime issues with lambda captures (PR #77066)

2024-01-17 Thread Utkarsh Saxena via cfe-commits


@@ -15845,8 +15845,10 @@ void Sema::CheckCoroutineWrapper(FunctionDecl *FD) {
   RecordDecl *RD = FD->getReturnType()->getAsRecordDecl();
   if (!RD || !RD->getUnderlyingDecl()->hasAttr())
 return;
-  // Allow `get_return_object()`.
-  if (FD->getDeclName().isIdentifier() &&
+  // Allow some_promise_type::get_return_object().
+  // Since we are still in the promise definition, we can only do this
+  // heuristically as the promise may not be yet associated to a coroutine.
+  if (isa(FD) && FD->getDeclName().isIdentifier() &&
   FD->getName().equals("get_return_object") && FD->param_empty())
 return;

usx95 wrote:

Thanks @ilya-biryukov for flagging the issue with Modules. Then I don't think 
it is wise to add these attributes. I will revert to the not-so-great heuristic 
of matching function names.

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


[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

2024-01-17 Thread via cfe-commits

https://github.com/kelbon updated 
https://github.com/llvm/llvm-project/pull/78200

>From b080d04eb30254502ccd5d59d76b5197db1fa88d Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Mon, 15 Jan 2024 22:24:34 +0400
Subject: [PATCH 1/6] add warning and test

---
 clang/include/clang/Basic/DiagnosticGroups.td| 1 +
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 7 +++
 clang/lib/Sema/SemaDecl.cpp  | 7 +++
 clang/test/Sema/incorrect_pure.cpp   | 7 +++
 4 files changed, 22 insertions(+)
 create mode 100644 clang/test/Sema/incorrect_pure.cpp

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c1..9fcf2be2e45458e 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -414,6 +414,7 @@ def : DiagGroup<"c++2a-compat", [CXX20Compat]>;
 def : DiagGroup<"c++2a-compat-pedantic", [CXX20CompatPedantic]>;
 
 def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
+def IncorrectAttributeUsage : DiagGroup<"incorrect-attribute-usage">;
 def FlexibleArrayExtensions : DiagGroup<"flexible-array-extensions">;
 def FourByteMultiChar : DiagGroup<"four-char-constants">;
 def GlobalConstructors : DiagGroup<"global-constructors"> {
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 414779a7970ab8e..0ad3ea64503d81e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -692,6 +692,13 @@ def warn_maybe_falloff_nonvoid_function : Warning<
 def warn_falloff_nonvoid_function : Warning<
   "non-void function does not return a value">,
   InGroup;
+def warn_pure_attr_on_cxx_constructor : Warning<
+  "constructor cannot be 'pure' (undefined behavior)">,
+  InGroup;
+def warn_pure_function_returns_void : Warning<
+  "'pure' attribute on function returning 'void'">,
+  InGroup;
+
 def err_maybe_falloff_nonvoid_block : Error<
   "non-void block does not return a value in all control paths">;
 def err_falloff_nonvoid_block : Error<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4e7049571eeb7a3..e340028703b3b31 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11889,6 +11889,13 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 NewFD->setInvalidDecl();
   }
 
+  if (NewFD->hasAttr() || NewFD->hasAttr()) {
+if (isa_and_nonnull(NewFD))
+  Diag(NewFD->getLocation(), diag::warn_pure_attr_on_cxx_constructor);
+else if (NewFD->getReturnType()->isVoidType())
+  Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void);
+  }
+
   // C++11 [dcl.constexpr]p8:
   //   A constexpr specifier for a non-static member function that is not
   //   a constructor declares that member function to be const.
diff --git a/clang/test/Sema/incorrect_pure.cpp 
b/clang/test/Sema/incorrect_pure.cpp
new file mode 100644
index 000..ce02309f0863863
--- /dev/null
+++ b/clang/test/Sema/incorrect_pure.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+[[gnu::pure]] void foo(); // expected-warning{{'pure' attribute on function 
returning 'void'}}
+
+struct A {
+[[gnu::pure]] A(); // expected-warning{{constructor cannot be 'pure' 
(undefined behavior)}}
+};

>From d43afccb027ea0e02c97ab9fbe55a1ad6c9d71dd Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Mon, 15 Jan 2024 22:52:23 +0400
Subject: [PATCH 2/6] use precondition: NewFD is not null

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

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e340028703b3b31..dcbc5c3c842cca3 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11890,7 +11890,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   }
 
   if (NewFD->hasAttr() || NewFD->hasAttr()) {
-if (isa_and_nonnull(NewFD))
+if (isa(NewFD))
   Diag(NewFD->getLocation(), diag::warn_pure_attr_on_cxx_constructor);
 else if (NewFD->getReturnType()->isVoidType())
   Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void);

>From 950ca9de1c05d561a1123c088455a3e21bd9795b Mon Sep 17 00:00:00 2001
From: Kelbon Nik 
Date: Tue, 16 Jan 2024 00:03:47 +0400
Subject: [PATCH 3/6] fix old incorrect test

---
 clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp 
b/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp
index 9d68a0e5d358f67..6ae146f0d08c7d3 100644
--- a/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp
+++ b/clang/test/SemaCXX/cxx0x-cursory-default-delete.cpp
@@ -194,7 +194,7 @@ struct except_spec_d_match : except_spec_a, except_spec_b {
 // gcc-compatibility: allow attributes on default definitions
 // (but not normal defini

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

2024-01-17 Thread Krystian Stasiowski via cfe-commits

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

>From 4ac6eb855fc302214a0cd0bcd15af351981eaf02 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Tue, 16 Jan 2024 08:05:33 -0500
Subject: [PATCH] [Clang][Sema] Diagnose function/variable templates that
 shadow their own template parameters

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/lib/Sema/SemaDecl.cpp   | 12 +--
 .../test/CXX/temp/temp.res/temp.local/p6.cpp  | 20 ---
 3 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e45e016b3d66bd1..a17eb7feed5d76a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -568,6 +568,7 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses the requirement that non-template friend declarations 
with requires clauses
   and template friend declarations with a constraint that depends on a 
template parameter from an
   enclosing template must be a definition.
+- Clang now diagnoses function/variable templates that shadow their own 
template parameters, e.g. ``template void T();``.
 
 
 Improvements to Clang's time-trace
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index bd38298a1481faa..6fb465d8f6aef8d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6377,12 +6377,6 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator 
&D,
   } else if (DiagnoseUnexpandedParameterPack(NameInfo, UPPC_DeclarationType))
 return nullptr;
 
-  // The scope passed in may not be a decl scope.  Zip up the scope tree until
-  // we find one that is.
-  while ((S->getFlags() & Scope::DeclScope) == 0 ||
- (S->getFlags() & Scope::TemplateParamScope) != 0)
-S = S->getParent();
-
   DeclContext *DC = CurContext;
   if (D.getCXXScopeSpec().isInvalid())
 D.setInvalidType();
@@ -6535,6 +6529,12 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator 
&D,
   if (getLangOpts().CPlusPlus)
 CheckExtraCXXDefaultArguments(D);
 
+  // The scope passed in may not be a decl scope.  Zip up the scope tree until
+  // we find one that is.
+  while ((S->getFlags() & Scope::DeclScope) == 0 ||
+ (S->getFlags() & Scope::TemplateParamScope) != 0)
+S = S->getParent();
+
   NamedDecl *New;
 
   bool AddToScope = true;
diff --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index e2aa0ff344291d2..0702966e5685480 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -127,16 +127,30 @@ template struct Z { // expected-note 16{{declared 
here}}
 template // expected-note {{declared here}}
 void f(int T) {} // expected-error {{declaration of 'T' shadows template 
parameter}}
 
-// FIXME: These are ill-formed: a template-parameter shall not have the same 
name as the template name.
 namespace A {
   template struct T {};  // expected-error{{declaration of 'T' 
shadows template parameter}}
  // expected-note@-1{{template parameter 
is declared here}}
+  template struct U {
+template struct V {}; // expected-error{{declaration of 'V' 
shadows template parameter}}
+  // expected-note@-1{{template parameter 
is declared here}}
+  };
 }
 namespace B {
-  template void T() {}
+  template void T() {} // expected-error{{declaration of 'T' 
shadows template parameter}}
+   // expected-note@-1{{template parameter is 
declared here}}
+
+  template struct U {
+template void V(); // expected-error{{declaration of 'V' 
shadows template parameter}}
+   // expected-note@-1{{template parameter is 
declared here}}
+  };
 }
 namespace C {
-  template int T;
+  template int T; // expected-error{{declaration of 'T' shadows 
template parameter}}
+  // expected-note@-1{{template parameter is 
declared here}}
+  template struct U {
+template static int V; // expected-error{{declaration of 'V' 
shadows template parameter}}
+   // expected-note@-1{{template parameter 
is declared here}}
+  };
 }
 
 namespace PR28023 {

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


[clang] [Clang] NFC: Move Arm type attributes to separate trailing object. (PR #78424)

2024-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sander de Smalen (sdesmalen-arm)


Changes

This decouples the Arm type attributes from other bits, which means
the data will only be allocated when a function uses these Arm
attributes.

The first patch adds the bit `HasArmTypeAttributes` to
`FunctionTypeBitfields`, which grows from 62 bits to 63 bits.

In the second patch, I've moved this bit (`HasArmTypeAttributes`) to
`FunctionTypeExtraBitfields`, because it looks like the bits in
`FunctionTypeBitfields` are precious and we really don't want that struct
to grow beyond 64 bits.

I've split this out into two patches to explain the rationale, but those
can be squashed before merging.


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


3 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+43-16) 
- (modified) clang/lib/AST/ASTContext.cpp (+4-3) 
- (modified) clang/lib/AST/Type.cpp (+10-2) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a7efe78591635e..259e920acf9ff3 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4029,6 +4029,22 @@ class FunctionType : public Type {
   /// because TrailingObjects cannot handle repeated types.
   struct ExceptionType { QualType Type; };
 
+  /// A simple holder for various uncommon bits which do not fit in
+  /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
+  /// alignment of subsequent objects in TrailingObjects.
+  struct alignas(void *) FunctionTypeExtraBitfields {
+/// The number of types in the exception specification.
+/// A whole unsigned is not needed here and according to
+/// [implimits] 8 bits would be enough here.
+unsigned NumExceptionType : 10;
+
+LLVM_PREFERRED_TYPE(bool)
+unsigned HasArmTypeAttributes : 1;
+
+FunctionTypeExtraBitfields()
+: NumExceptionType(0), HasArmTypeAttributes(false) {}
+  };
+
   /// The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number
   /// of function type attributes that can be set on function types, including
   /// function pointers.
@@ -4042,7 +4058,8 @@ class FunctionType : public Type {
 SME_ZAMask = 0b111 << SME_ZAShift,
 
 SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeExtraBitfields.
+  // the bitmask in FunctionTypeArmAttributes
+  // and ExtProtoInfo.
   };
 
   enum ArmStateValue : unsigned {
@@ -4057,20 +4074,15 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
-  /// A simple holder for various uncommon bits which do not fit in
-  /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
-  /// alignment of subsequent objects in TrailingObjects.
-  struct alignas(void *) FunctionTypeExtraBitfields {
-/// The number of types in the exception specification.
-/// A whole unsigned is not needed here and according to
-/// [implimits] 8 bits would be enough here.
-unsigned NumExceptionType : 10;
-
+  /// A holder for Arm type attributes as described in the Arm C/C++
+  /// Language extensions which are not particularly common to all
+  /// types and therefore accounted separately from FunctionTypeBitfields.
+  struct alignas(void *) FunctionTypeArmAttributes {
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
 unsigned AArch64SMEAttributes : 6;
-FunctionTypeExtraBitfields()
-: NumExceptionType(0), AArch64SMEAttributes(SME_NormalFunction) {}
+
+FunctionTypeArmAttributes() : AArch64SMEAttributes(SME_NormalFunction) {}
   };
 
 protected:
@@ -4169,7 +4181,8 @@ class FunctionProtoType final
   public llvm::FoldingSetNode,
   private llvm::TrailingObjects<
   FunctionProtoType, QualType, SourceLocation,
-  FunctionType::FunctionTypeExtraBitfields, 
FunctionType::ExceptionType,
+  FunctionType::FunctionTypeExtraBitfields,
+  FunctionType::FunctionTypeArmAttributes, FunctionType::ExceptionType,
   Expr *, FunctionDecl *, FunctionType::ExtParameterInfo, Qualifiers> {
   friend class ASTContext; // ASTContext creates these.
   friend TrailingObjects;
@@ -4276,7 +4289,11 @@ class FunctionProtoType final
 
 bool requiresFunctionProtoTypeExtraBitfields() const {
   return ExceptionSpec.Type == EST_Dynamic ||
- AArch64SMEAttributes != SME_NormalFunction;
+ requiresFunctionProtoTypeArmAttributes();
+}
+
+bool requiresFunctionProtoTypeArmAttributes() const {
+  return AArch64SMEAttributes != SME_NormalFunction;
 }
 
 void setArmSMEAttribute(AArch64SMETypeAttributes Kind, bool Enable = true) 
{
@@ -4296,6 +4313,10 @@ class FunctionProtoType final
 return isVariadic();
   }
 
+  unsigned numTrailingObj

[clang] [Clang] NFC: Move Arm type attributes to separate trailing object. (PR #78424)

2024-01-17 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm created 
https://github.com/llvm/llvm-project/pull/78424

This decouples the Arm type attributes from other bits, which means
the data will only be allocated when a function uses these Arm
attributes.

The first patch adds the bit `HasArmTypeAttributes` to
`FunctionTypeBitfields`, which grows from 62 bits to 63 bits.

In the second patch, I've moved this bit (`HasArmTypeAttributes`) to
`FunctionTypeExtraBitfields`, because it looks like the bits in
`FunctionTypeBitfields` are precious and we really don't want that struct
to grow beyond 64 bits.

I've split this out into two patches to explain the rationale, but those
can be squashed before merging.


>From 00748e8fe0a58ec350053487179c15cb988ad9f7 Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Wed, 17 Jan 2024 09:27:21 +
Subject: [PATCH 1/2] [Clang] NFC: Move Arm type attributes to separate
 trailing object.

This decouples the Arm type attributes from other bits, which means
the data will only be allocated when a function uses these Arm
attributes.

The first patch adds the bit `HasArmTypeAttributes` to
`FunctionTypeBitfields`, which grows from 62 bits to 63 bits.

In the second patch, I've moved this bit (`HasArmTypeAttributes`) to
`FunctionTypeExtraBitfields`, because it looks like the bits in
`FunctionTypeBitfields` are precious and we really don't want that struct
to grow beyond 64 bits.

I've split this out into two patches to explain the rationale, but those
can be squashed before merging.
---
 clang/include/clang/AST/Type.h | 58 --
 clang/lib/AST/ASTContext.cpp   |  7 ++--
 clang/lib/AST/Type.cpp | 12 +--
 3 files changed, 55 insertions(+), 22 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a7efe78591635e..63624a7ff1c554 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1754,6 +1754,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 LLVM_PREFERRED_TYPE(bool)
 unsigned HasExtraBitfields : 1;
 
+/// Whether this function has a trailing object for Arm type attributes.
+LLVM_PREFERRED_TYPE(bool)
+unsigned HasArmTypeAttributes : 1;
+
 /// Whether the function is variadic.
 LLVM_PREFERRED_TYPE(bool)
 unsigned Variadic : 1;
@@ -4029,6 +4033,18 @@ class FunctionType : public Type {
   /// because TrailingObjects cannot handle repeated types.
   struct ExceptionType { QualType Type; };
 
+  /// A simple holder for various uncommon bits which do not fit in
+  /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
+  /// alignment of subsequent objects in TrailingObjects.
+  struct alignas(void *) FunctionTypeExtraBitfields {
+/// The number of types in the exception specification.
+/// A whole unsigned is not needed here and according to
+/// [implimits] 8 bits would be enough here.
+unsigned NumExceptionType : 10;
+
+FunctionTypeExtraBitfields() : NumExceptionType(0) {}
+  };
+
   /// The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number
   /// of function type attributes that can be set on function types, including
   /// function pointers.
@@ -4042,7 +4058,8 @@ class FunctionType : public Type {
 SME_ZAMask = 0b111 << SME_ZAShift,
 
 SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeExtraBitfields.
+  // the bitmask in FunctionTypeArmAttributes
+  // and ExtProtoInfo.
   };
 
   enum ArmStateValue : unsigned {
@@ -4057,20 +4074,15 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
-  /// A simple holder for various uncommon bits which do not fit in
-  /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
-  /// alignment of subsequent objects in TrailingObjects.
-  struct alignas(void *) FunctionTypeExtraBitfields {
-/// The number of types in the exception specification.
-/// A whole unsigned is not needed here and according to
-/// [implimits] 8 bits would be enough here.
-unsigned NumExceptionType : 10;
-
+  /// A holder for Arm type attributes as described in the Arm C/C++
+  /// Language extensions which are not particularly common to all
+  /// types and therefore accounted separately from FunctionTypeBitfields.
+  struct alignas(void *) FunctionTypeArmAttributes {
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
 unsigned AArch64SMEAttributes : 6;
-FunctionTypeExtraBitfields()
-: NumExceptionType(0), AArch64SMEAttributes(SME_NormalFunction) {}
+
+FunctionTypeArmAttributes() : AArch64SMEAttributes(SME_NormalFunction) {}
   };
 
 protected:
@@ -4169,7 +4181,8 @@ class FunctionProtoType final
   public llvm::FoldingSetNode,
  

[clang] [Clang][Sema][NFC] Remove unused Scope* parameter from Sema::GetTypeForDeclarator and Sema::ActOnTypeName (PR #78325)

2024-01-17 Thread Krystian Stasiowski via cfe-commits

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


[clang] 68ae1e4 - [Clang][Sema][NFC] Remove unused Scope* parameter from Sema::GetTypeForDeclarator and Sema::ActOnTypeName (#78325)

2024-01-17 Thread via cfe-commits

Author: Krystian Stasiowski
Date: 2024-01-17T05:47:57-05:00
New Revision: 68ae1e49d24ce186331866ddae71063f4b8056e2

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

LOG: [Clang][Sema][NFC] Remove unused Scope* parameter from 
Sema::GetTypeForDeclarator and Sema::ActOnTypeName (#78325)

Split from #78274

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Parse/ParseObjc.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaObjCProperty.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4ef1fe542ea54f..92a6f218a0d0fe 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2153,7 +2153,7 @@ class Sema final {
  SourceLocation Loc);
   QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation 
Loc);
 
-  TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
+  TypeSourceInfo *GetTypeForDeclarator(Declarator &D);
   TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
 
   /// Package the given type and TSI into a ParsedType.
@@ -2194,7 +2194,7 @@ class Sema final {
   SourceLocation TargetLoc, const FunctionProtoType *Source,
   bool SkipSourceFirstParameter, SourceLocation SourceLoc);
 
-  TypeResult ActOnTypeName(Scope *S, Declarator &D);
+  TypeResult ActOnTypeName(Declarator &D);
 
   /// The parser has parsed the context-sensitive type 'instancetype'
   /// in an Objective-C message declaration. Return the appropriate type.

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 8d856cc2cf8313..a106ce14c71f77 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -79,7 +79,7 @@ TypeResult Parser::ParseTypeName(SourceRange *Range, 
DeclaratorContext Context,
   if (DeclaratorInfo.isInvalidType())
 return true;
 
-  return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
+  return Actions.ActOnTypeName(DeclaratorInfo);
 }
 
 /// Normalizes an attribute name by dropping prefixed and suffixed __.
@@ -5011,7 +5011,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, 
DeclSpec &DS,
   DeclSpecContext::DSC_type_specifier);
   Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
 DeclaratorContext::TypeName);
-  BaseType = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
+  BaseType = Actions.ActOnTypeName(DeclaratorInfo);
 
   BaseRange = SourceRange(ColonLoc, 
DeclaratorInfo.getSourceRange().getEnd());
 

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 5576be9e717a9b..c0d771dc93daee 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1290,7 +1290,7 @@ TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation 
&BaseLoc,
 
 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
   DeclaratorContext::TypeName);
-return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
+return Actions.ActOnTypeName(DeclaratorInfo);
   }
 
   // Check whether we have a template-id that names a type.
@@ -1385,7 +1385,7 @@ TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation 
&BaseLoc,
 
   Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
 DeclaratorContext::TypeName);
-  return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
+  return Actions.ActOnTypeName(DeclaratorInfo);
 }
 
 void Parser::ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs) 
{

diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index dcfd290d39cc48..e862856a08ca11 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1243,8 +1243,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
 
 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
   DeclaratorContext::TypeName);
-TypeResult Ty = Actions.ActOnTypeName(getCurScope(),
-  DeclaratorInfo);
+TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
 if (Ty.isInvalid())
   break;
 
@@ -1538,7 +1537,7 @@ ExprResult Parser::ParseCastExpres

[llvm] [clang] [clang-tools-extra] [AMDGPU] Disable V_MAD_U64_U32/V_MAD_I64_I32 workaround for GFX12 (PR #77927)

2024-01-17 Thread Jay Foad via cfe-commits

https://github.com/jayfoad updated 
https://github.com/llvm/llvm-project/pull/77927

>From 3f3bcdb89adf032e26c95807abf5e3b23ff50e4a Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Fri, 12 Jan 2024 12:24:28 +
Subject: [PATCH 1/2] Precommit extra GFX12 test coverage

---
 .../GlobalISel/inst-select-mad_64_32.mir  |  21 ++
 llvm/test/CodeGen/AMDGPU/llvm.mulo.ll | 163 ++
 llvm/test/CodeGen/AMDGPU/mad_64_32.ll | 211 ++
 3 files changed, 395 insertions(+)

diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-mad_64_32.mir 
b/llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-mad_64_32.mir
index 698281caca245e9..6e33ef37397d6b4 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-mad_64_32.mir
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-mad_64_32.mir
@@ -1,6 +1,7 @@
 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
 # RUN: llc -march=amdgcn -mcpu=gfx1030 -run-pass=instruction-select 
-global-isel-abort=2 -pass-remarks-missed='gisel*' -verify-machineinstrs %s -o 
- 2>%t | FileCheck -check-prefix=GFX10 %s
 # RUN: llc -march=amdgcn -mcpu=gfx1100 -run-pass=instruction-select 
-global-isel-abort=2 -pass-remarks-missed='gisel*' -verify-machineinstrs %s -o 
- 2>%t | FileCheck -check-prefix=GFX11 %s
+# RUN: llc -march=amdgcn -mcpu=gfx1200 -run-pass=instruction-select 
-global-isel-abort=2 -pass-remarks-missed='gisel*' -verify-machineinstrs %s -o 
- 2>%t | FileCheck -check-prefix=GFX12 %s
 
 ---
 name: mad_u64_u32_vvv
@@ -18,6 +19,7 @@ body: |
 ; GFX10-NEXT: [[COPY2:%[0-9]+]]:vreg_64 = COPY $vgpr3
 ; GFX10-NEXT: [[V_MAD_U64_U32_e64_:%[0-9]+]]:vreg_64, 
[[V_MAD_U64_U32_e64_1:%[0-9]+]]:sreg_32_xm0_xexec = V_MAD_U64_U32_e64 [[COPY]], 
[[COPY1]], [[COPY2]], 0, implicit $exec
 ; GFX10-NEXT: S_ENDPGM 0, implicit [[V_MAD_U64_U32_e64_]], implicit 
[[V_MAD_U64_U32_e64_1]]
+;
 ; GFX11-LABEL: name: mad_u64_u32_vvv
 ; GFX11: liveins: $vgpr0, $vgpr1, $vgpr2, $vgpr3
 ; GFX11-NEXT: {{  $}}
@@ -26,6 +28,15 @@ body: |
 ; GFX11-NEXT: [[COPY2:%[0-9]+]]:vreg_64 = COPY $vgpr3
 ; GFX11-NEXT: [[V_MAD_U64_U32_gfx11_e64_:%[0-9]+]]:vreg_64, 
[[V_MAD_U64_U32_gfx11_e64_1:%[0-9]+]]:sreg_32_xm0_xexec = 
V_MAD_U64_U32_gfx11_e64 [[COPY]], [[COPY1]], [[COPY2]], 0, implicit $exec
 ; GFX11-NEXT: S_ENDPGM 0, implicit [[V_MAD_U64_U32_gfx11_e64_]], implicit 
[[V_MAD_U64_U32_gfx11_e64_1]]
+;
+; GFX12-LABEL: name: mad_u64_u32_vvv
+; GFX12: liveins: $vgpr0, $vgpr1, $vgpr2, $vgpr3
+; GFX12-NEXT: {{  $}}
+; GFX12-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY $vgpr0
+; GFX12-NEXT: [[COPY1:%[0-9]+]]:vgpr_32 = COPY $vgpr1
+; GFX12-NEXT: [[COPY2:%[0-9]+]]:vreg_64 = COPY $vgpr3
+; GFX12-NEXT: [[V_MAD_U64_U32_gfx11_e64_:%[0-9]+]]:vreg_64, 
[[V_MAD_U64_U32_gfx11_e64_1:%[0-9]+]]:sreg_32_xm0_xexec = 
V_MAD_U64_U32_gfx11_e64 [[COPY]], [[COPY1]], [[COPY2]], 0, implicit $exec
+; GFX12-NEXT: S_ENDPGM 0, implicit [[V_MAD_U64_U32_gfx11_e64_]], implicit 
[[V_MAD_U64_U32_gfx11_e64_1]]
 %0:vgpr(s32) = COPY $vgpr0
 %1:vgpr(s32) = COPY $vgpr1
 %2:vgpr(s32) = COPY $vgpr2
@@ -51,6 +62,7 @@ body: |
 ; GFX10-NEXT: [[COPY2:%[0-9]+]]:vreg_64 = COPY $vgpr3
 ; GFX10-NEXT: [[V_MAD_I64_I32_e64_:%[0-9]+]]:vreg_64, 
[[V_MAD_I64_I32_e64_1:%[0-9]+]]:sreg_32_xm0_xexec = V_MAD_I64_I32_e64 [[COPY]], 
[[COPY1]], [[COPY2]], 0, implicit $exec
 ; GFX10-NEXT: S_ENDPGM 0, implicit [[V_MAD_I64_I32_e64_]], implicit 
[[V_MAD_I64_I32_e64_1]]
+;
 ; GFX11-LABEL: name: mad_i64_i32_vvv
 ; GFX11: liveins: $vgpr0, $vgpr1, $vgpr2, $vgpr3
 ; GFX11-NEXT: {{  $}}
@@ -59,6 +71,15 @@ body: |
 ; GFX11-NEXT: [[COPY2:%[0-9]+]]:vreg_64 = COPY $vgpr3
 ; GFX11-NEXT: [[V_MAD_I64_I32_gfx11_e64_:%[0-9]+]]:vreg_64, 
[[V_MAD_I64_I32_gfx11_e64_1:%[0-9]+]]:sreg_32_xm0_xexec = 
V_MAD_I64_I32_gfx11_e64 [[COPY]], [[COPY1]], [[COPY2]], 0, implicit $exec
 ; GFX11-NEXT: S_ENDPGM 0, implicit [[V_MAD_I64_I32_gfx11_e64_]], implicit 
[[V_MAD_I64_I32_gfx11_e64_1]]
+;
+; GFX12-LABEL: name: mad_i64_i32_vvv
+; GFX12: liveins: $vgpr0, $vgpr1, $vgpr2, $vgpr3
+; GFX12-NEXT: {{  $}}
+; GFX12-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY $vgpr0
+; GFX12-NEXT: [[COPY1:%[0-9]+]]:vgpr_32 = COPY $vgpr1
+; GFX12-NEXT: [[COPY2:%[0-9]+]]:vreg_64 = COPY $vgpr3
+; GFX12-NEXT: [[V_MAD_I64_I32_gfx11_e64_:%[0-9]+]]:vreg_64, 
[[V_MAD_I64_I32_gfx11_e64_1:%[0-9]+]]:sreg_32_xm0_xexec = 
V_MAD_I64_I32_gfx11_e64 [[COPY]], [[COPY1]], [[COPY2]], 0, implicit $exec
+; GFX12-NEXT: S_ENDPGM 0, implicit [[V_MAD_I64_I32_gfx11_e64_]], implicit 
[[V_MAD_I64_I32_gfx11_e64_1]]
 %0:vgpr(s32) = COPY $vgpr0
 %1:vgpr(s32) = COPY $vgpr1
 %2:vgpr(s32) = COPY $vgpr2
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.mulo.ll 
b/llvm/test/CodeGen/AMDGPU/llvm.mulo.ll
index 249acec639540b3..b9b03e52ec865c0 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.mulo.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.mulo.ll
@@ -3,6 +3,7 @@
 ; RUN: llc -march=amdgcn -

[clang] [Clang][Sema][NFC] Remove unused Scope* parameter from Sema::GetTypeForDeclarator and Sema::ActOnTypeName (PR #78325)

2024-01-17 Thread Krystian Stasiowski via cfe-commits

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

>From a35415e1282fa988c4e5b0d27704b63a6f20a7c5 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Tue, 16 Jan 2024 06:28:35 -0500
Subject: [PATCH] [Clang][Sema][NFC] Remove unused Scope* parameter from
 Sema::GetTypeForDeclarator and Sema::ActOnTypeName

---
 clang/include/clang/Sema/Sema.h |  4 ++--
 clang/lib/Parse/ParseDecl.cpp   |  4 ++--
 clang/lib/Parse/ParseDeclCXX.cpp|  4 ++--
 clang/lib/Parse/ParseExpr.cpp   | 13 ++---
 clang/lib/Parse/ParseExprCXX.cpp|  9 -
 clang/lib/Parse/ParseObjc.cpp   |  6 +++---
 clang/lib/Sema/SemaDecl.cpp | 12 ++--
 clang/lib/Sema/SemaDeclCXX.cpp  | 10 +-
 clang/lib/Sema/SemaDeclObjC.cpp |  4 ++--
 clang/lib/Sema/SemaExpr.cpp |  2 +-
 clang/lib/Sema/SemaExprCXX.cpp  |  2 +-
 clang/lib/Sema/SemaLambda.cpp   |  2 +-
 clang/lib/Sema/SemaObjCProperty.cpp |  2 +-
 clang/lib/Sema/SemaOpenMP.cpp   |  4 ++--
 clang/lib/Sema/SemaTemplate.cpp |  4 ++--
 clang/lib/Sema/SemaType.cpp |  6 +++---
 16 files changed, 43 insertions(+), 45 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4ef1fe542ea54f..92a6f218a0d0fe 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2153,7 +2153,7 @@ class Sema final {
  SourceLocation Loc);
   QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation 
Loc);
 
-  TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
+  TypeSourceInfo *GetTypeForDeclarator(Declarator &D);
   TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
 
   /// Package the given type and TSI into a ParsedType.
@@ -2194,7 +2194,7 @@ class Sema final {
   SourceLocation TargetLoc, const FunctionProtoType *Source,
   bool SkipSourceFirstParameter, SourceLocation SourceLoc);
 
-  TypeResult ActOnTypeName(Scope *S, Declarator &D);
+  TypeResult ActOnTypeName(Declarator &D);
 
   /// The parser has parsed the context-sensitive type 'instancetype'
   /// in an Objective-C message declaration. Return the appropriate type.
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 8d856cc2cf8313..a106ce14c71f77 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -79,7 +79,7 @@ TypeResult Parser::ParseTypeName(SourceRange *Range, 
DeclaratorContext Context,
   if (DeclaratorInfo.isInvalidType())
 return true;
 
-  return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
+  return Actions.ActOnTypeName(DeclaratorInfo);
 }
 
 /// Normalizes an attribute name by dropping prefixed and suffixed __.
@@ -5011,7 +5011,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, 
DeclSpec &DS,
   DeclSpecContext::DSC_type_specifier);
   Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
 DeclaratorContext::TypeName);
-  BaseType = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
+  BaseType = Actions.ActOnTypeName(DeclaratorInfo);
 
   BaseRange = SourceRange(ColonLoc, 
DeclaratorInfo.getSourceRange().getEnd());
 
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 5576be9e717a9b..c0d771dc93daee 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1290,7 +1290,7 @@ TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation 
&BaseLoc,
 
 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
   DeclaratorContext::TypeName);
-return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
+return Actions.ActOnTypeName(DeclaratorInfo);
   }
 
   // Check whether we have a template-id that names a type.
@@ -1385,7 +1385,7 @@ TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation 
&BaseLoc,
 
   Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
 DeclaratorContext::TypeName);
-  return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
+  return Actions.ActOnTypeName(DeclaratorInfo);
 }
 
 void Parser::ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs) 
{
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index dcfd290d39cc48..e862856a08ca11 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1243,8 +1243,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
 
 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
   DeclaratorContext::TypeName);
-TypeResult Ty = Actions.ActOnTypeName(getCurScope(),
-  DeclaratorInfo);
+TypeResult Ty = Actions.ActOnTypeName(DeclaratorInfo);
 if (Ty.isInvalid())
   break;
 
@@ -1538

[clang] [clang][dataflow] Consider `CXXDefaultInitExpr` to be an "original record ctor". (PR #78423)

2024-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-analysis

Author: None (martinboehme)


Changes

The CFG doesn't contain a CFGElement for the `CXXDefaultInitExpr::getInit()`, so
it makes sense to consider the `CXXDefaultInitExpr` to be the expression that
originally constructs the object.


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


2 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+1) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+42) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index a50ee57a3c11b44..c3dfac24837c98b 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -747,6 +747,7 @@ static bool isOriginalRecordConstructor(const Expr 
&RecordPRValue) {
 return !Init->isSemanticForm() || !Init->isTransparent();
   return isa(RecordPRValue) || isa(RecordPRValue) 
||
  isa(RecordPRValue) ||
+ isa(RecordPRValue) ||
  // The framework currently does not propagate the objects created in
  // the two branches of a `ConditionalOperator` because there is no way
  // to reconcile their storage locations, which are different. We
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 056c4f3383d8322..d0a0e6d3f583641 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2684,6 +2684,48 @@ TEST(TransferTest, ResultObjectLocation) {
   });
 }
 
+TEST(TransferTest, ResultObjectLocationForDefaultInitExpr) {
+  std::string Code = R"(
+struct S {};
+struct target {
+  target () {
+(void)0;
+// [[p]]
+  }
+  S s = {};
+};
+  )";
+
+  using ast_matchers::cxxCtorInitializer;
+  using ast_matchers::match;
+  using ast_matchers::selectFirst;
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *SField = findValueDecl(ASTCtx, "s");
+
+auto *CtorInit = selectFirst(
+"ctor_initializer",
+match(cxxCtorInitializer().bind("ctor_initializer"), ASTCtx));
+ASSERT_NE(CtorInit, nullptr);
+
+auto *DefaultInit = cast(CtorInit->getInit());
+
+RecordStorageLocation &Loc = Env.getResultObjectLocation(*DefaultInit);
+
+// FIXME: The result object location for the `CXXDefaultInitExpr` 
should
+// be the location of the member variable being initialized, but we
+// don't do this correctly yet; see also comments in
+// `builtinTransferInitializer()`.
+// For the time being, we just document the current erroneous behavior
+// here (this should be `EXPECT_EQ` when the behavior is fixed).
+EXPECT_NE(&Loc, 
Env.getThisPointeeStorageLocation()->getChild(*SField));
+  });
+}
+
 TEST(TransferTest, StaticCast) {
   std::string Code = R"(
 void target(int Foo) {

``




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


[clang] [clang][dataflow] Consider `CXXDefaultInitExpr` to be an "original record ctor". (PR #78423)

2024-01-17 Thread via cfe-commits

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

The CFG doesn't contain a CFGElement for the `CXXDefaultInitExpr::getInit()`, so
it makes sense to consider the `CXXDefaultInitExpr` to be the expression that
originally constructs the object.


>From 2a8a351c364848d27b38f4f25ac99e6ba1aee424 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Wed, 17 Jan 2024 10:31:19 +
Subject: [PATCH] [clang][dataflow] Consider `CXXDefaultInitExpr` to be an
 "original record ctor".

The CFG doesn't contain a CFGElement for the `CXXDefaultInitExpr::getInit()`, so
it makes sense to consider the `CXXDefaultInitExpr` to be the expression that
originally constructs the object.
---
 .../FlowSensitive/DataflowEnvironment.cpp |  1 +
 .../Analysis/FlowSensitive/TransferTest.cpp   | 42 +++
 2 files changed, 43 insertions(+)

diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index a50ee57a3c11b44..c3dfac24837c98b 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -747,6 +747,7 @@ static bool isOriginalRecordConstructor(const Expr 
&RecordPRValue) {
 return !Init->isSemanticForm() || !Init->isTransparent();
   return isa(RecordPRValue) || isa(RecordPRValue) 
||
  isa(RecordPRValue) ||
+ isa(RecordPRValue) ||
  // The framework currently does not propagate the objects created in
  // the two branches of a `ConditionalOperator` because there is no way
  // to reconcile their storage locations, which are different. We
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 056c4f3383d8322..d0a0e6d3f583641 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2684,6 +2684,48 @@ TEST(TransferTest, ResultObjectLocation) {
   });
 }
 
+TEST(TransferTest, ResultObjectLocationForDefaultInitExpr) {
+  std::string Code = R"(
+struct S {};
+struct target {
+  target () {
+(void)0;
+// [[p]]
+  }
+  S s = {};
+};
+  )";
+
+  using ast_matchers::cxxCtorInitializer;
+  using ast_matchers::match;
+  using ast_matchers::selectFirst;
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *SField = findValueDecl(ASTCtx, "s");
+
+auto *CtorInit = selectFirst(
+"ctor_initializer",
+match(cxxCtorInitializer().bind("ctor_initializer"), ASTCtx));
+ASSERT_NE(CtorInit, nullptr);
+
+auto *DefaultInit = cast(CtorInit->getInit());
+
+RecordStorageLocation &Loc = Env.getResultObjectLocation(*DefaultInit);
+
+// FIXME: The result object location for the `CXXDefaultInitExpr` 
should
+// be the location of the member variable being initialized, but we
+// don't do this correctly yet; see also comments in
+// `builtinTransferInitializer()`.
+// For the time being, we just document the current erroneous behavior
+// here (this should be `EXPECT_EQ` when the behavior is fixed).
+EXPECT_NE(&Loc, 
Env.getThisPointeeStorageLocation()->getChild(*SField));
+  });
+}
+
 TEST(TransferTest, StaticCast) {
   std::string Code = R"(
 void target(int Foo) {

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


[clang] [clang] Fix assertion failure with deleted overloaded unary operators (PR #78316)

2024-01-17 Thread Mariya Podchishchaeva via cfe-commits


@@ -598,3 +598,30 @@ namespace B {
 }
 void g(B::X x) { A::f(x); }
 }
+
+namespace GH78314 {
+
+class a {
+public:
+  void operator--() = delete; // expected-note {{candidate function has been 
explicitly deleted}} \
+  // expected-note {{candidate function not 
viable: requires 0 arguments, but 1 was provided}}
+  void operator--(int) = delete; // expected-note {{candidate function has 
been explicitly deleted}} \
+ // expected-note {{candidate function not 
viable: requires 1 argument, but 0 were provided}}
+};

Fznamznon wrote:

Sure, done.

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


[clang] [clang] Fix assertion failure with deleted overloaded unary operators (PR #78316)

2024-01-17 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/78316

>From cf33d7ce01aafe0fa29b8a38a9824a0b03d24f05 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 16 Jan 2024 09:16:10 -0800
Subject: [PATCH 1/2] [clang] Fix assertion failure with deleted overloaded
 unary operators

When emitting notes related to wrong number of arguments do not consider
implicit object argument.

Fixes https://github.com/llvm/llvm-project/issues/78314
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaOverload.cpp|  4 ++--
 clang/test/SemaCXX/overloaded-operator.cpp | 27 ++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6e31849ce16dd4..8382e5d55f6c6e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -750,6 +750,8 @@ Bug Fixes in This Version
   Fixes (`#77583 `_)
 - Fix an issue where CTAD fails for function-type/array-type arguments.
   Fixes (`#51710 `_)
+- Fixed assertion failure with deleted overloaded unary operators.
+  Fixes (`#78314 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 37c62b306b3cd3..83ab7cb0f3411b 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -14310,8 +14310,8 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, 
UnaryOperatorKind Opc,
 PartialDiagnosticAt(OpLoc, PDiag(diag::err_ovl_deleted_oper)
<< UnaryOperator::getOpcodeStr(Opc)
<< Input->getSourceRange()),
-*this, OCD_AllCandidates, ArgsArray, UnaryOperator::getOpcodeStr(Opc),
-OpLoc);
+*this, OCD_AllCandidates, ArgsArray.slice(1),
+UnaryOperator::getOpcodeStr(Opc), OpLoc);
 return ExprError();
   }
 
diff --git a/clang/test/SemaCXX/overloaded-operator.cpp 
b/clang/test/SemaCXX/overloaded-operator.cpp
index 83a7e65b43dd01..60332019f516cf 100644
--- a/clang/test/SemaCXX/overloaded-operator.cpp
+++ b/clang/test/SemaCXX/overloaded-operator.cpp
@@ -598,3 +598,30 @@ namespace B {
 }
 void g(B::X x) { A::f(x); }
 }
+
+namespace GH78314 {
+
+class a {
+public:
+  void operator--() = delete; // expected-note {{candidate function has been 
explicitly deleted}} \
+  // expected-note {{candidate function not 
viable: requires 0 arguments, but 1 was provided}}
+  void operator--(int) = delete; // expected-note {{candidate function has 
been explicitly deleted}} \
+ // expected-note {{candidate function not 
viable: requires 1 argument, but 0 were provided}}
+};
+
+void foo() {
+  a aa;
+  --aa; // expected-error {{overload resolution selected deleted operator 
'--'}}
+  aa--; // expected-error {{overload resolution selected deleted operator 
'--'}}
+}
+
+class b {
+  void operator++() = delete; // expected-note {{candidate function has been 
explicitly deleted}}
+  template  void operator++(int) { // expected-note {{function template 
not viable: requires 1 argument, but 0 were provided}}
+b bb;
+++bb; // expected-error {{overload resolution selected deleted operator 
'++'}}
+  }
+};
+
+
+}

>From 03daf97e74c05c1fa0c0c4b1637cbc76d3184404 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 17 Jan 2024 02:30:04 -0800
Subject: [PATCH 2/2] Add a test with explicit object parameter

---
 clang/test/SemaCXX/overloaded-operator.cpp | 30 ++
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/clang/test/SemaCXX/overloaded-operator.cpp 
b/clang/test/SemaCXX/overloaded-operator.cpp
index 60332019f516cf..887848c29b83c5 100644
--- a/clang/test/SemaCXX/overloaded-operator.cpp
+++ b/clang/test/SemaCXX/overloaded-operator.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx23 -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx23 -std=c++23 %s
+
 class X { };
 
 X operator+(X, X);
@@ -33,7 +35,9 @@ struct A {
 
 A make_A();
 
-bool operator==(A&, Z&); // expected-note 3{{candidate function}}
+bool operator==(A&, Z&); // expected-note 3{{candidate function}} \
+ // cxx23-note 2{{candidate function}}
+
 
 void h(A a, const A ac, Z z) {
   make_A() == z; // expected-warning{{equality comparison result unused}}
@@ -68,7 +72,9 @@ struct E2 {
 };
 
 // C++ [over.match.oper]p3 - enum restriction.
-float& operator==(E1, E2);  // expected-note{{candidate function}}
+float& operator==(E1, E2);  // expected-note{{candidate function}} \
+// cxx23-note{{candidate function}}
+
 
 void enum_test(Enum1 enum1, 

[clang] [-Wcompletion-handler] Fix a non-termination issue (PR #78380)

2024-01-17 Thread Valeriy Savchenko via cfe-commits

SavchenkoValeriy wrote:

Hey @ziqingluo-90, thank you for such a detailed description of the problem. It 
helped me to get up to speed quickly. 🙏 
However, I must say that I find this change too intrusive a this point, while 
not being 100% convinced that it is necessary.

Considering these rules (even be it for joining multiple paths), we shouldn't 
override `Reported` with `Escaped`. At the same time, we do that within a 
single block thanks to this code:
https://github.com/llvm/llvm-project/blob/5fcf907b34355980f77d7665a175b05fea7a6b7b/clang/lib/Analysis/CalledOnceCheck.cpp#L935
We do consider `Reported` to be an error state, and overwrite it. Maybe 
changing this logic and excluding `Reported` from that condition (i.e. 
`x.isErrorStatus() && x != Reported`) is the way to go? The reason for that is 
that we already found a problem on that path and the fact that it escaped 
before it shouldn't affect our conclusion. Another reason is more formal, 
`Reported` is supposed to be a top element of the lattice and this logic defies 
it.

Thanks again!

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


[compiler-rt] [lldb] [flang] [clang-tools-extra] [libc] [libcxxabi] [llvm] [clang] [libunwind] [libcxx] [ASan][AMDGPU] Fix Assertion Failure. (PR #78410)

2024-01-17 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,23 @@
+;RUN: opt < %s -passes=asan -S | FileCheck %s
+
+target datalayout = 
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
+target triple = "amdgcn-amd-amdhsa"
+
+@__const.__assert_fail.fmt = private unnamed_addr addrspace(4) constant [47 x 
i8] c"%s:%u: %s: Device-side assertion `%s' failed.\0A\00", align 16
+
+declare void @llvm.memcpy.p0.p4.i64(ptr noalias nocapture writeonly, ptr 
addrspace(4) noalias nocapture readonly, i64, i1 immarg) #1
+
+define weak hidden void @test_mem_intrinsic() sanitize_address #0 {
+; CHECK: define weak hidden void @test_mem_intrinsic() #1 {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[FMT:%.*]] = alloca [47 x i8], align 16, addrspace(5)
+; CHECK-NEXT: [[FADDRC:%.*]] = addrspacecast ptr addrspace(5) [[FMT]] to ptr
+; CHECK-NEXT: [[ITMP:%.*]] = call ptr @__asan_memcpy(ptr [[FADDRC]], ptr 
addrspacecast (ptr addrspace(4) @__const.__assert_fail.fmt to ptr), i64 47)
+; CHECK-NEXT: ret
+entry:
+%fmt = alloca [47 x i8], align 16, addrspace(5)
+%fmt.ascast = addrspacecast ptr addrspace(5) %fmt to ptr
+call void @llvm.memcpy.p0.p4.i64(ptr align 16 %fmt.ascast, ptr addrspace(4) 
align 16 @__const.__assert_fail.fmt, i64 47, i1 false)
+ret void
+}
+

arsenm wrote:

Also another test where both operands require the cast, as well as the integer 
cast.

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


[clang] [Clang] Support MSPropertyRefExpr as placement arg to new-expression (PR #75883)

2024-01-17 Thread via cfe-commits

Sirraide wrote:

Just did another rebase to update the release notes. 

Is there anything else that needs to be done for this pr?

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


[clang] [compiler-rt] [flang] [libc] [libcxxabi] [libcxx] [clang-tools-extra] [llvm] [lldb] [libunwind] [ASan][AMDGPU] Fix Assertion Failure. (PR #78410)

2024-01-17 Thread via cfe-commits

https://github.com/ampandey-1995 updated 
https://github.com/llvm/llvm-project/pull/78410

>From ed9754939ffb4d5ef405f80c20b6de6f5e3e1eed Mon Sep 17 00:00:00 2001
From: Amit Pandey 
Date: Mon, 11 Dec 2023 14:23:44 +0530
Subject: [PATCH] [ASan][AMDGPU] Fix Assertion Failure.

Assertion failure `(i >= FTy->getNumParams() || FTy->getParamType(i) ==
Args[i]->getType()) && "Calling a function with a bad signature!"'.  The
'llvm.memcpy' intercepted by ASan instrumentation pass is implemented by it's
own __asan_memcpy implementation. The second argument of llvm.memcpy accepts ptr
to addrspace(4), __asan_memcpy also has to follow ptr to addrspace(4)
convention.
---
 .../Instrumentation/AddressSanitizer.cpp  |  3 ++-
 .../AMDGPU/asan_instrument_mem_intrinsics.ll  | 23 +++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 
llvm/test/Instrumentation/AddressSanitizer/AMDGPU/asan_instrument_mem_intrinsics.ll

diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index fb5838bb7941ad..4d0be4715497a1 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1255,7 +1255,8 @@ void 
AddressSanitizer::instrumentMemIntrinsic(MemIntrinsic *MI) {
   InstrumentationIRBuilder IRB(MI);
   if (isa(MI)) {
 IRB.CreateCall(isa(MI) ? AsanMemmove : AsanMemcpy,
-   {MI->getOperand(0), MI->getOperand(1),
+   {MI->getOperand(0),
+IRB.CreateAddrSpaceCast(MI->getOperand(1), PtrTy),
 IRB.CreateIntCast(MI->getOperand(2), IntptrTy, false)});
   } else if (isa(MI)) {
 IRB.CreateCall(
diff --git 
a/llvm/test/Instrumentation/AddressSanitizer/AMDGPU/asan_instrument_mem_intrinsics.ll
 
b/llvm/test/Instrumentation/AddressSanitizer/AMDGPU/asan_instrument_mem_intrinsics.ll
new file mode 100644
index 00..bc905e24f40878
--- /dev/null
+++ 
b/llvm/test/Instrumentation/AddressSanitizer/AMDGPU/asan_instrument_mem_intrinsics.ll
@@ -0,0 +1,23 @@
+;RUN: opt < %s -passes=asan -S | FileCheck %s
+
+target datalayout = 
"e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
+target triple = "amdgcn-amd-amdhsa"
+
+@__const.__assert_fail.fmt = private unnamed_addr addrspace(4) constant [47 x 
i8] c"%s:%u: %s: Device-side assertion `%s' failed.\0A\00", align 16
+
+declare void @llvm.memcpy.p0.p4.i64(ptr noalias nocapture writeonly, ptr 
addrspace(4) noalias nocapture readonly, i64, i1 immarg) #1
+
+define weak hidden void @test_mem_intrinsic() sanitize_address #0 {
+; CHECK: define weak hidden void @test_mem_intrinsic() #1 {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[FMT:%.*]] = alloca [47 x i8], align 16, addrspace(5)
+; CHECK-NEXT: [[FADDRC:%.*]] = addrspacecast ptr addrspace(5) [[FMT]] to ptr
+; CHECK-NEXT: [[ITMP:%.*]] = call ptr @__asan_memcpy(ptr [[FADDRC]], ptr 
addrspacecast (ptr addrspace(4) @__const.__assert_fail.fmt to ptr), i64 47)
+; CHECK-NEXT: ret
+entry:
+%fmt = alloca [47 x i8], align 16, addrspace(5)
+%fmt.ascast = addrspacecast ptr addrspace(5) %fmt to ptr
+call void @llvm.memcpy.p0.p4.i64(ptr align 16 %fmt.ascast, ptr addrspace(4) 
align 16 @__const.__assert_fail.fmt, i64 47, i1 false)
+ret void
+}
+

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


[clang] [Clang] Support MSPropertyRefExpr as placement arg to new-expression (PR #75883)

2024-01-17 Thread via cfe-commits

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

>From 849b21f202f3c643c12f237920b137c3506996e7 Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Tue, 19 Dec 2023 02:48:25 +0100
Subject: [PATCH 1/6] [Clang] Support MSPropertyRefExpr as placement arg to
 new-expression

---
 clang/include/clang/Sema/Sema.h   |  4 ++
 clang/lib/Sema/SemaExpr.cpp   | 12 ++
 clang/lib/Sema/SemaExprCXX.cpp|  3 ++
 clang/test/CodeGenCXX/ms-property-new.cpp | 52 +++
 clang/test/SemaCXX/ms-property-new.cpp| 44 +++
 5 files changed, 107 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/ms-property-new.cpp
 create mode 100644 clang/test/SemaCXX/ms-property-new.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4ef1fe542ea54f0..aeb4075374022fa 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2108,6 +2108,10 @@ class Sema final {
 
   bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
 
+  /// Check an argument list for placeholders that we won't try to
+  /// handle later.
+  bool CheckArgsForPlaceholders(MultiExprArg args);
+
   /// Build a function type.
   ///
   /// This routine checks the function type according to C++ rules and
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 049fdae09bb185c..fcc227cf7a74f64 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5058,8 +5058,6 @@ static QualType getDependentArraySubscriptType(Expr *LHS, 
Expr *RHS,
   return Result->isDependentType() ? Result : Ctx.DependentTy;
 }
 
-static bool checkArgsForPlaceholders(Sema &S, MultiExprArg args);
-
 ExprResult Sema::ActOnArraySubscriptExpr(Scope *S, Expr *base,
  SourceLocation lbLoc,
  MultiExprArg ArgExprs,
@@ -5163,7 +5161,7 @@ ExprResult Sema::ActOnArraySubscriptExpr(Scope *S, Expr 
*base,
   return ExprError();
 ArgExprs[0] = result.get();
   } else {
-if (checkArgsForPlaceholders(*this, ArgExprs))
+if (CheckArgsForPlaceholders(ArgExprs))
   return ExprError();
   }
 
@@ -6912,15 +6910,13 @@ static bool isPlaceholderToRemoveAsArg(QualType type) {
   llvm_unreachable("bad builtin type kind");
 }
 
-/// Check an argument list for placeholders that we won't try to
-/// handle later.
-static bool checkArgsForPlaceholders(Sema &S, MultiExprArg args) {
+bool Sema::CheckArgsForPlaceholders(MultiExprArg args) {
   // Apply this processing to all the arguments at once instead of
   // dying at the first failure.
   bool hasInvalid = false;
   for (size_t i = 0, e = args.size(); i != e; i++) {
 if (isPlaceholderToRemoveAsArg(args[i]->getType())) {
-  ExprResult result = S.CheckPlaceholderExpr(args[i]);
+  ExprResult result = CheckPlaceholderExpr(args[i]);
   if (result.isInvalid()) hasInvalid = true;
   else args[i] = result.get();
 }
@@ -7194,7 +7190,7 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, 
SourceLocation LParenLoc,
   if (Result.isInvalid()) return ExprError();
   Fn = Result.get();
 
-  if (checkArgsForPlaceholders(*this, ArgExprs))
+  if (CheckArgsForPlaceholders(ArgExprs))
 return ExprError();
 
   if (getLangOpts().CPlusPlus) {
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4ae04358d5df7c8..0ca9e5b59e3c329 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2286,6 +2286,9 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
   bool PassAlignment = getLangOpts().AlignedAllocation &&
Alignment > NewAlignment;
 
+  if (CheckArgsForPlaceholders(PlacementArgs))
+return ExprError();
+
   AllocationFunctionScope Scope = UseGlobal ? AFS_Global : AFS_Both;
   if (!AllocType->isDependentType() &&
   !Expr::hasAnyTypeDependentArguments(PlacementArgs) &&
diff --git a/clang/test/CodeGenCXX/ms-property-new.cpp 
b/clang/test/CodeGenCXX/ms-property-new.cpp
new file mode 100644
index 000..e21ec3d6702f627
--- /dev/null
+++ b/clang/test/CodeGenCXX/ms-property-new.cpp
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -emit-llvm -triple=x86_64-pc-win32 -fms-compatibility %s -o 
- | FileCheck %s
+// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fms-compatibility -emit-pch -o %t 
%s
+// RUN: %clang_cc1 -emit-llvm -triple=x86_64-pc-win32 -fms-compatibility 
-include-pch %t -verify %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+struct S {
+  int GetX() { return 42; }
+  __declspec(property(get=GetX)) int x;
+
+  int GetY(int i, int j) { return i+j; }
+  __declspec(property(get=GetY)) int y[];
+
+  void* operator new(__SIZE_TYPE__, int);
+};
+
+template 
+struct TS {
+  T GetT() { return T(); }
+  __declspec(property(get=GetT)) T t;
+
+  T GetR(T i, T j) { return i+j; }
+  __declspec(property(get=GetR)) T 

[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78305)

2024-01-17 Thread Victor Campos via cfe-commits

vhscampos wrote:

Tagging @voltur01 for review

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


[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #66662)

2024-01-17 Thread Victor Campos via cfe-commits

vhscampos wrote:

I've addressed your comments, but I don't have permissions to edit this PR 
directly. Thus I've created a new pull request: 
https://github.com/llvm/llvm-project/pull/78305

Can you please have a look? Thanks

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


[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78305)

2024-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Victor Campos (vhscampos)


Changes



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


1 Files Affected:

- (modified) clang/lib/Headers/arm_acle.h (+38-32) 


``diff
diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index 9aae2285aeb1d8..9cd34948e3c535 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -4,6 +4,13 @@
  * See https://llvm.org/LICENSE.txt for license information.
  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  *
+ * The Arm C Language Extensions specifications can be found in the following
+ * link: https://github.com/ARM-software/acle/releases
+ *
+ * The ACLE section numbers are subject to change. When consulting the
+ * specifications, it is recommended to search using section titles if
+ * the section numbers look outdated.
+ *
  *===---===
  */
 
@@ -20,8 +27,8 @@
 extern "C" {
 #endif
 
-/* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
-/* 8.3 Memory barriers */
+/* 7 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
+/* 7.3 Memory barriers */
 #if !__has_builtin(__dmb)
 #define __dmb(i) __builtin_arm_dmb(i)
 #endif
@@ -32,7 +39,7 @@ extern "C" {
 #define __isb(i) __builtin_arm_isb(i)
 #endif
 
-/* 8.4 Hints */
+/* 7.4 Hints */
 
 #if !__has_builtin(__wfi)
 static __inline__ void __attribute__((__always_inline__, __nodebug__)) 
__wfi(void) {
@@ -68,7 +75,7 @@ static __inline__ void __attribute__((__always_inline__, 
__nodebug__)) __yield(v
 #define __dbg(t) __builtin_arm_dbg(t)
 #endif
 
-/* 8.5 Swap */
+/* 7.5 Swap */
 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
 __swp(uint32_t __x, volatile uint32_t *__p) {
   uint32_t v;
@@ -78,8 +85,8 @@ __swp(uint32_t __x, volatile uint32_t *__p) {
   return v;
 }
 
-/* 8.6 Memory prefetch intrinsics */
-/* 8.6.1 Data prefetch */
+/* 7.6 Memory prefetch intrinsics */
+/* 7.6.1 Data prefetch */
 #define __pld(addr) __pldx(0, 0, 0, addr)
 
 #if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
@@ -90,7 +97,7 @@ __swp(uint32_t __x, volatile uint32_t *__p) {
   __builtin_arm_prefetch(addr, access_kind, cache_level, retention_policy, 1)
 #endif
 
-/* 8.6.2 Instruction prefetch */
+/* 7.6.2 Instruction prefetch */
 #define __pli(addr) __plix(0, 0, addr)
 
 #if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
@@ -101,15 +108,15 @@ __swp(uint32_t __x, volatile uint32_t *__p) {
   __builtin_arm_prefetch(addr, 0, cache_level, retention_policy, 0)
 #endif
 
-/* 8.7 NOP */
+/* 7.7 NOP */
 #if !defined(_MSC_VER) || !defined(__aarch64__)
 static __inline__ void __attribute__((__always_inline__, __nodebug__)) 
__nop(void) {
   __builtin_arm_nop();
 }
 #endif
 
-/* 9 DATA-PROCESSING INTRINSICS */
-/* 9.2 Miscellaneous data-processing intrinsics */
+/* 8 DATA-PROCESSING INTRINSICS */
+/* 8.2 Miscellaneous data-processing intrinsics */
 /* ROR */
 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
 __ror(uint32_t __x, uint32_t __y) {
@@ -248,9 +255,7 @@ __rbitl(unsigned long __t) {
 #endif
 }
 
-/*
- * 9.3 16-bit multiplications
- */
+/* 8.3 16-bit multiplications */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__,__nodebug__))
 __smulbb(int32_t __a, int32_t __b) {
@@ -279,18 +284,18 @@ __smulwt(int32_t __a, int32_t __b) {
 #endif
 
 /*
- * 9.4 Saturating intrinsics
+ * 8.4 Saturating intrinsics
  *
  * FIXME: Change guard to their corresponding __ARM_FEATURE flag when Q flag
  * intrinsics are implemented and the flag is enabled.
  */
-/* 9.4.1 Width-specified saturation intrinsics */
+/* 8.4.1 Width-specified saturation intrinsics */
 #if defined(__ARM_FEATURE_SAT) && __ARM_FEATURE_SAT
 #define __ssat(x, y) __builtin_arm_ssat(x, y)
 #define __usat(x, y) __builtin_arm_usat(x, y)
 #endif
 
-/* 9.4.2 Saturating addition and subtraction intrinsics */
+/* 8.4.2 Saturating addition and subtraction intrinsics */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
 __qadd(int32_t __t, int32_t __v) {
@@ -308,7 +313,7 @@ __qdbl(int32_t __t) {
 }
 #endif
 
-/* 9.4.3 Accumultating multiplications */
+/* 8.4.3 Accumultating multiplications */
 #if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
 __smlabb(int32_t __a, int32_t __b, int32_t __c) {
@@ -337,13 +342,13 @@ __smlawt(int32_t __a, int32_t __b, int32_t __c) {
 #endif
 
 
-/* 9.5.4 Parallel 16-bit saturation */
+/* 8.5.4 Parallel 16-bit saturation */
 #if defined(__ARM_FEATURE_SIMD32) && __ARM_FEATURE_SIMD32
 #define __ssat16(x, y) __builtin_arm_ssat16(x, y)
 #define __usat16(x, y) __builtin_arm_usat16(x, y)
 #endif
 
-/* 9.5.5 Packing and unpacking */
+/* 8.5.5 Packing and unpacking */
 #if defined(__ARM_FEATURE_SIMD32) && __ARM_FEATURE_SI

[clang] [NFC][Clang][Headers] Update refs to ACLE in comments (PR #78305)

2024-01-17 Thread Victor Campos via cfe-commits

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


[clang] [clang] Fix assertion failure with deleted overloaded unary operators (PR #78316)

2024-01-17 Thread Mariya Podchishchaeva via cfe-commits


@@ -14310,8 +14310,8 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, 
UnaryOperatorKind Opc,
 PartialDiagnosticAt(OpLoc, PDiag(diag::err_ovl_deleted_oper)
<< UnaryOperator::getOpcodeStr(Opc)
<< Input->getSourceRange()),
-*this, OCD_AllCandidates, ArgsArray, UnaryOperator::getOpcodeStr(Opc),
-OpLoc);
+*this, OCD_AllCandidates, ArgsArray.slice(1),

Fznamznon wrote:

The problem `ArgArray.slice(1)` solves is that `CreateOverloadedUnaryOp` fills 
first element `ArgsArray` with the object whose method was called. Later in 
`NoteCandidates` size of `ArgsArray` is passed further and it eventually ends 
up compared to number of function candidate parameters which never includes 
implicit object parameter.

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


[clang-tools-extra] [clang] [llvm] [PowerPC] Peephole address calculation in TOC memops (PR #76488)

2024-01-17 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises updated 
https://github.com/llvm/llvm-project/pull/76488

>From 7eb909423d49ea19d9978b097ceb8c4a95fc7bac Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Thu, 28 Dec 2023 11:09:07 +0800
Subject: [PATCH 1/5] [PowerPC] Peephole address calculation in TOC memops

---
 llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp   | 391 +-
 llvm/test/CodeGen/PowerPC/toc-data-const.ll   |  45 +-
 .../PowerPC/toc-data-peephole-aligment.ll |  16 +
 llvm/test/CodeGen/PowerPC/toc-data.ll |  22 +-
 4 files changed, 253 insertions(+), 221 deletions(-)
 create mode 100644 llvm/test/CodeGen/PowerPC/toc-data-peephole-aligment.ll

diff --git a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp 
b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
index b57d185bb638b8..c96bf3204a32ed 100644
--- a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
@@ -7567,224 +7567,233 @@ static void reduceVSXSwap(SDNode *N, SelectionDAG 
*DAG) {
   DAG->ReplaceAllUsesOfValueWith(SDValue(N, 0), N->getOperand(0));
 }
 
-void PPCDAGToDAGISel::PeepholePPC64() {
-  SelectionDAG::allnodes_iterator Position = CurDAG->allnodes_end();
-
-  while (Position != CurDAG->allnodes_begin()) {
-SDNode *N = &*--Position;
-// Skip dead nodes and any non-machine opcodes.
-if (N->use_empty() || !N->isMachineOpcode())
-  continue;
-
-if (isVSXSwap(SDValue(N, 0)))
-  reduceVSXSwap(N, CurDAG);
-
-unsigned FirstOp;
-unsigned StorageOpcode = N->getMachineOpcode();
-bool RequiresMod4Offset = false;
+static void peepholeMemOffset(SDNode *N, SelectionDAG *DAG,
+  const PPCSubtarget *Subtarget) {
+  unsigned StorageOpcode = N->getMachineOpcode();
+  bool IsLoad = false;
+  SDValue MemOffset, MemBase;
+  bool IsToc = false;
+
+  // TODO: Enable for AIX 32-bit
+  if (!Subtarget->isPPC64())
+return;
 
-switch (StorageOpcode) {
-default: continue;
+  // Global must be word-aligned for LD, STD, LWA.
+  unsigned ExtraAlign = 0;
+  switch (StorageOpcode) {
+  default:
+return;
+  case PPC::LWA:
+  case PPC::LD:
+  case PPC::DFLOADf64:
+  case PPC::DFLOADf32:
+ExtraAlign = 4;
+[[fallthrough]];
+  case PPC::LBZ:
+  case PPC::LBZ8:
+  case PPC::LFD:
+  case PPC::LFS:
+  case PPC::LHA:
+  case PPC::LHA8:
+  case PPC::LHZ:
+  case PPC::LHZ8:
+  case PPC::LWZ:
+  case PPC::LWZ8:
+IsLoad = true;
+MemOffset = N->getOperand(0);
+MemBase = N->getOperand(1);
+break;
+  case PPC::STD:
+  case PPC::DFSTOREf64:
+  case PPC::DFSTOREf32:
+ExtraAlign = 4;
+[[fallthrough]];
+  case PPC::STB:
+  case PPC::STB8:
+  case PPC::STFD:
+  case PPC::STFS:
+  case PPC::STH:
+  case PPC::STH8:
+  case PPC::STW:
+  case PPC::STW8:
+MemOffset = N->getOperand(1);
+MemBase = N->getOperand(2);
+break;
+  }
 
-case PPC::LWA:
-case PPC::LD:
-case PPC::DFLOADf64:
-case PPC::DFLOADf32:
-  RequiresMod4Offset = true;
-  [[fallthrough]];
-case PPC::LBZ:
-case PPC::LBZ8:
-case PPC::LFD:
-case PPC::LFS:
-case PPC::LHA:
-case PPC::LHA8:
-case PPC::LHZ:
-case PPC::LHZ8:
-case PPC::LWZ:
-case PPC::LWZ8:
-  FirstOp = 0;
-  break;
+  // Only constant offsets can be folded.
+  if (!isa(MemOffset) || !MemBase.isMachineOpcode())
+return;
 
-case PPC::STD:
-case PPC::DFSTOREf64:
-case PPC::DFSTOREf32:
-  RequiresMod4Offset = true;
-  [[fallthrough]];
-case PPC::STB:
-case PPC::STB8:
-case PPC::STFD:
-case PPC::STFS:
-case PPC::STH:
-case PPC::STH8:
-case PPC::STW:
-case PPC::STW8:
-  FirstOp = 1;
-  break;
+  auto CheckAlign = [DAG](const SDValue &Val, unsigned TargetAlign) {
+if (TargetAlign == 0)
+  return true;
+if (GlobalAddressSDNode *GA = dyn_cast(Val)) {
+  const GlobalValue *GV = GA->getGlobal();
+  Align Alignment = GV->getPointerAlignment(DAG->getDataLayout());
+  if (Alignment < TargetAlign)
+return false;
 }
+return true;
+  };
 
-// If this is a load or store with a zero offset, or within the alignment,
-// we may be able to fold an add-immediate into the memory operation.
-// The check against alignment is below, as it can't occur until we check
-// the arguments to N
-if (!isa(N->getOperand(FirstOp)))
-  continue;
-
-SDValue Base = N->getOperand(FirstOp + 1);
-if (!Base.isMachineOpcode())
-  continue;
+  // We may need to carry relocation information in ADDI to load.
+  std::optional NewOpFlags;
+  switch (MemBase.getMachineOpcode()) {
+  default:
+return;
+  case PPC::ADDI8:
+  case PPC::ADDI:
+// In some cases (such as TLS) the relocation information
+// is already in place on the operand, so copying the operand
+// is sufficient.
+break;
+  case PPC::ADDIdtprelL:
+NewOpFlags = PPCII::MO_DTPREL_LO;
+break;
+  case PPC::ADDItlsldL:
+NewOpFlags = PPCII::MO_TLSLD_LO;
+break;

[clang] [clang-tools-extra] [llvm] DAG: Fix ABI lowering with FP promote in strictfp functions (PR #74405)

2024-01-17 Thread Simon Pilgrim via cfe-commits

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

LGTM

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


[clang] [llvm] [AMDGPU] Add InstCombine rule for ballot.i64 intrinsic in wave32 mode. (PR #71556)

2024-01-17 Thread Matt Arsenault via cfe-commits

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


[clang] 57b50ef - [AMDGPU] Add InstCombine rule for ballot.i64 intrinsic in wave32 mode. (#71556)

2024-01-17 Thread via cfe-commits

Author: Valery Pykhtin
Date: 2024-01-17T17:02:05+07:00
New Revision: 57b50ef0174b6fdf7b554c4ae2691e2fa4f78f96

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

LOG: [AMDGPU] Add InstCombine rule for ballot.i64 intrinsic in wave32 mode. 
(#71556)

Substitute with zero-extended to i64 ballot.i32 intrinsic.

Added: 


Modified: 
clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
index 43553131f63c54..a0e27ce22fe7d9 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
@@ -24,13 +24,11 @@ void test_ballot_wave32_target_attr(global uint* out, int 
a, int b)
 }
 
 // CHECK-LABEL: @test_read_exec(
-// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
 void test_read_exec(global uint* out) {
   *out = __builtin_amdgcn_read_exec();
 }
 
-// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
-
 // CHECK-LABEL: @test_read_exec_lo(
 // CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
 void test_read_exec_lo(global uint* out) {
@@ -38,9 +36,7 @@ void test_read_exec_lo(global uint* out) {
 }
 
 // CHECK-LABEL: @test_read_exec_hi(
-// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
-// CHECK: lshr i64 [[A:%.*]], 32
-// CHECK: trunc i64 [[B:%.*]] to i32
+// CHECK: store i32 0, ptr addrspace(1) %out
 void test_read_exec_hi(global uint* out) {
   *out = __builtin_amdgcn_read_exec_hi();
 }

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
index e753b75dbbf492..d21a17b7f8a287 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
@@ -2382,7 +2382,7 @@ void AMDGPUDAGToDAGISel::SelectBRCOND(SDNode *N) {
 auto CC = cast(Cond->getOperand(2))->get();
 if ((CC == ISD::SETEQ || CC == ISD::SETNE) &&
 isNullConstant(Cond->getOperand(1)) &&
-// TODO: make condition below an assert after fixing ballot bitwidth.
+// We may encounter ballot.i64 in wave32 mode on -O0.
 VCMP.getValueType().getSizeInBits() == ST->getWavefrontSize()) {
   // %VCMP = i(WaveSize) AMDGPUISD::SETCC ...
   // %C = i1 ISD::SETCC %VCMP, 0, setne/seteq

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
index 898289019c7189..3c2351673be5c7 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -990,6 +990,19 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, 
IntrinsicInst &II) const {
 return IC.replaceInstUsesWith(II, 
Constant::getNullValue(II.getType()));
   }
 }
+if (ST->isWave32() && II.getType()->getIntegerBitWidth() == 64) {
+  // %b64 = call i64 ballot.i64(...)
+  // =>
+  // %b32 = call i32 ballot.i32(...)
+  // %b64 = zext i32 %b32 to i64
+  Value *Call = IC.Builder.CreateZExt(
+  IC.Builder.CreateIntrinsic(Intrinsic::amdgcn_ballot,
+ {IC.Builder.getInt32Ty()},
+ {II.getArgOperand(0)}),
+  II.getType());
+  Call->takeName(&II);
+  return IC.replaceInstUsesWith(II, Call);
+}
 break;
   }
   case Intrinsic::amdgcn_wqm_vote: {

diff  --git a/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll 
b/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
index 804283cc20cd6a..94c32e3cbe99f7 100644
--- a/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
+++ b/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
@@ -2599,7 +2599,8 @@ declare i32 @llvm.amdgcn.ballot.i32(i1) nounwind readnone 
convergent
 
 define i64 @ballot_nocombine_64(i1 %i) {
 ; CHECK-LABEL: @ballot_nocombine_64(
-; CHECK-NEXT:[[B:%.*]] = call i64 @llvm.amdgcn.ballot.i64(i1 [[I:%.*]])
+; CHECK-NEXT:[[TMP1:%.*]] = call i32 @llvm.amdgcn.ballot.i32(i1 [[I:%.*]])
+; CHECK-NEXT:[[B:%.*]] = zext i32 [[TMP1]] to i64
 ; CHECK-NEXT:ret i64 [[B]]
 ;
   %b = call i64 @llvm.amdgcn.ballot.i64(i1 %i)
@@ -2616,7 +2617,8 @@ define i64 @ballot_zero_64() {
 
 define i64 @ballot_one_64() {
 ; CHECK-LABEL: @ballot_one_64(
-; CHECK-NEXT:[[B:%.*]] = call i64 @llvm.amdgcn.ballot.i64(i1 true)
+; CHECK-NEXT:[[TMP1:%.*]] = call i32 @llvm.amdgcn.ballot.i32(i1 true)
+; CHECK-NEXT:[[B:%.*]] = zext i32 [[TMP1]] to i64
 ; CHECK-NEXT:ret

[clang] [llvm] [AMDGPU] Add InstCombine rule for ballot.i64 intrinsic in wave32 mode. (PR #71556)

2024-01-17 Thread Matt Arsenault via cfe-commits

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


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


[llvm] [clang] [AArch64] Use parseArchExtension function. NFC (PR #78158)

2024-01-17 Thread Anatoly Trosinenko via cfe-commits

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


[clang] 7f7bbb9 - [AArch64] Use parseArchExtension function. NFC (#78158)

2024-01-17 Thread via cfe-commits

Author: Anatoly Trosinenko
Date: 2024-01-17T12:57:36+03:00
New Revision: 7f7bbb9b441eb4311419be051de4cc8e3cd3ab3c

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

LOG: [AArch64] Use parseArchExtension function. NFC (#78158)

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
llvm/lib/TargetParser/AArch64TargetParser.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 9ebaf4d40cd7e5..da6846cdbffb9a 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -622,9 +622,8 @@ AArch64TargetInfo::getVScaleRange(const LangOptions 
&LangOpts) const {
 unsigned AArch64TargetInfo::multiVersionSortPriority(StringRef Name) const {
   if (Name == "default")
 return 0;
-  for (const auto &E : llvm::AArch64::Extensions)
-if (Name == E.Name)
-  return E.FmvPriority;
+  if (auto Ext = llvm::AArch64::parseArchExtension(Name))
+return Ext->FmvPriority;
   return 0;
 }
 
@@ -634,24 +633,19 @@ unsigned AArch64TargetInfo::multiVersionFeatureCost() 
const {
 }
 
 bool AArch64TargetInfo::doesFeatureAffectCodeGen(StringRef Name) const {
-  auto F = llvm::find_if(llvm::AArch64::Extensions, [&](const auto &E) {
-return Name == E.Name && !E.DependentFeatures.empty();
-  });
-  return F != std::end(llvm::AArch64::Extensions);
+  if (auto Ext = llvm::AArch64::parseArchExtension(Name))
+return !Ext->DependentFeatures.empty();
+  return false;
 }
 
 StringRef AArch64TargetInfo::getFeatureDependencies(StringRef Name) const {
-  auto F = llvm::find_if(llvm::AArch64::Extensions,
- [&](const auto &E) { return Name == E.Name; });
-  return F != std::end(llvm::AArch64::Extensions) ? F->DependentFeatures
-  : StringRef();
+  if (auto Ext = llvm::AArch64::parseArchExtension(Name))
+return Ext->DependentFeatures;
+  return StringRef();
 }
 
 bool AArch64TargetInfo::validateCpuSupports(StringRef FeatureStr) const {
-  for (const auto &E : llvm::AArch64::Extensions)
-if (FeatureStr == E.Name)
-  return true;
-  return false;
+  return llvm::AArch64::parseArchExtension(FeatureStr).has_value();
 }
 
 bool AArch64TargetInfo::hasFeature(StringRef Feature) const {

diff  --git a/llvm/lib/TargetParser/AArch64TargetParser.cpp 
b/llvm/lib/TargetParser/AArch64TargetParser.cpp
index d3c72497c41cbe..fe051922061a91 100644
--- a/llvm/lib/TargetParser/AArch64TargetParser.cpp
+++ b/llvm/lib/TargetParser/AArch64TargetParser.cpp
@@ -47,11 +47,8 @@ std::optional 
AArch64::ArchInfo::findBySubArch(StringRef SubA
 uint64_t AArch64::getCpuSupportsMask(ArrayRef FeatureStrs) {
   uint64_t FeaturesMask = 0;
   for (const StringRef &FeatureStr : FeatureStrs) {
-for (const auto &E : llvm::AArch64::Extensions)
-  if (FeatureStr == E.Name) {
-FeaturesMask |= (1ULL << E.CPUFeature);
-break;
-  }
+if (auto Ext = parseArchExtension(FeatureStr))
+  FeaturesMask |= (1ULL << Ext->CPUFeature);
   }
   return FeaturesMask;
 }
@@ -75,17 +72,14 @@ StringRef AArch64::resolveCPUAlias(StringRef Name) {
 }
 
 StringRef AArch64::getArchExtFeature(StringRef ArchExt) {
-  if (ArchExt.starts_with("no")) {
-StringRef ArchExtBase(ArchExt.substr(2));
-for (const auto &AE : Extensions) {
-  if (!AE.NegFeature.empty() && ArchExtBase == AE.Name)
-return AE.NegFeature;
-}
+  bool IsNegated = ArchExt.starts_with("no");
+  StringRef ArchExtBase = IsNegated ? ArchExt.drop_front(2) : ArchExt;
+
+  if (auto AE = parseArchExtension(ArchExtBase)) {
+// Note: the returned string can be empty.
+return IsNegated ? AE->NegFeature : AE->Feature;
   }
 
-  for (const auto &AE : Extensions)
-if (!AE.Feature.empty() && ArchExt == AE.Name)
-  return AE.Feature;
   return StringRef();
 }
 



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


[clang-tools-extra] [llvm] [clang] DAG: Fix ABI lowering with FP promote in strictfp functions (PR #74405)

2024-01-17 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/74405

>From cdafeff37cd20e8cb8cdcf6ac8561455d5c9a30a Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Sat, 2 Dec 2023 20:49:51 +0700
Subject: [PATCH] DAG: Fix ABI lowering with FP promote in strictfp functions

This was emitting non-strict casts in ABI contexts for illegal
types.
---
 .../SelectionDAG/SelectionDAGBuilder.cpp  |  59 +-
 .../CodeGen/AMDGPU/llvm.is.fpclass.f16.ll |   3 +
 llvm/test/CodeGen/AMDGPU/strict_fp_casts.ll   | 110 
 llvm/test/CodeGen/AMDGPU/strict_fpext.ll  | 280 -
 llvm/test/CodeGen/AMDGPU/strict_fptrunc.ll| 248 +++-
 .../AMDGPU/strictfp_f16_abi_promote.ll| 558 ++
 6 files changed, 1079 insertions(+), 179 deletions(-)
 delete mode 100644 llvm/test/CodeGen/AMDGPU/strict_fp_casts.ll
 create mode 100644 llvm/test/CodeGen/AMDGPU/strictfp_f16_abi_promote.ll

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp 
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 78ebd2d33459a7..2f4f29f4e045ce 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -153,6 +153,7 @@ static const unsigned MaxParallelChains = 64;
 static SDValue getCopyFromPartsVector(SelectionDAG &DAG, const SDLoc &DL,
   const SDValue *Parts, unsigned NumParts,
   MVT PartVT, EVT ValueVT, const Value *V,
+  SDValue InChain,
   std::optional CC);
 
 /// getCopyFromParts - Create a value that contains the specified legal parts
@@ -163,6 +164,7 @@ static SDValue getCopyFromPartsVector(SelectionDAG &DAG, 
const SDLoc &DL,
 static SDValue
 getCopyFromParts(SelectionDAG &DAG, const SDLoc &DL, const SDValue *Parts,
  unsigned NumParts, MVT PartVT, EVT ValueVT, const Value *V,
+ SDValue InChain,
  std::optional CC = std::nullopt,
  std::optional AssertOp = std::nullopt) {
   // Let the target assemble the parts if it wants to
@@ -173,7 +175,7 @@ getCopyFromParts(SelectionDAG &DAG, const SDLoc &DL, const 
SDValue *Parts,
 
   if (ValueVT.isVector())
 return getCopyFromPartsVector(DAG, DL, Parts, NumParts, PartVT, ValueVT, V,
-  CC);
+  InChain, CC);
 
   assert(NumParts > 0 && "No parts to assemble!");
   SDValue Val = Parts[0];
@@ -194,10 +196,10 @@ getCopyFromParts(SelectionDAG &DAG, const SDLoc &DL, 
const SDValue *Parts,
   EVT HalfVT = EVT::getIntegerVT(*DAG.getContext(), RoundBits/2);
 
   if (RoundParts > 2) {
-Lo = getCopyFromParts(DAG, DL, Parts, RoundParts / 2,
-  PartVT, HalfVT, V);
-Hi = getCopyFromParts(DAG, DL, Parts + RoundParts / 2,
-  RoundParts / 2, PartVT, HalfVT, V);
+Lo = getCopyFromParts(DAG, DL, Parts, RoundParts / 2, PartVT, HalfVT, 
V,
+  InChain);
+Hi = getCopyFromParts(DAG, DL, Parts + RoundParts / 2, RoundParts / 2,
+  PartVT, HalfVT, V, InChain);
   } else {
 Lo = DAG.getNode(ISD::BITCAST, DL, HalfVT, Parts[0]);
 Hi = DAG.getNode(ISD::BITCAST, DL, HalfVT, Parts[1]);
@@ -213,7 +215,7 @@ getCopyFromParts(SelectionDAG &DAG, const SDLoc &DL, const 
SDValue *Parts,
 unsigned OddParts = NumParts - RoundParts;
 EVT OddVT = EVT::getIntegerVT(*DAG.getContext(), OddParts * PartBits);
 Hi = getCopyFromParts(DAG, DL, Parts + RoundParts, OddParts, PartVT,
-  OddVT, V, CC);
+  OddVT, V, InChain, CC);
 
 // Combine the round and odd parts.
 Lo = Val;
@@ -243,7 +245,8 @@ getCopyFromParts(SelectionDAG &DAG, const SDLoc &DL, const 
SDValue *Parts,
   assert(ValueVT.isFloatingPoint() && PartVT.isInteger() &&
  !PartVT.isVector() && "Unexpected split");
   EVT IntVT = EVT::getIntegerVT(*DAG.getContext(), 
ValueVT.getSizeInBits());
-  Val = getCopyFromParts(DAG, DL, Parts, NumParts, PartVT, IntVT, V, CC);
+  Val = getCopyFromParts(DAG, DL, Parts, NumParts, PartVT, IntVT, V,
+ InChain, CC);
 }
   }
 
@@ -283,10 +286,20 @@ getCopyFromParts(SelectionDAG &DAG, const SDLoc &DL, 
const SDValue *Parts,
 
   if (PartEVT.isFloatingPoint() && ValueVT.isFloatingPoint()) {
 // FP_ROUND's are always exact here.
-if (ValueVT.bitsLT(Val.getValueType()))
-  return DAG.getNode(
-  ISD::FP_ROUND, DL, ValueVT, Val,
-  DAG.getTargetConstant(1, DL, TLI.getPointerTy(DAG.getDataLayout(;
+if (ValueVT.bitsLT(Val.getValueType())) {
+
+  SDValue NoChange =
+  DAG.getTargetConstant(1, DL, TLI.getPointerTy(DAG.getDataLayout()));
+
+  if (DAG.getMachineFunction().getFunction().

[clang] [clang] Remove outdated parts of documentation for #pragma diagnostic (PR #78095)

2024-01-17 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

I documented that we don't support unpaired `pop` (tracked in #23065) and 
enabling diagnostics that are not enabled via CLI (tracked in #78418).

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


[clang] [clang] Remove outdated parts of documentation for #pragma diagnostic (PR #78095)

2024-01-17 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/78095

>From 1aca1cd3be8209675b8aa3b79b2d626ad9f3c559 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 14 Jan 2024 14:11:16 +0300
Subject: [PATCH 1/3] [clang] Remove outdated parts of documentation for
 #pragma diagnostic

GCC has changed over the past decade.
Fixes #51472
---
 clang/docs/UsersManual.rst | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index c6a6b06fc04be71..22fbb6764e2f006 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1132,7 +1132,7 @@ Controlling Diagnostics via Pragmas
 Clang can also control what diagnostics are enabled through the use of
 pragmas in the source code. This is useful for turning off specific
 warnings in a section of source code. Clang supports GCC's pragma for
-compatibility with existing source code, as well as several extensions.
+compatibility with existing source code.
 
 The pragma may control any warning that can be used from the command
 line. Warnings may be set to ignored, warning, error, or fatal. The
@@ -1143,8 +1143,7 @@ warnings:
 
   #pragma GCC diagnostic ignored "-Wall"
 
-In addition to all of the functionality provided by GCC's pragma, Clang
-also allows you to push and pop the current warning state. This is
+Clang also allows you to push and pop the current warning state. This is
 particularly useful when writing a header file that will be compiled by
 other people, because you don't know what warning flags they build with.
 
@@ -1157,19 +1156,16 @@ existed.
   #if foo
   #endif foo // warning: extra tokens at end of #endif directive
 
-  #pragma clang diagnostic push
-  #pragma clang diagnostic ignored "-Wextra-tokens"
+  #pragma GCC diagnostic push
+  #pragma GCC diagnostic ignored "-Wextra-tokens"
 
   #if foo
   #endif foo // no warning
 
-  #pragma clang diagnostic pop
+  #pragma GCC diagnostic pop
 
 The push and pop pragmas will save and restore the full diagnostic state
-of the compiler, regardless of how it was set. That means that it is
-possible to use push and pop around GCC compatible diagnostics and Clang
-will push and pop them appropriately, while GCC will ignore the pushes
-and pops as unknown pragmas. It should be noted that while Clang
+of the compiler, regardless of how it was set. It should be noted that while 
Clang
 supports the GCC pragma, Clang and GCC do not support the exact same set
 of warnings, so even when using GCC compatible #pragmas there is no
 guarantee that they will have identical behaviour on both compilers.

>From 005db51edbe76f48b2097444f77b0ea48d541212 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 17 Jan 2024 11:36:41 +0300
Subject: [PATCH 2/3] Clarify that we don't support some of GCC behavior

---
 clang/docs/UsersManual.rst | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 22fbb6764e2f006..9e8ffa760af92d0 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1132,7 +1132,9 @@ Controlling Diagnostics via Pragmas
 Clang can also control what diagnostics are enabled through the use of
 pragmas in the source code. This is useful for turning off specific
 warnings in a section of source code. Clang supports GCC's pragma for
-compatibility with existing source code.
+compatibility with existing source code, so ``#pragma GCC diagnostic``
+and ``#pragma clang diagnostic`` are synonyms for Clang. GCC will ignore
+``#pragma clang diagnostic``, though.
 
 The pragma may control any warning that can be used from the command
 line. Warnings may be set to ignored, warning, error, or fatal. The
@@ -1170,6 +1172,15 @@ supports the GCC pragma, Clang and GCC do not support 
the exact same set
 of warnings, so even when using GCC compatible #pragmas there is no
 guarantee that they will have identical behaviour on both compilers.
 
+Clang also doesn't support GCC behavior for ``#pragma diagnostic pop`` that 
doesn't have
+a corresponding ``#pragma diagnostic push``. In this case GCC pretends that
+there is a ``#pragma diagnostic push`` at the very beginning of source file,
+so "unpaired" ``#pragma diagnostic pop`` matches that implicit push.
+This makes a difference for ``#pragma GCC diagnostic ignored`` which are not
+guarded by push and pop. Refer to
+`GCC documentation 
`_
+for details.
+
 In addition to controlling warnings and errors generated by the compiler, it is
 possible to generate custom warning and error messages through the following
 pragmas:

>From e285dc23ede59979bbf2659cfeebf347e3247784 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 17 Jan 2024 12:48:10 +0300
Subject: [PATCH 3/3] Clarify that diagnostics not enabled via CLI can't be
 enabled via pragma yet

---
 clang/docs/UsersManual.rst | 1

[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2024-01-17 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


cor3ntin wrote:

> Here are the results for a quick implementation of check points: 
> http://llvm-compile-time-tracker.com/compare.php?from=12e425d0cf9bca072c7b2138e50acbc5f1cd818c&to=99f3a7853f9fa83bffe3b4d04e41e744169d426a&stat=instructions:u
> 
> With a little more fiddling: 
> http://llvm-compile-time-tracker.com/compare.php?from=12e425d0cf9bca072c7b2138e50acbc5f1cd818c&to=0ee6dd17747818b05a1d504e4916ce46ef061226&stat=instructions:u

Imo this is reasonable, we should go in that direction. It's not free but it is 
predictable

Further improvements:
 * cache the lookup of `CheckPoints[FID]` as it should not change between calls 
to `BeginSourceFile`
 * Play with reserve and/or dequeue





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


[clang-tools-extra] [llvm] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-17 Thread Aiden Grossman via cfe-commits


@@ -0,0 +1,6 @@
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

boomanaiden154 wrote:

Looks like all the other Python tests within the monorepo are pretty much lit 
tests. I'll work on converting these tests to lit tests later today. Should be 
feasible since we're essentially just using Python tooling to validate where 
files are, which we can easily do in lit.

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


[clang-tools-extra] [llvm] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-17 Thread Aiden Grossman via cfe-commits


@@ -0,0 +1,6 @@
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

boomanaiden154 wrote:

Or what's probably better for structuring is we can do `mlgo/mlgo/corpus` and 
then the package would be accessed as `mlgo.corpus` while still keeping 
everything together if we want to add more in the future. I'll switch to that 
for now.

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


[clang-tools-extra] [llvm] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-17 Thread Aiden Grossman via cfe-commits


@@ -0,0 +1,12 @@
+# MLGO Python Library
+
+This folder contains the MLGO python library. This library consists of telling

boomanaiden154 wrote:

Updated it to calling this the folder for MLGO Python Utilities. Good catch on 
the first line. Not sure exactly what happened there.

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


[clang] [libclang/python] Bump minimum compatibility to Python 3.6 (PR #77228)

2024-01-17 Thread Aiden Grossman via cfe-commits

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


[clang] 75f2321 - [libclang/python] Bump minimum compatibility to Python 3.6 (#77228)

2024-01-17 Thread via cfe-commits

Author: Craig Hesling
Date: 2024-01-17T01:02:54-08:00
New Revision: 75f232181a2b9c9bd85823f88b2d63559c592556

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

LOG: [libclang/python] Bump minimum compatibility to Python 3.6 (#77228)

Remove Python 2 support and clean up code that conditions based on
version.

Issue #76664.

Added: 


Modified: 
clang/bindings/python/README.txt
clang/bindings/python/clang/cindex.py

Removed: 




diff  --git a/clang/bindings/python/README.txt 
b/clang/bindings/python/README.txt
index 44c715e5de56f7..3e509662144fac 100644
--- a/clang/bindings/python/README.txt
+++ b/clang/bindings/python/README.txt
@@ -10,7 +10,7 @@ runner. For example:
 --
 $ env PYTHONPATH=$(echo ~/llvm/clang/bindings/python/) \
   CLANG_LIBRARY_PATH=$(llvm-config --libdir) \
-  python -m unittest discover -v
+  python3 -m unittest discover -v
 tests.cindex.test_index.test_create ... ok
 ...
 

diff  --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index d780ee353a133c..754f03d718e882 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -66,81 +66,50 @@
 
 import clang.enumerations
 
+import collections.abc
 import os
-import sys
-
-if sys.version_info[0] == 3:
-# Python 3 strings are unicode, translate them to/from utf8 for C-interop.
-class c_interop_string(c_char_p):
-def __init__(self, p=None):
-if p is None:
-p = ""
-if isinstance(p, str):
-p = p.encode("utf8")
-super(c_char_p, self).__init__(p)
 
-def __str__(self):
-return self.value
-
-@property
-def value(self):
-if super(c_char_p, self).value is None:
-return None
-return super(c_char_p, self).value.decode("utf8")
-
-@classmethod
-def from_param(cls, param):
-if isinstance(param, str):
-return cls(param)
-if isinstance(param, bytes):
-return cls(param)
-if param is None:
-# Support passing null to C functions expecting char arrays
-return None
-raise TypeError(
-"Cannot convert '{}' to '{}'".format(type(param).__name__, 
cls.__name__)
-)
-
-@staticmethod
-def to_python_string(x, *args):
-return x.value
 
-def b(x):
-if isinstance(x, bytes):
-return x
-return x.encode("utf8")
+# Python 3 strings are unicode, translate them to/from utf8 for C-interop.
+class c_interop_string(c_char_p):
+def __init__(self, p=None):
+if p is None:
+p = ""
+if isinstance(p, str):
+p = p.encode("utf8")
+super(c_char_p, self).__init__(p)
 
-elif sys.version_info[0] == 2:
-# Python 2 strings are utf8 byte strings, no translation is needed for
-# C-interop.
-c_interop_string = c_char_p
-
-def _to_python_string(x, *args):
-return x
-
-c_interop_string.to_python_string = staticmethod(_to_python_string)
+def __str__(self):
+return self.value
 
-def b(x):
-return x
+@property
+def value(self):
+if super(c_char_p, self).value is None:
+return None
+return super(c_char_p, self).value.decode("utf8")
 
+@classmethod
+def from_param(cls, param):
+if isinstance(param, str):
+return cls(param)
+if isinstance(param, bytes):
+return cls(param)
+if param is None:
+# Support passing null to C functions expecting char arrays
+return None
+raise TypeError(
+"Cannot convert '{}' to '{}'".format(type(param).__name__, 
cls.__name__)
+)
 
-# Importing ABC-s directly from collections is deprecated since Python 3.7,
-# will stop working in Python 3.8.
-# See: https://docs.python.org/dev/whatsnew/3.7.html#id3
-if sys.version_info[:2] >= (3, 7):
-from collections import abc as collections_abc
-else:
-import collections as collections_abc
+@staticmethod
+def to_python_string(x, *args):
+return x.value
 
-# We only support PathLike objects on Python version with os.fspath present
-# to be consistent with the Python standard library. On older Python versions
-# we only support strings and we have dummy fspath to just pass them through.
-try:
-fspath = os.fspath
-except AttributeError:
 
-def fspath(x):
+def b(x):
+if isinstance(x, bytes):
 return x
+return x.encode("utf8")
 
 
 # ctypes doesn't implicitly convert c_void_p to the appropriate wrapper
@@ -202,7 +171,7 @@ def __init__(self, enumeration, message):
 ### Structure

[clang] [libclang/python] Bump minimum compatibility to Python 3.6 (PR #77228)

2024-01-17 Thread Craig Hesling via cfe-commits

linux4life798 wrote:

Thanks all! @boomanaiden154 or @tru, could you merge this PR?

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


[clang-tools-extra] [llvm] [MLGO] Upstream the corpus extraction tooling (PR #72319)

2024-01-17 Thread Aiden Grossman via cfe-commits

boomanaiden154 wrote:

> Would it be also possible to remove the dependency on 
> [Abseil](https://github.com/abseil/abseil-py)? None of the existing scripts 
> in LLVM use it and I don't think we should be introducing this dependency. It 
> looks like Abseil is only used for flag parsing, logging and testing; those 
> should be straightforward to replace with standard libraries like `argparse`, 
> `logging` or `unittest`.

Yes. My plan was to remove the dependency on abseil as well. My plan was to get 
this landed with all the infrastructure setup and the code basically just 
directly copied and then remove the abseil dependency in a follow-up patch so 
that the different pieces get reviewed appropriately.

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


[lld] [mlir] [libcxx] [llvm] [clang-tools-extra] [libc] [openmp] [compiler-rt] [libcxxabi] [lldb] [libunwind] [clang] [flang] [clang] static operators should evaluate object argument (PR #68485)

2024-01-17 Thread Tianlan Zhou via cfe-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 01/15] [clang] static operators should evaluate object
 argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c0..a6c81f467fbe01c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac738..19406ff174dea14 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b639..a580c635998510f 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo &FnInfo =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, &CallOrInvoke, Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c95..42de125e7489911 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCal

[clang] [clang] Fix CTAD for aggregates for nested template classes (PR #78387)

2024-01-17 Thread Haojian Wu via cfe-commits

hokein wrote:

Thanks, this change looks good to me.

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


[llvm] [mlir] [clang-tools-extra] [libcxxabi] [compiler-rt] [flang] [libc] [libunwind] [libcxx] [lldb] [clang] [ASan][AMDGPU] Fix Assertion Failure. (PR #78242)

2024-01-17 Thread via cfe-commits


@@ -1254,9 +1254,11 @@ Value *AddressSanitizer::memToShadow(Value *Shadow, 
IRBuilder<> &IRB) {
 void AddressSanitizer::instrumentMemIntrinsic(MemIntrinsic *MI) {
   InstrumentationIRBuilder IRB(MI);
   if (isa(MI)) {
-IRB.CreateCall(isa(MI) ? AsanMemmove : AsanMemcpy,
-   {MI->getOperand(0), MI->getOperand(1),
-IRB.CreateIntCast(MI->getOperand(2), IntptrTy, false)});
+IRB.CreateCall(
+isa(MI) ? AsanMemmove : AsanMemcpy,
+{MI->getOperand(0),
+ IRB.CreatePointerBitCastOrAddrSpaceCast(MI->getOperand(1), PtrTy),

ampandey-1995 wrote:

Hi @arsenm Can you please review 
https://github.com/llvm/llvm-project/pull/78410. 

I have made changes according to your comments.

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


[flang] [clang] [lldb] [llvm] [lld] [libunwind] [libcxxabi] [clang-tools-extra] [libc] [compiler-rt] [mlir] [libcxx] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-17 Thread Hristo Hristov via cfe-commits


@@ -0,0 +1,119 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+#define _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__type_traits/decay.h>
+#include <__utility/cmp.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template 
+concept __libcpp_standard_integer = __libcpp_unsigned_integer> || 
__libcpp_signed_integer>;
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))
+return __sum;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return std::numeric_limits<_Tp>::max();
+  } else {
+// Signed addition overflow
+if (__x > 0)
+  // Overflows if (x > 0 && y > 0)
+  return std::numeric_limits<_Tp>::max();
+else
+  // Overflows if  (x < 0 && y < 0)
+  return std::numeric_limits<_Tp>::min();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sub; !__builtin_sub_overflow(__x, __y, &__sub))
+return __sub;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+// Overflows if (x < y)
+return std::numeric_limits<_Tp>::min();
+  } else {
+// Signed subtration overflow
+if (__x > 0)
+  // Overflows if (x > 0 && y < 0)
+  return std::numeric_limits<_Tp>::max();
+else
+  // Overflows if (x < 0 && y > 0)
+  return std::numeric_limits<_Tp>::min();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __mul; !__builtin_mul_overflow(__x, __y, &__mul))
+return __mul;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return std::numeric_limits<_Tp>::max();
+  } else {
+// Signed multiplication overflow
+if (__x > 0) {
+  if (__y > 0)
+// Overflows if (x > 0 && y > 0)
+return std::numeric_limits<_Tp>::max();
+  // Overflows if (x > 0 && y < 0)
+  return std::numeric_limits<_Tp>::min();
+}
+if (__y > 0)
+  // Overflows if (x < 0 && y > 0)
+  return std::numeric_limits<_Tp>::min();
+// Overflows if (x < 0 && y < 0)
+return std::numeric_limits<_Tp>::max();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
+  _LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined");
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return __x / __y;
+  } else {
+// Handle signed division overflow
+if (__x == std::numeric_limits<_Tp>::min() && __y == _Tp{-1})
+  return std::numeric_limits<_Tp>::max();
+return __x / __y;
+  }
+}
+
+template <__libcpp_standard_integer _Rp, __libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {

H-G-Hristov wrote:

OK. I'll remove the optimization for now. On optimized builds the difference 
according to my quick, stupid benchmark is near zero and on unoptimized builds 
less than 10%.
https://quick-bench.com/q/QFdMFKaw_5OnmeDqB_BMkh0BaSg

Please comment if you disagree.

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


[lld] [llvm] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-17 Thread via cfe-commits


@@ -360,6 +366,25 @@ bool 
BasicBlockSections::runOnMachineFunction(MachineFunction &MF) {
   return true;
 }
 
+// When the BB address map needs to be generated, this renumbers basic blocks 
to
+// make them appear in increasing order of their IDs in the function. This
+// avoids the need to store basic block IDs in the BB address map section, 
since
+// they can be determined implicitly.
+bool BasicBlockSections::handleBBAddrMap(MachineFunction &MF) {
+  if (!MF.getTarget().Options.BBAddrMap)
+return false;
+  MF.RenumberBlocks();
+  return true;
+}
+
+bool BasicBlockSections::runOnMachineFunction(MachineFunction &MF) {
+  // First handle the basic block sections.
+  auto R1 = handleBBSections(MF);
+  // Handle basic block address map after basic block sections are finalized.
+  auto R2 = handleBBAddrMap(MF);

lifengxiang1025 wrote:

If basic-block-sections=labels and basic-block-address-map were used together, 
doesn't need to run `handleBBAddrMap`

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-17 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > LGTM.
> > We need to delete 
> > `clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so` 
> > and 
> > `clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json`,
> >  we should generate them with `split-file`
> 
> Are you sure that is the proper way? Should these tests not use a complete 
> installation to make sure it works on installations?

We can use `mkdir` to generate more complex paths. For example,

```
// RUN: split-file %s %t
//
// RUN: mkdir %t/
// RUN: touch %t/.../libc++.so
```


The intention is to remove the use of `Inputs` in test. It is really hard to 
read.

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


<    1   2   3   4   5   6