[clang] a2da7d0 - [clang][Interp] Ignore LValueToRValue casts before doing the load

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

Author: Timm Bäder
Date: 2024-02-02T08:46:55+01:00
New Revision: a2da7d06c7e1ec75812ff8ced29541d4af3668c9

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

LOG: [clang][Interp] Ignore LValueToRValue casts before doing the load

If the SubExpr results in an invalid pointer, we will otherwise
reject the constant expression.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/c.c

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 01555b0fc7dac..3ca4f56903fda 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -78,6 +78,9 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
   switch (CE->getCastKind()) {
 
   case CK_LValueToRValue: {
+if (DiscardResult)
+  return this->discard(SubExpr);
+
 return dereference(
 SubExpr, DerefKind::Read,
 [](PrimType) {
@@ -86,9 +89,7 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 },
 [this, CE](PrimType T) {
   // Pointer on stack - dereference it.
-  if (!this->emitLoadPop(T, CE))
-return false;
-  return DiscardResult ? this->emitPop(T, CE) : true;
+  return this->emitLoadPop(T, CE);
 });
   }
 

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index df3807b371dea..bf5394b701587 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -98,3 +98,15 @@ void f (int z) {
 
 int expr;
 int chooseexpr[__builtin_choose_expr(1, 1, expr)];
+
+int somefunc(int i) {
+  return (i, 65537) * 65537; // expected-warning {{left operand of comma 
operator has no effect}} \
+ // expected-warning {{overflow in expression; 
result is 131073}} \
+ // pedantic-expected-warning {{left operand of 
comma operator has no effect}} \
+ // pedantic-expected-warning {{overflow in 
expression; result is 131073}} \
+ // ref-warning {{left operand of comma operator 
has no effect}} \
+ // ref-warning {{overflow in expression; result 
is 131073}} \
+ // pedantic-ref-warning {{left operand of comma 
operator has no effect}} \
+ // pedantic-ref-warning {{overflow in expression; 
result is 131073}}
+
+}



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


[flang] [libcxx] [libc] [clang] [lldb] [llvm] [mlir] [mlir] Skip invalid test on big endian platform (s390x) (PR #80246)

2024-02-02 Thread Mehdi Amini via cfe-commits

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


[llvm] [clang] [compiler-rt] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

2024-02-02 Thread Fangrui Song via cfe-commits

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

LGTM, but this should be signed off by phoebewang

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


[clang] a8b5994 - [clang][Interp][NFC] Add a broken test case

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

Author: Timm Bäder
Date: 2024-02-02T09:10:03+01:00
New Revision: a8b5994b337cf1d461202a65204a4ee6c5eae341

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

LOG: [clang][Interp][NFC] Add a broken test case

The LHS of the subtraction returns 16 right now, but should
return 0.

Added: 


Modified: 
clang/test/AST/Interp/c.c

Removed: 




diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index bf5394b701587..0b673253c6c70 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -110,3 +110,23 @@ int somefunc(int i) {
  // pedantic-ref-warning {{overflow in expression; 
result is 131073}}
 
 }
+
+/// FIXME: The following test is incorrect in the new interpreter.
+/// The null pointer returns 16 from its getIntegerRepresentation().
+struct ArrayStruct {
+  char n[1];
+};
+struct AA {
+  char name2[(int)&((struct ArrayStruct*)0)->n - 1]; // expected-warning 
{{cast to smaller integer type}} \
+ // expected-warning 
{{folded to constant array}} \
+ // 
pedantic-expected-warning {{cast to smaller integer type}} \
+ // 
pedantic-expected-warning {{folded to constant array}} \
+ // ref-error {{array size 
is negative}} \
+ // ref-warning {{cast to 
smaller integer type}} \
+ // pedantic-ref-error 
{{array size is negative}} \
+ // pedantic-ref-warning 
{{cast to smaller integer type}}
+};
+_Static_assert(sizeof(struct AA) == 15, ""); // ref-error {{failed}} \
+ // ref-note {{1 == 15}} \
+ // pedantic-ref-error {{failed}} \
+ // pedantic-ref-note {{1 == 15}}



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


[clang] [X86] [iamcu] Fix wrong alignment value for attr (aligned) with -miamcu (PR #80401)

2024-02-02 Thread via cfe-commits

https://github.com/joyhou-hw created 
https://github.com/llvm/llvm-project/pull/80401

attribute ((aligned)) should be 4 for -miamcu.

relate: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66818

>From 02bb222e186b91c918f2375460e8e3bee2e75eb8 Mon Sep 17 00:00:00 2001
From: houzhenyu 
Date: Fri, 2 Feb 2024 11:21:50 +0800
Subject: [PATCH] [X86] [iamcu] Fix wrong alignment value for attr (aligned)
 with -miamcu

attribute ((aligned)) should be 4 for -miamcu.
---
 clang/lib/Basic/Targets/X86.h  |  1 +
 clang/test/Sema/attr-aligned.c | 10 ++
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 1845f5a747af4..0adb1f3eacecb 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -634,6 +634,7 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_32TargetInfo : 
public X86_32TargetInfo {
   : X86_32TargetInfo(Triple, Opts) {
 this->WCharType = TargetInfo::UnsignedShort;
 DoubleAlign = LongLongAlign = 64;
+DefaultAlignForAttributeAligned = 32;
 resetDataLayout("e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-"
 "i128:128-f80:32-n8:16:32-a:0:32-S32",
 "_");
diff --git a/clang/test/Sema/attr-aligned.c b/clang/test/Sema/attr-aligned.c
index 130840d46650d..b285ce3d0ed78 100644
--- a/clang/test/Sema/attr-aligned.c
+++ b/clang/test/Sema/attr-aligned.c
@@ -1,4 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple i586-intel-elfiamcu -fsyntax-only -verify %s
+
+#ifdef __iamcu
+// expected-no-diagnostics
+struct dummy { int x __attribute__((aligned));  };
+int m0[__alignof__(struct dummy) == 4 ? 1 : -1];
+
+#else
 
 int x __attribute__((aligned(3))); // expected-error {{requested alignment is 
not a power of 2}}
 int y __attribute__((aligned(1ull << 33))); // expected-error {{requested 
alignment must be 4294967296 bytes or smaller}}
@@ -60,3 +68,5 @@ array_with_overaligned_struct F2;
 char f2[__alignof__(F2) == 16 ? 1 : -1] = { 0 };
 array_with_align_attr F3;
 char f3[__alignof__(F3) == 16 ? 1 : -1] = { 0 };
+
+#endif

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


[clang] [X86] [iamcu] Fix wrong alignment value for attr (aligned) with -miamcu (PR #80401)

2024-02-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (joyhou-hw)


Changes

attribute ((aligned)) should be 4 for -miamcu.

relate: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66818

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


2 Files Affected:

- (modified) clang/lib/Basic/Targets/X86.h (+1) 
- (modified) clang/test/Sema/attr-aligned.c (+10) 


``diff
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 1845f5a747af4..0adb1f3eacecb 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -634,6 +634,7 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_32TargetInfo : 
public X86_32TargetInfo {
   : X86_32TargetInfo(Triple, Opts) {
 this->WCharType = TargetInfo::UnsignedShort;
 DoubleAlign = LongLongAlign = 64;
+DefaultAlignForAttributeAligned = 32;
 resetDataLayout("e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-"
 "i128:128-f80:32-n8:16:32-a:0:32-S32",
 "_");
diff --git a/clang/test/Sema/attr-aligned.c b/clang/test/Sema/attr-aligned.c
index 130840d46650d..b285ce3d0ed78 100644
--- a/clang/test/Sema/attr-aligned.c
+++ b/clang/test/Sema/attr-aligned.c
@@ -1,4 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple i586-intel-elfiamcu -fsyntax-only -verify %s
+
+#ifdef __iamcu
+// expected-no-diagnostics
+struct dummy { int x __attribute__((aligned));  };
+int m0[__alignof__(struct dummy) == 4 ? 1 : -1];
+
+#else
 
 int x __attribute__((aligned(3))); // expected-error {{requested alignment is 
not a power of 2}}
 int y __attribute__((aligned(1ull << 33))); // expected-error {{requested 
alignment must be 4294967296 bytes or smaller}}
@@ -60,3 +68,5 @@ array_with_overaligned_struct F2;
 char f2[__alignof__(F2) == 16 ? 1 : -1] = { 0 };
 array_with_align_attr F3;
 char f3[__alignof__(F3) == 16 ? 1 : -1] = { 0 };
+
+#endif

``




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


[clang] d9c20e4 - [AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276)

2024-02-02 Thread via cfe-commits

Author: Matthew Devereau
Date: 2024-02-02T08:12:05Z
New Revision: d9c20e437fe110fb79b5ca73a52762e5b930b361

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

LOG: [AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276)

This enables specifing "za" or "zt0" to the clobber list for inline asm.
This complies with the acle SME addition to the asm extension here:
https://github.com/ARM-software/acle/pull/276

Added: 
llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll

Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/test/CodeGen/aarch64-inline-asm.c
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 36d178ea8ae98..d2c06f7191bfc 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1174,6 +1174,8 @@ TargetInfo::BuiltinVaListKind 
AArch64TargetInfo::getBuiltinVaListKind() const {
 }
 
 const char *const AArch64TargetInfo::GCCRegNames[] = {
+// clang-format off
+
 // 32-bit Integer registers
 "w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8", "w9", "w10", "w11",
 "w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21", 
"w22",
@@ -1210,7 +1212,12 @@ const char *const AArch64TargetInfo::GCCRegNames[] = {
 
 // SVE predicate-as-counter registers
 "pn0",  "pn1",  "pn2",  "pn3",  "pn4",  "pn5",  "pn6",  "pn7",  "pn8",
-"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15"
+"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15",
+
+// SME registers
+"za", "zt0",
+
+// clang-format on
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {

diff  --git a/clang/test/CodeGen/aarch64-inline-asm.c 
b/clang/test/CodeGen/aarch64-inline-asm.c
index 75e9a8c46b876..8ddee560b11da 100644
--- a/clang/test/CodeGen/aarch64-inline-asm.c
+++ b/clang/test/CodeGen/aarch64-inline-asm.c
@@ -95,3 +95,11 @@ void test_reduced_gpr_constraints(int var32, long var64) {
 // CHECK: [[ARG2:%.+]] = load i64, ptr
 // CHECK: call void asm sideeffect "add x0, x0, $0", "@3Ucj,~{x0}"(i64 
[[ARG2]])
 }
+
+void test_sme_constraints(){
+  asm("movt zt0[3, mul vl], z0" : : : "za");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
+
+  asm("movt zt0[3, mul vl], z0" : : : "zt0");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
+}
\ No newline at end of file

diff  --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index bb19aef978b94..a7d1592e53ab1 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -10728,6 +10728,14 @@ AArch64TargetLowering::getRegForInlineAsmConstraint(
   parseConstraintCode(Constraint) != AArch64CC::Invalid)
 return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass);
 
+  if (Constraint == "{za}") {
+return std::make_pair(unsigned(AArch64::ZA), &AArch64::MPRRegClass);
+  }
+
+  if (Constraint == "{zt0}") {
+return std::make_pair(unsigned(AArch64::ZT0), &AArch64::ZTRRegClass);
+  }
+
   // Use the default implementation in TargetLowering to convert the register
   // constraint into a member of a register class.
   std::pair Res;

diff  --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp 
b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
index f86e6947c9cdb..48e1c1bc73022 100644
--- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
@@ -507,6 +507,10 @@ bool AArch64RegisterInfo::isAsmClobberable(const 
MachineFunction &MF,
 MCRegisterInfo::regsOverlap(PhysReg, AArch64::X16))
 return true;
 
+  // ZA/ZT0 registers are reserved but may be permitted in the clobber list.
+  if (PhysReg == AArch64::ZA || PhysReg == AArch64::ZT0)
+return true;
+
   return !isReservedReg(MF, PhysReg);
 }
 

