[clang] [clang][CodeGen] Zero init unspecified fields in initializers in C (PR #97121)

2024-09-24 Thread via cfe-commits

https://github.com/yabinc updated 
https://github.com/llvm/llvm-project/pull/97121

>From 87aa01b96f46d5de40f5b0c3c3a95a4912edfde7 Mon Sep 17 00:00:00 2001
From: Yabin Cui 
Date: Tue, 24 Sep 2024 10:22:51 -0700
Subject: [PATCH] Zero init unspecified fields in initializers in C (#97459)

hen an initializer is provided to a variable, the Linux kernel relied
on the compiler to zero-initialize unspecified fields, as clarified in
https://www.spinics.net/lists/netdev/msg1007244.html.

But clang doesn't guarantee this:
1. For a union type, if an empty initializer is given, clang only
   initializes bytes for the first field, left bytes for other (larger)
   fields are marked as undef. Accessing those undef bytes can lead
   to undefined behaviors.
2. For a union type, if an initializer explicitly sets a field, left
   bytes for other (larger) fields are marked as undef.
3. When an initializer is given, clang doesn't zero initialize padding.

So this patch makes the following change:
1. In C, when an initializer is provided for a variable, zero-initialize
   undef and padding fields in the initializer.
2. Document the change in LanguageExtensions.rst.

As suggested in 
https://github.com/llvm/llvm-project/issues/78034#issuecomment-2183437928,
the change isn't required by C23, but it's standards conforming to do
so.
---
 clang/docs/LanguageExtensions.rst |  23 ++
 clang/lib/CodeGen/CGExprAgg.cpp   |  40 ++-
 clang/lib/CodeGen/CGExprConstant.cpp  |  93 +-
 clang/lib/CodeGen/CodeGenModule.h |  51 
 ...07-22-bitfield-init-after-zero-len-array.c |   2 +-
 clang/test/CodeGen/2008-08-07-AlignPadding1.c |   4 +-
 .../CodeGen/2009-06-14-anonymous-union-init.c |   4 +-
 clang/test/CodeGen/64bit-swiftcall.c  |  12 +-
 clang/test/CodeGen/arm-swiftcall.c|   4 +-
 clang/test/CodeGen/const-init.c   |   4 +-
 clang/test/CodeGen/decl.c |   4 +-
 clang/test/CodeGen/designated-initializers.c  |  12 +-
 clang/test/CodeGen/ext-int.c  |  18 +-
 clang/test/CodeGen/flexible-array-init.c  |  24 +-
 clang/test/CodeGen/global-init.c  |   2 +-
 clang/test/CodeGen/init.c |  19 --
 .../linux-kernel-struct-union-initializer.c   | 267 ++
 .../linux-kernel-struct-union-initializer2.c  | 140 +
 clang/test/CodeGen/mingw-long-double.c|   9 +-
 clang/test/CodeGen/mms-bitfields.c|   4 +-
 clang/test/CodeGen/union-init2.c  |   4 +-
 clang/test/CodeGen/windows-swiftcall.c|  12 +-
 .../CodeGenObjC/designated-initializers.m |   2 +-
 23 files changed, 658 insertions(+), 96 deletions(-)
 create mode 100644 clang/test/CodeGen/linux-kernel-struct-union-initializer.c
 create mode 100644 clang/test/CodeGen/linux-kernel-struct-union-initializer2.c

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 0c6b9b1b8f9ce4..f4be97047422fa 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -5860,3 +5860,26 @@ specify the starting offset to begin embedding from. The 
resources is treated
 as being empty if the specified offset is larger than the number of bytes in
 the resource. The offset will be applied *before* any ``limit`` parameters are
 applied.
+
+Union and aggregate initialization in C
+===
+
+In C23 (N2900), when an object is initialized from initializer ``= {}``, all
+elements of arrays, all members of structs, and the first members of unions are
+empty-initialized recursively. In addition, all padding bits are initialized to
+zero.
+
+Clang guarantees the following behaviors:
+
+* ``1:`` Clang supports initializer ``= {}`` mentioned above in all C
+  standards.
+
+* ``2:`` When unions are initialized from initializer ``= {}``, bytes outside
+  of the first members of unions are also initialized to zero.
+
+* ``3:`` When unions, structures and arrays are initialized from initializer
+  ``= { initializer-list }``, all members not explicitly initialized in
+  the initializer list are empty-initialized recursively. In addition, all
+  padding bits are initialized to zero.
+
+Currently, the above extension only applies to C source code, not C++.
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index bbfc6672ecc25a..43f3bcc95fe767 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -1698,6 +1698,17 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
   // Prepare a 'this' for CXXDefaultInitExprs.
   CodeGenFunction::FieldConstructionScope FCS(CGF, Dest.getAddress());
 
+  const bool ZeroInitPadding =
+  CGF.CGM.shouldZeroInitPadding() && !Dest.isZeroed();
+  const Address BaseLoc = Dest.getAddress().withElementType(CGF.Int8Ty);
+  auto DoZeroInitPadding = [&](CharUnits Offset, CharUnits Size) {
+if (Size.isPositive()) {
+  Address Loc = CGF.Builder.Create

[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)

2024-09-24 Thread via cfe-commits

eddyz87 wrote:

@peilin-ye ,

> Got it, rebased and added a 4th commit (can't say I like the 
> one-commit-per-PR policy either :-) to do this in v3. Please take another 
> look.

lgtm, but please note CI failure:

```
_bk;t=1727211158841FAIL: LLVM :: CodeGen/BPF/acquire-release.ll (11379 of 
55168)
_bk;t=1727211158841 TEST 'LLVM :: 
CodeGen/BPF/acquire-release.ll' FAILED 
_bk;t=1727211158841Exit Code: 2
_bk;t=1727211158841
_bk;t=1727211158841Command Output (stdout):
_bk;t=1727211158841--
_bk;t=1727211158841# RUN: at line 1
_bk;t=1727211158841c:\ws\src\build\bin\llc.exe < 
C:\ws\src\llvm\test\CodeGen\BPF\acquire-release.ll -march=bpfel -mcpu=v5 
-verify-machineinstrs -show-mc-encoding | c:\ws\src\build\bin\filecheck.exe 
C:\ws\src\llvm\test\CodeGen\BPF\acquire-release.ll
_bk;t=1727211158841# executed command: 'c:\ws\src\build\bin\llc.exe' 
-march=bpfel -mcpu=v5 -verify-machineinstrs -show-mc-encoding
_bk;t=1727211158841# .---command stderr
_bk;t=1727211158841# | Assertion failed: From.getNode() != To.getNode() && 
"Potential legalization loop!", file 
C:\ws\src\llvm\lib\CodeGen\SelectionDAG\LegalizeTypes.cpp, line 646
_bk;t=1727211158841# | PLEASE submit a bug report to 
https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
_bk;t=1727211158841# | Stack dump:
_bk;t=1727211158841# | 0. Program arguments: 
c:\\ws\\src\\build\\bin\\llc.exe -march=bpfel -mcpu=v5 -verify-machineinstrs 
-show-mc-encoding
_bk;t=1727211158841# | 1. Running pass 'Function Pass Manager' on module 
''.
_bk;t=1727211158841# | 2. Running pass 'BPF DAG->DAG Pattern Instruction 
Selection' on function '@store_release_i8'
_bk;t=1727211158841# | Exception Code: 0x8003
_bk;t=1727211158841# |  #0 0x7ff732c3a705 
(c:\ws\src\build\bin\llc.exe+0x2b4a705)
```

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


[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)

2024-09-24 Thread via cfe-commits

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


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


[clang] [clang][CodeGen] Zero init unspecified fields in initializers in C (PR #97121)

2024-09-24 Thread via cfe-commits

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


[clang] [compiler-rt] [Clang][compiler-rt][UBSan] Remove `BuiltinCheckKind` (PR #109088)

2024-09-24 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/109088

>From 255c4af822ea327b51547c5c666b172bb81c6454 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Wed, 18 Sep 2024 13:58:24 +0800
Subject: [PATCH 1/2] [Clang][compiler-rt][UBSan] Remove `BuiltinCheckKind`

---
 clang/lib/CodeGen/CGBuiltin.cpp   | 20 ++-
 clang/lib/CodeGen/CodeGenFunction.h   | 11 ++
 compiler-rt/lib/ubsan/ubsan_handlers.cpp  |  5 ++---
 compiler-rt/lib/ubsan/ubsan_handlers.h|  8 
 .../test/ubsan/TestCases/Misc/builtins.cpp| 14 ++---
 5 files changed, 17 insertions(+), 41 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a52e880a764252..7509d0eb097bb6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1994,11 +1994,7 @@ struct CallObjCArcUse final : EHScopeStack::Cleanup {
 };
 }
 
-Value *CodeGenFunction::EmitCheckedArgForBuiltin(const Expr *E,
- BuiltinCheckKind Kind) {
-  assert((Kind == BCK_CLZPassedZero || Kind == BCK_CTZPassedZero)
-  && "Unsupported builtin check kind");
-
+Value *CodeGenFunction::EmitCheckedArgForBuiltin(const Expr *E) {
   Value *ArgValue = EmitScalarExpr(E);
   if (!SanOpts.has(SanitizerKind::Builtin))
 return ArgValue;
@@ -2008,9 +2004,7 @@ Value *CodeGenFunction::EmitCheckedArgForBuiltin(const 
Expr *E,
   ArgValue, llvm::Constant::getNullValue(ArgValue->getType()));
   EmitCheck(std::make_pair(Cond, SanitizerKind::Builtin),
 SanitizerHandler::InvalidBuiltin,
-{EmitCheckSourceLocation(E->getExprLoc()),
- llvm::ConstantInt::get(Builder.getInt8Ty(), Kind)},
-std::nullopt);
+{EmitCheckSourceLocation(E->getExprLoc())}, std::nullopt);
   return ArgValue;
 }
 
@@ -3228,9 +3222,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_ctzg &&
E->getNumArgs() > 1;
 
-Value *ArgValue =
-HasFallback ? EmitScalarExpr(E->getArg(0))
-: EmitCheckedArgForBuiltin(E->getArg(0), 
BCK_CTZPassedZero);
+Value *ArgValue = HasFallback ? EmitScalarExpr(E->getArg(0))
+  : EmitCheckedArgForBuiltin(E->getArg(0));
 
 llvm::Type *ArgType = ArgValue->getType();
 Function *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType);
@@ -3260,9 +3253,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_clzg &&
E->getNumArgs() > 1;
 
-Value *ArgValue =
-HasFallback ? EmitScalarExpr(E->getArg(0))
-: EmitCheckedArgForBuiltin(E->getArg(0), 
BCK_CLZPassedZero);
+Value *ArgValue = HasFallback ? EmitScalarExpr(E->getArg(0))
+  : EmitCheckedArgForBuiltin(E->getArg(0));
 
 llvm::Type *ArgType = ArgValue->getType();
 Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType);
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 6802dc7f0c1598..69bb58f0e617c5 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -5078,16 +5078,9 @@ class CodeGenFunction : public CodeGenTypeCache {
  bool IsSubtraction, SourceLocation Loc,
  CharUnits Align, const Twine &Name = "");
 
-  /// Specifies which type of sanitizer check to apply when handling a
-  /// particular builtin.
-  enum BuiltinCheckKind {
-BCK_CTZPassedZero,
-BCK_CLZPassedZero,
-  };
-
   /// Emits an argument for a call to a builtin. If the builtin sanitizer is
-  /// enabled, a runtime check specified by \p Kind is also emitted.
-  llvm::Value *EmitCheckedArgForBuiltin(const Expr *E, BuiltinCheckKind Kind);
+  /// enabled, a runtime zero check is also emitted.
+  llvm::Value *EmitCheckedArgForBuiltin(const Expr *E);
 
   /// Emit a description of a type in a format suitable for passing to
   /// a runtime sanitizer handler.
diff --git a/compiler-rt/lib/ubsan/ubsan_handlers.cpp 
b/compiler-rt/lib/ubsan/ubsan_handlers.cpp
index 27d01653f088da..ffefbded64ad14 100644
--- a/compiler-rt/lib/ubsan/ubsan_handlers.cpp
+++ b/compiler-rt/lib/ubsan/ubsan_handlers.cpp
@@ -634,12 +634,11 @@ static void handleInvalidBuiltin(InvalidBuiltinData 
*Data, ReportOptions Opts) {
   ScopedReport R(Opts, Loc, ET);
 
   Diag(Loc, DL_Error, ET,
-   "passing zero to %0, which is not a valid argument")
-<< ((Data->Kind == BCK_CTZPassedZero) ? "ctz()" : "clz()");
+   "passing zero to __builtin_ctz/clz, which is not a valid argument");
 }
 
 void __ubsan::__ubsan_handle_invalid_builtin(InvalidBuiltinData *Data) {
-  GET_REPORT_OPTIONS(true);
+  GET_REPORT_OPTIONS(false

[clang] [compiler-rt] [UBSan] Diagnose assumption violation (PR #104741)

2024-09-24 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/104741

>From e2ce302a0d3649594ff1a6b94420f815d0e1acde Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Mon, 19 Aug 2024 15:22:39 +0800
Subject: [PATCH 1/2] [UBSan] Diagnose assumption violation

---
 clang/lib/CodeGen/CGBuiltin.cpp| 18 --
 clang/lib/CodeGen/CGStmt.cpp   |  3 ++-
 clang/lib/CodeGen/CodeGenFunction.h|  1 +
 clang/test/CodeGen/ubsan-builtin-checks.c  | 17 +
 compiler-rt/lib/ubsan/ubsan_handlers.cpp   |  8 +---
 compiler-rt/lib/ubsan/ubsan_handlers.h |  1 +
 .../test/ubsan/TestCases/Misc/builtins.cpp | 16 ++--
 7 files changed, 52 insertions(+), 12 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f424ddaa175400..83da5d7d75be3b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1996,16 +1996,21 @@ struct CallObjCArcUse final : EHScopeStack::Cleanup {
 
 Value *CodeGenFunction::EmitCheckedArgForBuiltin(const Expr *E,
  BuiltinCheckKind Kind) {
-  assert((Kind == BCK_CLZPassedZero || Kind == BCK_CTZPassedZero)
-  && "Unsupported builtin check kind");
+  assert((Kind == BCK_CLZPassedZero || Kind == BCK_CTZPassedZero ||
+  Kind == BCK_AssumePassedFalse) &&
+ "Unsupported builtin check kind");
 
-  Value *ArgValue = EmitScalarExpr(E);
+  Value *ArgValue =
+  Kind == BCK_AssumePassedFalse ? EvaluateExprAsBool(E) : 
EmitScalarExpr(E);
   if (!SanOpts.has(SanitizerKind::Builtin))
 return ArgValue;
 
   SanitizerScope SanScope(this);
-  Value *Cond = Builder.CreateICmpNE(
-  ArgValue, llvm::Constant::getNullValue(ArgValue->getType()));
+  Value *Cond =
+  Kind == BCK_AssumePassedFalse
+  ? ArgValue
+  : Builder.CreateICmpNE(
+ArgValue, llvm::Constant::getNullValue(ArgValue->getType()));
   EmitCheck(std::make_pair(Cond, SanitizerKind::Builtin),
 SanitizerHandler::InvalidBuiltin,
 {EmitCheckSourceLocation(E->getExprLoc()),
@@ -3424,7 +3429,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 if (E->getArg(0)->HasSideEffects(getContext()))
   return RValue::get(nullptr);
 
-Value *ArgValue = EmitScalarExpr(E->getArg(0));
+Value *ArgValue =
+EmitCheckedArgForBuiltin(E->getArg(0), BCK_AssumePassedFalse);
 Function *FnAssume = CGM.getIntrinsic(Intrinsic::assume);
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 7158a06e6bc3b3..291639346d8952 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -754,7 +754,8 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
   const Expr *Assumption = cast(A)->getAssumption();
   if (getLangOpts().CXXAssumptions &&
   !Assumption->HasSideEffects(getContext())) {
-llvm::Value *AssumptionVal = EvaluateExprAsBool(Assumption);
+llvm::Value *AssumptionVal =
+EmitCheckedArgForBuiltin(Assumption, BCK_AssumePassedFalse);
 Builder.CreateAssumption(AssumptionVal);
   }
 } break;
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 57e0b7f91e9bf8..99db330f3316e5 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -5070,6 +5070,7 @@ class CodeGenFunction : public CodeGenTypeCache {
   enum BuiltinCheckKind {
 BCK_CTZPassedZero,
 BCK_CLZPassedZero,
+BCK_AssumePassedFalse,
   };
 
   /// Emits an argument for a call to a builtin. If the builtin sanitizer is
diff --git a/clang/test/CodeGen/ubsan-builtin-checks.c 
b/clang/test/CodeGen/ubsan-builtin-checks.c
index c7f6078f903bad..8535ec915ac346 100644
--- a/clang/test/CodeGen/ubsan-builtin-checks.c
+++ b/clang/test/CodeGen/ubsan-builtin-checks.c
@@ -51,3 +51,20 @@ void check_clz(int n) {
   // CHECK: call void @__ubsan_handle_invalid_builtin
   __builtin_clzg((unsigned int)n);
 }
+
+// CHECK: define{{.*}} void @check_assume
+void check_assume(int n) {
+  // CHECK: [[TOBOOL:%.*]] = icmp ne i32 [[N:%.*]], 0
+  // CHECK-NEXT: br i1 [[TOBOOL]]
+  //
+  // Handler block:
+  // CHECK: call void @__ubsan_handle_invalid_builtin
+  // CHECK-NEXT: unreachable
+  //
+  // Continuation block:
+  // CHECK: call void @llvm.assume(i1 [[TOBOOL]])
+  __builtin_assume(n);
+
+  // CHECK: call void @__ubsan_handle_invalid_builtin
+  __attribute__((assume(n)));
+}
diff --git a/compiler-rt/lib/ubsan/ubsan_handlers.cpp 
b/compiler-rt/lib/ubsan/ubsan_handlers.cpp
index 27d01653f088da..44aec6b8b05cd2 100644
--- a/compiler-rt/lib/ubsan/ubsan_handlers.cpp
+++ b/compiler-rt/lib/ubsan/ubsan_handlers.cpp
@@ -633,9 +633,11 @@ static void handleInvalidBuiltin(InvalidBuiltinData *Data, 

[clang] 4c4fb6a - [BPF] Do atomic_fetch_*() pattern matching with memory ordering (#107343)

2024-09-24 Thread via cfe-commits

Author: yonghong-song
Date: 2024-09-24T15:55:50-07:00
New Revision: 4c4fb6ada7a168e5129a22efb4d604bb6fc60b17

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

LOG: [BPF] Do atomic_fetch_*() pattern matching with memory ordering (#107343)

Three commits in this pull request:
commit 1: implement pattern matching for memory ordering seq_cst,
acq_rel, release, acquire and monotonic. Specially, for monotonic memory
ordering (relaxed memory model), if no return value is used, locked insn
is used.
commit 2: add support to handle dwarf atomic modifier in BTF generation.
Actually atomic modifier is ignored in BTF.
commit 3: add tests for new atomic ordering support and BTF support with
_Atomic type.
I removed RFC tag as now patch sets are in reasonable states.

For atomic fetch_and_*() operations, do pattern matching with memory
ordering
seq_cst, acq_rel, release, acquire and monotonic (relaxed). For
fetch_and_*()
operations with seq_cst/acq_rel/release/acquire ordering,
atomic_fetch_*()
instructions are generated. For monotonic ordering, locked insns are
generated
if return value is not used. Otherwise, atomic_fetch_*() insns are used.
The main motivation is to resolve the kernel issue [1].
   
The following are memory ordering are supported:
  seq_cst, acq_rel, release, acquire, relaxed
Current gcc style __sync_fetch_and_*() operations are all seq_cst.

To use explicit memory ordering, the _Atomic type is needed. The
following is
an example:

```
$ cat test.c
\#include 
void f1(_Atomic int *i) {
   (void)__c11_atomic_fetch_and(i, 10, memory_order_relaxed);
}
void f2(_Atomic int *i) {
   (void)__c11_atomic_fetch_and(i, 10, memory_order_acquire);
}
void f3(_Atomic int *i) {
   (void)__c11_atomic_fetch_and(i, 10, memory_order_seq_cst);
}
$ cat run.sh
clang  -I/home/yhs/work/bpf-next/tools/testing/selftests/bpf -O2 --target=bpf 
-c test.c -o test.o && llvm-objdum
p -d test.o
$ ./run.sh
   
test.o: file format elf64-bpf
   
Disassembly of section .text:

 :
   0:   b4 02 00 00 0a 00 00 00 w2 = 0xa
   1:   c3 21 00 00 50 00 00 00 lock *(u32 *)(r1 + 0x0) &= w2
   2:   95 00 00 00 00 00 00 00 exit
   
0018 :
   3:   b4 02 00 00 0a 00 00 00 w2 = 0xa
   4:   c3 21 00 00 51 00 00 00 w2 = atomic_fetch_and((u32 *)(r1 + 
0x0), w2)
   5:   95 00 00 00 00 00 00 00 exit
   
0030 :
   6:   b4 02 00 00 0a 00 00 00 w2 = 0xa
   7:   c3 21 00 00 51 00 00 00 w2 = atomic_fetch_and((u32 *)(r1 + 
0x0), w2)
   8:   95 00 00 00 00 00 00 00 exit
```

The following is another example where return value is used:

```
$ cat test1.c
\#include 
int f1(_Atomic int *i) {
   return __c11_atomic_fetch_and(i, 10, memory_order_relaxed);
}  
int f2(_Atomic int *i) {
   return __c11_atomic_fetch_and(i, 10, memory_order_acquire);
}  
int f3(_Atomic int *i) {
   return __c11_atomic_fetch_and(i, 10, memory_order_seq_cst);
}  
$ cat run.sh
clang  -I/home/yhs/work/bpf-next/tools/testing/selftests/bpf -O2 --target=bpf 
-c test1.c -o test1.o && llvm-objdump -d test1.o
$ ./run.sh

test.o: file format elf64-bpf

Disassembly of section .text:

 :
   0:   b4 00 00 00 0a 00 00 00 w0 = 0xa
   1:   c3 01 00 00 51 00 00 00 w0 = atomic_fetch_and((u32 *)(r1 + 
0x0), w0)
   2:   95 00 00 00 00 00 00 00 exit
   
0018 :
   3:   b4 00 00 00 0a 00 00 00 w0 = 0xa
   4:   c3 01 00 00 51 00 00 00 w0 = atomic_fetch_and((u32 *)(r1 + 
0x0), w0)
   5:   95 00 00 00 00 00 00 00 exit
   
0030 :
   6:   b4 00 00 00 0a 00 00 00 w0 = 0xa
   7:   c3 01 00 00 51 00 00 00 w0 = atomic_fetch_and((u32 *)(r1 + 
0x0), w0)
   8:   95 00 00 00 00 00 00 00 exit
```

You can see that for relaxed memory ordering, if return value is used,
atomic_fetch_and()
insn is used. Otherwise, if return value is not used, locked insn is
used.

Here is another example with global _Atomic variable:

```
$ cat test3.c
\#include 

_Atomic int i;

void f1(void) {
   (void)__c11_atomic_fetch_and(&i, 10, memory_order_relaxed);
}
void f2(void) {
   (void)__c11_atomic_fetch_and(&i, 10, memory_order_seq_cst);
}
$ cat run.sh
clang  -I/home/yhs/work/bpf-next/tools/testing/selftests/bpf -O2 --target=bpf 
-c test3.c -o test3.o && llvm-objdump -d test3.o
$ ./run.sh

test3.o:file format elf64-bpf

Disassembly of section .text:

 :
   0:   b4 01 00 00 0a 00 00 00 w1 = 0xa
   1:   18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0x0 ll
   3:   c3 12 00 00 50 00 00 00 lock *(u32 *)(r2 + 0x0) &= w1
   4:   95 00 00 00 00 00 00 00 exit
   
0028 :
   5:   b4 01 00 00 0a 00 00 00 w1 = 0xa
   6:   18 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r2 = 0x0 ll

[clang] [compiler-rt] [UBSan] Diagnose assumption violation (PR #104741)

2024-09-24 Thread Vitaly Buka via cfe-commits


@@ -633,9 +633,11 @@ static void handleInvalidBuiltin(InvalidBuiltinData *Data, 
ReportOptions Opts) {
 
   ScopedReport R(Opts, Loc, ET);
 
-  Diag(Loc, DL_Error, ET,
-   "passing zero to %0, which is not a valid argument")
-<< ((Data->Kind == BCK_CTZPassedZero) ? "ctz()" : "clz()");
+  if (Data->Kind == BCK_AssumePassedFalse)
+Diag(Loc, DL_Error, ET, "assumption is violated during execution");

vitalybuka wrote:

probably fine as is

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


[clang] [compiler-rt] [UBSan] Diagnose assumption violation (PR #104741)

2024-09-24 Thread Vitaly Buka via cfe-commits


@@ -1996,16 +1996,21 @@ struct CallObjCArcUse final : EHScopeStack::Cleanup {
 
 Value *CodeGenFunction::EmitCheckedArgForBuiltin(const Expr *E,

vitalybuka wrote:

Done

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


[clang] [llvm] [BPF] Do atomic_fetch_*() pattern matching with memory ordering (PR #107343)

2024-09-24 Thread via cfe-commits

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


[clang] 4a9da96 - [clang] Add cc1 --output-asm-variant= to set output syntax

2024-09-24 Thread via cfe-commits

Author: Fangrui Song
Date: 2024-09-24T15:59:33-07:00
New Revision: 4a9da96dc68d878893399210888a03117b39b802

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

LOG: [clang] Add cc1 --output-asm-variant= to set output syntax

2fcaa549a824efeb56e807fcf750a56bf985296b (2010) added cc1as option
`-output-asm-variant` (untested) to set the output syntax.
`clang -cc1as -filetype asm -output-asm-variant 1` allows AT&T input and
Intel output (`AssemblerDialect` is also used by non-x86 targets).

This patch renames the cc1as option (to avoid collision with -o) and
makes it available for cc1 to set output syntax. This allows different
input & output syntax:

```
echo 'asm("mov $1, %eax");' | clang -xc - -S -o - -Xclang --output-asm-variant=1
```

Note: `AsmWriterFlavor` (with a misleading name), used to initialize
MCAsmInfo::AssemblerDialect, is primarily used for assembly input, not
for output.
Therefore,
`echo 'asm("mov $1, %eax");' | clang -x c - -mllvm --x86-asm-syntax=intel -S -o 
-`,
which achieves a similar goal before Clang 19, was unintended.

Close #109157

Pull Request: https://github.com/llvm/llvm-project/pull/109360

Added: 
clang/test/CodeGen/inline-asm-output-variant.c
clang/test/Misc/cc1as-output-asm-variant.c

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/MC/MCTargetOptions.h
llvm/lib/CodeGen/LLVMTargetMachine.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index b600198998d85b..2893377e5a38be 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -96,6 +96,7 @@ CODEGENOPT(EmulatedTLS   , 1, 0) ///< Set by default or 
-f[no-]emulated-tls.
 ENUM_CODEGENOPT(EmbedBitcode, EmbedBitcodeKind, 2, Embed_Off)
 /// Inline asm dialect, -masm=(att|intel)
 ENUM_CODEGENOPT(InlineAsmDialect, InlineAsmDialectKind, 1, IAD_ATT)
+CODEGENOPT(OutputAsmVariant, 2, 3) ///< Set the asm variant for output (3: 
unspecified).
 CODEGENOPT(ForbidGuardVariables , 1, 0) ///< Issue errors if C++ guard 
variables
 ///< are required.
 CODEGENOPT(FunctionSections  , 1, 0) ///< Set when -ffunction-sections is 
enabled.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 002f60350543d9..23bd686a85f526 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7217,6 +7217,9 @@ def fuse_ctor_homing: Flag<["-"], "fuse-ctor-homing">,
 def as_secure_log_file : Separate<["-"], "as-secure-log-file">,
   HelpText<"Emit .secure_log_unique directives to this filename.">,
   MarshallingInfoString>;
+def output_asm_variant : Joined<["--"], "output-asm-variant=">,
+  HelpText<"Select the asm variant (integer) to use for output (3: 
unspecified)">,
+  MarshallingInfoInt, "3">;
 
 } // let Visibility = [CC1Option, CC1AsOption]
 
@@ -8307,8 +8310,6 @@ def filetype : Separate<["-"], "filetype">,
 HelpText<"Specify the output file type ('asm', 'null', or 'obj')">;
 
 // Transliterate Options
-def output_asm_variant : Separate<["-"], "output-asm-variant">,
-HelpText<"Select the asm variant index to use for output">;
 def show_encoding : Flag<["-"], "show-encoding">,
 HelpText<"Show instruction encoding information in transliterate mode">;
 def show_inst : Flag<["-"], "show-inst">,

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index fa49763e312f13..916c92adb89309 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -509,6 +509,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.MCOptions.X86RelaxRelocations = CodeGenOpts.X86RelaxRelocations;
   Options.MCOptions.CompressDebugSections =
   CodeGenOpts.getCompressDebugSections();
+  if (CodeGenOpts.OutputAsmVariant != 3) // 3 (default): not specified
+Options.MCOptions.OutputAsmVariant = CodeGenOpts.OutputAsmVariant;
   Options.MCOptions.ABIName = TargetOpts.ABI;
   for (const auto &Entry : HSOpts.UserEntries)
 if (!Entry.IsFramework &&

diff  --git a/clang/test/CodeGen/inline-asm-output-variant.c 
b/clang/test/CodeGen/inline-asm-output-variant.c
new file mode 100644
index 00..376a8767540343
--- /dev/null
+++ b/clang/test/CodeGen/inline-asm-output-variant.c
@@ -0,0 +1,26 @@
+// REQUIRES: x86-registered-target
+/// AT&T input
+// RUN: %clang_cc1 -triple x86_64 -S --output-asm-variant=0 %s -o - | 
FileCheck --check-prefix=ATT %s
+// RUN: %clang_cc1 -triple x86_64 -S --output-asm-variant=1 %s -o - | 
FileCheck --check-prefix=INTEL %s
+
+/// Intel input
+// RUN: %clang_cc1 -

[clang] [llvm] [clang] Add cc1 --output-asm-variant= to set output syntax (PR #109360)

2024-09-24 Thread Fangrui Song via cfe-commits

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


[clang] [compiler-rt] [UBSan] Diagnose assumption violation (PR #104741)

2024-09-24 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

clang with UBSAN is fine, i am running other tests.

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


[clang] [clang] Fix the local parameter of void type inside the `Requires` expression. (PR #109831)

2024-09-24 Thread via cfe-commits


@@ -9509,6 +9509,19 @@ Sema::ActOnStartRequiresExpr(SourceLocation 
RequiresKWLoc,
   PushDeclContext(BodyScope, Body);
 
   for (ParmVarDecl *Param : LocalParameters) {
+if (Param->getType()->isVoidType()) {
+  if (LocalParameters.size() > 1) {
+Diag(Param->getBeginLoc(), diag::err_void_only_param);
+Body->setInvalidDecl();
+  } else if (Param->getIdentifier()) {
+Diag(Param->getBeginLoc(), diag::err_param_with_void_type);
+Body->setInvalidDecl();
+  } else if (Param->getType().hasQualifiers()) {
+Diag(Param->getBeginLoc(), diag::err_void_param_qualified);
+Body->setInvalidDecl();
+  }
+}

c8ef wrote:

Are you suggesting unifying the parameter type check for void type only or for 
all parameters? As I understand it, the complete parameter check involves a lot 
more branches, such as support for objc, opencl, etc. It appears challenging to 
merge these two aspects seamlessly.

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


[clang] [clang-tools-extra] [clang-tidy] Add support for bsl::optional (PR #101450)

2024-09-24 Thread Nicolas van Kempen via cfe-commits

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


[clang] [clang-tools-extra] [clang-tidy] Add support for bsl::optional (PR #101450)

2024-09-24 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,38 @@
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_NULLABLEVALUE_H_
+#define 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_NULLABLEVALUE_H_
+
+#include "bsl_optional.h"
+
+/// Mock of `bdbl::NullableValue`.

nicovank wrote:

```suggestion
/// Mock of `bdlb::NullableValue`.
```

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


[clang] [clang-tools-extra] [clang-tidy] Add support for bsl::optional (PR #101450)

2024-09-24 Thread Nicolas van Kempen via cfe-commits

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

LGTM. Rebase to fix release notes conflict and I'll merge 👍 

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


[clang] [libclang/python] Improve test coverage (PR #109846)

2024-09-24 Thread Jannick Kremer via cfe-commits


@@ -279,6 +280,90 @@ def test_is_default_method(self):
 self.assertTrue(xc.is_default_method())
 self.assertFalse(yc.is_default_method())
 
+def test_is_deleted_method(self):
+source = "class X { X() = delete; }; class Y { Y(); };"
+tu = get_tu(source, lang="cpp")
+
+xs = get_cursors(tu, "X")
+ys = get_cursors(tu, "Y")
+
+self.assertEqual(len(xs), 2)
+self.assertEqual(len(ys), 2)
+
+xc = xs[1]
+yc = ys[1]
+
+self.assertTrue(xc.is_deleted_method())
+self.assertFalse(yc.is_deleted_method())
+
+def test_is_copy_assignment_operator_method(self):

DeinAlptraum wrote:

Seems like it. I just added an inheriting class to check, and the number of 
detected `operator=` declarations in that TU stays unchanged.

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


[clang] [clang][CodeGen] Zero init unspecified fields in initializers in C (PR #97121)

2024-09-24 Thread via cfe-commits

yabinc wrote:

I manually squashed all the commits. Because there is a merge conflict when I 
was trying git merge --squash locally.

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


[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)

2024-09-24 Thread Zhengxing li via cfe-commits


@@ -0,0 +1,79 @@
+// DirectX target:
+//
+// -- Native Half support test ---
+//
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   --check-prefixes=CHECK \

lizhengxing wrote:

Done.

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


[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)

2024-09-24 Thread Zhengxing li via cfe-commits


@@ -0,0 +1,38 @@
+
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify -verify-ignore-unexpected
+
+float test_too_few_arg() {

lizhengxing wrote:

Done. Add 2 double type tests

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


[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)

2024-09-24 Thread Zhengxing li via cfe-commits

lizhengxing wrote:

> We should announce `__builtin_elementwise_fmod` here: 
> `clang/docs/ReleaseNotes.rst` See @spall PR where we just did this: 
> https://github.com/llvm/llvm-project/pull/108121/files

Done.

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


[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

2024-09-24 Thread Wentao Zhang via cfe-commits

whentojump wrote:

> Hello,
> 
> I noticed that before this patch `clang empty.c -fsanitize=undefined 
> -ffine-grained-bitfield-accesses -c -Werror` (on empty file empty.c) resulted 
> in `warning: option '-ffine-grained-bitfield-accesses' cannot be enabled 
> together with a sanitizer; flag ignored` but with the patch it results in 
> `error: option '-ffine-grained-bitfield-accesses' cannot be enabled together 
> with a sanitizer; flag ignored [-Werror]`
> 
> Is this on purpose?
> 
> (I originally asked this in [#108453 
> (comment)](https://github.com/llvm/llvm-project/pull/108453#issuecomment-2352155766)
>  but I suppose this PR has a bit wider audience.)

We are seeing similar changes in MC/DC-related warnings. Steps to reproduce:

```shell
cat > test.c << 'EOF'
int foo(int x) { return x; }
int main(void) {
int a, b, c, d, e, f, g, h;
a && b && c && d && e && f && g;
a && foo( b && c );
return 0;
}
EOF
clang -Xclang -fmcdc-max-conditions=6 -Werror -Wno-unused-value 
-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc test.c -o test
```



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


[clang] [clang][CodeGen] Zero init unspecified fields in initializers in C (PR #97121)

2024-09-24 Thread via cfe-commits

yabinc wrote:

> but maybe helpful if you can show Linux kernel codesize as a reference, to 
> show there aren't massive issues.

I tested it on android-mainline, which closely follows linux upstream. The size 
change is very small.
.text 0x1139000 -> 0x1138000
.init.text 0x061f08 -> 0x062050
.data 0x20bec8 -> 0x20bf08

The linux kernel enables -ftrivial-auto-var-init=zero by default, which I guess 
already covers most (if not all) initialization instructions.


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


[clang] [compiler-rt] [Clang][compiler-rt][UBSan] Improve `__ubsan_handle_invalid_builtin` (PR #109088)

2024-09-24 Thread Vitaly Buka via cfe-commits

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


[clang] [compiler-rt] [Clang][compiler-rt][UBSan] Improve `__ubsan_handle_invalid_builtin` (PR #109088)

2024-09-24 Thread Vitaly Buka via cfe-commits

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


[clang] [compiler-rt] [Clang][compiler-rt][UBSan] Improve `__ubsan_handle_invalid_builtin` (PR #109088)

2024-09-24 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 7046a9fb05f65f4699a2e88abbcb7dad8a21db2d 
c66becf3c8e1782a7cc3ee5848d259dde6d789d0 --extensions cpp -- 
compiler-rt/lib/ubsan/ubsan_handlers.cpp 
compiler-rt/test/ubsan/TestCases/Misc/builtins.cpp
``





View the diff from clang-format here.


``diff
diff --git a/compiler-rt/lib/ubsan/ubsan_handlers.cpp 
b/compiler-rt/lib/ubsan/ubsan_handlers.cpp
index cb17f6f3ae..9dbe8e6c0c 100644
--- a/compiler-rt/lib/ubsan/ubsan_handlers.cpp
+++ b/compiler-rt/lib/ubsan/ubsan_handlers.cpp
@@ -635,7 +635,7 @@ static void handleInvalidBuiltin(InvalidBuiltinData *Data, 
ReportOptions Opts) {
 
   Diag(Loc, DL_Error, ET,
"passing zero to __builtin_%0(), which is not a valid argument")
-<< ((Data->Kind == BCK_CTZPassedZero) ? "ctz" : "clz");
+  << ((Data->Kind == BCK_CTZPassedZero) ? "ctz" : "clz");
 }
 
 void __ubsan::__ubsan_handle_invalid_builtin(InvalidBuiltinData *Data) {

``




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


[clang] [compiler-rt] [Clang][compiler-rt][UBSan] Improve `__ubsan_handle_invalid_builtin` (PR #109088)

2024-09-24 Thread Vitaly Buka via cfe-commits

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

Sorry, I realized the my request does not make much sense.

Still PR contain message improvement and a bug fix.

LGTM.

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


[clang] [libclang/python] Improve test coverage (PR #109846)

2024-09-24 Thread Jannick Kremer via cfe-commits

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


[clang] [libclang/python] Improve test coverage (PR #109846)

2024-09-24 Thread Jannick Kremer via cfe-commits

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


[clang] [compiler-rt] [Clang][compiler-rt][UBSan] Improve `__ubsan_handle_invalid_builtin` (PR #109088)

2024-09-24 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/109088

>From 255c4af822ea327b51547c5c666b172bb81c6454 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Wed, 18 Sep 2024 13:58:24 +0800
Subject: [PATCH 1/3] [Clang][compiler-rt][UBSan] Remove `BuiltinCheckKind`

---
 clang/lib/CodeGen/CGBuiltin.cpp   | 20 ++-
 clang/lib/CodeGen/CodeGenFunction.h   | 11 ++
 compiler-rt/lib/ubsan/ubsan_handlers.cpp  |  5 ++---
 compiler-rt/lib/ubsan/ubsan_handlers.h|  8 
 .../test/ubsan/TestCases/Misc/builtins.cpp| 14 ++---
 5 files changed, 17 insertions(+), 41 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a52e880a764252..7509d0eb097bb6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1994,11 +1994,7 @@ struct CallObjCArcUse final : EHScopeStack::Cleanup {
 };
 }
 
-Value *CodeGenFunction::EmitCheckedArgForBuiltin(const Expr *E,
- BuiltinCheckKind Kind) {
-  assert((Kind == BCK_CLZPassedZero || Kind == BCK_CTZPassedZero)
-  && "Unsupported builtin check kind");
-
+Value *CodeGenFunction::EmitCheckedArgForBuiltin(const Expr *E) {
   Value *ArgValue = EmitScalarExpr(E);
   if (!SanOpts.has(SanitizerKind::Builtin))
 return ArgValue;
@@ -2008,9 +2004,7 @@ Value *CodeGenFunction::EmitCheckedArgForBuiltin(const 
Expr *E,
   ArgValue, llvm::Constant::getNullValue(ArgValue->getType()));
   EmitCheck(std::make_pair(Cond, SanitizerKind::Builtin),
 SanitizerHandler::InvalidBuiltin,
-{EmitCheckSourceLocation(E->getExprLoc()),
- llvm::ConstantInt::get(Builder.getInt8Ty(), Kind)},
-std::nullopt);
+{EmitCheckSourceLocation(E->getExprLoc())}, std::nullopt);
   return ArgValue;
 }
 
@@ -3228,9 +3222,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_ctzg &&
E->getNumArgs() > 1;
 
-Value *ArgValue =
-HasFallback ? EmitScalarExpr(E->getArg(0))
-: EmitCheckedArgForBuiltin(E->getArg(0), 
BCK_CTZPassedZero);
+Value *ArgValue = HasFallback ? EmitScalarExpr(E->getArg(0))
+  : EmitCheckedArgForBuiltin(E->getArg(0));
 
 llvm::Type *ArgType = ArgValue->getType();
 Function *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType);
@@ -3260,9 +3253,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_clzg &&
E->getNumArgs() > 1;
 
-Value *ArgValue =
-HasFallback ? EmitScalarExpr(E->getArg(0))
-: EmitCheckedArgForBuiltin(E->getArg(0), 
BCK_CLZPassedZero);
+Value *ArgValue = HasFallback ? EmitScalarExpr(E->getArg(0))
+  : EmitCheckedArgForBuiltin(E->getArg(0));
 
 llvm::Type *ArgType = ArgValue->getType();
 Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType);
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 6802dc7f0c1598..69bb58f0e617c5 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -5078,16 +5078,9 @@ class CodeGenFunction : public CodeGenTypeCache {
  bool IsSubtraction, SourceLocation Loc,
  CharUnits Align, const Twine &Name = "");
 
-  /// Specifies which type of sanitizer check to apply when handling a
-  /// particular builtin.
-  enum BuiltinCheckKind {
-BCK_CTZPassedZero,
-BCK_CLZPassedZero,
-  };
-
   /// Emits an argument for a call to a builtin. If the builtin sanitizer is
-  /// enabled, a runtime check specified by \p Kind is also emitted.
-  llvm::Value *EmitCheckedArgForBuiltin(const Expr *E, BuiltinCheckKind Kind);
+  /// enabled, a runtime zero check is also emitted.
+  llvm::Value *EmitCheckedArgForBuiltin(const Expr *E);
 
   /// Emit a description of a type in a format suitable for passing to
   /// a runtime sanitizer handler.
diff --git a/compiler-rt/lib/ubsan/ubsan_handlers.cpp 
b/compiler-rt/lib/ubsan/ubsan_handlers.cpp
index 27d01653f088da..ffefbded64ad14 100644
--- a/compiler-rt/lib/ubsan/ubsan_handlers.cpp
+++ b/compiler-rt/lib/ubsan/ubsan_handlers.cpp
@@ -634,12 +634,11 @@ static void handleInvalidBuiltin(InvalidBuiltinData 
*Data, ReportOptions Opts) {
   ScopedReport R(Opts, Loc, ET);
 
   Diag(Loc, DL_Error, ET,
-   "passing zero to %0, which is not a valid argument")
-<< ((Data->Kind == BCK_CTZPassedZero) ? "ctz()" : "clz()");
+   "passing zero to __builtin_ctz/clz, which is not a valid argument");
 }
 
 void __ubsan::__ubsan_handle_invalid_builtin(InvalidBuiltinData *Data) {
-  GET_REPORT_OPTIONS(true);
+  GET_REPORT_OPTIONS(false

[clang] [libclang/python] Improve test coverage (PR #109846)

2024-09-24 Thread Jannick Kremer via cfe-commits

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


[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v5 (PR #108636)

2024-09-24 Thread Peilin Ye via cfe-commits

peilin-ye wrote:

> lgtm, but please note CI failure:

Oops, I'll take a closer look later.  Thanks!

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


[clang] [clang-tools-extra] [clang-tidy] Add support for bsl::optional (PR #101450)

2024-09-24 Thread Chris Cotter via cfe-commits

https://github.com/ccotter updated 
https://github.com/llvm/llvm-project/pull/101450

>From f7e7681db6ad83878fd00cf250047c98b1b4f051 Mon Sep 17 00:00:00 2001
From: Chris Cotter 
Date: Tue, 23 Jul 2024 10:30:54 -0400
Subject: [PATCH 1/4] [clang-tidy] Add support for bsl::optional

---
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +
 .../bde/types/bdlb_nullablevalue.h| 38 
 .../bde/types/bsl_optional.h  | 75 +++
 .../bugprone/unchecked-optional-access.cpp| 91 +++
 .../Models/UncheckedOptionalAccessModel.cpp   | 62 ++---
 5 files changed, 258 insertions(+), 13 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bdlb_nullablevalue.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bsl_optional.h

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 642ad39cc0c1c5..cc999b142561f0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -104,6 +104,11 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`bugprone-unchecked-optional-access
+  ` to support
+  `bsl::optional` and `bdlb::NullableValue` from
+  _.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bdlb_nullablevalue.h
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bdlb_nullablevalue.h
new file mode 100644
index 00..53efebba1bb9f3
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bdlb_nullablevalue.h
@@ -0,0 +1,38 @@
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_NULLABLEVALUE_H_
+#define 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_NULLABLEVALUE_H_
+
+#include "bsl_optional.h"
+
+/// Mock of `bdbl::NullableValue`.
+namespace BloombergLP::bdlb {
+
+template 
+class NullableValue : public bsl::optional {
+public:
+  constexpr NullableValue() noexcept;
+
+  constexpr NullableValue(bsl::nullopt_t) noexcept;
+
+  NullableValue(const NullableValue &) = default;
+
+  NullableValue(NullableValue &&) = default;
+
+  const T &value() const &;
+  T &value() &;
+
+  // 'operator bool' is inherited from bsl::optional
+
+  constexpr bool isNull() const noexcept;
+
+  template 
+  constexpr T valueOr(U &&v) const &;
+
+  // 'reset' is inherited from bsl::optional
+
+  template  NullableValue &operator=(const U &u);
+};
+
+
+} // namespace BloombergLP::bdlb
+
+#endif // 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_NULLABLEVALUE_H_
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bsl_optional.h
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bsl_optional.h
new file mode 100644
index 00..7e1a129e04a55f
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bsl_optional.h
@@ -0,0 +1,75 @@
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_OPTIONAL_H_
+#define 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_OPTIONAL_H_
+
+/// Mock of `bsl::optional`.
+namespace bsl {
+
+// clang-format off
+template  struct remove_reference  { using type = T; };
+template  struct remove_reference  { using type = T; };
+template  struct remove_reference { using type = T; };
+// clang-format on
+
+template 
+using remove_reference_t = typename remove_reference::type;
+
+template 
+constexpr T &&forward(remove_reference_t &t) noexcept;
+
+template 
+constexpr T &&forward(remove_reference_t &&t) noexcept;
+
+template 
+constexpr remove_reference_t &&move(T &&x);
+
+struct nullopt_t {
+  constexpr explicit nullopt_t() {}
+};
+
+constexpr nullopt_t nullopt;
+
+template 
+class optional {
+public:
+  constexpr optional() noexcept;
+
+  constexpr optional(nullopt_t) noexcept;
+
+  optional(const optional &) = default;
+
+  optional(optional &&) = default;
+
+  const T &operator*() const &;
+  T &operator*() &;
+  const T &&operator*() const &&;
+  T &&operator*() &&;
+
+  const T *operator->() const;
+  T *operator->();
+
+  const T &value() const &;
+  T &value() &;
+  const T &&value() const &&;
+  T &&value() &&;
+
+  constexpr explicit operator bool() const noexcept;
+  constexpr bool has_value() const noexcept;
+
+  template 
+  constexpr T value_or(U &&v) const &;
+  template 
+  T value_or(U &&v) &&;
+
+  template 
+  T &emplace(Args &&...args);
+
+  void reset() noexcept;
+
+  void swap(optional &rhs) noexcept;
+
+  template  optional &operator=(const U &u);
+};
+
+} // namespace bs

[clang] [clang-tools-extra] [clang-tidy] Add support for bsl::optional (PR #101450)

2024-09-24 Thread Chris Cotter via cfe-commits

https://github.com/ccotter updated 
https://github.com/llvm/llvm-project/pull/101450

>From f7e7681db6ad83878fd00cf250047c98b1b4f051 Mon Sep 17 00:00:00 2001
From: Chris Cotter 
Date: Tue, 23 Jul 2024 10:30:54 -0400
Subject: [PATCH 1/3] [clang-tidy] Add support for bsl::optional

---
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +
 .../bde/types/bdlb_nullablevalue.h| 38 
 .../bde/types/bsl_optional.h  | 75 +++
 .../bugprone/unchecked-optional-access.cpp| 91 +++
 .../Models/UncheckedOptionalAccessModel.cpp   | 62 ++---
 5 files changed, 258 insertions(+), 13 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bdlb_nullablevalue.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bsl_optional.h

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 642ad39cc0c1c5..cc999b142561f0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -104,6 +104,11 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`bugprone-unchecked-optional-access
+  ` to support
+  `bsl::optional` and `bdlb::NullableValue` from
+  _.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bdlb_nullablevalue.h
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bdlb_nullablevalue.h
new file mode 100644
index 00..53efebba1bb9f3
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bdlb_nullablevalue.h
@@ -0,0 +1,38 @@
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_NULLABLEVALUE_H_
+#define 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_NULLABLEVALUE_H_
+
+#include "bsl_optional.h"
+
+/// Mock of `bdbl::NullableValue`.
+namespace BloombergLP::bdlb {
+
+template 
+class NullableValue : public bsl::optional {
+public:
+  constexpr NullableValue() noexcept;
+
+  constexpr NullableValue(bsl::nullopt_t) noexcept;
+
+  NullableValue(const NullableValue &) = default;
+
+  NullableValue(NullableValue &&) = default;
+
+  const T &value() const &;
+  T &value() &;
+
+  // 'operator bool' is inherited from bsl::optional
+
+  constexpr bool isNull() const noexcept;
+
+  template 
+  constexpr T valueOr(U &&v) const &;
+
+  // 'reset' is inherited from bsl::optional
+
+  template  NullableValue &operator=(const U &u);
+};
+
+
+} // namespace BloombergLP::bdlb
+
+#endif // 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_NULLABLEVALUE_H_
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bsl_optional.h
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bsl_optional.h
new file mode 100644
index 00..7e1a129e04a55f
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/bde/types/bsl_optional.h
@@ -0,0 +1,75 @@
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_OPTIONAL_H_
+#define 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_BDE_TYPES_OPTIONAL_H_
+
+/// Mock of `bsl::optional`.
+namespace bsl {
+
+// clang-format off
+template  struct remove_reference  { using type = T; };
+template  struct remove_reference  { using type = T; };
+template  struct remove_reference { using type = T; };
+// clang-format on
+
+template 
+using remove_reference_t = typename remove_reference::type;
+
+template 
+constexpr T &&forward(remove_reference_t &t) noexcept;
+
+template 
+constexpr T &&forward(remove_reference_t &&t) noexcept;
+
+template 
+constexpr remove_reference_t &&move(T &&x);
+
+struct nullopt_t {
+  constexpr explicit nullopt_t() {}
+};
+
+constexpr nullopt_t nullopt;
+
+template 
+class optional {
+public:
+  constexpr optional() noexcept;
+
+  constexpr optional(nullopt_t) noexcept;
+
+  optional(const optional &) = default;
+
+  optional(optional &&) = default;
+
+  const T &operator*() const &;
+  T &operator*() &;
+  const T &&operator*() const &&;
+  T &&operator*() &&;
+
+  const T *operator->() const;
+  T *operator->();
+
+  const T &value() const &;
+  T &value() &;
+  const T &&value() const &&;
+  T &&value() &&;
+
+  constexpr explicit operator bool() const noexcept;
+  constexpr bool has_value() const noexcept;
+
+  template 
+  constexpr T value_or(U &&v) const &;
+  template 
+  T value_or(U &&v) &&;
+
+  template 
+  T &emplace(Args &&...args);
+
+  void reset() noexcept;
+
+  void swap(optional &rhs) noexcept;
+
+  template  optional &operator=(const U &u);
+};
+
+} // namespace bs

[clang] [clang] fix assert in ADL finding entity in the implicit global module (PR #109882)

2024-09-24 Thread Chuanqi Xu via cfe-commits

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


[clang] [clang] fix assert in ADL finding entity in the implicit global module (PR #109882)

2024-09-24 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 %t/B.cppm -fprebuilt-module-path=%t 
-emit-module-interface -o %t/B.pcm
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -fprebuilt-module-path=%t -verify 
%t/C.cpp
+
+//--- A.cppm
+module;

ChuanqiXu9 wrote:

nit: `module;` is not required here.

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


[clang] [clang] fix assert in ADL finding entity in the implicit global module (PR #109882)

2024-09-24 Thread Chuanqi Xu via cfe-commits


@@ -115,7 +115,7 @@ C++ Language Changes
 - Allow single element access of GCC vector/ext_vector_type object to be
   constant expression. Supports the `V.xyzw` syntax and other tidbits
   as seen in OpenCL. Selecting multiple elements is left as a future work.
-- Implement `CWG1815 `_. Support lifetime extension 
+- Implement `CWG1815 `_. Support lifetime extension

ChuanqiXu9 wrote:

nit: generally we don't like such unrelated changes. We can land them 
seperately in other NFC patches.

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


[clang] [clang] fix assert in ADL finding entity in the implicit global module (PR #109882)

2024-09-24 Thread Chuanqi Xu via cfe-commits

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

LGTM

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


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-09-24 Thread Andy Kaylor via cfe-commits


@@ -2994,6 +2994,29 @@ A "convergencectrl" operand bundle is only valid on a 
``convergent`` operation.
 When present, the operand bundle must contain exactly one value of token type.
 See the :doc:`ConvergentOperations` document for details.
 
+.. _ob_fpe:
+
+Floating-point Environment Operand Bundles

andykaylor wrote:

Should we place restrictions on which intrinsics these operand bundles can be 
attached to? It seems that they would have no meaning for non-fp intrinsics, 
and it's unclear whether they should require the "strictfp" attribute.

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


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-09-24 Thread Andy Kaylor via cfe-commits

https://github.com/andykaylor commented:

I don't think attaching these operand bundles to the existing set of intrinsics 
is what we want to do. I'd prefer to deprecate the existing intrinsics and 
define some new scheme that uses these bundles on intrinsics that may be used 
in other ways.

One of the original reasons that we talked about the idea of using operand 
bundles this way is that we wanted a way to indicate strict FP constraints on 
vector predication intrinsics without requiring an entire second set of 
intrinsics. I'd like to see a set of generic floating point intrinsics 
(possibly the existing non-constrained intrinsics) that could be modified with 
operand bundles in the way you've implemented here, but I guess we'd need some 
mechanism to ensure that the operand bundles were respected.

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


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-09-24 Thread Andy Kaylor via cfe-commits


@@ -43,6 +43,15 @@ enum ExceptionBehavior : uint8_t {
 
 }
 
+inline bool isValidExceptionBehavior(unsigned X) {

andykaylor wrote:

Do you know why the exception behaviors aren't handled in FloatingPointMode.h?

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


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-09-24 Thread Andy Kaylor via cfe-commits


@@ -2994,6 +2994,29 @@ A "convergencectrl" operand bundle is only valid on a 
``convergent`` operation.
 When present, the operand bundle must contain exactly one value of token type.
 See the :doc:`ConvergentOperations` document for details.
 
+.. _ob_fpe:
+
+Floating-point Environment Operand Bundles
+^^
+
+These operand bundles provide details on how the operation interacts with the
+:ref:`floating-point environment <_floatenv>`. There are two kinds of such
+operand bundles, which characterize interaction with floating-point control
+modes and status bits.
+
+An operand bundle tagged with "fpe.round" may be associated with the operations
+that may depend on rounding mode. It has an integer value, which represents

andykaylor wrote:

I don't like having raw integers represent these values. It's entirely 
unreadable. Could you have the asm printer convert the value to a 
human-readbale token?

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


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-09-24 Thread Andy Kaylor via cfe-commits


@@ -47,6 +47,15 @@ enum class RoundingMode : int8_t {
   Invalid = -1///< Denotes invalid value.
 };
 
+inline bool isValidRoundingMode(int X) {
+  return X >= 0 && X <= static_cast(RoundingMode::Dynamic);

andykaylor wrote:

This isn't a sufficient check. For instance, 5 and 6 are invalid but are less 
than RoundingMode::Dynamic. I don't know why RoundingMode::Dynamic is defined 
the way it is, but it's set to 7.

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


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-09-24 Thread Andy Kaylor via cfe-commits

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


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

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



@@ -2808,27 +2825,63 @@ void ExprEngine::processBranch(const Stmt *Condition,
   std::tie(StTrue, StFalse) = *KnownCondValueAssumption;
 else {
   assert(!isa(Condition));
+  // TODO: instead of this shortcut perhaps it would be better to "rejoin"
+  // the common execution path with
+  // StTrue = StFalse = PrevState;
   builder.generateNode(PrevState, true, PredN);
   builder.generateNode(PrevState, false, PredN);
   continue;
 }
 if (StTrue && StFalse)
   assert(!isa(Condition));
 
+const Expr *EagerlyAssumeExpr =
+PrevState->get();
+const Expr *ConditionExpr = dyn_cast(Condition);
+if (ConditionExpr)
+  ConditionExpr = ConditionExpr->IgnoreParenCasts();
+bool DidEagerlyAssume = EagerlyAssumeExpr == ConditionExpr;
+bool BothFeasible = (DidEagerlyAssume || (StTrue && StFalse)) &&
+builder.isFeasible(true) && builder.isFeasible(false);
+
 // Process the true branch.
 if (builder.isFeasible(true)) {
-  if (StTrue)
+  if (StTrue) {
+if (BothFeasible && IterationsFinishedInLoop &&
+*IterationsFinishedInLoop >= 2) {

isuckatcs wrote:

```suggestion
if (BothFeasible && IterationsFinishedInLoop.value_or(0) >= 2) {
```
Why hardcode `2`?

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


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

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



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

isuckatcs wrote:

Every registered trait should be removed when they are no longer needed to stop 
polluting the states. Also, aren't the traits part of the exploded graph? If 
they are and they are not cleaned up, they pollute the egraph too.

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


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-09-24 Thread Andy Kaylor via cfe-commits


@@ -357,6 +357,9 @@ class IRBuilderBase {
 
   void setConstrainedFPCallAttr(CallBase *I) {
 I->addFnAttr(Attribute::StrictFP);
+MemoryEffects ME = MemoryEffects::inaccessibleMemOnly();

andykaylor wrote:

I think all of the constrained intrinsics currently use inaccessibleMemOnly, 
but it might be a good idea to get this attribute from the intrinsic itself. If 
we added an intrinsic for something like sincos, it would access argument 
memory too.

We should consider adding separate memory effects for fp control and status 
registers. Obviously that would be a separate change set.

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


[clang] [clang][bytecode] Handle vector comma op (PR #109827)

2024-09-24 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/109827

>From fcd804f4ae81b17d0afe94940042deb8a1568197 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Wed, 25 Sep 2024 07:44:40 +0800
Subject: [PATCH] [clang][bytecode] Handle vector comma op in common way

Signed-off-by: yronglin 
---
 clang/lib/AST/ByteCode/Compiler.cpp | 8 +---
 clang/test/Sema/fp16vec-sema.c  | 1 +
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 754cd0db9868b7..b531a2e6491e03 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -725,9 +725,7 @@ bool Compiler::VisitParenExpr(const ParenExpr *E) {
 template 
 bool Compiler::VisitBinaryOperator(const BinaryOperator *BO) {
   // Need short-circuiting for these.
-  if (BO->getType()->isVectorType())
-return this->VisitVectorBinOp(BO);
-  if (BO->isLogicalOp())
+  if (BO->isLogicalOp() && !BO->getType()->isVectorType())
 return this->VisitLogicalBinOp(BO);
 
   const Expr *LHS = BO->getLHS();
@@ -746,6 +744,8 @@ bool Compiler::VisitBinaryOperator(const 
BinaryOperator *BO) {
 
   if (BO->getType()->isAnyComplexType())
 return this->VisitComplexBinOp(BO);
+  if (BO->getType()->isVectorType())
+return this->VisitVectorBinOp(BO);
   if ((LHS->getType()->isAnyComplexType() ||
RHS->getType()->isAnyComplexType()) &&
   BO->isComparisonOp())
@@ -1264,6 +1264,8 @@ bool Compiler::VisitComplexBinOp(const 
BinaryOperator *E) {
 
 template 
 bool Compiler::VisitVectorBinOp(const BinaryOperator *E) {
+  assert(!E->isCommaOp() &&
+ "Comma op should be handled in VisitBinaryOperator");
   assert(E->getType()->isVectorType());
   assert(E->getLHS()->getType()->isVectorType());
   assert(E->getRHS()->getType()->isVectorType());
diff --git a/clang/test/Sema/fp16vec-sema.c b/clang/test/Sema/fp16vec-sema.c
index 80936cd622f7cd..89f01c6dcf47b6 100644
--- a/clang/test/Sema/fp16vec-sema.c
+++ b/clang/test/Sema/fp16vec-sema.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -fsyntax-only 
-Wno-unused-value -verify %s
 
 typedef __fp16 half4 __attribute__ ((vector_size (8)));
 typedef float float4 __attribute__ ((vector_size (16)));

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


[clang] [llvm] [SPIRV][RFC] Rework / extend support for memory scopes (PR #106429)

2024-09-24 Thread Alex Voicu via cfe-commits

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


[clang] [clang][bytecode] Handle vector comma op (PR #109827)

2024-09-24 Thread via cfe-commits

yronglin wrote:

> One of the test failures is related to this change.

Fixed

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


[clang] [RISCV] Enable f16 vget/vset/vcreate/vlmul_ext/vlmul_trunc/vundefined intrinsics with Zvfhmin. (PR #109889)

2024-09-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Craig Topper (topperc)


Changes

These intrinsics don't produce any instructions so don't require Zvfh.

This makes Zvfhmin consistent with Zvfbfmin. See also 
https://github.com/riscv-non-isa/rvv-intrinsic-doc/issues/351

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


11 Files Affected:

- (modified) clang/include/clang/Basic/riscv_vector.td (+34-10) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vcreate.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vget.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_ext_v.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vset.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vundefined.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vget.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vlmul_ext_v.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vlmul_trunc_v.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vset.c
 (+1-1) 


``diff
diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 5ef9602433697c..6e57e51793a712 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -361,7 +361,11 @@ multiclass RVVNonTupleVCreateBuiltin src_lmul_list> {
 defvar src_s = FixedVString.S;
 def vcreate # src_v # dst_v : RVVBuiltin;
+ "csilfd">;
+let RequiredFeatures = ["Zvfhmin"] in
+  def vcreate_h # src_v # dst_v : RVVBuiltin;
 let RequiredFeatures = ["Zvfbfmin"] in
   def vcreate_bf16 # src_v # dst_v : RVVBuiltin;
+def vundefined : RVVBuiltin<"v", "v", "csilfd">;
+let RequiredFeatures = ["Zvfhmin"] in
+  def vundefined_h : RVVBuiltin<"v", "v", "x">;
 let RequiredFeatures = ["Zvfbfmin"] in
   def vundefined_bf16 : RVVBuiltin<"v", "v", "y">;
 def vundefined_u : RVVBuiltin<"Uv", "Uv", "csil">;
@@ -2482,7 +2488,9 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 foreach nf = NFList in {
   let NF = nf in {
 defvar T = "(Tuple:" # nf # ")";
-def : RVVBuiltin;
+def : RVVBuiltin;
+let RequiredFeatures = ["Zvfhmin"] in
+  def : RVVBuiltin;
 let RequiredFeatures = ["Zvfbfmin"] in
   def : RVVBuiltin;
 def : RVVBuiltin;
@@ -2502,7 +2510,10 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 foreach dst_lmul = ["(SFixedLog2LMUL:-3)", "(SFixedLog2LMUL:-2)", 
"(SFixedLog2LMUL:-1)",
 "(SFixedLog2LMUL:0)", "(SFixedLog2LMUL:1)", 
"(SFixedLog2LMUL:2)"] in {
   def vlmul_trunc # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
-  dst_lmul # "vv", "csilxfd", 
dst_lmul # "v">;
+  dst_lmul # "vv", "csilfd", 
dst_lmul # "v">;
+  let RequiredFeatures = ["Zvfhmin"] in
+def vlmul_trunc_h # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
+  dst_lmul # "vv", "x", 
dst_lmul # "v">;
   let RequiredFeatures = ["Zvfbfmin"] in
 def vlmul_trunc_bf16 # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
  dst_lmul # "vv", "y", 
dst_lmul # "v">;
@@ -2523,7 +2534,10 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 foreach dst_lmul = ["(LFixedLog2LMUL:-2)", "(LFixedLog2LMUL:-1)", 
"(LFixedLog2LMUL:-0)",
 "(LFixedLog2LMUL:1)", "(LFixedLog2LMUL:2)", 
"(LFixedLog2LMUL:3)"] in {
   def vlmul_ext # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
-dst_lmul # "vv", "csilxfd", 
dst_lmul # "v">;
+dst_lmul # "vv", "csilfd", 
dst_lmul # "v">;
+  let RequiredFeatures = ["Zvfhmin"] in
+def vlmul_ext_h # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
+dst_lmul # "vv", "x", dst_lmul 
# "v">;
   let RequiredFeatures = ["Zvfbfmin"] in
 def vlmul_ext_bf16 # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
dst_lmul # "vv", "y", 
dst_lmul # "v">;
@@ -2555,14 +2569,18 @@ let HasMasked = false, HasVL = false, IRName = "" in {
   }
   }] in {
 foreach dst_lmul = ["(SFixedLog2LMUL:0)", "(SFixedLog2LMUL:1)", 
"(SF

[clang] [RISCV] Enable f16 vget/vset/vcreate/vlmul_ext/vlmul_trunc/vundefined intrinsics with Zvfhmin. (PR #109889)

2024-09-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Craig Topper (topperc)


Changes

These intrinsics don't produce any instructions so don't require Zvfh.

This makes Zvfhmin consistent with Zvfbfmin. See also 
https://github.com/riscv-non-isa/rvv-intrinsic-doc/issues/351

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


11 Files Affected:

- (modified) clang/include/clang/Basic/riscv_vector.td (+34-10) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vcreate.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vget.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_ext_v.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vlmul_trunc_v.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vset.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vundefined.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vget.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vlmul_ext_v.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vlmul_trunc_v.c
 (+1-1) 
- (modified) 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vset.c
 (+1-1) 


``diff
diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 5ef9602433697c..6e57e51793a712 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -361,7 +361,11 @@ multiclass RVVNonTupleVCreateBuiltin src_lmul_list> {
 defvar src_s = FixedVString.S;
 def vcreate # src_v # dst_v : RVVBuiltin;
+ "csilfd">;
+let RequiredFeatures = ["Zvfhmin"] in
+  def vcreate_h # src_v # dst_v : RVVBuiltin;
 let RequiredFeatures = ["Zvfbfmin"] in
   def vcreate_bf16 # src_v # dst_v : RVVBuiltin;
+def vundefined : RVVBuiltin<"v", "v", "csilfd">;
+let RequiredFeatures = ["Zvfhmin"] in
+  def vundefined_h : RVVBuiltin<"v", "v", "x">;
 let RequiredFeatures = ["Zvfbfmin"] in
   def vundefined_bf16 : RVVBuiltin<"v", "v", "y">;
 def vundefined_u : RVVBuiltin<"Uv", "Uv", "csil">;
@@ -2482,7 +2488,9 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 foreach nf = NFList in {
   let NF = nf in {
 defvar T = "(Tuple:" # nf # ")";
-def : RVVBuiltin;
+def : RVVBuiltin;
+let RequiredFeatures = ["Zvfhmin"] in
+  def : RVVBuiltin;
 let RequiredFeatures = ["Zvfbfmin"] in
   def : RVVBuiltin;
 def : RVVBuiltin;
@@ -2502,7 +2510,10 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 foreach dst_lmul = ["(SFixedLog2LMUL:-3)", "(SFixedLog2LMUL:-2)", 
"(SFixedLog2LMUL:-1)",
 "(SFixedLog2LMUL:0)", "(SFixedLog2LMUL:1)", 
"(SFixedLog2LMUL:2)"] in {
   def vlmul_trunc # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
-  dst_lmul # "vv", "csilxfd", 
dst_lmul # "v">;
+  dst_lmul # "vv", "csilfd", 
dst_lmul # "v">;
+  let RequiredFeatures = ["Zvfhmin"] in
+def vlmul_trunc_h # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
+  dst_lmul # "vv", "x", 
dst_lmul # "v">;
   let RequiredFeatures = ["Zvfbfmin"] in
 def vlmul_trunc_bf16 # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
  dst_lmul # "vv", "y", 
dst_lmul # "v">;
@@ -2523,7 +2534,10 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 foreach dst_lmul = ["(LFixedLog2LMUL:-2)", "(LFixedLog2LMUL:-1)", 
"(LFixedLog2LMUL:-0)",
 "(LFixedLog2LMUL:1)", "(LFixedLog2LMUL:2)", 
"(LFixedLog2LMUL:3)"] in {
   def vlmul_ext # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
-dst_lmul # "vv", "csilxfd", 
dst_lmul # "v">;
+dst_lmul # "vv", "csilfd", 
dst_lmul # "v">;
+  let RequiredFeatures = ["Zvfhmin"] in
+def vlmul_ext_h # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
+dst_lmul # "vv", "x", dst_lmul 
# "v">;
   let RequiredFeatures = ["Zvfbfmin"] in
 def vlmul_ext_bf16 # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
dst_lmul # "vv", "y", 
dst_lmul # "v">;
@@ -2555,14 +2569,18 @@ let HasMasked = false, HasVL = false, IRName = "" in {
   }
   }] in {
 foreach dst_lmul = ["(SFixedLog2LMUL:0)", "(SFixedLog2LMUL:1

[clang] [RISCV] Enable f16 vget/vset/vcreate/vlmul_ext/vlmul_trunc/vundefined intrinsics with Zvfhmin. (PR #109889)

2024-09-24 Thread Craig Topper via cfe-commits

https://github.com/topperc created 
https://github.com/llvm/llvm-project/pull/109889

These intrinsics don't produce any instructions so don't require Zvfh.

This makes Zvfhmin consistent with Zvfbfmin. See also 
https://github.com/riscv-non-isa/rvv-intrinsic-doc/issues/351

>From 810444f5601e1f3c2c2b8f1e040a78e8fc5c37f5 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Tue, 24 Sep 2024 17:50:39 -0700
Subject: [PATCH] [RISCV] Enable f16
 vget/vset/vcreate/vlmul_ext/vlmul_trunc/vundefined intrinsics with Zvfhmin.

This makes Zvfhmin consistent with Zvfbfmin. See also
https://github.com/riscv-non-isa/rvv-intrinsic-doc/issues/351
---
 clang/include/clang/Basic/riscv_vector.td | 44 ++-
 .../non-policy/non-overloaded/vcreate.c   |  2 +-
 .../non-policy/non-overloaded/vget.c  |  2 +-
 .../non-policy/non-overloaded/vlmul_ext_v.c   |  2 +-
 .../non-policy/non-overloaded/vlmul_trunc_v.c |  2 +-
 .../non-policy/non-overloaded/vset.c  |  2 +-
 .../non-policy/non-overloaded/vundefined.c|  2 +-
 .../non-policy/overloaded/vget.c  |  2 +-
 .../non-policy/overloaded/vlmul_ext_v.c   |  2 +-
 .../non-policy/overloaded/vlmul_trunc_v.c |  2 +-
 .../non-policy/overloaded/vset.c  |  2 +-
 11 files changed, 44 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 5ef9602433697c..6e57e51793a712 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -361,7 +361,11 @@ multiclass RVVNonTupleVCreateBuiltin src_lmul_list> {
 defvar src_s = FixedVString.S;
 def vcreate # src_v # dst_v : RVVBuiltin;
+ "csilfd">;
+let RequiredFeatures = ["Zvfhmin"] in
+  def vcreate_h # src_v # dst_v : RVVBuiltin;
 let RequiredFeatures = ["Zvfbfmin"] in
   def vcreate_bf16 # src_v # dst_v : RVVBuiltin;
+def vundefined : RVVBuiltin<"v", "v", "csilfd">;
+let RequiredFeatures = ["Zvfhmin"] in
+  def vundefined_h : RVVBuiltin<"v", "v", "x">;
 let RequiredFeatures = ["Zvfbfmin"] in
   def vundefined_bf16 : RVVBuiltin<"v", "v", "y">;
 def vundefined_u : RVVBuiltin<"Uv", "Uv", "csil">;
@@ -2482,7 +2488,9 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 foreach nf = NFList in {
   let NF = nf in {
 defvar T = "(Tuple:" # nf # ")";
-def : RVVBuiltin;
+def : RVVBuiltin;
+let RequiredFeatures = ["Zvfhmin"] in
+  def : RVVBuiltin;
 let RequiredFeatures = ["Zvfbfmin"] in
   def : RVVBuiltin;
 def : RVVBuiltin;
@@ -2502,7 +2510,10 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 foreach dst_lmul = ["(SFixedLog2LMUL:-3)", "(SFixedLog2LMUL:-2)", 
"(SFixedLog2LMUL:-1)",
 "(SFixedLog2LMUL:0)", "(SFixedLog2LMUL:1)", 
"(SFixedLog2LMUL:2)"] in {
   def vlmul_trunc # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
-  dst_lmul # "vv", "csilxfd", 
dst_lmul # "v">;
+  dst_lmul # "vv", "csilfd", 
dst_lmul # "v">;
+  let RequiredFeatures = ["Zvfhmin"] in
+def vlmul_trunc_h # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
+  dst_lmul # "vv", "x", 
dst_lmul # "v">;
   let RequiredFeatures = ["Zvfbfmin"] in
 def vlmul_trunc_bf16 # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
  dst_lmul # "vv", "y", 
dst_lmul # "v">;
@@ -2523,7 +2534,10 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 foreach dst_lmul = ["(LFixedLog2LMUL:-2)", "(LFixedLog2LMUL:-1)", 
"(LFixedLog2LMUL:-0)",
 "(LFixedLog2LMUL:1)", "(LFixedLog2LMUL:2)", 
"(LFixedLog2LMUL:3)"] in {
   def vlmul_ext # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
-dst_lmul # "vv", "csilxfd", 
dst_lmul # "v">;
+dst_lmul # "vv", "csilfd", 
dst_lmul # "v">;
+  let RequiredFeatures = ["Zvfhmin"] in
+def vlmul_ext_h # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
+dst_lmul # "vv", "x", dst_lmul 
# "v">;
   let RequiredFeatures = ["Zvfbfmin"] in
 def vlmul_ext_bf16 # dst_lmul : RVVBuiltin<"v" # dst_lmul # "v",
dst_lmul # "vv", "y", 
dst_lmul # "v">;
@@ -2555,14 +2569,18 @@ let HasMasked = false, HasVL = false, IRName = "" in {
   }
   }] in {
 foreach dst_lmul = ["(SFixedLog2LMUL:0)", "(SFixedLog2LMUL:1)", 
"(SFixedLog2LMUL:2)"] in {
-  def : RVVBuiltin<"v" # dst_lmul # "v", dst_lmul # "vvKz", "csilxfd", 
dst_lmul # "v">;
+  def : RVVBuiltin<"v" # dst_lmul # "v", dst_lmul # "vvKz", "csilfd", 
dst_lmul # "v">;
+  let RequiredFeatures = ["Zvfhmin"] in
+ 

[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)

2024-09-24 Thread Farzon Lotfi via cfe-commits

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


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


[clang] 7a086e1 - [clang][CodeGen] Zero init unspecified fields in initializers in C (#97121)

2024-09-24 Thread via cfe-commits

Author: yabinc
Date: 2024-09-24T19:06:20-07:00
New Revision: 7a086e1b2dc05f54afae3591614feede727601fa

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

LOG: [clang][CodeGen] Zero init unspecified fields in initializers in C (#97121)

When an initializer is provided to a variable, the Linux kernel relied
on the compiler to zero-initialize unspecified fields, as clarified in
https://www.spinics.net/lists/netdev/msg1007244.html.

But clang doesn't guarantee this:
1. For a union type, if an empty initializer is given, clang only
   initializes bytes for the first field, left bytes for other (larger)
   fields are marked as undef. Accessing those undef bytes can lead
   to undefined behaviors.
2. For a union type, if an initializer explicitly sets a field, left
   bytes for other (larger) fields are marked as undef.
3. When an initializer is given, clang doesn't zero initialize padding.

So this patch makes the following change:
1. In C, when an initializer is provided for a variable, zero-initialize
   undef and padding fields in the initializer.
2. Document the change in LanguageExtensions.rst.

As suggested in
https://github.com/llvm/llvm-project/issues/78034#issuecomment-2183437928,
the change isn't required by C23, but it's standards conforming to do
so.

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

Added: 
clang/test/CodeGen/linux-kernel-struct-union-initializer.c
clang/test/CodeGen/linux-kernel-struct-union-initializer2.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/CodeGen/CGExprConstant.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/test/CodeGen/2008-07-22-bitfield-init-after-zero-len-array.c
clang/test/CodeGen/2008-08-07-AlignPadding1.c
clang/test/CodeGen/2009-06-14-anonymous-union-init.c
clang/test/CodeGen/64bit-swiftcall.c
clang/test/CodeGen/arm-swiftcall.c
clang/test/CodeGen/const-init.c
clang/test/CodeGen/decl.c
clang/test/CodeGen/designated-initializers.c
clang/test/CodeGen/ext-int.c
clang/test/CodeGen/flexible-array-init.c
clang/test/CodeGen/global-init.c
clang/test/CodeGen/init.c
clang/test/CodeGen/mingw-long-double.c
clang/test/CodeGen/mms-bitfields.c
clang/test/CodeGen/union-init2.c
clang/test/CodeGen/windows-swiftcall.c
clang/test/CodeGenObjC/designated-initializers.m

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 0c6b9b1b8f9ce4..f4be97047422fa 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -5860,3 +5860,26 @@ specify the starting offset to begin embedding from. The 
resources is treated
 as being empty if the specified offset is larger than the number of bytes in
 the resource. The offset will be applied *before* any ``limit`` parameters are
 applied.
+
+Union and aggregate initialization in C
+===
+
+In C23 (N2900), when an object is initialized from initializer ``= {}``, all
+elements of arrays, all members of structs, and the first members of unions are
+empty-initialized recursively. In addition, all padding bits are initialized to
+zero.
+
+Clang guarantees the following behaviors:
+
+* ``1:`` Clang supports initializer ``= {}`` mentioned above in all C
+  standards.
+
+* ``2:`` When unions are initialized from initializer ``= {}``, bytes outside
+  of the first members of unions are also initialized to zero.
+
+* ``3:`` When unions, structures and arrays are initialized from initializer
+  ``= { initializer-list }``, all members not explicitly initialized in
+  the initializer list are empty-initialized recursively. In addition, all
+  padding bits are initialized to zero.
+
+Currently, the above extension only applies to C source code, not C++.

diff  --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index bbfc6672ecc25a..43f3bcc95fe767 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -1698,6 +1698,17 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
   // Prepare a 'this' for CXXDefaultInitExprs.
   CodeGenFunction::FieldConstructionScope FCS(CGF, Dest.getAddress());
 
+  const bool ZeroInitPadding =
+  CGF.CGM.shouldZeroInitPadding() && !Dest.isZeroed();
+  const Address BaseLoc = Dest.getAddress().withElementType(CGF.Int8Ty);
+  auto DoZeroInitPadding = [&](CharUnits Offset, CharUnits Size) {
+if (Size.isPositive()) {
+  Address Loc = CGF.Builder.CreateConstGEP(BaseLoc, Offset.getQuantity());
+  llvm::Constant *SizeVal = CGF.Builder.getInt64(Size.getQuantity());
+  CGF.Builder.CreateMemSet(Loc, CGF.Builder.getInt8(0), SizeVal, false);
+}
+  };
+
   if (record->isUnion()) {
 // Only initia

[clang] [clang][CodeGen] Zero init unspecified fields in initializers in C (PR #97121)

2024-09-24 Thread via cfe-commits

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


[clang] [clang] fix assert in ADL finding entity in the implicit global module (PR #109882)

2024-09-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/109882

>From b1a659af4fccba0f7511ab52f0932d5a32958eb7 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Tue, 24 Sep 2024 20:02:05 -0300
Subject: [PATCH 1/2] [clang] fix assert in ADL finding entity in the implicit
 global module

This adds to the assert the implicit global module case as in module
purview.

Fixes #109879
---
 clang/docs/ReleaseNotes.rst   |  7 +--
 clang/lib/Sema/SemaLookup.cpp |  5 +++--
 clang/test/Modules/GH109879-1.cpp | 26 ++
 clang/test/Modules/GH109879-2.cpp | 29 +
 4 files changed, 63 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Modules/GH109879-1.cpp
 create mode 100644 clang/test/Modules/GH109879-2.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e511614fcf2451..5923888383022a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -43,7 +43,7 @@ code bases.
   still supporting SPARC V8 CPUs need to specify ``-mcpu=v8`` with a
   `config file
   `_.
-  
+
 - The ``clang-rename`` tool has been removed.
 
 C/C++ Language Potentially Breaking Changes
@@ -115,7 +115,7 @@ C++ Language Changes
 - Allow single element access of GCC vector/ext_vector_type object to be
   constant expression. Supports the `V.xyzw` syntax and other tidbits
   as seen in OpenCL. Selecting multiple elements is left as a future work.
-- Implement `CWG1815 `_. Support lifetime extension 
+- Implement `CWG1815 `_. Support lifetime extension
   of temporary created by aggregate initialization using a default member
   initializer.
 
@@ -452,6 +452,9 @@ Miscellaneous Clang Crashes Fixed
 
 - Fixed ``-ast-dump`` crashes on codes involving ``concept`` with 
``-ast-dump-decl-types``. (#GH94928)
 
+- Fixed internal assertion firing when a declaration in the implicit global
+  module is found through ADL. (GH#109879)
+
 OpenACC Specific Changes
 
 
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index ed5d44aa898f4f..f3f62474d06441 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -3850,8 +3850,9 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, 
SourceLocation Loc,
 // exports are only valid in module purview and outside of any
 // PMF (although a PMF should not even be present in a module
 // with an import).
-assert(FM && FM->isNamedModule() && !FM->isPrivateModule() &&
-   "bad export context");
+assert(FM &&
+   (FM->isNamedModule() || FM->isImplicitGlobalModule()) &&
+   !FM->isPrivateModule() && "bad export context");
 // .. are attached to a named module M, do not appear in the
 // translation unit containing the point of the lookup..
 if (D->isInAnotherModuleUnit() &&
diff --git a/clang/test/Modules/GH109879-1.cpp 
b/clang/test/Modules/GH109879-1.cpp
new file mode 100644
index 00..a984556b382e20
--- /dev/null
+++ b/clang/test/Modules/GH109879-1.cpp
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 %t/B.cppm -fprebuilt-module-path=%t 
-emit-module-interface -o %t/B.pcm
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -fprebuilt-module-path=%t -verify 
%t/C.cpp
+
+//--- A.cppm
+module;
+export module A;
+export extern "C" void foo(struct Bar);
+
+//--- B.cppm
+module;
+import A;
+export module B;
+
+//--- C.cpp
+import B;
+struct Bar {};
+void test() {
+  foo(Bar());
+  // expected-error@-1 {{declaration of 'foo' must be imported}}
+  // expected-n...@a.cppm:3 {{declaration here is not visible}}
+}
diff --git a/clang/test/Modules/GH109879-2.cpp 
b/clang/test/Modules/GH109879-2.cpp
new file mode 100644
index 00..ccec57839898a2
--- /dev/null
+++ b/clang/test/Modules/GH109879-2.cpp
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 %t/B.cppm -fprebuilt-module-path=%t 
-emit-module-interface -o %t/B.pcm
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -fprebuilt-module-path=%t -verify 
%t/C.cpp
+
+//--- foo.h
+struct Bar {};
+extern "C" void foo(struct Bar);
+
+//--- A.cppm
+module;
+#include "foo.h"
+export module A;
+export extern "C" using ::foo;
+//--- B.cppm
+module;
+import A;
+export module B;
+
+//--- C.cpp
+// expected-no-diagnostics
+import B;
+#include "foo.h"
+void test() {
+  foo(Bar());
+}

>From 0e898547d7fdc7ffc73d0e76a2aa1eb24ce13519 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Tue, 24 Sep 2024 22:55:15 -0300
Subject: [PATCH 2

[clang] 0a42c7c - [clang] fix assert in ADL finding entity in the implicit global module (#109882)

2024-09-24 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2024-09-24T22:57:07-03:00
New Revision: 0a42c7c6679bcc6f7be4b3d103670197acac96a9

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

LOG: [clang] fix assert in ADL finding entity in the implicit global module 
(#109882)

This adds to the assert the implicit global module case as in module
purview.

Fixes #109879

Added: 
clang/test/Modules/GH109879-1.cpp
clang/test/Modules/GH109879-2.cpp

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

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e511614fcf2451..5923888383022a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -43,7 +43,7 @@ code bases.
   still supporting SPARC V8 CPUs need to specify ``-mcpu=v8`` with a
   `config file
   `_.
-  
+
 - The ``clang-rename`` tool has been removed.
 
 C/C++ Language Potentially Breaking Changes
@@ -115,7 +115,7 @@ C++ Language Changes
 - Allow single element access of GCC vector/ext_vector_type object to be
   constant expression. Supports the `V.xyzw` syntax and other tidbits
   as seen in OpenCL. Selecting multiple elements is left as a future work.
-- Implement `CWG1815 `_. Support lifetime extension 
+- Implement `CWG1815 `_. Support lifetime extension
   of temporary created by aggregate initialization using a default member
   initializer.
 
@@ -452,6 +452,9 @@ Miscellaneous Clang Crashes Fixed
 
 - Fixed ``-ast-dump`` crashes on codes involving ``concept`` with 
``-ast-dump-decl-types``. (#GH94928)
 
+- Fixed internal assertion firing when a declaration in the implicit global
+  module is found through ADL. (GH#109879)
+
 OpenACC Specific Changes
 
 

diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index ed5d44aa898f4f..f3f62474d06441 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -3850,8 +3850,9 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, 
SourceLocation Loc,
 // exports are only valid in module purview and outside of any
 // PMF (although a PMF should not even be present in a module
 // with an import).
-assert(FM && FM->isNamedModule() && !FM->isPrivateModule() &&
-   "bad export context");
+assert(FM &&
+   (FM->isNamedModule() || FM->isImplicitGlobalModule()) &&
+   !FM->isPrivateModule() && "bad export context");
 // .. are attached to a named module M, do not appear in the
 // translation unit containing the point of the lookup..
 if (D->isInAnotherModuleUnit() &&

diff  --git a/clang/test/Modules/GH109879-1.cpp 
b/clang/test/Modules/GH109879-1.cpp
new file mode 100644
index 00..72cfb11081e482
--- /dev/null
+++ b/clang/test/Modules/GH109879-1.cpp
@@ -0,0 +1,25 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 %t/B.cppm -fprebuilt-module-path=%t 
-emit-module-interface -o %t/B.pcm
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -fprebuilt-module-path=%t -verify 
%t/C.cpp
+
+//--- A.cppm
+export module A;
+export extern "C" void foo(struct Bar);
+
+//--- B.cppm
+module;
+import A;
+export module B;
+
+//--- C.cpp
+import B;
+struct Bar {};
+void test() {
+  foo(Bar());
+  // expected-error@-1 {{declaration of 'foo' must be imported}}
+  // expected-n...@a.cppm:2 {{declaration here is not visible}}
+}

diff  --git a/clang/test/Modules/GH109879-2.cpp 
b/clang/test/Modules/GH109879-2.cpp
new file mode 100644
index 00..ccec57839898a2
--- /dev/null
+++ b/clang/test/Modules/GH109879-2.cpp
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 %t/B.cppm -fprebuilt-module-path=%t 
-emit-module-interface -o %t/B.pcm
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -fprebuilt-module-path=%t -verify 
%t/C.cpp
+
+//--- foo.h
+struct Bar {};
+extern "C" void foo(struct Bar);
+
+//--- A.cppm
+module;
+#include "foo.h"
+export module A;
+export extern "C" using ::foo;
+//--- B.cppm
+module;
+import A;
+export module B;
+
+//--- C.cpp
+// expected-no-diagnostics
+import B;
+#include "foo.h"
+void test() {
+  foo(Bar());
+}



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


[clang] [clang] fix assert in ADL finding entity in the implicit global module (PR #109882)

2024-09-24 Thread Matheus Izvekov via cfe-commits

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


[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)

2024-09-24 Thread Tristan Ross via cfe-commits

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


[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)

2024-09-24 Thread Tristan Ross via cfe-commits

RossComputerGuy wrote:

Replaced by #109817

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


[clang] [clang] fix assert in ADL finding entity in the implicit global module (PR #109882)

2024-09-24 Thread Matheus Izvekov via cfe-commits


@@ -115,7 +115,7 @@ C++ Language Changes
 - Allow single element access of GCC vector/ext_vector_type object to be
   constant expression. Supports the `V.xyzw` syntax and other tidbits
   as seen in OpenCL. Selecting multiple elements is left as a future work.
-- Implement `CWG1815 `_. Support lifetime extension 
+- Implement `CWG1815 `_. Support lifetime extension

mizvekov wrote:

This is just stray whitespace cleanup that is automatically performed by most 
unix editors.

I don't think doing a whole separate commit to fix it is worth it, specially as 
there aren't a lot of lines changed here.

We do generally just ignore these unless there is so much noise it makes review 
difficult.

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


[clang] [clang][CodeGen] Zero init unspecified fields in initializers in C (PR #97121)

2024-09-24 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-cmake-x86_64-avx512-linux` running on `avx512-intel64` while building 
`clang` at step 13 "test-suite".

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


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

```
Step 13 (test-suite) failure: test (failure)
...
cd 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/MultiSource/Benchmarks/tramp3d-v4
 && 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1.install/bin/llvm-size
 --format=sysv 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/MultiSource/Benchmarks/tramp3d-v4/tramp3d-v4
 > 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/MultiSource/Benchmarks/tramp3d-v4/tramp3d-v4.size
cd 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/MultiSource/Benchmarks/tramp3d-v4
 && /usr/bin/cmake -E create_symlink 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/test-suite/MultiSource/Benchmarks/tramp3d-v4/tramp3d-v4.reference_output
 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/MultiSource/Benchmarks/tramp3d-v4/tramp3d-v4.reference_output
gmake[2]: Leaving directory 
'/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build'
[ 36%] Built target tramp3d-v4
gmake[1]: Leaving directory 
'/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build'
gmake: *** [Makefile:136: all] Error 2
2024-09-24 19:12:47 INFO: Testing...
2024-09-24 19:12:47 INFO: Execute: 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/llvm-lit
 -v -j 32 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build
 -o 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/outputc9h6rhng.json
-- Testing: 2514 tests, 32 workers --
NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_blendvps_253.test (1 of 
2514)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_blendvps_253.test' FAILED 
Executable 
'/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_blendvps_253'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_blendvps_299.test (2 of 
2514)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_blendvps_299.test' FAILED 
Executable 
'/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_blendvps_299'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_addpd_205.test (3 of 
2514)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_addpd_205.test' FAILED 
Executable 
'/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_addpd_205'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_addpd_190.test (4 of 
2514)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_addpd_190.test' FAILED 
Executable 
'/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_addpd_190'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_cmpeqpd_197.test (5 of 
2514)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_cmpeqpd_197.test' FAILED 
Executable 
'/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_cmpeqpd_197'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_addps_117.test (6 of 
2514)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_addps_117.test' FAILED 
Executable 
'/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_addps_117'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_cmpeqpd_212.test (7 of 
2514)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_cmpeqpd_212.test' FAILED 
Executable 
'/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_cmpeqpd_212'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_addps_165.test (8 of 
2514)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_addps_165.test' FAILED 
Executable 
'/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linu

[clang] [clang][CodeGen] Zero init unspecified fields in initializers in C (PR #97121)

2024-09-24 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-armv7-lnt` running 
on `linaro-clang-armv7-lnt` while building `clang` at step 12 "test-suite".

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


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

```
Step 12 (test-suite) failure: test (failure)
...
cd 
/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/SingleSource/UnitTests/Vector
 && /usr/local/bin/cmake -E create_symlink 
/home/tcwg-buildbot/worker/clang-armv7-lnt/test/test-suite/SingleSource/UnitTests/Vector/constpool.reference_output
 
/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/SingleSource/UnitTests/Vector/constpool.reference_output
gmake[2]: Leaving directory 
'/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build'
[ 23%] Built target Vector-constpool
gmake[1]: Leaving directory 
'/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build'
gmake: *** [Makefile:136: all] Error 2

2024-09-25 02:32:56 INFO: Testing...
2024-09-25 02:32:56 INFO: Execute: 
/home/tcwg-buildbot/worker/clang-armv7-lnt/stage1/bin/llvm-lit -v -j 32 
/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build -o 
/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/outputtny53rq4.json
-- Testing: 3423 tests, 32 workers --
NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_vaba_s16_3.test (1 of 
3423)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_vaba_s16_3.test' FAILED 
Executable 
'/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_vaba_s16_3'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_vaba_s16_331.test (2 of 
3423)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_vaba_s16_331.test' FAILED 
Executable 
'/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_vaba_s16_331'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_vaba_s16_662.test (3 of 
3423)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_vaba_s16_662.test' FAILED 
Executable 
'/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_vaba_s16_662'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_vaba_s16_991.test (4 of 
3423)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_vaba_s16_991.test' FAILED 
Executable 
'/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_vaba_s16_991'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_vaba_s32_333.test (5 of 
3423)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_vaba_s32_333.test' FAILED 
Executable 
'/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_vaba_s32_333'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_vaba_s32_5.test (6 of 
3423)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_vaba_s32_5.test' FAILED 
Executable 
'/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_vaba_s32_5'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_vaba_s32_664.test (7 of 
3423)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_vaba_s32_664.test' FAILED 
Executable 
'/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_vaba_s32_664'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_vaba_s32_993.test (8 of 
3423)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_vaba_s32_993.test' FAILED 
Executable 
'/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_vaba_s32_993'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_vaba_s8_1.test (9 of 
3423)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_vaba_s8_1.test' FAILED 
Executable 
'/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_vaba_s8_1'
 is missing

NOEXE: test-suite :: Bitcode/simd_ops/simd_ops_test_op_vaba_s8_329.test (10 of 
3423)
 TEST 'test-suite :: 
Bitcode/simd_ops/simd_ops_test_op_vaba_s8_329.test' FAILED 
Executable 
'/home/tcwg-buildbot/worker/clang-armv7-lnt/test/sandbox/build/Bitcode/simd_ops/simd_ops_test_op_vaba_s8_329'
 is missing


```



https://githu

[clang] [llvm] [SPIRV][RFC] Rework / extend support for memory scopes (PR #106429)

2024-09-24 Thread Alex Voicu via cfe-commits

AlexVlx wrote:

I've created  
for the (potential) Translator work.

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


[clang] [Clang][Sema] Refactor collection of multi-level template argument lists (PR #106585)

2024-09-24 Thread Erich Keane via cfe-commits

erichkeane wrote:

I agree I think with your take on temp.expl.spec, we run into this in quite a 
few places.  I'd like to hear from the others, but this is a paragraph I've 
used in the past to justify a lot of this sort of diagnostics.

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


[clang] [PS4, PS5][Driver] Pass `-L<...>/target/lib -L.` to linker (PR #109796)

2024-09-24 Thread Edd Dawson via cfe-commits

https://github.com/playstation-edd updated 
https://github.com/llvm/llvm-project/pull/109796

>From 89ff568fda0062a89ed690cdb0267fc41a89325c Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Tue, 24 Sep 2024 13:05:39 +0100
Subject: [PATCH 1/2] [PS4,PS5][Driver] Pass `-L<...>/target/lib -L.` to linker

The proprietary PS4 linker implicitly adds `=/target/lib` and `.` as
library search paths. This behaviour was added to the PS5 linker via a
downstream patch in LLD. This really belongs in the driver, instead.
This change adds the driver behaviour to allow removal of the downstream
patch in LLD.

There are no plans to update the PS4 linker behaviour in the analogous
way, so do not pass the same search paths to the PS4 linker.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp |  6 ++
 clang/test/Driver/ps5-linker.c | 23 +++
 2 files changed, 29 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 647580e4e235dc..0a43ab19b434c5 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -186,6 +186,9 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
+  // Other drivers typically add library search paths (`-L`) here via
+  // TC.AddFilePathLibArgs(). We don't do that on PS4 as the PS4 linker
+  // searches those locations by default.
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
 
@@ -290,6 +293,7 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
+  TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
 
@@ -382,6 +386,8 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
 llvm::sys::path::append(Dir, "target/include");
 CheckSDKPartExists(Dir, "system headers");
   }
+
+  getFilePaths().push_back(".");
 }
 
 void toolchains::PS4PS5Base::AddClangSystemIncludeArgs(
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index c0cf0b864028c8..852659ae86d5cf 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -46,3 +46,26 @@
 
 // CHECK-SYSROOT: {{ld(\.exe)?}}"
 // CHECK-SYSROOT-SAME: "--sysroot=mysdk"
+
+// Test that "." is always added to library search paths. This is long-standing
+// behavior, unique to PlayStation toolchains.
+
+// RUN: %clang --target=x64_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LDOT %s
+
+// CHECK-LDOT: {{ld(\.exe)?}}"
+// CHECK-LDOT-SAME: "-L."
+
+// Test that /target/lib is added to library search paths, if it
+// exists and no --sysroot is specified.
+
+// RUN: rm -rf %t.dir && mkdir -p %t.dir/target/lib
+// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 
2>&1 | FileCheck --check-prefixes=CHECK-TARGETLIB %s
+
+// CHECK-TARGETLIB: {{ld(\.exe)?}}"
+// CHECK-TARGETLIB-SAME: "-L{{.*[/\\]}}target/lib"
+
+// RUN: env SCE_PROSPERO_SDK_DIR=missing %clang --target=x64_64-sie-ps5 %s 
-### 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
+// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 
--sysroot=missing 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
+
+// CHECK-NO-TARGETLIB: {{ld(\.exe)?}}"
+// CHECK-NO-TARGETLIB-NOT: "-L{{.*[/\\]}}target/lib"

>From 1a6dc7d8060722400032f6ad149b940f0197bc4d Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Tue, 24 Sep 2024 16:52:25 +0100
Subject: [PATCH 2/2] Rewrite test cases to remove assumed non-existence of
 'missing' directory

---
 clang/test/Driver/ps5-linker.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 852659ae86d5cf..4ae65963e361aa 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -58,14 +58,15 @@
 // Test that /target/lib is added to library search paths, if it
 // exists and no --sysroot is specified.
 
-// RUN: rm -rf %t.dir && mkdir -p %t.dir/target/lib
+// RUN: rm -rf %t.dir && mkdir %t.dir
+// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 
2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
+// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 
--sysroot=%t.dir 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
+
+// CHECK-NO-TARGETLIB: {{ld(\.exe)?}}"
+// CHECK-NO-TARGETLIB-NOT: "-L{{.*[/\\]}}target/lib"
+
+// RUN: mkdir -p %t.dir/target/lib
 // RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64

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

2024-09-24 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

Instead of the loop widening plans that I discussed earlier (e.g. on discourse) 
I ended up implementing this suppression heuristic, which is currently in a 
"minimal stable product" state: it is working and ready to be merged IMO, but 
I'm also open to suggestions about technical improvements and generalizations.

This change significantly reduces the amount of ArrayBoundV2 false positives, 
for example on FFMPEG (the project where I've seen the most results) **the 
number of ArrayBoundV2 results is reduced from 316 to 80**.

I hope that after this change ArrayBoundV2 can be brought out of the alpha 
state, because the new result count is comparable to stable checkers:  e.g. on 
ffmpeg where ArrayBoundV2 produces 80 results, there are 166 
core.NullDereference results, 135 core.UndefinedBinaryOperatorResult results 
and 120 core.uninitialized.Assign results.

My first impression is that the remaining ArrayBoundV2 results are still mostly 
false positives (which is not surprising because these are stable open source 
projects), but I didn't find any "typical issue" among the first 20 results (on 
ffmpeg) that I investigated.

The following diff shows the effect of enabling ArrayBoundV2 (in addition to 
the core, cplusplus, nullability, unix and valist checkers, which are enabled 
on both sides of the diff).
| Project | New Reports | Resolved Reports |
|-|-|--|
| memcached | [2 new 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=memcached_1.6.8_ericsson-weak-loop-assumptions_8890e0a&newcheck=memcached_1.6.8_ericsson-weak-loop-assumptions_742b07a&diff-type=New)
 | [0 resolved 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=memcached_1.6.8_ericsson-weak-loop-assumptions_8890e0a&newcheck=memcached_1.6.8_ericsson-weak-loop-assumptions_742b07a&diff-type=Resolved)
 
| tmux | [1 new 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=tmux_2.6_ericsson-weak-loop-assumptions_8890e0a&newcheck=tmux_2.6_ericsson-weak-loop-assumptions_742b07a&diff-type=New)
 | [0 resolved 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=tmux_2.6_ericsson-weak-loop-assumptions_8890e0a&newcheck=tmux_2.6_ericsson-weak-loop-assumptions_742b07a&diff-type=Resolved)
 
| curl | [4 new 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=curl_curl-7_66_0_ericsson-weak-loop-assumptions_8890e0a&newcheck=curl_curl-7_66_0_ericsson-weak-loop-assumptions_742b07a&diff-type=New)
 | [1 resolved 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=curl_curl-7_66_0_ericsson-weak-loop-assumptions_8890e0a&newcheck=curl_curl-7_66_0_ericsson-weak-loop-assumptions_742b07a&diff-type=Resolved)
 
| twin | [12 new 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=twin_v0.8.1_ericsson-weak-loop-assumptions_8890e0a&newcheck=twin_v0.8.1_ericsson-weak-loop-assumptions_742b07a&diff-type=New)
 | [1 resolved 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=twin_v0.8.1_ericsson-weak-loop-assumptions_8890e0a&newcheck=twin_v0.8.1_ericsson-weak-loop-assumptions_742b07a&diff-type=Resolved)
 
| vim | [38 new 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=vim_v8.2.1920_ericsson-weak-loop-assumptions_8890e0a&newcheck=vim_v8.2.1920_ericsson-weak-loop-assumptions_742b07a&diff-type=New)
 | [1 resolved 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=vim_v8.2.1920_ericsson-weak-loop-assumptions_8890e0a&newcheck=vim_v8.2.1920_ericsson-weak-loop-assumptions_742b07a&diff-type=Resolved)
 
| openssl | [18 new 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=openssl_openssl-3.0.0-alpha7_ericsson-weak-loop-assumptions_8890e0a&newcheck=openssl_openssl-3.0.0-alpha7_ericsson-weak-loop-assumptions_742b07a&diff-type=New)
 | [0 resolved 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=openssl_openssl-3.0.0-alpha7_ericsson-weak-loop-assumptions_8890e0a&newcheck=openssl_openssl-3.0.0-alpha7_ericsson-weak-loop-assumptions_742b07a&diff-type=Resolved)
 
| sqlite | [5 new 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=sqlite_version-3.33.0_ericsson-weak-loop-assumptions_8890e0a&newcheck=sqlite_version-3.33.0_ericsson-weak-loop-assumptions_742b07a&diff-type=New)
 | [1 resolved 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=sqlite_version-3.33.0_ericsson-weak-loop-assumptions_8890e0a&newcheck=sqlite_version-3.33.0_ericsson-weak-loop-assumptions_742b07a&diff-type=Resolved)
 
| ffmpeg | [80 new 
reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=ffmpeg_n4.3.1_ericsson-weak-loop-assumptions_8890e0a&newcheck=ffmpeg_n4.3.1_ericsson-weak-loop-assumptions_742b07a&diff-type=New)
 | [16 resolved

[clang] [llvm] [BPF] Do atomic_fetch_*() pattern matching with memory ordering (PR #107343)

2024-09-24 Thread via cfe-commits


@@ -0,0 +1,186 @@
+; RUN: llc -march=bpfel -mcpu=v3 -filetype=asm -o - %s | FileCheck 
-check-prefixes=CHECK %s
+; RUN: llc -march=bpfeb -mcpu=v3 -filetype=asm -o - %s | FileCheck 
-check-prefixes=CHECK %s
+;
+; Source:
+;   #include 
+;   struct gstruct_t {
+; _Atomic int a;
+;   } gstruct;
+;   extern _Atomic int ext;
+;   _Atomic int gbl;
+;   _Atomic int *pgbl;
+;   volatile _Atomic int vvar;
+;   _Atomic int foo(_Atomic int a1, _Atomic int *p1) {
+; (void)__c11_atomic_fetch_add(&gstruct.a, 1, memory_order_relaxed);
+; (void)__c11_atomic_fetch_add(&ext, 1, memory_order_relaxed);
+; (void)__c11_atomic_fetch_add(&gbl, 1, memory_order_relaxed);
+; (void)__c11_atomic_fetch_add(pgbl, 1, memory_order_relaxed);
+; (void)__c11_atomic_fetch_add(&vvar, 1, memory_order_relaxed);
+; (void)__c11_atomic_fetch_add(p1, 1, memory_order_relaxed);
+;
+; return a1;
+;   }
+
+target triple = "bpf"
+
+%struct.gstruct_t = type { i32 }
+
+@gstruct = dso_local global %struct.gstruct_t zeroinitializer, align 4, !dbg !0
+@ext = external dso_local global i32, align 4, !dbg !26
+@gbl = dso_local global i32 0, align 4, !dbg !16
+@pgbl = dso_local local_unnamed_addr global ptr null, align 8, !dbg !20
+@vvar = dso_local global i32 0, align 4, !dbg !23
+
+; Function Attrs: mustprogress nofree norecurse nounwind willreturn
+define dso_local i32 @foo(i32 returned %a1, ptr nocapture noundef %p1) 
local_unnamed_addr #0 !dbg !37 {
+entry:
+#dbg_value(i32 %a1, !41, !DIExpression(), !43)
+#dbg_value(ptr %p1, !42, !DIExpression(), !43)
+  %0 = atomicrmw add ptr @gstruct, i32 1 monotonic, align 4, !dbg !44
+  %1 = atomicrmw add ptr @ext, i32 1 monotonic, align 4, !dbg !45
+  %2 = atomicrmw add ptr @gbl, i32 1 monotonic, align 4, !dbg !46
+  %3 = load ptr, ptr @pgbl, align 8, !dbg !47, !tbaa !48
+  %4 = atomicrmw add ptr %3, i32 1 monotonic, align 4, !dbg !52
+  %5 = atomicrmw volatile add ptr @vvar, i32 1 monotonic, align 4, !dbg !53
+  %6 = atomicrmw add ptr %p1, i32 1 monotonic, align 4, !dbg !54
+  ret i32 %a1, !dbg !55
+}
+
+; CHECK: .long   1   # BTF_KIND_INT(id 
= 1)

yonghong-song wrote:

No problem. Let me fix it.

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


[clang] [llvm] [BPF] Do atomic_fetch_*() pattern matching with memory ordering (PR #107343)

2024-09-24 Thread via cfe-commits


@@ -35,6 +35,15 @@ static const char *BTFKindStr[] = {
 #include "llvm/DebugInfo/BTF/BTF.def"
 };
 
+static const DIType *tryRemoveAtomicType(const DIType *Ty) {

yonghong-song wrote:

Good point. I probably missed this case. Let me fix it.

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


[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)

2024-09-24 Thread Evan Wilde via cfe-commits

etcwilde wrote:

This drops the dependency edge between the compile step and generating 
`GenVT.inc` though. There was already a (indirect) dependency between the link 
step of `clangCodeGen` and generating `GetnVT.inc`.
Perhaps LLVM should export `vt_gen` like it does `intrinsics_gen` so that 
standalone builds can pick it up?

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


[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)

2024-09-24 Thread Saleem Abdulrasool via cfe-commits


@@ -31,6 +31,7 @@ set(LLVM_LINK_COMPONENTS
   Target
   TargetParser
   TransformUtils
+  CodeGenTypes

compnerd wrote:

This is duplicated (L6).

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


[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)

2024-09-24 Thread Tristan Ross via cfe-commits

https://github.com/RossComputerGuy updated 
https://github.com/llvm/llvm-project/pull/109601

>From b97cb5af6dbf92edeeceedac38d0b657e3856fbe Mon Sep 17 00:00:00 2001
From: Tristan Ross 
Date: Sun, 22 Sep 2024 21:02:12 -0700
Subject: [PATCH] [Clang] Replace vt_gen with LLVMCodeGenTypes

---
 clang/lib/CodeGen/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index 868ec847b9634b..372e944cfa1082 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -31,6 +31,7 @@ set(LLVM_LINK_COMPONENTS
   Target
   TargetParser
   TransformUtils
+  CodeGenTypes
   )
 
 # Workaround for MSVC ARM64 performance regression:
@@ -144,7 +145,6 @@ add_clang_library(clangCodeGen
   VarBypassDetector.cpp
 
   DEPENDS
-  vt_gen
   intrinsics_gen
   ClangDriverOptions
   # These generated headers are included transitively.

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


[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)

2024-09-24 Thread Saleem Abdulrasool via cfe-commits


@@ -31,6 +31,7 @@ set(LLVM_LINK_COMPONENTS
   Target
   TargetParser
   TransformUtils
+  LLVMCodeGenTypes

compnerd wrote:

These are lexicographically sorted, please maintain that invariant.

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


[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)

2024-09-24 Thread Tristan Ross via cfe-commits

RossComputerGuy wrote:

You're welcome, though it looks like CI is borked.
```
ld.lld: error: unable to find library -lLLVMLLVMCodeGenTypes
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
I've changed it from `LLVMCodeGenTypes` to `CodeGenTypes` so hopefully CI 
passes now.

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


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

2024-09-24 Thread Paul Walker via cfe-commits


@@ -2986,6 +2986,14 @@ void CastOperation::CheckCStyleCast() {
 return;
   }
 
+  if ((DestType->isArmMFloat8Type() && !SrcType->isArmMFloat8Type()) ||
+  (!DestType->isArmMFloat8Type() && SrcType->isArmMFloat8Type())) {

paulwalker-arm wrote:

`DestType->isArmMFloat8Type() != SrcType->isArmMFloat8Type()`?

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


[clang] fda0143 - [Rewrite] Use SmallSetVector (NFC) (#109746)

2024-09-24 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-09-24T08:33:24-07:00
New Revision: fda01437af339c87ecd226596dd1b5f6d2c6cbfa

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

LOG: [Rewrite] Use SmallSetVector (NFC) (#109746)

We can combine:

  SmallVector BlockByCopyDecls;
  llvm::SmallPtrSet BlockByCopyDeclsPtrSet;

into:

  llvm::SmallSetVector BlockByCopyDecls;

Likewise, we can combine:

  SmallVector BlockByRefDecls;
  llvm::SmallPtrSet BlockByRefDeclsPtrSet;

into:

  llvm::SmallSetVector BlockByRefDecls;

Added: 


Modified: 
clang/lib/Frontend/Rewrite/RewriteObjC.cpp

Removed: 




diff  --git a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp 
b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
index a1e792bf772ba2..f49ccf7be68e22 100644
--- a/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
+++ b/clang/lib/Frontend/Rewrite/RewriteObjC.cpp
@@ -128,10 +128,8 @@ namespace {
 SmallVector BlockDeclRefs;
 
 // Block related declarations.
-SmallVector BlockByCopyDecls;
-llvm::SmallPtrSet BlockByCopyDeclsPtrSet;
-SmallVector BlockByRefDecls;
-llvm::SmallPtrSet BlockByRefDeclsPtrSet;
+llvm::SmallSetVector BlockByCopyDecls;
+llvm::SmallSetVector BlockByRefDecls;
 llvm::DenseMap BlockByRefDeclNo;
 llvm::SmallPtrSet ImportedBlockDecls;
 llvm::SmallPtrSet ImportedLocalExternalDecls;
@@ -3357,7 +3355,7 @@ std::string 
RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i,
 S += VD->getNameAsString();
 S += ", (void*)src->";
 S += VD->getNameAsString();
-if (BlockByRefDeclsPtrSet.count(VD))
+if (BlockByRefDecls.contains(VD))
   S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);";
 else if (VD->getType()->isBlockPointerType())
   S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);";
@@ -3374,7 +3372,7 @@ std::string 
RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i,
   for (ValueDecl *VD : ImportedBlockDecls) {
 S += "_Block_object_dispose((void*)src->";
 S += VD->getNameAsString();
-if (BlockByRefDeclsPtrSet.count(VD))
+if (BlockByRefDecls.contains(VD))
   S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);";
 else if (VD->getType()->isBlockPointerType())
   S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);";
@@ -3553,14 +3551,10 @@ void 
RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
   DeclRefExpr *Exp = InnerDeclRefs[count++];
   ValueDecl *VD = Exp->getDecl();
   BlockDeclRefs.push_back(Exp);
-  if (!VD->hasAttr() && !BlockByCopyDeclsPtrSet.count(VD)) {
-BlockByCopyDeclsPtrSet.insert(VD);
-BlockByCopyDecls.push_back(VD);
-  }
-  if (VD->hasAttr() && !BlockByRefDeclsPtrSet.count(VD)) {
-BlockByRefDeclsPtrSet.insert(VD);
-BlockByRefDecls.push_back(VD);
-  }
+  if (VD->hasAttr())
+BlockByRefDecls.insert(VD);
+  else
+BlockByCopyDecls.insert(VD);
   // imported objects in the inner blocks not used in the outer
   // blocks must be copied/disposed in the outer block as well.
   if (VD->hasAttr() ||
@@ -3590,9 +3584,7 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation 
FunLocStart,
 
 BlockDeclRefs.clear();
 BlockByRefDecls.clear();
-BlockByRefDeclsPtrSet.clear();
 BlockByCopyDecls.clear();
-BlockByCopyDeclsPtrSet.clear();
 ImportedBlockDecls.clear();
   }
   if (RewriteSC) {
@@ -4314,20 +4306,12 @@ void RewriteObjC::CollectBlockDeclRefInfo(BlockExpr 
*Exp) {
   if (BlockDeclRefs.size()) {
 // Unique all "by copy" declarations.
 for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
-  if (!BlockDeclRefs[i]->getDecl()->hasAttr()) {
-if (!BlockByCopyDeclsPtrSet.count(BlockDeclRefs[i]->getDecl())) {
-  BlockByCopyDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl());
-  BlockByCopyDecls.push_back(BlockDeclRefs[i]->getDecl());
-}
-  }
+  if (!BlockDeclRefs[i]->getDecl()->hasAttr())
+BlockByCopyDecls.insert(BlockDeclRefs[i]->getDecl());
 // Unique all "by ref" declarations.
 for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
-  if (BlockDeclRefs[i]->getDecl()->hasAttr()) {
-if (!BlockByRefDeclsPtrSet.count(BlockDeclRefs[i]->getDecl())) {
-  BlockByRefDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl());
-  BlockByRefDecls.push_back(BlockDeclRefs[i]->getDecl());
-}
-  }
+  if (BlockDeclRefs[i]->getDecl()->hasAttr())
+BlockByRefDecls.insert(BlockDeclRefs[i]->getDecl());
 // Find any imported blocks...they will need special attention.
 for (unsigned i = 0; i < BlockDeclRefs.size(); i++)
   if (BlockDeclRefs[i]->getDecl()->hasAttr() ||
@@ -4358,22 +4342,18 @@ Stmt *Rew

[clang] [Rewrite] Use SmallSetVector (NFC) (PR #109746)

2024-09-24 Thread Kazu Hirata via cfe-commits

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


[clang] [clang][bytecode] Fix vector shifts on big-endian systems (PR #109800)

2024-09-24 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/109800

For shifts, the LHS and RHS element types might be different. The variable 
naming here could probably use some love now, but I'm trying to fix this as 
fast as possible.

See the discussion in https://github.com/llvm/llvm-project/pull/108949

>From a45f4620fdaef4063e002b3a9c64b65590c9f60c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 24 Sep 2024 15:56:05 +0200
Subject: [PATCH] [clang][bytecode] Fix vector shifts on big-endian systems

For shifts, the LHS and RHS element types might be different.
The variable naming here could probably use some love now, but I'm
trying to fix this as fast as possible.
---
 clang/lib/AST/ByteCode/Compiler.cpp | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 754cd0db9868b7..785918846976d4 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1282,9 +1282,8 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
 ? BinaryOperator::getOpForCompoundAssignment(E->getOpcode())
 : E->getOpcode();
 
-  // The LHS and RHS of a comparison operator must have the same type. So we
-  // just use LHS vector element type here.
   PrimType ElemT = this->classifyVectorElementType(LHS->getType());
+  PrimType RHSElemT = this->classifyVectorElementType(RHS->getType());
   PrimType ResultElemT = this->classifyVectorElementType(E->getType());
 
   // Evaluate LHS and save value to LHSOffset.
@@ -1312,7 +1311,7 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   PrimType PromotT = classifyPrim(PromotTy);
   PrimType OpT = NeedIntPromot ? PromotT : ElemT;
 
-  auto getElem = [=](unsigned Offset, unsigned Index) {
+  auto getElem = [=](unsigned Offset, PrimType ElemT, unsigned Index) {
 if (!this->emitGetLocal(PT_Ptr, Offset, E))
   return false;
 if (!this->emitArrayElemPop(ElemT, Index, E))
@@ -1342,9 +1341,9 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   }
 
   for (unsigned I = 0; I != VecTy->getNumElements(); ++I) {
-if (!getElem(LHSOffset, I))
+if (!getElem(LHSOffset, ElemT, I))
   return false;
-if (!getElem(RHSOffset, I))
+if (!getElem(RHSOffset, RHSElemT, I))
   return false;
 switch (Op) {
 case BO_Add:
@@ -1372,11 +1371,11 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
 return false;
   break;
 case BO_Shl:
-  if (!this->emitShl(OpT, ElemT, E))
+  if (!this->emitShl(OpT, RHSElemT, E))
 return false;
   break;
 case BO_Shr:
-  if (!this->emitShr(OpT, ElemT, E))
+  if (!this->emitShr(OpT, RHSElemT, E))
 return false;
   break;
 case BO_EQ:

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


[clang] [clang][bytecode] Fix vector shifts on big-endian systems (PR #109800)

2024-09-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

For shifts, the LHS and RHS element types might be different. The variable 
naming here could probably use some love now, but I'm trying to fix this as 
fast as possible.

See the discussion in https://github.com/llvm/llvm-project/pull/108949

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


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+6-7) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 754cd0db9868b7..785918846976d4 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1282,9 +1282,8 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
 ? BinaryOperator::getOpForCompoundAssignment(E->getOpcode())
 : E->getOpcode();
 
-  // The LHS and RHS of a comparison operator must have the same type. So we
-  // just use LHS vector element type here.
   PrimType ElemT = this->classifyVectorElementType(LHS->getType());
+  PrimType RHSElemT = this->classifyVectorElementType(RHS->getType());
   PrimType ResultElemT = this->classifyVectorElementType(E->getType());
 
   // Evaluate LHS and save value to LHSOffset.
@@ -1312,7 +1311,7 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   PrimType PromotT = classifyPrim(PromotTy);
   PrimType OpT = NeedIntPromot ? PromotT : ElemT;
 
-  auto getElem = [=](unsigned Offset, unsigned Index) {
+  auto getElem = [=](unsigned Offset, PrimType ElemT, unsigned Index) {
 if (!this->emitGetLocal(PT_Ptr, Offset, E))
   return false;
 if (!this->emitArrayElemPop(ElemT, Index, E))
@@ -1342,9 +1341,9 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   }
 
   for (unsigned I = 0; I != VecTy->getNumElements(); ++I) {
-if (!getElem(LHSOffset, I))
+if (!getElem(LHSOffset, ElemT, I))
   return false;
-if (!getElem(RHSOffset, I))
+if (!getElem(RHSOffset, RHSElemT, I))
   return false;
 switch (Op) {
 case BO_Add:
@@ -1372,11 +1371,11 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
 return false;
   break;
 case BO_Shl:
-  if (!this->emitShl(OpT, ElemT, E))
+  if (!this->emitShl(OpT, RHSElemT, E))
 return false;
   break;
 case BO_Shr:
-  if (!this->emitShr(OpT, ElemT, E))
+  if (!this->emitShr(OpT, RHSElemT, E))
 return false;
   break;
 case BO_EQ:

``




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


[clang] [Clang][AArch64] Fix checkArmStreamingBuiltin for 'sve-b16b16' (PR #109420)

2024-09-24 Thread via cfe-commits


@@ -1802,9 +1854,29 @@ void SVEEmitter::createStreamingAttrs(raw_ostream &OS, 
ACLEKind Kind) {
 
 if (Def->isFlagSet(IsStreamingFlag))
   StreamingMap["ArmStreaming"].insert(Def->getMangledName());
-else if (Def->isFlagSet(VerifyRuntimeMode))
+else if (Def->isFlagSet(VerifyRuntimeMode)) {
+  // Verify that the target guards contain at least one feature that
+  // actually enables SVE or SME (explicitly, or implicitly). This is 
needed
+  // for the code in SemaARM.cpp (checkArmStreamingBuiltin) that checks
+  // whether the required runtime mode for an intrinsic matches with the
+  // given set of target features and function attributes.
+  //
+  // The feature lists below must match the disabled features in
+  // 'checkArmStreamingBuiltin'!
+  if (!Def->getSVEGuard().empty() &&
+  !verifyGuard(Def->getSVEGuard(),
+   {"sve", "sve2", "sve2p1", "sve2-aes", "sve2-sha3",

SpencerAbson wrote:

Yes, I believe so. 

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


[clang] [llvm] [SPIRV][RFC] Rework / extend support for memory scopes (PR #106429)

2024-09-24 Thread Alex Voicu via cfe-commits

AlexVlx wrote:

Thank you ever so much for the review @VyacheslavLevytskyy! I will create a PR 
for the Translator as well, since there's some handling missing there; I will 
refer to it here for future readers. Final check: are you OK with the OpenCL 
changes @yxsamliu?

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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-24 Thread via cfe-commits


@@ -86,6 +127,21 @@ Options
this option enables.
Default is `true`.
 
+.. _option-ReportDefaultFunctions:
+
+.. option:: ReportDefaultFunctions
+
+When `true`, the check reports the default set of functions.
+Copnsider changing the setting to false if you only want to see custom

whisperity wrote:

```suggestion
Consider changing the setting to false if you only want to see custom
```

Typo!

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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-24 Thread via cfe-commits


@@ -86,6 +127,21 @@ Options
this option enables.
Default is `true`.
 
+.. _option-ReportDefaultFunctions:
+

whisperity wrote:

```suggestion
```

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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-24 Thread via cfe-commits


@@ -74,10 +75,50 @@ Both macros have to be defined to suggest replacement 
functions from *Annex K.*
 ``__STDC_WANT_LIB_EXT1__`` must be defined to ``1`` by the user **before**
 including any system headers.
 
+.. _CustomFunctions:
+
+Custom functions
+
+
+The option `CustomFunctions` allows the user to define custom functions to be
+checked. The format is the following, without newlines:
+
+.. code::
+
+   bugprone-unsafe-functions.CustomFunctions="
+ functionRegex1[, replacement1[, reason1]]; 
+ functionRegex2[, replacement2[, reason2]];
+ ...
+   "
+
+The functions are matched using POSIX extended regular expressions.
+*(Note: The regular expressions do not support negative* ``(?!)`` *matches)*
+
+The `reason` is optional and is used to provide additional information about 
the
+reasoning behind the replacement. The default reason is `is marked as unsafe`.
+
+If `replacement` is empty, the text `it should not be used` will be shown
+instead of the suggestion for a replacement.
+
+As an example, the configuration `^original$, replacement, is deprecated;`
+will produce the following diagnostic message.
+
+.. code:: c
+  
+   original(); // warning: function 'original' is deprecated; 'replacement' 
should be used instead.
+   ::std::original(); // no-warning
+   original_function(); // no-warning
+
+If the regular expression contains the character `:`, it is matched against the
+qualified name (i.e. ``std::original``), otherwise the regex is matched 
against the unqualified name (``original``).
+If the regular expression starts with `::` (or `^::`), it is matched against 
the
+fully qualified name (``::std::original``).
 
 Options
 ---
 
+.. _option-ReportMoreUnsafeFunctions:
+

whisperity wrote:

```suggestion
```

With using `:option:...` maybe these are not needed, but please double check!

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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-24 Thread via cfe-commits


@@ -45,8 +47,7 @@ The following functions are always checked, regardless of 
*Annex K* availability
  - ``rewind``, suggested replacement: ``fseek``
  - ``setbuf``, suggested replacement: ``setvbuf``
 
-If `ReportMoreUnsafeFunctions
-`_ is enabled,
+If :ref:`ReportMoreUnsafeFunctions` is 
enabled,

whisperity wrote:

```suggestion
If :option:`ReportMoreUnsafeFunctions` is enabled,
```

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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-24 Thread via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-24 Thread via cfe-commits


@@ -104,6 +104,10 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`bugprone-unsafe-functions
+  ` check to allow specifying
+  custom matched functions as well.

whisperity wrote:

```suggestion
  ` check to allow specifying
  additional functions to match.
```

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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-24 Thread via cfe-commits


@@ -74,10 +75,50 @@ Both macros have to be defined to suggest replacement 
functions from *Annex K.*
 ``__STDC_WANT_LIB_EXT1__`` must be defined to ``1`` by the user **before**
 including any system headers.
 
+.. _CustomFunctions:
+
+Custom functions
+
+
+The option `CustomFunctions` allows the user to define custom functions to be
+checked. The format is the following, without newlines:
+
+.. code::
+
+   bugprone-unsafe-functions.CustomFunctions="
+ functionRegex1[, replacement1[, reason1]]; 
+ functionRegex2[, replacement2[, reason2]];
+ ...
+   "
+
+The functions are matched using POSIX extended regular expressions.
+*(Note: The regular expressions do not support negative* ``(?!)`` *matches)*

whisperity wrote:

```suggestion
*(Note: The regular expressions do not support negative* ``(?!)`` *matches.)*
```

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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-24 Thread via cfe-commits


@@ -19,6 +19,8 @@ The check implements the following rules from the CERT C 
Coding Standard:
 Unsafe functions
 
 
+The following functions are reported if 
:ref:`ReportDefaultFunctions` is enabled.

whisperity wrote:

```suggestion
The following functions are reported if :option:`ReportDefaultFunctions` is 
enabled.
```

I knew there were examples for this, and now I was able to find some:

https://github.com/llvm/llvm-project/blame/02a334de6690202154ef09456c581618ff290f9a/clang-tools-extra/docs/clang-tidy/checks/misc/unused-parameters.rst#L13

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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-24 Thread via cfe-commits


@@ -74,10 +75,50 @@ Both macros have to be defined to suggest replacement 
functions from *Annex K.*
 ``__STDC_WANT_LIB_EXT1__`` must be defined to ``1`` by the user **before**
 including any system headers.
 
+.. _CustomFunctions:
+
+Custom functions
+
+
+The option `CustomFunctions` allows the user to define custom functions to be

whisperity wrote:

```suggestion
The option :option:`CustomFunctions` allows the user to define custom functions 
to be
```

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


[clang] 679c971 - [clang][bytecode] Fix vector shifts on big-endian systems (#109800)

2024-09-24 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-09-24T18:07:18+02:00
New Revision: 679c9717dfc9687a3bca78b45d9fd104b67e16f9

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

LOG: [clang][bytecode] Fix vector shifts on big-endian systems (#109800)

For shifts, the LHS and RHS element types might be different. The
variable naming here could probably use some love now, but I'm trying to
fix this as fast as possible.

See the discussion in https://github.com/llvm/llvm-project/pull/108949

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 754cd0db9868b7..785918846976d4 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1282,9 +1282,8 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
 ? BinaryOperator::getOpForCompoundAssignment(E->getOpcode())
 : E->getOpcode();
 
-  // The LHS and RHS of a comparison operator must have the same type. So we
-  // just use LHS vector element type here.
   PrimType ElemT = this->classifyVectorElementType(LHS->getType());
+  PrimType RHSElemT = this->classifyVectorElementType(RHS->getType());
   PrimType ResultElemT = this->classifyVectorElementType(E->getType());
 
   // Evaluate LHS and save value to LHSOffset.
@@ -1312,7 +1311,7 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   PrimType PromotT = classifyPrim(PromotTy);
   PrimType OpT = NeedIntPromot ? PromotT : ElemT;
 
-  auto getElem = [=](unsigned Offset, unsigned Index) {
+  auto getElem = [=](unsigned Offset, PrimType ElemT, unsigned Index) {
 if (!this->emitGetLocal(PT_Ptr, Offset, E))
   return false;
 if (!this->emitArrayElemPop(ElemT, Index, E))
@@ -1342,9 +1341,9 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   }
 
   for (unsigned I = 0; I != VecTy->getNumElements(); ++I) {
-if (!getElem(LHSOffset, I))
+if (!getElem(LHSOffset, ElemT, I))
   return false;
-if (!getElem(RHSOffset, I))
+if (!getElem(RHSOffset, RHSElemT, I))
   return false;
 switch (Op) {
 case BO_Add:
@@ -1372,11 +1371,11 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
 return false;
   break;
 case BO_Shl:
-  if (!this->emitShl(OpT, ElemT, E))
+  if (!this->emitShl(OpT, RHSElemT, E))
 return false;
   break;
 case BO_Shr:
-  if (!this->emitShr(OpT, ElemT, E))
+  if (!this->emitShr(OpT, RHSElemT, E))
 return false;
   break;
 case BO_EQ:



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


[clang] [clang][bytecode] Fix vector shifts on big-endian systems (PR #109800)

2024-09-24 Thread Timm Baeder via cfe-commits

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


[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)

2024-09-24 Thread Erich Keane via cfe-commits


@@ -119,6 +119,15 @@ FIELD(HasInitMethod, 1, NO_MERGE)
 /// within anonymous unions or structs.
 FIELD(HasInClassInitializer, 1, NO_MERGE)
 
+/// Custom attribute that is True if any field is marked as requiring explicit
+/// initialization with [[clang::requires_explicit_initialization]] in a type
+/// without a user-provided default constructor, or if this is the case for any
+/// base classes and/or member variables whose types are aggregates.
+///
+/// In this case, default-construction is diagnosed, as it would not explicitly
+/// initialize the field.
+FIELD(HasUninitializedExplicitInitFields, 1, NO_MERGE)

erichkeane wrote:

I think I was the one confused, I think I thought this added to the recorddecl, 
not the field decl.  So disregard this one.

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


[clang] [Clang][Driver] Add option to provide path for multilib's YAML config file (PR #109640)

2024-09-24 Thread via cfe-commits


@@ -1,79 +1,79 @@
-// RUN: %clang -print-multi-flags-experimental --target=aarch64-linux 
-fc++-abi=itanium -fsanitize=address | FileCheck --check-prefix=CHECK-LINUX %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-linux -fc++-abi=itanium 
-fsanitize=address | FileCheck --check-prefix=CHECK-LINUX %s

ArcaneNibble wrote:

Do you actually need to add this argument in this file? The file is only 
testing the flags and not the chosen final path, so the (lack of) YAML file 
should have no effect (`--sysroot=` isn't passed)

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


[clang] [lld] [llvm] [mlir] [IR] Introduce `T` to `DataLayout` to represent flat address space if a target supports it (PR #108786)

2024-09-24 Thread Shilei Tian via cfe-commits

shiltian wrote:

> Is there a value in not defining 0 as flat?

Like @AlexVlx mentioned, as well as the wording I put into `LangRef.rst`, 
SPIR/SPIR-V uses AS 4 as flat AS.

> It's what we basically assume everywhere already, isn't it?

I don't think this is technically true, but it is unfortunately practically 
true. There is no formal definition of what a flat AS is (except the one in TTI 
which is not widely used at all), which is the central question of this PR. 
That means all the "assumption everywhere" is basically assumption of every 
means for its own purpose. The current AS 0 is nothing special but just taken 
as the default AS for various object allocation if no explicit AS is used. 
That's all.

> Perhaps another solution(?) here would be to tweak LangRef to be binding in 
> that it spells out that iff a particular Target has a Flat AS, that will be 
> reflected in LLVM as AS0?

I'm fine with adding the enforcement in LLVM that AS0 needs to be the flat AS, 
if a target has it, but the definition of a flat AS still needs to be set. If 
we do that, how will SPIR/SPIR-V work?

---

I think to have a clear definition of what a flat AS is critical, no matter if 
we want to add a new specification, as what is done is this PR, or add the 
wording into LLVM LangRef, enforcing it to AS 0. I'd like to give it a try 
here. ⬇️

---

A flat address space is an address space with the following characteristics:

1. It must correspond to an existing address space; defining a flat address 
space does not create a new address space.
2. Pointers in this address space can be used to access multiple memory 
segments, each associated with distinct address spaces.
3. Accessing memory through a pointer in this address space **may** be slower 
than accessing memory through a pointer in a more specific address space.
4. Pointers in this address space must be able to be losslessly converted 
**to** other address spaces.

All other characteristics of the flat address space will align with those of 
the original existing address space.

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


[clang] [Clang][AArch64] Fix checkArmStreamingBuiltin for 'sve-b16b16' (PR #109420)

2024-09-24 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm updated 
https://github.com/llvm/llvm-project/pull/109420

>From af4cd0b3643e682fcb34042d209df03037743eb0 Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Fri, 20 Sep 2024 14:16:23 +0100
Subject: [PATCH 1/2] [Clang][AArch64] Fix checkArmStreamingBuiltin for
 'sve-b16b16'

The implementation made the assumption that any feature starting with
"sve" meant that this was an SVE feature. This is not the case for
"sve-b16b16", as this is a feature that applies to both SVE and SME.

This meant that:

  __attribute__((target("+sme2,+sve2,+sve-b16b16")))
  svbfloat16_t foo(svbfloat16_t a, svbfloat16_t b, svbfloat16_t c)
  __arm_streaming {
  return svclamp_bf16(a, b, c);
  }

would result in an incorrect diagnostic saying that `svclamp_bf16`
could only be used in non-streaming functions.
---
 clang/lib/Sema/SemaARM.cpp| 21 ---
 ...reaming-sme-or-nonstreaming-sve-builtins.c |  6 ++
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp
index efde354860de43..fba1453e5d38fc 100644
--- a/clang/lib/Sema/SemaARM.cpp
+++ b/clang/lib/Sema/SemaARM.cpp
@@ -567,15 +567,18 @@ static bool checkArmStreamingBuiltin(Sema &S, CallExpr 
*TheCall,
   // * When compiling for SVE only, the caller must be in non-streaming mode.
   // * When compiling for both SVE and SME, the caller can be in either mode.
   if (BuiltinType == SemaARM::VerifyRuntimeMode) {
-auto DisableFeatures = [](llvm::StringMap &Map, StringRef S) {
-  for (StringRef K : Map.keys())
-if (K.starts_with(S))
-  Map[K] = false;
-};
-
 llvm::StringMap CallerFeatureMapWithoutSVE;
 S.Context.getFunctionFeatureMap(CallerFeatureMapWithoutSVE, FD);
-DisableFeatures(CallerFeatureMapWithoutSVE, "sve");
+CallerFeatureMapWithoutSVE["sve"] = false;
+CallerFeatureMapWithoutSVE["sve2"] = false;
+CallerFeatureMapWithoutSVE["sve2p1"] = false;
+// FIXME: This list must be updated with future extensions, because when
+// an intrinsic is enabled by (sve2p1|sme2p1), disabling just "sve" is
+// not sufficient, as the feature dependences are not resolved.
+// At the moment, it should be sufficient to test the 'base' architectural
+// support for SVE and SME, which must always be provided in the
+// target guard. e.g. TargetGuard = "sve-b16b16" without "sme" or "sve"
+// is not sufficient.
 
 // Avoid emitting diagnostics for a function that can never compile.
 if (FnType == SemaARM::ArmStreaming && !CallerFeatureMapWithoutSVE["sme"])
@@ -583,7 +586,9 @@ static bool checkArmStreamingBuiltin(Sema &S, CallExpr 
*TheCall,
 
 llvm::StringMap CallerFeatureMapWithoutSME;
 S.Context.getFunctionFeatureMap(CallerFeatureMapWithoutSME, FD);
-DisableFeatures(CallerFeatureMapWithoutSME, "sme");
+CallerFeatureMapWithoutSME["sme"] = false;
+CallerFeatureMapWithoutSME["sme2"] = false;
+CallerFeatureMapWithoutSME["sme2p1"] = false;
 
 // We know the builtin requires either some combination of SVE flags, or
 // some combination of SME flags, but we need to figure out which part
diff --git 
a/clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c 
b/clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c
index 45776eb13e4fbc..792d79ee3e600d 100644
--- a/clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c
+++ b/clang/test/Sema/aarch64-streaming-sme-or-nonstreaming-sve-builtins.c
@@ -38,6 +38,12 @@ svfloat32_t good6(svfloat32_t a, svfloat32_t b, svfloat32_t 
c) __arm_streaming_c
   return svclamp(a, b, c);
 }
 
+// Test that the +sve-b16b16 is not considered an SVE flag (it applies to both)
+__attribute__((target("+sme2,+sve2,+sve-b16b16")))
+svbfloat16_t good7(svbfloat16_t a, svbfloat16_t b, svbfloat16_t c) 
__arm_streaming {
+return svclamp_bf16(a, b, c);
+}
+
 // Without '+sme2', the builtin is only valid in non-streaming mode.
 __attribute__((target("+sve2p1,+sme")))
 svfloat32_t bad1(svfloat32_t a, svfloat32_t b, svfloat32_t c) __arm_streaming {

>From bfa1348e06a78c2cc30f2cf7e64ae993191fcd2d Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Tue, 24 Sep 2024 07:23:37 +
Subject: [PATCH 2/2] Add TableGen checks

---
 clang/lib/Sema/SemaARM.cpp  | 20 +++-
 clang/utils/TableGen/SveEmitter.cpp | 76 -
 2 files changed, 81 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp
index fba1453e5d38fc..de2236207564bd 100644
--- a/clang/lib/Sema/SemaARM.cpp
+++ b/clang/lib/Sema/SemaARM.cpp
@@ -569,16 +569,9 @@ static bool checkArmStreamingBuiltin(Sema &S, CallExpr 
*TheCall,
   if (BuiltinType == SemaARM::VerifyRuntimeMode) {
 llvm::StringMap CallerFeatureMapWithoutSVE;
 S.Context.getFunctionFeatureMap(CallerFeatureMapWithoutSVE, FD);
-CallerFeatureMapW

[clang] [llvm] [BPF] Do atomic_fetch_*() pattern matching with memory ordering (PR #107343)

2024-09-24 Thread via cfe-commits


@@ -35,6 +35,15 @@ static const char *BTFKindStr[] = {
 #include "llvm/DebugInfo/BTF/BTF.def"
 };
 
+static const DIType *tryRemoveAtomicType(const DIType *Ty) {

eddyz87 wrote:

I meant that it seems that `tryRemoveAtomicType` is missing from 
`BTFTypeTypeTag::completeType`, e.g. the following example drops type tag:

```
$ cat test5.c 
int _Atomic __attribute__((btf_type_tag("foo"))) *root;

$ clang -c --target=bpf -g test5.c -O2 -o test5.o && bpftool btf dump file 
test5.o
[1] PTR '(anon)' type_id=2
[2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[3] VAR 'root' type_id=1, linkage=global
[4] DATASEC '.bss' size=0 vlen=1
type_id=3 offset=0 size=8 (VAR 'root')
```

As far as I understand, expected output is:

```
[1] TYPE_TAG 'foo' type_id=3
[2] PTR '(anon)' type_id=1
[3] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[4] VAR 'root' type_id=2, linkage=global
[5] DATASEC '.bss' size=0 vlen=1
type_id=4 offset=0 size=8 (VAR 'root')
```

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


[clang] [clang] Fix the local parameter of void type inside the `Requires` expression. (PR #109831)

2024-09-24 Thread via cfe-commits

c8ef wrote:

CC @erichkeane @zyn0217, since I do not have permission to request reviewers.

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


  1   2   3   4   5   >