[clang] [flang] [Flang][OpenMP] Add -fopenmp-default-none command line flag (PR #120287)

2024-12-18 Thread Leandro Lupori via cfe-commits

https://github.com/luporl commented:

LG, except for the issue raised by @kiranchandramohan, to skip constructs that 
don't support data-sharing clauses.

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


[clang] [flang] [Flang][OpenMP] Add -fopenmp-default-none command line flag (PR #120287)

2024-12-18 Thread Leandro Lupori via cfe-commits


@@ -855,6 +855,9 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // is experimental.
   D.Diag(diag::warn_openmp_experimental);
 
+  if (Args.hasArg((options::OPT_fopenmp_default_none)))

luporl wrote:

```suggestion
  if (Args.hasArg(options::OPT_fopenmp_default_none))
```

nit: extra parentheses

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


[clang] [ubsan] Add -fsanitize-nonmerged-handlers (and -fno-sanitize-nonmerge… (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits

https://github.com/thurstond updated 
https://github.com/llvm/llvm-project/pull/120464

>From 2c0da9aa6f58900387fa91cdc6bcb41e0235d94c Mon Sep 17 00:00:00 2001
From: Thurston Dang 
Date: Wed, 18 Dec 2024 18:37:11 +
Subject: [PATCH 1/6] [ubsan] Add -fsanitize-nonmerged-handlers (and
 -fno-sanitize-nonmerged-handlers)

'-mllvm -ubsan-unique-traps' (https://github.com/llvm/llvm-project/pull/65972) 
applies to all UBSan
checks. This patch introduces -fsanitize-nonmerged-handlers and
-fno-sanitize-nonmerged-handlers, which allows selectively applying
non-merged handlers to a subset of UBSan checks.

N.B. we use "non-merged handlers" instead of "unique traps", since
https://github.com/llvm/llvm-project/pull/119302 has generalized it to
work for non-trap mode as well (min-rt and regular rt).

This patch does not remove the -ubsan-unique-traps flag; that will
override -f(no-)sanitize-non-merged-handlers.
---
 clang/include/clang/Basic/CodeGenOptions.h |  4 
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Driver/SanitizerArgs.h |  1 +
 clang/lib/CodeGen/CGExpr.cpp   | 26 +-
 clang/lib/CodeGen/CodeGenFunction.h|  2 +-
 clang/lib/Driver/SanitizerArgs.cpp | 24 +++-
 clang/lib/Frontend/CompilerInvocation.cpp  |  6 +
 7 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 2dcf98b465661e..9b97adce42cc2a 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -380,6 +380,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Set of sanitizer checks that trap rather than diagnose.
   SanitizerSet SanitizeTrap;
 
+  /// Set of sanitizer checks that have non-merged handlers (better
+  /// debuggability at the expense of code size).
+  SanitizerSet SanitizeNonMergedHandlers;
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7b544d2534d469..1a09f08890edad 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2548,6 +2548,10 @@ def fsanitize_trap_EQ : CommaJoined<["-"], 
"fsanitize-trap=">, Group;
+def fsanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fsanitize-nonmerged-handlers=">, Group,
+HelpText<"Enable non-merged handlers for specified 
sanitizers">;
+def fno_sanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fno-sanitize-nonmerged-handlers=">, Group,
+HelpText<"Disable non-merged handlers for specified 
sanitizers">;
 def fsanitize_trap : Flag<["-"], "fsanitize-trap">, Group,
  Alias, AliasArgs<["all"]>,
  HelpText<"Enable trapping for all sanitizers">;
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 4f08ea2b260179..28cfe72d6a34bd 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -25,6 +25,7 @@ class SanitizerArgs {
   SanitizerSet Sanitizers;
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
+  SanitizerSet NonMergedHandlers;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 79955f55714164..9c4dfaa393966b 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3546,7 +3546,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
  ArrayRef FnArgs,
  SanitizerHandler CheckHandler,
  CheckRecoverableKind RecoverKind, bool 
IsFatal,
- llvm::BasicBlock *ContBB) {
+ llvm::BasicBlock *ContBB, bool NoMerge) {
   assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
   std::optional DL;
   if (!CGF.Builder.getCurrentDebugLocation()) {
@@ -3581,7 +3581,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
llvm::AttributeList::FunctionIndex, B),
   /*Local=*/true);
   llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs);
-  bool NoMerge =
+  NoMerge = NoMerge ||
   ClSanitizeDebugDeoptimization ||
   !CGF.CGM.getCodeGenOpts().OptimizationLevel ||
   (CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
@@ -3608,6 +3608,7 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *FatalCond = nullptr;
   llvm::Value *RecoverableCond = nullptr;
   llvm::Value *TrapCond = nullptr;
+  bool NoMerge = false;
   for (int i = 0, n = Checked.size(); i < n; ++i) {
 llvm::Value *Check = Checked[i].first;
 // -fsanitize-trap= overrides -fsanitize-recover=.
@@ -3618,6 +3619,9 @@ void CodeGenFunct

[clang] [llvm] [DirectX][SPIRV] Consistent names for HLSL resource intrinsics (PR #120466)

2024-12-18 Thread Joshua Batista via cfe-commits

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


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


[clang] [ubsan] Add -fsanitize-nonmerged-handlers (and -fno-sanitize-nonmerge… (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits

https://github.com/thurstond updated 
https://github.com/llvm/llvm-project/pull/120464

>From 2c0da9aa6f58900387fa91cdc6bcb41e0235d94c Mon Sep 17 00:00:00 2001
From: Thurston Dang 
Date: Wed, 18 Dec 2024 18:37:11 +
Subject: [PATCH 1/7] [ubsan] Add -fsanitize-nonmerged-handlers (and
 -fno-sanitize-nonmerged-handlers)

'-mllvm -ubsan-unique-traps' (https://github.com/llvm/llvm-project/pull/65972) 
applies to all UBSan
checks. This patch introduces -fsanitize-nonmerged-handlers and
-fno-sanitize-nonmerged-handlers, which allows selectively applying
non-merged handlers to a subset of UBSan checks.

N.B. we use "non-merged handlers" instead of "unique traps", since
https://github.com/llvm/llvm-project/pull/119302 has generalized it to
work for non-trap mode as well (min-rt and regular rt).

This patch does not remove the -ubsan-unique-traps flag; that will
override -f(no-)sanitize-non-merged-handlers.
---
 clang/include/clang/Basic/CodeGenOptions.h |  4 
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Driver/SanitizerArgs.h |  1 +
 clang/lib/CodeGen/CGExpr.cpp   | 26 +-
 clang/lib/CodeGen/CodeGenFunction.h|  2 +-
 clang/lib/Driver/SanitizerArgs.cpp | 24 +++-
 clang/lib/Frontend/CompilerInvocation.cpp  |  6 +
 7 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 2dcf98b465661e..9b97adce42cc2a 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -380,6 +380,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Set of sanitizer checks that trap rather than diagnose.
   SanitizerSet SanitizeTrap;
 
+  /// Set of sanitizer checks that have non-merged handlers (better
+  /// debuggability at the expense of code size).
+  SanitizerSet SanitizeNonMergedHandlers;
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7b544d2534d469..1a09f08890edad 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2548,6 +2548,10 @@ def fsanitize_trap_EQ : CommaJoined<["-"], 
"fsanitize-trap=">, Group;
+def fsanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fsanitize-nonmerged-handlers=">, Group,
+HelpText<"Enable non-merged handlers for specified 
sanitizers">;
+def fno_sanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fno-sanitize-nonmerged-handlers=">, Group,
+HelpText<"Disable non-merged handlers for specified 
sanitizers">;
 def fsanitize_trap : Flag<["-"], "fsanitize-trap">, Group,
  Alias, AliasArgs<["all"]>,
  HelpText<"Enable trapping for all sanitizers">;
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 4f08ea2b260179..28cfe72d6a34bd 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -25,6 +25,7 @@ class SanitizerArgs {
   SanitizerSet Sanitizers;
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
+  SanitizerSet NonMergedHandlers;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 79955f55714164..9c4dfaa393966b 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3546,7 +3546,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
  ArrayRef FnArgs,
  SanitizerHandler CheckHandler,
  CheckRecoverableKind RecoverKind, bool 
IsFatal,
- llvm::BasicBlock *ContBB) {
+ llvm::BasicBlock *ContBB, bool NoMerge) {
   assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
   std::optional DL;
   if (!CGF.Builder.getCurrentDebugLocation()) {
@@ -3581,7 +3581,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
llvm::AttributeList::FunctionIndex, B),
   /*Local=*/true);
   llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs);
-  bool NoMerge =
+  NoMerge = NoMerge ||
   ClSanitizeDebugDeoptimization ||
   !CGF.CGM.getCodeGenOpts().OptimizationLevel ||
   (CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
@@ -3608,6 +3608,7 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *FatalCond = nullptr;
   llvm::Value *RecoverableCond = nullptr;
   llvm::Value *TrapCond = nullptr;
+  bool NoMerge = false;
   for (int i = 0, n = Checked.size(); i < n; ++i) {
 llvm::Value *Check = Checked[i].first;
 // -fsanitize-trap= overrides -fsanitize-recover=.
@@ -3618,6 +3619,9 @@ void CodeGenFunct

[clang] [clang][ObjectiveC] Fix Parsing Types with the `::` Optional Scope Specifier (PR #119908)

2024-12-18 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu updated 
https://github.com/llvm/llvm-project/pull/119908

>From 63c424414c1814ec9b4c3c5a459bfe1be684586d Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Fri, 13 Dec 2024 09:41:41 -0800
Subject: [PATCH 1/4] Fix parsing :: in method parameter type.

---
 clang/lib/Parse/Parser.cpp  | 8 +++-
 clang/test/Parser/objc-coloncolon.m | 5 +
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Parser/objc-coloncolon.m

diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 36e56a92c3092e..aa78d702553172 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -,8 +,14 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(
 }
   }
 
-  if (SS.isEmpty())
+  if (SS.isEmpty()) {
+if (getLangOpts().ObjC && Tok.is(tok::coloncolon)) {
+  // ObjectiveC does not allow :: as as a scope token.
+  Diag(ConsumeToken(), diag::err_expected_type);
+  return true;
+}
 return false;
+  }
 
   // A C++ scope specifier that isn't followed by a typename.
   AnnotateScopeToken(SS, IsNewScope);
diff --git a/clang/test/Parser/objc-coloncolon.m 
b/clang/test/Parser/objc-coloncolon.m
new file mode 100644
index 00..e8a09898263bb3
--- /dev/null
+++ b/clang/test/Parser/objc-coloncolon.m
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s
+
+@interface A
+- (instancetype)init:(::A *) foo; // expected-error {{expected a type}} 
+@end

>From ec903eb3fcd18ba53af901582060bd61b13cf324 Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Mon, 16 Dec 2024 09:34:52 -0800
Subject: [PATCH 2/4] Fix ObjectiveC++

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

diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index aa78d702553172..8ba6a5dce8a994 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -2223,7 +2223,8 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(
   }
 
   if (SS.isEmpty()) {
-if (getLangOpts().ObjC && Tok.is(tok::coloncolon)) {
+if (getLangOpts().ObjC && !getLangOpts().CPlusPlus &&
+Tok.is(tok::coloncolon)) {
   // ObjectiveC does not allow :: as as a scope token.
   Diag(ConsumeToken(), diag::err_expected_type);
   return true;

>From 66c3b0b874f5a962ff902c43d33fbb22c658780c Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Wed, 18 Dec 2024 09:49:15 -0800
Subject: [PATCH 3/4] Address code review.

---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/test/Parser/objc-coloncolon.m| 12 ++--
 clang/test/Parser/objcxx-coloncolon.mm |  9 +
 3 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/objcxx-coloncolon.mm

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 26fa986810a4b8..d6d3149df07d87 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -675,6 +675,9 @@ Improvements to Clang's diagnostics
   views.push_back(std::string("123")); // warning
 }
 
+- Fixed a bug where Clang hangs on unsupported optional scope specifier ``::`` 
when parsing
+  Objective-C. Clang now emits a diagnostic message instead of hanging.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/test/Parser/objc-coloncolon.m 
b/clang/test/Parser/objc-coloncolon.m
index e8a09898263bb3..68b54ef5229af5 100644
--- a/clang/test/Parser/objc-coloncolon.m
+++ b/clang/test/Parser/objc-coloncolon.m
@@ -1,5 +1,13 @@
-// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x objective-c -fsyntax-only -Wno-objc-root-class -verify %s
+
+int GV = 42;
 
 @interface A
-- (instancetype)init:(::A *) foo; // expected-error {{expected a type}} 
++ (int) getGV;
+- (instancetype)init:(::A *) foo; // expected-error {{expected a type}}
+@end
+
+@implementation A
++ (int) getGV { return ::GV; } // expected-error {{expected a type}}
+- (instancetype)init:(::A *) foo { return self; } // expected-error {{expected 
a type}}
 @end
diff --git a/clang/test/Parser/objcxx-coloncolon.mm 
b/clang/test/Parser/objcxx-coloncolon.mm
new file mode 100644
index 00..864a7df8400c1c
--- /dev/null
+++ b/clang/test/Parser/objcxx-coloncolon.mm
@@ -0,0 +1,9 @@
+// Test to make sure the parser does not get stuck on the optional
+// scope specifier on the type B.
+// RUN: %clang_cc1 -fsyntax-only %s
+
+class B;
+
+@interface A
+- (void) init:(::B *) foo;
+@end

>From 2e0667d1f21f406be8c9ae1f10eb12f60296ddd8 Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Wed, 18 Dec 2024 11:10:16 -0800
Subject: [PATCH 4/4] Modifying the test to include valid Objective-C with

---
 clang/test/Parser/objc-coloncolon.m | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/clang/test/Parser/objc-coloncolon.m 
b/clang/test/Parser/objc-coloncolon.m
index 68b54ef5229af5..04a24fd81ec08f 100644
--- a/clang/test/Parser/objc-coloncolon.m
+++ b/clang/t

[clang] [llvm] [DirectX][SPIRV] Consistent names for HLSL resource intrinsics (PR #120466)

2024-12-18 Thread Chris B via cfe-commits

https://github.com/llvm-beanz approved this pull request.


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


[clang] [llvm] [DirectX][SPIRV] Consistent names for HLSL resource intrinsics (PR #120466)

2024-12-18 Thread Chris B via cfe-commits


@@ -208,37 +208,44 @@ Examples:
 
 .. code-block:: llvm
 
-   ; RWBuffer Buf : register(u5, space3)
-   %buf = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
-   @llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0(
-   i32 3, i32 5, i32 1, i32 0, i1 false)
-
-   ; RWBuffer Buf : register(u7, space2)
-   %buf = call target("dx.TypedBuffer", i32, 1, 0, 1)
-   @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0t(
-   i32 2, i32 7, i32 1, i32 0, i1 false)
-
-   ; Buffer Buf[24] : register(t3, space5)
-   %buf = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 0)
-   @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_0_0t(
-   i32 2, i32 7, i32 24, i32 0, i1 false)
-
-   ; struct S { float4 a; uint4 b; };
+   ;
+RWBuffer Buf : register(u5, space3) % buf =

llvm-beanz wrote:

This is from the failing doc build. Seems to be referring to this block.

> /home/runner/work/llvm-project/llvm-project/llvm/docs/DirectX/DXILResources.rst:212:Explicit
>  markup ends without a blank line; unexpected unindent.

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


[clang] [ubsan] Add -fsanitize-nonmerged-handlers (and -fno-sanitize-nonmerge… (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits

https://github.com/thurstond updated 
https://github.com/llvm/llvm-project/pull/120464

>From 2c0da9aa6f58900387fa91cdc6bcb41e0235d94c Mon Sep 17 00:00:00 2001
From: Thurston Dang 
Date: Wed, 18 Dec 2024 18:37:11 +
Subject: [PATCH 1/5] [ubsan] Add -fsanitize-nonmerged-handlers (and
 -fno-sanitize-nonmerged-handlers)

'-mllvm -ubsan-unique-traps' (https://github.com/llvm/llvm-project/pull/65972) 
applies to all UBSan
checks. This patch introduces -fsanitize-nonmerged-handlers and
-fno-sanitize-nonmerged-handlers, which allows selectively applying
non-merged handlers to a subset of UBSan checks.

N.B. we use "non-merged handlers" instead of "unique traps", since
https://github.com/llvm/llvm-project/pull/119302 has generalized it to
work for non-trap mode as well (min-rt and regular rt).

This patch does not remove the -ubsan-unique-traps flag; that will
override -f(no-)sanitize-non-merged-handlers.
---
 clang/include/clang/Basic/CodeGenOptions.h |  4 
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Driver/SanitizerArgs.h |  1 +
 clang/lib/CodeGen/CGExpr.cpp   | 26 +-
 clang/lib/CodeGen/CodeGenFunction.h|  2 +-
 clang/lib/Driver/SanitizerArgs.cpp | 24 +++-
 clang/lib/Frontend/CompilerInvocation.cpp  |  6 +
 7 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 2dcf98b465661e..9b97adce42cc2a 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -380,6 +380,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Set of sanitizer checks that trap rather than diagnose.
   SanitizerSet SanitizeTrap;
 
+  /// Set of sanitizer checks that have non-merged handlers (better
+  /// debuggability at the expense of code size).
+  SanitizerSet SanitizeNonMergedHandlers;
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7b544d2534d469..1a09f08890edad 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2548,6 +2548,10 @@ def fsanitize_trap_EQ : CommaJoined<["-"], 
"fsanitize-trap=">, Group;
+def fsanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fsanitize-nonmerged-handlers=">, Group,
+HelpText<"Enable non-merged handlers for specified 
sanitizers">;
+def fno_sanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fno-sanitize-nonmerged-handlers=">, Group,
+HelpText<"Disable non-merged handlers for specified 
sanitizers">;
 def fsanitize_trap : Flag<["-"], "fsanitize-trap">, Group,
  Alias, AliasArgs<["all"]>,
  HelpText<"Enable trapping for all sanitizers">;
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 4f08ea2b260179..28cfe72d6a34bd 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -25,6 +25,7 @@ class SanitizerArgs {
   SanitizerSet Sanitizers;
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
+  SanitizerSet NonMergedHandlers;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 79955f55714164..9c4dfaa393966b 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3546,7 +3546,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
  ArrayRef FnArgs,
  SanitizerHandler CheckHandler,
  CheckRecoverableKind RecoverKind, bool 
IsFatal,
- llvm::BasicBlock *ContBB) {
+ llvm::BasicBlock *ContBB, bool NoMerge) {
   assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
   std::optional DL;
   if (!CGF.Builder.getCurrentDebugLocation()) {
@@ -3581,7 +3581,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
llvm::AttributeList::FunctionIndex, B),
   /*Local=*/true);
   llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs);
-  bool NoMerge =
+  NoMerge = NoMerge ||
   ClSanitizeDebugDeoptimization ||
   !CGF.CGM.getCodeGenOpts().OptimizationLevel ||
   (CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
@@ -3608,6 +3608,7 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *FatalCond = nullptr;
   llvm::Value *RecoverableCond = nullptr;
   llvm::Value *TrapCond = nullptr;
+  bool NoMerge = false;
   for (int i = 0, n = Checked.size(); i < n; ++i) {
 llvm::Value *Check = Checked[i].first;
 // -fsanitize-trap= overrides -fsanitize-recover=.
@@ -3618,6 +3619,9 @@ void CodeGenFunct

[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)

2024-12-18 Thread via cfe-commits

https://github.com/4m4n-x-B4w4ne updated 
https://github.com/llvm/llvm-project/pull/120087

>From 03f536888ddc5b7be2514c2d880c6d3119b7f4ee Mon Sep 17 00:00:00 2001
From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com>
Date: Mon, 16 Dec 2024 19:43:42 +0530
Subject: [PATCH 01/17] Update ImplicitBoolConversionCheck.cpp

Added new options in ImplicitBoolConversionCheck CheckConversionToBool and 
CheckConversionFromBool.
---
 .../readability/ImplicitBoolConversionCheck.cpp   | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index f9fd1d903e231e..517a5d2b982751 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -258,14 +258,17 @@ ImplicitBoolConversionCheck::ImplicitBoolConversionCheck(
 : ClangTidyCheck(Name, Context),
   AllowIntegerConditions(Options.get("AllowIntegerConditions", false)),
   AllowPointerConditions(Options.get("AllowPointerConditions", false)),
-  UseUpperCaseLiteralSuffix(
-  Options.get("UseUpperCaseLiteralSuffix", false)) {}
+  UseUpperCaseLiteralSuffix(Options.get("UseUpperCaseLiteralSuffix", 
false)),
+  CheckConversionsToBool(Options.get("CheckConversionsToBool",true)),
+  CheckConversionsFromBool(Options.get("CheckConversionsFromBool",true)) {}
 
 void ImplicitBoolConversionCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "AllowIntegerConditions", AllowIntegerConditions);
   Options.store(Opts, "AllowPointerConditions", AllowPointerConditions);
   Options.store(Opts, "UseUpperCaseLiteralSuffix", UseUpperCaseLiteralSuffix);
+  Options.store(Opts,"CheckConversionsToBool",CheckConversionsToBool);
+  Options.store(Opts,"CheckConversionsFromBool",CheckConversionsFromBool);
 }
 
 void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
@@ -358,14 +361,14 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
 void ImplicitBoolConversionCheck::check(
 const MatchFinder::MatchResult &Result) {
 
-  if (const auto *CastToBool =
-  Result.Nodes.getNodeAs("implicitCastToBool")) {
+  if (CheckConversionsToBool && (const auto *CastToBool =
+  Result.Nodes.getNodeAs("implicitCastToBool"))) {
 const auto *Parent = Result.Nodes.getNodeAs("parentStmt");
 return handleCastToBool(CastToBool, Parent, *Result.Context);
   }
 
-  if (const auto *CastFromBool =
-  Result.Nodes.getNodeAs("implicitCastFromBool")) {
+  if (CheckConversionsFromBool && (const auto *CastFromBool =
+  Result.Nodes.getNodeAs("implicitCastFromBool"))) {
 const auto *NextImplicitCast =
 Result.Nodes.getNodeAs("furtherImplicitCast");
 return handleCastFromBool(CastFromBool, NextImplicitCast, *Result.Context);

>From 16c7c95939b4c0c38ebccbbc6cd1da3739244a24 Mon Sep 17 00:00:00 2001
From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com>
Date: Mon, 16 Dec 2024 19:45:37 +0530
Subject: [PATCH 02/17] Update ImplicitBoolConversionCheck.h

Added CheckConversionToBool and CheckConversionFromBool Options in the header
---
 .../clang-tidy/readability/ImplicitBoolConversionCheck.h| 2 ++
 1 file changed, 2 insertions(+)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
index 5947f7316e67cc..b0c3c2943e649c 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
@@ -37,6 +37,8 @@ class ImplicitBoolConversionCheck : public ClangTidyCheck {
   const bool AllowIntegerConditions;
   const bool AllowPointerConditions;
   const bool UseUpperCaseLiteralSuffix;
+  const bool CheckConversionsToBool;
+  const bool CheckConversionsFromBool;
 };
 
 } // namespace clang::tidy::readability

>From 0d6fae8b08a4a365c9295ac8a96de2aba9974c98 Mon Sep 17 00:00:00 2001
From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com>
Date: Mon, 16 Dec 2024 19:48:48 +0530
Subject: [PATCH 03/17] Create implicit-bool-conversion-check.cpp

Added new test to check the new options added in the 
ImplicitBoolConversionCheck.cpp
---
 .../implicit-bool-conversion-check.cpp| 92 +++
 1 file changed, 92 insertions(+)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp
new file mode 100644
index 00..506769d5a57322
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers

[clang] [llvm] [DirectX][SPIRV] Consistent names for HLSL resource intrinsics (PR #120466)

2024-12-18 Thread Justin Bogner via cfe-commits


@@ -208,37 +208,44 @@ Examples:
 
 .. code-block:: llvm
 
-   ; RWBuffer Buf : register(u5, space3)
-   %buf = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
-   @llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0(
-   i32 3, i32 5, i32 1, i32 0, i1 false)
-
-   ; RWBuffer Buf : register(u7, space2)
-   %buf = call target("dx.TypedBuffer", i32, 1, 0, 1)
-   @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0t(
-   i32 2, i32 7, i32 1, i32 0, i1 false)
-
-   ; Buffer Buf[24] : register(t3, space5)
-   %buf = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 0)
-   @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_0_0t(
-   i32 2, i32 7, i32 24, i32 0, i1 false)
-
-   ; struct S { float4 a; uint4 b; };
+   ;
+RWBuffer Buf : register(u5, space3) % buf =

bogner wrote:

Fixed (and built docs locally). A few lines in this file were reformatted 
incorrectly.

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


[clang] [flang] [Flang][OpenMP] Add -fopenmp-default-none command line flag (PR #120287)

2024-12-18 Thread Leandro Lupori via cfe-commits

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


[clang] [flang] [Flang][OpenMP] Add -fopenmp-default-none command line flag (PR #120287)

2024-12-18 Thread Leandro Lupori via cfe-commits


@@ -0,0 +1,34 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-default-none
+
+
+! Test that -fopenmp-default-none shows the same errors as DEFAULT(NONE)
+subroutine default_none()
+  integer a(3)
+  integer, parameter :: D=10
+  A = 1
+  B = 2
+  !$omp parallel private(c)
+  !ERROR: The DEFAULT(NONE) clause requires that 'a' must be listed in a 
data-sharing attribute clause
+  A(1:2) = 3
+  !ERROR: The DEFAULT(NONE) clause requires that 'b' must be listed in a 
data-sharing attribute clause
+  B = 4
+  C = 5 + D
+  !$omp end parallel
+end subroutine default_none
+
+! Test that indices of sequential loops are privatised and hence do not error
+! for -fopenmp-default-none.
+subroutine default_none_seq_loop
+  integer :: i
+
+  !$omp parallel do
+  do i = 1, 10
+ do j = 1, 20
+enddo
+  enddo
+end subroutine
+
+program mm
+  call default_none()
+  call default_none_seq_loop()

luporl wrote:

It would be nice to add a test for a construct that doesn't support 
data-sharing clauses, such as `workshare`, to make sure no error is reported.

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


[clang] [ubsan] Add -fsanitize-nonmerged-handlers (and -fno-sanitize-nonmerged-handlers) (PR #120464)

2024-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Thurston Dang (thurstond)


Changes

'-mllvm -ubsan-unique-traps' (https://github.com/llvm/llvm-project/pull/65972) 
applies to all UBSan checks. This patch introduces 
-fsanitize-nonmerged-handlers and -fno-sanitize-nonmerged-handlers, which 
allows selectively applying non-merged handlers to a subset of UBSan checks.

N.B. we use "non-merged handlers" instead of "unique traps", since 
https://github.com/llvm/llvm-project/pull/119302 has generalized it to work for 
non-trap mode as well (min-rt and regular rt).

This patch does not remove the -ubsan-unique-traps flag; that will override 
-f(no-)sanitize-non-merged-handlers.

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


9 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.h (+4) 
- (modified) clang/include/clang/Driver/Options.td (+8) 
- (modified) clang/include/clang/Driver/SanitizerArgs.h (+1) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+17-13) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+2-1) 
- (modified) clang/lib/Driver/SanitizerArgs.cpp (+31-7) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+7) 
- (modified) clang/test/CodeGen/ubsan-trap-merge.c (+6-1) 
- (modified) clang/test/Driver/fsanitize.c (+5) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 2dcf98b465661e..9b97adce42cc2a 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -380,6 +380,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Set of sanitizer checks that trap rather than diagnose.
   SanitizerSet SanitizeTrap;
 
+  /// Set of sanitizer checks that have non-merged handlers (better
+  /// debuggability at the expense of code size).
+  SanitizerSet SanitizeNonMergedHandlers;
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7b544d2534d469..e9fd59df3f9111 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2548,6 +2548,14 @@ def fsanitize_trap_EQ : CommaJoined<["-"], 
"fsanitize-trap=">, Group;
+def fsanitize_nonmerged_handlers_EQ
+: CommaJoined<["-"], "fsanitize-nonmerged-handlers=">,
+  Group,
+  HelpText<"Enable non-merged handlers for specified sanitizers">;
+def fno_sanitize_nonmerged_handlers_EQ
+: CommaJoined<["-"], "fno-sanitize-nonmerged-handlers=">,
+  Group,
+  HelpText<"Disable non-merged handlers for specified sanitizers">;
 def fsanitize_trap : Flag<["-"], "fsanitize-trap">, Group,
  Alias, AliasArgs<["all"]>,
  HelpText<"Enable trapping for all sanitizers">;
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 4f08ea2b260179..28cfe72d6a34bd 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -25,6 +25,7 @@ class SanitizerArgs {
   SanitizerSet Sanitizers;
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
+  SanitizerSet NonMergedHandlers;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 79955f55714164..9c0ddda2e28d9d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3546,7 +3546,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
  ArrayRef FnArgs,
  SanitizerHandler CheckHandler,
  CheckRecoverableKind RecoverKind, bool 
IsFatal,
- llvm::BasicBlock *ContBB) {
+ llvm::BasicBlock *ContBB, bool NoMerge) {
   assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
   std::optional DL;
   if (!CGF.Builder.getCurrentDebugLocation()) {
@@ -3581,10 +3581,9 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
llvm::AttributeList::FunctionIndex, B),
   /*Local=*/true);
   llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs);
-  bool NoMerge =
-  ClSanitizeDebugDeoptimization ||
-  !CGF.CGM.getCodeGenOpts().OptimizationLevel ||
-  (CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
+  NoMerge = NoMerge || ClSanitizeDebugDeoptimization ||
+!CGF.CGM.getCodeGenOpts().OptimizationLevel ||
+(CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
   if (NoMerge)
 HandlerCall->addFnAttr(llvm::Attribute::NoMerge);
   if (!MayReturn) {
@@ -3608,6 +3607,7 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *FatalCond = nullptr;
   llvm::Value *RecoverableCond = nullptr;
   llvm::Value *TrapCond = nullptr;
+  bool NoMerge = false;
   for (int i = 0, n

[clang] [ubsan] Add -fsanitize-nonmerged-handlers (and -fno-sanitize-nonmerged-handlers) (PR #120464)

2024-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Thurston Dang (thurstond)


Changes

'-mllvm -ubsan-unique-traps' (https://github.com/llvm/llvm-project/pull/65972) 
applies to all UBSan checks. This patch introduces 
-fsanitize-nonmerged-handlers and -fno-sanitize-nonmerged-handlers, which 
allows selectively applying non-merged handlers to a subset of UBSan checks.

N.B. we use "non-merged handlers" instead of "unique traps", since 
https://github.com/llvm/llvm-project/pull/119302 has generalized it to work for 
non-trap mode as well (min-rt and regular rt).

This patch does not remove the -ubsan-unique-traps flag; that will override 
-f(no-)sanitize-non-merged-handlers.

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


9 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.h (+4) 
- (modified) clang/include/clang/Driver/Options.td (+8) 
- (modified) clang/include/clang/Driver/SanitizerArgs.h (+1) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+17-13) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+2-1) 
- (modified) clang/lib/Driver/SanitizerArgs.cpp (+31-7) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+7) 
- (modified) clang/test/CodeGen/ubsan-trap-merge.c (+6-1) 
- (modified) clang/test/Driver/fsanitize.c (+5) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 2dcf98b465661e..9b97adce42cc2a 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -380,6 +380,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Set of sanitizer checks that trap rather than diagnose.
   SanitizerSet SanitizeTrap;
 
+  /// Set of sanitizer checks that have non-merged handlers (better
+  /// debuggability at the expense of code size).
+  SanitizerSet SanitizeNonMergedHandlers;
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7b544d2534d469..e9fd59df3f9111 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2548,6 +2548,14 @@ def fsanitize_trap_EQ : CommaJoined<["-"], 
"fsanitize-trap=">, Group;
+def fsanitize_nonmerged_handlers_EQ
+: CommaJoined<["-"], "fsanitize-nonmerged-handlers=">,
+  Group,
+  HelpText<"Enable non-merged handlers for specified sanitizers">;
+def fno_sanitize_nonmerged_handlers_EQ
+: CommaJoined<["-"], "fno-sanitize-nonmerged-handlers=">,
+  Group,
+  HelpText<"Disable non-merged handlers for specified sanitizers">;
 def fsanitize_trap : Flag<["-"], "fsanitize-trap">, Group,
  Alias, AliasArgs<["all"]>,
  HelpText<"Enable trapping for all sanitizers">;
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 4f08ea2b260179..28cfe72d6a34bd 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -25,6 +25,7 @@ class SanitizerArgs {
   SanitizerSet Sanitizers;
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
+  SanitizerSet NonMergedHandlers;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 79955f55714164..9c0ddda2e28d9d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3546,7 +3546,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
  ArrayRef FnArgs,
  SanitizerHandler CheckHandler,
  CheckRecoverableKind RecoverKind, bool 
IsFatal,
- llvm::BasicBlock *ContBB) {
+ llvm::BasicBlock *ContBB, bool NoMerge) {
   assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
   std::optional DL;
   if (!CGF.Builder.getCurrentDebugLocation()) {
@@ -3581,10 +3581,9 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
llvm::AttributeList::FunctionIndex, B),
   /*Local=*/true);
   llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs);
-  bool NoMerge =
-  ClSanitizeDebugDeoptimization ||
-  !CGF.CGM.getCodeGenOpts().OptimizationLevel ||
-  (CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
+  NoMerge = NoMerge || ClSanitizeDebugDeoptimization ||
+!CGF.CGM.getCodeGenOpts().OptimizationLevel ||
+(CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
   if (NoMerge)
 HandlerCall->addFnAttr(llvm::Attribute::NoMerge);
   if (!MayReturn) {
@@ -3608,6 +3607,7 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *FatalCond = nullptr;
   llvm::Value *RecoverableCond = nullptr;
   llvm::Value *TrapCond = nullptr;
+  bool NoMerge = false;
   for (int i = 0, n = Chec

[clang] [ubsan] Add -fsanitize-nonmerged-handlers (and -fno-sanitize-nonmerge… (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits

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


[clang] [ubsan] Add -fsanitize-nonmerged-handlers (and -fno-sanitize-nonmerged-handlers) (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits

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


[clang] [clang][ObjectiveC] Fix Parsing Types with the `::` Optional Scope Specifier (PR #119908)

2024-12-18 Thread Qiongsi Wu via cfe-commits

qiongsiwu wrote:

The Objective-C test is modified to contain valid code with `::` to include 
@vsapsai 's suggestion . 
https://github.com/llvm/llvm-project/pull/119908/files#diff-0c0e8844905a75c581903811a694e614f49b2945e2254a76bb5a215443028554R11

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


[clang] [ubsan] Add -fsanitize-nonmerged-handlers (and -fno-sanitize-nonmerged-handlers) (PR #120464)

2024-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Thurston Dang (thurstond)


Changes

'-mllvm -ubsan-unique-traps' (https://github.com/llvm/llvm-project/pull/65972) 
applies to all UBSan checks. This patch introduces 
-fsanitize-nonmerged-handlers and -fno-sanitize-nonmerged-handlers, which 
allows selectively applying non-merged handlers to a subset of UBSan checks.

N.B. we use "non-merged handlers" instead of "unique traps", since 
https://github.com/llvm/llvm-project/pull/119302 has generalized it to work for 
non-trap mode as well (min-rt and regular rt).

This patch does not remove the -ubsan-unique-traps flag; that will override 
-f(no-)sanitize-non-merged-handlers.

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


9 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.h (+4) 
- (modified) clang/include/clang/Driver/Options.td (+8) 
- (modified) clang/include/clang/Driver/SanitizerArgs.h (+1) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+17-13) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+2-1) 
- (modified) clang/lib/Driver/SanitizerArgs.cpp (+31-7) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+7) 
- (modified) clang/test/CodeGen/ubsan-trap-merge.c (+6-1) 
- (modified) clang/test/Driver/fsanitize.c (+5) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 2dcf98b465661e..9b97adce42cc2a 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -380,6 +380,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Set of sanitizer checks that trap rather than diagnose.
   SanitizerSet SanitizeTrap;
 
+  /// Set of sanitizer checks that have non-merged handlers (better
+  /// debuggability at the expense of code size).
+  SanitizerSet SanitizeNonMergedHandlers;
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7b544d2534d469..e9fd59df3f9111 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2548,6 +2548,14 @@ def fsanitize_trap_EQ : CommaJoined<["-"], 
"fsanitize-trap=">, Group;
+def fsanitize_nonmerged_handlers_EQ
+: CommaJoined<["-"], "fsanitize-nonmerged-handlers=">,
+  Group,
+  HelpText<"Enable non-merged handlers for specified sanitizers">;
+def fno_sanitize_nonmerged_handlers_EQ
+: CommaJoined<["-"], "fno-sanitize-nonmerged-handlers=">,
+  Group,
+  HelpText<"Disable non-merged handlers for specified sanitizers">;
 def fsanitize_trap : Flag<["-"], "fsanitize-trap">, Group,
  Alias, AliasArgs<["all"]>,
  HelpText<"Enable trapping for all sanitizers">;
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 4f08ea2b260179..28cfe72d6a34bd 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -25,6 +25,7 @@ class SanitizerArgs {
   SanitizerSet Sanitizers;
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
+  SanitizerSet NonMergedHandlers;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 79955f55714164..9c0ddda2e28d9d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3546,7 +3546,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
  ArrayRef FnArgs,
  SanitizerHandler CheckHandler,
  CheckRecoverableKind RecoverKind, bool 
IsFatal,
- llvm::BasicBlock *ContBB) {
+ llvm::BasicBlock *ContBB, bool NoMerge) {
   assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
   std::optional DL;
   if (!CGF.Builder.getCurrentDebugLocation()) {
@@ -3581,10 +3581,9 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
llvm::AttributeList::FunctionIndex, B),
   /*Local=*/true);
   llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs);
-  bool NoMerge =
-  ClSanitizeDebugDeoptimization ||
-  !CGF.CGM.getCodeGenOpts().OptimizationLevel ||
-  (CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
+  NoMerge = NoMerge || ClSanitizeDebugDeoptimization ||
+!CGF.CGM.getCodeGenOpts().OptimizationLevel ||
+(CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
   if (NoMerge)
 HandlerCall->addFnAttr(llvm::Attribute::NoMerge);
   if (!MayReturn) {
@@ -3608,6 +3607,7 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *FatalCond = nullptr;
   llvm::Value *RecoverableCond = nullptr;
   llvm::Value *TrapCond = nullptr;
+  bool NoMerge = false;
   for (int i = 0, 

[clang] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy (PR #120367)

2024-12-18 Thread Chris B via cfe-commits


@@ -1754,6 +1755,17 @@ static bool interp__builtin_vector_reduce(InterpState 
&S, CodePtr OpPC,
   PrimType ElemT = *S.getContext().classify(ElemType);
   unsigned NumElems = Arg.getNumElems();
 
+  if (ElemType->isRealFloatingType()) {
+if (ID != Builtin::BI__builtin_reduce_add &&
+ID != Builtin::BI__builtin_reduce_mul)
+  llvm_unreachable("Only reduce_add and reduce_mul are supported for "

llvm-beanz wrote:

Is this actually unreachable? You have a mix of both real error handling code 
and an unreachable. Code after an unreachable (like the return) can be removed 
by a compiler, which would cause some bad behavior here if this ever got hit.

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


[clang] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy (PR #120367)

2024-12-18 Thread Chris B via cfe-commits


@@ -12338,7 +12338,8 @@ def err_builtin_invalid_arg_type: Error <
   "a vector of integers|"
   "an unsigned integer|"
   "an 'int'|"
-  "a vector of floating points}1 (was %2)">;
+  "a vector of floating points|"
+  "a vector of integers or floating points}1 (was %2)">;

llvm-beanz wrote:

nit: I assume this is for any non-bool vector. Maybe:
```suggestion
  "a vector of arithmetic element type}1 (was %2)">;
```

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


[clang] [llvm] [InstCombine] Infer nuw for gep inbounds from base of object (PR #119225)

2024-12-18 Thread Nikita Popov via cfe-commits

nikic wrote:

> Heads up: apart from a number of instances of actual UB in the code (which 
> are quite tedious to localize and understand due to a lack of specialized 
> tooling) we're investigating a bad interaction of this commit with msan, 
> which seems to result in a miscompilation.

Thanks for the heads up! As I mentioned on another thread, I'm happy to just 
entirely revert this patch due to lack of good sanitizer support (I can do it 
tomorrow, but feel free to do it yourself earlier). Having a reproducer for the 
msan issue is probably still valuable, as it may indicate a larger problem.

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


[clang] [Clang] Re-write codegen for atomic_test_and_set and atomic_clear (PR #120449)

2024-12-18 Thread Oliver Stannard via cfe-commits

https://github.com/ostannard updated 
https://github.com/llvm/llvm-project/pull/120449

>From 28174b0b54d36b070200d630bdeae64232264841 Mon Sep 17 00:00:00 2001
From: Oliver Stannard 
Date: Wed, 18 Dec 2024 15:46:02 +
Subject: [PATCH 1/4] Add test for current behaviour

---
 clang/test/CodeGen/atomic-test-and-set.c | 199 +++
 1 file changed, 199 insertions(+)
 create mode 100644 clang/test/CodeGen/atomic-test-and-set.c

diff --git a/clang/test/CodeGen/atomic-test-and-set.c 
b/clang/test/CodeGen/atomic-test-and-set.c
new file mode 100644
index 00..a736849f16e3ac
--- /dev/null
+++ b/clang/test/CodeGen/atomic-test-and-set.c
@@ -0,0 +1,199 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=aarch64-none-elf | FileCheck %s
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+// CHECK-LABEL: define dso_local void @clear_relaxed(
+// CHECK-SAME: ptr noundef [[PTR:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[PTR_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR]], align 8
+// CHECK-NEXT:store atomic i8 0, ptr [[TMP0]] monotonic, align 1
+// CHECK-NEXT:ret void
+//
+void clear_relaxed(char *ptr) {
+  __atomic_clear(ptr, memory_order_relaxed);
+}
+
+// CHECK-LABEL: define dso_local void @clear_seq_cst(
+// CHECK-SAME: ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[PTR_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR]], align 8
+// CHECK-NEXT:store atomic i8 0, ptr [[TMP0]] seq_cst, align 1
+// CHECK-NEXT:ret void
+//
+void clear_seq_cst(char *ptr) {
+  __atomic_clear(ptr, memory_order_seq_cst);
+}
+
+// CHECK-LABEL: define dso_local void @clear_release(
+// CHECK-SAME: ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[PTR_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR]], align 8
+// CHECK-NEXT:store atomic i8 0, ptr [[TMP0]] release, align 1
+// CHECK-NEXT:ret void
+//
+void clear_release(char *ptr) {
+  __atomic_clear(ptr, memory_order_release);
+}
+
+// CHECK-LABEL: define dso_local void @clear_dynamic(
+// CHECK-SAME: ptr noundef [[PTR:%.*]], i32 noundef [[ORDER:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[PTR_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[ORDER_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8
+// CHECK-NEXT:store i32 [[ORDER]], ptr [[ORDER_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[ORDER_ADDR]], align 4
+// CHECK-NEXT:switch i32 [[TMP1]], label %[[MONOTONIC:.*]] [
+// CHECK-NEXT:  i32 0, label %[[MONOTONIC]]
+// CHECK-NEXT:  i32 3, label %[[RELEASE:.*]]
+// CHECK-NEXT:  i32 5, label %[[SEQCST:.*]]
+// CHECK-NEXT:]
+// CHECK:   [[ATOMIC_CONTINUE:.*]]:
+// CHECK-NEXT:ret void
+// CHECK:   [[MONOTONIC]]:
+// CHECK-NEXT:store atomic i8 0, ptr [[TMP0]] monotonic, align 1
+// CHECK-NEXT:br label %[[ATOMIC_CONTINUE]]
+// CHECK:   [[RELEASE]]:
+// CHECK-NEXT:store atomic i8 0, ptr [[TMP0]] release, align 1
+// CHECK-NEXT:br label %[[ATOMIC_CONTINUE]]
+// CHECK:   [[SEQCST]]:
+// CHECK-NEXT:store atomic i8 0, ptr [[TMP0]] seq_cst, align 1
+// CHECK-NEXT:br label %[[ATOMIC_CONTINUE]]
+//
+void clear_dynamic(char *ptr, int order) {
+  __atomic_clear(ptr, order);
+}
+
+// CHECK-LABEL: define dso_local void @test_and_set_relaxed(
+// CHECK-SAME: ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[PTR_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw xchg ptr [[TMP0]], i8 1 monotonic, 
align 1
+// CHECK-NEXT:[[TOBOOL:%.*]] = icmp ne i8 [[TMP1]], 0
+// CHECK-NEXT:ret void
+//
+void test_and_set_relaxed(char *ptr) {
+  __atomic_test_and_set(ptr, memory_order_relaxed);
+}
+
+// CHECK-LABEL: define dso_local void @test_and_set_consume(
+// CHECK-SAME: ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[PTR_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:store ptr [[PTR]], ptr [[PTR_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw xchg ptr [[TMP0]], i8 1 acquire, 
align 1
+// CHECK-NEXT:[[TOBOOL:%.*]] = icmp ne i8 [[TMP1]], 0
+// CHECK-NEXT:ret void
+//

[clang] [compiler-rt] [driver] Fix sanitizer libc++ runtime linking (PR #120370)

2024-12-18 Thread Fangrui Song via cfe-commits

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


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


[clang] [compiler-rt] [driver] Fix sanitizer libc++ runtime linking (PR #120370)

2024-12-18 Thread Fangrui Song via cfe-commits


@@ -145,6 +152,62 @@
 // CHECK-ASAN-LINUX-CXX: "-ldl"
 // CHECK-ASAN-LINUX-CXX: "-lresolv"
 
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform 
-fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -fno-sanitize-link-c++-runtime \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX-CNOCXX %s
+
+// CHECK-ASAN-LINUX-CNOCXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-LINUX-CNOCXX-NOT: "-lc"
+// CHECK-ASAN-LINUX-CNOCXX: "--whole-archive" "{{.*}}libclang_rt.asan.a" 
"--no-whole-archive"
+// CHECK-ASAN-LINUX-CNOCXX-NOT: libclang_rt.asan_cxx
+// CHECK-ASAN-LINUX-CNOCXX-NOT: "--dynamic-list"
+// CHECK-ASAN-LINUX-CNOCXX: "--export-dynamic"
+// CHECK-ASAN-LINUX-CNOCXX-NOT: stdc++
+// CHECK-ASAN-LINUX-CNOCXX: "-lpthread"
+// CHECK-ASAN-LINUX-CNOCXX: "-lrt"
+// CHECK-ASAN-LINUX-CNOCXX: "-ldl"
+// CHECK-ASAN-LINUX-CNOCXX: "-lresolv"
+
+// RUN: %clangxx -### %s 2>&1 \
+// RUN: --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform 
-fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -fno-sanitize-link-c++-runtime \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX-NOCXX %s
+
+// CHECK-ASAN-LINUX-NOCXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-LINUX-NOCXX-NOT: "-lc"
+// CHECK-ASAN-LINUX-NOCXX: "--whole-archive" "{{.*}}libclang_rt.asan.a" 
"--no-whole-archive"
+// CHECK-ASAN-LINUX-NOCXX-NOT: libclang_rt.asan_cxx
+// CHECK-ASAN-LINUX-NOCXX-NOT: "--dynamic-list"
+// CHECK-ASAN-LINUX-NOCXX: "--export-dynamic"
+// CHECK-ASAN-LINUX-NOCXX: stdc++
+// CHECK-ASAN-LINUX-NOCXX: "-lpthread"
+// CHECK-ASAN-LINUX-NOCXX: "-lrt"
+// CHECK-ASAN-LINUX-NOCXX: "-ldl"
+// CHECK-ASAN-LINUX-NOCXX: "-lresolv"
+
+// RUN: %clangxx -### %s 2>&1 \
+// RUN: --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform 
-fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -nostdlib++ \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX-NOSTDCXX %s
+
+// CHECK-ASAN-LINUX-NOSTDCXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-LINUX-NOSTDCXX-NOT: "-lc"
+// CHECK-ASAN-LINUX-NOSTDCXX: "--whole-archive" "{{.*}}libclang_rt.asan.a" 
"--no-whole-archive"
+// CHECK-ASAN-LINUX-NOSTDCXX-NOT: libclang_rt.asan_cxx
+// CHECK-ASAN-LINUX-NOSTDCXX-NOT: "--dynamic-list"
+// CHECK-ASAN-LINUX-NOSTDCXX: "--export-dynamic"

MaskRay wrote:

use `-SAME:` for new tests

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


[clang] [clang] Fix sub-integer __builtin_elementwise_(add|sub)_sat (PR #119423)

2024-12-18 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/119423

>From 30b30fd3c74e41363984ae1055470b9e37d3ee20 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Tue, 10 Dec 2024 17:41:07 +
Subject: [PATCH 1/3] [clang] Fix sub-integer
 __builtin_elementwise_(add|sub)_sat

These builtins would unconditionally perform the usual arithmetic
conversions on promotable scalar integer arguments. This meant in
practice that char and short arguments were promoted to int, and the
operation was truncated back down afterwards. This in effect silently
replaced a saturating add/sub with a regular add/sub, which is not
intuitive (or intended) behaviour.

With this patch, promotable scalar integer types are not promoted to
int, but are kept intact. If the types differ, the smaller integer is
promoted to the larger one. The signedness of the operation matches the
larger integer type.

No change is made to vector types, which are both not promoted and whose
element types must match.
---
 clang/lib/Sema/SemaChecking.cpp   | 38 +++
 .../test/CodeGen/builtins-elementwise-math.c  | 98 ++-
 2 files changed, 134 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a248a6b53b0d06c..6107eb854fb95e7 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2765,6 +2765,44 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   // types only.
   case Builtin::BI__builtin_elementwise_add_sat:
   case Builtin::BI__builtin_elementwise_sub_sat: {
+if (checkArgCount(TheCall, 2))
+  return ExprError();
+ExprResult LHS = TheCall->getArg(0);
+ExprResult RHS = TheCall->getArg(1);
+QualType LHSType = LHS.get()->getType().getUnqualifiedType();
+QualType RHSType = RHS.get()->getType().getUnqualifiedType();
+// If both LHS/RHS are promotable integer types, do not perform the usual
+// conversions - we must keep the saturating operation at the correct
+// bitwidth.
+if (Context.isPromotableIntegerType(LHSType) &&
+Context.isPromotableIntegerType(RHSType)) {
+  // First, convert each argument to an r-value.
+  ExprResult ResLHS = DefaultFunctionArrayLvalueConversion(LHS.get());
+  if (ResLHS.isInvalid())
+return ExprError();
+  LHS = ResLHS.get();
+
+  ExprResult ResRHS = DefaultFunctionArrayLvalueConversion(RHS.get());
+  if (ResRHS.isInvalid())
+return ExprError();
+  RHS = ResRHS.get();
+
+  LHSType = LHS.get()->getType().getUnqualifiedType();
+  RHSType = RHS.get()->getType().getUnqualifiedType();
+
+  // If the two integer types are not of equal order, cast the smaller
+  // integer one to the larger one
+  if (int Order = Context.getIntegerTypeOrder(LHSType, RHSType); Order == 
1)
+RHS = ImpCastExprToType(RHS.get(), LHSType, CK_IntegralCast);
+  else if (Order == -1)
+LHS = ImpCastExprToType(LHS.get(), RHSType, CK_IntegralCast);
+
+  TheCall->setArg(0, LHS.get());
+  TheCall->setArg(1, RHS.get());
+  TheCall->setType(LHS.get()->getType().getUnqualifiedType());
+  break;
+}
+
 if (BuiltinElementwiseMath(TheCall))
   return ExprError();
 
diff --git a/clang/test/CodeGen/builtins-elementwise-math.c 
b/clang/test/CodeGen/builtins-elementwise-math.c
index 7f6b5f26eb93070..4ac6fe18c4d5a36 100644
--- a/clang/test/CodeGen/builtins-elementwise-math.c
+++ b/clang/test/CodeGen/builtins-elementwise-math.c
@@ -68,7 +68,10 @@ void test_builtin_elementwise_add_sat(float f1, float f2, 
double d1, double d2,
   long long int i2, si8 vi1, si8 vi2,
   unsigned u1, unsigned u2, u4 vu1, u4 vu2,
   _BitInt(31) bi1, _BitInt(31) bi2,
-  unsigned _BitInt(55) bu1, unsigned 
_BitInt(55) bu2) {
+  unsigned _BitInt(55) bu1, unsigned 
_BitInt(55) bu2,
+  char c1, char c2, unsigned char uc1,
+  unsigned char uc2, short s1, short s2,
+  unsigned short us1, unsigned short us2) {
   // CHECK:  [[I1:%.+]] = load i64, ptr %i1.addr, align 8
   // CHECK-NEXT: [[I2:%.+]] = load i64, ptr %i2.addr, align 8
   // CHECK-NEXT: call i64 @llvm.sadd.sat.i64(i64 [[I1]], i64 [[I2]])
@@ -114,6 +117,50 @@ void test_builtin_elementwise_add_sat(float f1, float f2, 
double d1, double d2,
 
   // CHECK: store i64 98, ptr %i1.addr, align 8
   i1 = __builtin_elementwise_add_sat(1, 'a');
+
+  // CHECK:  [[C1:%.+]] = load i8, ptr %c1.addr, align 1
+  // CHECK-NEXT: [[C2:%.+]] = load i8, ptr %c2.addr, align 1
+  // CHECK-NEXT: call i8 @llvm.sadd.sat.i8(i8 [[C1]], i8 [[C2]])
+  c1 = __builtin_elementwise_add_sat(c1, c2);
+
+  // CHECK:  [[UC1:%.+]] = load i8, ptr %uc1.addr, a

[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2024-12-18 Thread Tom Honermann via cfe-commits


@@ -206,3 +208,124 @@ void SemaSYCL::handleKernelEntryPointAttr(Decl *D, const 
ParsedAttr &AL) {
   D->addAttr(::new (SemaRef.Context)
  SYCLKernelEntryPointAttr(SemaRef.Context, AL, TSI));
 }
+
+static SourceLocation SourceLocationForType(QualType QT) {
+  SourceLocation Loc;
+  const Type *T = QT->getUnqualifiedDesugaredType();
+  if (const TagType *TT = dyn_cast(T))
+Loc = TT->getDecl()->getLocation();
+  else if (const ObjCInterfaceType *ObjCIT = dyn_cast(T))
+Loc = ObjCIT->getDecl()->getLocation();
+  return Loc;
+}
+
+static bool CheckSYCLKernelName(Sema &S, SourceLocation Loc,
+QualType KernelName) {
+  assert(!KernelName->isDependentType());
+
+  if (!KernelName->isStructureOrClassType()) {
+// SYCL 2020 section 5.2, "Naming of kernels", only requires that the
+// kernel name be a C++ typename. However, the definition of "kernel name"
+// in the glossary states that a kernel name is a class type. Neither
+// section explicitly states whether the kernel name type can be
+// cv-qualified. For now, kernel name types are required to be class types
+// and that they may be cv-qualified. The following issue requests
+// clarification from the SYCL WG.
+//   https://github.com/KhronosGroup/SYCL-Docs/issues/568
+S.Diag(Loc, diag::warn_sycl_kernel_name_not_a_class_type) << KernelName;
+SourceLocation DeclTypeLoc = SourceLocationForType(KernelName);
+if (DeclTypeLoc.isValid())
+  S.Diag(DeclTypeLoc, diag::note_entity_declared_at) << KernelName;
+return true;
+  }
+
+  return false;
+}
+
+void SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
+  // Ensure that all attributes present on the declaration are consistent
+  // and warn about any redundant ones.
+  const SYCLKernelEntryPointAttr *SKEPAttr = nullptr;
+  for (auto SAI = FD->specific_attr_begin();
+   SAI != FD->specific_attr_end(); ++SAI) {
+if (!SKEPAttr) {
+  SKEPAttr = *SAI;
+  continue;
+}
+if (!getASTContext().hasSameType(SAI->getKernelName(),
+ SKEPAttr->getKernelName())) {
+  Diag(SAI->getLocation(), 
diag::err_sycl_entry_point_invalid_redeclaration)
+  << SAI->getKernelName() << SKEPAttr->getKernelName();
+  Diag(SKEPAttr->getLocation(), diag::note_previous_attribute);
+} else {
+  Diag(SAI->getLocation(),
+   diag::warn_sycl_entry_point_redundant_declaration);
+  Diag(SKEPAttr->getLocation(), diag::note_previous_attribute);
+}
+  }
+  assert(SKEPAttr && "Missing sycl_kernel_entry_point attribute");
+
+  // Ensure the kernel name type is valid.
+  if (!SKEPAttr->getKernelName()->isDependentType()) {
+CheckSYCLKernelName(SemaRef, SKEPAttr->getLocation(),
+SKEPAttr->getKernelName());
+  }
+
+  // Ensure that an attribute present on the previous declaration
+  // matches the one on this declaration.
+  FunctionDecl *PrevFD = FD->getPreviousDecl();
+  if (PrevFD && !PrevFD->isInvalidDecl()) {
+const auto *PrevSKEPAttr = PrevFD->getAttr();
+if (PrevSKEPAttr) {
+  if (!getASTContext().hasSameType(SKEPAttr->getKernelName(),
+   PrevSKEPAttr->getKernelName())) {
+Diag(SKEPAttr->getLocation(),
+ diag::err_sycl_entry_point_invalid_redeclaration)
+<< SKEPAttr->getKernelName() << PrevSKEPAttr->getKernelName();
+Diag(PrevSKEPAttr->getLocation(), diag::note_previous_decl) << PrevFD;
+  }
+}
+  }
+
+  if (auto *MD = dyn_cast(FD)) {
+if (!MD->isStatic()) {
+  Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
+  << /*non-static member function*/ 0;
+}
+  }
+  if (FD->isVariadic()) {
+Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
+<< /*variadic function*/ 1;
+  }
+  if (FD->isConsteval()) {
+Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
+<< /*consteval function*/ 5;
+  } else if (FD->isConstexpr()) {
+Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
+<< /*constexpr function*/ 4;
+  }
+  if (FD->isNoReturn()) {
+Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
+<< /*noreturn function*/ 6;
+  }
+
+  if (!FD->getReturnType()->isVoidType()) {
+Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_return_type);
+  }
+
+  if (!FD->isInvalidDecl() && !FD->isTemplated()) {

tahonermann wrote:

Definitely `isTemplated()` here. There is no need to register a dependent type 
as a kernel name and, if the kernel name type is not dependent, registering the 
templated declaration could lead to a kernel name conflict with its own 
instantiated declaration.

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

[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2024-12-18 Thread Tom Honermann via cfe-commits


@@ -206,3 +208,124 @@ void SemaSYCL::handleKernelEntryPointAttr(Decl *D, const 
ParsedAttr &AL) {
   D->addAttr(::new (SemaRef.Context)
  SYCLKernelEntryPointAttr(SemaRef.Context, AL, TSI));
 }
+
+static SourceLocation SourceLocationForType(QualType QT) {
+  SourceLocation Loc;
+  const Type *T = QT->getUnqualifiedDesugaredType();
+  if (const TagType *TT = dyn_cast(T))
+Loc = TT->getDecl()->getLocation();
+  else if (const ObjCInterfaceType *ObjCIT = dyn_cast(T))
+Loc = ObjCIT->getDecl()->getLocation();
+  return Loc;
+}
+
+static bool CheckSYCLKernelName(Sema &S, SourceLocation Loc,
+QualType KernelName) {
+  assert(!KernelName->isDependentType());
+
+  if (!KernelName->isStructureOrClassType()) {
+// SYCL 2020 section 5.2, "Naming of kernels", only requires that the
+// kernel name be a C++ typename. However, the definition of "kernel name"
+// in the glossary states that a kernel name is a class type. Neither
+// section explicitly states whether the kernel name type can be
+// cv-qualified. For now, kernel name types are required to be class types
+// and that they may be cv-qualified. The following issue requests
+// clarification from the SYCL WG.
+//   https://github.com/KhronosGroup/SYCL-Docs/issues/568
+S.Diag(Loc, diag::warn_sycl_kernel_name_not_a_class_type) << KernelName;
+SourceLocation DeclTypeLoc = SourceLocationForType(KernelName);
+if (DeclTypeLoc.isValid())
+  S.Diag(DeclTypeLoc, diag::note_entity_declared_at) << KernelName;
+return true;
+  }
+
+  return false;
+}
+
+void SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
+  // Ensure that all attributes present on the declaration are consistent
+  // and warn about any redundant ones.
+  const SYCLKernelEntryPointAttr *SKEPAttr = nullptr;
+  for (auto SAI = FD->specific_attr_begin();

tahonermann wrote:

I don't see how that is an improvement. What is the concern with 
`specific_attr_iterator`? 

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


[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2024-12-18 Thread Tom Honermann via cfe-commits

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


[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2024-12-18 Thread Tom Honermann via cfe-commits


@@ -206,3 +208,124 @@ void SemaSYCL::handleKernelEntryPointAttr(Decl *D, const 
ParsedAttr &AL) {
   D->addAttr(::new (SemaRef.Context)
  SYCLKernelEntryPointAttr(SemaRef.Context, AL, TSI));
 }
+
+static SourceLocation SourceLocationForType(QualType QT) {
+  SourceLocation Loc;
+  const Type *T = QT->getUnqualifiedDesugaredType();
+  if (const TagType *TT = dyn_cast(T))
+Loc = TT->getDecl()->getLocation();
+  else if (const ObjCInterfaceType *ObjCIT = dyn_cast(T))
+Loc = ObjCIT->getDecl()->getLocation();
+  return Loc;
+}
+
+static bool CheckSYCLKernelName(Sema &S, SourceLocation Loc,
+QualType KernelName) {
+  assert(!KernelName->isDependentType());
+
+  if (!KernelName->isStructureOrClassType()) {

tahonermann wrote:

`isStructureOrClassType()` excludes unions (but includes Microsoft's 
`__interface` types; we could exclude those); see 
[here](https://github.com/llvm/llvm-project/blob/2b932bc111c0d96db7044b0a854d7ad763710df2/clang/lib/AST/Type.cpp#L690-L696).
 

The SYCL 2020 specification is imprecise; see 
[here](https://github.com/KhronosGroup/SYCL-Docs/issues/568) for an issue I 
previously reported against it. For now, I've been taking a conservative view 
and restricting what is allowed to just non-union class types. We can then lift 
these restrictions once the SYCL specification is clarified.

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


[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2024-12-18 Thread Tom Honermann via cfe-commits


@@ -12408,6 +12408,29 @@ def err_sycl_special_type_num_init_method : Error<
   "types with 'sycl_special_class' attribute must have one and only one 
'__init' "
   "method defined">;
 
+// SYCL kernel entry point diagnostics
+def err_sycl_entry_point_invalid : Error<
+  "'sycl_kernel_entry_point' attribute cannot be applied to a"
+  " %select{non-static member|variadic|deleted|defaulted|constexpr|consteval|"
+   "noreturn|coroutine}0 function">;

tahonermann wrote:

Just "coroutine" is what is commonly used, though I do see a couple of cases of 
"coroutine function" (only one of which is user facing):
```
def note_coroutine_promise_call_implicitly_required : Note<
  "call to %0 implicitly required by coroutine function here">;
...
def note_coroutine_function_declare_noexcept : Note<
  "must be declared with 'noexcept'"
>;
```

I agree a change is warranted. That additional `%select` is pretty ugly, but I 
do see similar precedent, so ok.

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


[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2024-12-18 Thread Tom Honermann via cfe-commits


@@ -12408,6 +12408,29 @@ def err_sycl_special_type_num_init_method : Error<
   "types with 'sycl_special_class' attribute must have one and only one 
'__init' "
   "method defined">;
 
+// SYCL kernel entry point diagnostics
+def err_sycl_entry_point_invalid : Error<
+  "'sycl_kernel_entry_point' attribute cannot be applied to a"
+  " %select{non-static member|variadic|deleted|defaulted|constexpr|consteval|"
+   "noreturn|coroutine}0 function">;
+def err_sycl_entry_point_invalid_redeclaration : Error<
+  "'sycl_kernel_entry_point' kernel name argument does not match prior"
+  " declaration%diff{: $ vs $|}0,1">;
+def err_sycl_kernel_name_conflict : Error<
+  "'sycl_kernel_entry_point' kernel name argument conflicts with a previous"
+  " declaration">;
+def warn_sycl_kernel_name_not_a_class_type : Warning<
+  "%0 is not a valid SYCL kernel name type; a class type is required">,

tahonermann wrote:

I mentioned in another response that the SYCL 2020 specification is lacking in 
specificity. My intent is to be conservative for now and relax kernel name type 
constraints later once the SYCL specification is clarified. I'll make the 
following change for now (we do state "non-union" else where, but I don't see 
existing examples of "non-union class type").
```suggestion
  "%0 is not a valid SYCL kernel name type; a non-union class type is 
required">,
```

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


[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2024-12-18 Thread Tom Honermann via cfe-commits


@@ -1134,8 +1134,18 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
   // the presence of a sycl_kernel_entry_point attribute, register it so that
   // associated metadata is recreated.
   if (FD->hasAttr()) {
+const auto *SKEPAttr = FD->getAttr();
 ASTContext &C = Reader.getContext();
-C.registerSYCLEntryPointFunction(FD);
+const SYCLKernelInfo *SKI = 
C.findSYCLKernelInfo(SKEPAttr->getKernelName());
+if (SKI) {
+  if (!declaresSameEntity(FD, SKI->getKernelEntryPointDecl())) {
+Reader.Diag(FD->getLocation(), diag::err_sycl_kernel_name_conflict);

tahonermann wrote:

I don't know where else it could be checked. If you search for `.Diag` 
elsewhere in the file, you'll see checks for similar conditions; e.g., for 
duplicate definitions across modules in 
`checkMultipleDefinitionInNamedModules()` (as required by the C++ standard), 
for duplicate Objective-C instance variables in `VisitObjCIvarDecl()`, and for 
duplicate Objective-C category definitions in `ObjCCategoriesVisitor::add()`. I 
think this follows existing precedent.

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


[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2024-12-18 Thread Tom Honermann via cfe-commits


@@ -1550,6 +1550,8 @@ NamedDecl *Sema::ActOnNonTypeTemplateParameter(Scope *S, 
Declarator &D,
 IdResolver.AddDecl(Param);
   }
 
+  ProcessDeclAttributes(S, Param, D);

tahonermann wrote:

This was needed to ensure diagnostics were issued for a few of the tests. I 
think this was a simple omission. I appreciate wanting other eyes on it though 
and we could move this to a separate PR. Note that this checks attributes on 
the types of non-type template arguments; from the C++ standard perspective, 
this is like any other type specifier.

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


[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2024-12-18 Thread Tom Honermann via cfe-commits


@@ -206,3 +208,124 @@ void SemaSYCL::handleKernelEntryPointAttr(Decl *D, const 
ParsedAttr &AL) {
   D->addAttr(::new (SemaRef.Context)
  SYCLKernelEntryPointAttr(SemaRef.Context, AL, TSI));
 }
+
+static SourceLocation SourceLocationForType(QualType QT) {
+  SourceLocation Loc;
+  const Type *T = QT->getUnqualifiedDesugaredType();
+  if (const TagType *TT = dyn_cast(T))
+Loc = TT->getDecl()->getLocation();
+  else if (const ObjCInterfaceType *ObjCIT = dyn_cast(T))
+Loc = ObjCIT->getDecl()->getLocation();
+  return Loc;
+}
+
+static bool CheckSYCLKernelName(Sema &S, SourceLocation Loc,
+QualType KernelName) {
+  assert(!KernelName->isDependentType());
+
+  if (!KernelName->isStructureOrClassType()) {
+// SYCL 2020 section 5.2, "Naming of kernels", only requires that the
+// kernel name be a C++ typename. However, the definition of "kernel name"
+// in the glossary states that a kernel name is a class type. Neither
+// section explicitly states whether the kernel name type can be
+// cv-qualified. For now, kernel name types are required to be class types
+// and that they may be cv-qualified. The following issue requests
+// clarification from the SYCL WG.
+//   https://github.com/KhronosGroup/SYCL-Docs/issues/568
+S.Diag(Loc, diag::warn_sycl_kernel_name_not_a_class_type) << KernelName;
+SourceLocation DeclTypeLoc = SourceLocationForType(KernelName);
+if (DeclTypeLoc.isValid())
+  S.Diag(DeclTypeLoc, diag::note_entity_declared_at) << KernelName;
+return true;
+  }
+
+  return false;
+}
+
+void SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
+  // Ensure that all attributes present on the declaration are consistent
+  // and warn about any redundant ones.
+  const SYCLKernelEntryPointAttr *SKEPAttr = nullptr;
+  for (auto SAI = FD->specific_attr_begin();
+   SAI != FD->specific_attr_end(); ++SAI) {
+if (!SKEPAttr) {
+  SKEPAttr = *SAI;
+  continue;
+}
+if (!getASTContext().hasSameType(SAI->getKernelName(),
+ SKEPAttr->getKernelName())) {
+  Diag(SAI->getLocation(), 
diag::err_sycl_entry_point_invalid_redeclaration)
+  << SAI->getKernelName() << SKEPAttr->getKernelName();
+  Diag(SKEPAttr->getLocation(), diag::note_previous_attribute);
+} else {
+  Diag(SAI->getLocation(),
+   diag::warn_sycl_entry_point_redundant_declaration);
+  Diag(SKEPAttr->getLocation(), diag::note_previous_attribute);
+}
+  }
+  assert(SKEPAttr && "Missing sycl_kernel_entry_point attribute");
+
+  // Ensure the kernel name type is valid.
+  if (!SKEPAttr->getKernelName()->isDependentType()) {
+CheckSYCLKernelName(SemaRef, SKEPAttr->getLocation(),
+SKEPAttr->getKernelName());
+  }
+
+  // Ensure that an attribute present on the previous declaration
+  // matches the one on this declaration.
+  FunctionDecl *PrevFD = FD->getPreviousDecl();
+  if (PrevFD && !PrevFD->isInvalidDecl()) {
+const auto *PrevSKEPAttr = PrevFD->getAttr();
+if (PrevSKEPAttr) {
+  if (!getASTContext().hasSameType(SKEPAttr->getKernelName(),
+   PrevSKEPAttr->getKernelName())) {
+Diag(SKEPAttr->getLocation(),
+ diag::err_sycl_entry_point_invalid_redeclaration)
+<< SKEPAttr->getKernelName() << PrevSKEPAttr->getKernelName();
+Diag(PrevSKEPAttr->getLocation(), diag::note_previous_decl) << PrevFD;
+  }
+}
+  }
+
+  if (auto *MD = dyn_cast(FD)) {
+if (!MD->isStatic()) {
+  Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
+  << /*non-static member function*/ 0;
+}

tahonermann wrote:

Right, thanks. I forgot to clean up such cases after some recent changes. Will 
do.

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


[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2024-12-18 Thread Tom Honermann via cfe-commits

https://github.com/tahonermann commented:

Responses to Erich's comments. Thanks, Erich!

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


[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2024-12-18 Thread Tom Honermann via cfe-commits


@@ -15978,6 +15988,24 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
   CheckCoroutineWrapper(FD);
   }
 
+  // Diagnose invalid SYCL kernel entry point function declarations.
+  if (FD && !FD->isInvalidDecl() && !FD->isTemplated() &&
+  FD->hasAttr()) {
+if (FD->isDeleted()) {
+  Diag(FD->getAttr()->getLocation(),
+   diag::err_sycl_entry_point_invalid)
+  << /*deleted function*/ 2;
+} else if (FD->isDefaulted()) {
+  Diag(FD->getAttr()->getLocation(),
+   diag::err_sycl_entry_point_invalid)
+  << /*defaulted function*/ 3;
+} else if (FSI->isCoroutine()) {
+  Diag(FD->getAttr()->getLocation(),
+   diag::err_sycl_entry_point_invalid)
+  << /*coroutine*/ 7;

tahonermann wrote:

Can you point me to an example? I haven't been able to find one. It doesn't 
look like there is a way to declare an enum with the diagnostic definition. 
Without the ability to do so, I don't see how adding an intermediate enum 
somewhere else improves the situation.

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


[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2024-12-18 Thread Tom Honermann via cfe-commits


@@ -206,3 +208,124 @@ void SemaSYCL::handleKernelEntryPointAttr(Decl *D, const 
ParsedAttr &AL) {
   D->addAttr(::new (SemaRef.Context)
  SYCLKernelEntryPointAttr(SemaRef.Context, AL, TSI));
 }
+
+static SourceLocation SourceLocationForType(QualType QT) {
+  SourceLocation Loc;
+  const Type *T = QT->getUnqualifiedDesugaredType();
+  if (const TagType *TT = dyn_cast(T))
+Loc = TT->getDecl()->getLocation();
+  else if (const ObjCInterfaceType *ObjCIT = dyn_cast(T))
+Loc = ObjCIT->getDecl()->getLocation();
+  return Loc;

tahonermann wrote:

No, it is intentional that an invalid source location be returned if there is 
no source location for the type (e.g., for `int`). I think the above covers all 
(non-alias) types that can be user declared. I could add comments to better 
explain the intent for this function; I'll do that.

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


[clang] [CIR] floating-point, pointer, and function types (PR #120484)

2024-12-18 Thread David Olsen via cfe-commits

https://github.com/dkolsen-pgi created 
https://github.com/llvm/llvm-project/pull/120484

Upstream ClangIR support for `void` type, floating-point types, pointer types, 
and function types.

Floating-point support is missing the IBM double-double format, because that 
hasn't been implemented in the incubator project yet.

Pointer types do not yet support address spaces.

Function type support includes only the return type and the parameter types.  
The many other properties and attributes of function types will be upstreamed 
later.

>From b76111ab93253a772156992e70acb5c78511a6bf Mon Sep 17 00:00:00 2001
From: David Olsen 
Date: Wed, 18 Dec 2024 13:52:58 -0800
Subject: [PATCH] [CIR] floating-point, pointer, and function types

Upstream ClangIR support for `void` type, floating-point types, pointer
types, and function types.

Floating-point support is missing the IBM double-double format, because
that hasn't been implemented in the incubator project yet.

Pointer types do not yet support address spaces.

Function type support includes only the return type and the parameter
types.  The many other properties and attributes of function types will
be upstreamed later.
---
 clang/include/clang/CIR/CMakeLists.txt|   1 +
 .../CIR/Dialect/Builder/CIRBaseBuilder.h  |   8 +
 clang/include/clang/CIR/Dialect/IR/CIRTypes.h |   7 +
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  | 221 ++
 .../clang/CIR/Interfaces/CIRFPTypeInterface.h |  22 ++
 .../CIR/Interfaces/CIRFPTypeInterface.td  |  52 
 .../clang/CIR/Interfaces/CMakeLists.txt   |  14 +
 clang/lib/CIR/CMakeLists.txt  |   1 +
 clang/lib/CIR/CodeGen/CIRGenBuilder.h |  12 +
 clang/lib/CIR/CodeGen/CIRGenModule.cpp|   7 +
 clang/lib/CIR/CodeGen/CIRGenTypeCache.h   |  11 +
 clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 143 +
 clang/lib/CIR/CodeGen/CIRGenTypes.h   |   9 +
 clang/lib/CIR/CodeGen/CMakeLists.txt  |   1 +
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 280 ++
 clang/lib/CIR/Dialect/IR/CMakeLists.txt   |   1 +
 .../lib/CIR/Interfaces/CIRFPTypeInterface.cpp |  14 +
 clang/lib/CIR/Interfaces/CMakeLists.txt   |  14 +
 clang/test/CIR/global-var-simple.cpp  |  39 +++
 19 files changed, 857 insertions(+)
 create mode 100644 clang/include/clang/CIR/Interfaces/CIRFPTypeInterface.h
 create mode 100644 clang/include/clang/CIR/Interfaces/CIRFPTypeInterface.td
 create mode 100644 clang/include/clang/CIR/Interfaces/CMakeLists.txt
 create mode 100644 clang/lib/CIR/Interfaces/CIRFPTypeInterface.cpp
 create mode 100644 clang/lib/CIR/Interfaces/CMakeLists.txt

diff --git a/clang/include/clang/CIR/CMakeLists.txt 
b/clang/include/clang/CIR/CMakeLists.txt
index f8d6f407a03d02..e20c896171c928 100644
--- a/clang/include/clang/CIR/CMakeLists.txt
+++ b/clang/include/clang/CIR/CMakeLists.txt
@@ -4,3 +4,4 @@ include_directories(${MLIR_INCLUDE_DIR})
 include_directories(${MLIR_TABLEGEN_OUTPUT_DIR})
 
 add_subdirectory(Dialect)
+add_subdirectory(Interfaces)
diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index 75ae74e926fbc6..0e414921324b7f 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -18,6 +18,14 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 public:
   CIRBaseBuilderTy(mlir::MLIRContext &mlirContext)
   : mlir::OpBuilder(&mlirContext) {}
+
+  cir::PointerType getPointerTo(mlir::Type ty) {
+return cir::PointerType::get(getContext(), ty);
+  }
+
+  cir::PointerType getVoidPtrTy() {
+return getPointerTo(cir::VoidType::get(getContext()));
+  }
 };
 
 } // namespace cir
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
index 2bc7d77b2bc8a3..5d1eb17e146d03 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
@@ -16,6 +16,13 @@
 #include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/IR/Types.h"
 #include "mlir/Interfaces/DataLayoutInterfaces.h"
+#include "clang/CIR/Interfaces/CIRFPTypeInterface.h"
+
+namespace cir {
+
+bool isAnyFloatingPointType(mlir::Type t);
+
+} // namespace cir
 
 
//===--===//
 // CIR Dialect Tablegen'd Types
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index ce0b6ba1d68c55..ef00b26c1fd98c 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -14,6 +14,7 @@
 #define MLIR_CIR_DIALECT_CIR_TYPES
 
 include "clang/CIR/Dialect/IR/CIRDialect.td"
+include "clang/CIR/Interfaces/CIRFPTypeInterface.td"
 include "mlir/Interfaces/DataLayoutInterfaces.td"
 include "mlir/IR/AttrTypeBase.td"
 
@@ -129,4 +130,224 @@ def PrimitiveInt
 : AnyTypeOf<[UInt8, UInt16,

[clang] [CIR] floating-point, pointer, and function types (PR #120484)

2024-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: David Olsen (dkolsen-pgi)


Changes

Upstream ClangIR support for `void` type, floating-point types, pointer types, 
and function types.

Floating-point support is missing the IBM double-double format, because that 
hasn't been implemented in the incubator project yet.

Pointer types do not yet support address spaces.

Function type support includes only the return type and the parameter types.  
The many other properties and attributes of function types will be upstreamed 
later.

---

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


19 Files Affected:

- (modified) clang/include/clang/CIR/CMakeLists.txt (+1) 
- (modified) clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h (+8) 
- (modified) clang/include/clang/CIR/Dialect/IR/CIRTypes.h (+7) 
- (modified) clang/include/clang/CIR/Dialect/IR/CIRTypes.td (+221) 
- (added) clang/include/clang/CIR/Interfaces/CIRFPTypeInterface.h (+22) 
- (added) clang/include/clang/CIR/Interfaces/CIRFPTypeInterface.td (+52) 
- (added) clang/include/clang/CIR/Interfaces/CMakeLists.txt (+14) 
- (modified) clang/lib/CIR/CMakeLists.txt (+1) 
- (modified) clang/lib/CIR/CodeGen/CIRGenBuilder.h (+12) 
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+7) 
- (modified) clang/lib/CIR/CodeGen/CIRGenTypeCache.h (+11) 
- (modified) clang/lib/CIR/CodeGen/CIRGenTypes.cpp (+143) 
- (modified) clang/lib/CIR/CodeGen/CIRGenTypes.h (+9) 
- (modified) clang/lib/CIR/CodeGen/CMakeLists.txt (+1) 
- (modified) clang/lib/CIR/Dialect/IR/CIRTypes.cpp (+280) 
- (modified) clang/lib/CIR/Dialect/IR/CMakeLists.txt (+1) 
- (added) clang/lib/CIR/Interfaces/CIRFPTypeInterface.cpp (+14) 
- (added) clang/lib/CIR/Interfaces/CMakeLists.txt (+14) 
- (modified) clang/test/CIR/global-var-simple.cpp (+39) 


``diff
diff --git a/clang/include/clang/CIR/CMakeLists.txt 
b/clang/include/clang/CIR/CMakeLists.txt
index f8d6f407a03d02..e20c896171c928 100644
--- a/clang/include/clang/CIR/CMakeLists.txt
+++ b/clang/include/clang/CIR/CMakeLists.txt
@@ -4,3 +4,4 @@ include_directories(${MLIR_INCLUDE_DIR})
 include_directories(${MLIR_TABLEGEN_OUTPUT_DIR})
 
 add_subdirectory(Dialect)
+add_subdirectory(Interfaces)
diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index 75ae74e926fbc6..0e414921324b7f 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -18,6 +18,14 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 public:
   CIRBaseBuilderTy(mlir::MLIRContext &mlirContext)
   : mlir::OpBuilder(&mlirContext) {}
+
+  cir::PointerType getPointerTo(mlir::Type ty) {
+return cir::PointerType::get(getContext(), ty);
+  }
+
+  cir::PointerType getVoidPtrTy() {
+return getPointerTo(cir::VoidType::get(getContext()));
+  }
 };
 
 } // namespace cir
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
index 2bc7d77b2bc8a3..5d1eb17e146d03 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
@@ -16,6 +16,13 @@
 #include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/IR/Types.h"
 #include "mlir/Interfaces/DataLayoutInterfaces.h"
+#include "clang/CIR/Interfaces/CIRFPTypeInterface.h"
+
+namespace cir {
+
+bool isAnyFloatingPointType(mlir::Type t);
+
+} // namespace cir
 
 
//===--===//
 // CIR Dialect Tablegen'd Types
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index ce0b6ba1d68c55..ef00b26c1fd98c 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -14,6 +14,7 @@
 #define MLIR_CIR_DIALECT_CIR_TYPES
 
 include "clang/CIR/Dialect/IR/CIRDialect.td"
+include "clang/CIR/Interfaces/CIRFPTypeInterface.td"
 include "mlir/Interfaces/DataLayoutInterfaces.td"
 include "mlir/IR/AttrTypeBase.td"
 
@@ -129,4 +130,224 @@ def PrimitiveInt
 : AnyTypeOf<[UInt8, UInt16, UInt32, UInt64, SInt8, SInt16, SInt32, SInt64],
 "primitive int", "::cir::IntType">;
 
+//===--===//
+// FloatType
+//===--===//
+
+class CIR_FloatType
+: CIR_Type,
+DeclareTypeInterfaceMethods,
+  ]> {}
+
+def CIR_Single : CIR_FloatType<"Single", "float"> {
+  let summary = "CIR single-precision 32-bit float type";
+  let description = [{
+A 32-bit floating-point type whose format is IEEE-754 `binary32`.  It
+represents the types `float`, `_Float32`, and `std::float32_t` in C and 
C++.
+  }];
+}
+
+def CIR_Double : CIR_FloatType<"Double", "double"> {
+  let summary = "CIR double-precision 64-

[clang] [CIR] floating-point, pointer, and function types (PR #120484)

2024-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: David Olsen (dkolsen-pgi)


Changes

Upstream ClangIR support for `void` type, floating-point types, pointer types, 
and function types.

Floating-point support is missing the IBM double-double format, because that 
hasn't been implemented in the incubator project yet.

Pointer types do not yet support address spaces.

Function type support includes only the return type and the parameter types.  
The many other properties and attributes of function types will be upstreamed 
later.

---

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


19 Files Affected:

- (modified) clang/include/clang/CIR/CMakeLists.txt (+1) 
- (modified) clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h (+8) 
- (modified) clang/include/clang/CIR/Dialect/IR/CIRTypes.h (+7) 
- (modified) clang/include/clang/CIR/Dialect/IR/CIRTypes.td (+221) 
- (added) clang/include/clang/CIR/Interfaces/CIRFPTypeInterface.h (+22) 
- (added) clang/include/clang/CIR/Interfaces/CIRFPTypeInterface.td (+52) 
- (added) clang/include/clang/CIR/Interfaces/CMakeLists.txt (+14) 
- (modified) clang/lib/CIR/CMakeLists.txt (+1) 
- (modified) clang/lib/CIR/CodeGen/CIRGenBuilder.h (+12) 
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+7) 
- (modified) clang/lib/CIR/CodeGen/CIRGenTypeCache.h (+11) 
- (modified) clang/lib/CIR/CodeGen/CIRGenTypes.cpp (+143) 
- (modified) clang/lib/CIR/CodeGen/CIRGenTypes.h (+9) 
- (modified) clang/lib/CIR/CodeGen/CMakeLists.txt (+1) 
- (modified) clang/lib/CIR/Dialect/IR/CIRTypes.cpp (+280) 
- (modified) clang/lib/CIR/Dialect/IR/CMakeLists.txt (+1) 
- (added) clang/lib/CIR/Interfaces/CIRFPTypeInterface.cpp (+14) 
- (added) clang/lib/CIR/Interfaces/CMakeLists.txt (+14) 
- (modified) clang/test/CIR/global-var-simple.cpp (+39) 


``diff
diff --git a/clang/include/clang/CIR/CMakeLists.txt 
b/clang/include/clang/CIR/CMakeLists.txt
index f8d6f407a03d02..e20c896171c928 100644
--- a/clang/include/clang/CIR/CMakeLists.txt
+++ b/clang/include/clang/CIR/CMakeLists.txt
@@ -4,3 +4,4 @@ include_directories(${MLIR_INCLUDE_DIR})
 include_directories(${MLIR_TABLEGEN_OUTPUT_DIR})
 
 add_subdirectory(Dialect)
+add_subdirectory(Interfaces)
diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index 75ae74e926fbc6..0e414921324b7f 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -18,6 +18,14 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 public:
   CIRBaseBuilderTy(mlir::MLIRContext &mlirContext)
   : mlir::OpBuilder(&mlirContext) {}
+
+  cir::PointerType getPointerTo(mlir::Type ty) {
+return cir::PointerType::get(getContext(), ty);
+  }
+
+  cir::PointerType getVoidPtrTy() {
+return getPointerTo(cir::VoidType::get(getContext()));
+  }
 };
 
 } // namespace cir
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
index 2bc7d77b2bc8a3..5d1eb17e146d03 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
@@ -16,6 +16,13 @@
 #include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/IR/Types.h"
 #include "mlir/Interfaces/DataLayoutInterfaces.h"
+#include "clang/CIR/Interfaces/CIRFPTypeInterface.h"
+
+namespace cir {
+
+bool isAnyFloatingPointType(mlir::Type t);
+
+} // namespace cir
 
 
//===--===//
 // CIR Dialect Tablegen'd Types
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index ce0b6ba1d68c55..ef00b26c1fd98c 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -14,6 +14,7 @@
 #define MLIR_CIR_DIALECT_CIR_TYPES
 
 include "clang/CIR/Dialect/IR/CIRDialect.td"
+include "clang/CIR/Interfaces/CIRFPTypeInterface.td"
 include "mlir/Interfaces/DataLayoutInterfaces.td"
 include "mlir/IR/AttrTypeBase.td"
 
@@ -129,4 +130,224 @@ def PrimitiveInt
 : AnyTypeOf<[UInt8, UInt16, UInt32, UInt64, SInt8, SInt16, SInt32, SInt64],
 "primitive int", "::cir::IntType">;
 
+//===--===//
+// FloatType
+//===--===//
+
+class CIR_FloatType
+: CIR_Type,
+DeclareTypeInterfaceMethods,
+  ]> {}
+
+def CIR_Single : CIR_FloatType<"Single", "float"> {
+  let summary = "CIR single-precision 32-bit float type";
+  let description = [{
+A 32-bit floating-point type whose format is IEEE-754 `binary32`.  It
+represents the types `float`, `_Float32`, and `std::float32_t` in C and 
C++.
+  }];
+}
+
+def CIR_Double : CIR_FloatType<"Double", "double"> {
+  let summary = "CIR double-precision 64-bi

[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)

2024-12-18 Thread via cfe-commits

https://github.com/4m4n-x-B4w4ne updated 
https://github.com/llvm/llvm-project/pull/120087

>From 03f536888ddc5b7be2514c2d880c6d3119b7f4ee Mon Sep 17 00:00:00 2001
From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com>
Date: Mon, 16 Dec 2024 19:43:42 +0530
Subject: [PATCH 01/22] Update ImplicitBoolConversionCheck.cpp

Added new options in ImplicitBoolConversionCheck CheckConversionToBool and 
CheckConversionFromBool.
---
 .../readability/ImplicitBoolConversionCheck.cpp   | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index f9fd1d903e231e..517a5d2b982751 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -258,14 +258,17 @@ ImplicitBoolConversionCheck::ImplicitBoolConversionCheck(
 : ClangTidyCheck(Name, Context),
   AllowIntegerConditions(Options.get("AllowIntegerConditions", false)),
   AllowPointerConditions(Options.get("AllowPointerConditions", false)),
-  UseUpperCaseLiteralSuffix(
-  Options.get("UseUpperCaseLiteralSuffix", false)) {}
+  UseUpperCaseLiteralSuffix(Options.get("UseUpperCaseLiteralSuffix", 
false)),
+  CheckConversionsToBool(Options.get("CheckConversionsToBool",true)),
+  CheckConversionsFromBool(Options.get("CheckConversionsFromBool",true)) {}
 
 void ImplicitBoolConversionCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "AllowIntegerConditions", AllowIntegerConditions);
   Options.store(Opts, "AllowPointerConditions", AllowPointerConditions);
   Options.store(Opts, "UseUpperCaseLiteralSuffix", UseUpperCaseLiteralSuffix);
+  Options.store(Opts,"CheckConversionsToBool",CheckConversionsToBool);
+  Options.store(Opts,"CheckConversionsFromBool",CheckConversionsFromBool);
 }
 
 void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
@@ -358,14 +361,14 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
 void ImplicitBoolConversionCheck::check(
 const MatchFinder::MatchResult &Result) {
 
-  if (const auto *CastToBool =
-  Result.Nodes.getNodeAs("implicitCastToBool")) {
+  if (CheckConversionsToBool && (const auto *CastToBool =
+  Result.Nodes.getNodeAs("implicitCastToBool"))) {
 const auto *Parent = Result.Nodes.getNodeAs("parentStmt");
 return handleCastToBool(CastToBool, Parent, *Result.Context);
   }
 
-  if (const auto *CastFromBool =
-  Result.Nodes.getNodeAs("implicitCastFromBool")) {
+  if (CheckConversionsFromBool && (const auto *CastFromBool =
+  Result.Nodes.getNodeAs("implicitCastFromBool"))) {
 const auto *NextImplicitCast =
 Result.Nodes.getNodeAs("furtherImplicitCast");
 return handleCastFromBool(CastFromBool, NextImplicitCast, *Result.Context);

>From 16c7c95939b4c0c38ebccbbc6cd1da3739244a24 Mon Sep 17 00:00:00 2001
From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com>
Date: Mon, 16 Dec 2024 19:45:37 +0530
Subject: [PATCH 02/22] Update ImplicitBoolConversionCheck.h

Added CheckConversionToBool and CheckConversionFromBool Options in the header
---
 .../clang-tidy/readability/ImplicitBoolConversionCheck.h| 2 ++
 1 file changed, 2 insertions(+)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
index 5947f7316e67cc..b0c3c2943e649c 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
@@ -37,6 +37,8 @@ class ImplicitBoolConversionCheck : public ClangTidyCheck {
   const bool AllowIntegerConditions;
   const bool AllowPointerConditions;
   const bool UseUpperCaseLiteralSuffix;
+  const bool CheckConversionsToBool;
+  const bool CheckConversionsFromBool;
 };
 
 } // namespace clang::tidy::readability

>From 0d6fae8b08a4a365c9295ac8a96de2aba9974c98 Mon Sep 17 00:00:00 2001
From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com>
Date: Mon, 16 Dec 2024 19:48:48 +0530
Subject: [PATCH 03/22] Create implicit-bool-conversion-check.cpp

Added new test to check the new options added in the 
ImplicitBoolConversionCheck.cpp
---
 .../implicit-bool-conversion-check.cpp| 92 +++
 1 file changed, 92 insertions(+)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp
new file mode 100644
index 00..506769d5a57322
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers

[libcxx] [libcxxabi] [libunwind] [llvm] [runtimes] Probe for -nostdlib++ and -nostdinc++ with the C compiler (PR #108357)

2024-12-18 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

Ok, so with https://github.com/llvm/llvm-project/pull/120370 landed, I guess we 
could consider trying to reland this.

By doing that, we would however break doing msan+libcxx builds unless using the 
very latest Clang (while libcxx in general supports building with the last two 
stable releases of Clang). Do you think this is an issue, or are we ok with 
implicitly requiring the very latest for this particular configuration?

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


[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)

2024-12-18 Thread via cfe-commits


@@ -0,0 +1,86 @@
+// RUN: %check_clang_tidy %s readability-implicit-bool-conversion %t
+
+// RUN: %check_clang_tidy %s readability-implicit-bool-conversion %t \
+// RUN: -- -config='{CheckOptions: [{key: 
readability-implicit-bool-conversion.CheckConversionsToBool, value: false}, 
{key: readability-implicit-bool-conversion.CheckConversionsFromBool, value: 
true}]}'

4m4n-x-B4w4ne wrote:

I have done this . Can you please review it?

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


[clang] [llvm] [AMDGPU][True16][MC] true16 for v_alignbyte_b32 (PR #119750)

2024-12-18 Thread Brox Chen via cfe-commits

https://github.com/broxigarchen updated 
https://github.com/llvm/llvm-project/pull/119750

>From dc1cc19d8d3cb2c41ca05a131f67bb576effb614 Mon Sep 17 00:00:00 2001
From: guochen2 
Date: Thu, 12 Dec 2024 13:33:14 -0500
Subject: [PATCH 1/2] True16 for v_alignbyte_b32 in MC

---
 clang/lib/CodeGen/CGBuiltin.cpp   |  8 
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |  2 +-
 llvm/lib/Target/AMDGPU/VOP3Instructions.td|  8 +++-
 llvm/test/MC/AMDGPU/gfx11_asm_vop3.s  | 11 +++--
 llvm/test/MC/AMDGPU/gfx11_asm_vop3_dpp16.s| 42 +--
 llvm/test/MC/AMDGPU/gfx11_asm_vop3_dpp8.s | 17 ++--
 llvm/test/MC/AMDGPU/gfx12_asm_vop3.s  |  3 ++
 llvm/test/MC/AMDGPU/gfx12_asm_vop3_dpp16.s|  3 ++
 llvm/test/MC/AMDGPU/gfx12_asm_vop3_dpp8.s |  3 ++
 .../Disassembler/AMDGPU/gfx11_dasm_vop3.txt   | 16 ++-
 .../AMDGPU/gfx11_dasm_vop3_dpp16.txt  | 31 +++---
 .../AMDGPU/gfx11_dasm_vop3_dpp8.txt   | 16 ++-
 .../Disassembler/AMDGPU/gfx12_dasm_vop3.txt   | 16 ++-
 .../AMDGPU/gfx12_dasm_vop3_dpp16.txt  | 36 +---
 .../AMDGPU/gfx12_dasm_vop3_dpp8.txt   | 21 --
 15 files changed, 190 insertions(+), 43 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c2e983eebebc10..2c359f67680e3f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19567,6 +19567,14 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   llvm::AtomicOrdering AO = llvm::AtomicOrdering::SequentiallyConsistent;
   llvm::SyncScope::ID SSID;
   switch (BuiltinID) {
+  case AMDGPU::BI__builtin_amdgcn_alignbyte: {
+llvm::Value *Src0 = EmitScalarExpr(E->getArg(0));
+llvm::Value *Src1 = EmitScalarExpr(E->getArg(1));
+llvm::Value *Src2 = EmitScalarExpr(E->getArg(2));
+llvm::Function *F =
+CGM.getIntrinsic(Intrinsic::amdgcn_alignbyte, Src2->getType());
+return Builder.CreateCall(F, {Src0, Src1, Src2});
+  }
   case AMDGPU::BI__builtin_amdgcn_div_scale:
   case AMDGPU::BI__builtin_amdgcn_div_scalef: {
 // Translate from the intrinsics's struct return to the builtin's out
diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td 
b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index 92418b9104ad14..a3f2d3df3f5276 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -2354,7 +2354,7 @@ def int_amdgcn_writelane :
 >;
 
 def int_amdgcn_alignbyte : ClangBuiltin<"__builtin_amdgcn_alignbyte">,
-  DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
+  DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, 
llvm_anyint_ty],
   [IntrNoMem, IntrSpeculatable]
 >;
 
diff --git a/llvm/lib/Target/AMDGPU/VOP3Instructions.td 
b/llvm/lib/Target/AMDGPU/VOP3Instructions.td
index 8a9f8aa3d16d3a..804a15c94d4728 100644
--- a/llvm/lib/Target/AMDGPU/VOP3Instructions.td
+++ b/llvm/lib/Target/AMDGPU/VOP3Instructions.td
@@ -212,7 +212,11 @@ defm V_BFE_U32 : VOP3Inst <"v_bfe_u32", 
VOP3_Profile, AMDGP
 defm V_BFE_I32 : VOP3Inst <"v_bfe_i32", VOP3_Profile, 
AMDGPUbfe_i32>;
 defm V_BFI_B32 : VOP3Inst <"v_bfi_b32", VOP3_Profile, 
AMDGPUbfi>;
 defm V_ALIGNBIT_B32 : VOP3Inst <"v_alignbit_b32", 
VOP3_Profile, fshr>;
-defm V_ALIGNBYTE_B32 : VOP3Inst <"v_alignbyte_b32", 
VOP3_Profile, int_amdgcn_alignbyte>;
+defm V_ALIGNBYTE_B32 : VOP3Inst_t16_with_profiles <"v_alignbyte_b32",
+   
VOP3_Profile,
+   
VOP3_Profile_True16,
+   
VOP3_Profile_Fake16,
+   int_amdgcn_alignbyte>;
 
 // XXX - No FPException seems suspect but manual doesn't say it does
 let mayRaiseFPException = 0 in {
@@ -1676,7 +1680,7 @@ defm V_FMA_F32 : 
VOP3_Realtriple_gfx11_gfx12<0x213>;
 defm V_FMA_F64 : VOP3_Real_Base_gfx11_gfx12<0x214>;
 defm V_LERP_U8 : VOP3_Realtriple_gfx11_gfx12<0x215>;
 defm V_ALIGNBIT_B32: VOP3_Realtriple_gfx11_gfx12<0x216>;
-defm V_ALIGNBYTE_B32   : VOP3_Realtriple_gfx11_gfx12<0x217>;
+defm V_ALIGNBYTE_B32   : VOP3_Realtriple_t16_and_fake16_gfx11_gfx12<0x217, 
"v_alignbyte_b32">;
 defm V_MULLIT_F32  : VOP3_Realtriple_gfx11_gfx12<0x218>;
 defm V_MIN3_F32: VOP3_Realtriple_gfx11<0x219>;
 defm V_MIN3_I32: VOP3_Realtriple_gfx11_gfx12<0x21a>;
diff --git a/llvm/test/MC/AMDGPU/gfx11_asm_vop3.s 
b/llvm/test/MC/AMDGPU/gfx11_asm_vop3.s
index b649bab532f262..94cd631590ae97 100644
--- a/llvm/test/MC/AMDGPU/gfx11_asm_vop3.s
+++ b/llvm/test/MC/AMDGPU/gfx11_asm_vop3.s
@@ -461,11 +461,11 @@ v_alignbyte_b32 v5, s1, v255, s3
 v_alignbyte_b32 v5, s105, s105, s105
 // GFX11: v_alignbyte_b32 v5, s105, s105, s105; encoding: 
[0x05,0x00,0x17,0xd6,0x69,0xd2,0xa4,0x01]
 
-v_alignbyte_b32 v5, vcc_lo, ttmp15, v3
-// GFX11: v_alignbyte_b32 v5, vc

[clang] [ubsan] Add -fsanitize-nonmerged-handlers (and -fno-sanitize-nonmerged-handlers) (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits

https://github.com/thurstond updated 
https://github.com/llvm/llvm-project/pull/120464

>From 2c0da9aa6f58900387fa91cdc6bcb41e0235d94c Mon Sep 17 00:00:00 2001
From: Thurston Dang 
Date: Wed, 18 Dec 2024 18:37:11 +
Subject: [PATCH 01/10] [ubsan] Add -fsanitize-nonmerged-handlers (and
 -fno-sanitize-nonmerged-handlers)

'-mllvm -ubsan-unique-traps' (https://github.com/llvm/llvm-project/pull/65972) 
applies to all UBSan
checks. This patch introduces -fsanitize-nonmerged-handlers and
-fno-sanitize-nonmerged-handlers, which allows selectively applying
non-merged handlers to a subset of UBSan checks.

N.B. we use "non-merged handlers" instead of "unique traps", since
https://github.com/llvm/llvm-project/pull/119302 has generalized it to
work for non-trap mode as well (min-rt and regular rt).

This patch does not remove the -ubsan-unique-traps flag; that will
override -f(no-)sanitize-non-merged-handlers.
---
 clang/include/clang/Basic/CodeGenOptions.h |  4 
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Driver/SanitizerArgs.h |  1 +
 clang/lib/CodeGen/CGExpr.cpp   | 26 +-
 clang/lib/CodeGen/CodeGenFunction.h|  2 +-
 clang/lib/Driver/SanitizerArgs.cpp | 24 +++-
 clang/lib/Frontend/CompilerInvocation.cpp  |  6 +
 7 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 2dcf98b465661e..9b97adce42cc2a 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -380,6 +380,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Set of sanitizer checks that trap rather than diagnose.
   SanitizerSet SanitizeTrap;
 
+  /// Set of sanitizer checks that have non-merged handlers (better
+  /// debuggability at the expense of code size).
+  SanitizerSet SanitizeNonMergedHandlers;
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7b544d2534d469..1a09f08890edad 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2548,6 +2548,10 @@ def fsanitize_trap_EQ : CommaJoined<["-"], 
"fsanitize-trap=">, Group;
+def fsanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fsanitize-nonmerged-handlers=">, Group,
+HelpText<"Enable non-merged handlers for specified 
sanitizers">;
+def fno_sanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fno-sanitize-nonmerged-handlers=">, Group,
+HelpText<"Disable non-merged handlers for specified 
sanitizers">;
 def fsanitize_trap : Flag<["-"], "fsanitize-trap">, Group,
  Alias, AliasArgs<["all"]>,
  HelpText<"Enable trapping for all sanitizers">;
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 4f08ea2b260179..28cfe72d6a34bd 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -25,6 +25,7 @@ class SanitizerArgs {
   SanitizerSet Sanitizers;
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
+  SanitizerSet NonMergedHandlers;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 79955f55714164..9c4dfaa393966b 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3546,7 +3546,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
  ArrayRef FnArgs,
  SanitizerHandler CheckHandler,
  CheckRecoverableKind RecoverKind, bool 
IsFatal,
- llvm::BasicBlock *ContBB) {
+ llvm::BasicBlock *ContBB, bool NoMerge) {
   assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
   std::optional DL;
   if (!CGF.Builder.getCurrentDebugLocation()) {
@@ -3581,7 +3581,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
llvm::AttributeList::FunctionIndex, B),
   /*Local=*/true);
   llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs);
-  bool NoMerge =
+  NoMerge = NoMerge ||
   ClSanitizeDebugDeoptimization ||
   !CGF.CGM.getCodeGenOpts().OptimizationLevel ||
   (CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
@@ -3608,6 +3608,7 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *FatalCond = nullptr;
   llvm::Value *RecoverableCond = nullptr;
   llvm::Value *TrapCond = nullptr;
+  bool NoMerge = false;
   for (int i = 0, n = Checked.size(); i < n; ++i) {
 llvm::Value *Check = Checked[i].first;
 // -fsanitize-trap= overrides -fsanitize-recover=.
@@ -3618,6 +3619,9 @@ void CodeGenFun

[clang] [cindex] Add python binding for clang_Cursor_isAnonymousRecordDecl (PR #120483)

2024-12-18 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic created 
https://github.com/llvm/llvm-project/pull/120483

None

>From 16e84acd0e86bf2653d4b3fa132bcf661a34e62f Mon Sep 17 00:00:00 2001
From: Eli Friedman 
Date: Wed, 18 Dec 2024 13:55:40 -0800
Subject: [PATCH] [cindex] Add python binding for
 clang_Cursor_isAnonymousRecordDecl

---
 clang/bindings/python/clang/cindex.py | 21 ---
 .../bindings/python/tests/cindex/test_type.py |  3 +++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index f8a20a1e224724..b6e0d71c1ae1b9 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -2125,12 +2125,26 @@ def get_field_offsetof(self):
 
 def is_anonymous(self):
 """
-Check if the record is anonymous.
+Check whether this is a record type without a name, or a field where
+the type is a record type without a name.
+
+Use is_anonymous_record_decl to check whether a record is an
+"anonymous union" as defined in the C/C++ standard.
 """
 if self.kind == CursorKind.FIELD_DECL:
 return self.type.get_declaration().is_anonymous()
 return conf.lib.clang_Cursor_isAnonymous(self)  # type: ignore 
[no-any-return]
 
+def is_anonymous_record_decl(self):
+"""
+Check if the record is an anonymous union as defined in the C/C++ 
standard
+(or an "anonymous struct", the corresponding non-standard extension for
+structs).
+"""
+if self.kind == CursorKind.FIELD_DECL:
+return self.type.get_declaration().is_anonymous_record_decl()
+return conf.lib.clang_Cursor_isAnonymousRecordDecl(self)  # type: 
ignore [no-any-return]
+
 def is_bitfield(self):
 """
 Check if the field is a bitfield.
@@ -3902,12 +3916,13 @@ def write_main_file_to_stdout(self):
 ("clang_Cursor_getTemplateArgumentType", [Cursor, c_uint], Type),
 ("clang_Cursor_getTemplateArgumentValue", [Cursor, c_uint], c_longlong),
 ("clang_Cursor_getTemplateArgumentUnsignedValue", [Cursor, c_uint], 
c_ulonglong),
-("clang_Cursor_isAnonymous", [Cursor], bool),
-("clang_Cursor_isBitField", [Cursor], bool),
 ("clang_Cursor_getBinaryOpcode", [Cursor], c_int),
 ("clang_Cursor_getBriefCommentText", [Cursor], _CXString),
 ("clang_Cursor_getRawCommentText", [Cursor], _CXString),
 ("clang_Cursor_getOffsetOfField", [Cursor], c_longlong),
+("clang_Cursor_isAnonymous", [Cursor], bool),
+("clang_Cursor_isAnonymousRecordDecl", [Cursor], bool),
+("clang_Cursor_isBitField", [Cursor], bool),
 ("clang_Location_isInSystemHeader", [SourceLocation], bool),
 ("clang_Type_getAlignOf", [Type], c_longlong),
 ("clang_Type_getClassType", [Type], Type),
diff --git a/clang/bindings/python/tests/cindex/test_type.py 
b/clang/bindings/python/tests/cindex/test_type.py
index ce05fdb1a1ebc0..e1d8c2aad1c3a4 100644
--- a/clang/bindings/python/tests/cindex/test_type.py
+++ b/clang/bindings/python/tests/cindex/test_type.py
@@ -463,8 +463,11 @@ def test_offset(self):
 self.assertNotEqual(children[0].spelling, "typeanon")
 self.assertEqual(children[1].spelling, "typeanon")
 self.assertEqual(fields[0].kind, CursorKind.FIELD_DECL)
+self.assertTrue(fields[0].is_anonymous())
+self.assertFalse(fields[0].is_anonymous_record_decl())
 self.assertEqual(fields[1].kind, CursorKind.FIELD_DECL)
 self.assertTrue(fields[1].is_anonymous())
+self.assertTrue(fields[1].is_anonymous_record_decl())
 self.assertEqual(teststruct.type.get_offset("typeanon"), f1)
 self.assertEqual(teststruct.type.get_offset("bariton"), bariton)
 self.assertEqual(teststruct.type.get_offset("foo"), foo)

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


[clang] [ubsan] Add -fsanitize-nonmerged-handlers (and -fno-sanitize-nonmerged-handlers) (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits


@@ -2548,6 +2548,14 @@ def fsanitize_trap_EQ : CommaJoined<["-"], 
"fsanitize-trap=">, Group;
+def fsanitize_nonmerged_handlers_EQ
+: CommaJoined<["-"], "fsanitize-nonmerged-handlers=">,

thurstond wrote:

Done

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


[clang] [cindex] Add python binding for clang_Cursor_isAnonymousRecordDecl (PR #120483)

2024-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Eli Friedman (efriedma-quic)


Changes



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


2 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+18-3) 
- (modified) clang/bindings/python/tests/cindex/test_type.py (+3) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index f8a20a1e224724..b6e0d71c1ae1b9 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -2125,12 +2125,26 @@ def get_field_offsetof(self):
 
 def is_anonymous(self):
 """
-Check if the record is anonymous.
+Check whether this is a record type without a name, or a field where
+the type is a record type without a name.
+
+Use is_anonymous_record_decl to check whether a record is an
+"anonymous union" as defined in the C/C++ standard.
 """
 if self.kind == CursorKind.FIELD_DECL:
 return self.type.get_declaration().is_anonymous()
 return conf.lib.clang_Cursor_isAnonymous(self)  # type: ignore 
[no-any-return]
 
+def is_anonymous_record_decl(self):
+"""
+Check if the record is an anonymous union as defined in the C/C++ 
standard
+(or an "anonymous struct", the corresponding non-standard extension for
+structs).
+"""
+if self.kind == CursorKind.FIELD_DECL:
+return self.type.get_declaration().is_anonymous_record_decl()
+return conf.lib.clang_Cursor_isAnonymousRecordDecl(self)  # type: 
ignore [no-any-return]
+
 def is_bitfield(self):
 """
 Check if the field is a bitfield.
@@ -3902,12 +3916,13 @@ def write_main_file_to_stdout(self):
 ("clang_Cursor_getTemplateArgumentType", [Cursor, c_uint], Type),
 ("clang_Cursor_getTemplateArgumentValue", [Cursor, c_uint], c_longlong),
 ("clang_Cursor_getTemplateArgumentUnsignedValue", [Cursor, c_uint], 
c_ulonglong),
-("clang_Cursor_isAnonymous", [Cursor], bool),
-("clang_Cursor_isBitField", [Cursor], bool),
 ("clang_Cursor_getBinaryOpcode", [Cursor], c_int),
 ("clang_Cursor_getBriefCommentText", [Cursor], _CXString),
 ("clang_Cursor_getRawCommentText", [Cursor], _CXString),
 ("clang_Cursor_getOffsetOfField", [Cursor], c_longlong),
+("clang_Cursor_isAnonymous", [Cursor], bool),
+("clang_Cursor_isAnonymousRecordDecl", [Cursor], bool),
+("clang_Cursor_isBitField", [Cursor], bool),
 ("clang_Location_isInSystemHeader", [SourceLocation], bool),
 ("clang_Type_getAlignOf", [Type], c_longlong),
 ("clang_Type_getClassType", [Type], Type),
diff --git a/clang/bindings/python/tests/cindex/test_type.py 
b/clang/bindings/python/tests/cindex/test_type.py
index ce05fdb1a1ebc0..e1d8c2aad1c3a4 100644
--- a/clang/bindings/python/tests/cindex/test_type.py
+++ b/clang/bindings/python/tests/cindex/test_type.py
@@ -463,8 +463,11 @@ def test_offset(self):
 self.assertNotEqual(children[0].spelling, "typeanon")
 self.assertEqual(children[1].spelling, "typeanon")
 self.assertEqual(fields[0].kind, CursorKind.FIELD_DECL)
+self.assertTrue(fields[0].is_anonymous())
+self.assertFalse(fields[0].is_anonymous_record_decl())
 self.assertEqual(fields[1].kind, CursorKind.FIELD_DECL)
 self.assertTrue(fields[1].is_anonymous())
+self.assertTrue(fields[1].is_anonymous_record_decl())
 self.assertEqual(teststruct.type.get_offset("typeanon"), f1)
 self.assertEqual(teststruct.type.get_offset("bariton"), bariton)
 self.assertEqual(teststruct.type.get_offset("foo"), foo)

``




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


[clang] [ubsan] Add -fsanitize-nonmerged-handlers (and -fno-sanitize-nonmerged-handlers) (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits


@@ -2548,6 +2548,14 @@ def fsanitize_trap_EQ : CommaJoined<["-"], 
"fsanitize-trap=">, Group;
+def fsanitize_nonmerged_handlers_EQ
+: CommaJoined<["-"], "fsanitize-nonmerged-handlers=">,
+  Group,
+  HelpText<"Enable non-merged handlers for specified sanitizers">;

thurstond wrote:

Done

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


[clang] [Sema] Fix tautological bounds check warning with -fwrapv (PR #120480)

2024-12-18 Thread Nikita Popov via cfe-commits

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

LGTM

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


[clang] [llvm] [AMDGPU][True16][MC] true16 for v_alignbyte_b32 (PR #119750)

2024-12-18 Thread Brox Chen via cfe-commits

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


[clang] [llvm] [AMDGPU][True16][MC] true16 for v_alignbyte_b32 (PR #119750)

2024-12-18 Thread Brox Chen via cfe-commits

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


[clang] [libclang] Add API to query more information about base classes. (PR #120300)

2024-12-18 Thread Eli Friedman via cfe-commits

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


[clang] [llvm] [AMDGPU][True16][MC] true16 for v_alignbyte_b32 (PR #119750)

2024-12-18 Thread Brox Chen via cfe-commits

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


[clang] [ubsan] Add -fsanitize-merge (and -fno-sanitize-merge) (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits

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


[clang] [ubsan] Add -fsanitize-merge (and -fno-sanitize-merge) (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits

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


[clang] [ubsan] Add -fsanitize-merge (and -fno-sanitize-merge) (PR #120464)

2024-12-18 Thread Vitaly Buka via cfe-commits


@@ -68,6 +68,8 @@ static const SanitizerMask TrappingSupported =
 SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
 SanitizerKind::LocalBounds | SanitizerKind::CFI |
 SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast;
+static const SanitizerMask MergeDefault = SanitizerKind::Undefined;
+static const SanitizerMask MergeSupported = SanitizerKind::Undefined;

vitalybuka wrote:

Having that this is advisory feature, maybe we don't need to be strict on 
support checking,
so no need to MergeSupported

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


[clang] [APINotes] Avoid assertion failure with expensive checks (PR #120487)

2024-12-18 Thread Björn Pettersson via cfe-commits

https://github.com/bjope created 
https://github.com/llvm/llvm-project/pull/120487

Found assertion failures when using EXPENSIVE_CHECKS and running lit tests for 
APINotes:
   Assertion `left.first != right.first && "two entries for the same version"' 
failed.

It seems like std::is_sorted is verifying that the comparison function is 
reflective (comp(a,a)=false) when using expensive checks. So we would get 
callbacks to the lambda used for comparison, even for vectors with a single 
element in APINotesReader::VersionedInfo::VersionedInfo, with "left" and 
"right" being the same object. Therefore the assert checking that we never 
found equal values would fail.

Fix makes sure that we skip the check for equal values when "left" and "right" 
is the same object.

From b3d95e794735c3f8242643c3d187c24a1ad51421 Mon Sep 17 00:00:00 2001
From: Bjorn Pettersson 
Date: Wed, 18 Dec 2024 19:32:34 +0100
Subject: [PATCH] [APINotes] Avoid "two entries for the same version" failure
 with expensive checks

Found assertion failures when using EXPENSIVE_CHECKS and running
lit tests for APINotes. It seems like std::is_sorted is verifying
that the comparison function is reflective (comp(a,a)=false) when
using expensive checks. So we would get callbacks to the lambda
used for comparison, even for vectors with a single element
in APINotesReader::VersionedInfo::VersionedInfo, with "left"
and "right" being the same object. Therefore the assert checking
that we never found equal values would fail.

Fix makes sure that we skip the check for equal values when
"left" and "right" is the same object.
---
 clang/lib/APINotes/APINotesReader.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index fa06dffdd14b03..646eabd2a5ecd3 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -2045,7 +2045,12 @@ APINotesReader::VersionedInfo::VersionedInfo(
   Results.begin(), Results.end(),
   [](const std::pair &left,
  const std::pair &right) -> bool {
-assert(left.first != right.first && "two entries for the same 
version");
+// The comparison function should be reflective, and with expensive
+// checks we can get callbacks basically checking that lambda(a,a) is
+// false. We could still check that we do not find equal elements when
+// left!=right.
+assert((&left == &right || left.first != right.first) &&
+   "two entries for the same version");
 return left.first < right.first;
   }));
 

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


[clang] [libclang/python] Add python binding for clang_Cursor_isAnonymousRecordDecl (PR #120483)

2024-12-18 Thread Eli Friedman via cfe-commits

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


[clang] [ubsan] Add -fsanitize-merge (and -fno-sanitize-merge) (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits

https://github.com/thurstond updated 
https://github.com/llvm/llvm-project/pull/120464

>From 2c0da9aa6f58900387fa91cdc6bcb41e0235d94c Mon Sep 17 00:00:00 2001
From: Thurston Dang 
Date: Wed, 18 Dec 2024 18:37:11 +
Subject: [PATCH 01/11] [ubsan] Add -fsanitize-nonmerged-handlers (and
 -fno-sanitize-nonmerged-handlers)

'-mllvm -ubsan-unique-traps' (https://github.com/llvm/llvm-project/pull/65972) 
applies to all UBSan
checks. This patch introduces -fsanitize-nonmerged-handlers and
-fno-sanitize-nonmerged-handlers, which allows selectively applying
non-merged handlers to a subset of UBSan checks.

N.B. we use "non-merged handlers" instead of "unique traps", since
https://github.com/llvm/llvm-project/pull/119302 has generalized it to
work for non-trap mode as well (min-rt and regular rt).

This patch does not remove the -ubsan-unique-traps flag; that will
override -f(no-)sanitize-non-merged-handlers.
---
 clang/include/clang/Basic/CodeGenOptions.h |  4 
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Driver/SanitizerArgs.h |  1 +
 clang/lib/CodeGen/CGExpr.cpp   | 26 +-
 clang/lib/CodeGen/CodeGenFunction.h|  2 +-
 clang/lib/Driver/SanitizerArgs.cpp | 24 +++-
 clang/lib/Frontend/CompilerInvocation.cpp  |  6 +
 7 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 2dcf98b465661e..9b97adce42cc2a 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -380,6 +380,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Set of sanitizer checks that trap rather than diagnose.
   SanitizerSet SanitizeTrap;
 
+  /// Set of sanitizer checks that have non-merged handlers (better
+  /// debuggability at the expense of code size).
+  SanitizerSet SanitizeNonMergedHandlers;
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7b544d2534d469..1a09f08890edad 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2548,6 +2548,10 @@ def fsanitize_trap_EQ : CommaJoined<["-"], 
"fsanitize-trap=">, Group;
+def fsanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fsanitize-nonmerged-handlers=">, Group,
+HelpText<"Enable non-merged handlers for specified 
sanitizers">;
+def fno_sanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fno-sanitize-nonmerged-handlers=">, Group,
+HelpText<"Disable non-merged handlers for specified 
sanitizers">;
 def fsanitize_trap : Flag<["-"], "fsanitize-trap">, Group,
  Alias, AliasArgs<["all"]>,
  HelpText<"Enable trapping for all sanitizers">;
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 4f08ea2b260179..28cfe72d6a34bd 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -25,6 +25,7 @@ class SanitizerArgs {
   SanitizerSet Sanitizers;
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
+  SanitizerSet NonMergedHandlers;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 79955f55714164..9c4dfaa393966b 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3546,7 +3546,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
  ArrayRef FnArgs,
  SanitizerHandler CheckHandler,
  CheckRecoverableKind RecoverKind, bool 
IsFatal,
- llvm::BasicBlock *ContBB) {
+ llvm::BasicBlock *ContBB, bool NoMerge) {
   assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
   std::optional DL;
   if (!CGF.Builder.getCurrentDebugLocation()) {
@@ -3581,7 +3581,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
llvm::AttributeList::FunctionIndex, B),
   /*Local=*/true);
   llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs);
-  bool NoMerge =
+  NoMerge = NoMerge ||
   ClSanitizeDebugDeoptimization ||
   !CGF.CGM.getCodeGenOpts().OptimizationLevel ||
   (CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
@@ -3608,6 +3608,7 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *FatalCond = nullptr;
   llvm::Value *RecoverableCond = nullptr;
   llvm::Value *TrapCond = nullptr;
+  bool NoMerge = false;
   for (int i = 0, n = Checked.size(); i < n; ++i) {
 llvm::Value *Check = Checked[i].first;
 // -fsanitize-trap= overrides -fsanitize-recover=.
@@ -3618,6 +3619,9 @@ void CodeGenFun

[clang] [llvm] [AMDGPU][True16][MC] true16 for v_alignbyte_b32 (PR #119750)

2024-12-18 Thread Brox Chen via cfe-commits

https://github.com/broxigarchen updated 
https://github.com/llvm/llvm-project/pull/119750

>From 826cc5ccb8c4fb0d4edd53823725ba497ce86949 Mon Sep 17 00:00:00 2001
From: guochen2 
Date: Thu, 12 Dec 2024 13:33:14 -0500
Subject: [PATCH 1/2] True16 for v_alignbyte_b32 in MC

---
 clang/lib/CodeGen/CGBuiltin.cpp   |  8 
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |  2 +-
 llvm/lib/Target/AMDGPU/VOP3Instructions.td|  8 +++-
 llvm/test/MC/AMDGPU/gfx11_asm_vop3.s  | 11 +++--
 llvm/test/MC/AMDGPU/gfx11_asm_vop3_dpp16.s| 42 +--
 llvm/test/MC/AMDGPU/gfx11_asm_vop3_dpp8.s | 17 ++--
 llvm/test/MC/AMDGPU/gfx12_asm_vop3.s  |  3 ++
 llvm/test/MC/AMDGPU/gfx12_asm_vop3_dpp16.s|  3 ++
 llvm/test/MC/AMDGPU/gfx12_asm_vop3_dpp8.s |  3 ++
 .../Disassembler/AMDGPU/gfx11_dasm_vop3.txt   | 16 ++-
 .../AMDGPU/gfx11_dasm_vop3_dpp16.txt  | 31 +++---
 .../AMDGPU/gfx11_dasm_vop3_dpp8.txt   | 16 ++-
 .../Disassembler/AMDGPU/gfx12_dasm_vop3.txt   | 16 ++-
 .../AMDGPU/gfx12_dasm_vop3_dpp16.txt  | 36 +---
 .../AMDGPU/gfx12_dasm_vop3_dpp8.txt   | 21 --
 15 files changed, 190 insertions(+), 43 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 4d4b7428abd505..1b6437b44e07be 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19593,6 +19593,14 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   llvm::AtomicOrdering AO = llvm::AtomicOrdering::SequentiallyConsistent;
   llvm::SyncScope::ID SSID;
   switch (BuiltinID) {
+  case AMDGPU::BI__builtin_amdgcn_alignbyte: {
+llvm::Value *Src0 = EmitScalarExpr(E->getArg(0));
+llvm::Value *Src1 = EmitScalarExpr(E->getArg(1));
+llvm::Value *Src2 = EmitScalarExpr(E->getArg(2));
+llvm::Function *F =
+CGM.getIntrinsic(Intrinsic::amdgcn_alignbyte, Src2->getType());
+return Builder.CreateCall(F, {Src0, Src1, Src2});
+  }
   case AMDGPU::BI__builtin_amdgcn_div_scale:
   case AMDGPU::BI__builtin_amdgcn_div_scalef: {
 // Translate from the intrinsics's struct return to the builtin's out
diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td 
b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index 92418b9104ad14..a3f2d3df3f5276 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -2354,7 +2354,7 @@ def int_amdgcn_writelane :
 >;
 
 def int_amdgcn_alignbyte : ClangBuiltin<"__builtin_amdgcn_alignbyte">,
-  DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
+  DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, 
llvm_anyint_ty],
   [IntrNoMem, IntrSpeculatable]
 >;
 
diff --git a/llvm/lib/Target/AMDGPU/VOP3Instructions.td 
b/llvm/lib/Target/AMDGPU/VOP3Instructions.td
index 34f90b33bc4ba4..ba5da9000879ae 100644
--- a/llvm/lib/Target/AMDGPU/VOP3Instructions.td
+++ b/llvm/lib/Target/AMDGPU/VOP3Instructions.td
@@ -212,7 +212,11 @@ defm V_BFE_U32 : VOP3Inst <"v_bfe_u32", 
VOP3_Profile, AMDGP
 defm V_BFE_I32 : VOP3Inst <"v_bfe_i32", VOP3_Profile, 
AMDGPUbfe_i32>;
 defm V_BFI_B32 : VOP3Inst <"v_bfi_b32", VOP3_Profile, 
AMDGPUbfi>;
 defm V_ALIGNBIT_B32 : VOP3Inst <"v_alignbit_b32", 
VOP3_Profile, fshr>;
-defm V_ALIGNBYTE_B32 : VOP3Inst <"v_alignbyte_b32", 
VOP3_Profile, int_amdgcn_alignbyte>;
+defm V_ALIGNBYTE_B32 : VOP3Inst_t16_with_profiles <"v_alignbyte_b32",
+   
VOP3_Profile,
+   
VOP3_Profile_True16,
+   
VOP3_Profile_Fake16,
+   int_amdgcn_alignbyte>;
 
 // XXX - No FPException seems suspect but manual doesn't say it does
 let mayRaiseFPException = 0 in {
@@ -1679,7 +1683,7 @@ defm V_FMA_F32 : 
VOP3_Realtriple_gfx11_gfx12<0x213>;
 defm V_FMA_F64 : VOP3_Real_Base_gfx11_gfx12<0x214>;
 defm V_LERP_U8 : VOP3_Realtriple_gfx11_gfx12<0x215>;
 defm V_ALIGNBIT_B32: VOP3_Realtriple_gfx11_gfx12<0x216>;
-defm V_ALIGNBYTE_B32   : VOP3_Realtriple_gfx11_gfx12<0x217>;
+defm V_ALIGNBYTE_B32   : VOP3_Realtriple_t16_and_fake16_gfx11_gfx12<0x217, 
"v_alignbyte_b32">;
 defm V_MULLIT_F32  : VOP3_Realtriple_gfx11_gfx12<0x218>;
 defm V_MIN3_F32: VOP3_Realtriple_gfx11<0x219>;
 defm V_MIN3_I32: VOP3_Realtriple_gfx11_gfx12<0x21a>;
diff --git a/llvm/test/MC/AMDGPU/gfx11_asm_vop3.s 
b/llvm/test/MC/AMDGPU/gfx11_asm_vop3.s
index d46f010a2dafbd..1dbdb9ed5b6fda 100644
--- a/llvm/test/MC/AMDGPU/gfx11_asm_vop3.s
+++ b/llvm/test/MC/AMDGPU/gfx11_asm_vop3.s
@@ -461,11 +461,11 @@ v_alignbyte_b32 v5, s1, v255, s3
 v_alignbyte_b32 v5, s105, s105, s105
 // GFX11: v_alignbyte_b32 v5, s105, s105, s105; encoding: 
[0x05,0x00,0x17,0xd6,0x69,0xd2,0xa4,0x01]
 
-v_alignbyte_b32 v5, vcc_lo, ttmp15, v3
-// GFX11: v_alignbyte_b32 v5, vc

[clang] [APINotes] Avoid assertion failure with expensive checks (PR #120487)

2024-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Björn Pettersson (bjope)


Changes

Found assertion failures when using EXPENSIVE_CHECKS and running lit tests for 
APINotes:
   Assertion `left.first != right.first && "two entries for the same 
version"' failed.

It seems like std::is_sorted is verifying that the comparison function is 
reflective (comp(a,a)=false) when using expensive checks. So we would get 
callbacks to the lambda used for comparison, even for vectors with a single 
element in APINotesReader::VersionedInfo::VersionedInfo, with "left" 
and "right" being the same object. Therefore the assert checking that we never 
found equal values would fail.

Fix makes sure that we skip the check for equal values when "left" and "right" 
is the same object.

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


1 Files Affected:

- (modified) clang/lib/APINotes/APINotesReader.cpp (+6-1) 


``diff
diff --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index fa06dffdd14b03..646eabd2a5ecd3 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -2045,7 +2045,12 @@ APINotesReader::VersionedInfo::VersionedInfo(
   Results.begin(), Results.end(),
   [](const std::pair &left,
  const std::pair &right) -> bool {
-assert(left.first != right.first && "two entries for the same 
version");
+// The comparison function should be reflective, and with expensive
+// checks we can get callbacks basically checking that lambda(a,a) is
+// false. We could still check that we do not find equal elements when
+// left!=right.
+assert((&left == &right || left.first != right.first) &&
+   "two entries for the same version");
 return left.first < right.first;
   }));
 

``




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


[clang] [APINotes] Avoid assertion failure with expensive checks (PR #120487)

2024-12-18 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 5ca3794e82bd4d96e5aa32821bed033e40f51814 
b3d95e794735c3f8242643c3d187c24a1ad51421 --extensions cpp -- 
clang/lib/APINotes/APINotesReader.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index 646eabd2a5..e70146467f 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -2041,18 +2041,19 @@ APINotesReader::VersionedInfo::VersionedInfo(
 : Results(std::move(R)) {
 
   assert(!Results.empty());
-  assert(std::is_sorted(
-  Results.begin(), Results.end(),
-  [](const std::pair &left,
- const std::pair &right) -> bool {
-// The comparison function should be reflective, and with expensive
-// checks we can get callbacks basically checking that lambda(a,a) is
-// false. We could still check that we do not find equal elements when
-// left!=right.
-assert((&left == &right || left.first != right.first) &&
-   "two entries for the same version");
-return left.first < right.first;
-  }));
+  assert(
+  std::is_sorted(Results.begin(), Results.end(),
+ [](const std::pair &left,
+const std::pair &right) -> bool 
{
+   // The comparison function should be reflective, and 
with
+   // expensive checks we can get callbacks basically
+   // checking that lambda(a,a) is false. We could still
+   // check that we do not find equal elements when
+   // left!=right.
+   assert((&left == &right || left.first != right.first) &&
+  "two entries for the same version");
+   return left.first < right.first;
+ }));
 
   Selected = std::nullopt;
   for (unsigned i = 0, n = Results.size(); i != n; ++i) {

``




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


[clang] [ubsan] Add -fsanitize-merge (and -fno-sanitize-merge) (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits


@@ -68,6 +68,8 @@ static const SanitizerMask TrappingSupported =
 SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
 SanitizerKind::LocalBounds | SanitizerKind::CFI |
 SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast;
+static const SanitizerMask MergeDefault = SanitizerKind::Undefined;
+static const SanitizerMask MergeSupported = SanitizerKind::Undefined;

thurstond wrote:

Removed

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


[clang] [ubsan] Add -fsanitize-merge (and -fno-sanitize-merge) (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits

https://github.com/thurstond updated 
https://github.com/llvm/llvm-project/pull/120464

>From 2c0da9aa6f58900387fa91cdc6bcb41e0235d94c Mon Sep 17 00:00:00 2001
From: Thurston Dang 
Date: Wed, 18 Dec 2024 18:37:11 +
Subject: [PATCH 01/12] [ubsan] Add -fsanitize-nonmerged-handlers (and
 -fno-sanitize-nonmerged-handlers)

'-mllvm -ubsan-unique-traps' (https://github.com/llvm/llvm-project/pull/65972) 
applies to all UBSan
checks. This patch introduces -fsanitize-nonmerged-handlers and
-fno-sanitize-nonmerged-handlers, which allows selectively applying
non-merged handlers to a subset of UBSan checks.

N.B. we use "non-merged handlers" instead of "unique traps", since
https://github.com/llvm/llvm-project/pull/119302 has generalized it to
work for non-trap mode as well (min-rt and regular rt).

This patch does not remove the -ubsan-unique-traps flag; that will
override -f(no-)sanitize-non-merged-handlers.
---
 clang/include/clang/Basic/CodeGenOptions.h |  4 
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Driver/SanitizerArgs.h |  1 +
 clang/lib/CodeGen/CGExpr.cpp   | 26 +-
 clang/lib/CodeGen/CodeGenFunction.h|  2 +-
 clang/lib/Driver/SanitizerArgs.cpp | 24 +++-
 clang/lib/Frontend/CompilerInvocation.cpp  |  6 +
 7 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 2dcf98b465661e..9b97adce42cc2a 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -380,6 +380,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Set of sanitizer checks that trap rather than diagnose.
   SanitizerSet SanitizeTrap;
 
+  /// Set of sanitizer checks that have non-merged handlers (better
+  /// debuggability at the expense of code size).
+  SanitizerSet SanitizeNonMergedHandlers;
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7b544d2534d469..1a09f08890edad 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2548,6 +2548,10 @@ def fsanitize_trap_EQ : CommaJoined<["-"], 
"fsanitize-trap=">, Group;
+def fsanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fsanitize-nonmerged-handlers=">, Group,
+HelpText<"Enable non-merged handlers for specified 
sanitizers">;
+def fno_sanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fno-sanitize-nonmerged-handlers=">, Group,
+HelpText<"Disable non-merged handlers for specified 
sanitizers">;
 def fsanitize_trap : Flag<["-"], "fsanitize-trap">, Group,
  Alias, AliasArgs<["all"]>,
  HelpText<"Enable trapping for all sanitizers">;
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 4f08ea2b260179..28cfe72d6a34bd 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -25,6 +25,7 @@ class SanitizerArgs {
   SanitizerSet Sanitizers;
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
+  SanitizerSet NonMergedHandlers;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 79955f55714164..9c4dfaa393966b 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3546,7 +3546,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
  ArrayRef FnArgs,
  SanitizerHandler CheckHandler,
  CheckRecoverableKind RecoverKind, bool 
IsFatal,
- llvm::BasicBlock *ContBB) {
+ llvm::BasicBlock *ContBB, bool NoMerge) {
   assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
   std::optional DL;
   if (!CGF.Builder.getCurrentDebugLocation()) {
@@ -3581,7 +3581,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
llvm::AttributeList::FunctionIndex, B),
   /*Local=*/true);
   llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs);
-  bool NoMerge =
+  NoMerge = NoMerge ||
   ClSanitizeDebugDeoptimization ||
   !CGF.CGM.getCodeGenOpts().OptimizationLevel ||
   (CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
@@ -3608,6 +3608,7 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *FatalCond = nullptr;
   llvm::Value *RecoverableCond = nullptr;
   llvm::Value *TrapCond = nullptr;
+  bool NoMerge = false;
   for (int i = 0, n = Checked.size(); i < n; ++i) {
 llvm::Value *Check = Checked[i].first;
 // -fsanitize-trap= overrides -fsanitize-recover=.
@@ -3618,6 +3619,9 @@ void CodeGenFun

[clang] [ubsan] Add -fsanitize-merge (and -fno-sanitize-merge) (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits

https://github.com/thurstond updated 
https://github.com/llvm/llvm-project/pull/120464

>From 2c0da9aa6f58900387fa91cdc6bcb41e0235d94c Mon Sep 17 00:00:00 2001
From: Thurston Dang 
Date: Wed, 18 Dec 2024 18:37:11 +
Subject: [PATCH 01/13] [ubsan] Add -fsanitize-nonmerged-handlers (and
 -fno-sanitize-nonmerged-handlers)

'-mllvm -ubsan-unique-traps' (https://github.com/llvm/llvm-project/pull/65972) 
applies to all UBSan
checks. This patch introduces -fsanitize-nonmerged-handlers and
-fno-sanitize-nonmerged-handlers, which allows selectively applying
non-merged handlers to a subset of UBSan checks.

N.B. we use "non-merged handlers" instead of "unique traps", since
https://github.com/llvm/llvm-project/pull/119302 has generalized it to
work for non-trap mode as well (min-rt and regular rt).

This patch does not remove the -ubsan-unique-traps flag; that will
override -f(no-)sanitize-non-merged-handlers.
---
 clang/include/clang/Basic/CodeGenOptions.h |  4 
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Driver/SanitizerArgs.h |  1 +
 clang/lib/CodeGen/CGExpr.cpp   | 26 +-
 clang/lib/CodeGen/CodeGenFunction.h|  2 +-
 clang/lib/Driver/SanitizerArgs.cpp | 24 +++-
 clang/lib/Frontend/CompilerInvocation.cpp  |  6 +
 7 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 2dcf98b465661e..9b97adce42cc2a 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -380,6 +380,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// Set of sanitizer checks that trap rather than diagnose.
   SanitizerSet SanitizeTrap;
 
+  /// Set of sanitizer checks that have non-merged handlers (better
+  /// debuggability at the expense of code size).
+  SanitizerSet SanitizeNonMergedHandlers;
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7b544d2534d469..1a09f08890edad 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2548,6 +2548,10 @@ def fsanitize_trap_EQ : CommaJoined<["-"], 
"fsanitize-trap=">, Group;
+def fsanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fsanitize-nonmerged-handlers=">, Group,
+HelpText<"Enable non-merged handlers for specified 
sanitizers">;
+def fno_sanitize_nonmerged_handlers_EQ : CommaJoined<["-"], 
"fno-sanitize-nonmerged-handlers=">, Group,
+HelpText<"Disable non-merged handlers for specified 
sanitizers">;
 def fsanitize_trap : Flag<["-"], "fsanitize-trap">, Group,
  Alias, AliasArgs<["all"]>,
  HelpText<"Enable trapping for all sanitizers">;
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 4f08ea2b260179..28cfe72d6a34bd 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -25,6 +25,7 @@ class SanitizerArgs {
   SanitizerSet Sanitizers;
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
+  SanitizerSet NonMergedHandlers;
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 79955f55714164..9c4dfaa393966b 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3546,7 +3546,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
  ArrayRef FnArgs,
  SanitizerHandler CheckHandler,
  CheckRecoverableKind RecoverKind, bool 
IsFatal,
- llvm::BasicBlock *ContBB) {
+ llvm::BasicBlock *ContBB, bool NoMerge) {
   assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
   std::optional DL;
   if (!CGF.Builder.getCurrentDebugLocation()) {
@@ -3581,7 +3581,7 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
llvm::AttributeList::FunctionIndex, B),
   /*Local=*/true);
   llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs);
-  bool NoMerge =
+  NoMerge = NoMerge ||
   ClSanitizeDebugDeoptimization ||
   !CGF.CGM.getCodeGenOpts().OptimizationLevel ||
   (CGF.CurCodeDecl && CGF.CurCodeDecl->hasAttr());
@@ -3608,6 +3608,7 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *FatalCond = nullptr;
   llvm::Value *RecoverableCond = nullptr;
   llvm::Value *TrapCond = nullptr;
+  bool NoMerge = false;
   for (int i = 0, n = Checked.size(); i < n; ++i) {
 llvm::Value *Check = Checked[i].first;
 // -fsanitize-trap= overrides -fsanitize-recover=.
@@ -3618,6 +3619,9 @@ void CodeGenFun

[clang] [clang][ObjectiveC] Fix Parsing Types with the `::` Optional Scope Specifier (PR #119908)

2024-12-18 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu updated 
https://github.com/llvm/llvm-project/pull/119908

>From 63c424414c1814ec9b4c3c5a459bfe1be684586d Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Fri, 13 Dec 2024 09:41:41 -0800
Subject: [PATCH 1/4] Fix parsing :: in method parameter type.

---
 clang/lib/Parse/Parser.cpp  | 8 +++-
 clang/test/Parser/objc-coloncolon.m | 5 +
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Parser/objc-coloncolon.m

diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 36e56a92c3092e..aa78d702553172 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -,8 +,14 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(
 }
   }
 
-  if (SS.isEmpty())
+  if (SS.isEmpty()) {
+if (getLangOpts().ObjC && Tok.is(tok::coloncolon)) {
+  // ObjectiveC does not allow :: as as a scope token.
+  Diag(ConsumeToken(), diag::err_expected_type);
+  return true;
+}
 return false;
+  }
 
   // A C++ scope specifier that isn't followed by a typename.
   AnnotateScopeToken(SS, IsNewScope);
diff --git a/clang/test/Parser/objc-coloncolon.m 
b/clang/test/Parser/objc-coloncolon.m
new file mode 100644
index 00..e8a09898263bb3
--- /dev/null
+++ b/clang/test/Parser/objc-coloncolon.m
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s
+
+@interface A
+- (instancetype)init:(::A *) foo; // expected-error {{expected a type}} 
+@end

>From ec903eb3fcd18ba53af901582060bd61b13cf324 Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Mon, 16 Dec 2024 09:34:52 -0800
Subject: [PATCH 2/4] Fix ObjectiveC++

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

diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index aa78d702553172..8ba6a5dce8a994 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -2223,7 +2223,8 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(
   }
 
   if (SS.isEmpty()) {
-if (getLangOpts().ObjC && Tok.is(tok::coloncolon)) {
+if (getLangOpts().ObjC && !getLangOpts().CPlusPlus &&
+Tok.is(tok::coloncolon)) {
   // ObjectiveC does not allow :: as as a scope token.
   Diag(ConsumeToken(), diag::err_expected_type);
   return true;

>From 66c3b0b874f5a962ff902c43d33fbb22c658780c Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Wed, 18 Dec 2024 09:49:15 -0800
Subject: [PATCH 3/4] Address code review.

---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/test/Parser/objc-coloncolon.m| 12 ++--
 clang/test/Parser/objcxx-coloncolon.mm |  9 +
 3 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/objcxx-coloncolon.mm

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 26fa986810a4b8..d6d3149df07d87 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -675,6 +675,9 @@ Improvements to Clang's diagnostics
   views.push_back(std::string("123")); // warning
 }
 
+- Fixed a bug where Clang hangs on unsupported optional scope specifier ``::`` 
when parsing
+  Objective-C. Clang now emits a diagnostic message instead of hanging.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/test/Parser/objc-coloncolon.m 
b/clang/test/Parser/objc-coloncolon.m
index e8a09898263bb3..68b54ef5229af5 100644
--- a/clang/test/Parser/objc-coloncolon.m
+++ b/clang/test/Parser/objc-coloncolon.m
@@ -1,5 +1,13 @@
-// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x objective-c -fsyntax-only -Wno-objc-root-class -verify %s
+
+int GV = 42;
 
 @interface A
-- (instancetype)init:(::A *) foo; // expected-error {{expected a type}} 
++ (int) getGV;
+- (instancetype)init:(::A *) foo; // expected-error {{expected a type}}
+@end
+
+@implementation A
++ (int) getGV { return ::GV; } // expected-error {{expected a type}}
+- (instancetype)init:(::A *) foo { return self; } // expected-error {{expected 
a type}}
 @end
diff --git a/clang/test/Parser/objcxx-coloncolon.mm 
b/clang/test/Parser/objcxx-coloncolon.mm
new file mode 100644
index 00..864a7df8400c1c
--- /dev/null
+++ b/clang/test/Parser/objcxx-coloncolon.mm
@@ -0,0 +1,9 @@
+// Test to make sure the parser does not get stuck on the optional
+// scope specifier on the type B.
+// RUN: %clang_cc1 -fsyntax-only %s
+
+class B;
+
+@interface A
+- (void) init:(::B *) foo;
+@end

>From 2e0667d1f21f406be8c9ae1f10eb12f60296ddd8 Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Wed, 18 Dec 2024 11:10:16 -0800
Subject: [PATCH 4/4] Modifying the test to include valid Objective-C with

---
 clang/test/Parser/objc-coloncolon.m | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/clang/test/Parser/objc-coloncolon.m 
b/clang/test/Parser/objc-coloncolon.m
index 68b54ef5229af5..04a24fd81ec08f 100644
--- a/clang/test/Parser/objc-coloncolon.m
+++ b/clang/t

[clang] [ubsan] Add -fsanitize-merge (and -fno-sanitize-merge) (PR #120464)

2024-12-18 Thread Thurston Dang via cfe-commits

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


[clang] [APINotes] Avoid assertion failure with expensive checks (PR #120487)

2024-12-18 Thread Saleem Abdulrasool via cfe-commits

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


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


[clang] [APINotes] Avoid assertion failure with expensive checks (PR #120487)

2024-12-18 Thread Björn Pettersson via cfe-commits

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


[clang] 26f5d1e - [APINotes] Avoid assertion failure with expensive checks (#120487)

2024-12-18 Thread via cfe-commits

Author: Björn Pettersson
Date: 2024-12-18T23:36:45+01:00
New Revision: 26f5d1ee9c37e2a6d50898a5bf2d3b9171060ba0

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

LOG: [APINotes] Avoid assertion failure with expensive checks (#120487)

Found assertion failures when using EXPENSIVE_CHECKS and running lit
tests for APINotes:
Assertion `left.first != right.first && "two entries for the same
version"' failed.

It seems like std::is_sorted is verifying that the comparison function
is reflective (comp(a,a)=false) when using expensive checks. So we would
get callbacks to the lambda used for comparison, even for vectors with a
single element in APINotesReader::VersionedInfo::VersionedInfo, with
"left" and "right" being the same object. Therefore the assert checking
that we never found equal values would fail.

Fix makes sure that we skip the check for equal values when "left" and
"right" is the same object.

Added: 


Modified: 
clang/lib/APINotes/APINotesReader.cpp

Removed: 




diff  --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index fa06dffdd14b03..646eabd2a5ecd3 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -2045,7 +2045,12 @@ APINotesReader::VersionedInfo::VersionedInfo(
   Results.begin(), Results.end(),
   [](const std::pair &left,
  const std::pair &right) -> bool {
-assert(left.first != right.first && "two entries for the same 
version");
+// The comparison function should be reflective, and with expensive
+// checks we can get callbacks basically checking that lambda(a,a) is
+// false. We could still check that we do not find equal elements when
+// left!=right.
+assert((&left == &right || left.first != right.first) &&
+   "two entries for the same version");
 return left.first < right.first;
   }));
 



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


[clang] [clang][ObjectiveC] Fix Parsing Types with the `::` Optional Scope Specifier (PR #119908)

2024-12-18 Thread Qiongsi Wu via cfe-commits

qiongsiwu wrote:

Thanks for the feedback everyone! The PR is updated to address the review 
comments. 

- A test is added to cover Objective-C++. 
https://github.com/llvm/llvm-project/pull/119908/files#diff-7f1cce2d0397139fc73d3615c8249ac9530082aa707868c0e921f53daf594384R1
 I am not sure if this is sufficient so please provide feedback. 
- The Objective-C test is revised to cover the optional scope specifier on 
variables (in addition to parameters) 
https://github.com/llvm/llvm-project/pull/119908/files#diff-0c0e8844905a75c581903811a694e614f49b2945e2254a76bb5a215443028554R11.
 
- The release note is updated 
https://github.com/llvm/llvm-project/pull/119908/files#diff-ec770381d76c859f5f572db789175fe44410a72608f58ad5dbb14335ba56eb97R678.
 

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


[clang] [clang] Restrict use of scalar types in vector builtins (PR #119423)

2024-12-18 Thread Fraser Cormack via cfe-commits


@@ -6,7 +6,7 @@
 // CHECK: %conv2 = fptrunc double %hlsl.dot to float
 // CHECK: ret float %conv2
 float builtin_bool_to_float_type_promotion ( float p0, bool p1 ) {
-  return __builtin_hlsl_dot ( p0, p1 );
+  return __builtin_hlsl_dot ( (double)p0, (double)p1 );

frasercrmck wrote:

@farzonl I've quickly hacked this in place to satisfy the tests. The HLSL 
builtins use the same Sema APIs as the ones I'm interested in changing. Is the 
old behaviour something that needs preserved?

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


[clang] [clang] Restrict use of scalar types in vector builtins (PR #119423)

2024-12-18 Thread Fraser Cormack via cfe-commits


@@ -68,15 +66,18 @@ void test_builtin_elementwise_add_sat(float f1, float f2, 
double d1, double d2,
   long long int i2, si8 vi1, si8 vi2,
   unsigned u1, unsigned u2, u4 vu1, u4 vu2,
   _BitInt(31) bi1, _BitInt(31) bi2,
-  unsigned _BitInt(55) bu1, unsigned 
_BitInt(55) bu2) {
+  unsigned _BitInt(55) bu1, unsigned 
_BitInt(55) bu2,
+  char c1, char c2, unsigned char uc1,
+  unsigned char uc2, short s1, short s2,
+  unsigned short us1, unsigned short us2) {
   // CHECK:  [[I1:%.+]] = load i64, ptr %i1.addr, align 8
   // CHECK-NEXT: [[I2:%.+]] = load i64, ptr %i2.addr, align 8
   // CHECK-NEXT: call i64 @llvm.sadd.sat.i64(i64 [[I1]], i64 [[I2]])
   i1 = __builtin_elementwise_add_sat(i1, i2);
 
   // CHECK:  [[I1:%.+]] = load i64, ptr %i1.addr, align 8
   // CHECK-NEXT: call i64 @llvm.sadd.sat.i64(i64 [[I1]], i64 10)
-  i1 = __builtin_elementwise_add_sat(i1, 10);
+  i1 = __builtin_elementwise_add_sat(i1, (long long int)10);

frasercrmck wrote:

I've implemented a naive version of the RFC, but I'm not sure if we want to 
require explicit casting of immediates in this case. It arguably matches the 
vector behaviour, and floating-point behaviour, but it's still awkward. 
Thoughts?

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


[clang] [llvm] [clang][llvm][aarch64] Add aarch64_sme_in_streaming_mode intrinsic (PR #120265)

2024-12-18 Thread Benjamin Maxwell via cfe-commits


@@ -11285,6 +11285,21 @@ Value 
*CodeGenFunction::EmitAArch64SMEBuiltinExpr(unsigned BuiltinID,
   if (Builtin->LLVMIntrinsic == 0)
 return nullptr;
 
+  if (BuiltinID == SME::BI__builtin_sme___arm_in_streaming_mode) {
+// If we already know the streaming mode, don't bother with the intrinsic
+// and emit a constant instead

MacDue wrote:

(optional suggestion): Rather than doing this while emitting builtins you could 
always emit the intrinsic, then handle the 
`Intrinsic::aarch64_sme_in_streaming_mode` in 
`llvm/lib/Analysis/ConstantFolding.cpp` (other target specific intrinsics are 
already handled there). 

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


[clang] [llvm] [InstCombine] Infer nuw for gep inbounds from base of object (PR #119225)

2024-12-18 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

Heads up: apart from a number of instances of actual UB in the code (which are 
quite tedious to localize and understand due to a lack of specialized tooling) 
we're investigating a bad interaction of this commit with msan, which seems to 
result in a miscompilation.

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


[clang] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy (PR #120367)

2024-12-18 Thread Farzon Lotfi via cfe-commits


@@ -1754,6 +1755,17 @@ static bool interp__builtin_vector_reduce(InterpState 
&S, CodePtr OpPC,
   PrimType ElemT = *S.getContext().classify(ElemType);
   unsigned NumElems = Arg.getNumElems();
 
+  if (ElemType->isRealFloatingType()) {
+if (ID != Builtin::BI__builtin_reduce_add &&
+ID != Builtin::BI__builtin_reduce_mul)
+  llvm_unreachable("Only reduce_add and reduce_mul are supported for "

farzonl wrote:

Context the float case was exposed by the changes in SemaChecking.cpp which 
allowed `reduce_add` and `reduce_mul`  to operate on floating point vectors. 
The remaining reduce builtins `Builtin::BI__builtin_reduce_xor, 
`Builtin::BI__builtin_reduce_or`, and `Builtin::BI__builtin_reduce_and` are not 
reachable here because the integer checks in SemaChecking.cpp  still apply to 
them. So yes this branch should be unreachable for all non `reduce_add` and 
`reduce_mul` reduction cases.

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


[clang] [llvm] [clang][llvm][aarch64] Add aarch64_sme_in_streaming_mode intrinsic (PR #120265)

2024-12-18 Thread Benjamin Maxwell via cfe-commits

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


[clang] [llvm] Revert "[InstCombine] Infer nuw for gep inbounds from base of object" (PR #120460)

2024-12-18 Thread Alexander Kornienko via cfe-commits

https://github.com/alexfh created 
https://github.com/llvm/llvm-project/pull/120460

Reverts llvm/llvm-project#119225 due to the lack of sanitizer support, large 
potential of breaking code containing latent UB, non-trivial localization and 
investigation, and what seems to be a bad interaction with msan (a test is in 
the works).

Related discussions:
https://github.com/llvm/llvm-project/pull/119225#issuecomment-2551904822
https://github.com/llvm/llvm-project/pull/118472#issuecomment-2549986255

>From 18c410940d8c0c506f759dec6d28dfe40d021a01 Mon Sep 17 00:00:00 2001
From: Alexander Kornienko 
Date: Wed, 18 Dec 2024 18:55:04 +0100
Subject: [PATCH] Revert "[InstCombine] Infer nuw for gep inbounds from base of
 object (#119225)"

This reverts commit e21ab4d16b555c28ded307571d138f594f33e325.
---
 clang/test/CodeGen/attr-counted-by.c  |  4 +-
 clang/test/CodeGen/union-tbaa1.c  |  6 +--
 .../InstCombine/InstructionCombining.cpp  | 20 --
 .../AMDGPU/memcpy-from-constant.ll|  6 +--
 llvm/test/Transforms/InstCombine/cast_phi.ll  |  4 +-
 llvm/test/Transforms/InstCombine/load-cmp.ll  |  2 +-
 .../InstCombine/memcpy-addrspace.ll   | 16 
 .../InstCombine/memcpy-from-global.ll |  2 +-
 llvm/test/Transforms/InstCombine/stpcpy-1.ll  |  2 +-
 .../Transforms/InstCombine/stpcpy_chk-1.ll|  2 +-
 llvm/test/Transforms/InstCombine/strlen-1.ll  |  6 +--
 llvm/test/Transforms/InstCombine/strlen-4.ll  | 16 
 llvm/test/Transforms/InstCombine/strncat-2.ll |  2 +-
 llvm/test/Transforms/InstCombine/strnlen-3.ll | 18 -
 llvm/test/Transforms/InstCombine/strnlen-4.ll |  4 +-
 llvm/test/Transforms/InstCombine/strnlen-5.ll |  4 +-
 llvm/test/Transforms/InstCombine/sub-gep.ll   |  8 ++--
 llvm/test/Transforms/InstCombine/wcslen-1.ll  |  6 +--
 llvm/test/Transforms/InstCombine/wcslen-3.ll  |  2 +-
 llvm/test/Transforms/InstCombine/wcslen-5.ll  | 16 
 .../AArch64/sve-interleaved-accesses.ll   |  8 ++--
 .../LoopVectorize/AArch64/sve2-histcnt.ll |  6 +--
 .../LoopVectorize/X86/small-size.ll   | 38 +--
 .../X86/x86_fp80-vector-store.ll  |  4 +-
 .../LoopVectorize/interleaved-accesses.ll |  6 +--
 .../LoopVectorize/multiple-address-spaces.ll  |  4 +-
 .../Transforms/LoopVectorize/non-const-n.ll   |  6 +--
 .../PhaseOrdering/X86/excessive-unrolling.ll  |  6 +--
 .../SLPVectorizer/X86/operandorder.ll | 16 
 29 files changed, 110 insertions(+), 130 deletions(-)

diff --git a/clang/test/CodeGen/attr-counted-by.c 
b/clang/test/CodeGen/attr-counted-by.c
index be4c7f07e92150..6b3cad5708835b 100644
--- a/clang/test/CodeGen/attr-counted-by.c
+++ b/clang/test/CodeGen/attr-counted-by.c
@@ -1043,7 +1043,7 @@ int test12_a, test12_b;
 // NO-SANITIZE-WITH-ATTR-NEXT:call void @llvm.lifetime.start.p0(i64 24, 
ptr nonnull [[BAZ]]) #[[ATTR11:[0-9]+]]
 // NO-SANITIZE-WITH-ATTR-NEXT:call void @llvm.memcpy.p0.p0.i64(ptr noundef 
nonnull align 4 dereferenceable(24) [[BAZ]], ptr noundef nonnull align 4 
dereferenceable(24) @test12_bar, i64 24, i1 false), !tbaa.struct 
[[TBAA_STRUCT7:![0-9]+]]
 // NO-SANITIZE-WITH-ATTR-NEXT:[[IDXPROM:%.*]] = sext i32 [[INDEX]] to i64
-// NO-SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds 
nuw [6 x i32], ptr [[BAZ]], i64 0, i64 [[IDXPROM]]
+// NO-SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds [6 
x i32], ptr [[BAZ]], i64 0, i64 [[IDXPROM]]
 // NO-SANITIZE-WITH-ATTR-NEXT:[[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], 
align 4, !tbaa [[TBAA2]]
 // NO-SANITIZE-WITH-ATTR-NEXT:store i32 [[TMP0]], ptr @test12_b, align 4, 
!tbaa [[TBAA2]]
 // NO-SANITIZE-WITH-ATTR-NEXT:[[TMP1:%.*]] = load i32, ptr getelementptr 
inbounds nuw (i8, ptr @test12_foo, i64 4), align 4, !tbaa [[TBAA2]]
@@ -1085,7 +1085,7 @@ int test12_a, test12_b;
 // NO-SANITIZE-WITHOUT-ATTR-NEXT:call void @llvm.lifetime.start.p0(i64 24, 
ptr nonnull [[BAZ]]) #[[ATTR9:[0-9]+]]
 // NO-SANITIZE-WITHOUT-ATTR-NEXT:call void @llvm.memcpy.p0.p0.i64(ptr 
noundef nonnull align 4 dereferenceable(24) [[BAZ]], ptr noundef nonnull align 
4 dereferenceable(24) @test12_bar, i64 24, i1 false), !tbaa.struct 
[[TBAA_STRUCT7:![0-9]+]]
 // NO-SANITIZE-WITHOUT-ATTR-NEXT:[[IDXPROM:%.*]] = sext i32 [[INDEX]] to 
i64
-// NO-SANITIZE-WITHOUT-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds 
nuw [6 x i32], ptr [[BAZ]], i64 0, i64 [[IDXPROM]]
+// NO-SANITIZE-WITHOUT-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds 
[6 x i32], ptr [[BAZ]], i64 0, i64 [[IDXPROM]]
 // NO-SANITIZE-WITHOUT-ATTR-NEXT:[[TMP0:%.*]] = load i32, ptr 
[[ARRAYIDX]], align 4, !tbaa [[TBAA2]]
 // NO-SANITIZE-WITHOUT-ATTR-NEXT:store i32 [[TMP0]], ptr @test12_b, align 
4, !tbaa [[TBAA2]]
 // NO-SANITIZE-WITHOUT-ATTR-NEXT:[[TMP1:%.*]] = load i32, ptr 
getelementptr inbounds nuw (i8, ptr @test12_foo, i64 4), align 4, !tbaa 
[[TBAA2]]
diff --git a/clang/test/CodeGen/union-tbaa1.c b/cl

[clang] [llvm] Revert "[InstCombine] Infer nuw for gep inbounds from base of object" (PR #120460)

2024-12-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alexander Kornienko (alexfh)


Changes

Reverts llvm/llvm-project#119225 due to the lack of sanitizer support, 
large potential of breaking code containing latent UB, non-trivial localization 
and investigation, and what seems to be a bad interaction with msan (a test is 
in the works).

Related discussions:
https://github.com/llvm/llvm-project/pull/119225#issuecomment-2551904822
https://github.com/llvm/llvm-project/pull/118472#issuecomment-2549986255

---

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


29 Files Affected:

- (modified) clang/test/CodeGen/attr-counted-by.c (+2-2) 
- (modified) clang/test/CodeGen/union-tbaa1.c (+3-3) 
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (-20) 
- (modified) llvm/test/Transforms/InstCombine/AMDGPU/memcpy-from-constant.ll 
(+3-3) 
- (modified) llvm/test/Transforms/InstCombine/cast_phi.ll (+2-2) 
- (modified) llvm/test/Transforms/InstCombine/load-cmp.ll (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/memcpy-addrspace.ll (+8-8) 
- (modified) llvm/test/Transforms/InstCombine/memcpy-from-global.ll (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/stpcpy-1.ll (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/stpcpy_chk-1.ll (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/strlen-1.ll (+3-3) 
- (modified) llvm/test/Transforms/InstCombine/strlen-4.ll (+8-8) 
- (modified) llvm/test/Transforms/InstCombine/strncat-2.ll (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/strnlen-3.ll (+9-9) 
- (modified) llvm/test/Transforms/InstCombine/strnlen-4.ll (+2-2) 
- (modified) llvm/test/Transforms/InstCombine/strnlen-5.ll (+2-2) 
- (modified) llvm/test/Transforms/InstCombine/sub-gep.ll (+4-4) 
- (modified) llvm/test/Transforms/InstCombine/wcslen-1.ll (+3-3) 
- (modified) llvm/test/Transforms/InstCombine/wcslen-3.ll (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/wcslen-5.ll (+8-8) 
- (modified) 
llvm/test/Transforms/LoopVectorize/AArch64/sve-interleaved-accesses.ll (+4-4) 
- (modified) llvm/test/Transforms/LoopVectorize/AArch64/sve2-histcnt.ll (+3-3) 
- (modified) llvm/test/Transforms/LoopVectorize/X86/small-size.ll (+19-19) 
- (modified) llvm/test/Transforms/LoopVectorize/X86/x86_fp80-vector-store.ll 
(+2-2) 
- (modified) llvm/test/Transforms/LoopVectorize/interleaved-accesses.ll (+3-3) 
- (modified) llvm/test/Transforms/LoopVectorize/multiple-address-spaces.ll 
(+2-2) 
- (modified) llvm/test/Transforms/LoopVectorize/non-const-n.ll (+3-3) 
- (modified) llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll 
(+3-3) 
- (modified) llvm/test/Transforms/SLPVectorizer/X86/operandorder.ll (+8-8) 


``diff
diff --git a/clang/test/CodeGen/attr-counted-by.c 
b/clang/test/CodeGen/attr-counted-by.c
index be4c7f07e92150..6b3cad5708835b 100644
--- a/clang/test/CodeGen/attr-counted-by.c
+++ b/clang/test/CodeGen/attr-counted-by.c
@@ -1043,7 +1043,7 @@ int test12_a, test12_b;
 // NO-SANITIZE-WITH-ATTR-NEXT:call void @llvm.lifetime.start.p0(i64 24, 
ptr nonnull [[BAZ]]) #[[ATTR11:[0-9]+]]
 // NO-SANITIZE-WITH-ATTR-NEXT:call void @llvm.memcpy.p0.p0.i64(ptr noundef 
nonnull align 4 dereferenceable(24) [[BAZ]], ptr noundef nonnull align 4 
dereferenceable(24) @test12_bar, i64 24, i1 false), !tbaa.struct 
[[TBAA_STRUCT7:![0-9]+]]
 // NO-SANITIZE-WITH-ATTR-NEXT:[[IDXPROM:%.*]] = sext i32 [[INDEX]] to i64
-// NO-SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds 
nuw [6 x i32], ptr [[BAZ]], i64 0, i64 [[IDXPROM]]
+// NO-SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds [6 
x i32], ptr [[BAZ]], i64 0, i64 [[IDXPROM]]
 // NO-SANITIZE-WITH-ATTR-NEXT:[[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], 
align 4, !tbaa [[TBAA2]]
 // NO-SANITIZE-WITH-ATTR-NEXT:store i32 [[TMP0]], ptr @test12_b, align 4, 
!tbaa [[TBAA2]]
 // NO-SANITIZE-WITH-ATTR-NEXT:[[TMP1:%.*]] = load i32, ptr getelementptr 
inbounds nuw (i8, ptr @test12_foo, i64 4), align 4, !tbaa [[TBAA2]]
@@ -1085,7 +1085,7 @@ int test12_a, test12_b;
 // NO-SANITIZE-WITHOUT-ATTR-NEXT:call void @llvm.lifetime.start.p0(i64 24, 
ptr nonnull [[BAZ]]) #[[ATTR9:[0-9]+]]
 // NO-SANITIZE-WITHOUT-ATTR-NEXT:call void @llvm.memcpy.p0.p0.i64(ptr 
noundef nonnull align 4 dereferenceable(24) [[BAZ]], ptr noundef nonnull align 
4 dereferenceable(24) @test12_bar, i64 24, i1 false), !tbaa.struct 
[[TBAA_STRUCT7:![0-9]+]]
 // NO-SANITIZE-WITHOUT-ATTR-NEXT:[[IDXPROM:%.*]] = sext i32 [[INDEX]] to 
i64
-// NO-SANITIZE-WITHOUT-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds 
nuw [6 x i32], ptr [[BAZ]], i64 0, i64 [[IDXPROM]]
+// NO-SANITIZE-WITHOUT-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds 
[6 x i32], ptr [[BAZ]], i64 0, i64 [[IDXPROM]]
 // NO-SANITIZE-WITHOUT-ATTR-NEXT:[[TMP0:%.*]] = load i32, ptr 
[[ARRAYIDX]], align 4, !tbaa [[TBAA2]]
 // NO-SANITIZE-WITHOUT-ATTR-NEXT:store i32 [[TMP0]], ptr 

[clang] [llvm] [InstCombine] Infer nuw for gep inbounds from base of object (PR #119225)

2024-12-18 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

> > Heads up: apart from a number of instances of actual UB in the code (which 
> > are quite tedious to localize and understand due to a lack of specialized 
> > tooling) we're investigating a bad interaction of this commit with msan, 
> > which seems to result in a miscompilation.
> 
> Thanks for the heads up! As I mentioned on another thread, I'm happy to just 
> entirely revert this patch due to lack of good sanitizer support (I can do it 
> tomorrow, but feel free to do it yourself earlier). Having a reproducer for 
> the msan issue is probably still valuable, as it may indicate a larger 
> problem.

Thanks! Sent a PR with a revert: 
https://github.com/llvm/llvm-project/pull/120460

As mentioned, a test case is in the works.

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


[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-18 Thread Nathan Chancellor via cfe-commits

nathanchance wrote:

@nikic I noticed your comment on #118472 (the motivator for this change AFAICT):

> `-fwrapv` should already cover pointers

but it does not seem like this warning takes that into account (see the last 
example below)? I noticed a few instances of this warning in the Linux kernel 
but it sets `-fno-strict-overflow` for well defined overflow semantics it can 
depend on because it wants to avoid optimizations like the one that triggered 
this warning (`-fno-delete-null-pointer-checks` is a similarly used flag), so 
claiming the result of the checks are always false just does not seem to line 
up with reality. It seems like if the optimizer is going to respect this check 
and not remove it, this warning should not trigger either.

```c
int check(const int* foo, unsigned int idx)
{
return foo + idx < foo;
}
```

```
$ clang-19 -O2 -c test.c

$ llvm-objdump -dr test.o
...
 :
   0: 31 c0 xorl%eax, %eax
   2: c3retq

$ clang-19 -O2 -fno-strict-overflow -c test.o

$ llvm-objdump -dr test.o
...
 :
   0: 89 f0 movl%esi, %eax
   2: 48 8d 0c 87   leaq(%rdi,%rax,4), %rcx
   6: 31 c0 xorl%eax, %eax
   8: 48 39 f9  cmpq%rdi, %rcx
   b: 0f 92 c0  setb%al
   e: c3retq
```

```
$ gcc --version | head -1
gcc (GCC) 14.2.1 20240910

$ gcc -O2 -c test.c

$ llvm-objdump -dr test.o
...
 :
   0: 31 c0 xorl%eax, %eax
   2: c3retq

$ gcc -O2 -fno-strict-overflow -c test.c

$ llvm-objdump -dr test.o
...
 :
   0: 89 f6 movl%esi, %esi
   2: 48 8d 04 b7   leaq(%rdi,%rsi,4), %rax
   6: 48 39 f8  cmpq%rdi, %rax
   9: 0f 92 c0  setb%al
   c: 0f b6 c0  movzbl  %al, %eax
   f: c3retq
```

```
$ clang --version | head -1
ClangBuiltLinux clang version 20.0.0git 
(https://github.com/llvm/llvm-project.git 
99c2e3b78210a345afb1b5121f12b0e7bf923543)

$ clang -O2 -c test.c
test.c:3:19: warning: pointer comparison always evaluates to false 
[-Wtautological-compare]
3 | return foo + idx < foo;
  |  ^
1 warning generated.

$ llvm-objdump -dr test.o
...
 :
   0: 31 c0 xorl%eax, %eax
   2: c3retq

$ clang -O2 -c -fno-strict-overflow test.c
test.c:3:19: warning: pointer comparison always evaluates to false 
[-Wtautological-compare]
3 | return foo + idx < foo;
  |  ^
1 warning generated.

$ llvm-objdump -dr test.o
...
 :
   0: 89 f0 movl%esi, %eax
   2: 48 8d 0c 87   leaq(%rdi,%rax,4), %rcx
   6: 31 c0 xorl%eax, %eax
   8: 48 39 f9  cmpq%rdi, %rcx
   b: 0f 92 c0  setb%al
   e: c3retq
```

I tested something like:

```diff
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e06a092177ef..2dd7c5951d71 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -11789,10 +11789,11 @@ static bool checkForArray(const Expr *E) {
 /// Detect patterns ptr + size >= ptr and ptr + size < ptr, where ptr is a
 /// pointer and size is an unsigned integer. Return whether the result is
 /// always true/false.
-static std::optional isTautologicalBoundsCheck(const Expr *LHS,
+static std::optional isTautologicalBoundsCheck(Sema &S,
+ const Expr *LHS,
  const Expr *RHS,
  BinaryOperatorKind Opc) {
-  if (!LHS->getType()->isPointerType())
+  if (!LHS->getType()->isPointerType() || 
S.getLangOpts().isSignedOverflowDefined())
 return std::nullopt;

   // Canonicalize to >= or < predicate.
@@ -11940,7 +11941,7 @@ static void diagnoseTautologicalComparison(Sema &S, 
SourceLocation Loc,
 << 1 /*array comparison*/
 << Result);
 } else if (std::optional Res =
-   isTautologicalBoundsCheck(LHS, RHS, Opc)) {
+   isTautologicalBoundsCheck(S, LHS, RHS, Opc)) {
   S.DiagRuntimeBehavior(Loc, nullptr,
 S.PDiag(diag::warn_comparison_always)
 << 2 /*pointer comparison*/
```

which results in a behavior I would expect:

```
$ clang -fsyntax-only test.c
test.c:3:19: warning: pointer comparison always evaluates to false 
[-Wt

[clang] [llvm] Revert "[InstCombine] Infer nuw for gep inbounds from base of object" (PR #120460)

2024-12-18 Thread Vitaly Buka via cfe-commits

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


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


[clang] [clang][CodeGen][SPIRV] Translate `amdgpu_flat_work_group_size` into `reqd_work_group_size`. (PR #116820)

2024-12-18 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/116820

>From c5efdd24c0c889e26e3b00865780970ca5ed1f4c Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 19 Nov 2024 14:55:25 +
Subject: [PATCH 1/3] Translate `amdgpu_flat_work_group_size` into
 `reqd_work_group_size`.

---
 clang/lib/CodeGen/Targets/SPIR.cpp| 34 +++
 clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu |  7 
 2 files changed, 41 insertions(+)

diff --git a/clang/lib/CodeGen/Targets/SPIR.cpp 
b/clang/lib/CodeGen/Targets/SPIR.cpp
index a48fe9d5f1ee9c..c35d91b1f49af2 100644
--- a/clang/lib/CodeGen/Targets/SPIR.cpp
+++ b/clang/lib/CodeGen/Targets/SPIR.cpp
@@ -64,6 +64,8 @@ class SPIRVTargetCodeGenInfo : public 
CommonSPIRTargetCodeGenInfo {
   void setCUDAKernelCallingConvention(const FunctionType *&FT) const override;
   LangAS getGlobalVarAddressSpace(CodeGenModule &CGM,
   const VarDecl *D) const override;
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
   llvm::SyncScope::ID getLLVMSyncScopeID(const LangOptions &LangOpts,
  SyncScope Scope,
  llvm::AtomicOrdering Ordering,
@@ -245,6 +247,38 @@ 
SPIRVTargetCodeGenInfo::getGlobalVarAddressSpace(CodeGenModule &CGM,
   return DefaultGlobalAS;
 }
 
+void SPIRVTargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (!M.getLangOpts().HIP ||
+  M.getTarget().getTriple().getVendor() != llvm::Triple::AMD)
+return;
+  if (GV->isDeclaration())
+return;
+
+  auto F = dyn_cast(GV);
+  if (!F)
+return;
+
+  auto FD = dyn_cast_or_null(D);
+  if (!FD)
+return;
+  if (!FD->hasAttr())
+return;
+
+  unsigned N = M.getLangOpts().GPUMaxThreadsPerBlock;
+  if (auto FlatWGS = FD->getAttr())
+N = FlatWGS->getMax()->EvaluateKnownConstInt(M.getContext()).getExtValue();
+
+  auto Int32Ty = llvm::IntegerType::getInt32Ty(M.getLLVMContext());
+  llvm::Metadata *AttrMDArgs[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, N)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 1)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 1))};
+
+  F->setMetadata("reqd_work_group_size",
+ llvm::MDNode::get(M.getLLVMContext(), AttrMDArgs));
+}
+
 llvm::SyncScope::ID
 SPIRVTargetCodeGenInfo::getLLVMSyncScopeID(const LangOptions &, SyncScope 
Scope,
llvm::AtomicOrdering,
diff --git a/clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu 
b/clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
index 11a133fd1351d2..3d01ac40259254 100644
--- a/clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
@@ -4,6 +4,9 @@
 // RUN: %clang_cc1 -triple amdgcn-amd-amdhsa --gpu-max-threads-per-block=1024 \
 // RUN: -fcuda-is-device -emit-llvm -o - -x hip %s \
 // RUN: | FileCheck -check-prefixes=CHECK,MAX1024 %s
+// RUN: %clang_cc1 -triple spirv64-amd-amdhsa --gpu-max-threads-per-block=1024 
\
+// RUN: -fcuda-is-device -emit-llvm -o - -x hip %s \
+// RUN: | FileCheck -check-prefixes=CHECK-SPIRV,MAX1024-SPIRV %s
 // RUN: %clang_cc1 -triple nvptx \
 // RUN: -fcuda-is-device -emit-llvm -o - %s | FileCheck %s \
 // RUN: -check-prefix=NAMD
@@ -21,12 +24,14 @@
 
 __global__ void flat_work_group_size_default() {
 // CHECK: define{{.*}} amdgpu_kernel void @_Z28flat_work_group_size_defaultv() 
[[FLAT_WORK_GROUP_SIZE_DEFAULT:#[0-9]+]]
+// CHECK-SPIRV: define{{.*}} spir_kernel void 
@_Z28flat_work_group_size_defaultv(){{.*}} !reqd_work_group_size 
[[REQD_WORK_GROUP_SIZE_DEFAULT:![0-9]+]]
 // NOUB: define{{.*}} void @_Z28flat_work_group_size_defaultv() 
[[NOUB:#[0-9]+]]
 }
 
 __attribute__((amdgpu_flat_work_group_size(32, 64))) // expected-no-diagnostics
 __global__ void flat_work_group_size_32_64() {
 // CHECK: define{{.*}} amdgpu_kernel void @_Z26flat_work_group_size_32_64v() 
[[FLAT_WORK_GROUP_SIZE_32_64:#[0-9]+]]
+// CHECK-SPIRV: define{{.*}} spir_kernel void 
@_Z26flat_work_group_size_32_64v(){{.*}} !reqd_work_group_size 
[[REQD_WORK_GROUP_SIZE_64:![0-9]+]]
 }
 __attribute__((amdgpu_waves_per_eu(2))) // expected-no-diagnostics
 __global__ void waves_per_eu_2() {
@@ -82,7 +87,9 @@ template __global__ void 
template_32_4_a_max_num_work_groups<2>();
 
 // DEFAULT-DAG: attributes [[FLAT_WORK_GROUP_SIZE_DEFAULT]] = 
{{.*}}"amdgpu-flat-work-group-size"="1,1024"{{.*}}"uniform-work-group-size"="true"
 // MAX1024-DAG: attributes [[FLAT_WORK_GROUP_SIZE_DEFAULT]] = 
{{.*}}"amdgpu-flat-work-group-size"="1,1024"
+// MAX1024-SPIRV-DAG: [[REQD_WORK_GROUP_SIZE_DEFAULT]] = !{i32 1024, i32 1, 
i32 1}
 // CHECK-DAG: attributes [[FLAT_WORK_GROUP_SIZE_32_64]] = 
{{.*}}"amdgpu-flat-work-group-size"="32,64"
+// CHECK-SPIRV-DAG: [[REQD_WORK_GROUP_SIZE_64]

[clang] [clang][CodeGen][SPIRV] Translate `amdgpu_flat_work_group_size` into `reqd_work_group_size`. (PR #116820)

2024-12-18 Thread Alex Voicu via cfe-commits

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


[clang] [clang-format] extend clang-format directive with options to prevent formatting for one line (PR #118566)

2024-12-18 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/118566

>From 75da343b0bd6e3b0f3219b349f6be4c882947820 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 4 Dec 2024 02:24:12 +0200
Subject: [PATCH 1/5] [clang-format] extend clang-format directive with options
 to prevent formatting for one line

---
 clang/include/clang/Format/Format.h   | 11 +++-
 clang/lib/Format/DefinitionBlockSeparator.cpp |  3 +-
 clang/lib/Format/Format.cpp   | 59 +--
 clang/lib/Format/FormatTokenLexer.cpp | 39 +---
 clang/lib/Format/FormatTokenLexer.h   |  8 ++-
 .../Format/IntegerLiteralSeparatorFixer.cpp   |  4 +-
 clang/lib/Format/SortJavaScriptImports.cpp| 10 +++-
 clang/lib/Format/TokenAnnotator.cpp   |  4 +-
 clang/unittests/Format/FormatTest.cpp | 53 +
 .../unittests/Format/SortImportsTestJava.cpp  |  9 +++
 10 files changed, 165 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..b25d190178247d 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5620,8 +5620,15 @@ inline StringRef 
getLanguageName(FormatStyle::LanguageKind Language) {
   }
 }
 
-bool isClangFormatOn(StringRef Comment);
-bool isClangFormatOff(StringRef Comment);
+enum class ClangFormatDirective {
+  None,
+  Off,
+  On,
+  OffLine,
+  OffNextLine,
+};
+
+ClangFormatDirective parseClangFormatDirective(StringRef Comment);
 
 } // end namespace format
 } // end namespace clang
diff --git a/clang/lib/Format/DefinitionBlockSeparator.cpp 
b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 319236d3bd618c..709ad5e776cc5a 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -144,7 +144,8 @@ void DefinitionBlockSeparator::separateBlocks(
 return false;
 
   if (const auto *Tok = OperateLine->First;
-  Tok->is(tok::comment) && !isClangFormatOn(Tok->TokenText)) {
+  Tok->is(tok::comment) && parseClangFormatDirective(Tok->TokenText) ==
+   ClangFormatDirective::None) {
 return true;
   }
 
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index dcaac4b0d42cc5..11802e8f5b3738 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3266,10 +3266,11 @@ tooling::Replacements sortCppIncludes(const FormatStyle 
&Style, StringRef Code,
   FormattingOff = false;
 
 bool IsBlockComment = false;
+ClangFormatDirective CFD = parseClangFormatDirective(Trimmed);
 
-if (isClangFormatOff(Trimmed)) {
+if (CFD == ClangFormatDirective::Off) {
   FormattingOff = true;
-} else if (isClangFormatOn(Trimmed)) {
+} else if (CFD == ClangFormatDirective::On) {
   FormattingOff = false;
 } else if (Trimmed.starts_with("/*")) {
   IsBlockComment = true;
@@ -3452,9 +3453,10 @@ tooling::Replacements sortJavaImports(const FormatStyle 
&Style, StringRef Code,
 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
 
 StringRef Trimmed = Line.trim();
-if (isClangFormatOff(Trimmed))
+ClangFormatDirective CFD = parseClangFormatDirective(Trimmed);
+if (CFD == ClangFormatDirective::Off)
   FormattingOff = true;
-else if (isClangFormatOn(Trimmed))
+else if (CFD == ClangFormatDirective::On)
   FormattingOff = false;
 
 if (ImportRegex.match(Line, &Matches)) {
@@ -4190,24 +4192,45 @@ Expected getStyle(StringRef StyleName, 
StringRef FileName,
   return FallbackStyle;
 }
 
-static bool isClangFormatOnOff(StringRef Comment, bool On) {
-  if (Comment == (On ? "/* clang-format on */" : "/* clang-format off */"))
-return true;
+static unsigned skipWhitespace(unsigned Pos, StringRef Str, unsigned Length) {
+  while (Pos < Length && isspace(Str[Pos]))
+++Pos;
+  return Pos;
+}
 
-  static const char ClangFormatOn[] = "// clang-format on";
-  static const char ClangFormatOff[] = "// clang-format off";
-  const unsigned Size = (On ? sizeof ClangFormatOn : sizeof ClangFormatOff) - 
1;
+ClangFormatDirective parseClangFormatDirective(StringRef Comment) {
+  size_t Pos = std::min(Comment.find("/*"), Comment.find("//"));
+  unsigned Length = Comment.size();
+  if (Pos == StringRef::npos)
+return ClangFormatDirective::None;
 
-  return Comment.starts_with(On ? ClangFormatOn : ClangFormatOff) &&
- (Comment.size() == Size || Comment[Size] == ':');
-}
+  Pos = skipWhitespace(Pos + 2, Comment, Length);
+  StringRef ClangFormatDirectiveName = "clang-format";
 
-bool isClangFormatOn(StringRef Comment) {
-  return isClangFormatOnOff(Comment, /*On=*/true);
-}
+  if (Comment.substr(Pos, ClangFormatDirectiveName.size()) ==
+  ClangFormatDirectiveName) {
+Pos =
+skipWhitespace(Pos + ClangFormatDirectiveName.size(), Comment, Length);
+
+unsigned EndDi

[clang] [Coverage] Resurrect Branch:FalseCnt in SwitchStmt that was pruned in #112694 (PR #120418)

2024-12-18 Thread Alan Phipps via cfe-commits

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


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


[clang] [clang-format] extend clang-format directive with options to prevent formatting for one line (PR #118566)

2024-12-18 Thread Oleksandr T. via cfe-commits


@@ -144,7 +144,8 @@ void DefinitionBlockSeparator::separateBlocks(
 return false;
 
   if (const auto *Tok = OperateLine->First;
-  Tok->is(tok::comment) && !isClangFormatOn(Tok->TokenText)) {
+  Tok->is(tok::comment) && parseClangFormatDirective(Tok->TokenText) ==
+   ClangFormatDirective::None) {

a-tarasyuk wrote:

@HazardyKnusperkeks Thank you for the review. I've made the changes. I extended 
the parsing of the directive because handling only On/Off doesn't fully address 
cases where we need to determine what the directive does to apply the 
appropriate formatting—such as disabling the next line, disabling the current 
line, or toggling an entire block. Does that make sense? I'd be happy to 
discuss alternative solutions if there's a better way to handle this.


Based on the discussions on the issue and this PR, where a clear consensus on 
these features hasn’t been reached. I’ve added a comment 
https://github.com/llvm/llvm-project/pull/118566#issuecomment-2531572587 - it 
might be best to hold off on these changes until a decision is made, on whether 
to move forward or close the issue entirely.


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


[clang] [clang][CodeGen][SPIRV] Translate `amdgpu_flat_work_group_size` into `reqd_work_group_size`. (PR #116820)

2024-12-18 Thread Alex Voicu via cfe-commits

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


[clang] [WebKit checkers] Recognize adoptRef as a safe function (PR #119846)

2024-12-18 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated 
https://github.com/llvm/llvm-project/pull/119846

>From 6b4a6b832f61efc26396f60309744c2e7264156d Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Fri, 13 Dec 2024 01:49:21 -0800
Subject: [PATCH 1/3] [WebKit checkers] Recognize adoptRef as a safe function

adoptRef in WebKit constructs Ref/RefPtr so treat it as such in 
isCtorOfRefCounted.
Also removed the support for makeRef and makeRefPtr as they don't exist any 
more.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp |  5 ++--
 .../Analysis/Checkers/WebKit/call-args.cpp| 17 +++
 .../Analysis/Checkers/WebKit/mock-types.h | 28 ++-
 3 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 797f3e1f3fba5a..5487fea1b956c8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -125,9 +125,8 @@ bool isCtorOfRefCounted(const clang::FunctionDecl *F) {
   assert(F);
   const std::string &FunctionName = safeGetName(F);
 
-  return isRefType(FunctionName) || FunctionName == "makeRef" ||
- FunctionName == "makeRefPtr" || FunctionName == "UniqueRef" ||
- FunctionName == "makeUniqueRef" ||
+  return isRefType(FunctionName) || FunctionName == "adoptRef" ||
+ FunctionName == "UniqueRef" || FunctionName == "makeUniqueRef" ||
  FunctionName == "makeUniqueRefWithoutFastMallocCheck"
 
  || FunctionName == "String" || FunctionName == "AtomString" ||
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index 94efddeaf66cd8..574e3aa6ef476a 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -365,3 +365,20 @@ namespace call_with_explicit_temporary_obj {
 RefPtr { provide() }->method();
   }
 }
+
+namespace call_with_adopt_ref {
+  class Obj {
+  public:
+void ref() const;
+void deref() const;
+void method();
+  };
+
+  struct dummy {
+RefPtr any;
+  };
+
+  void foo() {
+adoptRef(new Obj)->method();
+  }
+}
diff --git a/clang/test/Analysis/Checkers/WebKit/mock-types.h 
b/clang/test/Analysis/Checkers/WebKit/mock-types.h
index fb1ee51c7ec1de..17c449b6c2ec26 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-types.h
@@ -46,7 +46,10 @@ template struct DefaultRefDerefTraits {
 template , typename 
RefDerefTraits = DefaultRefDerefTraits> struct Ref {
   typename PtrTraits::StorageType t;
 
+  enum AdoptTag { Adopt };
+
   Ref() : t{} {};
+  Ref(T &t, AdoptTag) : t(&t) { }
   Ref(T &t) : t(&RefDerefTraits::ref(t)) { }
   Ref(const Ref& o) : t(RefDerefTraits::refIfNotNull(PtrTraits::unwrap(o.t))) 
{ }
   Ref(Ref&& o) : t(o.leakRef()) { }
@@ -73,10 +76,19 @@ template , 
typename RefDerefTra
   T* leakRef() { return PtrTraits::exchange(t, nullptr); }
 };
 
+template  Ref adoptRef(T& t) {
+  using Ref = Ref;
+  return Ref(t, Ref::Adopt);
+}
+
+template class RefPtr;
+template RefPtr adoptRef(T*);
+
 template  struct RefPtr {
   T *t;
 
-  RefPtr() : t(new T) {}
+  RefPtr() : t(nullptr) { }
+
   RefPtr(T *t)
 : t(t) {
 if (t)
@@ -85,6 +97,9 @@ template  struct RefPtr {
   RefPtr(Ref&& o)
 : t(o.leakRef())
   { }
+  RefPtr(RefPtr&& o)
+: t(o.leakRef())
+  { }
   ~RefPtr() {
 if (t)
   t->deref();
@@ -110,8 +125,19 @@ template  struct RefPtr {
 return *this;
   }
   operator bool() const { return t; }
+
+private:
+  friend RefPtr adoptRef(T*);
+
+  // call_with_adopt_ref in call-args.cpp requires this method to be private.
+  enum AdoptTag { Adopt };
+  RefPtr(T *t, AdoptTag) : t(t) { }
 };
 
+template  RefPtr adoptRef(T* t) {
+  return RefPtr(t, RefPtr::Adopt);
+}
+
 template  bool operator==(const RefPtr &, const RefPtr &) {
   return false;
 }

>From 0cdeb5676251a3c8d832baf1de800fe8a535b600 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Fri, 13 Dec 2024 01:58:00 -0800
Subject: [PATCH 2/3] Fix the mock RefPtr

---
 clang/test/Analysis/Checkers/WebKit/mock-types.h | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/clang/test/Analysis/Checkers/WebKit/mock-types.h 
b/clang/test/Analysis/Checkers/WebKit/mock-types.h
index 17c449b6c2ec26..9625ae6128883c 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-types.h
@@ -95,11 +95,13 @@ template  struct RefPtr {
   t->ref();
   }
   RefPtr(Ref&& o)
-: t(o.leakRef())
+: t(o.leafkRef())
   { }
   RefPtr(RefPtr&& o)
-: t(o.leakRef())
-  { }
+: t(o.t)
+  {
+o.t = nullptr;
+  }
   ~RefPtr() {
 if (t)
   t->deref();

>From bc318db7b2a4c48882988d1ca26ab54cb351757a Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Wed, 18 Dec 2024 10:31:41 -0800
Subject: [PATCH 3/3]

[clang] [compiler-rt] [driver] Fix sanitizer libc++ runtime linking (PR #120370)

2024-12-18 Thread Thurston Dang via cfe-commits

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


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


[clang] [clang] Change placeholder from `undef` to `poison` (PR #120446)

2024-12-18 Thread Nuno Lopes via cfe-commits

https://github.com/nunoplopes updated 
https://github.com/llvm/llvm-project/pull/120446

>From eac0aa0d6a60a61a4312b248229aa94559ca5add Mon Sep 17 00:00:00 2001
From: Pedro Lobo 
Date: Wed, 18 Dec 2024 15:58:46 +
Subject: [PATCH] [clang] Change placeholder from `undef` to `poison`

Call `insertvalue` with a `poison` operand instead of `undef`.
---
 clang/lib/CodeGen/MicrosoftCXXABI.cpp   | 2 +-
 clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index d587daac5a88a9..90651c3bafe26e 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -3454,7 +3454,7 @@ llvm::Value 
*MicrosoftCXXABI::EmitNonNullMemberPointerConversion(
   if (inheritanceModelHasOnlyOneField(IsFunc, DstInheritance)) {
 Dst = FirstField;
   } else {
-Dst = llvm::UndefValue::get(ConvertMemberPointerType(DstTy));
+Dst = llvm::PoisonValue::get(ConvertMemberPointerType(DstTy));
 unsigned Idx = 0;
 Dst = Builder.CreateInsertValue(Dst, FirstField, Idx++);
 if (inheritanceModelHasNVOffsetField(IsFunc, DstInheritance))
diff --git a/clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp 
b/clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
index 2ac1961465d8a8..fc8a31e0350e5f 100644
--- a/clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
+++ b/clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
@@ -647,7 +647,7 @@ void (Multiple::*convertB2FuncToMultiple(void 
(B2::*mp)()))() {
 // CHECK:   br i1 %{{.*}} label %{{.*}}, label %{{.*}}
 //
 //memptr.convert:   ; preds = %entry
-// CHECK:   insertvalue { ptr, i32 } undef, ptr %[[mp]], 0
+// CHECK:   insertvalue { ptr, i32 } poison, ptr %[[mp]], 0
 // CHECK:   insertvalue { ptr, i32 } %{{.*}}, i32 4, 1
 // CHECK:   br label
 //
@@ -705,7 +705,7 @@ void (D::*convertCToD(void (C::*mp)()))() {
 // CHECK:   %[[nv_adj:.*]] = select i1 %[[is_nvbase]], i32 %[[nv_disp]], i32 0
 // CHECK:   %[[dst_adj:.*]] = select i1 %[[is_nvbase]], i32 4, i32 0
 // CHECK:   %[[adj:.*]] = sub nsw i32 %[[nv_adj]], %[[dst_adj]]
-// CHECK:   insertvalue { ptr, i32, i32 } undef, ptr {{.*}}, 0
+// CHECK:   insertvalue { ptr, i32, i32 } poison, ptr {{.*}}, 0
 // CHECK:   insertvalue { ptr, i32, i32 } {{.*}}, i32 %[[adj]], 1
 // CHECK:   insertvalue { ptr, i32, i32 } {{.*}}, i32 {{.*}}, 2
 // CHECK:   br label

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


[clang] [clang] Change placeholder from `undef` to `poison` (PR #120446)

2024-12-18 Thread Nuno Lopes via cfe-commits

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


[clang] 1a87f07 - [clang] Change initialization of a vector from undef to poison [NFC] (#120446)

2024-12-18 Thread via cfe-commits

Author: Pedro Lobo
Date: 2024-12-18T18:35:31Z
New Revision: 1a87f07465d76c87ace25623c67faf9596bbbf56

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

LOG: [clang] Change initialization of a vector from undef to poison [NFC] 
(#120446)

It is fully initialized with insertelements.

Added: 


Modified: 
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index d587daac5a88a9..90651c3bafe26e 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -3454,7 +3454,7 @@ llvm::Value 
*MicrosoftCXXABI::EmitNonNullMemberPointerConversion(
   if (inheritanceModelHasOnlyOneField(IsFunc, DstInheritance)) {
 Dst = FirstField;
   } else {
-Dst = llvm::UndefValue::get(ConvertMemberPointerType(DstTy));
+Dst = llvm::PoisonValue::get(ConvertMemberPointerType(DstTy));
 unsigned Idx = 0;
 Dst = Builder.CreateInsertValue(Dst, FirstField, Idx++);
 if (inheritanceModelHasNVOffsetField(IsFunc, DstInheritance))

diff  --git a/clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp 
b/clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
index 2ac1961465d8a8..fc8a31e0350e5f 100644
--- a/clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
+++ b/clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
@@ -647,7 +647,7 @@ void (Multiple::*convertB2FuncToMultiple(void 
(B2::*mp)()))() {
 // CHECK:   br i1 %{{.*}} label %{{.*}}, label %{{.*}}
 //
 //memptr.convert:   ; preds = %entry
-// CHECK:   insertvalue { ptr, i32 } undef, ptr %[[mp]], 0
+// CHECK:   insertvalue { ptr, i32 } poison, ptr %[[mp]], 0
 // CHECK:   insertvalue { ptr, i32 } %{{.*}}, i32 4, 1
 // CHECK:   br label
 //
@@ -705,7 +705,7 @@ void (D::*convertCToD(void (C::*mp)()))() {
 // CHECK:   %[[nv_adj:.*]] = select i1 %[[is_nvbase]], i32 %[[nv_disp]], i32 0
 // CHECK:   %[[dst_adj:.*]] = select i1 %[[is_nvbase]], i32 4, i32 0
 // CHECK:   %[[adj:.*]] = sub nsw i32 %[[nv_adj]], %[[dst_adj]]
-// CHECK:   insertvalue { ptr, i32, i32 } undef, ptr {{.*}}, 0
+// CHECK:   insertvalue { ptr, i32, i32 } poison, ptr {{.*}}, 0
 // CHECK:   insertvalue { ptr, i32, i32 } {{.*}}, i32 %[[adj]], 1
 // CHECK:   insertvalue { ptr, i32, i32 } {{.*}}, i32 {{.*}}, 2
 // CHECK:   br label



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


[clang] [llvm] Revert "[InstCombine] Infer nuw for gep inbounds from base of object" (PR #120460)

2024-12-18 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`llvm-nvptx64-nvidia-ubuntu` running on `as-builder-7` while building 
`clang,llvm` at step 6 "test-build-unified-tree-check-llvm".

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


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

```
Step 6 (test-build-unified-tree-check-llvm) failure: test (failure)
 TEST 'LLVM :: 
Transforms/PhaseOrdering/X86/excessive-unrolling.ll' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/opt
 -passes='default' -unroll-runtime -S 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll
 | 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck
 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll
+ 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/opt
 '-passes=default' -unroll-runtime -S 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll
+ 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/bin/FileCheck
 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll:182:15:
 error: CHECK-NEXT: expected string not found in input
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds [58 x double], ptr @b, i64 
0, i64 [[INDEX]]
  ^
:156:67: note: scanning from here
 %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  ^
:156:67: note: with "INDEX" equal to "%index"
 %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  ^
:157:2: note: possible intended match here
 %0 = getelementptr inbounds nuw [58 x double], ptr @b, i64 0, i64 %index
 ^

Input file: 
Check file: 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/llvm-project/llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll

-dump-input=help explains the following input dump.

Input was:
<<
.
.
.
  151: vector.ph: ; preds = %for.body.preheader 
  152:  %n.vec = and i64 %wide.trip.count, 2147483644 
  153:  br label %vector.body 
  154:  
  155: vector.body: ; preds = %vector.body, %vector.ph 
  156:  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body 
] 
next:182'0  
 X error: no match found
next:182'1  
   with "INDEX" equal to "%index"
  157:  %0 = getelementptr inbounds nuw [58 x double], ptr @b, i64 0, 
i64 %index 
next:182'0 
~~
next:182'2  ?   
  possible intended match
  158:  %1 = getelementptr inbounds nuw i8, ptr %0, i64 16 
next:182'0 
  159:  %wide.load = load <2 x double>, ptr %0, align 16 
next:182'0 ~~
  160:  %wide.load4 = load <2 x double>, ptr %1, align 16 
next:182'0 ~~~
  161:  %2 = getelementptr inbounds nuw [58 x double], ptr @c, i64 0, 
i64 %index 
next:182'0 
~~
...

```



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


[clang] [llvm] Revert "[InstCombine] Infer nuw for gep inbounds from base of object" (PR #120460)

2024-12-18 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-nvptx-nvidia-ubuntu` 
running on `as-builder-7` while building `clang,llvm` at step 6 
"test-build-unified-tree-check-llvm".

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


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

```
Step 6 (test-build-unified-tree-check-llvm) failure: test (failure)
 TEST 'LLVM :: 
Transforms/PhaseOrdering/X86/excessive-unrolling.ll' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/opt
 -passes='default' -unroll-runtime -S 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll
 | 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck
 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll
+ 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/opt
 '-passes=default' -unroll-runtime -S 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll
+ 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/bin/FileCheck
 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll:182:15:
 error: CHECK-NEXT: expected string not found in input
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds [58 x double], ptr @b, i64 
0, i64 [[INDEX]]
  ^
:156:67: note: scanning from here
 %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  ^
:156:67: note: with "INDEX" equal to "%index"
 %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  ^
:157:2: note: possible intended match here
 %0 = getelementptr inbounds nuw [58 x double], ptr @b, i64 0, i64 %index
 ^

Input file: 
Check file: 
/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/llvm-project/llvm/test/Transforms/PhaseOrdering/X86/excessive-unrolling.ll

-dump-input=help explains the following input dump.

Input was:
<<
.
.
.
  151: vector.ph: ; preds = %for.body.preheader 
  152:  %n.vec = and i64 %wide.trip.count, 2147483644 
  153:  br label %vector.body 
  154:  
  155: vector.body: ; preds = %vector.body, %vector.ph 
  156:  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body 
] 
next:182'0  
 X error: no match found
next:182'1  
   with "INDEX" equal to "%index"
  157:  %0 = getelementptr inbounds nuw [58 x double], ptr @b, i64 0, 
i64 %index 
next:182'0 
~~
next:182'2  ?   
  possible intended match
  158:  %1 = getelementptr inbounds nuw i8, ptr %0, i64 16 
next:182'0 
  159:  %wide.load = load <2 x double>, ptr %0, align 16 
next:182'0 ~~
  160:  %wide.load4 = load <2 x double>, ptr %1, align 16 
next:182'0 ~~~
  161:  %2 = getelementptr inbounds nuw [58 x double], ptr @c, i64 0, 
i64 %index 
next:182'0 
~~
...

```



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


[clang] [compiler-rt] [driver] Fix sanitizer libc++ runtime linking (PR #120370)

2024-12-18 Thread Vitaly Buka via cfe-commits

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

>From 6787146cf0e81ad8a69b3b2fadd7caf0f49c78d9 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 17 Dec 2024 23:11:12 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/Driver/SanitizerArgs.cpp  |  9 +--
 clang/test/Driver/sanitizer-ld.c| 65 -
 compiler-rt/test/hwasan/TestCases/sizes.cpp |  2 +-
 3 files changed, 70 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 81f94f23873661..0edfe641416129 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -1098,10 +1098,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
options::OPT_fno_sanitize_link_runtime, LinkRuntimes);
 
   // Parse -link-cxx-sanitizer flag.
-  LinkCXXRuntimes = Args.hasArg(options::OPT_fsanitize_link_cxx_runtime,
-options::OPT_fno_sanitize_link_cxx_runtime,
-LinkCXXRuntimes) ||
-D.CCCIsCXX();
+  LinkCXXRuntimes =
+  D.CCCIsCXX() && !Args.hasArg(clang::driver::options::OPT_nostdlibxx);
+  LinkCXXRuntimes =
+  Args.hasFlag(options::OPT_fsanitize_link_cxx_runtime,
+   options::OPT_fno_sanitize_link_cxx_runtime, 
LinkCXXRuntimes);
 
   NeedsMemProfRt = Args.hasFlag(options::OPT_fmemory_profile,
 options::OPT_fmemory_profile_EQ,
diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
index 60d60a6047b0f4..6ab1adf401ae0a 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -132,7 +132,14 @@
 // RUN: -resource-dir=%S/Inputs/empty_resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX-CXX %s
-//
+
+// RUN: %clangxx -### %s 2>&1 \
+// RUN: --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform 
-fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -fsanitize-link-c++-runtime \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX-CXX %s
+
 // CHECK-ASAN-LINUX-CXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-ASAN-LINUX-CXX-NOT: "-lc"
 // CHECK-ASAN-LINUX-CXX: "--whole-archive" "{{.*}}libclang_rt.asan.a" 
"--no-whole-archive"
@@ -145,6 +152,62 @@
 // CHECK-ASAN-LINUX-CXX: "-ldl"
 // CHECK-ASAN-LINUX-CXX: "-lresolv"
 
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform 
-fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -fno-sanitize-link-c++-runtime \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX-CNOCXX %s
+
+// CHECK-ASAN-LINUX-CNOCXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-LINUX-CNOCXX-NOT: "-lc"
+// CHECK-ASAN-LINUX-CNOCXX: "--whole-archive" "{{.*}}libclang_rt.asan.a" 
"--no-whole-archive"
+// CHECK-ASAN-LINUX-CNOCXX-NOT: libclang_rt.asan_cxx
+// CHECK-ASAN-LINUX-CNOCXX-NOT: "--dynamic-list"
+// CHECK-ASAN-LINUX-CNOCXX: "--export-dynamic"
+// CHECK-ASAN-LINUX-CNOCXX-NOT: stdc++
+// CHECK-ASAN-LINUX-CNOCXX: "-lpthread"
+// CHECK-ASAN-LINUX-CNOCXX: "-lrt"
+// CHECK-ASAN-LINUX-CNOCXX: "-ldl"
+// CHECK-ASAN-LINUX-CNOCXX: "-lresolv"
+
+// RUN: %clangxx -### %s 2>&1 \
+// RUN: --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform 
-fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -fno-sanitize-link-c++-runtime \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX-NOCXX %s
+
+// CHECK-ASAN-LINUX-NOCXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-LINUX-NOCXX-NOT: "-lc"
+// CHECK-ASAN-LINUX-NOCXX: "--whole-archive" "{{.*}}libclang_rt.asan.a" 
"--no-whole-archive"
+// CHECK-ASAN-LINUX-NOCXX-NOT: libclang_rt.asan_cxx
+// CHECK-ASAN-LINUX-NOCXX-NOT: "--dynamic-list"
+// CHECK-ASAN-LINUX-NOCXX: "--export-dynamic"
+// CHECK-ASAN-LINUX-NOCXX: stdc++
+// CHECK-ASAN-LINUX-NOCXX: "-lpthread"
+// CHECK-ASAN-LINUX-NOCXX: "-lrt"
+// CHECK-ASAN-LINUX-NOCXX: "-ldl"
+// CHECK-ASAN-LINUX-NOCXX: "-lresolv"
+
+// RUN: %clangxx -### %s 2>&1 \
+// RUN: --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform 
-fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -nostdlib++ \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX-NOSTDCXX %s
+
+// CHECK-ASAN-LINUX-NOSTDCXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-LINUX-NOSTDCXX-NOT: "-lc"
+// CHECK-ASAN-LINUX-NOSTDCXX: "--whole

[clang] [compiler-rt] [driver] Fix sanitizer libc++ runtime linking (PR #120370)

2024-12-18 Thread Vitaly Buka via cfe-commits

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


[clang] 9af5de3 - [driver] Fix sanitizer libc++ runtime linking (#120370)

2024-12-18 Thread via cfe-commits

Author: Vitaly Buka
Date: 2024-12-18T10:37:44-08:00
New Revision: 9af5de320b77d3757ea2b7e3d85c67f88dfbabb5

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

LOG: [driver] Fix sanitizer libc++ runtime linking (#120370)

1. -f[no-]sanitize-link-c++-runtime suppose to
   override defauld behavior implied from `CCCIsCXX`
2. Take into account -nostdlib++ (unblocks #108357)
3. Fix typo hasFlag vs hasArg.

Added: 


Modified: 
clang/lib/Driver/SanitizerArgs.cpp
clang/test/Driver/sanitizer-ld.c
compiler-rt/test/hwasan/TestCases/sizes.cpp

Removed: 




diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 81f94f23873661..0edfe641416129 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -1098,10 +1098,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
options::OPT_fno_sanitize_link_runtime, LinkRuntimes);
 
   // Parse -link-cxx-sanitizer flag.
-  LinkCXXRuntimes = Args.hasArg(options::OPT_fsanitize_link_cxx_runtime,
-options::OPT_fno_sanitize_link_cxx_runtime,
-LinkCXXRuntimes) ||
-D.CCCIsCXX();
+  LinkCXXRuntimes =
+  D.CCCIsCXX() && !Args.hasArg(clang::driver::options::OPT_nostdlibxx);
+  LinkCXXRuntimes =
+  Args.hasFlag(options::OPT_fsanitize_link_cxx_runtime,
+   options::OPT_fno_sanitize_link_cxx_runtime, 
LinkCXXRuntimes);
 
   NeedsMemProfRt = Args.hasFlag(options::OPT_fmemory_profile,
 options::OPT_fmemory_profile_EQ,

diff  --git a/clang/test/Driver/sanitizer-ld.c 
b/clang/test/Driver/sanitizer-ld.c
index 60d60a6047b0f4..3d55bd33cc0d15 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -132,18 +132,81 @@
 // RUN: -resource-dir=%S/Inputs/empty_resource_dir \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX-CXX %s
-//
-// CHECK-ASAN-LINUX-CXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+
+// RUN: %clangxx -### %s 2>&1 \
+// RUN: --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform 
-fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -fsanitize-link-c++-runtime \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX-CXX %s
+
 // CHECK-ASAN-LINUX-CXX-NOT: "-lc"
-// CHECK-ASAN-LINUX-CXX: "--whole-archive" "{{.*}}libclang_rt.asan.a" 
"--no-whole-archive"
-// CHECK-ASAN-LINUX-CXX: "--whole-archive" "{{.*}}libclang_rt.asan_cxx.a" 
"--no-whole-archive"
 // CHECK-ASAN-LINUX-CXX-NOT: "--dynamic-list"
-// CHECK-ASAN-LINUX-CXX: "--export-dynamic"
-// CHECK-ASAN-LINUX-CXX: stdc++
-// CHECK-ASAN-LINUX-CXX: "-lpthread"
-// CHECK-ASAN-LINUX-CXX: "-lrt"
-// CHECK-ASAN-LINUX-CXX: "-ldl"
-// CHECK-ASAN-LINUX-CXX: "-lresolv"
+// CHECK-ASAN-LINUX-CXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-LINUX-CXX-SAME: "--whole-archive" "{{.*}}libclang_rt.asan.a" 
"--no-whole-archive"
+// CHECK-ASAN-LINUX-CXX-SAME: "--whole-archive" "{{.*}}libclang_rt.asan_cxx.a" 
"--no-whole-archive"
+// CHECK-ASAN-LINUX-CXX-SAME: "--export-dynamic"
+// CHECK-ASAN-LINUX-CXX-SAME: stdc++
+// CHECK-ASAN-LINUX-CXX-SAME: "-lpthread"
+// CHECK-ASAN-LINUX-CXX-SAME: "-lrt"
+// CHECK-ASAN-LINUX-CXX-SAME: "-ldl"
+// CHECK-ASAN-LINUX-CXX-SAME: "-lresolv"
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform 
-fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -fno-sanitize-link-c++-runtime \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX-CNOCXX %s
+
+// CHECK-ASAN-LINUX-CNOCXX-NOT: "-lc"
+// CHECK-ASAN-LINUX-CNOCXX-NOT: libclang_rt.asan_cxx
+// CHECK-ASAN-LINUX-CNOCXX-NOT: "--dynamic-list"
+// CHECK-ASAN-LINUX-CNOCXX-NOT: stdc++
+// CHECK-ASAN-LINUX-CNOCXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-ASAN-LINUX-CNOCXX-SAME: "--whole-archive" "{{.*}}libclang_rt.asan.a" 
"--no-whole-archive"
+// CHECK-ASAN-LINUX-CNOCXX-SAME: "--export-dynamic"
+// CHECK-ASAN-LINUX-CNOCXX-SAME: "-lpthread"
+// CHECK-ASAN-LINUX-CNOCXX-SAME: "-lrt"
+// CHECK-ASAN-LINUX-CNOCXX-SAME: "-ldl"
+// CHECK-ASAN-LINUX-CNOCXX-SAME: "-lresolv"
+
+// RUN: %clangxx -### %s 2>&1 \
+// RUN: --target=i386-unknown-linux -fuse-ld=ld -stdlib=platform 
-fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN: -fno-sanitize-link-c++-runtime \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-LINUX-NOCXX %s
+
+// CHECK-ASAN-LINUX-NOCXX-NOT: "-lc"
+// CHECK-ASAN-LINUX-NOCXX-NOT: libcl

  1   2   3   4   5   6   >