diff  --git a/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll 
b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
new file mode 100644
index 0..a8cba7dc9a91e
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-linux-gnu -stop-after=aarch64-isel < %s -o - 
| FileCheck %s
+
+define void @alpha( %x) local_unnamed_addr {
+entry:
+; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 
12 /* clobber */, implicit-def early-clobber $za
+  tail call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
+  ret void
+}
+
+define void @beta( %x) local_unnamed_addr {
+entry:
+; CHECK: INLINEASM &"movt zt0[3, mul vl], z0

[llvm] [clang] [AArch64][SME] Implement inline-asm clobbers for za/zt0 (PR #79276)

2024-02-02 Thread Matthew Devereau via cfe-commits

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


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

2024-02-02 Thread Matt Arsenault via cfe-commits

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


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


[clang] 0be3915 - [clang][Interp] Protect stores against dummy pointers

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

Author: Timm Bäder
Date: 2024-02-02T09:18:06+01:00
New Revision: 0be39155bd22258b3e90468b6184bfd87a948bec

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

LOG: [clang][Interp] Protect stores against dummy pointers

Added: 


Modified: 
clang/lib/AST/Interp/Interp.cpp
clang/test/Sema/warn-cast-qual.c

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 4c3184aec9968..0766ad88e9224 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -399,6 +399,8 @@ bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer 
&Ptr) {
 bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
   if (!CheckLive(S, OpPC, Ptr, AK_Assign))
 return false;
+  if (!CheckDummy(S, OpPC, Ptr))
+return false;
   if (!CheckExtern(S, OpPC, Ptr))
 return false;
   if (!CheckRange(S, OpPC, Ptr, AK_Assign))

diff  --git a/clang/test/Sema/warn-cast-qual.c 
b/clang/test/Sema/warn-cast-qual.c
index ec140180ffa12..609c1b8d31fa3 100644
--- a/clang/test/Sema/warn-cast-qual.c
+++ b/clang/test/Sema/warn-cast-qual.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -Wcast-qual 
-verify %s
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -x c++ -fsyntax-only 
-Wcast-qual -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -Wcast-qual 
-verify %s -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -x c++ -fsyntax-only 
-Wcast-qual -verify %s -fexperimental-new-constant-interpreter
 
 #include 
 



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


[llvm] [clang] [RISCV] Add support for RISC-V Pointer Masking (PR #79929)

2024-02-02 Thread Jesse Huang via cfe-commits

https://github.com/jaidTw commented:

Should you also update the `riscv32-toolchain-extra.c` and 
`riscv64-toolchain-extra.c`?
LGTM otherwise

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


[clang] [clang] Update documentation for `#pragma diagnostic` (PR #78095)

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

https://github.com/Endilll closed 
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] 75c4339 - [clang][Interp][NFC] Implement dumping Invalid/Valid results

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

Author: Timm Bäder
Date: 2024-02-02T09:25:54+01:00
New Revision: 75c4339ef31922bf8c883a7a5dfe638ec6818ab2

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

LOG: [clang][Interp][NFC] Implement dumping Invalid/Valid results

This was just an omission from an earlier commit, clearly
we can print them.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/EvaluationResult.cpp 
b/clang/lib/AST/Interp/EvaluationResult.cpp
index a14dc87f1dfde..05105862a53a8 100644
--- a/clang/lib/AST/Interp/EvaluationResult.cpp
+++ b/clang/lib/AST/Interp/EvaluationResult.cpp
@@ -186,9 +186,12 @@ void EvaluationResult::dump() const {
 OS << "\n";
 break;
   }
-
-  default:
-llvm_unreachable("Can't print that.");
+  case Invalid:
+OS << "Invalid\n";
+  break;
+  case Valid:
+OS << "Valid\n";
+  break;
   }
 }
 



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


[llvm] [clang] [compiler-rt] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

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


@@ -139,20 +139,79 @@ enum ProcessorFeatures {
   FEATURE_AVX512BITALG,
   FEATURE_AVX512BF16,
   FEATURE_AVX512VP2INTERSECT,
+  // Below Features has many missings comparing to gcc, it's because gcc has
+  // some LLVM doesn't include, e.g. FEATURE_ABM, FEATURE_HLE, ...
+  FEATURE_3DNOW,
+  FEATURE_ADX = 40,
+  FEATURE_CLDEMOTE = 42,
+  FEATURE_CLFLUSHOPT,
+  FEATURE_CLWB,
+  FEATURE_CLZERO,
+  FEATURE_CMPXCHG16B,
+
+  FEATURE_ENQCMD = 48,
+  FEATURE_F16C,
+  FEATURE_FSGSBASE,

phoebewang wrote:

I didn't check others, but think `FEATURE_IBT` should map tp `FeatureSHSTK` in 
LLVM.

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


[compiler-rt] [llvm] [clang] [X86] Support more ISAs to enable __builtin_cpu_supports (PR #79086)

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


@@ -139,20 +139,77 @@ enum ProcessorFeatures {
   FEATURE_AVX512BITALG,
   FEATURE_AVX512BF16,
   FEATURE_AVX512VP2INTERSECT,
+  FEATURE_3DNOW,
+  FEATURE_ADX = 40,
+  FEATURE_CLDEMOTE = 42,

phoebewang wrote:

ABM is a AMD specific feature 
https://en.wikipedia.org/wiki/X86_Bit_manipulation_instruction_set
Maybe LLVM doesn't support it. But we should be able to map it to its 
corresponding [CPUID 
bit](https://github.com/gcc-mirror/gcc/blob/02948ced062b730e2859f718dd46bfcaa3c16c6b/gcc/config/i386/cpuid.h#L56).
 Maybe not in this patch.
I'd expect we can list the missing parts with comments like
```
FEATURE_3DNOW,
FEATURE_ADX = 40,
// FEATURE_ABM,
FEATURE_CLDEMOTE = 42,
```

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


[clang] [clang][Sema] GH58548 (PR #80395)

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

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


[clang] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate. (PR #80395)

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

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


[clang] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (PR #80395)

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

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


[clang] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (PR #80395)

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

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


[flang] [libc] [clang-tools-extra] [clang] [llvm] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (PR #80395)

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

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/80395

>From 24a8251aab9a1a03953412ae47508d039d926212 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 2 Feb 2024 15:24:13 +0800
Subject: [PATCH 1/2] [clang][Sema] Fix GH58548

---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaOverload.cpp   |  3 ++-
 .../SemaTemplate/concepts-recovery-expr.cpp   | 27 +++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37f2423441a30..f4c5c3421f2e8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -183,6 +183,9 @@ Bug Fixes to C++ Support
 - Fix for crash when using a erroneous type in a return statement.
   Fixes (`#63244 `_)
   and (`#79745 `_)
+- Fixed an out-of-bounds error caused by building a recovery expression for 
ill-formed
+  function calls while substituting into constraints.
+  (`https://github.com/llvm/llvm-project/issues/58548`_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 940bcccb9e261..6a04d68b4f041 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7623,7 +7623,8 @@ void Sema::AddTemplateOverloadCandidate(
   //   functions. In such a case, the candidate functions generated from each
   //   function template are combined with the set of non-template candidate
   //   functions.
-  TemplateDeductionInfo Info(CandidateSet.getLocation());
+  TemplateDeductionInfo Info(CandidateSet.getLocation(),
+ FunctionTemplate->getTemplateDepth());
   FunctionDecl *Specialization = nullptr;
   ConversionSequenceList Conversions;
   if (TemplateDeductionResult Result = DeduceTemplateArguments(
diff --git a/clang/test/SemaTemplate/concepts-recovery-expr.cpp 
b/clang/test/SemaTemplate/concepts-recovery-expr.cpp
index 2f9d432ebac0e..b338f3bc271bf 100644
--- a/clang/test/SemaTemplate/concepts-recovery-expr.cpp
+++ b/clang/test/SemaTemplate/concepts-recovery-expr.cpp
@@ -180,3 +180,30 @@ void StaticMemOVCUse() {
   // expected-note@#SMEMOVC3 {{candidate template ignored: constraints not 
satisfied}}
   // expected-note@#SMEMOVC3REQ{{because substituted constraint expression is 
ill-formed: constraint depends on a previously diagnosed expression}}
 }
+
+namespace GH58548 {
+
+template  struct formatter; // #primary-template
+template  struct basic_format_context {};
+
+template 
+concept has_format_function =
+format(basic_format_context());
+
+template 
+  requires has_format_function
+struct formatter {
+  template 
+  CharType format(basic_format_context);
+};
+
+template  int handle_replacement_field(Ctx arg) {
+  formatter ctx; // expected-error {{implicit 
instantiation of undefined template}}
+  return 0;
+}
+
+int x = handle_replacement_field(0);
+// expected-note@-1 {{template specialization 
'GH58548::handle_replacement_field' requested here}}
+// expected-note@#primary-template {{is declared here}}
+
+} // GH58548

>From 4b0ad32d98e2e8f515db2e6163aa3a7394d76ccf Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 2 Feb 2024 15:38:56 +0800
Subject: [PATCH 2/2] fixup

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f4c5c3421f2e8..67661b9d94db9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -185,7 +185,7 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fixed an out-of-bounds error caused by building a recovery expression for 
ill-formed
   function calls while substituting into constraints.
-  (`https://github.com/llvm/llvm-project/issues/58548`_)
+  (`#58548 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 

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


[flang] [libc] [clang-tools-extra] [clang] [llvm] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (PR #80395)

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

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


[clang] [clang] Fix a possible out-of-bounds read (PR #80023)

2024-02-02 Thread via cfe-commits


@@ -1251,7 +1251,7 @@ highlightLines(StringRef FileData, unsigned 
StartLineNumber,
 unsigned LineLength = 0;
 for (unsigned I = 0; I <= Spelling.size(); ++I) {
   // This line is done.
-  if (isVerticalWhitespace(Spelling[I]) || I == Spelling.size()) {
+  if (I == Spelling.size() || isVerticalWhitespace(Spelling.at(I))) {

cor3ntin wrote:

The bug was the order of the instruction,  the `at` is not doing anything 
useful here here. checking the size first should be necessary and sufficient.

The interesting question is why that wasn't caught by tools?
We have a repro? ( I don't insist on having one to land that though)


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


[clang] c07fcd4 - [Coverage] Map regions from system headers (#76950)

2024-02-02 Thread NAKAMURA Takumi via cfe-commits

Author: ManuelvOK
Date: 2024-02-02T18:04:24+09:00
New Revision: c07fcd45f140bb95fb0f1ed10468db2bb6b1a77b

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

LOG: [Coverage] Map regions from system headers (#76950)

In 2155195131a57f2f01e7cfabb85bb027518c2dc6, the
"system-headers-coverage" option has been added but not used in all
necessary places.

This is the recommit since it has been reverted in
faef68bca852d08511ea0311d8a0d221cb202e73

Potential reviewers: @gulfemsavrun @petrhosek

Co-authored-by: Manuel Kalettka 

Added: 


Modified: 
clang/lib/CodeGen/CodeGenPGO.cpp
clang/lib/CodeGen/CoverageMappingGen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenPGO.cpp 
b/clang/lib/CodeGen/CodeGenPGO.cpp
index d68844d476eb4..5d7c384774576 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -28,6 +28,8 @@ static llvm::cl::opt
  llvm::cl::desc("Enable value profiling"),
  llvm::cl::Hidden, llvm::cl::init(false));
 
+extern llvm::cl::opt SystemHeadersCoverage;
+
 using namespace clang;
 using namespace CodeGen;
 
@@ -1022,7 +1024,7 @@ bool CodeGenPGO::skipRegionMappingForDecl(const Decl *D) {
   // Don't map the functions in system headers.
   const auto &SM = CGM.getContext().getSourceManager();
   auto Loc = D->getBody()->getBeginLoc();
-  return SM.isInSystemHeader(Loc);
+  return !SystemHeadersCoverage && SM.isInSystemHeader(Loc);
 }
 
 void CodeGenPGO::emitCounterRegionMapping(const Decl *D) {

diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index f7f73546af017..0c43317642bca 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -37,7 +37,7 @@ static llvm::cl::opt EmptyLineCommentCoverage(
"disable it on test)"),
 llvm::cl::init(true), llvm::cl::Hidden);
 
-static llvm::cl::opt SystemHeadersCoverage(
+llvm::cl::opt SystemHeadersCoverage(
 "system-headers-coverage",
 llvm::cl::desc("Enable collecting coverage from system headers"),
 llvm::cl::init(false), llvm::cl::Hidden);



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


[clang] [Coverage] Map regions from system headers (PR #76950)

2024-02-02 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

I have restored this since our issue has been resolved in #80292.

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


[clang] [openmp] [llvm] [clang-tools-extra] Fix Issue #76121 [OpenMP] [Flang] Program crashes at runtime (PR #76122)

2024-02-02 Thread via cfe-commits

shivaramaarao wrote:

> This is not the right fix. Something else is broken, this just hides it. 
> Following the link in the commit message, it clearly shows the segfault is at 
> a place that is guarded by argc > 4 (or similar), which should not be 
> executed. I strongly suspect something else is already broken when this 
> happens. We most certainly have run this code from C/C++ successfully on all 
> archs.

@jdoerfert 

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


[clang] [Clang][CodeGen] Mark `__dynamic_cast` as `willreturn` (PR #80409)

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

https://github.com/dtcxzyw created 
https://github.com/llvm/llvm-project/pull/80409

According to the C++ standard, `dynamic_cast` of pointers either returns a 
pointer (7.6.1.7) or results in undefined behavior (11.9.5). This patch marks 
`__dynamic_cast` as `willreturn` to remove unused calls.

Fixes #77606.

>From f96205dbcdbc5bb89a95cd563e47a4bb3616d843 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Fri, 2 Feb 2024 16:14:54 +0800
Subject: [PATCH] [Clang][CodeGen] Mark `__dynamic_cast` as `willreturn`

---
 clang/lib/CodeGen/ItaniumCXXABI.cpp  | 3 ++-
 clang/test/CodeGenCXX/dynamic-cast-address-space.cpp | 2 +-
 clang/test/CodeGenCXX/dynamic-cast-dead.cpp  | 8 
 clang/test/CodeGenCXX/dynamic-cast.cpp   | 2 +-
 4 files changed, 12 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/dynamic-cast-dead.cpp

diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index d173806ec8ce5..60b45ee78d931 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1347,9 +1347,10 @@ static llvm::FunctionCallee 
getItaniumDynamicCastFn(CodeGenFunction &CGF) {
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
 
-  // Mark the function as nounwind readonly.
+  // Mark the function as nounwind willreturn readonly.
   llvm::AttrBuilder FuncAttrs(CGF.getLLVMContext());
   FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
+  FuncAttrs.addAttribute(llvm::Attribute::WillReturn);
   FuncAttrs.addMemoryAttr(llvm::MemoryEffects::readOnly());
   llvm::AttributeList Attrs = llvm::AttributeList::get(
   CGF.getLLVMContext(), llvm::AttributeList::FunctionIndex, FuncAttrs);
diff --git a/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp 
b/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
index c278988c9647b..83a408984b760 100644
--- a/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
+++ b/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -20,5 +20,5 @@ const B& f(A *a) {
 
 // CHECK: declare ptr @__dynamic_cast(ptr, ptr addrspace(1), ptr addrspace(1), 
i64) [[NUW_RO:#[0-9]+]]
 
-// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NUW_RO]] = { nounwind willreturn memory(read) }
 // CHECK: attributes [[NR]] = { noreturn }
diff --git a/clang/test/CodeGenCXX/dynamic-cast-dead.cpp 
b/clang/test/CodeGenCXX/dynamic-cast-dead.cpp
new file mode 100644
index 0..8154cc1ba123a
--- /dev/null
+++ b/clang/test/CodeGenCXX/dynamic-cast-dead.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -I%S %s -O3 -triple x86_64-apple-darwin10 -emit-llvm 
-fcxx-exceptions -fexceptions -std=c++11 -o - | FileCheck %s
+struct A { virtual ~A(); };
+struct B : A { };
+
+void foo(A* a) {
+  // CHECK-NOT: call {{.*}} @__dynamic_cast
+  B* b = dynamic_cast(a);
+}
diff --git a/clang/test/CodeGenCXX/dynamic-cast.cpp 
b/clang/test/CodeGenCXX/dynamic-cast.cpp
index 1d36376a55bc7..b39186c85b60a 100644
--- a/clang/test/CodeGenCXX/dynamic-cast.cpp
+++ b/clang/test/CodeGenCXX/dynamic-cast.cpp
@@ -20,5 +20,5 @@ const B& f(A *a) {
 
 // CHECK: declare ptr @__dynamic_cast(ptr, ptr, ptr, i64) [[NUW_RO:#[0-9]+]]
 
-// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NUW_RO]] = { nounwind willreturn memory(read) }
 // CHECK: attributes [[NR]] = { noreturn }

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


[clang] [Clang][CodeGen] Mark `__dynamic_cast` as `willreturn` (PR #80409)

2024-02-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Yingwei Zheng (dtcxzyw)


Changes

According to the C++ standard, `dynamic_cast` of pointers either returns a 
pointer (7.6.1.7) or results in undefined behavior (11.9.5). This patch marks 
`__dynamic_cast` as `willreturn` to remove unused calls.

Fixes #77606.

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


4 Files Affected:

- (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+2-1) 
- (modified) clang/test/CodeGenCXX/dynamic-cast-address-space.cpp (+1-1) 
- (added) clang/test/CodeGenCXX/dynamic-cast-dead.cpp (+8) 
- (modified) clang/test/CodeGenCXX/dynamic-cast.cpp (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index d173806ec8ce5..60b45ee78d931 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1347,9 +1347,10 @@ static llvm::FunctionCallee 
getItaniumDynamicCastFn(CodeGenFunction &CGF) {
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
 
-  // Mark the function as nounwind readonly.
+  // Mark the function as nounwind willreturn readonly.
   llvm::AttrBuilder FuncAttrs(CGF.getLLVMContext());
   FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
+  FuncAttrs.addAttribute(llvm::Attribute::WillReturn);
   FuncAttrs.addMemoryAttr(llvm::MemoryEffects::readOnly());
   llvm::AttributeList Attrs = llvm::AttributeList::get(
   CGF.getLLVMContext(), llvm::AttributeList::FunctionIndex, FuncAttrs);
diff --git a/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp 
b/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
index c278988c9647b..83a408984b760 100644
--- a/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
+++ b/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -20,5 +20,5 @@ const B& f(A *a) {
 
 // CHECK: declare ptr @__dynamic_cast(ptr, ptr addrspace(1), ptr addrspace(1), 
i64) [[NUW_RO:#[0-9]+]]
 
-// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NUW_RO]] = { nounwind willreturn memory(read) }
 // CHECK: attributes [[NR]] = { noreturn }
diff --git a/clang/test/CodeGenCXX/dynamic-cast-dead.cpp 
b/clang/test/CodeGenCXX/dynamic-cast-dead.cpp
new file mode 100644
index 0..8154cc1ba123a
--- /dev/null
+++ b/clang/test/CodeGenCXX/dynamic-cast-dead.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -I%S %s -O3 -triple x86_64-apple-darwin10 -emit-llvm 
-fcxx-exceptions -fexceptions -std=c++11 -o - | FileCheck %s
+struct A { virtual ~A(); };
+struct B : A { };
+
+void foo(A* a) {
+  // CHECK-NOT: call {{.*}} @__dynamic_cast
+  B* b = dynamic_cast(a);
+}
diff --git a/clang/test/CodeGenCXX/dynamic-cast.cpp 
b/clang/test/CodeGenCXX/dynamic-cast.cpp
index 1d36376a55bc7..b39186c85b60a 100644
--- a/clang/test/CodeGenCXX/dynamic-cast.cpp
+++ b/clang/test/CodeGenCXX/dynamic-cast.cpp
@@ -20,5 +20,5 @@ const B& f(A *a) {
 
 // CHECK: declare ptr @__dynamic_cast(ptr, ptr, ptr, i64) [[NUW_RO:#[0-9]+]]
 
-// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NUW_RO]] = { nounwind willreturn memory(read) }
 // CHECK: attributes [[NR]] = { noreturn }

``




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


[clang] [Clang][CodeGen] Mark `__dynamic_cast` as `willreturn` (PR #80409)

2024-02-02 Thread Nikita Popov via cfe-commits

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

LGTM, nice find!

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


[clang] [libc] [flang] [clang-tools-extra] [llvm] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (PR #80395)

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

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


[clang] 73e5466 - [clang][Interp] Fix up broken test case

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

Author: Timm Bäder
Date: 2024-02-02T10:11:29+01:00
New Revision: 73e546625d6567e5a33454741d257b6929c89635

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

LOG: [clang][Interp] Fix up broken test case

This was not working right on armv8:
https://lab.llvm.org/buildbot/#/builders/245/builds/20020

Added: 


Modified: 
clang/test/AST/Interp/c.c

Removed: 




diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 0b673253c6c70..65d83eab2ea19 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -113,20 +113,17 @@ int somefunc(int i) {
 
 /// FIXME: The following test is incorrect in the new interpreter.
 /// The null pointer returns 16 from its getIntegerRepresentation().
+#pragma clang diagnostic ignored "-Wpointer-to-int-cast"
 struct ArrayStruct {
   char n[1];
 };
 struct AA {
-  char name2[(int)&((struct ArrayStruct*)0)->n - 1]; // expected-warning 
{{cast to smaller integer type}} \
- // expected-warning 
{{folded to constant array}} \
- // 
pedantic-expected-warning {{cast to smaller integer type}} \
+  char name2[(int)&((struct ArrayStruct*)0)->n - 1]; // expected-warning 
{{folded to constant array}} \
  // 
pedantic-expected-warning {{folded to constant array}} \
  // ref-error {{array size 
is negative}} \
- // ref-warning {{cast to 
smaller integer type}} \
- // pedantic-ref-error 
{{array size is negative}} \
- // pedantic-ref-warning 
{{cast to smaller integer type}}
+ // pedantic-ref-error 
{{array size is negative}}
 };
 _Static_assert(sizeof(struct AA) == 15, ""); // ref-error {{failed}} \
- // ref-note {{1 == 15}} \
+ // ref-note {{ == 15}} \
  // pedantic-ref-error {{failed}} \
- // pedantic-ref-note {{1 == 15}}
+ // pedantic-ref-note {{ == 15}}



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


[clang] [clang] Fix a possible out-of-bounds read (PR #80023)

2024-02-02 Thread Timm Baeder via cfe-commits


@@ -1251,7 +1251,7 @@ highlightLines(StringRef FileData, unsigned 
StartLineNumber,
 unsigned LineLength = 0;
 for (unsigned I = 0; I <= Spelling.size(); ++I) {
   // This line is done.
-  if (isVerticalWhitespace(Spelling[I]) || I == Spelling.size()) {
+  if (I == Spelling.size() || isVerticalWhitespace(Spelling.at(I))) {

tbaederr wrote:

Well it would've been caught earlier if it had been using `at()` in the first 
place.

> We have a repro? ( I don't insist on having one to land that though)

Even though I have assertions and sanitizers (but not msan) enabled locally, 
the `Spelling[I]` did not crash for me or cause anything else in the `I == 
Spelling.size()` case.


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


[clang] [openmp] [llvm] [clang-tools-extra] Fix Issue #76121 [OpenMP] [Flang] Program crashes at runtime (PR #76122)

2024-02-02 Thread via cfe-commits

shivaramaarao wrote:

These cmov instructions load the operand irrespective of condition 
satisfaction. 

=>  cmpq$4, %rax  
=>  cmovnsq 24(%r11), %r9   

 here r11 is 0 and 24(0) will be loaded even if argc < 4 and hence we get 
this crash. if we pass the address of argv, we will get a valid address to load.

   I think we need to add a check for argc <=0 in this function. But, there may 
be performance implications with this extra check.


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


[clang] [X86] [iamcu] Fix wrong alignment value for attr (aligned) with -miamcu (PR #80401)

2024-02-02 Thread via cfe-commits

https://github.com/joyhou-hw updated 
https://github.com/llvm/llvm-project/pull/80401

>From e476b28fa123822c695beb5c0ba0f2c381df0e95 Mon Sep 17 00:00:00 2001
From: houzhenyu 
Date: Fri, 2 Feb 2024 11:21:50 +0800
Subject: [PATCH] [X86] [iamcu] Fix wrong alignment value for attr (aligned)
 with -miamcu

attribute ((aligned)) should be 4 for -miamcu.
---
 clang/lib/Basic/Targets/X86.h  |  1 +
 clang/test/Sema/attr-aligned.c | 10 ++
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 1845f5a747af4..0026d8781c8fa 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -672,6 +672,7 @@ class LLVM_LIBRARY_VISIBILITY MCUX86_32TargetInfo : public 
X86_32TargetInfo {
   MCUX86_32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : X86_32TargetInfo(Triple, Opts) {
 LongDoubleWidth = 64;
+DefaultAlignForAttributeAligned = 32;
 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
 resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:32-"
 "f64:32-f128:32-n8:16:32-a:0:32-S32");
diff --git a/clang/test/Sema/attr-aligned.c b/clang/test/Sema/attr-aligned.c
index 130840d46650d..b285ce3d0ed78 100644
--- a/clang/test/Sema/attr-aligned.c
+++ b/clang/test/Sema/attr-aligned.c
@@ -1,4 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple i586-intel-elfiamcu -fsyntax-only -verify %s
+
+#ifdef __iamcu
+// expected-no-diagnostics
+struct dummy { int x __attribute__((aligned));  };
+int m0[__alignof__(struct dummy) == 4 ? 1 : -1];
+
+#else
 
 int x __attribute__((aligned(3))); // expected-error {{requested alignment is 
not a power of 2}}
 int y __attribute__((aligned(1ull << 33))); // expected-error {{requested 
alignment must be 4294967296 bytes or smaller}}
@@ -60,3 +68,5 @@ array_with_overaligned_struct F2;
 char f2[__alignof__(F2) == 16 ? 1 : -1] = { 0 };
 array_with_align_attr F3;
 char f3[__alignof__(F3) == 16 ? 1 : -1] = { 0 };
+
+#endif

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


[clang] [clang] Fix a possible out-of-bounds read (PR #80023)

2024-02-02 Thread via cfe-commits


@@ -1251,7 +1251,7 @@ highlightLines(StringRef FileData, unsigned 
StartLineNumber,
 unsigned LineLength = 0;
 for (unsigned I = 0; I <= Spelling.size(); ++I) {
   // This line is done.
-  if (isVerticalWhitespace(Spelling[I]) || I == Spelling.size()) {
+  if (I == Spelling.size() || isVerticalWhitespace(Spelling.at(I))) {

cor3ntin wrote:

I won't insist but I'd rather remove the at.
It occurs to me that between the lack of warnings, and the fact that unit tests 
probably have color disabled, this won't be easy to test oh well

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


[clang] [clang] Fix a possible out-of-bounds read (PR #80023)

2024-02-02 Thread via cfe-commits

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


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


[clang] [lldb] [libc] [flang] [lld] [clang-tools-extra] [libcxx] [llvm] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

2024-02-02 Thread David Stuttard via cfe-commits

https://github.com/dstutt updated 
https://github.com/llvm/llvm-project/pull/67104

>From 259138920126f09149b488fc54e8d2a7da969ca4 Mon Sep 17 00:00:00 2001
From: David Stuttard 
Date: Thu, 24 Aug 2023 16:45:50 +0100
Subject: [PATCH 1/4] [AMDGPU] Add pal metadata 3.0 support to callable pal
 funcs

---
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp   |  28 +-
 .../AMDGPU/pal-metadata-3.0-callable.ll   | 290 ++
 2 files changed, 314 insertions(+), 4 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index b2360ce30fd6e..22ecd3656d00a 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -1098,10 +1098,30 @@ void AMDGPUAsmPrinter::emitPALFunctionMetadata(const 
MachineFunction &MF) {
   StringRef FnName = MF.getFunction().getName();
   MD->setFunctionScratchSize(FnName, MFI.getStackSize());
 
-  // Set compute registers
-  MD->setRsrc1(CallingConv::AMDGPU_CS,
-   CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
-  MD->setRsrc2(CallingConv::AMDGPU_CS, 
CurrentProgramInfo.getComputePGMRSrc2());
+  if (MD->getPALMajorVersion() < 3) {
+// Set compute registers
+MD->setRsrc1(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
+MD->setRsrc2(CallingConv::AMDGPU_CS,
+ CurrentProgramInfo.getComputePGMRSrc2());
+  } else {
+MD->setHwStage(CallingConv::AMDGPU_CS, ".ieee_mode",
+   (bool)CurrentProgramInfo.IEEEMode);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".wgp_mode",
+   (bool)CurrentProgramInfo.WgpMode);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".mem_ordered",
+   (bool)CurrentProgramInfo.MemOrdered);
+
+MD->setHwStage(CallingConv::AMDGPU_CS, ".trap_present",
+   (bool)CurrentProgramInfo.TrapHandlerEnable);
+MD->setHwStage(CallingConv::AMDGPU_CS, ".excp_en",
+   CurrentProgramInfo.EXCPEnable);
+
+const unsigned LdsDwGranularity = 128;
+MD->setHwStage(CallingConv::AMDGPU_CS, ".lds_size",
+   (unsigned)(CurrentProgramInfo.LdsSize * LdsDwGranularity *
+  sizeof(uint32_t)));
+  }
 
   // Set optional info
   MD->setFunctionLdsSize(FnName, CurrentProgramInfo.LDSSize);
diff --git a/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll 
b/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll
new file mode 100644
index 0..d4a5f61aced61
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0-callable.ll
@@ -0,0 +1,290 @@
+; RUN: llc -mtriple=amdgcn--amdpal -mcpu=gfx1100 -verify-machineinstrs < %s | 
FileCheck %s
+
+; CHECK:   .amdgpu_pal_metadata
+; CHECK-NEXT: ---
+; CHECK-NEXT: amdpal.pipelines:
+; CHECK-NEXT:  - .api:Vulkan
+; CHECK-NEXT:.compute_registers:
+; CHECK-NEXT:  .tg_size_en: true
+; CHECK-NEXT:  .tgid_x_en:  false
+; CHECK-NEXT:  .tgid_y_en:  false
+; CHECK-NEXT:  .tgid_z_en:  false
+; CHECK-NEXT:  .tidig_comp_cnt: 0x1
+; CHECK-NEXT:.hardware_stages:
+; CHECK-NEXT:  .cs:
+; CHECK-NEXT:.checksum_value: 0x9444d7d0
+; CHECK-NEXT:.debug_mode: 0
+; CHECK-NEXT:.excp_en:0
+; CHECK-NEXT:.float_mode: 0xc0
+; CHECK-NEXT:.ieee_mode:  true
+; CHECK-NEXT:.image_op:   false
+; CHECK-NEXT:.lds_size:   0x200
+; CHECK-NEXT:.mem_ordered:true
+; CHECK-NEXT:.sgpr_limit: 0x6a
+; CHECK-NEXT:.threadgroup_dimensions:
+; CHECK-NEXT:  - 0x1
+; CHECK-NEXT:  - 0x400
+; CHECK-NEXT:  - 0x1
+; CHECK-NEXT:.trap_present:   false
+; CHECK-NEXT:.user_data_reg_map:
+; CHECK-NEXT:  - 0x1000
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT:  - 0x
+; CHECK-NEXT

[clang-tools-extra] [clang] [flang] [libc] [llvm] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (PR #80395)

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

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


[clang] 9e64951 - [Clang][AArch64] Add missing SME macros (#80293)

2024-02-02 Thread via cfe-commits

Author: Sander de Smalen
Date: 2024-02-02T09:29:47Z
New Revision: 9e649518e6038a5b9ea38cfa424468657d3be59e

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

LOG: [Clang][AArch64] Add missing SME macros (#80293)

__ARM_STATE_ZA and __ARM_STATE_ZT0 are set when the compiler can parse 
the "za" and "zt0" strings in the SME attributes.

__ARM_FEATURE_SME and __ARM_FEATURE_SME2 are set when the compiler can 
generate code for attributes with "za" and "zt0" state, respectively.

__ARM_FEATURE_LOCALLY_STREAMING is set when the compiler supports the
__arm_locally_streaming attribute.

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/test/Preprocessor/aarch64-target-features.c
clang/test/Preprocessor/init-aarch64.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index d2c06f7191bfc..68032961451d9 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -386,6 +386,11 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 
   Builder.defineMacro("__ARM_ALIGN_MAX_STACK_PWR", "4");
 
+  // These macros are set when Clang can parse declarations with these
+  // attributes.
+  Builder.defineMacro("__ARM_STATE_ZA", "1");
+  Builder.defineMacro("__ARM_STATE_ZT0", "1");
+
   // 0xe implies support for half, single and double precision operations.
   if (FPU & FPUMode)
 Builder.defineMacro("__ARM_FP", "0xE");
@@ -430,6 +435,17 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasSVE2 && HasSVE2SM4)
 Builder.defineMacro("__ARM_FEATURE_SVE2_SM4", "1");
 
+  if (HasSME) {
+Builder.defineMacro("__ARM_FEATURE_SME");
+Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
+  }
+
+  if (HasSME2) {
+Builder.defineMacro("__ARM_FEATURE_SME");
+Builder.defineMacro("__ARM_FEATURE_SME2");
+Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
+  }
+
   if (HasCRC)
 Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 
@@ -692,6 +708,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const 
{
   .Case("sve2-sha3", FPU & SveMode && HasSVE2SHA3)
   .Case("sve2-sm4", FPU & SveMode && HasSVE2SM4)
   .Case("sme", HasSME)
+  .Case("sme2", HasSME2)
   .Case("sme-f64f64", HasSMEF64F64)
   .Case("sme-i16i64", HasSMEI16I64)
   .Case("sme-fa64", HasSMEFA64)
@@ -812,6 +829,12 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasBFloat16 = true;
   HasFullFP16 = true;
 }
+if (Feature == "+sme2") {
+  HasSME = true;
+  HasSME2 = true;
+  HasBFloat16 = true;
+  HasFullFP16 = true;
+}
 if (Feature == "+sme-f64f64") {
   HasSME = true;
   HasSMEF64F64 = true;

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 7761812295ffa..26ee7fa197825 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -68,6 +68,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool HasCCDP = false;
   bool HasFRInt3264 = false;
   bool HasSME = false;
+  bool HasSME2 = false;
   bool HasSMEF64F64 = false;
   bool HasSMEI16I64 = false;
   bool HasSB = false;

diff  --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index 43402225f0689..41fb26e04ef69 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -60,6 +60,10 @@
 // CHECK-NOT: __ARM_FEATURE_SVE_BITS 512
 // CHECK-NOT: __ARM_FEATURE_SVE_BITS 1024
 // CHECK-NOT: __ARM_FEATURE_SVE_BITS 2048
+// CHECK: __ARM_STATE_ZA 1
+// CHECK: __ARM_STATE_ZT0 1
+// CHECK-NOT: __ARM_FEATURE_SME
+// CHECK-NOT: __ARM_FEATURE_SME2
 
 // RUN: %clang -target aarch64-none-elf -march=armv8-r -x c -E -dM %s -o - | 
FileCheck %s -check-prefix CHECK-R-PROFILE
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-r -x c -E -dM %s -o - 
| FileCheck %s -check-prefix CHECK-R-PROFILE
@@ -672,3 +676,12 @@
 
 // RUN: %clang --target=aarch64 -march=armv8.2-a+rcpc3 -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-RCPC3 %s
 // CHECK-RCPC3: __ARM_FEATURE_RCPC 3
+
+// RUN: %clang --target=aarch64 -march=armv9-a+sme -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-SME %s
+// CHECK-SME: __ARM_FEATURE_LOCALLY_STREAMING 1
+// CHECK-SME: __ARM_FEATURE_SME 1
+//
+// RUN: %clang --target=aarch64 -march=armv9-a+sme2 -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-SME2 %s
+// CHECK-SME2: __ARM_FEATURE_LOCALLY_STREAMING 1
+// CHECK-SME2: __ARM_FEATURE_SME 1
+// CHECK-SME2: __ARM_FEATURE_SME2 1

diff  --git a/clang/test/Preprocessor/init-aarch64.c 
b/clang/tes

[clang] [Clang][AArch64] Add missing SME macros (PR #80293)

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

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


[clang-tools-extra] [clang] [flang] [libc] [llvm] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (PR #80395)

2024-02-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

This is yet another one-line patch to fix crashes on constraint substitution.

```cpp
template  struct formatter;

template  struct basic_format_context {};

template 
concept has_format_function = format(basic_format_context());

template 
  requires has_format_function
struct formatter {
  template 
  CharType format(basic_format_context);
};
```

In this case, we would build up a `RecoveryExpr` for a call within a constraint 
expression due to the absence of viable functions. The heuristic algorithm 
attempted to find such a function inside of a 
ClassTemplatePartialSpecialization, from which we started to substitute its 
requires-expression, and it succeeded with a FunctionTemplate such that

1) It has only one parameter, which is dependent.
2) The only one parameter depends on two template parameters. They are, in 
canonical form, `` and 
`` respectively.

Before we emit an error, we still want to recover the most viable functions. 
This goes downhill to deducing template parameters against its arguments, where 
we would collect the argument type with the same depth as the parameter type 
into a Deduced set. The size of the set is presumed to be that of function 
template parameters, which is 1 in this case. However, since we haven't yet 
properly set the template depth before the dance, we'll end up putting the type 
for `` to the second position of Deduced set, 
which is unfortunately an access violation!

The bug seems to appear since clang 12.0.

This should fix https://github.com/llvm/llvm-project/issues/58548.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+2-1) 
- (modified) clang/test/SemaTemplate/concepts-recovery-expr.cpp (+27) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 53040aa0f9074..028afba2de6cd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -186,6 +186,9 @@ Bug Fixes to C++ Support
 - Fix for crash when using a erroneous type in a return statement.
   Fixes (`#63244 `_)
   and (`#79745 `_)
+- Fixed an out-of-bounds error caused by building a recovery expression for 
ill-formed
+  function calls while substituting into constraints.
+  (`#58548 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 940bcccb9e261..6a04d68b4f041 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7623,7 +7623,8 @@ void Sema::AddTemplateOverloadCandidate(
   //   functions. In such a case, the candidate functions generated from each
   //   function template are combined with the set of non-template candidate
   //   functions.
-  TemplateDeductionInfo Info(CandidateSet.getLocation());
+  TemplateDeductionInfo Info(CandidateSet.getLocation(),
+ FunctionTemplate->getTemplateDepth());
   FunctionDecl *Specialization = nullptr;
   ConversionSequenceList Conversions;
   if (TemplateDeductionResult Result = DeduceTemplateArguments(
diff --git a/clang/test/SemaTemplate/concepts-recovery-expr.cpp 
b/clang/test/SemaTemplate/concepts-recovery-expr.cpp
index 2f9d432ebac0e..b338f3bc271bf 100644
--- a/clang/test/SemaTemplate/concepts-recovery-expr.cpp
+++ b/clang/test/SemaTemplate/concepts-recovery-expr.cpp
@@ -180,3 +180,30 @@ void StaticMemOVCUse() {
   // expected-note@#SMEMOVC3 {{candidate template ignored: constraints not 
satisfied}}
   // expected-note@#SMEMOVC3REQ{{because substituted constraint expression is 
ill-formed: constraint depends on a previously diagnosed expression}}
 }
+
+namespace GH58548 {
+
+template  struct formatter; // #primary-template
+template  struct basic_format_context {};
+
+template 
+concept has_format_function =
+format(basic_format_context());
+
+template 
+  requires has_format_function
+struct formatter {
+  template 
+  CharType format(basic_format_context);
+};
+
+template  int handle_replacement_field(Ctx arg) {
+  formatter ctx; // expected-error {{implicit 
instantiation of undefined template}}
+  return 0;
+}
+
+int x = handle_replacement_field(0);
+// expected-note@-1 {{template specialization 
'GH58548::handle_replacement_field' requested here}}
+// expected-note@#

[clang-tools-extra] [clang] [flang] [libc] [llvm] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (PR #80395)

2024-02-02 Thread via cfe-commits

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

Looks great, Thanks!


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


[clang-tools-extra] [clang] [flang] [libc] [llvm] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (PR #80395)

2024-02-02 Thread via cfe-commits

cor3ntin wrote:

if that's impacting std::format we might want to backport @AaronBallman 
@erichkeane 

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


[llvm] [clang-tools-extra] [clang] [AMDGPU] Add IR-level pass to rewrite away address space 7 (PR #77952)

2024-02-02 Thread Piotr Sobczak via cfe-commits


@@ -0,0 +1,1983 @@
+//===-- AMDGPULowerBufferFatPointers.cpp ---=//
+//
+// 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
+//
+//===--===//
+//
+// This pass lowers operations on buffer fat pointers (addrspace 7) to
+// operations on buffer resources (addrspace 8) and is needed for correct
+// codegen.
+//
+// # Background
+//
+// Address space 7 (the buffer fat pointer) is a 160-bit pointer that consists
+// of a 128-bit buffer descriptor and a 32-bit offset into that descriptor.
+// The buffer resource part needs to be it needs to be a "raw" buffer resource
+// (it must have a stride of 0 and bounds checks must be in raw buffer mode
+// or disabled).
+//
+// When these requirements are met, a buffer resource can be treated as a
+// typical (though quite wide) pointer that follows typical LLVM pointer
+// semantics. This allows the frontend to reason about such buffers (which are
+// often encountered in the context of SPIR-V kernels).
+//
+// However, because of their non-power-of-2 size, these fat pointers cannot be
+// present during translation to MIR (though this restriction may be lifted
+// during the transition to GlobalISel). Therefore, this pass is needed in 
order
+// to correctly implement these fat pointers.
+//
+// The resource intrinsics take the resource part (the address space 8 pointer)
+// and the offset part (the 32-bit integer) as separate arguments. In addition,
+// many users of these buffers manipulate the offset while leaving the resource
+// part alone. For these reasons, we want to typically separate the resource
+// and offset parts into separate variables, but combine them together when
+// encountering cases where this is required, such as by inserting these values
+// into aggretates or moving them to memory.
+//
+// Therefore, at a high level, `ptr addrspace(7) %x` becomes `ptr addrspace(8)
+// %x.rsrc` and `i32 %x.off`, which will be combined into `{ptr addrspace(8),
+// i32} %x = {%x.rsrc, %x.off}` if needed. Similarly, `vector` becomes
+// `{vector, vector}` and its component parts.
+//
+// # Implementation
+//
+// This pass proceeds in three main phases:
+//
+// ## Rewriting loads and stores of p7
+//
+// The first phase is to rewrite away all loads and stors of `ptr 
addrspace(7)`,
+// including aggregates containing such pointers, to ones that use `i160`. This
+// is handled by `StoreFatPtrsAsIntsVisitor` , which visits loads, stores, and
+// allocas and, if the loaded or stored type contains `ptr addrspace(7)`,
+// rewrites that type to one where the p7s are replaced by i160s, copying other
+// parts of aggregates as needed. In the case of a store, each pointer is
+// `ptrtoint`d to i160 before storing, and load integers are `inttoptr`d back.
+// This same transformation is applied to vectors of pointers.
+//
+// Such a transformation allows the later phases of the pass to not need
+// to handle buffer fat pointers moving to and from memory, where we load
+// have to handle the incompatibility between a `{Nxp8, Nxi32}` representation
+// and `Nxi60` directly. Instead, that transposing action (where the vectors
+// of resources and vectors of offsets are concatentated before being stored to
+// memory) are handled through implementing `inttoptr` and `ptrtoint` only.
+//
+// Atomics operations on `ptr addrspace(7)` values are not suppported, as the
+// hardware does not include a 160-bit atomic.
+//
+// ## Type remapping
+//
+// We use a `ValueMapper` to mangle uses of [vectors of] buffer fat pointers
+// to the corresponding struct type, which has a resource part and an offset
+// part.
+//
+// This uses a `BufferFatPtrToStructTypeMap` and a `FatPtrConstMaterializer`
+// to, usually by way of `setType`ing values. Constants are handled here
+// because there isn't a good way to fix them up later.
+//
+// This has the downside of leaving the IR in an invalid state (for example,
+// the instruction `getelementptr {ptr addrspace(8), i32} %p, ...` will exist),
+// but all such invalid states will be resolved by the third phase.
+//
+// Functions that don't take buffer fat pointers are modified in place. Those
+// that do take such pointers have their basic blocks moved to a new function
+// with arguments that are {ptr addrspace(8), i32} arguments and return values.
+// This phase also records intrinsics so that they can be remangled or deleted
+// later.
+//
+//
+// ## Splitting pointer structs
+//
+// The meat of this pass consists of defining semantics for operations that
+// produce or consume [vectors of] buffer fat pointers in terms of their
+// resource and offset parts. This is accomplished throgh the `SplitPtrStructs`
+// visitor.
+//
+// In the first pass through each function that is being lowered, the

[clang] a52e9ec - [Preprocessor] Fix __has_builtin for CPU ID functions (#80058)

2024-02-02 Thread via cfe-commits

Author: Nemanja Ivanovic
Date: 2024-02-02T10:49:45+01:00
New Revision: a52e9eca3001b23c7952300e5a32b5c58ef2e0e2

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

LOG: [Preprocessor] Fix __has_builtin for CPU ID functions (#80058)

My recent commit (67c1c1d) made the CPU ID builtins target-independent
so they can be used on PPC as well. However, that had the unintended
consequence of changing the behaviour of __has_builtin in that it
reports these as supported at the pre-processor level. This makes it
impossible to guard the use of these with this feature test macro which
is clearly not ideal.
This patch restores the behaviour of __has_builtin for __builtin_cpu_is,
__builtin_cpu_init,
__builtin_cpu_supports. Now the preprocessor queries the target to
determine whether the target supports the builtin.

Added: 
clang/test/Preprocessor/has_builtin_cpuid.c

Modified: 
clang/lib/Lex/PPMacroExpansion.cpp

Removed: 




diff  --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index ad02f31209b0b..3017461dc66e8 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1672,6 +1672,12 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
   return false;
 else if (II->getBuiltinID() != 0) {
   switch (II->getBuiltinID()) {
+  case Builtin::BI__builtin_cpu_is:
+return getTargetInfo().supportsCpuIs();
+  case Builtin::BI__builtin_cpu_init:
+return getTargetInfo().supportsCpuInit();
+  case Builtin::BI__builtin_cpu_supports:
+return getTargetInfo().supportsCpuSupports();
   case Builtin::BI__builtin_operator_new:
   case Builtin::BI__builtin_operator_delete:
 // denotes date of behavior change to support calling arbitrary

diff  --git a/clang/test/Preprocessor/has_builtin_cpuid.c 
b/clang/test/Preprocessor/has_builtin_cpuid.c
new file mode 100644
index 0..8de6331e62d6e
--- /dev/null
+++ b/clang/test/Preprocessor/has_builtin_cpuid.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -triple arm64-- -DARM -verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-- -DX86 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple powerpc64-unknown-linux-gnu -DPPC \
+// RUN:   -verify %s
+// expected-no-diagnostics
+#if __has_builtin(__builtin_cpu_is)
+# ifdef ARM
+#   error "ARM shouldn't have __builtin_cpu_is"
+# endif
+#endif
+#if __has_builtin(__builtin_cpu_init)
+# if defined(ARM) || defined(PPC)
+#   error "ARM/PPC shouldn't have __builtin_cpu_init"
+# endif
+#endif
+#if __has_builtin(__builtin_cpu_supports)
+# ifdef ARM
+#   error "ARM shouldn't have __builtin_cpu_supports"
+# endif
+#endif



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


[clang] [Preprocessor] Fix __has_builtin for CPU ID functions (PR #80058)

2024-02-02 Thread Nemanja Ivanovic via cfe-commits

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


[flang] [llvm] [lld] [clang] [AMDGPU] Introduce Code Object V6 (PR #76954)

2024-02-02 Thread via cfe-commits

https://github.com/mikaelholmen updated 
https://github.com/llvm/llvm-project/pull/76954

>From a967fdae9a8557331d2a228f391f39f9e27e8943 Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Thu, 4 Jan 2024 14:12:00 +0100
Subject: [PATCH 1/4] [AMDGPU] Introduce Code Object V6

Introduce Code Object V6 in Clang, LLD, Flang and LLVM.
This is the same as V5 except a new "generic version" flag can be present in 
EFLAGS. This is related to new generic targets that'll be added in a follow-up 
patch. It's also likely V6 will have new changes (possibly new metadata 
entries) added later.

Docs change are not included, I'm planning to do them in a follow-up patch all 
at once (when generic targets land too).
---
 clang/include/clang/Driver/Options.td |   4 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |   6 +-
 clang/lib/Driver/ToolChains/CommonArgs.cpp|   2 +-
 .../amdgpu-code-object-version-linking.cu |  37 +++
 .../CodeGenCUDA/amdgpu-code-object-version.cu |   4 +
 .../test/CodeGenCUDA/amdgpu-workgroup-size.cu |   4 +
 .../amdgcn/bitcode/oclc_abi_version_600.bc|   0
 clang/test/Driver/hip-code-object-version.hip |  12 +
 clang/test/Driver/hip-device-libs.hip |  18 +-
 flang/lib/Frontend/CompilerInvocation.cpp |   2 +
 flang/test/Lower/AMD/code-object-version.f90  |   3 +-
 lld/ELF/Arch/AMDGPU.cpp   |  21 ++
 lld/test/ELF/amdgpu-tid.s |  16 ++
 llvm/include/llvm/BinaryFormat/ELF.h  |   9 +-
 llvm/include/llvm/Support/AMDGPUMetadata.h|   7 +
 llvm/include/llvm/Support/ScopedPrinter.h |   4 +-
 llvm/include/llvm/Target/TargetOptions.h  |   1 +
 llvm/lib/ObjectYAML/ELFYAML.cpp   |   9 +
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp   |   3 +
 .../AMDGPU/AMDGPUHSAMetadataStreamer.cpp  |  10 +
 .../Target/AMDGPU/AMDGPUHSAMetadataStreamer.h |  11 +-
 .../MCTargetDesc/AMDGPUTargetStreamer.cpp |  26 ++
 .../MCTargetDesc/AMDGPUTargetStreamer.h   |   1 +
 .../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp|   6 +
 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h |   2 +-
 ...licit-kernarg-backend-usage-global-isel.ll |   2 +
 .../AMDGPU/call-graph-register-usage.ll   |   1 +
 .../AMDGPU/codegen-internal-only-func.ll  |   3 +
 llvm/test/CodeGen/AMDGPU/elf-header-osabi.ll  |   4 +
 .../enable-scratch-only-dynamic-stack.ll  |   1 +
 .../AMDGPU/implicit-kernarg-backend-usage.ll  |   2 +
 .../AMDGPU/implicitarg-offset-attributes.ll   |  46 
 .../AMDGPU/llvm.amdgcn.implicitarg.ptr.ll |   1 +
 llvm/test/CodeGen/AMDGPU/non-entry-alloca.ll  |   1 +
 llvm/test/CodeGen/AMDGPU/recursion.ll |   1 +
 .../AMDGPU/resource-usage-dead-function.ll|   1 +
 .../AMDGPU/tid-mul-func-xnack-all-any.ll  |   6 +
 .../tid-mul-func-xnack-all-not-supported.ll   |   6 +
 .../AMDGPU/tid-mul-func-xnack-all-off.ll  |   6 +
 .../AMDGPU/tid-mul-func-xnack-all-on.ll   |   6 +
 .../AMDGPU/tid-mul-func-xnack-any-off-1.ll|   6 +
 .../AMDGPU/tid-mul-func-xnack-any-off-2.ll|   6 +
 .../AMDGPU/tid-mul-func-xnack-any-on-1.ll |   6 +
 .../AMDGPU/tid-mul-func-xnack-any-on-2.ll |   6 +
 .../tid-one-func-xnack-not-supported.ll   |   6 +
 .../CodeGen/AMDGPU/tid-one-func-xnack-off.ll  |   6 +
 .../CodeGen/AMDGPU/tid-one-func-xnack-on.ll   |   6 +
 .../MC/AMDGPU/hsa-v5-uses-dynamic-stack.s |   5 +
 .../elf-headers.test} |   0
 .../ELF/AMDGPU/generic_versions.s |  16 ++
 .../ELF/AMDGPU/generic_versions.test  |  26 ++
 llvm/tools/llvm-readobj/ELFDumper.cpp | 224 --
 52 files changed, 483 insertions(+), 135 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/rocm/amdgcn/bitcode/oclc_abi_version_600.bc
 rename llvm/test/tools/llvm-readobj/ELF/{amdgpu-elf-headers.test => 
AMDGPU/elf-headers.test} (100%)
 create mode 100644 llvm/test/tools/llvm-readobj/ELF/AMDGPU/generic_versions.s
 create mode 100644 
llvm/test/tools/llvm-readobj/ELF/AMDGPU/generic_versions.test

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 73071a6648541..fb5f50ef452c2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4801,9 +4801,9 @@ defm amdgpu_ieee : BoolOption<"m", "amdgpu-ieee",
 def mcode_object_version_EQ : Joined<["-"], "mcode-object-version=">, 
Group,
   HelpText<"Specify code object ABI version. Defaults to 5. (AMDGPU only)">,
   Visibility<[ClangOption, FlangOption, CC1Option, FC1Option]>,
-  Values<"none,4,5">,
+  Values<"none,4,5,6">,
   NormalizedValuesScope<"llvm::CodeObjectVersionKind">,
-  NormalizedValues<["COV_None", "COV_4", "COV_5"]>,
+  NormalizedValues<["COV_None", "COV_4", "COV_5", "COV_6"]>,
   MarshallingInfoEnum, "COV_5">;
 
 defm cumode : SimpleMFlag<"cumode",
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 196be813a4896..f17e4a83305bf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGe

[llvm] [clang] [lld] [flang] [AMDGPU] Introduce Code Object V6 (PR #76954)

2024-02-02 Thread Pierre van Houtryve via cfe-commits

https://github.com/Pierre-vh updated 
https://github.com/llvm/llvm-project/pull/76954

>From a967fdae9a8557331d2a228f391f39f9e27e8943 Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Thu, 4 Jan 2024 14:12:00 +0100
Subject: [PATCH 1/4] [AMDGPU] Introduce Code Object V6

Introduce Code Object V6 in Clang, LLD, Flang and LLVM.
This is the same as V5 except a new "generic version" flag can be present in 
EFLAGS. This is related to new generic targets that'll be added in a follow-up 
patch. It's also likely V6 will have new changes (possibly new metadata 
entries) added later.

Docs change are not included, I'm planning to do them in a follow-up patch all 
at once (when generic targets land too).
---
 clang/include/clang/Driver/Options.td |   4 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |   6 +-
 clang/lib/Driver/ToolChains/CommonArgs.cpp|   2 +-
 .../amdgpu-code-object-version-linking.cu |  37 +++
 .../CodeGenCUDA/amdgpu-code-object-version.cu |   4 +
 .../test/CodeGenCUDA/amdgpu-workgroup-size.cu |   4 +
 .../amdgcn/bitcode/oclc_abi_version_600.bc|   0
 clang/test/Driver/hip-code-object-version.hip |  12 +
 clang/test/Driver/hip-device-libs.hip |  18 +-
 flang/lib/Frontend/CompilerInvocation.cpp |   2 +
 flang/test/Lower/AMD/code-object-version.f90  |   3 +-
 lld/ELF/Arch/AMDGPU.cpp   |  21 ++
 lld/test/ELF/amdgpu-tid.s |  16 ++
 llvm/include/llvm/BinaryFormat/ELF.h  |   9 +-
 llvm/include/llvm/Support/AMDGPUMetadata.h|   7 +
 llvm/include/llvm/Support/ScopedPrinter.h |   4 +-
 llvm/include/llvm/Target/TargetOptions.h  |   1 +
 llvm/lib/ObjectYAML/ELFYAML.cpp   |   9 +
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp   |   3 +
 .../AMDGPU/AMDGPUHSAMetadataStreamer.cpp  |  10 +
 .../Target/AMDGPU/AMDGPUHSAMetadataStreamer.h |  11 +-
 .../MCTargetDesc/AMDGPUTargetStreamer.cpp |  26 ++
 .../MCTargetDesc/AMDGPUTargetStreamer.h   |   1 +
 .../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp|   6 +
 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h |   2 +-
 ...licit-kernarg-backend-usage-global-isel.ll |   2 +
 .../AMDGPU/call-graph-register-usage.ll   |   1 +
 .../AMDGPU/codegen-internal-only-func.ll  |   3 +
 llvm/test/CodeGen/AMDGPU/elf-header-osabi.ll  |   4 +
 .../enable-scratch-only-dynamic-stack.ll  |   1 +
 .../AMDGPU/implicit-kernarg-backend-usage.ll  |   2 +
 .../AMDGPU/implicitarg-offset-attributes.ll   |  46 
 .../AMDGPU/llvm.amdgcn.implicitarg.ptr.ll |   1 +
 llvm/test/CodeGen/AMDGPU/non-entry-alloca.ll  |   1 +
 llvm/test/CodeGen/AMDGPU/recursion.ll |   1 +
 .../AMDGPU/resource-usage-dead-function.ll|   1 +
 .../AMDGPU/tid-mul-func-xnack-all-any.ll  |   6 +
 .../tid-mul-func-xnack-all-not-supported.ll   |   6 +
 .../AMDGPU/tid-mul-func-xnack-all-off.ll  |   6 +
 .../AMDGPU/tid-mul-func-xnack-all-on.ll   |   6 +
 .../AMDGPU/tid-mul-func-xnack-any-off-1.ll|   6 +
 .../AMDGPU/tid-mul-func-xnack-any-off-2.ll|   6 +
 .../AMDGPU/tid-mul-func-xnack-any-on-1.ll |   6 +
 .../AMDGPU/tid-mul-func-xnack-any-on-2.ll |   6 +
 .../tid-one-func-xnack-not-supported.ll   |   6 +
 .../CodeGen/AMDGPU/tid-one-func-xnack-off.ll  |   6 +
 .../CodeGen/AMDGPU/tid-one-func-xnack-on.ll   |   6 +
 .../MC/AMDGPU/hsa-v5-uses-dynamic-stack.s |   5 +
 .../elf-headers.test} |   0
 .../ELF/AMDGPU/generic_versions.s |  16 ++
 .../ELF/AMDGPU/generic_versions.test  |  26 ++
 llvm/tools/llvm-readobj/ELFDumper.cpp | 224 --
 52 files changed, 483 insertions(+), 135 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/rocm/amdgcn/bitcode/oclc_abi_version_600.bc
 rename llvm/test/tools/llvm-readobj/ELF/{amdgpu-elf-headers.test => 
AMDGPU/elf-headers.test} (100%)
 create mode 100644 llvm/test/tools/llvm-readobj/ELF/AMDGPU/generic_versions.s
 create mode 100644 
llvm/test/tools/llvm-readobj/ELF/AMDGPU/generic_versions.test

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 73071a6648541..fb5f50ef452c2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4801,9 +4801,9 @@ defm amdgpu_ieee : BoolOption<"m", "amdgpu-ieee",
 def mcode_object_version_EQ : Joined<["-"], "mcode-object-version=">, 
Group,
   HelpText<"Specify code object ABI version. Defaults to 5. (AMDGPU only)">,
   Visibility<[ClangOption, FlangOption, CC1Option, FC1Option]>,
-  Values<"none,4,5">,
+  Values<"none,4,5,6">,
   NormalizedValuesScope<"llvm::CodeObjectVersionKind">,
-  NormalizedValues<["COV_None", "COV_4", "COV_5"]>,
+  NormalizedValues<["COV_None", "COV_4", "COV_5", "COV_6"]>,
   MarshallingInfoEnum, "COV_5">;
 
 defm cumode : SimpleMFlag<"cumode",
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 196be813a4896..f17e4a83305bf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/C

[llvm] [flang] [libc] [clang] [clang-tools-extra] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (PR #80395)

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

zyn0217 wrote:

Thanks for the quick review!
I tested the original bug report without the patch but couldn't reproduce it. 
Nevertheless, the example produced by @royjacobson (which still crashes the 
trunk) was fixed by this patch. 
I'm not sure if this merits a backport?

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


[llvm] [flang] [libc] [clang] [clang-tools-extra] [clang][Sema] Populate function template depth at AddTemplateOverloadCandidate (PR #80395)

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

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


[clang] [clang] Fix a possible out-of-bounds read (PR #80023)

2024-02-02 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/80023

>From 675a369815ab8b328f7ec67732e34d67b342377c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 30 Jan 2024 17:04:23 +0100
Subject: [PATCH] [clang] Fix a possible out-of-bounds read

Fixes #79964
---
 clang/lib/Frontend/TextDiagnostic.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 291d71f6db61f..627a7641308a1 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -1251,7 +1251,7 @@ highlightLines(StringRef FileData, unsigned 
StartLineNumber,
 unsigned LineLength = 0;
 for (unsigned I = 0; I <= Spelling.size(); ++I) {
   // This line is done.
-  if (isVerticalWhitespace(Spelling[I]) || I == Spelling.size()) {
+  if (I == Spelling.size() || isVerticalWhitespace(Spelling[I])) {
 SmallVector &LineRanges =
 SnippetRanges[L - StartLineNumber];
 

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


[clang] [coroutine] Suppress unreachable-code warning on coroutine statements. (PR #77454)

2024-02-02 Thread Haojian Wu via cfe-commits

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

>From 43810d2b18e1e31c5f15dc58c847c83b3c34d982 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Tue, 9 Jan 2024 12:29:45 +0100
Subject: [PATCH 1/3] [coroutine] Suppress unreachable-code warning on
 coroutine statements.

---
 clang/lib/Analysis/ReachableCode.cpp  | 42 +++-
 .../SemaCXX/coroutine-unreachable-warning.cpp | 50 +++
 2 files changed, 91 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/coroutine-unreachable-warning.cpp

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 1bf0d9aec8620..d839d2f999609 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ParentMap.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
@@ -60,6 +61,45 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt 
*S) {
   return false;
 }
 
+// Check if the block starts with a coroutine statement and see if the given
+// unreachable 'S' is the substmt of the coroutine statement.
+//
+// We suppress the unreachable warning for cases where an unreachable code is
+// a substmt of the coroutine statement, becase removing it will change the
+// function semantic if this is the only coroutine statement of the coroutine.
+static bool isInCoroutineStmt(const CFGBlock *Block, const Stmt* S) {
+  // The coroutine statement, co_return, co_await, or co_yield.
+  const Stmt* CoroStmt = nullptr;
+  // Find the first coroutine statement in the block.
+  for (CFGBlock::const_iterator I = Block->begin(), E = Block->end(); I != E;
+   ++I)
+if (std::optional CS = I->getAs()) {
+  const Stmt *S = CS->getStmt();
+  if (llvm::isa(S) || llvm::isa(S)) {
+CoroStmt = S ;
+break;
+  }
+}
+  if (!CoroStmt)
+return false;
+
+  struct Checker : RecursiveASTVisitor {
+const Stmt *StmtToCheck;
+bool CoroutineSubStmt = false;
+Checker(const Stmt *S) : StmtToCheck(S) {}
+bool VisitStmt(const Stmt *S) {
+  if (S == StmtToCheck)
+CoroutineSubStmt = true;
+  return true;
+}
+// The 'S' stmt captured in the CFG can be implicit.
+bool shouldVisitImplicitCode() const { return true; }
+  };
+  Checker checker(S);
+  checker.TraverseStmt(const_cast(CoroStmt));
+  return checker.CoroutineSubStmt;
+}
+
 static bool isBuiltinUnreachable(const Stmt *S) {
   if (const auto *DRE = dyn_cast(S))
 if (const auto *FDecl = dyn_cast(DRE->getDecl()))
@@ -623,7 +663,7 @@ void DeadCodeScan::reportDeadCode(const CFGBlock *B,
   if (isa(S)) {
 UK = reachable_code::UK_Break;
   } else if (isTrivialDoWhile(B, S) || isBuiltinUnreachable(S) ||
- isBuiltinAssumeFalse(B, S, C)) {
+ isBuiltinAssumeFalse(B, S, C) || isInCoroutineStmt(B, S)) {
 return;
   }
   else if (isDeadReturn(B, S)) {
diff --git a/clang/test/SemaCXX/coroutine-unreachable-warning.cpp 
b/clang/test/SemaCXX/coroutine-unreachable-warning.cpp
new file mode 100644
index 0..6ac5c34262b7e
--- /dev/null
+++ b/clang/test/SemaCXX/coroutine-unreachable-warning.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -std=c++20 -fsyntax-only 
-verify -Wunreachable-code
+
+#include "Inputs/std-coroutine.h"
+
+extern void abort (void) __attribute__ ((__noreturn__));
+
+struct task {
+  struct promise_type {
+std::suspend_always initial_suspend();
+std::suspend_always final_suspend() noexcept;
+void return_void();
+std::suspend_always yield_value(int) { return {}; }
+  task get_return_object();
+void unhandled_exception();
+  };
+};
+
+task test1() {
+  abort();
+  co_yield 1;
+}
+
+task test2() {
+  abort();
+  1; // expected-warning {{code will never be executed}}
+  co_yield 1;
+}
+
+task test3() {
+  abort();
+  co_return;
+}
+
+task test4() {
+  abort();
+  1; // expected-warning {{code will never be executed}}
+  co_return;
+}
+
+
+task test5() {
+  abort();
+  co_await std::suspend_never{};
+}
+
+task test6() {
+  abort();
+  1; // expected-warning {{code will never be executed}}
+  co_await std::suspend_never{};
+}

>From ee6fa40a7864480a059225ef56ae6cf2187d5f18 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Wed, 31 Jan 2024 16:08:32 +0100
Subject: [PATCH 2/3] Never treat coroutine statements as valid dead
 statements.

---
 clang/lib/Analysis/ReachableCode.cpp  | 91 ++-
 .../SemaCXX/coroutine-unreachable-warning.cpp | 17 +++-
 2 files changed, 63 insertions(+), 45 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index d839d2f999609..1e92e6458a538 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cp

[clang] [coroutine] Suppress unreachable-code warning on coroutine statements. (PR #77454)

2024-02-02 Thread Haojian Wu via cfe-commits


@@ -453,26 +454,68 @@ bool DeadCodeScan::isDeadCodeRoot(const clang::CFGBlock 
*Block) {
   return isDeadRoot;
 }
 
-static bool isValidDeadStmt(const Stmt *S) {
+// Check if the given `DeadStmt` is a coroutine statement and is a substmt of
+// the coroutine statement.
+static bool isInCoroutineStmt(const Stmt* DeadStmt, const CFGBlock *Block) {
+  // The coroutine statement, co_return, co_await, or co_yield.
+  const Stmt* CoroStmt = nullptr;
+  // Find the first coroutine statement after the DeadStmt in the block.
+  bool AfterDeadStmt = false;
+  for (CFGBlock::const_iterator I = Block->begin(), E = Block->end(); I != E;
+   ++I)
+if (std::optional CS = I->getAs()) {
+  const Stmt *S = CS->getStmt();
+  if (S == DeadStmt)
+AfterDeadStmt = true;
+  if (AfterDeadStmt &&
+  (llvm::isa(S) || llvm::isa(S))) {

hokein wrote:

Yeah, you're right. For this particular case, we still give a unreachable 
warning but at different locations.

```
// before this patch, on the coroutine stmt
int x = co_await 1;
   ^~~

// after this patch, on the decl stmt it self.
int x = co_await 1;
^
```

IMO, it is not ideal, but it is slightly better.

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


[clang] 6d1d2c6 - [clang] Fix a possible out-of-bounds read (#80023)

2024-02-02 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-02-02T11:15:57+01:00
New Revision: 6d1d2c67e7597dc417c097d5027558b0159ed2e2

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

LOG: [clang] Fix a possible out-of-bounds read (#80023)

Fixes #79964

Added: 


Modified: 
clang/lib/Frontend/TextDiagnostic.cpp

Removed: 




diff  --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 291d71f6db61f..627a7641308a1 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -1251,7 +1251,7 @@ highlightLines(StringRef FileData, unsigned 
StartLineNumber,
 unsigned LineLength = 0;
 for (unsigned I = 0; I <= Spelling.size(); ++I) {
   // This line is done.
-  if (isVerticalWhitespace(Spelling[I]) || I == Spelling.size()) {
+  if (I == Spelling.size() || isVerticalWhitespace(Spelling[I])) {
 SmallVector &LineRanges =
 SnippetRanges[L - StartLineNumber];
 



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


[clang] [clang] Fix a possible out-of-bounds read (PR #80023)

2024-02-02 Thread Timm Baeder via cfe-commits

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


[clang] [llvm] MIPS/clang: Disallow constraint f for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/79116

>From afacadad3f6654c60609a8d024ab9b6c0123195d Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Jan 2024 18:14:48 +0800
Subject: [PATCH] MIPS/clang: Fix asm constraint for softfloat

This include 2 fixes:
1. Disallow 'f' for softfloat.
2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: #64241
---
 clang/lib/Basic/Targets/Mips.h|  3 ++
 clang/test/Driver/mips-float.c| 47 +++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 10 +++--
 3 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c..2b8ad6645e605 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 case 'd': // Equivalent to "r" unless generating MIPS16 code.
 case 'y': // Equivalent to "r", backward compatibility only.
 case 'f': // floating-point registers.
+  if (*Name == 'f' && FloatABI == SoftFloat)
+return false;
+  LLVM_FALLTHROUGH;
 case 'c': // $25 for indirect jumps
 case 'l': // lo register
 case 'x': // hilo register pair
diff --git a/clang/test/Driver/mips-float.c b/clang/test/Driver/mips-float.c
index 2f1b813a15322..34cf7fdfb9b79 100644
--- a/clang/test/Driver/mips-float.c
+++ b/clang/test/Driver/mips-float.c
@@ -102,3 +102,50 @@
 // CHECK-ABI-SOFT-MIPS16: "-target-feature" "+mips16"
 // CHECK-ABI-SOFT-MIPS16: "-msoft-float"
 // CHECK-ABI-SOFT-MIPS16: "-mfloat-abi" "soft"
+
+/// On MIPS, don't accept constraint "f" for soft-float.
+// RUN: not %clang -S %s -o %t.s 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float \
+// RUN: -DSOFT_FLOAT_NO_CONSTRAINT_F \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-NO-F %s
+// CHECK-SOFTFLOAT-ASM-NO-F: error: invalid input constraint 'f' in asm
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float* p) {
+float result = *p;
+__asm__("" ::"f"(result));
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F
+
+/// On MIPS, accept constraint "r" for soft-float.
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=32 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=float \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-3232 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-3232: lw  $2, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=32 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=double \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-3264 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-3264: lw  $2, 4($4)
+// CHECK-SOFTFLOAT-ASM-USE-R-3264: lw  $3, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=64 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=float \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-6432 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-6432: lw  $2, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=64 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=double \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-6464 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-6464: ld  $2, 0($4)
+
+#ifdef SOFT_FLOAT_USE_CONSTRAINT_R
+void read_float(FLOAT* p) {
+FLOAT result = *p;
+__asm__("" ::"r"(result));
+}
+#endif // SOFT_FLOAT_USE_CONSTRAINT_R
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index d431d3d91494f..88b226eaaccfa 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4128,14 +4128,18 @@ MipsTargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
 case 'y': // Same as 'r'. Exists for compatibility.
 case 'r':
-  if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 || VT == MVT::i1) {
+  if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
+   VT == MVT::i1) ||
+  (VT == MVT::f32 && Subtarget.useSoftFloat())) {
 if (Subtarget.inMips16Mode())
   return std::make_pair(0U, &Mips::CPU16RegsRegClass);
 return std::make_pair(0U, &Mips::GPR32RegClass);
   }
-  if (VT == MVT::i64 && !Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  !Subtarget.isGP64bit())
 return std::make_pair(0U, &Mips::GPR32RegClass);
-  if (VT == MVT::i64 && Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  Subtarget.isGP64bit())
 return s

[clang] [Clang][AArch64] Emit 'unimplemented' diagnostic for SME (PR #80295)

2024-02-02 Thread Dinar Temirbulatov via cfe-commits

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

LGTM.

https://github.com/llvm/llvm-project/pull/80295
___
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] Add IR-level pass to rewrite away address space 7 (PR #77952)

2024-02-02 Thread Piotr Sobczak via cfe-commits

piotrAMD wrote:

Came across an assertion, see the attachment for the reproducer 
[repro.txt](https://github.com/llvm/llvm-project/files/14138750/repro.txt):
opt -S -mcpu=gfx1100 -amdgpu-lower-buffer-fat-pointers  repro.txt

#10 0x03aed749 llvm::StructLayout::StructLayout(llvm::StructType*, 
llvm::DataLayout const&) 
(/work/sw/drivers/xgl/rel/compiler/llpc/llvm/bin/opt+0x3aed749)
#11 0x03af069d llvm::DataLayout::getStructLayout(llvm::StructType*) 
const (/work/sw/drivers/xgl/rel/compiler/llpc/llvm/bin/opt+0x3af069d)
#12 0x03c03494 llvm::GEPOperator::collectOffset(llvm::DataLayout 
const&, unsigned int, llvm::MapVector, llvm::detail::DenseMapPair>, 
llvm::SmallVector, 0u>>&, llvm::APInt&) 
const (/work/sw/drivers/xgl/rel/compiler/llpc/llvm/bin/opt+0x3c03494)
#13 0x02d999d0 (anonymous 
namespace)::SplitPtrStructs::visitGetElementPtrInst(llvm::GetElementPtrInst&) 
AMDGPULowerBufferFatPointers.cpp:0:0
#14 0x02d97ba6 llvm::InstVisitor<(anonymous 
namespace)::SplitPtrStructs, std::pair>::visit(llvm::Instruction&) AMDGPULowerBufferFatPointers.cpp:0:0
#15 0x02d8f4b3 (anonymous 
namespace)::AMDGPULowerBufferFatPointers::run(llvm::Module&, 
llvm::TargetMachine const&) AMDGPULowerBufferFatPointers.cpp:0:0




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


[llvm] [clang] MIPS/clang: Disallow constraint f for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

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


[flang] [libc] [compiler-rt] [openmp] [clang-tools-extra] [libcxxabi] [clang] [mlir] [llvm] [libcxx] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2024-02-02 Thread Mariya Podchishchaeva via cfe-commits

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

>From 169d962b64b8ae242c3a6d332677296cf7503839 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 5 Dec 2023 10:28:44 -0800
Subject: [PATCH 1/4] [clang] Avoid -Wshadow warning when init-capture named
 same as class field

Shadowing warning doesn't make much sense since field is not available
in lambda's body without capturing this.

Fixes https://github.com/llvm/llvm-project/issues/71976
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaDecl.cpp   |  8 +---
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 18 ++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 828dd10e3d6db..7ac81e16492d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -655,6 +655,9 @@ Bug Fixes in This Version
   Fixes (`#64467 `_)
 - Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are 
known non-negative constants.
   Fixes (`#18763 `_)
+- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
+  field.
+  Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f12424d33b7da..65d095b2431dd 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8395,10 +8395,11 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
-  if (isa(D) && isa(ShadowedDecl) && NewDC &&
-  isa(NewDC)) {
+  if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+if (!isa(ShadowedDecl))
+  return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
   // Try to avoid warnings for lambdas with an explicit capture list.
   const auto *LSI = cast(getCurFunction());
@@ -8416,7 +8417,8 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 }
   }
 
-  if (cast(ShadowedDecl)->hasLocalStorage()) {
+  if (const auto *VD = dyn_cast(ShadowedDecl);
+  VD && VD->hasLocalStorage()) {
 // A variable can't shadow a local variable in an enclosing scope, if
 // they are separated by a non-capturing declaration context.
 for (DeclContext *ParentDC = NewDC;
diff --git a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp 
b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
index bda6a65c02168..58af7a2e65c55 100644
--- a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -179,3 +179,21 @@ void f() {
 #endif
 }
 }
+
+namespace GH71976 {
+struct A {
+  int b = 5;
+  int foo() {
+return [b = b]() { return b; }();
+  }
+};
+
+struct B {
+  int a;
+  void foo() {
+auto b = [a = this->a] {
+
+};
+  }
+};
+}

>From 3798e1f25a8d812c082ac5815c490eb9c7f67e62 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 6 Dec 2023 02:24:59 -0800
Subject: [PATCH 2/4] Apply comments

---
 clang/docs/ReleaseNotes.rst   | 4 ++--
 clang/lib/Sema/SemaDecl.cpp   | 1 +
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d1f3ed22cf2e..f5e0d4fa39737 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -661,8 +661,8 @@ Bug Fixes in This Version
 - Fixed false positive error emitted when templated alias inside a class
   used private members of the same class.
   Fixes (`#41693 `_)
-- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
-  field.
+- Clang's ``-Wshadow`` no longer warns when an init-capture is named the same 
as
+  a class field.
   Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 65d095b2431dd..f590d1b3ade81 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8398,6 +8398,7 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
   if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+// If it is not VarDecl then it can not shadow.
 if (!isa(ShadowedDecl))
   return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
diff --git a/clang/test/SemaCXX/warn-shadow-in-lam

[flang] [libcxxabi] [llvm] [libcxx] [clang] [mlir] [openmp] [clang-tools-extra] [libc] [compiler-rt] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2024-02-02 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Ping.

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


[clang-tools-extra] [llvm] [clang] MIPS/clang: Disallow constraint f for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/79116

>From afacadad3f6654c60609a8d024ab9b6c0123195d Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Jan 2024 18:14:48 +0800
Subject: [PATCH] MIPS/clang: Fix asm constraint for softfloat

This include 2 fixes:
1. Disallow 'f' for softfloat.
2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: #64241
---
 clang/lib/Basic/Targets/Mips.h|  3 ++
 clang/test/Driver/mips-float.c| 47 +++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 10 +++--
 3 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c..2b8ad6645e605 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 case 'd': // Equivalent to "r" unless generating MIPS16 code.
 case 'y': // Equivalent to "r", backward compatibility only.
 case 'f': // floating-point registers.
+  if (*Name == 'f' && FloatABI == SoftFloat)
+return false;
+  LLVM_FALLTHROUGH;
 case 'c': // $25 for indirect jumps
 case 'l': // lo register
 case 'x': // hilo register pair
diff --git a/clang/test/Driver/mips-float.c b/clang/test/Driver/mips-float.c
index 2f1b813a15322..34cf7fdfb9b79 100644
--- a/clang/test/Driver/mips-float.c
+++ b/clang/test/Driver/mips-float.c
@@ -102,3 +102,50 @@
 // CHECK-ABI-SOFT-MIPS16: "-target-feature" "+mips16"
 // CHECK-ABI-SOFT-MIPS16: "-msoft-float"
 // CHECK-ABI-SOFT-MIPS16: "-mfloat-abi" "soft"
+
+/// On MIPS, don't accept constraint "f" for soft-float.
+// RUN: not %clang -S %s -o %t.s 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float \
+// RUN: -DSOFT_FLOAT_NO_CONSTRAINT_F \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-NO-F %s
+// CHECK-SOFTFLOAT-ASM-NO-F: error: invalid input constraint 'f' in asm
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float* p) {
+float result = *p;
+__asm__("" ::"f"(result));
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F
+
+/// On MIPS, accept constraint "r" for soft-float.
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=32 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=float \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-3232 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-3232: lw  $2, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=32 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=double \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-3264 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-3264: lw  $2, 4($4)
+// CHECK-SOFTFLOAT-ASM-USE-R-3264: lw  $3, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=64 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=float \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-6432 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-6432: lw  $2, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=64 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=double \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-6464 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-6464: ld  $2, 0($4)
+
+#ifdef SOFT_FLOAT_USE_CONSTRAINT_R
+void read_float(FLOAT* p) {
+FLOAT result = *p;
+__asm__("" ::"r"(result));
+}
+#endif // SOFT_FLOAT_USE_CONSTRAINT_R
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index d431d3d91494f..88b226eaaccfa 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4128,14 +4128,18 @@ MipsTargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
 case 'y': // Same as 'r'. Exists for compatibility.
 case 'r':
-  if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 || VT == MVT::i1) {
+  if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
+   VT == MVT::i1) ||
+  (VT == MVT::f32 && Subtarget.useSoftFloat())) {
 if (Subtarget.inMips16Mode())
   return std::make_pair(0U, &Mips::CPU16RegsRegClass);
 return std::make_pair(0U, &Mips::GPR32RegClass);
   }
-  if (VT == MVT::i64 && !Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  !Subtarget.isGP64bit())
 return std::make_pair(0U, &Mips::GPR32RegClass);
-  if (VT == MVT::i64 && Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  Subtarget.isGP64bit())
 return s

[llvm] [clang] [AArch64] Support optional constant offset for constraint "S" (PR #80255)

2024-02-02 Thread Peter Smith via cfe-commits

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

Thanks for the response. LGTM.

I think the RISCV inline-asm-S-constraint.ll is no longer necessary thanks to 
#80201

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


[llvm] [clang] [AArch64] Support optional constant offset for constraint "S" (PR #80255)

2024-02-02 Thread Peter Smith via cfe-commits

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


[llvm] [clang] [AArch64] Support optional constant offset for constraint "S" (PR #80255)

2024-02-02 Thread Peter Smith via cfe-commits


@@ -3,6 +3,7 @@
 ; RUN: llc -mtriple=riscv64 < %s | FileCheck %s --check-prefix=RV64
 
 @var = external dso_local global i32, align 4
+@a = external global [2 x [2 x i32]], align 4

smithp35 wrote:

Did you mean to change this file in this PR? I think this change has already 
been made in #80201

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


[clang] [coroutine] Suppress unreachable-code warning on coroutine statements. (PR #77454)

2024-02-02 Thread Utkarsh Saxena via cfe-commits

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

LGTM. Thanks.

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


[clang] [coroutine] Suppress unreachable-code warning on coroutine statements. (PR #77454)

2024-02-02 Thread Utkarsh Saxena via cfe-commits

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


[clang] [coroutine] Suppress unreachable-code warning on coroutine statements. (PR #77454)

2024-02-02 Thread Utkarsh Saxena via cfe-commits


@@ -33,33 +40,37 @@ task test3() {
 
 task test4() {
   abort();
-  1; // expected-warning {{code will never be executed}}
+  1;  // expected-warning {{code will never be executed}}
   co_return;
 }
 
-
 task test5() {
   abort();
-  co_await std::suspend_never{};
+  co_await 1;
 }
 
 task test6() {
   abort();
-  1; // expected-warning {{code will never be executed}}
-  co_await std::suspend_never{};
+  1;  // expected-warning {{code will never be executed}}
+  co_await 3;
 }
 
 task test7() {
   // coroutine statements are not considered unreachable.
-  co_await std::suspend_never{};
+  co_await 1;
   abort();
-  co_await std::suspend_never{};
+  co_await 2;
 }
 
 task test8() {
   // coroutine statements are not considered unreachable.
-  // co_await std::suspend_never{};
   abort();
   co_return;
-  1 + 1; // expected-warning {{code will never be executed}}
+  1 + 1;  // expected-warning {{code will never be executed}}
+}
+
+task test9() {
+  abort();
+  // This warning is emit on the declaration itself, rather the coroutine 
substmt.

usx95 wrote:

s/emit/emitted

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


[clang] [coroutine] Suppress unreachable-code warning on coroutine statements. (PR #77454)

2024-02-02 Thread Utkarsh Saxena via cfe-commits


@@ -12,6 +12,13 @@ struct task {
 std::suspend_always yield_value(int) { return {}; }
 task get_return_object();
 void unhandled_exception();
+
+struct Awaiter {
+  bool await_ready();
+  void await_suspend(auto);
+  int await_resume();
+};
+auto await_transform(const int& x) { return Awaiter{}; }

usx95 wrote:

nit: (Just to reduce the boilerplate not related to the test itself) we do not 
need to define a new awaitable here. Maybe just:
`std::suspend_always await_transform(int) { return {}; }`

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


[clang] [coroutine] Suppress unreachable-code warning on coroutine statements. (PR #77454)

2024-02-02 Thread Utkarsh Saxena via cfe-commits


@@ -453,26 +454,68 @@ bool DeadCodeScan::isDeadCodeRoot(const clang::CFGBlock 
*Block) {
   return isDeadRoot;
 }
 
-static bool isValidDeadStmt(const Stmt *S) {
+// Check if the given `DeadStmt` is a coroutine statement and is a substmt of
+// the coroutine statement.
+static bool isInCoroutineStmt(const Stmt* DeadStmt, const CFGBlock *Block) {
+  // The coroutine statement, co_return, co_await, or co_yield.
+  const Stmt* CoroStmt = nullptr;
+  // Find the first coroutine statement after the DeadStmt in the block.
+  bool AfterDeadStmt = false;
+  for (CFGBlock::const_iterator I = Block->begin(), E = Block->end(); I != E;
+   ++I)
+if (std::optional CS = I->getAs()) {
+  const Stmt *S = CS->getStmt();
+  if (S == DeadStmt)
+AfterDeadStmt = true;
+  if (AfterDeadStmt &&
+  (llvm::isa(S) || llvm::isa(S))) {

usx95 wrote:

SG. Thanks.

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


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

2024-02-02 Thread via cfe-commits

bgra8 wrote:

https://github.com/llvm/llvm-project/pull/80023 does not fix the problem we're 
seeing here.

The problem is extremely hard to reduce as it happens during preprocessing and 
even removing unrelated headers causes the crash to disappear.

I've built `clang` with assertions enabled and debug information and got a bit 
of more information in the stack trace:

```
..
#6  0x666ce7a4 in __assert_fail ()
#7  0x5e86b604 in highlightLines (FileData=..., StartLineNumber=40, 
EndLineNumber=40, PP=0x68f3f80ec98, LangOpts=..., ShowColors=true, FID=..., 
SM=...) at /work/llvm-project/clang/lib/Frontend/TextDiagnostic.cpp:1156
#8  0x5e86a7d3 in clang::TextDiagnostic::emitSnippetAndCaret 
(this=0x68f3fc7cec0, Loc=..., Level=clang::DiagnosticsEngine::Note, Ranges=..., 
Hints=...) at /work/llvm-project/clang/lib/Frontend/TextDiagnostic.cpp:1352
#9  0x5e86e908 in clang::TextDiagnostic::emitCodeContext 
(this=0x68f3fc7cec0, Loc=..., Level=clang::DiagnosticsEngine::Note, Ranges=..., 
Hints=...) at 
/work/llvm-project/clang/include/clang/Frontend/TextDiagnostic.h:97
#10 0x5e844c4e in clang::DiagnosticRenderer::emitCaret 
(this=0x68f3fc7cec0, Loc=..., Level=clang::DiagnosticsEngine::Note, Ranges=..., 
Hints=...) at /work/llvm-project/clang/lib/Frontend/DiagnosticRenderer.cpp:429
#11 0x5e844482 in clang::DiagnosticRenderer::emitDiagnostic 
(this=0x68f3fc7cec0, Loc=..., Level=clang::DiagnosticsEngine::Note, 
Message=..., Ranges=..., FixItHints=..., D=...) at 
/work/llvm-project/clang/lib/Frontend/DiagnosticRenderer.cpp:127
#12 0x5e84619f in clang::DiagnosticRenderer::emitSingleMacroExpansion 
(this=0x68f3fc7cec0, Loc=..., Level=clang::DiagnosticsEngine::Warning, 
Ranges=...) at /work/llvm-project/clang/lib/Frontend/DiagnosticRenderer.cpp:454
#13 0x5e845044 in clang::DiagnosticRenderer::emitMacroExpansions 
(this=0x68f3fc7cec0, Loc=..., Level=clang::DiagnosticsEngine::Warning, 
Ranges=..., Hints=...) at 
/work/llvm-project/clang/lib/Frontend/DiagnosticRenderer.cpp:569
#14 0x5e84454c in clang::DiagnosticRenderer::emitDiagnostic 
(this=0x68f3fc7cec0, Loc=..., Level=clang::DiagnosticsEngine::Warning, 
Message=..., Ranges=..., FixItHints=..., D=...) at 
/work/llvm-project/clang/lib/Frontend/DiagnosticRenderer.cpp:132
#15 0x5e86866f in clang::TextDiagnosticPrinter::HandleDiagnostic 
(this=0x68f3fc1c900, Level=clang::DiagnosticsEngine::Warning, Info=...) at 
/work/llvm-project/clang/lib/Frontend/TextDiagnosticPrinter.cpp:151
#16 0x61435102 in clang::DiagnosticIDs::EmitDiag (this=0x68f3fc14bb0, 
Diag=..., DiagLevel=clang::DiagnosticIDs::Warning) at 
/work/llvm-project/clang/lib/Basic/DiagnosticIDs.cpp:823
#17 0x61434f44 in clang::DiagnosticIDs::ProcessDiag 
(this=0x68f3fc14bb0, Diag=...) at 
/work/llvm-project/clang/lib/Basic/DiagnosticIDs.cpp:815
#18 0x61429b49 in clang::DiagnosticsEngine::ProcessDiag 
(this=0x68f3f85c400) at 
/work/llvm-project/clang/include/clang/Basic/Diagnostic.h:1042
#19 0x61429ac9 in clang::DiagnosticsEngine::EmitCurrentDiagnostic 
(this=0x68f3f85c400, Force=false) at 
/work/llvm-project/clang/lib/Basic/Diagnostic.cpp:545
...
```

The failed assertion is in this block of code:

```
  const char *FirstLineStart =
  FileData.data() +
  SM.getDecomposedLoc(SM.translateLineCol(FID, StartLineNumber, 1)).second;
  if (const char *CheckPoint = PP->getCheckPoint(FID, FirstLineStart)) {
// THIS IS THE FAILED ASSERTION:
assert(CheckPoint >= Buff->getBufferStart() &&
   CheckPoint <= Buff->getBufferEnd());
assert(CheckPoint <= FirstLineStart);
size_t Offset = CheckPoint - Buff->getBufferStart();
L.seek(Offset, /*IsAtStartOfLine=*/false);
  }
```

The crash happens when the preprocessor outputs a warning related to this code:

```
#ifndef __GTS_H__
#define __GTS_H__

#include 
#include 
// #include "glib.h"

#define G_STRINGIFY(macro_or_string)G_STRINGIFY_ARG (macro_or_string)
#define G_STRINGIFY_ARG(contents)   #contents
#define _GLIB_GNUC_DO_PRAGMA(x) _Pragma(G_STRINGIFY (x))
#define GLIB_DEPRECATED_MACRO_FOR(f) \
  _GLIB_GNUC_DO_PRAGMA(GCC warning G_STRINGIFY (Deprecated pre-processor 
symbol: replace with #f))
#define GLIB_DEPRECATED_MACRO_IN_2_48_FOR(f) GLIB_DEPRECATED_MACRO_FOR (f)
#define G_INLINE_FUNC static inline GLIB_DEPRECATED_MACRO_IN_2_48_FOR(static 
inline)


/* Class declarations for base types */
G_INLINE_FUNC
gpointer gts_object_is_from_class  (gpointer object,
gpointer klass);

#endif /* __GTS_H__ */
```

In the previous code snippet the macro definitions are extracted from the 
`lib.h` header (provided by package `libglib2.0-dev`). Just compiling that does 
not reproduce the crash but it might give you an idea of the code that might 
setup the crash condition. The compiler output just before the crash is:

```
In file included from matrix.c:1:
gts.h:9:1: warning: Deprecated pre-pr

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

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

Endilll wrote:

@bgra8 Thank you! This is helpful.

> The problem is extremely hard to reduce as it happens during preprocessing 
> and even removing unrelated headers causes the crash to disappear.

Yeah, crashes happening at this stage can easily be insane to reduce manually.

> This crash is blocking our internal work at Google. I second @eaeltsin's 
> proposal to put the highlightLines() function behind a flag at least until we 
> can get to the bottom of this.

As mentioned above, `-fno-color-diagnostics` is the flag you can deploy 
internally this very moment.

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] [clang][Diagnostics] Highlight code snippets (PR #66514)

2024-02-02 Thread via cfe-commits

bgra8 wrote:

> As mentioned above, `-fno-color-diagnostics` is the flag you can deploy 
> internally this very moment.

Disabling color diagnostics would make the job of other software engineers 
harder, right? This hammer is a bit too big for the problem at hand, right?

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] [Clang][Sema] Fix crash with const qualified member operator new (PR #80327)

2024-02-02 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [Clang][Sema] Fix crash with const qualified member operator new (PR #80327)

2024-02-02 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

Needs a release note.

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


[clang] [Clang][Sema] Fix crash with const qualified member operator new (PR #80327)

2024-02-02 Thread Mariya Podchishchaeva via cfe-commits


@@ -37,3 +37,10 @@ void instantiateArrayDecay() {
   int a[1];
   arrayDecay(a);
 }
+
+namespace GH79748 {
+typedef decltype(sizeof(0)) size_t;
+struct A {
+  void* operator new(size_t bytes) const; //expected-error {{static member 
function cannot have 'const' qualifier}}

Fznamznon wrote:

Perhaps a test with `volatile` qualifier also makes sense?
Crashes too https://godbolt.org/z/TWr8zqKK1

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


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

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

Endilll wrote:

> > As mentioned above, `-fno-color-diagnostics` is the flag you can deploy 
> > internally this very moment.
> 
> Disabling color diagnostics would make the job of other software engineers 
> harder, right? This hammer is a bit too big for the problem at hand, right?

I thought we are still talking about internal work being blocked on this, which 
is much more severe issue.


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] [IRGen][AArch64][RISCV] Generalize bitcast between i1 predicate vector and i8 fixed vector. (PR #76548)

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

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


[clang] [IRGen][AArch64][RISCV] Generalize bitcast between i1 predicate vector and i8 fixed vector. (PR #76548)

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


@@ -2136,14 +2136,16 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 // bitcast.
 if (const auto *FixedSrc = dyn_cast(SrcTy)) {
   if (const auto *ScalableDst = dyn_cast(DstTy)) 
{
-// If we are casting a fixed i8 vector to a scalable 16 x i1 predicate
+// If we are casting a fixed i8 vector to a scalable i1 predicate
 // vector, use a vector insert and bitcast the result.
 bool NeedsBitCast = false;
-auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
 llvm::Type *OrigType = DstTy;
-if (ScalableDst == PredType &&
-FixedSrc->getElementType() == Builder.getInt8Ty()) {
-  DstTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
+if (ScalableDst->getElementType()->isIntegerTy(1) &&

sdesmalen-arm wrote:

nit: While you're touching this code, maybe refactor this whole block to remove 
the control flow by `NeedsBitCast`, by something like this:

```
if (const auto *FixedSrc = dyn_cast(SrcTy)) {
  if (const auto *ScalableDst = dyn_cast(DstTy)) {
llvm::Value *Zero = llvm::Constant::getNullValue(CGF.CGM.Int64Ty);
if (ScalableDst->getElementType()->isIntegerTy(1) &&
ScalableDst->getElementCount().isKnownMultipleOf(8) &&
FixedSrc->getElementType()->isIntegerTy(8)) {
  auto InsertTy = llvm::ScalableVectorType::get(
  FixedSrc->getElementType(), FixedSrc->getNumElements());
  llvm::Value *Insert = Builder.CreateInsertVector(
  InsertTy, llvm::UndefValue::get(InsertTy), Src, Zero,
  "cast.scalable");
  return Builder.CreateBitCast(Insert, DstTy);
} else if (FixedSrc->getElementType() == ScalableDst->getElementType())
  return Builder.CreateInsertVector(DstTy, llvm::UndefValue::get(DstTy),
Src, Zero, "cast.scalable");
  }
}
```

What do you think?

(similar suggestion for the other case below for scalable -> fixed)

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


[clang] [IRGen][AArch64][RISCV] Generalize bitcast between i1 predicate vector and i8 fixed vector. (PR #76548)

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

https://github.com/sdesmalen-arm commented:

Generalising this code makes sense, 16 should never have been hardcoded here.

Is it possible to add a test for the case where the predicate type is not 
``?

> Though I do wonder if we have the bitcast on the wrong side. Maybe we should 
> be casting the fixed type to an i1 fixed vector? That would better handle 
> cases where the mininum elements isn't a multiple of 8, but 
> vscale*min_elements is.
I'm not sure if there are any fundamental reasons not to do this, but at least 
for AArch64 `16 x i1` is not a legal type which leads to some inefficient 
legalisation code. I can see however that the IR is missing some folds, so 
perhaps with those folds added making this change is fine.

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


[clang] [IRGen][AArch64][RISCV] Generalize bitcast between i1 predicate vector and i8 fixed vector. (PR #76548)

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

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


[clang] [llvm] MIPS/clang: Disallow constraint f for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/79116

>From 009bd230a51a1790e6691ae3f104f57af311272f Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Tue, 23 Jan 2024 18:14:48 +0800
Subject: [PATCH] MIPS/clang: Fix asm constraint for softfloat

This include 2 fixes:
1. Disallow 'f' for softfloat.
2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: #64241
---
 clang/lib/Basic/Targets/Mips.h|  3 ++
 clang/test/Driver/mips-float.c| 47 +++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 10 +++--
 3 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f46b95abfd75c..2b8ad6645e605 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -238,6 +238,9 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 case 'd': // Equivalent to "r" unless generating MIPS16 code.
 case 'y': // Equivalent to "r", backward compatibility only.
 case 'f': // floating-point registers.
+  if (*Name == 'f' && FloatABI == SoftFloat)
+return false;
+  LLVM_FALLTHROUGH;
 case 'c': // $25 for indirect jumps
 case 'l': // lo register
 case 'x': // hilo register pair
diff --git a/clang/test/Driver/mips-float.c b/clang/test/Driver/mips-float.c
index 2f1b813a15322..34cf7fdfb9b79 100644
--- a/clang/test/Driver/mips-float.c
+++ b/clang/test/Driver/mips-float.c
@@ -102,3 +102,50 @@
 // CHECK-ABI-SOFT-MIPS16: "-target-feature" "+mips16"
 // CHECK-ABI-SOFT-MIPS16: "-msoft-float"
 // CHECK-ABI-SOFT-MIPS16: "-mfloat-abi" "soft"
+
+/// On MIPS, don't accept constraint "f" for soft-float.
+// RUN: not %clang -S %s -o %t.s 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float \
+// RUN: -DSOFT_FLOAT_NO_CONSTRAINT_F \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-NO-F %s
+// CHECK-SOFTFLOAT-ASM-NO-F: error: invalid input constraint 'f' in asm
+
+#ifdef SOFT_FLOAT_NO_CONSTRAINT_F
+void read_float(float* p) {
+float result = *p;
+__asm__("" ::"f"(result));
+}
+#endif // SOFT_FLOAT_NO_CONSTRAINT_F
+
+/// On MIPS, accept constraint "r" for soft-float.
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=32 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=float \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-3232 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-3232: lw  $2, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=32 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=double \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-3264 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-3264: lw  $2, 4($4)
+// CHECK-SOFTFLOAT-ASM-USE-R-3264: lw  $3, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=64 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=float \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-6432 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-6432: lw  $2, 0($4)
+//
+// RUN: %clang -S %s -o - -O2 2>&1 \
+// RUN: -target mips-linux-gnu -msoft-float -mabi=64 \
+// RUN: -DSOFT_FLOAT_USE_CONSTRAINT_R -DFLOAT=double \
+// RUN:   | FileCheck --check-prefix=CHECK-SOFTFLOAT-ASM-USE-R-6464 %s
+// CHECK-SOFTFLOAT-ASM-USE-R-6464: ld  $2, 0($4)
+
+#ifdef SOFT_FLOAT_USE_CONSTRAINT_R
+void read_float(FLOAT* p) {
+FLOAT result = *p;
+__asm__("" ::"r"(result));
+}
+#endif // SOFT_FLOAT_USE_CONSTRAINT_R
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index b2812f87914df..97e830cec27ca 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4128,14 +4128,18 @@ MipsTargetLowering::getRegForInlineAsmConstraint(const 
TargetRegisterInfo *TRI,
 case 'd': // Address register. Same as 'r' unless generating MIPS16 code.
 case 'y': // Same as 'r'. Exists for compatibility.
 case 'r':
-  if (VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 || VT == MVT::i1) {
+  if ((VT == MVT::i32 || VT == MVT::i16 || VT == MVT::i8 ||
+   VT == MVT::i1) ||
+  (VT == MVT::f32 && Subtarget.useSoftFloat())) {
 if (Subtarget.inMips16Mode())
   return std::make_pair(0U, &Mips::CPU16RegsRegClass);
 return std::make_pair(0U, &Mips::GPR32RegClass);
   }
-  if (VT == MVT::i64 && !Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  !Subtarget.isGP64bit())
 return std::make_pair(0U, &Mips::GPR32RegClass);
-  if (VT == MVT::i64 && Subtarget.isGP64bit())
+  if ((VT == MVT::i64 || (VT == MVT::f64 && Subtarget.useSoftFloat())) &&
+  Subtarget.isGP64bit())
 return s

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

2024-02-02 Thread via cfe-commits

bgra8 wrote:

> I thought we are still talking about internal work being blocked on this, 
> which is much more severe issue.

We can't push internally a compiler that crashes unless we disable color 
diagnostics.

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] [flang] [flang]Add support for -moutline-atomics and -mno-outline-atomics (PR #78755)

2024-02-02 Thread Mats Petersson via cfe-commits

https://github.com/Leporacanthicus updated 
https://github.com/llvm/llvm-project/pull/78755

>From a0e256f379130a98ba03793f7102c67d02cbdef1 Mon Sep 17 00:00:00 2001
From: Mats Petersson 
Date: Fri, 19 Jan 2024 16:30:31 +
Subject: [PATCH 1/4] [flang]Add support for -moutline-atomics and
 -mno-outline-atomics

Clang has support for genarting atomic operations as functions rather
than inline atomic operations, using a target feature.

This is useful for code-size, some cases of debugging, and it also affects
the ability to inline functions from C into Fortran or the other way around
when using LTO - the inliner will check the target features to make sure
functions are compatible, and a difference in outline-atomics would disable
the inlining of an outline-atomics into a non-outline-atomics function.
---
 clang/include/clang/Driver/Options.td |  4 ++--
 clang/lib/Driver/ToolChains/Flang.cpp | 23 ++-
 flang/lib/Frontend/CompilerInvocation.cpp | 15 
 flang/test/Driver/aarch64-outline-atomics.f90 | 11 +
 flang/test/Driver/driver-help-hidden.f90  |  2 ++
 flang/test/Driver/driver-help.f90 |  4 
 6 files changed, 56 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Driver/aarch64-outline-atomics.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d940665969339..0eb72f5722541 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4982,10 +4982,10 @@ def mno_fmv : Flag<["-"], "mno-fmv">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Disable function multiversioning">;
 def moutline_atomics : Flag<["-"], "moutline-atomics">, Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   HelpText<"Generate local calls to out-of-line atomic operations">;
 def mno_outline_atomics : Flag<["-"], "mno-outline-atomics">, 
Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   HelpText<"Don't generate local calls to out-of-line atomic operations">;
 def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group,
   HelpText<"Don't generate implicit floating point or vector instructions">;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index b659521df88ff..bdd8afde44165 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -352,6 +352,27 @@ void Flang::addTargetOptions(const ArgList &Args,
 CmdArgs.push_back(Args.MakeArgString(CPU));
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
+   options::OPT_mno_outline_atomics)) {
+// Option -moutline-atomics supported for AArch64 target only.
+if (!Triple.isAArch64()) {
+  D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
+  << Triple.getArchName() << A->getOption().getName();
+} else {
+  if (A->getOption().matches(options::OPT_moutline_atomics)) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+outline-atomics");
+  } else {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("-outline-atomics");
+  }
+}
+  } else if (Triple.isAArch64() &&
+ getToolChain().IsAArch64OutlineAtomicsDefault(Args)) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+outline-atomics");
+  }
+
   // Add the target features.
   switch (TC.getArch()) {
   default:
@@ -672,7 +693,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   CmdArgs.push_back(Args.MakeArgString(TripleStr));
 
   if (isa(JA)) {
-  CmdArgs.push_back("-E");
+CmdArgs.push_back("-E");
   } else if (isa(JA) || isa(JA)) {
 if (JA.getType() == types::TY_Nothing) {
   CmdArgs.push_back("-fsyntax-only");
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index a3c41fb4611f5..74127327e798e 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -402,6 +402,21 @@ static void parseTargetArgs(TargetOptions &opts, 
llvm::opt::ArgList &args) {
   for (const llvm::opt::Arg *currentArg :
args.filtered(clang::driver::options::OPT_target_feature))
 opts.featuresAsWritten.emplace_back(currentArg->getValue());
+
+  llvm::Triple targetTriple{llvm::Triple(opts.triple)};
+  if (const llvm::opt::Arg *A =
+  args.getLastArg(clang::driver::options::OPT_moutline_atomics,
+  clang::driver::options::OPT_mno_outline_atomics)) {
+// Option -moutline-atomics supported for AArch64 target only.
+if (!targetTriple.isAArch64()) {
+  if (A->getOption().matches(
+  clang::driver::options::OPT_moutline_atomics)) {
+opts.featuresAsWritten.push_back("+outline-atomics");
+  } else {
+o

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

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

Endilll wrote:

> We can't push internally a compiler that crashes unless we disable color 
> diagnostics.

I hope you realize this is self-imposed limitation that Clang community doesn't 
necessary have to respect.

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] [llvm] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

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


[clang] [lld] [llvm] [flang] [AMDGPU] Introduce Code Object V6 (PR #76954)

2024-02-02 Thread Pierre van Houtryve via cfe-commits

https://github.com/Pierre-vh updated 
https://github.com/llvm/llvm-project/pull/76954

>From a967fdae9a8557331d2a228f391f39f9e27e8943 Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Thu, 4 Jan 2024 14:12:00 +0100
Subject: [PATCH 1/5] [AMDGPU] Introduce Code Object V6

Introduce Code Object V6 in Clang, LLD, Flang and LLVM.
This is the same as V5 except a new "generic version" flag can be present in 
EFLAGS. This is related to new generic targets that'll be added in a follow-up 
patch. It's also likely V6 will have new changes (possibly new metadata 
entries) added later.

Docs change are not included, I'm planning to do them in a follow-up patch all 
at once (when generic targets land too).
---
 clang/include/clang/Driver/Options.td |   4 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |   6 +-
 clang/lib/Driver/ToolChains/CommonArgs.cpp|   2 +-
 .../amdgpu-code-object-version-linking.cu |  37 +++
 .../CodeGenCUDA/amdgpu-code-object-version.cu |   4 +
 .../test/CodeGenCUDA/amdgpu-workgroup-size.cu |   4 +
 .../amdgcn/bitcode/oclc_abi_version_600.bc|   0
 clang/test/Driver/hip-code-object-version.hip |  12 +
 clang/test/Driver/hip-device-libs.hip |  18 +-
 flang/lib/Frontend/CompilerInvocation.cpp |   2 +
 flang/test/Lower/AMD/code-object-version.f90  |   3 +-
 lld/ELF/Arch/AMDGPU.cpp   |  21 ++
 lld/test/ELF/amdgpu-tid.s |  16 ++
 llvm/include/llvm/BinaryFormat/ELF.h  |   9 +-
 llvm/include/llvm/Support/AMDGPUMetadata.h|   7 +
 llvm/include/llvm/Support/ScopedPrinter.h |   4 +-
 llvm/include/llvm/Target/TargetOptions.h  |   1 +
 llvm/lib/ObjectYAML/ELFYAML.cpp   |   9 +
 llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp   |   3 +
 .../AMDGPU/AMDGPUHSAMetadataStreamer.cpp  |  10 +
 .../Target/AMDGPU/AMDGPUHSAMetadataStreamer.h |  11 +-
 .../MCTargetDesc/AMDGPUTargetStreamer.cpp |  26 ++
 .../MCTargetDesc/AMDGPUTargetStreamer.h   |   1 +
 .../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp|   6 +
 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h |   2 +-
 ...licit-kernarg-backend-usage-global-isel.ll |   2 +
 .../AMDGPU/call-graph-register-usage.ll   |   1 +
 .../AMDGPU/codegen-internal-only-func.ll  |   3 +
 llvm/test/CodeGen/AMDGPU/elf-header-osabi.ll  |   4 +
 .../enable-scratch-only-dynamic-stack.ll  |   1 +
 .../AMDGPU/implicit-kernarg-backend-usage.ll  |   2 +
 .../AMDGPU/implicitarg-offset-attributes.ll   |  46 
 .../AMDGPU/llvm.amdgcn.implicitarg.ptr.ll |   1 +
 llvm/test/CodeGen/AMDGPU/non-entry-alloca.ll  |   1 +
 llvm/test/CodeGen/AMDGPU/recursion.ll |   1 +
 .../AMDGPU/resource-usage-dead-function.ll|   1 +
 .../AMDGPU/tid-mul-func-xnack-all-any.ll  |   6 +
 .../tid-mul-func-xnack-all-not-supported.ll   |   6 +
 .../AMDGPU/tid-mul-func-xnack-all-off.ll  |   6 +
 .../AMDGPU/tid-mul-func-xnack-all-on.ll   |   6 +
 .../AMDGPU/tid-mul-func-xnack-any-off-1.ll|   6 +
 .../AMDGPU/tid-mul-func-xnack-any-off-2.ll|   6 +
 .../AMDGPU/tid-mul-func-xnack-any-on-1.ll |   6 +
 .../AMDGPU/tid-mul-func-xnack-any-on-2.ll |   6 +
 .../tid-one-func-xnack-not-supported.ll   |   6 +
 .../CodeGen/AMDGPU/tid-one-func-xnack-off.ll  |   6 +
 .../CodeGen/AMDGPU/tid-one-func-xnack-on.ll   |   6 +
 .../MC/AMDGPU/hsa-v5-uses-dynamic-stack.s |   5 +
 .../elf-headers.test} |   0
 .../ELF/AMDGPU/generic_versions.s |  16 ++
 .../ELF/AMDGPU/generic_versions.test  |  26 ++
 llvm/tools/llvm-readobj/ELFDumper.cpp | 224 --
 52 files changed, 483 insertions(+), 135 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/rocm/amdgcn/bitcode/oclc_abi_version_600.bc
 rename llvm/test/tools/llvm-readobj/ELF/{amdgpu-elf-headers.test => 
AMDGPU/elf-headers.test} (100%)
 create mode 100644 llvm/test/tools/llvm-readobj/ELF/AMDGPU/generic_versions.s
 create mode 100644 
llvm/test/tools/llvm-readobj/ELF/AMDGPU/generic_versions.test

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 73071a6648541..fb5f50ef452c2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4801,9 +4801,9 @@ defm amdgpu_ieee : BoolOption<"m", "amdgpu-ieee",
 def mcode_object_version_EQ : Joined<["-"], "mcode-object-version=">, 
Group,
   HelpText<"Specify code object ABI version. Defaults to 5. (AMDGPU only)">,
   Visibility<[ClangOption, FlangOption, CC1Option, FC1Option]>,
-  Values<"none,4,5">,
+  Values<"none,4,5,6">,
   NormalizedValuesScope<"llvm::CodeObjectVersionKind">,
-  NormalizedValues<["COV_None", "COV_4", "COV_5"]>,
+  NormalizedValues<["COV_None", "COV_4", "COV_5", "COV_6"]>,
   MarshallingInfoEnum, "COV_5">;
 
 defm cumode : SimpleMFlag<"cumode",
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 196be813a4896..f17e4a83305bf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/C

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

2024-02-02 Thread via cfe-commits

bgra8 wrote:

> I hope you realize this is self-imposed limitation that Clang community 
> doesn't necessary have to respect.

Well, the actual LLVM policy is to revert to green: 
https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy

```
When should you revert your own change?

* Any time you learn of a serious problem with a change, you should revert it. 
We strongly encourage “revert to green” as opposed to “fixing forward”. We 
encourage reverting first, investigating offline, and then reapplying the fixed 
patch - possibly after another round of review if warranted.
```

This I think qualifies as a serious problem as it introduces a crash which may 
occur in *any* existent codebase. Anyone using the compiler at trunk and 
encountering the crash has no way to know how to deal with it.



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] [llvm] MIPS/clang: Fix asm constraint for softfloat (PR #79116)

2024-02-02 Thread YunQiang Su via cfe-commits

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


[clang] 319f4c0 - [Clang][AArch64] Emit 'unimplemented' diagnostic for SME (#80295)

2024-02-02 Thread via cfe-commits

Author: Sander de Smalen
Date: 2024-02-02T11:56:38Z
New Revision: 319f4c03ba2909c7240ac157cc46216bf1518c10

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

LOG: [Clang][AArch64] Emit 'unimplemented' diagnostic for SME (#80295)

When a function F has ZA and ZT0 state, calls another function G that 
only shares ZT0 state with its caller, F will have to save ZA before
the call to G, and restore it afterwards (rather than setting up a
lazy-sve).

This is not yet implemented in LLVM and does not result in a 
compile-time error either. So instead of silently generating incorrect
code, it's better to emit an error saying this is not yet implemented.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/aarch64-sme-func-attrs.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 7638a7e84c3c0..21a767cfc5e5c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3711,6 +3711,12 @@ def err_sme_za_call_no_za_state : Error<
   "call to a shared ZA function requires the caller to have ZA state">;
 def err_sme_zt0_call_no_zt0_state : Error<
   "call to a shared ZT0 function requires the caller to have ZT0 state">;
+def err_sme_unimplemented_za_save_restore : Error<
+  "call to a function that shares state other than 'za' from a "
+  "function that has live 'za' state requires a spill/fill of ZA, which is not 
yet "
+  "implemented">;
+def note_sme_use_preserves_za : Note<
+  "add '__arm_preserves(\"za\")' to the callee if it preserves ZA">;
 def err_sme_definition_using_sm_in_non_sme_target : Error<
   "function executed in streaming-SVE mode requires 'sme'">;
 def err_sme_definition_using_za_in_non_sme_target : Error<

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 7b877da1a928f..b071a02ca3713 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -7513,47 +7513,43 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   }
 }
 
-// If the callee uses AArch64 SME ZA state but the caller doesn't define
-// any, then this is an error.
-FunctionType::ArmStateValue ArmZAState =
+FunctionType::ArmStateValue CalleeArmZAState =
 FunctionType::getArmZAState(ExtInfo.AArch64SMEAttributes);
-if (ArmZAState != FunctionType::ARM_None) {
+FunctionType::ArmStateValue CalleeArmZT0State =
+FunctionType::getArmZT0State(ExtInfo.AArch64SMEAttributes);
+if (CalleeArmZAState != FunctionType::ARM_None ||
+CalleeArmZT0State != FunctionType::ARM_None) {
   bool CallerHasZAState = false;
+  bool CallerHasZT0State = false;
   if (const auto *CallerFD = dyn_cast(CurContext)) {
 auto *Attr = CallerFD->getAttr();
 if (Attr && Attr->isNewZA())
   CallerHasZAState = true;
-else if (const auto *FPT =
- CallerFD->getType()->getAs())
-  CallerHasZAState = FunctionType::getArmZAState(
- FPT->getExtProtoInfo().AArch64SMEAttributes) 
!=
- FunctionType::ARM_None;
-  }
-
-  if (!CallerHasZAState)
-Diag(Loc, diag::err_sme_za_call_no_za_state);
-}
-
-// If the callee uses AArch64 SME ZT0 state but the caller doesn't define
-// any, then this is an error.
-FunctionType::ArmStateValue ArmZT0State =
-FunctionType::getArmZT0State(ExtInfo.AArch64SMEAttributes);
-if (ArmZT0State != FunctionType::ARM_None) {
-  bool CallerHasZT0State = false;
-  if (const auto *CallerFD = dyn_cast(CurContext)) {
-auto *Attr = CallerFD->getAttr();
 if (Attr && Attr->isNewZT0())
   CallerHasZT0State = true;
-else if (const auto *FPT =
- CallerFD->getType()->getAs())
-  CallerHasZT0State =
+if (const auto *FPT = CallerFD->getType()->getAs()) 
{
+  CallerHasZAState |=
+  FunctionType::getArmZAState(
+  FPT->getExtProtoInfo().AArch64SMEAttributes) !=
+  FunctionType::ARM_None;
+  CallerHasZT0State |=
   FunctionType::getArmZT0State(
   FPT->getExtProtoInfo().AArch64SMEAttributes) !=
   FunctionType::ARM_None;
+}
   }
 
-  if (!CallerHasZT0State)
+  if (CalleeArmZAState != FunctionType::ARM_None && !CallerHasZAState)
+Diag(Loc, diag::err_sme_za_call_no_za_state);
+
+  if (CalleeArmZT0State != FunctionType::ARM_None && !CallerHasZT0State)
 Diag(Loc, diag::err_sme_zt0_call_no_zt0_state);
+
+  if (CallerHasZAStat

[clang] [Clang][AArch64] Emit 'unimplemented' diagnostic for SME (PR #80295)

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

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


[clang] Diagnose misuse of the cleanup attribute (PR #80040)

2024-02-02 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/80040

>From 93adb872d0e18ff3a1356ab47527d81b61c920cd Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Tue, 30 Jan 2024 23:19:04 +0530
Subject: [PATCH 1/5] Diagnose misuse of the cleanup attribute

Signed-off-by: 11happy 
---
 .../include/clang/Basic/DiagnosticSemaKinds.td  |  4 
 clang/include/clang/Sema/Sema.h |  2 ++
 clang/lib/Sema/SemaDeclAttr.cpp |  7 +++
 clang/lib/Sema/SemaExpr.cpp | 17 +
 4 files changed, 30 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 24d32cb87c89e..99ef803b1e0ec 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8265,6 +8265,10 @@ def warn_condition_is_assignment : Warning<"using the 
result of an "
 def warn_free_nonheap_object
   : Warning<"attempt to call %0 on non-heap %select{object %2|object: block 
expression|object: lambda-to-function-pointer conversion}1">,
 InGroup;
+def warn_free_called_on_unallocated_object : Warning<
+  "'%0' called on unallocated object '%1'">,
+  InGroup;
+  
 
 // Completely identical except off by default.
 def warn_condition_is_idiomatic_assignment : Warning<"using the result "
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b5946e3f3178f..535c479aeb7c5 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12932,6 +12932,8 @@ class Sema final {
 
   bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
 
+  bool IsPointerToPointer(QualType LHSType, QualType RHSType);
+
   bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
 
   ExprResult PerformImplicitConversion(Expr *From, QualType ToType,
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 069571fcf7864..e149f745cc2f9 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3782,6 +3782,13 @@ static void handleCleanupAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   }
 
   D->addAttr(::new (S.Context) CleanupAttr(S.Context, AL, FD));
+
+  if (S.IsPointerToPointer(ParamTy, Ty)) {
+VarDecl *VD = cast(D);
+S.Diag(Loc, diag::warn_free_called_on_unallocated_object)
+<< NI.getName() << VD;
+return;
+  }
 }
 
 static void handleEnumExtensibilityAttr(Sema &S, Decl *D,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 2f1ddfb215116..255e0be3cc842 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10098,6 +10098,23 @@ static bool isVector(QualType QT, QualType 
ElementType) {
   return false;
 }
 
+bool Sema::IsPointerToPointer(QualType LHSType, QualType RHSType) {
+  if (const PointerType *LHSPointer = dyn_cast(LHSType)) {
+// Check if LHS is a single pointer, not a pointer to a pointer.
+if (!isa(LHSPointer->getPointeeType())) {
+  if (isa(RHSType)) {
+if (const PointerType *RHSPtr = dyn_cast(RHSType)) {
+  // If RHSType is a pointer to a pointer type, return True
+  if (isa(RHSPtr->getPointeeType())) {
+return true;
+  }
+}
+  }
+}
+  }
+  return false;
+}
+
 /// CheckAssignmentConstraints (C99 6.5.16) - This routine currently
 /// has code to accommodate several GCC extensions when type checking
 /// pointers. Here are some objectionable examples that GCC considers warnings:

>From 730f4d7f088645f4b49649c73328ca25e681339a Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Wed, 31 Jan 2024 05:45:00 +0530
Subject: [PATCH 2/5] remove whitespace

Signed-off-by: 11happy 
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 99ef803b1e0ec..ae9ad757788e8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8268,7 +8268,6 @@ def warn_free_nonheap_object
 def warn_free_called_on_unallocated_object : Warning<
   "'%0' called on unallocated object '%1'">,
   InGroup;
-  
 
 // Completely identical except off by default.
 def warn_condition_is_idiomatic_assignment : Warning<"using the result "

>From 1a3cc18276be89969d5a262ff12499d20fd925ee Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Wed, 31 Jan 2024 20:58:19 +0530
Subject: [PATCH 3/5] change diagnostic

Signed-off-by: 11happy 
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 ++--
 clang/lib/Sema/SemaDeclAttr.cpp  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ae9ad757788e8..e8165394701c9 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/i

[clang] [APINotes] Upstream Sema logic to apply API Notes to decls (PR #78445)

2024-02-02 Thread Egor Zhdan via cfe-commits

egorzhdan wrote:

@compnerd ping! ;)

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


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

2024-02-02 Thread Timm Baeder via cfe-commits

tbaederr wrote:

> This I think qualifies as a serious problem as it introduces a crash which 
> may occur in _any_ existent codebase. Anyone using the compiler at trunk and 
> encountering the crash has no way to know how to deal with it.

Since we don't have a reproducer, the danger is that we revert the commit but 
never get such a reproducer, leaving us in a state where we can never re-commit 
safely.


If you have some sort of internal deployment, why not revert the commit 
locally? Or just apply something like
```diff
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -1350,7 +1350,7 @@ void TextDiagnostic::emitSnippetAndCaret(
   // emit, starting from the first line.
   std::unique_ptr[]> SourceStyles =
   highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
- DiagOpts->ShowColors, FID, SM);
+ false, FID, SM);

   SmallVector LineRanges =
   prepareAndFilterRanges(Ranges, SM, Lines, FID, LangOpts);
```

That is, unless 
https://github.com/llvm/llvm-project/commit/6d1d2c67e7597dc417c097d5027558b0159ed2e2
 actually fixed the problem already, which would be good to check.





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] [Clang][Sema] Fix crash with const qualified member operator new (PR #80327)

2024-02-02 Thread via cfe-commits


@@ -37,3 +37,10 @@ void instantiateArrayDecay() {
   int a[1];
   arrayDecay(a);
 }
+
+namespace GH79748 {
+typedef decltype(sizeof(0)) size_t;
+struct A {
+  void* operator new(size_t bytes) const; //expected-error {{static member 
function cannot have 'const' qualifier}}

cor3ntin wrote:

And maybe delete, new[], delete[]

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


[clang] [Clang][Sema] Fix crash with const qualified member operator new (PR #80327)

2024-02-02 Thread via cfe-commits


@@ -5914,8 +5914,10 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
 //
 // ... for instance.
 if (IsQualifiedFunction &&
-!(Kind == Member && !D.isExplicitObjectMemberFunction() &&
-  D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static) &&
+(Kind != Member || D.isExplicitObjectMemberFunction() ||
+ D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
+ (D.getContext() == clang::DeclaratorContext::Member &&

cor3ntin wrote:

I think this is worth a comment

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


[clang] Diagnose misuse of the cleanup attribute (PR #80040)

2024-02-02 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

tried to implement the requested changes along the new direction, further I 
have some queries should I let this statament as is or assign to a variable:
```
S.CheckFunctionCall(FD, FunctionCallExpression,
  FD->getType()->getAs());
```
Further I request some guidance on how to use `malloc` & `free` etc , standard 
library functions in tests.
Added Release notes but not sure about its framing.

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


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-02-02 Thread via cfe-commits

eaeltsin wrote:

> #80050 opened. Nevertheless, a reproducer for future work would be 
> appreciated.

I'm running a reduction, but it progresses extremely slowly. Will post as soon 
as it converges to something meaningful (or I'll get some time to reduce the 
test case by hand).


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


[clang] b8025d1 - Reapply "[AMDGPU] Add InstCombine rule for ballot.i64 intrinsic in wave32 mode." (#80303)

2024-02-02 Thread via cfe-commits

Author: Valery Pykhtin
Date: 2024-02-02T13:09:25+01:00
New Revision: b8025d1482a9664463cfc727a0e51cad86fdf2fe

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

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

Reapply #71556 with added lit test constraint: `REQUIRES: 
amdgpu-registered-target`.

This reverts commit 9791e5414960f92396582b9e9ee503ac15799312.

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 43553131f63c5..da1ae24443155 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
@@ -1,3 +1,4 @@
+// REQUIRES: amdgpu-registered-target
 // RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-unknown-unknown 
-D__AMDGCN_WAVEFRONT_SIZE=32 -target-feature +wavefrontsize32 -S -emit-llvm -o 
- %s | FileCheck -enable-var-scope %s
 // RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-unknown-unknown -target-cpu 
gfx1010 -S -emit-llvm -o - %s | FileCheck -enable-var-scope %s
 // RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-unknown-unknown -target-cpu 
gfx1010 -target-feature +wavefrontsize32 -S -emit-llvm -o - %s | FileCheck 
-enable-var-scope %s
@@ -24,13 +25,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 +37,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 07997b7e1678a..5278b552a6551 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
@@ -2391,7 +2391,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 cf1e62151046c..703b0738a3855 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 804283cc20cd6..94c32e3cbe99f 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_noc

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

2024-02-02 Thread Valery Pykhtin via cfe-commits

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


[flang] [clang] [flang]Add support for -moutline-atomics and -mno-outline-atomics (PR #78755)

2024-02-02 Thread Mats Petersson via cfe-commits

https://github.com/Leporacanthicus updated 
https://github.com/llvm/llvm-project/pull/78755

>From a0e256f379130a98ba03793f7102c67d02cbdef1 Mon Sep 17 00:00:00 2001
From: Mats Petersson 
Date: Fri, 19 Jan 2024 16:30:31 +
Subject: [PATCH 1/5] [flang]Add support for -moutline-atomics and
 -mno-outline-atomics

Clang has support for genarting atomic operations as functions rather
than inline atomic operations, using a target feature.

This is useful for code-size, some cases of debugging, and it also affects
the ability to inline functions from C into Fortran or the other way around
when using LTO - the inliner will check the target features to make sure
functions are compatible, and a difference in outline-atomics would disable
the inlining of an outline-atomics into a non-outline-atomics function.
---
 clang/include/clang/Driver/Options.td |  4 ++--
 clang/lib/Driver/ToolChains/Flang.cpp | 23 ++-
 flang/lib/Frontend/CompilerInvocation.cpp | 15 
 flang/test/Driver/aarch64-outline-atomics.f90 | 11 +
 flang/test/Driver/driver-help-hidden.f90  |  2 ++
 flang/test/Driver/driver-help.f90 |  4 
 6 files changed, 56 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Driver/aarch64-outline-atomics.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d940665969339..0eb72f5722541 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4982,10 +4982,10 @@ def mno_fmv : Flag<["-"], "mno-fmv">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Disable function multiversioning">;
 def moutline_atomics : Flag<["-"], "moutline-atomics">, Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   HelpText<"Generate local calls to out-of-line atomic operations">;
 def mno_outline_atomics : Flag<["-"], "mno-outline-atomics">, 
Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   HelpText<"Don't generate local calls to out-of-line atomic operations">;
 def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group,
   HelpText<"Don't generate implicit floating point or vector instructions">;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index b659521df88ff..bdd8afde44165 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -352,6 +352,27 @@ void Flang::addTargetOptions(const ArgList &Args,
 CmdArgs.push_back(Args.MakeArgString(CPU));
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
+   options::OPT_mno_outline_atomics)) {
+// Option -moutline-atomics supported for AArch64 target only.
+if (!Triple.isAArch64()) {
+  D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
+  << Triple.getArchName() << A->getOption().getName();
+} else {
+  if (A->getOption().matches(options::OPT_moutline_atomics)) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+outline-atomics");
+  } else {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("-outline-atomics");
+  }
+}
+  } else if (Triple.isAArch64() &&
+ getToolChain().IsAArch64OutlineAtomicsDefault(Args)) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+outline-atomics");
+  }
+
   // Add the target features.
   switch (TC.getArch()) {
   default:
@@ -672,7 +693,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   CmdArgs.push_back(Args.MakeArgString(TripleStr));
 
   if (isa(JA)) {
-  CmdArgs.push_back("-E");
+CmdArgs.push_back("-E");
   } else if (isa(JA) || isa(JA)) {
 if (JA.getType() == types::TY_Nothing) {
   CmdArgs.push_back("-fsyntax-only");
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index a3c41fb4611f5..74127327e798e 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -402,6 +402,21 @@ static void parseTargetArgs(TargetOptions &opts, 
llvm::opt::ArgList &args) {
   for (const llvm::opt::Arg *currentArg :
args.filtered(clang::driver::options::OPT_target_feature))
 opts.featuresAsWritten.emplace_back(currentArg->getValue());
+
+  llvm::Triple targetTriple{llvm::Triple(opts.triple)};
+  if (const llvm::opt::Arg *A =
+  args.getLastArg(clang::driver::options::OPT_moutline_atomics,
+  clang::driver::options::OPT_mno_outline_atomics)) {
+// Option -moutline-atomics supported for AArch64 target only.
+if (!targetTriple.isAArch64()) {
+  if (A->getOption().matches(
+  clang::driver::options::OPT_moutline_atomics)) {
+opts.featuresAsWritten.push_back("+outline-atomics");
+  } else {
+o

  1   2   3   4   >