[clang] [llvm] [HLSL] Implement a header only distance intrinsic (PR #117240)

2025-01-06 Thread Farzon Lotfi via cfe-commits

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

>From 271141588db106f888dd6abb3ad7da41732a4f52 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Thu, 21 Nov 2024 14:46:31 -0500
Subject: [PATCH] [HLSL] Implement a header only distance intrinsic

Addressing RFC comments, replace LangBuiltin with TargetBuiltin
---
 clang/include/clang/Basic/Builtins.td |   6 -
 clang/include/clang/Basic/BuiltinsSPIRV.td|   6 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  24 +-
 clang/lib/CodeGen/CGHLSLRuntime.h |   1 -
 clang/lib/Headers/hlsl/hlsl_detail.h  |  42 +++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  57 ++--
 clang/lib/Sema/SemaHLSL.cpp   |  21 +-
 clang/lib/Sema/SemaSPIRV.cpp  |  18 ++
 clang/test/CodeGenHLSL/builtins/distance.hlsl | 141 ++
 clang/test/CodeGenHLSL/builtins/length.hlsl   | 232 +++-
 .../SemaHLSL/BuiltIns/distance-errors.hlsl|  33 +++
 .../test/SemaHLSL/BuiltIns/length-errors.hlsl |  51 +++-
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   1 -
 .../Target/DirectX/DXILIntrinsicExpansion.cpp |  30 --
 llvm/test/CodeGen/DirectX/length.ll   | 261 --
 llvm/test/CodeGen/DirectX/length_error.ll |  10 -
 .../DirectX/length_invalid_intrinsic_error.ll |  10 -
 .../length_invalid_intrinsic_error_scalar.ll  |  10 -
 18 files changed, 664 insertions(+), 290 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/distance.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/distance-errors.hlsl
 delete mode 100644 llvm/test/CodeGen/DirectX/length_error.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error.ll
 delete mode 100644 
llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error_scalar.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 468c16050e2bf0..f4216bd01a0743 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4865,12 +4865,6 @@ def HLSLIsinf : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
-def HLSLLength : LangBuiltin<"HLSL_LANG"> {
-  let Spellings = ["__builtin_hlsl_length"];
-  let Attributes = [NoThrow, Const];
-  let Prototype = "void(...)";
-}
-
 def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_lerp"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td 
b/clang/include/clang/Basic/BuiltinsSPIRV.td
index 1e66939b822ef8..f72c555921dfe6 100644
--- a/clang/include/clang/Basic/BuiltinsSPIRV.td
+++ b/clang/include/clang/Basic/BuiltinsSPIRV.td
@@ -13,3 +13,9 @@ def SPIRVDistance : Builtin {
   let Attributes = [NoThrow, Const];
   let Prototype = "void(...)";
 }
+
+def SPIRVLength : Builtin {
+  let Spellings = ["__builtin_spirv_length"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5cd893d70695c8..29c1dd19ba7105 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19332,20 +19332,6 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType=*/X->getType(), CGM.getHLSLRuntime().getLerpIntrinsic(),
 ArrayRef{X, Y, S}, nullptr, "hlsl.lerp");
   }
-  case Builtin::BI__builtin_hlsl_length: {
-Value *X = EmitScalarExpr(E->getArg(0));
-
-assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
-   "length operand must have a float representation");
-// if the operand is a scalar, we can use the fabs llvm intrinsic directly
-if (!E->getArg(0)->getType()->isVectorType())
-  return EmitFAbs(*this, X);
-
-return Builder.CreateIntrinsic(
-/*ReturnType=*/X->getType()->getScalarType(),
-CGM.getHLSLRuntime().getLengthIntrinsic(), ArrayRef{X},
-nullptr, "hlsl.length");
-  }
   case Builtin::BI__builtin_hlsl_normalize: {
 Value *X = EmitScalarExpr(E->getArg(0));
 
@@ -20498,6 +20484,16 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_distance,
 ArrayRef{X, Y}, nullptr, "spv.distance");
   }
+  case SPIRV::BI__builtin_spirv_length: {
+Value *X = EmitScalarExpr(E->getArg(0));
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+   "length operand must have a float representation");
+assert(E->getArg(0)->getType()->isVectorType() &&
+   "length operand must be a vector");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_length,
+ArrayRef{X}, nullptr, "hlsl.length");
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 3d5724118611cb..780ea6426ee7c8 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CG

[clang] [llvm] [HLSL] Implement a header only distance intrinsic (PR #117240)

2025-01-06 Thread Farzon Lotfi via cfe-commits

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

>From 89507233b8b7ac859e1abbedb97e69574e54dfc8 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Thu, 21 Nov 2024 14:46:31 -0500
Subject: [PATCH] [HLSL] Implement a header only distance intrinsic

Addressing RFC comments, replace LangBuiltin with TargetBuiltin
---
 clang/include/clang/Basic/Builtins.td |   6 -
 clang/include/clang/Basic/BuiltinsSPIRV.td|   6 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  24 +-
 clang/lib/CodeGen/CGHLSLRuntime.h |   1 -
 clang/lib/Headers/hlsl/hlsl_detail.h  |  42 +++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  57 ++--
 clang/lib/Sema/SemaHLSL.cpp   |  21 +-
 clang/lib/Sema/SemaSPIRV.cpp  |  18 ++
 clang/test/CodeGenHLSL/builtins/distance.hlsl | 141 ++
 clang/test/CodeGenHLSL/builtins/length.hlsl   | 232 +++-
 .../SemaHLSL/BuiltIns/distance-errors.hlsl|  33 +++
 .../test/SemaHLSL/BuiltIns/length-errors.hlsl |  51 +++-
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   1 -
 .../Target/DirectX/DXILIntrinsicExpansion.cpp |  31 +--
 llvm/test/CodeGen/DirectX/length.ll   | 261 --
 llvm/test/CodeGen/DirectX/length_error.ll |  10 -
 .../DirectX/length_invalid_intrinsic_error.ll |  10 -
 .../length_invalid_intrinsic_error_scalar.ll  |  10 -
 18 files changed, 665 insertions(+), 290 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/distance.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/distance-errors.hlsl
 delete mode 100644 llvm/test/CodeGen/DirectX/length_error.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error.ll
 delete mode 100644 
llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error_scalar.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 468c16050e2bf0..f4216bd01a0743 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4865,12 +4865,6 @@ def HLSLIsinf : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
-def HLSLLength : LangBuiltin<"HLSL_LANG"> {
-  let Spellings = ["__builtin_hlsl_length"];
-  let Attributes = [NoThrow, Const];
-  let Prototype = "void(...)";
-}
-
 def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_lerp"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td 
b/clang/include/clang/Basic/BuiltinsSPIRV.td
index 1e66939b822ef8..f72c555921dfe6 100644
--- a/clang/include/clang/Basic/BuiltinsSPIRV.td
+++ b/clang/include/clang/Basic/BuiltinsSPIRV.td
@@ -13,3 +13,9 @@ def SPIRVDistance : Builtin {
   let Attributes = [NoThrow, Const];
   let Prototype = "void(...)";
 }
+
+def SPIRVLength : Builtin {
+  let Spellings = ["__builtin_spirv_length"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5cd893d70695c8..29c1dd19ba7105 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19332,20 +19332,6 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType=*/X->getType(), CGM.getHLSLRuntime().getLerpIntrinsic(),
 ArrayRef{X, Y, S}, nullptr, "hlsl.lerp");
   }
-  case Builtin::BI__builtin_hlsl_length: {
-Value *X = EmitScalarExpr(E->getArg(0));
-
-assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
-   "length operand must have a float representation");
-// if the operand is a scalar, we can use the fabs llvm intrinsic directly
-if (!E->getArg(0)->getType()->isVectorType())
-  return EmitFAbs(*this, X);
-
-return Builder.CreateIntrinsic(
-/*ReturnType=*/X->getType()->getScalarType(),
-CGM.getHLSLRuntime().getLengthIntrinsic(), ArrayRef{X},
-nullptr, "hlsl.length");
-  }
   case Builtin::BI__builtin_hlsl_normalize: {
 Value *X = EmitScalarExpr(E->getArg(0));
 
@@ -20498,6 +20484,16 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_distance,
 ArrayRef{X, Y}, nullptr, "spv.distance");
   }
+  case SPIRV::BI__builtin_spirv_length: {
+Value *X = EmitScalarExpr(E->getArg(0));
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+   "length operand must have a float representation");
+assert(E->getArg(0)->getType()->isVectorType() &&
+   "length operand must be a vector");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_length,
+ArrayRef{X}, nullptr, "hlsl.length");
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 3d5724118611cb..780ea6426ee7c8 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/C

[clang] [llvm] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. (PR #105738)

2025-01-06 Thread Tom Honermann via cfe-commits

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


[clang] [clang] Fix crashes when passing VLA to va_arg (PR #119563)

2025-01-06 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

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


[clang] [libclang/python] Add python bindings for PrintingPolicy (PR #120494)

2025-01-06 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

@DeinAlptraum any idea why the Python tests are failing?

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


[clang] [llvm] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. (PR #105738)

2025-01-06 Thread Tom Honermann via cfe-commits

tahonermann wrote:

I've been continuing to work on this, but have yet to get all of our internal 
tests to pass. I've reverted the PR to a draft pending successful internal 
testing.

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Vitaly Buka via cfe-commits


@@ -186,10 +188,24 @@ struct SanitizerSet {
 /// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
 SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups);
 
+/// Parse a single weighted value (e.g., 'undefined=0.05') from a -fsanitize= 
or
+/// -fno-sanitize= value list.
+/// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
+/// The relevant weight(s) are updated in the passed array.
+/// Individual Cutoffs are never reset to zero unless explicitly set
+/// (e.g., 'null=0.0').
+SanitizerMask parseSanitizerWeightedValue(StringRef Value, bool AllowGroups,

vitalybuka wrote:

Inconsistency here is not nice - parse returns SanitizerMask and 
SanitizerMaskCutoffs
but serialize takes into account only SanitizerMaskCutoffs

If SanitizerMask is optimization for faster checks, better to create it where 
it used

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


[clang] 737d6ca - [RISCV] Add Qualcomm uC Xqcicm (Conditional Move) extension (#121752)

2025-01-06 Thread via cfe-commits

Author: quic_hchandel
Date: 2025-01-07T08:25:00+05:30
New Revision: 737d6ca44d383bcf33a0605a7d9014027296269a

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

LOG: [RISCV] Add Qualcomm uC Xqcicm (Conditional Move) extension  (#121752)

The Qualcomm uC Xqcicm extension adds 13 conditional move instructions.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.

-

Co-authored-by: Harsh Chandel 

Added: 
llvm/test/MC/RISCV/xqcicm-invalid.s
llvm/test/MC/RISCV/xqcicm-valid.s

Modified: 
clang/test/Driver/print-supported-extensions-riscv.c
llvm/docs/RISCVUsage.rst
llvm/docs/ReleaseNotes.md
llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
llvm/lib/TargetParser/RISCVISAInfo.cpp
llvm/test/CodeGen/RISCV/attributes.ll
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index f08ff00c9cbeb8..a8d9fcd8569cfb 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -193,6 +193,7 @@
 // CHECK-NEXT: xqcia0.2   'Xqcia' (Qualcomm uC 
Arithmetic Extension)
 // CHECK-NEXT: xqciac   0.2   'Xqciac' (Qualcomm uC 
Load-Store Address Calculation Extension)
 // CHECK-NEXT: xqcicli  0.2   'Xqcicli' (Qualcomm uC 
Conditional Load Immediate Extension)
+// CHECK-NEXT: xqcicm   0.2   'Xqcicm' (Qualcomm uC 
Conditional Move Extension)
 // CHECK-NEXT: xqcics   0.2   'Xqcics' (Qualcomm uC 
Conditional Select Extension)
 // CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-NEXT: xqcilsm  0.2   'Xqcilsm' (Qualcomm uC Load 
Store Multiple Extension)

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 835b910ec452da..0dc63f34806b4c 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -438,6 +438,9 @@ The current vendor extensions supported are:
 ``experimental-Xqcicli``
   LLVM implements `version 0.2 of the Qualcomm uC Conditional Load Immediate 
extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
+``experimental-Xqcicm``
+  LLVM implements `version 0.2 of the Qualcomm uC Conditional Move extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
+
 ``experimental-Xqcics``
   LLVM implements `version 0.2 of the Qualcomm uC Conditional Select extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
 

diff  --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 11ee9864e5174d..159bd5cea973f8 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -232,6 +232,8 @@ Changes to the RISC-V Backend
   extension.
 * Adds experimental assembler support for the Qualcomm uC 'Xqcicli` 
(Conditional Load Immediate)
   extension.
+* Adds experimental assembler support for the Qualcomm uC 'Xqcicm` (Conditonal 
Move)
+  extension.
 * Added ``Sdext`` and ``Sdtrig`` extensions.
 
 Changes to the WebAssembly Backend

diff  --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index 30122831767f61..a490910154eb4d 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -698,6 +698,8 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst 
&MI, uint64_t &Size,
   TRY_TO_DECODE_FEATURE(
   RISCV::FeatureVendorXqcicli, DecoderTableXqcicli32,
   "Qualcomm uC Conditional Load Immediate custom opcode table");
+  TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicm, DecoderTableXqcicm32,
+"Qualcomm uC Conditional Move custom opcode table");
   TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table");
 
   return MCDisassembler::Fail;
@@ -727,6 +729,9 @@ DecodeStatus RISCVDisassembler::getInstruction16(MCInst 
&MI, uint64_t &Size,
   TRY_TO_DECODE_FEATURE(
   RISCV::FeatureVendorXqciac, DecoderTableXqc

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicm (Conditional Move) extension (PR #121752)

2025-01-06 Thread Sudharsan Veeravalli via cfe-commits

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


[clang] Deprecate order file instrumentation (PR #121514)

2025-01-06 Thread Ellis Hoag via cfe-commits


@@ -8010,15 +8010,19 @@ void Clang::ConstructJob(Compilation &C, const 
JobAction &JA,
 }
   }
 
-  if (Args.hasArg(options::OPT_forder_file_instrumentation)) {
- CmdArgs.push_back("-forder-file-instrumentation");
- // Enable order file instrumentation when ThinLTO is not on. When ThinLTO 
is
- // on, we need to pass these flags as linker flags and that will be 
handled
- // outside of the compiler.
- if (!IsUsingLTO) {
-   CmdArgs.push_back("-mllvm");
-   CmdArgs.push_back("-enable-order-file-instrumentation");
- }
+  if (const Arg *A =
+  Args.getLastArg(options::OPT_forder_file_instrumentation)) {
+D.Diag(diag::warn_drv_deprecated_arg)
+<< A->getAsString(Args) << /*hasReplacement=*/true
+<< "-mllvm -pgo-temporal-instrumentation";

ellishg wrote:

These flags are extensively documented in this 
[RFC](https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068/7)
 and this [EuroLLVM talk](https://youtu.be/yd4pbSTjwuA). And LLVM options do 
have descriptions like clang frontend flags. I think it might be overkill to 
turn this into a frontend flag.

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Thurston Dang via cfe-commits

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

>From ca1fabc5ea75af0acdd1969c0ad505e04103e1c9 Mon Sep 17 00:00:00 2001
From: Thurston Dang 
Date: Sat, 4 Jan 2025 02:53:00 +
Subject: [PATCH 1/9] [sanitizer] Parse weighted sanitizer args and
 -fno-sanitize-top-hot

This adds a function to parse weighted sanitizer flags (e.g.,
-fsanitize-blah=undefined=0.5,null=0.3) and adds the plumbing to
apply that to -fno-sanitize-top-hot from the frontend to backend.

-fno-sanitize-top-hot currently has no effect; future work will
use it to generalize ubsan-guard-checks (originaly introduced in 
5f9ed2ff8364ff3e4fac410472f421299dafa793).
---
 clang/include/clang/Basic/CodeGenOptions.h |  4 ++
 clang/include/clang/Basic/Sanitizers.h | 14 +
 clang/include/clang/Driver/Options.td  |  7 +++
 clang/include/clang/Driver/SanitizerArgs.h |  1 +
 clang/lib/Basic/Sanitizers.cpp | 38 
 clang/lib/Driver/SanitizerArgs.cpp | 69 +-
 clang/lib/Frontend/CompilerInvocation.cpp  |  5 ++
 7 files changed, 124 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 8097c9ef772bc7..f69f52e49a2fe9 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -384,6 +384,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// the expense of debuggability).
   SanitizerSet SanitizeMergeHandlers;
 
+  /// Set of top hotness thresholds, specifying the fraction of code that is
+  /// excluded from sanitization (0 = skip none, 0.1 = skip hottest 10%, 1.0 = 
skip all).
+  SanitizerMaskWeights NoSanitizeTopHot = {0};
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Basic/Sanitizers.h 
b/clang/include/clang/Basic/Sanitizers.h
index c890242269b334..fa6b557819a1a1 100644
--- a/clang/include/clang/Basic/Sanitizers.h
+++ b/clang/include/clang/Basic/Sanitizers.h
@@ -154,6 +154,8 @@ struct SanitizerKind {
 #include "clang/Basic/Sanitizers.def"
 }; // SanitizerKind
 
+typedef double SanitizerMaskWeights[SanitizerKind::SO_Count];
+
 struct SanitizerSet {
   /// Check if a certain (single) sanitizer is enabled.
   bool has(SanitizerMask K) const {
@@ -186,10 +188,22 @@ struct SanitizerSet {
 /// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
 SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups);
 
+/// Parse a single weighted value (e.g., 'undefined=0.05') from a -fsanitize= 
or
+/// -fno-sanitize= value list.
+/// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
+/// The relevant weight(s) are updated in the passed array.
+/// Individual weights are never reset to zero unless explicitly set
+/// (e.g., 'null=0.0').
+SanitizerMask parseSanitizerWeightedValue(StringRef Value, bool AllowGroups, 
SanitizerMaskWeights Weights);
+
 /// Serialize a SanitizerSet into values for -fsanitize= or -fno-sanitize=.
 void serializeSanitizerSet(SanitizerSet Set,
SmallVectorImpl &Values);
 
+/// Serialize a SanitizerMaskWeights into values for -fsanitize= or 
-fno-sanitize=.
+void serializeSanitizerMaskWeights(const SanitizerMaskWeights Weights,
+   SmallVectorImpl &Values);
+
 /// For each sanitizer group bit set in \p Kinds, set the bits for sanitizers
 /// this group enables.
 SanitizerMask expandSanitizerGroups(SanitizerMask Kinds);
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d922709db17786..631a6099781e6c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2649,6 +2649,13 @@ def fsanitize_undefined_strip_path_components_EQ : 
Joined<["-"], "fsanitize-unde
   HelpText<"Strip (or keep only, if negative) a given number of path 
components "
"when emitting check metadata.">,
   MarshallingInfoInt, "0", 
"int">;
+def fno_sanitize_top_hot_EQ
+: CommaJoined<["-"], "fno-sanitize-top-hot=">,
+  Group,
+  HelpText<"Skip sanitization for the fraction of top hottest code "
+   "(0.0 [default] = do not skip any sanitization; "
+   "0.1 = skip the hottest 10% of code; "
+   "1.0 = skip all sanitization)">;
 
 } // end -f[no-]sanitize* flags
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 3b275092bbbe86..854893269e8543 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -26,6 +26,7 @@ class SanitizerArgs {
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
   SanitizerSet MergeHandlers;
+  SanitizerMaskWeights TopHot = {0};
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/lib/Basic/Sanitizers.cpp b/clang/lib/Basic/Sa

[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Thurston Dang via cfe-commits


@@ -154,6 +154,8 @@ struct SanitizerKind {
 #include "clang/Basic/Sanitizers.def"
 }; // SanitizerKind
 
+typedef double SanitizerMaskWeights[SanitizerKind::SO_Count];

thurstond wrote:

Done

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Thurston Dang via cfe-commits


@@ -2649,6 +2649,11 @@ def fsanitize_undefined_strip_path_components_EQ : 
Joined<["-"], "fsanitize-unde
   HelpText<"Strip (or keep only, if negative) a given number of path 
components "
"when emitting check metadata.">,
   MarshallingInfoInt, "0", 
"int">;
+def fno_sanitize_top_hot_EQ
+: CommaJoined<["-"], "fno-sanitize-top-hot=">,
+  Group,
+  HelpText<"Exclude sanitization for the top hottest fraction of code "

thurstond wrote:

Done

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Thurston Dang via cfe-commits


@@ -2649,6 +2649,11 @@ def fsanitize_undefined_strip_path_components_EQ : 
Joined<["-"], "fsanitize-unde
   HelpText<"Strip (or keep only, if negative) a given number of path 
components "
"when emitting check metadata.">,
   MarshallingInfoInt, "0", 
"int">;
+def fno_sanitize_top_hot_EQ
+: CommaJoined<["-"], "fno-sanitize-top-hot=">,
+  Group,
+  HelpText<"Exclude sanitization for the top hottest fraction of code "

thurstond wrote:

Done

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Thurston Dang via cfe-commits


@@ -26,6 +26,8 @@ class SanitizerArgs {
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
   SanitizerSet MergeHandlers;
+  SanitizerSet TopHot;
+  SanitizerMaskWeights TopHotWeights = {0};

thurstond wrote:

Renamed to Cutoff - is that ok instead of CutoffThreshold?

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


[clang] [clang] Implement __attribute__((format_matches)) (PR #116708)

2025-01-06 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier 
Message-ID:
In-Reply-To: 


apple-fcloutier wrote:

As an update, I've been adding more tests and I found that I can make 
improvements with follow-up work. Since these aren't stability problems or 
false positives, and we think the change is already big enough, I am currently 
planning to submit them as a separate PR once this lands. The things in 
question that are addressed:

* Passing a format string with the wrong type (for instance, a `NSString` 
format string to a function accepting a `printf` format string) terminates 
verification without emitting a diagnostic. This is an issue with the `format` 
attribute too (it emits a -Wformat-nonliteral warning for it, which is bad 
categorization and unspecific about what needs to happen).
* If you have a function with `format_matches` that calls another function with 
`format_matches` passing its own format argument, Clang doesn't verify that the 
two format strings are compatible.
* `format_matches` diagnostics always point at the format string: for instance, 
directly at the format string argument in `printf("%s", "hello")`, but at the 
`fmt` variable definition in `const char *const fmt = "%s"; printf(fmt, 
"hello")`. This can create situations where the diagnostic shows the 
problematic format strings, but not the format function call that references 
them. `Format` attribute checking uses 
`CheckFormatHandler::EmitFormatDiagnostic` to ensure that the format function 
call is consistently there (either directly where the warning points, or with a 
note if the call is elsewhere). Diagnostics for `format_matches` should do that 
too.
* Reusing the "data argument not used by format string" diagnostic in the 
context of `format_matches` is not a great experience, this should be "more 
specifiers in format string than expected".

Let me know if you would like me to fold anything from this list into this PR.

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Thurston Dang via cfe-commits


@@ -3602,6 +3602,7 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *RecoverableCond = nullptr;
   llvm::Value *TrapCond = nullptr;
   bool NoMerge = false;
+  bool SanitizeGuardChecks = ClSanitizeGuardChecks;

thurstond wrote:

Noted for the next patch (this patch has been updated to be Driver changes 
only).

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Thurston Dang via cfe-commits


@@ -3615,9 +3616,12 @@ void CodeGenFunction::EmitCheck(
 

thurstond wrote:

Done

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Thurston Dang via cfe-commits

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Thurston Dang (thurstond)


Changes

This adds a function to parse weighted sanitizer flags (e.g., 
-fsanitize-blah=undefined=0.5,null=0.3) and adds the plumbing to apply that to 
a new flag, -fno-sanitize-top-hot, from the frontend to backend.

-fno-sanitize-top-hot currently has no effect; future work will use it to 
generalize ubsan-guard-checks (originaly introduced in 
5f9ed2ff8364ff3e4fac410472f421299dafa793).

---

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


9 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.h (+8) 
- (modified) clang/include/clang/Basic/Sanitizers.h (+16) 
- (modified) clang/include/clang/Driver/Options.td (+7) 
- (modified) clang/include/clang/Driver/SanitizerArgs.h (+2) 
- (modified) clang/lib/Basic/Sanitizers.cpp (+40) 
- (modified) clang/lib/Driver/SanitizerArgs.cpp (+72-23) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+24) 
- (modified) clang/test/CodeGen/allow-ubsan-check.c (-1) 
- (modified) clang/test/Driver/fsanitize.c (+19) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 8097c9ef772bc7..227bddf831002e 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -384,6 +384,14 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// the expense of debuggability).
   SanitizerSet SanitizeMergeHandlers;
 
+  /// Set of thresholds: the top hottest code responsible for the given
+  /// fraction of PGO counters will be excluded from sanitization
+  /// (0.0 [default] = skip none, 1.0 = skip all).
+  SanitizerSet NoSanitizeTopHot;
+  /// N.B. The cutoffs contain strictly more information than the SanitizerSet,
+  /// but the SanitizerSet is more efficient for some calculations.
+  SanitizerMaskCutoffs NoSanitizeTopHotCutoffs = {0};
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Basic/Sanitizers.h 
b/clang/include/clang/Basic/Sanitizers.h
index c890242269b334..12c2c93a7f89f6 100644
--- a/clang/include/clang/Basic/Sanitizers.h
+++ b/clang/include/clang/Basic/Sanitizers.h
@@ -154,6 +154,8 @@ struct SanitizerKind {
 #include "clang/Basic/Sanitizers.def"
 }; // SanitizerKind
 
+using SanitizerMaskCutoffs = std::array;
+
 struct SanitizerSet {
   /// Check if a certain (single) sanitizer is enabled.
   bool has(SanitizerMask K) const {
@@ -186,10 +188,24 @@ struct SanitizerSet {
 /// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
 SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups);
 
+/// Parse a single weighted value (e.g., 'undefined=0.05') from a -fsanitize= 
or
+/// -fno-sanitize= value list.
+/// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
+/// The relevant weight(s) are updated in the passed array.
+/// Individual Cutoffs are never reset to zero unless explicitly set
+/// (e.g., 'null=0.0').
+SanitizerMask parseSanitizerWeightedValue(StringRef Value, bool AllowGroups,
+  SanitizerMaskCutoffs *Cutoffs);
+
 /// Serialize a SanitizerSet into values for -fsanitize= or -fno-sanitize=.
 void serializeSanitizerSet(SanitizerSet Set,
SmallVectorImpl &Values);
 
+/// Serialize a SanitizerMaskCutoffs into values for -fsanitize= or
+/// -fno-sanitize=.
+void serializeSanitizerMaskCutoffs(const SanitizerMaskCutoffs Cutoffs,
+   SmallVectorImpl &Values);
+
 /// For each sanitizer group bit set in \p Kinds, set the bits for sanitizers
 /// this group enables.
 SanitizerMask expandSanitizerGroups(SanitizerMask Kinds);
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d922709db17786..027093157d4c73 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2649,6 +2649,13 @@ def fsanitize_undefined_strip_path_components_EQ : 
Joined<["-"], "fsanitize-unde
   HelpText<"Strip (or keep only, if negative) a given number of path 
components "
"when emitting check metadata.">,
   MarshallingInfoInt, "0", 
"int">;
+def fno_sanitize_top_hot_EQ
+: CommaJoined<["-"], "fno-sanitize-top-hot=">,
+  Group,
+  HelpText<"Exclude sanitization for the top hottest code responsible for "
+   "the given fraction of PGO counters "
+   "(0.0 [default] = skip none; 1.0 = skip all). "
+   "Argument format: =,=,...">;
 
 } // end -f[no-]sanitize* flags
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 3b275092bbbe86..2462228f533746 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -26,6 +26,8 @@ class SanitizerArgs {
   SanitizerSet

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

2025-01-06 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 `max_work_group_size`. (PR #116820)

2025-01-06 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] [llvm] [RISCV] Add a generic OOO CPU (PR #120712)

2025-01-06 Thread Min-Yih Hsu via cfe-commits

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Thurston Dang (thurstond)


Changes

This adds a function to parse weighted sanitizer flags (e.g., 
-fsanitize-blah=undefined=0.5,null=0.3) and adds the plumbing to apply that to 
a new flag, -fno-sanitize-top-hot, from the frontend to backend.

-fno-sanitize-top-hot currently has no effect; future work will use it to 
generalize ubsan-guard-checks (originaly introduced in 
5f9ed2ff8364ff3e4fac410472f421299dafa793).

---

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


9 Files Affected:

- (modified) clang/include/clang/Basic/CodeGenOptions.h (+8) 
- (modified) clang/include/clang/Basic/Sanitizers.h (+16) 
- (modified) clang/include/clang/Driver/Options.td (+7) 
- (modified) clang/include/clang/Driver/SanitizerArgs.h (+2) 
- (modified) clang/lib/Basic/Sanitizers.cpp (+40) 
- (modified) clang/lib/Driver/SanitizerArgs.cpp (+72-23) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+24) 
- (modified) clang/test/CodeGen/allow-ubsan-check.c (-1) 
- (modified) clang/test/Driver/fsanitize.c (+19) 


``diff
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 8097c9ef772bc7..227bddf831002e 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -384,6 +384,14 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// the expense of debuggability).
   SanitizerSet SanitizeMergeHandlers;
 
+  /// Set of thresholds: the top hottest code responsible for the given
+  /// fraction of PGO counters will be excluded from sanitization
+  /// (0.0 [default] = skip none, 1.0 = skip all).
+  SanitizerSet NoSanitizeTopHot;
+  /// N.B. The cutoffs contain strictly more information than the SanitizerSet,
+  /// but the SanitizerSet is more efficient for some calculations.
+  SanitizerMaskCutoffs NoSanitizeTopHotCutoffs = {0};
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Basic/Sanitizers.h 
b/clang/include/clang/Basic/Sanitizers.h
index c890242269b334..12c2c93a7f89f6 100644
--- a/clang/include/clang/Basic/Sanitizers.h
+++ b/clang/include/clang/Basic/Sanitizers.h
@@ -154,6 +154,8 @@ struct SanitizerKind {
 #include "clang/Basic/Sanitizers.def"
 }; // SanitizerKind
 
+using SanitizerMaskCutoffs = std::array;
+
 struct SanitizerSet {
   /// Check if a certain (single) sanitizer is enabled.
   bool has(SanitizerMask K) const {
@@ -186,10 +188,24 @@ struct SanitizerSet {
 /// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
 SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups);
 
+/// Parse a single weighted value (e.g., 'undefined=0.05') from a -fsanitize= 
or
+/// -fno-sanitize= value list.
+/// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
+/// The relevant weight(s) are updated in the passed array.
+/// Individual Cutoffs are never reset to zero unless explicitly set
+/// (e.g., 'null=0.0').
+SanitizerMask parseSanitizerWeightedValue(StringRef Value, bool AllowGroups,
+  SanitizerMaskCutoffs *Cutoffs);
+
 /// Serialize a SanitizerSet into values for -fsanitize= or -fno-sanitize=.
 void serializeSanitizerSet(SanitizerSet Set,
SmallVectorImpl &Values);
 
+/// Serialize a SanitizerMaskCutoffs into values for -fsanitize= or
+/// -fno-sanitize=.
+void serializeSanitizerMaskCutoffs(const SanitizerMaskCutoffs Cutoffs,
+   SmallVectorImpl &Values);
+
 /// For each sanitizer group bit set in \p Kinds, set the bits for sanitizers
 /// this group enables.
 SanitizerMask expandSanitizerGroups(SanitizerMask Kinds);
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d922709db17786..027093157d4c73 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2649,6 +2649,13 @@ def fsanitize_undefined_strip_path_components_EQ : 
Joined<["-"], "fsanitize-unde
   HelpText<"Strip (or keep only, if negative) a given number of path 
components "
"when emitting check metadata.">,
   MarshallingInfoInt, "0", 
"int">;
+def fno_sanitize_top_hot_EQ
+: CommaJoined<["-"], "fno-sanitize-top-hot=">,
+  Group,
+  HelpText<"Exclude sanitization for the top hottest code responsible for "
+   "the given fraction of PGO counters "
+   "(0.0 [default] = skip none; 1.0 = skip all). "
+   "Argument format: =,=,...">;
 
 } // end -f[no-]sanitize* flags
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 3b275092bbbe86..2462228f533746 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -26,6 +26,8 @@ class SanitizerArgs {
   Sanit

[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Thurston Dang via cfe-commits


@@ -154,6 +154,8 @@ struct SanitizerKind {
 #include "clang/Basic/Sanitizers.def"
 }; // SanitizerKind
 
+typedef double SanitizerMaskWeights[SanitizerKind::SO_Count];

thurstond wrote:

Done

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


[clang] [clang] add llvm abi support (PR #121123)

2025-01-06 Thread Chris B via cfe-commits


@@ -1531,7 +1531,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 
   // Check if the environment version is valid except wasm case.
   llvm::Triple Triple = TC.getTriple();
-  if (!Triple.isWasm()) {
+  if (!Triple.isWasm() && Triple.getEnvironment() != llvm::Triple::LLVM) {

llvm-beanz wrote:

This seems wrong to me. Opting out of here makes me think there is something 
wrong with how the LLVM environment was implemented in the triple.

The Wasm case is special because (apparently) it is supported to pass arbitrary 
non-environment values in the triple (see discussion: 
https://github.com/llvm/llvm-project/pull/78655#issuecomment-1928458721).

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


[clang] [llvm] [NFC] fix up typos (PR #121842)

2025-01-06 Thread Justin Bogner via cfe-commits

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


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


[clang] [llvm] [Arm] Regenerate tests (NFC) (PR #121801)

2025-01-06 Thread Momchil Velikov via cfe-commits

momchil-velikov wrote:

> > This patch adds instcombine to some tests that were passing
> Can the instcombines be replaced with something simpler like dce or maybe 
> instsimplify? It might be OK with just mem2reg.

Unfortunately just `mem2reg` does not cut it. The original issue it that Clang 
generates very different code for C-style
cast and `__builtin_bit_cast`, e.g. for (https://gcc.godbolt.org/z/7rKqhTY5W)
```
typedef __attribute__((neon_vector_type(4))) unsigned uint32x4_t;
typedef __attribute__((neon_vector_type(4))) float float32x4_t;

uint32x4_t f(float32x4_t v) {
  return __builtin_bit_cast(uint32x4_t ,v);
}

uint32x4_t g(float32x4_t v) {
  return (uint32x4_t) v;
}
```
and the differences persist after `mem2reg` :
```
define dso_local <4 x i32> @f(<4 x float> noundef %v) #0 {
entry:
  %v.addr = alloca <4 x float>, align 16
  store <4 x float> %v, ptr %v.addr, align 16
  %0 = load <4 x i32>, ptr %v.addr, align 16
  ret <4 x i32> %0
}

define dso_local <4 x i32> @g(<4 x float> noundef %v) #0 {
entry:
  %0 = bitcast <4 x float> %v to <4 x i32>
  ret <4 x i32> %0
}
```

which makes the test updates after 
https://github.com/llvm/llvm-project/pull/121802 very hard to inspect.
I can try with `sroa` instead of `instcombine` (works on this example above at 
least)


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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

2025-01-06 Thread Greg Roth via cfe-commits

https://github.com/pow2clk commented:

I think we require descriptions and not just titles. 

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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

2025-01-06 Thread Greg Roth via cfe-commits


@@ -1297,27 +1297,16 @@ float4 lerp(float4, float4, float4);
 ///
 /// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).
 
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
-half length(half);
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
-half length(half2);
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
-half length(half3);
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
-half length(half4);

pow2clk wrote:

Is the 6.2 restriction preserved somehow?

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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

2025-01-06 Thread Greg Roth via cfe-commits


@@ -1,32 +1,53 @@
-// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -disable-llvm-passes 
-verify -verify-ignore-unexpected
-
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify
 
 void test_too_few_arg()
 {
-  return __builtin_hlsl_length();
-  // expected-error@-1 {{too few arguments to function call, expected 1, have 
0}}
+  return length();
+  // expected-error@-1 {{no matching function for call to 'length'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires single argument 'X', but no arguments were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires single argument 'X', but no arguments were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires single argument 'X', but no arguments were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires single argument 'X', but no arguments were provided}}
 }
 
 void test_too_many_arg(float2 p0)
 {
-  return __builtin_hlsl_length(p0, p0);
-  // expected-error@-1 {{too many arguments to function call, expected 1, have 
2}}
+  return length(p0, p0);
+  // expected-error@-1 {{no matching function for call to 'length'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires single argument 'X', but 2 arguments were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires single argument 'X', but 2 arguments were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires single argument 'X', but 2 arguments were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires single argument 'X', but 2 arguments were provided}}
+}
+
+float double_to_float_type(double p0) {
+  return length(p0);
+  // expected-error@-1  {{call to 'length' is ambiguous}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
 }
 
-bool builtin_bool_to_float_type_promotion(bool p1)
+
+float bool_to_float_type_promotion(bool p1)
 {
-  return __builtin_hlsl_length(p1);
-  // expected-error@-1 {passing 'bool' to parameter of incompatible type 
'float'}}
+  return length(p1);
+  // expected-error@-1  {{call to 'length' is ambiguous}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
 }
 
-bool builtin_length_int_to_float_promotion(int p1)
+float length_int_to_float_promotion(int p1)
 {
-  return __builtin_hlsl_length(p1);
-  // expected-error@-1 {{passing 'int' to parameter of incompatible type 
'float'}}
+  return length(p1);
+  // expected-error@-1  {{call to 'length' is ambiguous}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
 }
 
-bool2 builtin_length_int2_to_float2_promotion(int2 p1)
+float2 length_int2_to_float2_promotion(int2 p1)
 {
-  return __builtin_hlsl_length(p1);
-  // expected-error@-1 {{passing 'int2' (aka 'vector') to parameter of 
incompatible type '__attribute__((__vector_size__(2 * sizeof(float float' 
(vector of 2 'float' values)}}
+  return length(p1);
+  // expected-error@-1  {{call to 'length' is ambiguous}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}

pow2clk wrote:

Doubles, integers and bools are all allowed by DXC. Removing that behavior 
would be a regression and I don't know why we would want to. If it's not 
implemented yet, that's one thing, but testing for the failure suggests intent. 

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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

2025-01-06 Thread Greg Roth via cfe-commits

pow2clk wrote:

Thanks for the description. I would find some justification useful even if it 
just repeats the reasoning we've established for all such changes.

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


[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

2025-01-06 Thread Greg Roth via cfe-commits


@@ -1,73 +1,151 @@
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
-// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ 
-// RUN:   --check-prefixes=CHECK,NATIVE_HALF
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
-// RUN:   -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF

pow2clk wrote:

Would you explain why you removed the NO_HALF variant?

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


[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #117268)

2025-01-06 Thread Shilei Tian via cfe-commits

shiltian wrote:

This PR introduced a new compile warning when compiling using clang. Please fix 
it.

```
llvm-project/clang/lib/Driver/ToolChains/SYCL.cpp:35:10: warning: returning 
address of local temporary object [-Wreturn-stack-address]
   35 |   return {
  |  ^
   36 |   options::OPT_fsanitize_EQ,  // -fsanitize
  |   ~
   37 |   options::OPT_fcf_protection_EQ, // -fcf-protection
  |   ~~
   38 |   options::OPT_fprofile_generate,
  |   ~~~
   39 |   options::OPT_fprofile_generate_EQ,
  |   ~~
   40 |   options::OPT_fno_profile_generate, // -f[no-]profile-generate
  |   ~
   41 |   options::OPT_ftest_coverage,
  |   
   42 |   options::OPT_fno_test_coverage, // -f[no-]test-coverage
  |   ~~~
   43 |   options::OPT_fcoverage_mapping,
  |   ~~~
   44 |   options::OPT_fno_coverage_mapping, // -f[no-]coverage-mapping
  |   ~
   45 |   options::OPT_coverage, // --coverage
  |   
   46 |   options::OPT_fprofile_instr_generate,
  |   ~
   47 |   options::OPT_fprofile_instr_generate_EQ,
  |   
   48 |   options::OPT_fno_profile_instr_generate, // 
-f[no-]profile-instr-generate
  |   
~
   49 |   options::OPT_fprofile_arcs,
  |   ~~~
   50 |   options::OPT_fno_profile_arcs, // -f[no-]profile-arcs
  |   ~
In file included from llvm-project/clang/lib/Driver/ToolChains/SYCL.cpp:8:
llvm-project/clang/lib/Driver/ToolChains/SYCL.h:27:17: warning: private field 
'D' is not used [-Wunused-private-field]
   27 |   const Driver &D;
  | ^
2 warnings generated.
```

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


[libunwind] [libunwind][cmake] Compile _Unwind* routines with -fexceptions (PR #121819)

2025-01-06 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi created 
https://github.com/llvm/llvm-project/pull/121819

When building libunwind with LTO, we found that routines, like
_Unwind_RaiseException were marked `nounwind`. This causes problems when
libunwind is then used with exception throwing code, since many of the
routines are marked `nounwind`. This causes miscompiles, and the
incorrect generation of unwind tables (see #120657).

In #56825, it was pointed out that these C routines should be compiled
with `-fexceptions`, to prevent this from happening. Since we only add
the `-fexceptions` flag to C sources, there shouldn't be any conflict
with any C++ sources or interactions with libcxx/libcxxabi.

Fixes #56825 #120657


>From 9f952de3cb3e973f17121c057089a28bf4c6e5e0 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 6 Jan 2025 11:15:35 -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.6-beta.1
---
 libunwind/src/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index e7ea57734cca97..72dd3f5bca9960 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,7 +20,7 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
-  COMPILE_FLAGS "-std=c99")
+  COMPILE_FLAGS "-std=c99 -fexceptions")
 
 set(LIBUNWIND_ASM_SOURCES
 UnwindRegistersRestore.S

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


[libunwind] [libunwind][cmake] Compile _Unwind* routines with -fexceptions (PR #121819)

2025-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind

Author: Paul Kirth (ilovepi)


Changes

When building libunwind with LTO, we found that routines, like
_Unwind_RaiseException were marked `nounwind`. This causes problems when
libunwind is then used with exception throwing code, since many of the
routines are marked `nounwind`. This causes miscompiles, and the
incorrect generation of unwind tables (see #120657).

In #56825, it was pointed out that these C routines should be compiled
with `-fexceptions`, to prevent this from happening. Since we only add
the `-fexceptions` flag to C sources, there shouldn't be any conflict
with any C++ sources or interactions with libcxx/libcxxabi.

Fixes #56825 #120657


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


1 Files Affected:

- (modified) libunwind/src/CMakeLists.txt (+1-1) 


``diff
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index e7ea57734cca97..72dd3f5bca9960 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -20,7 +20,7 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
-  COMPILE_FLAGS "-std=c99")
+  COMPILE_FLAGS "-std=c99 -fexceptions")
 
 set(LIBUNWIND_ASM_SOURCES
 UnwindRegistersRestore.S

``




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


[clang] Driver][SYCL] Address sanitizer and test issue (PR #121822)

2025-01-06 Thread Michael Toguchi via cfe-commits

https://github.com/mdtoguchi updated 
https://github.com/llvm/llvm-project/pull/121822

>From 92796278b87c5713a0cf16119009c07f87568df5 Mon Sep 17 00:00:00 2001
From: Michael D Toguchi 
Date: Mon, 6 Jan 2025 11:42:12 -0800
Subject: [PATCH 1/2] Driver][SYCL] Address sanitizer and test issue

The following commit:
https://github.com/llvm/llvm-project/commit/d00f65c6acd9f0e1ddae83391f55eb9d232d2f9e

Caused sanitizer build issues and also a test issue when using
%clang_cl.  Address these problems.

 - Use local static array
 - Use '--' for clang_cl calls
---
 clang/lib/Driver/ToolChains/SYCL.cpp   | 6 +++---
 clang/lib/Driver/ToolChains/SYCL.h | 3 ---
 clang/test/Driver/sycl-offload-jit.cpp | 4 ++--
 3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp 
b/clang/lib/Driver/ToolChains/SYCL.cpp
index e42b65cc07deea..8c39d1b5b2299f 100644
--- a/clang/lib/Driver/ToolChains/SYCL.cpp
+++ b/clang/lib/Driver/ToolChains/SYCL.cpp
@@ -17,8 +17,7 @@ using namespace llvm::opt;
 
 SYCLInstallationDetector::SYCLInstallationDetector(
 const Driver &D, const llvm::Triple &HostTriple,
-const llvm::opt::ArgList &Args)
-: D(D) {}
+const llvm::opt::ArgList &Args) {}
 
 void SYCLInstallationDetector::addSYCLIncludeArgs(
 const ArgList &DriverArgs, ArgStringList &CC1Args) const {
@@ -32,7 +31,7 @@ void SYCLInstallationDetector::addSYCLIncludeArgs(
 
 // Unsupported options for SYCL device compilation.
 static ArrayRef getUnsupportedOpts() {
-  return {
+  static std::vector UnsupportedOpts = {
   options::OPT_fsanitize_EQ,  // -fsanitize
   options::OPT_fcf_protection_EQ, // -fcf-protection
   options::OPT_fprofile_generate,
@@ -54,6 +53,7 @@ static ArrayRef getUnsupportedOpts() {
   options::OPT_forder_file_instrumentation, // -forder-file-instrumentation
   options::OPT_fcs_profile_generate,// -fcs-profile-generate
   options::OPT_fcs_profile_generate_EQ};
+  return UnsupportedOpts;
 }
 
 SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
diff --git a/clang/lib/Driver/ToolChains/SYCL.h 
b/clang/lib/Driver/ToolChains/SYCL.h
index 9af2fd0c45c5ed..2a8b4eca9e9f82 100644
--- a/clang/lib/Driver/ToolChains/SYCL.h
+++ b/clang/lib/Driver/ToolChains/SYCL.h
@@ -22,9 +22,6 @@ class SYCLInstallationDetector {
 
   void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
   llvm::opt::ArgStringList &CC1Args) const;
-
-private:
-  const Driver &D;
 };
 
 namespace toolchains {
diff --git a/clang/test/Driver/sycl-offload-jit.cpp 
b/clang/test/Driver/sycl-offload-jit.cpp
index d7ab630084098e..ff7e973c6078f5 100644
--- a/clang/test/Driver/sycl-offload-jit.cpp
+++ b/clang/test/Driver/sycl-offload-jit.cpp
@@ -3,7 +3,7 @@
 /// Check the phases graph with -fsycl. Use of -fsycl enables offload
 // RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fsycl %s 
2>&1 \
 // RUN:   | FileCheck -check-prefixes=CHK-PHASES %s
-// RUN: %clang_cl -ccc-print-phases --target=x86_64-pc-windows-msvc -fsycl %s 
2>&1 \
+// RUN: %clang_cl -ccc-print-phases --target=x86_64-pc-windows-msvc -fsycl -- 
%s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=CHK-PHASES %s
 // CHK-PHASES: 0: input, "[[INPUT:.+\.cpp]]", c++, (host-sycl)
 // CHK-PHASES-NEXT: 1: preprocessor, {0}, c++-cpp-output, (host-sycl)
@@ -36,7 +36,7 @@
 // RUN: %clang -### -fsycl -fsycl-device-only %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-FSYCL-IS-DEVICE %s
 // RUN: %clang_cl -### -fsycl -c %s 2>&1 \
-// RUN:   | FileCheck -check-prefixes=CHK-FSYCL-IS-DEVICE,CHK-FSYCL-IS-HOST %s
+// RUN:   | FileCheck -check-prefixes=CHK-FSYCL-IS-DEVICE,CHK-FSYCL-IS-HOST -- 
%s
 // RUN: %clang -### -fsycl -fsycl-host-only %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-FSYCL-IS-HOST %s
 // CHK-FSYCL-IS-DEVICE: "-cc1"{{.*}} "-fsycl-is-device" {{.*}} "-emit-llvm-bc"

>From 79c4b729190d8c5b45d8231e05a1a4adc71f8e21 Mon Sep 17 00:00:00 2001
From: Michael D Toguchi 
Date: Mon, 6 Jan 2025 11:50:53 -0800
Subject: [PATCH 2/2] Fix test, put -- on wrong line

---
 clang/test/Driver/sycl-offload-jit.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/sycl-offload-jit.cpp 
b/clang/test/Driver/sycl-offload-jit.cpp
index ff7e973c6078f5..eb192e08a3bc0c 100644
--- a/clang/test/Driver/sycl-offload-jit.cpp
+++ b/clang/test/Driver/sycl-offload-jit.cpp
@@ -35,8 +35,8 @@
 // RUN:   | FileCheck -check-prefixes=CHK-FSYCL-IS-DEVICE,CHK-FSYCL-IS-HOST %s
 // RUN: %clang -### -fsycl -fsycl-device-only %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-FSYCL-IS-DEVICE %s
-// RUN: %clang_cl -### -fsycl -c %s 2>&1 \
-// RUN:   | FileCheck -check-prefixes=CHK-FSYCL-IS-DEVICE,CHK-FSYCL-IS-HOST -- 
%s
+// RUN: %clang_cl -### -fsycl -c -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=CHK-FSYCL-IS-DEVICE,CHK-FSYCL-IS-HOST %s
 // RUN: %clang -### -fsycl -fsycl-host-only %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-FSYCL-IS-HOST %s
 // 

[clang] Driver][SYCL] Address sanitizer and test issue (PR #121822)

2025-01-06 Thread Vitaly Buka via cfe-commits


@@ -32,7 +31,7 @@ void SYCLInstallationDetector::addSYCLIncludeArgs(
 
 // Unsupported options for SYCL device compilation.
 static ArrayRef getUnsupportedOpts() {
-  return {
+  static std::vector UnsupportedOpts = {

vitalybuka wrote:

and C array: UnsupportedOpts[] = {
}

https://github.com/llvm/llvm-project/pull/121822
___
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)

2025-01-06 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

I think the relevant code that prevents visiting template instantiations is 
CursorVisitor::VisitClassTemplateSpecializationDecl.  It intentionally skips 
implicit template instantiations, I guess because of the origin of the API, 
which was focused around code written by the user.

> * methods()

It might be a little weird to see uninstantiated methods in some cases... but 
this probably makes sense.

> * fields()

get_fields() already exists.

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] Driver][SYCL] Address sanitizer and test issue (PR #121822)

2025-01-06 Thread Vitaly Buka via cfe-commits


@@ -17,8 +17,7 @@ using namespace llvm::opt;
 
 SYCLInstallationDetector::SYCLInstallationDetector(
 const Driver &D, const llvm::Triple &HostTriple,
-const llvm::opt::ArgList &Args)
-: D(D) {}
+const llvm::opt::ArgList &Args) {}

vitalybuka wrote:

what happened with driver?

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


[clang] Driver][SYCL] Address sanitizer and test issue (PR #121822)

2025-01-06 Thread Tom Honermann via cfe-commits


@@ -32,7 +31,7 @@ void SYCLInstallationDetector::addSYCLIncludeArgs(
 
 // Unsupported options for SYCL device compilation.
 static ArrayRef getUnsupportedOpts() {
-  return {
+  static std::vector UnsupportedOpts = {

tahonermann wrote:

Declaring the function `constexpr` wouldn't address the lifetime issue that is 
fixed by this change. The function is called at run-time, so the data backing 
the array reference needs to persist until run-time. 

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


[clang] Driver][SYCL] Address sanitizer and test issue (PR #121822)

2025-01-06 Thread Tom Honermann via cfe-commits

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


[clang] [Clang][Driver] Declare win32 threads on Windows (PR #121442)

2025-01-06 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

I'd invoke @AaronBallman for feedback/guidance here, before deciding the 
direction on this one.

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


[clang] [Driver][SYCL] Address sanitizer and test issue (PR #121822)

2025-01-06 Thread Vitaly Buka via cfe-commits

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

>From 92796278b87c5713a0cf16119009c07f87568df5 Mon Sep 17 00:00:00 2001
From: Michael D Toguchi 
Date: Mon, 6 Jan 2025 11:42:12 -0800
Subject: [PATCH 1/3] Driver][SYCL] Address sanitizer and test issue

The following commit:
https://github.com/llvm/llvm-project/commit/d00f65c6acd9f0e1ddae83391f55eb9d232d2f9e

Caused sanitizer build issues and also a test issue when using
%clang_cl.  Address these problems.

 - Use local static array
 - Use '--' for clang_cl calls
---
 clang/lib/Driver/ToolChains/SYCL.cpp   | 6 +++---
 clang/lib/Driver/ToolChains/SYCL.h | 3 ---
 clang/test/Driver/sycl-offload-jit.cpp | 4 ++--
 3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp 
b/clang/lib/Driver/ToolChains/SYCL.cpp
index e42b65cc07deea..8c39d1b5b2299f 100644
--- a/clang/lib/Driver/ToolChains/SYCL.cpp
+++ b/clang/lib/Driver/ToolChains/SYCL.cpp
@@ -17,8 +17,7 @@ using namespace llvm::opt;
 
 SYCLInstallationDetector::SYCLInstallationDetector(
 const Driver &D, const llvm::Triple &HostTriple,
-const llvm::opt::ArgList &Args)
-: D(D) {}
+const llvm::opt::ArgList &Args) {}
 
 void SYCLInstallationDetector::addSYCLIncludeArgs(
 const ArgList &DriverArgs, ArgStringList &CC1Args) const {
@@ -32,7 +31,7 @@ void SYCLInstallationDetector::addSYCLIncludeArgs(
 
 // Unsupported options for SYCL device compilation.
 static ArrayRef getUnsupportedOpts() {
-  return {
+  static std::vector UnsupportedOpts = {
   options::OPT_fsanitize_EQ,  // -fsanitize
   options::OPT_fcf_protection_EQ, // -fcf-protection
   options::OPT_fprofile_generate,
@@ -54,6 +53,7 @@ static ArrayRef getUnsupportedOpts() {
   options::OPT_forder_file_instrumentation, // -forder-file-instrumentation
   options::OPT_fcs_profile_generate,// -fcs-profile-generate
   options::OPT_fcs_profile_generate_EQ};
+  return UnsupportedOpts;
 }
 
 SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
diff --git a/clang/lib/Driver/ToolChains/SYCL.h 
b/clang/lib/Driver/ToolChains/SYCL.h
index 9af2fd0c45c5ed..2a8b4eca9e9f82 100644
--- a/clang/lib/Driver/ToolChains/SYCL.h
+++ b/clang/lib/Driver/ToolChains/SYCL.h
@@ -22,9 +22,6 @@ class SYCLInstallationDetector {
 
   void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
   llvm::opt::ArgStringList &CC1Args) const;
-
-private:
-  const Driver &D;
 };
 
 namespace toolchains {
diff --git a/clang/test/Driver/sycl-offload-jit.cpp 
b/clang/test/Driver/sycl-offload-jit.cpp
index d7ab630084098e..ff7e973c6078f5 100644
--- a/clang/test/Driver/sycl-offload-jit.cpp
+++ b/clang/test/Driver/sycl-offload-jit.cpp
@@ -3,7 +3,7 @@
 /// Check the phases graph with -fsycl. Use of -fsycl enables offload
 // RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fsycl %s 
2>&1 \
 // RUN:   | FileCheck -check-prefixes=CHK-PHASES %s
-// RUN: %clang_cl -ccc-print-phases --target=x86_64-pc-windows-msvc -fsycl %s 
2>&1 \
+// RUN: %clang_cl -ccc-print-phases --target=x86_64-pc-windows-msvc -fsycl -- 
%s 2>&1 \
 // RUN:   | FileCheck -check-prefixes=CHK-PHASES %s
 // CHK-PHASES: 0: input, "[[INPUT:.+\.cpp]]", c++, (host-sycl)
 // CHK-PHASES-NEXT: 1: preprocessor, {0}, c++-cpp-output, (host-sycl)
@@ -36,7 +36,7 @@
 // RUN: %clang -### -fsycl -fsycl-device-only %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-FSYCL-IS-DEVICE %s
 // RUN: %clang_cl -### -fsycl -c %s 2>&1 \
-// RUN:   | FileCheck -check-prefixes=CHK-FSYCL-IS-DEVICE,CHK-FSYCL-IS-HOST %s
+// RUN:   | FileCheck -check-prefixes=CHK-FSYCL-IS-DEVICE,CHK-FSYCL-IS-HOST -- 
%s
 // RUN: %clang -### -fsycl -fsycl-host-only %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-FSYCL-IS-HOST %s
 // CHK-FSYCL-IS-DEVICE: "-cc1"{{.*}} "-fsycl-is-device" {{.*}} "-emit-llvm-bc"

>From 79c4b729190d8c5b45d8231e05a1a4adc71f8e21 Mon Sep 17 00:00:00 2001
From: Michael D Toguchi 
Date: Mon, 6 Jan 2025 11:50:53 -0800
Subject: [PATCH 2/3] Fix test, put -- on wrong line

---
 clang/test/Driver/sycl-offload-jit.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/sycl-offload-jit.cpp 
b/clang/test/Driver/sycl-offload-jit.cpp
index ff7e973c6078f5..eb192e08a3bc0c 100644
--- a/clang/test/Driver/sycl-offload-jit.cpp
+++ b/clang/test/Driver/sycl-offload-jit.cpp
@@ -35,8 +35,8 @@
 // RUN:   | FileCheck -check-prefixes=CHK-FSYCL-IS-DEVICE,CHK-FSYCL-IS-HOST %s
 // RUN: %clang -### -fsycl -fsycl-device-only %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-FSYCL-IS-DEVICE %s
-// RUN: %clang_cl -### -fsycl -c %s 2>&1 \
-// RUN:   | FileCheck -check-prefixes=CHK-FSYCL-IS-DEVICE,CHK-FSYCL-IS-HOST -- 
%s
+// RUN: %clang_cl -### -fsycl -c -- %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=CHK-FSYCL-IS-DEVICE,CHK-FSYCL-IS-HOST %s
 // RUN: %clang -### -fsycl -fsycl-host-only %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-FSYCL-IS-HOST %s
 //

[clang] [z/OS][SystemZ] Clang dependency files are text files (PR #121849)

2025-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kai Nacke (redstar)


Changes

The dependency file and the P1689 file are text files, but the
open call misses the OF_Text flag. This PR adds the flag.
Fixes regressions in test cases ClangScanDeps/modules-extern-unrelated.m
and ClangScanDeps/P1689.cppm.

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


1 Files Affected:

- (modified) clang/tools/clang-scan-deps/ClangScanDeps.cpp (+4-4) 


``diff
diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index bd36181fca3f31..709dc513be2811 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -913,7 +913,7 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
   return llvm::nulls();
 
 std::error_code EC;
-FileOS.emplace(OutputFileName, EC);
+FileOS.emplace(OutputFileName, EC, llvm::sys::fs::OF_Text);
 if (EC) {
   llvm::errs() << "Failed to open output file '" << OutputFileName
<< "': " << llvm::errorCodeToError(EC) << '\n';
@@ -1003,9 +1003,9 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
   auto OSIter = OSs.find(MakeformatOutputPath);
   if (OSIter == OSs.end()) {
 std::error_code EC;
-OSIter =
-OSs.try_emplace(MakeformatOutputPath, MakeformatOutputPath, EC)
-.first;
+OSIter = OSs.try_emplace(MakeformatOutputPath, 
MakeformatOutputPath,
+ EC, llvm::sys::fs::OF_Text)
+ .first;
 if (EC)
   llvm::errs() << "Failed to open P1689 make format output file \""
<< MakeformatOutputPath << "\" for " << EC.message()

``




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


[clang] [clang][OpenMP] Add 'align' modifier for 'allocate' clause (PR #121814)

2025-01-06 Thread David Pagan via cfe-commits

ddpagan wrote:

> Update OpenMPSupport.rst

New 'align' modifier added to implemented features list.

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Vitaly Buka via cfe-commits


@@ -3615,9 +3616,12 @@ void CodeGenFunction::EmitCheck(
 
 if (!CGM.getCodeGenOpts().SanitizeMergeHandlers.has(Checked[i].second))
   NoMerge = true;
+
+if (!CGM.getCodeGenOpts().NoSanitizeTopHot.has(Checked[i].second))
+  SanitizeGuardChecks = true;
   }
 
-  if (ClSanitizeGuardChecks) {
+  if (SanitizeGuardChecks) {
 llvm::Value *Allow =
 
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::allow_ubsan_check),
llvm::ConstantInt::get(CGM.Int8Ty, CheckHandler));

vitalybuka wrote:

It's maybe not important for the patch, but we will have  a problem here.

LLVM pass will need to lookup fraction by the argument,
but the argument is `CheckHandler` which is not the same as NoSanitizeTopHot.

but maybe we need to think a little bit now.

Assuming very few `Checked.size() > 1` also `Checked[i].second` is usually 1 
bit.
Probably correct approach will be to apply llvm::Intrinsic::allow_ubsan_check 
on line 3606?
And use the bit with with highest sanitizer coverage as ID.

WDYT?



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


[clang] [llvm] [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (PR #120507)

2025-01-06 Thread Jon Roelofs via cfe-commits

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


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


[clang] [z/OS][SystemZ] Clang dependency files are text files (PR #121849)

2025-01-06 Thread Kai Nacke via cfe-commits

https://github.com/redstar created 
https://github.com/llvm/llvm-project/pull/121849

The dependency file and the P1689 file are text files, but the
open call misses the OF_Text flag. This PR adds the flag.
Fixes regressions in test cases ClangScanDeps/modules-extern-unrelated.m
and ClangScanDeps/P1689.cppm.

>From 32e11cd86c229f875c2522f7ac087245ef98dc22 Mon Sep 17 00:00:00 2001
From: Kai Nacke 
Date: Mon, 6 Jan 2025 15:59:03 -0500
Subject: [PATCH] [z/OS][SystemZ] Clang dependency files are text files

The dependency file and the P1689 file are text files, but the
open call misses the OF_Text flag. This PR adds the flag.
Fixes regressions in test cases ClangScanDeps/modules-extern-unrelated.m
and ClangScanDeps/P1689.cppm.
---
 clang/tools/clang-scan-deps/ClangScanDeps.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index bd36181fca3f31..709dc513be2811 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -913,7 +913,7 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
   return llvm::nulls();
 
 std::error_code EC;
-FileOS.emplace(OutputFileName, EC);
+FileOS.emplace(OutputFileName, EC, llvm::sys::fs::OF_Text);
 if (EC) {
   llvm::errs() << "Failed to open output file '" << OutputFileName
<< "': " << llvm::errorCodeToError(EC) << '\n';
@@ -1003,9 +1003,9 @@ int clang_scan_deps_main(int argc, char **argv, const 
llvm::ToolContext &) {
   auto OSIter = OSs.find(MakeformatOutputPath);
   if (OSIter == OSs.end()) {
 std::error_code EC;
-OSIter =
-OSs.try_emplace(MakeformatOutputPath, MakeformatOutputPath, EC)
-.first;
+OSIter = OSs.try_emplace(MakeformatOutputPath, 
MakeformatOutputPath,
+ EC, llvm::sys::fs::OF_Text)
+ .first;
 if (EC)
   llvm::errs() << "Failed to open P1689 make format output file \""
<< MakeformatOutputPath << "\" for " << EC.message()

___
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)

2025-01-06 Thread Farzon Lotfi via cfe-commits

farzonl wrote:

> I'd definitely suggest you reduce the scope - maybe always expand the 
> reduction serially in the frontend and not create the llvm intrinsic at all? 

Between @Il-Capitano  and @RKSimon comments I think it makes the most sense to 
do a sequential reduction in the frontend. Thats actually easier because we 
won't have to add SPIRV backend support for vec reduce. 


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)

2025-01-06 Thread Farzon Lotfi via cfe-commits

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

>From e46ef6592aec6a1a0b3f7509eb260bb1e9bda692 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Wed, 18 Dec 2024 01:44:42 -0500
Subject: [PATCH 1/3] [Clang] Add float type support to __builtin_reduce_add
 and __builtin_reduce_multipy

---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +-
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  | 12 
 clang/lib/CodeGen/CGBuiltin.cpp   | 29 +--
 clang/lib/Sema/SemaChecking.cpp   | 26 +++--
 clang/test/AST/ByteCode/builtin-functions.cpp | 15 ++
 clang/test/CodeGen/builtins-reduction-math.c  | 21 ++
 clang/test/Sema/builtins-reduction-math.c | 16 +-
 clang/test/Sema/constant_builtins_vector.cpp  | 12 
 8 files changed, 120 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 03fb7ca9bc3c3b..ee7a3e48b6421c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12355,7 +12355,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)">;
 
 def err_builtin_matrix_disabled: Error<
   "matrix types extension is disabled. Pass -fenable-matrix to enable it">;
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 0d52083b069464..5fff1afe4d2a2c 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 #include "../ExprConstShared.h"
 #include "Boolean.h"
+#include "ByteCode/Floating.h"
 #include "Compiler.h"
 #include "EvalEmitter.h"
 #include "Interp.h"
@@ -1756,6 +1757,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 "
+   "floating-point types.");
+// Floating-point arithmetic is not valid for constant expression
+// initialization. Returning false defers checks to integral constant
+// expression validation, preventing a bad deref of Floating as an integer.
+return false;
+  }
+
   INT_TYPE_SWITCH_NO_BOOL(ElemT, {
 T Result = Arg.atIndex(0).deref();
 unsigned BitWidth = Result.bitWidth();
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5cd893d70695c8..29ba65a575505e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4314,12 +4314,37 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 *this, E, GetIntrinsicID(E->getArg(0)->getType()), "rdx.min"));
   }
 
-  case Builtin::BI__builtin_reduce_add:
+  case Builtin::BI__builtin_reduce_add: {
+// Note: vector_reduce_fadd takes two arguments a
+// scalar start value and a vector. That would mean to
+// correctly call it we would need emitBuiltinWithOneOverloadedType<2>
+// To keep the  builtin sema behavior the same despite type we will
+// popululate vector_reduce_fadd scalar value with a 0.
+if (E->getArg(0)->getType()->hasFloatingRepresentation()) {
+  Value *X = EmitScalarExpr(E->getArg(0));
+  auto EltTy = X->getType()->getScalarType();
+  Value *Seed = ConstantFP::get(EltTy, 0);
+  return RValue::get(Builder.CreateIntrinsic(
+  /*ReturnType=*/EltTy, llvm::Intrinsic::vector_reduce_fadd,
+  ArrayRef{Seed, X}, nullptr, "rdx.fadd"));
+}
+assert(E->getArg(0)->getType()->hasIntegerRepresentation());
 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
 *this, E, llvm::Intrinsic::vector_reduce_add, "rdx.add"));
-  case Builtin::BI__builtin_reduce_mul:
+  }
+  case Builtin::BI__builtin_reduce_mul: {
+if (E->getArg(0)->getType()->hasFloatingRepresentation()) {
+  Value *X = EmitScalarExpr(E->getArg(0));
+  auto EltTy = X->getType()->getScalarType();
+  Value *Seed = ConstantFP::get(EltTy, 0);
+  return RValue::get(Builder.CreateIntrinsic(
+  /*ReturnType=*/EltTy, llvm::Intrinsic::vector_reduce_fmul,
+  ArrayRef{Seed, X}, nullptr, "rdx.fmul"));
+}
+assert(E->getArg(0)->getType()->hasIntegerRepresentation());
 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
 *this, E, llvm::Intrinsic::vector_reduce_mul, "rdx.mul"));
+  }
   case Builtin::BI__builtin_reduce_xor:
 return RV

[clang] [Clang][ASTMatcher] Add a matcher for the name of a DependentScopeDeclRefExpr (PR #121656)

2025-01-06 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> We can also create a new matcher for `dependentNameType` so we can use it 
> like `dependentNameType(hasDependentType(builtinType()))`, which is similar 
> to Complex and Array types.

I don't think `DependentNameType` has a `Type` property that we could match in 
this way; the idea behind `DependentNameType` is that resolving it to a 
concrete `Type` needs to be deferred until after instantiation when the 
dependent name can be looked up.

That said, it would be useful to have a matcher for the **name** of a 
`DependentNameType`, something like 
`dependentNameType(hasDependentName("type"))` for `typename T::type`. I don't 
know how straightforward it is to overload a matcher name (`hasDependentName` 
in this case) in this way, but if you're interested in playing around with it, 
I think that would make for a useful addition!

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


[clang] Driver][SYCL] Address sanitizer and test issue (PR #121822)

2025-01-06 Thread Paul Kirth via cfe-commits


@@ -32,7 +31,7 @@ void SYCLInstallationDetector::addSYCLIncludeArgs(
 
 // Unsupported options for SYCL device compilation.
 static ArrayRef getUnsupportedOpts() {
-  return {
+  static std::vector UnsupportedOpts = {

ilovepi wrote:

Can't this function be `constexpr` instead of using a static variable?

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


[clang] [RISCV] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-01-06 Thread Garvit Gupta via cfe-commits

https://github.com/quic-garvgupt created 
https://github.com/llvm/llvm-project/pull/121829

This patch introduces the baretmetal toolchain object about GCC Installation.
Currently, if `--gcc-installation` ot `--gcc-install-dir` options are passed on
commandline, then sysroot will be formed from there if paths will be valid.
Otherwise, it will be fallback to as it already existed in the Baremetal
toolchaibn object.

Additionally, the restriction to always use integrated assembler is removed
because with valid gcc installation, gnu assembler can be invoked as well.

This patch currently adds and modifies arm related test only. The riscv specific
test will be added in the last PR when driver code related to calling of
RISCVToolchain object will be removed. Currently in this PR, there is no way to
test riscv target.

This is the first PR in the series of 3 PRs for merging and extending Baremetal
toolchain object. The division of the PRs is as follows:
- Teach Baremetal toolchain about GCC installation and make sysroot and 
assembler
  related changes.
- Changes related to linker job and defaults for CXXStdlib and other runtime 
libs.
- Finally removing the call to RISCVToolchain object.

The above division will also ensure that riscv and arm specific tests are not
modified in the same PR.

RFC: 
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

Change-Id: Ibaeb569cf7e2cee03c022aa9ecd1abe29d5c30d4

>From 908c2dfa26c5fa7dea14945e4eba411ebe5b3e82 Mon Sep 17 00:00:00 2001
From: Garvit Gupta 
Date: Fri, 13 Dec 2024 05:31:56 -0800
Subject: [PATCH] [RISCV] Teach Barmetal toolchain about GCC installation(1/3)

This patch introduces the baretmetal toolchain object about GCC Installation.
Currently, if `--gcc-installation` ot `--gcc-install-dir` options are passed on
commandline, then sysroot will be formed from there if paths will be valid.
Otherwise, it will be fallback to as it already existed in the Baremetal
toolchaibn object.

Additionally, the restriction to always use integrated assembler is removed
because with valid gcc installation, gnu assembler can be invoked as well.

This patch currently adds and modifies arm related test only. The riscv specific
test will be added in the last PR when driver code related to calling of
RISCVToolchain object will be removed. Currently in this PR, there is no way to
test riscv target.

This is the first PR in the series of 3 PRs for merging and extending Baremetal
toolchain object. The division of the PRs is as follows:
- Teach Baremetal toolchain about GCC installation and make sysroot and 
assembler
  related changes.
- Changes related to linker job and defaults for CXXStdlib and other runtime 
libs.
- Finally removing the call to RISCVToolchain object.

The above division will also ensure that riscv and arm specific tests are not
modified in the same PR.

RFC: 
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

Change-Id: Ibaeb569cf7e2cee03c022aa9ecd1abe29d5c30d4
---
 clang/lib/Driver/ToolChains/BareMetal.cpp | 121 +++---
 clang/lib/Driver/ToolChains/BareMetal.h   |   8 +-
 .../aarch64-none-elf/bin/ld   |   1 +
 .../aarch64-none-elf/include/c++/8.2.1/.keep  |   0
 .../aarch64-none-elf/lib/.keep|   0
 .../aarch64-none-elf/lib/crt0.o   |   0
 .../lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o |   0
 .../lib/gcc/aarch64-none-elf/8.2.1/crtend.o   |   0
 .../aarch64-none-elf/bin/ld   |   1 +
 .../aarch64-none-elf/lib/.keep|   0
 .../aarch64-none-elf/lib/crt0.o   |   0
 .../aarch64-none-elf/lib/crtbegin.o   |   0
 .../aarch64-none-elf/lib/crtend.o |   0
 .../armv6m-none-eabi/bin/ld   |   1 +
 .../armv6m-none-eabi/include/c++/8.2.1/.keep  |   0
 .../armv6m-none-eabi/lib/.keep|   0
 .../armv6m-none-eabi/lib/crt0.o   |   0
 .../armv6m-none-eabi/lib/libstdc++.a  |   0
 .../lib/gcc/armv6m-none-eabi/8.2.1/crtbegin.o |   0
 .../lib/gcc/armv6m-none-eabi/8.2.1/crtend.o   |   0
 .../armv6m-none-eabi/bin/ld   |   1 +
 .../armv6m-none-eabi/lib/.keep|   0
 .../armv6m-none-eabi/lib/crt0.o   |   0
 .../armv6m-none-eabi/lib/crtbegin.o   |   0
 .../armv6m-none-eabi/lib/crtend.o |   0
 clang/test/Driver/aarch64-toolchain-extra.c   |  28 
 clang/test/Driver/aarch64-toolchain.c |  61 +
 clang/test/Driver/arm-gnutools.c  |  12 ++
 clang/test/Driver/arm-toolchain-extra.c   |  28 
 clang/test/Driver/arm-toolchain.c |  62 +
 clang/test/Driver/baremetal.cpp   |  16 +++
 31 files changed, 320 insertions(+), 20 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/bin/ld
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include/c++/8.2.1/.keep
 create m

[clang] [RISCV] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-01-06 Thread Garvit Gupta via cfe-commits

quic-garvgupt wrote:

* **#121829** https://app.graphite.dev/github/pr/llvm/llvm-project/121829?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/121829?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


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


[clang] [llvm] [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (PR #120507)

2025-01-06 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder updated 
https://github.com/llvm/llvm-project/pull/120507

>From 543f1337efaa50ecc9ca4d264ba0e1ea94517ad2 Mon Sep 17 00:00:00 2001
From: Ian Anderson 
Date: Wed, 18 Dec 2024 16:31:19 -0800
Subject: [PATCH] [Darwin][Driver][clang] apple-none-macho orders the resource
 directory after internal-externc-isystem when nostdlibinc is used

Embedded development often needs to use a different C standard library, 
replacing the existing one normally passed as -internal-externc-isystem. This 
works fine for an apple-macos target, but apple-none-macho doesn't work because 
the MachO driver doesn't implement AddClangSystemIncludeArgs to add the 
resource directory as -internal-isystem like most other drivers do. Move most 
of the search path logic from Darwin and DarwinClang down into an AppleMachO 
toolchain between the MachO and Darwin toolchains.

Also define __MACH__ for apple-none-macho, as Swift expects all MachO targets 
to have that defined.
---
 clang/lib/Basic/Targets/OSTargets.cpp |   3 -
 clang/lib/Driver/Driver.cpp   |   2 +
 clang/lib/Driver/ToolChains/Darwin.cpp| 121 ++
 clang/lib/Driver/ToolChains/Darwin.h  |  78 +++
 clang/lib/Frontend/InitPreprocessor.cpp   |   5 +
 clang/lib/Lex/InitHeaderSearch.cpp|   2 +-
 .../MacOSX15.1.sdk/embedded/usr/include/.keep |   0
 .../embedded/usr/local/include/.keep  |   0
 .../MacOSX15.1.sdk/usr/include/c++/v1/.keep   |   0
 .../MacOSX15.1.sdk/usr/local/include/.keep|   0
 .../Driver/darwin-embedded-search-paths.c |  43 +++
 .../Preprocessor/macho-embedded-predefines.c  |   6 +-
 llvm/include/llvm/TargetParser/Triple.h   |   5 +
 13 files changed, 175 insertions(+), 90 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/MacOSX15.1.sdk/embedded/usr/include/.keep
 create mode 100644 
clang/test/Driver/Inputs/MacOSX15.1.sdk/embedded/usr/local/include/.keep
 create mode 100644 
clang/test/Driver/Inputs/MacOSX15.1.sdk/usr/include/c++/v1/.keep
 create mode 100644 
clang/test/Driver/Inputs/MacOSX15.1.sdk/usr/local/include/.keep
 create mode 100644 clang/test/Driver/darwin-embedded-search-paths.c

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 88c054150ab224..6f98353fb8c2e4 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -114,9 +114,6 @@ void getDarwinDefines(MacroBuilder &Builder, const 
LangOptions &Opts,
 assert(OsVersion.getMinor().value_or(0) < 100 &&
OsVersion.getSubminor().value_or(0) < 100 && "Invalid version!");
 Builder.defineMacro("__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__", Str);
-
-// Tell users about the kernel if there is one.
-Builder.defineMacro("__MACH__");
   }
 
   PlatformMinVersion = OsVersion;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 36d6c93c43321f..7a678ea8aa3fad 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6686,6 +6686,8 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
   TC = std::make_unique(*this, Target, Args);
 else if (Target.isOSBinFormatELF())
   TC = std::make_unique(*this, Target, Args);
+else if (Target.isAppleMachO())
+  TC = std::make_unique(*this, Target, Args);
 else if (Target.isOSBinFormatMachO())
   TC = std::make_unique(*this, Target, Args);
 else
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 56b6dd78673cb6..e5dffb11d1a5e6 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -966,11 +966,14 @@ MachO::MachO(const Driver &D, const llvm::Triple &Triple, 
const ArgList &Args)
   getProgramPaths().push_back(getDriver().Dir);
 }
 
+AppleMachO::AppleMachO(const Driver &D, const llvm::Triple &Triple,
+   const ArgList &Args)
+: MachO(D, Triple, Args), CudaInstallation(D, Triple, Args),
+  RocmInstallation(D, Triple, Args), SYCLInstallation(D, Triple, Args) {}
+
 /// Darwin - Darwin tool chain for i386 and x86_64.
 Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList 
&Args)
-: MachO(D, Triple, Args), TargetInitialized(false),
-  CudaInstallation(D, Triple, Args), RocmInstallation(D, Triple, Args),
-  SYCLInstallation(D, Triple, Args) {}
+: AppleMachO(D, Triple, Args), TargetInitialized(false) {}
 
 types::ID MachO::LookupTypeForExtension(StringRef Ext) const {
   types::ID Ty = ToolChain::LookupTypeForExtension(Ext);
@@ -1019,18 +1022,18 @@ bool Darwin::hasBlocksRuntime() const {
   }
 }
 
-void Darwin::AddCudaIncludeArgs(const ArgList &DriverArgs,
-ArgStringList &CC1Args) const {
+void AppleMachO::AddCudaIncludeArgs(const ArgList &DriverArgs,
+ArgStringList &CC1Args) const {
   CudaInstallation->

[clang] [llvm] [HLSL] Move length support out of the DirectX Backend (PR #121611)

2025-01-06 Thread Chris B via cfe-commits


@@ -1,73 +1,151 @@
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
-// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ 
-// RUN:   --check-prefixes=CHECK,NATIVE_HALF
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
-// RUN:   -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
-
-// NATIVE_HALF: define noundef half @
-// NATIVE_HALF: call half @llvm.fabs.f16(half
-// NO_HALF: call float @llvm.fabs.f32(float
-// NATIVE_HALF: ret half
-// NO_HALF: ret float
-half test_length_half(half p0)
-{
-  return length(p0);
-}
-// NATIVE_HALF: define noundef half @
-// NATIVE_HALF: %hlsl.length = call half @llvm.dx.length.v2f16
-// NO_HALF: %hlsl.length = call float @llvm.dx.length.v2f32(
-// NATIVE_HALF: ret half %hlsl.length
-// NO_HALF: ret float %hlsl.length
-half test_length_half2(half2 p0)
-{
-  return length(p0);
-}
-// NATIVE_HALF: define noundef half @
-// NATIVE_HALF: %hlsl.length = call half @llvm.dx.length.v3f16
-// NO_HALF: %hlsl.length = call float @llvm.dx.length.v3f32(
-// NATIVE_HALF: ret half %hlsl.length
-// NO_HALF: ret float %hlsl.length
-half test_length_half3(half3 p0)
-{
-  return length(p0);
-}
-// NATIVE_HALF: define noundef half @
-// NATIVE_HALF: %hlsl.length = call half @llvm.dx.length.v4f16
-// NO_HALF: %hlsl.length = call float @llvm.dx.length.v4f32(
-// NATIVE_HALF: ret half %hlsl.length
-// NO_HALF: ret float %hlsl.length
-half test_length_half4(half4 p0)
-{
-  return length(p0);
-}
-
-// CHECK: define noundef float @
-// CHECK: call float @llvm.fabs.f32(float
-// CHECK: ret float
-float test_length_float(float p0)
-{
-  return length(p0);
-}
-// CHECK: define noundef float @
-// CHECK: %hlsl.length = call float @llvm.dx.length.v2f32(
-// CHECK: ret float %hlsl.length
-float test_length_float2(float2 p0)
-{
-  return length(p0);
-}
-// CHECK: define noundef float @
-// CHECK: %hlsl.length = call float @llvm.dx.length.v3f32(
-// CHECK: ret float %hlsl.length
-float test_length_float3(float3 p0)
-{
-  return length(p0);
-}
-// CHECK: define noundef float @
-// CHECK: %hlsl.length = call float @llvm.dx.length.v4f32(
-// CHECK: ret float %hlsl.length
-float test_length_float4(float4 p0)
-{
-  return length(p0);
-}
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN: -emit-llvm -O2 -o - | FileCheck %s
+
+// CHECK-LABEL: define noundef half @_Z16test_length_halfDh(
+// CHECK-SAME: half noundef [[P0:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[ELT_ABS_I:%.*]] = tail call noundef half 
@llvm.fabs.f16(half [[P0]])
+// CHECK-NEXT:ret half [[ELT_ABS_I]]
+//
+half test_length_half(half p0)
+{
+  return length(p0);
+}
+
+// CHECK-LABEL: define noundef half @_Z17test_length_half2Dv2_Dh(
+// CHECK-SAME: <2 x half> noundef [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul <2 x half> [[P0]], [[P0]]
+// CHECK-NEXT:[[VECEXT_I:%.*]] = extractelement <2 x half> [[MUL_I]], i64 0
+// CHECK-NEXT:[[VECEXT1_I:%.*]] = extractelement <2 x half> [[MUL_I]], i64 
1
+// CHECK-NEXT:[[ADD_I:%.*]] = fadd half [[VECEXT1_I]], [[VECEXT_I]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call noundef half @llvm.sqrt.f16(half 
[[ADD_I]])
+// CHECK-NEXT:ret half [[TMP0]]
+//
+half test_length_half2(half2 p0)
+{
+  return length(p0);
+}
+
+// CHECK-LABEL: define noundef half @_Z17test_length_half3Dv3_Dh(
+// CHECK-SAME: <3 x half> noundef [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul <3 x half> [[P0]], [[P0]]
+// CHECK-NEXT:[[VECEXT_I:%.*]] = extractelement <3 x half> [[MUL_I]], i64 0
+// CHECK-NEXT:[[VECEXT1_I:%.*]] = extractelement <3 x half> [[MUL_I]], i64 
1
+// CHECK-NEXT:[[ADD_I:%.*]] = fadd half [[VECEXT_I]], [[VECEXT1_I]]
+// CHECK-NEXT:[[VECEXT1_I_1:%.*]] = extractelement <3 x half> [[MUL_I]], 
i64 2
+// CHECK-NEXT:[[ADD_I_1:%.*]] = fadd half [[ADD_I]], [[VECEXT1_I_1]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call noundef half @llvm.sqrt.f16(half 
[[ADD_I_1]])
+// CHECK-NEXT:ret half [[TMP0]]
+//
+half test_length_half3(half3 p0)
+{
+  return length(p0);
+}
+
+// CHECK-LABEL: define noundef half @_Z17test_length_half4Dv4_Dh(
+// CHECK-SAME: <4 x half> noundef [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul <4 x half> [[P0]], [[P0]]
+// CHECK-NEXT:[[VECEXT_I:%.*]] = extractelement <4 x half> [[MUL_I]], i64 0
+// CHECK-NEXT:[[VECEXT1_I:%.*]] = extractelement <4 x half> [[MUL_I]], i64 
1
+// CHECK-NEXT:[[ADD_I:%.*]] = fadd half [[VECEXT_I]], [[VECEXT1_I]]

[clang] [libclang/python] Add python bindings for PrintingPolicy (PR #120494)

2025-01-06 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic updated 
https://github.com/llvm/llvm-project/pull/120494

>From 13a9c0b88afae7a5f48a66e86357f7284fdace95 Mon Sep 17 00:00:00 2001
From: Eli Friedman 
Date: Tue, 17 Dec 2024 15:25:00 -0800
Subject: [PATCH] [libclang/python] Add python bindings for PrintingPolicy

This allows changing the way pretty-printed code is formatted.
---
 clang/bindings/python/clang/cindex.py | 83 +++
 .../python/tests/cindex/test_cursor.py| 14 
 clang/docs/ReleaseNotes.rst   |  2 +
 3 files changed, 99 insertions(+)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index f8a20a1e224724..50bd5e0929f99e 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -1770,6 +1770,16 @@ def spelling(self):
 
 return self._spelling
 
+def pretty_printed(self, policy):
+"""
+Pretty print declarations.
+Parameters:
+policy -- The policy to control the entities being printed.
+"""
+return _CXString.from_result(
+conf.lib.clang_getCursorPrettyPrinted(self, policy)
+)
+
 @property
 def displayname(self):
 """
@@ -3685,6 +3695,72 @@ def write_main_file_to_stdout(self):
 conf.lib.clang_CXRewriter_writeMainFileToStdOut(self)
 
 
+class PrintingPolicyProperty(BaseEnumeration):
+
+"""
+A PrintingPolicyProperty identifies a property of a PrintingPolicy.
+"""
+
+Indentation = 0
+SuppressSpecifiers = 1
+SuppressTagKeyword = 2
+IncludeTagDefinition = 3
+SuppressScope = 4
+SuppressUnwrittenScope = 5
+SuppressInitializers = 6
+ConstantArraySizeAsWritten = 7
+AnonymousTagLocations = 8
+SuppressStrongLifetime = 9
+SuppressLifetimeQualifiers = 10
+SuppressTemplateArgsInCXXConstructors = 11
+Bool = 12
+Restrict = 13
+Alignof = 14
+UnderscoreAlignof = 15
+UseVoidForZeroParams = 16
+TerseOutput = 17
+PolishForDeclaration = 18
+Half = 19
+MSWChar = 20
+IncludeNewlines = 21
+MSVCFormatting = 22
+ConstantsAsWritten = 23
+SuppressImplicitBase = 24
+FullyQualifiedName = 25
+
+
+class PrintingPolicy(ClangObject):
+"""
+The PrintingPolicy is a wrapper class around clang::PrintingPolicy
+
+It allows specifying how declarations, expressions, and types should be
+pretty-printed.
+"""
+
+@staticmethod
+def create(cursor):
+"""
+Creates a new PrintingPolicy
+Parameters:
+cursor -- Any cursor for a translation unit.
+"""
+return PrintingPolicy(conf.lib.clang_getCursorPrintingPolicy(cursor))
+
+def __init__(self, ptr):
+ClangObject.__init__(self, ptr)
+
+def __del__(self):
+conf.lib.clang_PrintingPolicy_dispose(self)
+
+def get_property(self, property):
+"""Get a property value for the given printing policy."""
+return conf.lib.clang_PrintingPolicy_getProperty(self, property.value)
+
+def set_property(self, property, value):
+"""Set a property value for the given printing policy."""
+conf.lib.clang_PrintingPolicy_setProperty(self, property.value, value)
+
+
 # Now comes the plumbing to hook up the C library.
 
 # Register callback types
@@ -3787,6 +3863,8 @@ def write_main_file_to_stdout(self):
 ("clang_getCursorExtent", [Cursor], SourceRange),
 ("clang_getCursorLexicalParent", [Cursor], Cursor),
 ("clang_getCursorLocation", [Cursor], SourceLocation),
+("clang_getCursorPrettyPrinted", [Cursor, PrintingPolicy], _CXString),
+("clang_getCursorPrintingPolicy", [Cursor], c_object_p),
 ("clang_getCursorReferenced", [Cursor], Cursor),
 ("clang_getCursorReferenceNameRange", [Cursor, c_uint, c_uint], 
SourceRange),
 ("clang_getCursorResultType", [Cursor], Type),
@@ -3909,6 +3987,9 @@ def write_main_file_to_stdout(self):
 ("clang_Cursor_getRawCommentText", [Cursor], _CXString),
 ("clang_Cursor_getOffsetOfField", [Cursor], c_longlong),
 ("clang_Location_isInSystemHeader", [SourceLocation], bool),
+("clang_PrintingPolicy_dispose", [PrintingPolicy]),
+("clang_PrintingPolicy_getProperty", [PrintingPolicy, c_int], c_uint),
+("clang_PrintingPolicy_setProperty", [PrintingPolicy, c_int, c_uint]),
 ("clang_Type_getAlignOf", [Type], c_longlong),
 ("clang_Type_getClassType", [Type], Type),
 ("clang_Type_getNumTemplateArguments", [Type], c_int),
@@ -4089,6 +4170,8 @@ def function_exists(self, name: str) -> bool:
 "FixIt",
 "Index",
 "LinkageKind",
+"PrintingPolicy",
+"PrintingPolicyProperty",
 "RefQualifierKind",
 "SourceLocation",
 "SourceRange",
diff --git a/clang/bindings/python/tests/cindex/test_cursor.py 
b/clang/bindings/python/tests/cindex/test_cursor.py
index 4d989a7421e790..c6aa65ce3c29f8 100644
--- a/clang/bindings/python/tests/cindex/test_cursor.py
+++ b/clang/bindings/

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

2025-01-06 Thread via cfe-commits

Author: Eli Friedman
Date: 2025-01-06T12:56:34-08:00
New Revision: fbcf3cb7fe95d9d420b643ce379f7ee2106a6efc

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

LOG: [libclang/python] Add python binding for 
clang_Cursor_isAnonymousRecordDecl (#120483)

This function allows checking whether a declaration declares an
anonymous union (as opposed to clang_Cursor_isAnonymous, which just
checks if the declaration has a name).

Added: 


Modified: 
clang/bindings/python/clang/cindex.py
clang/bindings/python/tests/cindex/test_type.py
clang/docs/ReleaseNotes.rst

Removed: 




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)

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index acd9dd9298ce1e..8a48a9e3e1f693 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1275,6 +1275,8 @@ Sanitizers
 Python Binding Changes
 --
 - Fixed an issue that led to crashes when calling 
``Type.get_exception_specification_kind``.
+- Added binding for ``clang_Cursor_isAnonymousRecordDecl``, which allows 
checking if
+  a declaration is an anonymous union or anonymous struct.
 
 OpenMP Support
 --



___
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)

2025-01-06 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic closed 
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] [Clang] __has_builtin should return false for aux triple builtins (PR #121839)

2025-01-06 Thread Nick Sarnie via cfe-commits

sarnex wrote:

> Is it possible that we could just skip generating the builtin IDs at all for 
> the aux target? Or does that break something.

Seems like we can't, I tried this:
```
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index c6e54b89e848..904c64f05c36 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -64,8 +64,8 @@ void Builtin::Context::InitializeTarget(const TargetInfo 
&Target,
 const TargetInfo *AuxTarget) {
   assert(TSRecords.empty() && "Already initialized target?");
   TSRecords = Target.getTargetBuiltins();
-  if (AuxTarget)
-AuxTSRecords = AuxTarget->getTargetBuiltins();
+  //  if (AuxTarget)
+  //  AuxTSRecords = AuxTarget->getTargetBuiltins();
 }
```
and got these failures
```
Failed Tests (3):
  Clang :: CodeGenHipStdPar/unsupported-builtins.cpp
  Clang :: Headers/__cpuidex_conflict.c
  Clang :: Sema/builtin-spirv-amdgcn-atomic-inc-dec-failure.cpp
```

and then reverted that and tried this
```
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index c6e54b89e848..34e1d0aa4b68 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -153,9 +153,9 @@ void Builtin::Context::initializeBuiltins(IdentifierTable 
&Table,
   Table.get(TSRecords[i].Name).setBuiltinID(i + Builtin::FirstTSBuiltin);
 
   // Step #3: Register target-specific builtins for AuxTarget.
-  for (unsigned i = 0, e = AuxTSRecords.size(); i != e; ++i)
-Table.get(AuxTSRecords[i].Name)
-.setBuiltinID(i + Builtin::FirstTSBuiltin + TSRecords.size());
+  //for (unsigned i = 0, e = AuxTSRecords.size(); i != e; ++i)
+  //  Table.get(AuxTSRecords[i].Name)
+  //  .setBuiltinID(i + Builtin::FirstTSBuiltin + TSRecords.size());
 
   // Step #4: Unregister any builtins specified by -fno-builtin-foo.
   for (llvm::StringRef Name : LangOpts.NoBuiltinFuncs) {

```
and got it broke the same tests
```
Failed Tests (3):
  Clang :: CodeGenHipStdPar/unsupported-builtins.cpp
  Clang :: Headers/__cpuidex_conflict.c
  Clang :: Sema/builtin-spirv-amdgcn-atomic-inc-dec-failure.cpp

```

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Vitaly Buka via cfe-commits


@@ -154,6 +154,8 @@ struct SanitizerKind {
 #include "clang/Basic/Sanitizers.def"
 }; // SanitizerKind
 
+typedef double SanitizerMaskWeights[SanitizerKind::SO_Count];

vitalybuka wrote:

float is probably enough

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Vitaly Buka via cfe-commits


@@ -154,6 +154,8 @@ struct SanitizerKind {
 #include "clang/Basic/Sanitizers.def"
 }; // SanitizerKind
 
+typedef double SanitizerMaskWeights[SanitizerKind::SO_Count];

vitalybuka wrote:

typedef -> using

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Vitaly Buka via cfe-commits


@@ -154,6 +154,8 @@ struct SanitizerKind {
 #include "clang/Basic/Sanitizers.def"
 }; // SanitizerKind
 
+typedef double SanitizerMaskWeights[SanitizerKind::SO_Count];

vitalybuka wrote:

also std::array<>

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


[clang] [llvm] [NFC] fix up typos (PR #121842)

2025-01-06 Thread Joshua Batista via cfe-commits

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


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


[clang] [Clang] __has_builtin should return false for aux triple builtins (PR #121839)

2025-01-06 Thread Nick Sarnie via cfe-commits

sarnex wrote:

`.CodeGenHipStdPar/unsupported-builtins.cpp` is pretty interesting actually, it 
looks like it tests for some behavior in CodeGen that seems like it's trying to 
fix the exact same problem

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


[clang] [llvm] [NFC] fix up typos (PR #121842)

2025-01-06 Thread via cfe-commits

llvmbot wrote:




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

Author: Farzon Lotfi (farzonl)


Changes

Fix Tablegen typo to indicate SPIRV and not HLSL
Fix miscellaneous test case typos.

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


5 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsSPIRV.td (+1-1) 
- (modified) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll (+4-4) 
- (modified) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/length.ll (+8-6) 
- (modified) llvm/test/CodeGen/SPIRV/opencl/degrees.ll (+5-5) 
- (modified) llvm/test/CodeGen/SPIRV/opencl/radians.ll (+5-5) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td 
b/clang/include/clang/Basic/BuiltinsSPIRV.td
index 195c13573d047f..1e66939b822ef8 100644
--- a/clang/include/clang/Basic/BuiltinsSPIRV.td
+++ b/clang/include/clang/Basic/BuiltinsSPIRV.td
@@ -8,7 +8,7 @@
 
 include "clang/Basic/BuiltinsBase.td"
 
-def HLSLDistance : Builtin {
+def SPIRVDistance : Builtin {
   let Spellings = ["__builtin_spirv_distance"];
   let Attributes = [NoThrow, Const];
   let Prototype = "void(...)";
diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll 
b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll
index 2e0eb8c429ac27..b1625c07111e44 100644
--- a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll
+++ b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll
@@ -15,7 +15,7 @@ entry:
   ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec3_float_16]]
   ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec3_float_16]]
   ; CHECK: %[[#]] = OpExtInst %[[#vec3_float_16]] %[[#op_ext_glsl]] Cross 
%[[#arg0]] %[[#arg1]]
-  %hlsl.cross = call <3 x half> @llvm.spv.cross.v4f16(<3 x half> %a, <3 x 
half> %b)
+  %hlsl.cross = call <3 x half> @llvm.spv.cross.v3f16(<3 x half> %a, <3 x 
half> %b)
   ret <3 x half> %hlsl.cross
 }
 
@@ -25,9 +25,9 @@ entry:
   ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec3_float_32]]
   ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec3_float_32]]
   ; CHECK: %[[#]] = OpExtInst %[[#vec3_float_32]] %[[#op_ext_glsl]] Cross 
%[[#arg0]] %[[#arg1]]
-  %hlsl.cross = call <3 x float> @llvm.spv.cross.v4f32(<3 x float> %a, <3 x 
float> %b)
+  %hlsl.cross = call <3 x float> @llvm.spv.cross.v3f32(<3 x float> %a, <3 x 
float> %b)
   ret <3 x float> %hlsl.cross
 }
 
-declare <3 x half> @llvm.spv.cross.v4f16(<3 x half>, <3 x half>)
-declare <3 x float> @llvm.spv.cross.v4f32(<3 x float>, <3 x float>)
+declare <3 x half> @llvm.spv.cross.v3f16(<3 x half>, <3 x half>)
+declare <3 x float> @llvm.spv.cross.v3f32(<3 x float>, <3 x float>)
diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/length.ll 
b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/length.ll
index b4a9d8e0664b7e..1ac862b79a3fac 100644
--- a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/length.ll
+++ b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/length.ll
@@ -11,19 +11,21 @@
 
 define noundef half @length_half4(<4 x half> noundef %a) {
 entry:
-  ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#]]
+  ; CHECK: %[[#]] = OpFunction %[[#float_16]] None %[[#]]
+  ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_16]]
   ; CHECK: %[[#]] = OpExtInst %[[#float_16]] %[[#op_ext_glsl]] Length 
%[[#arg0]]
-  %hlsl.length = call half @llvm.spv.length.v4f16(<4 x half> %a)
+  %hlsl.length = call half @llvm.spv.length.f16(<4 x half> %a)
   ret half %hlsl.length
 }
 
 define noundef float @length_float4(<4 x float> noundef %a) {
 entry:
-  ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#]]
+  ; CHECK: %[[#]] = OpFunction %[[#float_32]] None %[[#]]
+  ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_32]]
   ; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_ext_glsl]] Length 
%[[#arg0]]
-  %hlsl.length = call float @llvm.spv.length.v4f32(<4 x float> %a)
+  %hlsl.length = call float @llvm.spv.length.f32(<4 x float> %a)
   ret float %hlsl.length
 }
 
-declare half @llvm.spv.length.v4f16(<4 x half>)
-declare float @llvm.spv.length.v4f32(<4 x float>)
+declare half @llvm.spv.length.f16(<4 x half>)
+declare float @llvm.spv.length.f32(<4 x float>)
diff --git a/llvm/test/CodeGen/SPIRV/opencl/degrees.ll 
b/llvm/test/CodeGen/SPIRV/opencl/degrees.ll
index 88f97835fe7194..b8d4f52a287959 100644
--- a/llvm/test/CodeGen/SPIRV/opencl/degrees.ll
+++ b/llvm/test/CodeGen/SPIRV/opencl/degrees.ll
@@ -3,7 +3,7 @@
 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - 
-filetype=obj | spirv-val %}
 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - 
-filetype=obj | spirv-val %}
 
-; CHECK-DAG: %[[#op_ext_glsl:]] = OpExtInstImport "OpenCL.std"
+; CHECK-DAG: %[[#op_ext_ocl:]] = OpExtInstImport "OpenCL.std"
 
 ; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32
 ; CHECK-DAG: %[[#float_16:]] = OpTypeFloat 16
@@ -20,7 +20,7 @@ declare <4 x half> @llvm.spv.degrees.v4f16(<4 x half>)
 define noundef float @degrees_float(float noundef %a) {
 entry:
 ; CHECK: %[[#float_32_arg:]] = OpFunctionParameter %[[#float_32]]
-; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_

[clang] [llvm] [NFC] fix up typos (PR #121842)

2025-01-06 Thread Farzon Lotfi via cfe-commits

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

Fix Tablegen typo to indicate SPIRV and not HLSL
Fix miscellaneous test case typos.

>From 269b25fae5ea78c3c851bd041966d2eff4c01eb1 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Mon, 6 Jan 2025 16:45:14 -0500
Subject: [PATCH] [NFC] fix up typos Fix Tablegen typo to indicate SPIRV and
 not HLSL Fix miscellaneous test case typos.

---
 clang/include/clang/Basic/BuiltinsSPIRV.td|  2 +-
 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll  |  8 
 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/length.ll | 14 --
 llvm/test/CodeGen/SPIRV/opencl/degrees.ll | 10 +-
 llvm/test/CodeGen/SPIRV/opencl/radians.ll | 10 +-
 5 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsSPIRV.td 
b/clang/include/clang/Basic/BuiltinsSPIRV.td
index 195c13573d047f..1e66939b822ef8 100644
--- a/clang/include/clang/Basic/BuiltinsSPIRV.td
+++ b/clang/include/clang/Basic/BuiltinsSPIRV.td
@@ -8,7 +8,7 @@
 
 include "clang/Basic/BuiltinsBase.td"
 
-def HLSLDistance : Builtin {
+def SPIRVDistance : Builtin {
   let Spellings = ["__builtin_spirv_distance"];
   let Attributes = [NoThrow, Const];
   let Prototype = "void(...)";
diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll 
b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll
index 2e0eb8c429ac27..b1625c07111e44 100644
--- a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll
+++ b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll
@@ -15,7 +15,7 @@ entry:
   ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec3_float_16]]
   ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec3_float_16]]
   ; CHECK: %[[#]] = OpExtInst %[[#vec3_float_16]] %[[#op_ext_glsl]] Cross 
%[[#arg0]] %[[#arg1]]
-  %hlsl.cross = call <3 x half> @llvm.spv.cross.v4f16(<3 x half> %a, <3 x 
half> %b)
+  %hlsl.cross = call <3 x half> @llvm.spv.cross.v3f16(<3 x half> %a, <3 x 
half> %b)
   ret <3 x half> %hlsl.cross
 }
 
@@ -25,9 +25,9 @@ entry:
   ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec3_float_32]]
   ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec3_float_32]]
   ; CHECK: %[[#]] = OpExtInst %[[#vec3_float_32]] %[[#op_ext_glsl]] Cross 
%[[#arg0]] %[[#arg1]]
-  %hlsl.cross = call <3 x float> @llvm.spv.cross.v4f32(<3 x float> %a, <3 x 
float> %b)
+  %hlsl.cross = call <3 x float> @llvm.spv.cross.v3f32(<3 x float> %a, <3 x 
float> %b)
   ret <3 x float> %hlsl.cross
 }
 
-declare <3 x half> @llvm.spv.cross.v4f16(<3 x half>, <3 x half>)
-declare <3 x float> @llvm.spv.cross.v4f32(<3 x float>, <3 x float>)
+declare <3 x half> @llvm.spv.cross.v3f16(<3 x half>, <3 x half>)
+declare <3 x float> @llvm.spv.cross.v3f32(<3 x float>, <3 x float>)
diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/length.ll 
b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/length.ll
index b4a9d8e0664b7e..1ac862b79a3fac 100644
--- a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/length.ll
+++ b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/length.ll
@@ -11,19 +11,21 @@
 
 define noundef half @length_half4(<4 x half> noundef %a) {
 entry:
-  ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#]]
+  ; CHECK: %[[#]] = OpFunction %[[#float_16]] None %[[#]]
+  ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_16]]
   ; CHECK: %[[#]] = OpExtInst %[[#float_16]] %[[#op_ext_glsl]] Length 
%[[#arg0]]
-  %hlsl.length = call half @llvm.spv.length.v4f16(<4 x half> %a)
+  %hlsl.length = call half @llvm.spv.length.f16(<4 x half> %a)
   ret half %hlsl.length
 }
 
 define noundef float @length_float4(<4 x float> noundef %a) {
 entry:
-  ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#]]
+  ; CHECK: %[[#]] = OpFunction %[[#float_32]] None %[[#]]
+  ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_32]]
   ; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_ext_glsl]] Length 
%[[#arg0]]
-  %hlsl.length = call float @llvm.spv.length.v4f32(<4 x float> %a)
+  %hlsl.length = call float @llvm.spv.length.f32(<4 x float> %a)
   ret float %hlsl.length
 }
 
-declare half @llvm.spv.length.v4f16(<4 x half>)
-declare float @llvm.spv.length.v4f32(<4 x float>)
+declare half @llvm.spv.length.f16(<4 x half>)
+declare float @llvm.spv.length.f32(<4 x float>)
diff --git a/llvm/test/CodeGen/SPIRV/opencl/degrees.ll 
b/llvm/test/CodeGen/SPIRV/opencl/degrees.ll
index 88f97835fe7194..b8d4f52a287959 100644
--- a/llvm/test/CodeGen/SPIRV/opencl/degrees.ll
+++ b/llvm/test/CodeGen/SPIRV/opencl/degrees.ll
@@ -3,7 +3,7 @@
 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - 
-filetype=obj | spirv-val %}
 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - 
-filetype=obj | spirv-val %}
 
-; CHECK-DAG: %[[#op_ext_glsl:]] = OpExtInstImport "OpenCL.std"
+; CHECK-DAG: %[[#op_ext_ocl:]] = OpExtInstImport "OpenCL.std"
 
 ; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32
 ; CHECK-DAG: %[[#float_16:]] = OpTypeFloat 16
@@ -20,7 +20,7 @@ declare <4 x half> @llvm.spv.degrees.v4f16(<4 x hal

[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Thurston Dang via cfe-commits

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

>From ca1fabc5ea75af0acdd1969c0ad505e04103e1c9 Mon Sep 17 00:00:00 2001
From: Thurston Dang 
Date: Sat, 4 Jan 2025 02:53:00 +
Subject: [PATCH 1/5] [sanitizer] Parse weighted sanitizer args and
 -fno-sanitize-top-hot

This adds a function to parse weighted sanitizer flags (e.g.,
-fsanitize-blah=undefined=0.5,null=0.3) and adds the plumbing to
apply that to -fno-sanitize-top-hot from the frontend to backend.

-fno-sanitize-top-hot currently has no effect; future work will
use it to generalize ubsan-guard-checks (originaly introduced in 
5f9ed2ff8364ff3e4fac410472f421299dafa793).
---
 clang/include/clang/Basic/CodeGenOptions.h |  4 ++
 clang/include/clang/Basic/Sanitizers.h | 14 +
 clang/include/clang/Driver/Options.td  |  7 +++
 clang/include/clang/Driver/SanitizerArgs.h |  1 +
 clang/lib/Basic/Sanitizers.cpp | 38 
 clang/lib/Driver/SanitizerArgs.cpp | 69 +-
 clang/lib/Frontend/CompilerInvocation.cpp  |  5 ++
 7 files changed, 124 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 8097c9ef772bc7..f69f52e49a2fe9 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -384,6 +384,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// the expense of debuggability).
   SanitizerSet SanitizeMergeHandlers;
 
+  /// Set of top hotness thresholds, specifying the fraction of code that is
+  /// excluded from sanitization (0 = skip none, 0.1 = skip hottest 10%, 1.0 = 
skip all).
+  SanitizerMaskWeights NoSanitizeTopHot = {0};
+
   /// List of backend command-line options for -fembed-bitcode.
   std::vector CmdArgs;
 
diff --git a/clang/include/clang/Basic/Sanitizers.h 
b/clang/include/clang/Basic/Sanitizers.h
index c890242269b334..fa6b557819a1a1 100644
--- a/clang/include/clang/Basic/Sanitizers.h
+++ b/clang/include/clang/Basic/Sanitizers.h
@@ -154,6 +154,8 @@ struct SanitizerKind {
 #include "clang/Basic/Sanitizers.def"
 }; // SanitizerKind
 
+typedef double SanitizerMaskWeights[SanitizerKind::SO_Count];
+
 struct SanitizerSet {
   /// Check if a certain (single) sanitizer is enabled.
   bool has(SanitizerMask K) const {
@@ -186,10 +188,22 @@ struct SanitizerSet {
 /// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
 SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups);
 
+/// Parse a single weighted value (e.g., 'undefined=0.05') from a -fsanitize= 
or
+/// -fno-sanitize= value list.
+/// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
+/// The relevant weight(s) are updated in the passed array.
+/// Individual weights are never reset to zero unless explicitly set
+/// (e.g., 'null=0.0').
+SanitizerMask parseSanitizerWeightedValue(StringRef Value, bool AllowGroups, 
SanitizerMaskWeights Weights);
+
 /// Serialize a SanitizerSet into values for -fsanitize= or -fno-sanitize=.
 void serializeSanitizerSet(SanitizerSet Set,
SmallVectorImpl &Values);
 
+/// Serialize a SanitizerMaskWeights into values for -fsanitize= or 
-fno-sanitize=.
+void serializeSanitizerMaskWeights(const SanitizerMaskWeights Weights,
+   SmallVectorImpl &Values);
+
 /// For each sanitizer group bit set in \p Kinds, set the bits for sanitizers
 /// this group enables.
 SanitizerMask expandSanitizerGroups(SanitizerMask Kinds);
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d922709db17786..631a6099781e6c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2649,6 +2649,13 @@ def fsanitize_undefined_strip_path_components_EQ : 
Joined<["-"], "fsanitize-unde
   HelpText<"Strip (or keep only, if negative) a given number of path 
components "
"when emitting check metadata.">,
   MarshallingInfoInt, "0", 
"int">;
+def fno_sanitize_top_hot_EQ
+: CommaJoined<["-"], "fno-sanitize-top-hot=">,
+  Group,
+  HelpText<"Skip sanitization for the fraction of top hottest code "
+   "(0.0 [default] = do not skip any sanitization; "
+   "0.1 = skip the hottest 10% of code; "
+   "1.0 = skip all sanitization)">;
 
 } // end -f[no-]sanitize* flags
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 3b275092bbbe86..854893269e8543 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -26,6 +26,7 @@ class SanitizerArgs {
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
   SanitizerSet MergeHandlers;
+  SanitizerMaskWeights TopHot = {0};
 
   std::vector UserIgnorelistFiles;
   std::vector SystemIgnorelistFiles;
diff --git a/clang/lib/Basic/Sanitizers.cpp b/clang/lib/Basic/Sa

[clang] [Clang] __has_builtin should return false for aux triple builtins (PR #121839)

2025-01-06 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> `CodeGenHipStdPar/unsupported-builtins.cpp` is pretty interesting actually, 
> it looks like it tests for some behavior in CodeGen that seems like it's 
> trying to fix the exact same problem
> 
> The other two tests seem to be actually unrelated breakages though.

Maybe @AlexVlx would know about this in general, but I'd definitely say it's 
problematic behavior.

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


[clang] [clang] Fix implicit integer conversion for opaque enums declared in class templates (PR #121039)

2025-01-06 Thread via cfe-commits
=?utf-8?q?André?= Brand 
Message-ID:
In-Reply-To: 



@@ -1571,6 +1571,23 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl 
*D) {
 Enum->setIntegerType(SemaRef.Context.IntTy);
   else
 Enum->setIntegerTypeSourceInfo(NewTI);
+
+  // The following lines are relevant for opaque-enum-declarations.
+  // If users declare a full enum-specifier, the promotion type is reset
+  // again when parsing the (potentially empty) enumerator-list.
+  // We implement the same logic from C++11 [conv.prom] p4 here but only
+  // after template specialization [temp.spec.general] because it requires
+  // the concrete type.
+  // Note that (1) this also correctly handles the non-dependent case,
+  // (2) we set the promotion type for scoped enumerations to ensure
+  // consistency with declarations outside of templates, (3) we guarantee a
+  // valid promotion even if the user provided an invalid underlying type
+  // (fallback to "default int").

cor3ntin wrote:

```suggestion
  // C++23 [conv.prom]p4
  // if integral promotion can be applied to its underlying type, a prvalue 
of an unscoped enumeration type 
  // whose underlying type is fixed can also be converted to a prvalue of 
the promoted underlying type.
  // 
  // FIXME: that logic is already implemented in ActOnEnumBody, factor out 
into (Re)BuildEnumBody. 
```

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


[clang] [clang] Fix implicit integer conversion for opaque enums declared in class templates (PR #121039)

2025-01-06 Thread via cfe-commits
=?utf-8?q?Andr=C3=A9?= Brand 
Message-ID:
In-Reply-To: 


cor3ntin wrote:

The issue number here seems wrong, can you update the description?
https://github.com/llvm/llvm-project/pull/121039#issue-2757453924

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Vitaly Buka via cfe-commits


@@ -2649,6 +2649,11 @@ def fsanitize_undefined_strip_path_components_EQ : 
Joined<["-"], "fsanitize-unde
   HelpText<"Strip (or keep only, if negative) a given number of path 
components "
"when emitting check metadata.">,
   MarshallingInfoInt, "0", 
"int">;
+def fno_sanitize_top_hot_EQ
+: CommaJoined<["-"], "fno-sanitize-top-hot=">,
+  Group,
+  HelpText<"Exclude sanitization for the top hottest fraction of code "

vitalybuka wrote:

I should mention something that we expect coma separated list of 
=,

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


[clang] [Clang][ASTMatcher] Add a matcher for the name of a DependentScopeDeclRefExpr (PR #121656)

2025-01-06 Thread Amr Hesham via cfe-commits

AmrDeveloper wrote:

> > We can also create a new matcher for `dependentNameType` so we can use it 
> > like `dependentNameType(hasDependentType(builtinType()))`, which is similar 
> > to Complex and Array types.
> 
> I don't think `DependentNameType` has a `Type` property that we could match 
> in this way; the idea behind `DependentNameType` is that resolving it to a 
> concrete `Type` needs to be deferred until after instantiation when the 
> dependent name can be looked up.
> 
> That said, it would be useful to have a matcher for the **name** of a 
> `DependentNameType`, something like 
> `dependentNameType(hasDependentName("type"))` for `typename T::type`. I don't 
> know how straightforward it is to overload a matcher name (`hasDependentName` 
> in this case) in this way, but if you're interested in playing around with 
> it, I think that would make for a useful addition!

Thanks for the explanation, I am interested to try to play around with it and 
will update you with result, 

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Vitaly Buka via cfe-commits


@@ -2649,6 +2649,11 @@ def fsanitize_undefined_strip_path_components_EQ : 
Joined<["-"], "fsanitize-unde
   HelpText<"Strip (or keep only, if negative) a given number of path 
components "
"when emitting check metadata.">,
   MarshallingInfoInt, "0", 
"int">;
+def fno_sanitize_top_hot_EQ
+: CommaJoined<["-"], "fno-sanitize-top-hot=">,
+  Group,
+  HelpText<"Exclude sanitization for the top hottest fraction of code "

vitalybuka wrote:

`fraction of code` is not a fraction of the code. it's a fraction of time (more 
precisely PGO counters) 

Please feel free to reword, but meaning should be like:
`Exclude sanitization for the top hottest code responsible for the given 
fraction of PGO counters.`

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


[clang] [sanitizer] Parse weighted sanitizer args and -fno-sanitize-top-hot (PR #121619)

2025-01-06 Thread Vitaly Buka via cfe-commits


@@ -26,6 +26,8 @@ class SanitizerArgs {
   SanitizerSet RecoverableSanitizers;
   SanitizerSet TrapSanitizers;
   SanitizerSet MergeHandlers;
+  SanitizerSet TopHot;
+  SanitizerMaskWeights TopHotWeights = {0};

vitalybuka wrote:

It's not `Weight`, it's `cutoff threshold`.

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


[clang] [clang][OpenMP] Add 'align' modifier for 'allocate' clause (PR #121814)

2025-01-06 Thread David Pagan via cfe-commits

https://github.com/ddpagan updated 
https://github.com/llvm/llvm-project/pull/121814

>From c2c2c4c46c3ea615e86484b9f9a14a74fab21295 Mon Sep 17 00:00:00 2001
From: Dave Pagan 
Date: Fri, 22 Nov 2024 10:35:40 -0600
Subject: [PATCH 1/2] [clang][OpenMP] Add 'align' modifier for 'allocate'
 clause

The 'align' modifier is now accepted in the 'allocate' clause. Added
LIT tests covering codegen, PCH, template handling, and serialization
for 'align' modifier.

Added support for align-modifier to release notes.

Testing
- New allocate modifier LIT tests.
- OpenMP LIT tests.
- check-all
---
 clang/docs/ReleaseNotes.rst   |   1 +
 clang/include/clang/AST/OpenMPClause.h|  92 +++-
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 clang/include/clang/Basic/OpenMPKinds.def |   1 +
 clang/include/clang/Basic/OpenMPKinds.h   |   4 +
 clang/include/clang/Sema/SemaOpenMP.h |  20 +-
 clang/lib/AST/OpenMPClause.cpp|  58 ++-
 clang/lib/Parse/ParseOpenMP.cpp   |  95 +++-
 clang/lib/Sema/SemaOpenMP.cpp | 102 +++--
 clang/lib/Sema/TreeTransform.h|  30 +-
 clang/lib/Serialization/ASTReader.cpp |   6 +-
 clang/lib/Serialization/ASTWriter.cpp |   4 +-
 .../allocate_allocator_modifier_codegen.cpp   | 255 ---
 .../allocate_allocator_modifier_messages.cpp  |  97 -
 ...t.cpp => allocate_modifiers_ast_print.cpp} |  77 +++-
 .../OpenMP/allocate_modifiers_codegen.cpp | 409 ++
 .../OpenMP/allocate_modifiers_messages.cpp| 159 +++
 17 files changed, 961 insertions(+), 451 deletions(-)
 delete mode 100644 clang/test/OpenMP/allocate_allocator_modifier_codegen.cpp
 delete mode 100644 clang/test/OpenMP/allocate_allocator_modifier_messages.cpp
 rename clang/test/OpenMP/{allocate_allocator_modifier_ast_print.cpp => 
allocate_modifiers_ast_print.cpp} (51%)
 create mode 100644 clang/test/OpenMP/allocate_modifiers_codegen.cpp
 create mode 100644 clang/test/OpenMP/allocate_modifiers_messages.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index acd9dd9298ce1e..25d390f69bcea3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1284,6 +1284,7 @@ OpenMP Support
 - Changed the OpenMP DeviceRTL to use 'generic' IR. The
   ``LIBOMPTARGET_DEVICE_ARCHITECTURES`` CMake argument is now unused and will
   always build support for AMDGPU and NVPTX targets.
+- Added support for align-modifier in 'allocate' clause.
 
 Improvements
 
diff --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index d2f5267e4da5ea..b9088eff3bb52e 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -498,6 +498,9 @@ class OMPAllocateClause final
   /// Allocator specified in the clause, or 'nullptr' if the default one is
   /// used.
   Expr *Allocator = nullptr;
+  /// Alignment specified in the clause, or 'nullptr' if the default one is
+  /// used.
+  Expr *Alignment = nullptr;
   /// Position of the ':' delimiter in the clause;
   SourceLocation ColonLoc;
   /// Modifier of 'allocate' clause.
@@ -505,6 +508,41 @@ class OMPAllocateClause final
   /// Location of allocator modifier if any.
   SourceLocation AllocatorModifierLoc;
 
+  // 

+
+  /// Modifiers for 'allocate' clause.
+  enum { FIRST, SECOND, NUM_MODIFIERS };
+  OpenMPAllocateClauseModifier Modifiers[NUM_MODIFIERS];
+
+  /// Locations of modifiers.
+  SourceLocation ModifiersLoc[NUM_MODIFIERS];
+
+  /// Set the first allocate modifier.
+  ///
+  /// \param M Allocate modifier.
+  void setFirstAllocateModifier(OpenMPAllocateClauseModifier M) {
+Modifiers[FIRST] = M;
+  }
+
+  /// Set the second allocate modifier.
+  ///
+  /// \param M Allocate modifier.
+  void setSecondAllocateModifier(OpenMPAllocateClauseModifier M) {
+Modifiers[SECOND] = M;
+  }
+
+  /// Set location of the first allocate modifier.
+  void setFirstAllocateModifierLoc(SourceLocation Loc) {
+ModifiersLoc[FIRST] = Loc;
+  }
+
+  /// Set location of the second allocate modifier.
+  void setSecondAllocateModifierLoc(SourceLocation Loc) {
+ModifiersLoc[SECOND] = Loc;
+  }
+
+  // 

+
   /// Build clause with number of variables \a N.
   ///
   /// \param StartLoc Starting location of the clause.
@@ -514,15 +552,20 @@ class OMPAllocateClause final
   /// \param EndLoc Ending location of the clause.
   /// \param N Number of the variables in the clause.
   OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
-Expr *Allocator, SourceLocation ColonLoc,
-OpenMPAllocateClauseModifier AllocatorModifier,
-SourceLocation AllocatorModifierLoc, SourceLocation EndLoc,
+Expr *Allocator, Expr *Alignment, Sou

[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `WaveActiveSum` intrinsic (PR #118580)

2025-01-06 Thread Adam Yang via cfe-commits

https://github.com/adam-yang updated 
https://github.com/llvm/llvm-project/pull/118580

>From d435e26eb327b4d6c1e3530586b97372292ce214 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Fri, 18 Oct 2024 10:49:18 -0700
Subject: [PATCH 1/5] [HLSL][SPIRV][DXIL] Implement `WaveActiveSum` intrinsic

- add clang builtin to Builtins.td
  - link builtin in hlsl_intrinsics
  - add codegen for spirv intrinsic and two directx intrinsics to retain
signedness information of the operands in CGBuiltin.cpp
  - add semantic analysis in SemaHLSL.cpp
  - add lowering of spirv intrinsic to spirv backend in
SPIRVInstructionSelector.cpp
  - add lowering of directx intrinsics to WaveActiveOp dxil op in
DXIL.td

  - add test cases to illustrate passes
---
 clang/include/clang/Basic/Builtins.td |   6 +
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  34 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  99 
 clang/lib/Sema/SemaHLSL.cpp   |  31 
 .../CodeGenHLSL/builtins/WaveActiveSum.hlsl   |  45 ++
 .../BuiltIns/WaveActiveSum-errors.hlsl|  28 
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   2 +
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |   1 +
 llvm/lib/Target/DirectX/DXIL.td   |  26 
 .../DirectX/DirectXTargetTransformInfo.cpp|   2 +
 .../Target/SPIRV/SPIRVInstructionSelector.cpp |  30 
 llvm/test/CodeGen/DirectX/WaveActiveSum.ll| 143 ++
 .../SPIRV/hlsl-intrinsics/WaveActiveSum.ll|  41 +
 14 files changed, 491 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/WaveActiveSum.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/WaveActiveSum-errors.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/WaveActiveSum.ll
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveSum.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 32a09e2ceb3857..5d825eba1ab7f4 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4774,6 +4774,12 @@ def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "unsigned int(bool)";
 }
 
+def HLSLWaveActiveSum : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_wave_active_sum"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void (...)";
+}
+
 def HLSLWaveGetLaneIndex : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_wave_get_lane_index"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f185a98720f5b9..d33c760fd214ca 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9272,6 +9272,9 @@ def err_typecheck_expect_scalar_or_vector : Error<
   "a vector of such type is required">;
 def err_typecheck_expect_any_scalar_or_vector : Error<
   "invalid operand of type %0 where a scalar or vector is required">;
+def err_typecheck_expect_scalar_or_vector_not_type : Error<
+  "invalid operand of type %0 where %1 or "
+  "a vector of such type is not allowed">;
 def err_typecheck_expect_flt_or_vector : Error<
   "invalid operand of type %0 where floating, complex or "
   "a vector of such types is required">;
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c2e983eebebc10..68f52ff2c36190 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19126,6 +19126,23 @@ static Intrinsic::ID 
getFirstBitHighIntrinsic(CGHLSLRuntime &RT, QualType QT) {
   return RT.getFirstBitUHighIntrinsic();
 }
 
+// Return wave active sum that corresponds to the QT scalar type
+static Intrinsic::ID getWaveActiveSumIntrinsic(llvm::Triple::ArchType Arch,
+   CGHLSLRuntime &RT, QualType QT) 
{
+  switch (Arch) {
+  case llvm::Triple::spirv:
+return llvm::Intrinsic::spv_wave_active_sum;
+  case llvm::Triple::dxil: {
+if (QT->isUnsignedIntegerType())
+  return llvm::Intrinsic::dx_wave_active_usum;
+return llvm::Intrinsic::dx_wave_active_sum;
+  }
+  default:
+llvm_unreachable("Intrinsic WaveActiveSum"
+ " not supported by target architecture");
+  }
+}
+
 Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
 const CallExpr *E,
 ReturnValueSlot ReturnValue) {
@@ -19435,6 +19452,23 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID),
 ArrayRef{OpExpr});
   }
+  case Builtin::BI__builtin_hlsl_wave_active_sum: {
+// Due to the use of variadic arguments, explicitly retreive argument
+Value *OpExpr = EmitScalarExpr(E->getArg(0));
+llvm::FunctionType *FT = llvm::FunctionType::get(
+  

[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `WaveActiveSum` intrinsic (PR #118580)

2025-01-06 Thread Adam Yang via cfe-commits


@@ -9272,6 +9272,8 @@ def err_typecheck_expect_scalar_or_vector : Error<
   "a vector of such type is required">;
 def err_typecheck_expect_any_scalar_or_vector : Error<
   "invalid operand of type %0 where a scalar or vector is required">;
+def err_typecheck_expect_scalar_or_vector_not_type : Error<

adam-yang wrote:

Merged `err_typecheck_expect_scalar_or_vector_not_type` and 
`err_typecheck_expect_any_scalar_or_vector` by putting ` where a scalar or 
vector is required` behind a `%select`.

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


[clang] [clang-tools-extra] [libcxx] [llvm] [libc++] implement views::concat (PR #120920)

2025-01-06 Thread A. Jiang via cfe-commits


@@ -0,0 +1,623 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___RANGES_CONCAT_VIEW_H
+#define _LIBCPP___RANGES_CONCAT_VIEW_H
+
+#include <__algorithm/ranges_find_if.h>
+#include <__assert>
+#include <__concepts/common_reference_with.h>
+#include <__concepts/constructible.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/copyable.h>
+#include <__concepts/derived_from.h>
+#include <__concepts/equality_comparable.h>
+#include <__concepts/swappable.h>
+#include <__config>
+#include <__functional/bind_back.h>
+#include <__functional/invoke.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/default_sentinel.h>
+#include <__iterator/distance.h>
+#include <__iterator/incrementable_traits.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iter_swap.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__memory/addressof.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/movable_box.h>
+#include <__ranges/non_propagating_cache.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__ranges/zip_view.h>
+#include <__type_traits/conditional.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/is_nothrow_constructible.h>
+#include <__type_traits/is_nothrow_convertible.h>
+#include <__type_traits/is_object.h>
+#include <__type_traits/make_unsigned.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/in_place.h>
+#include <__utility/move.h>
+#include 
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+namespace ranges {
+
+template 
+struct __extract_last : __extract_last<_Tail...> {};

frederick-vs-ja wrote:

We can use conditional compilation like this:

```C++
#ifdef __cpp_pack_indexing
template 
using __extract_last = _Tp...[sizeof...(_Tp) - 1];
#else
template 
struct __extract_last_impl : __extract_last<_Tail...> {};
template 
struct __extract_last_impl<_Tp> {
  using type = _Tp;
};

template 
using __extract_last = __extract_last_impl<_Tp...>::type;
#endif
```

But I'm not sure whether this is wanted.

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


[libclc] [llvm] [libclc] Add Maintainers.md for libclc (PR #118309)

2025-01-06 Thread David Spickett via cfe-commits

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


[clang] [clang-format] Add LT_RequiresExpression and LT_SimpleRequirement (PR #121681)

2025-01-06 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/121681

>From 14e26d9bb27724705e51fc134a4f3df2a09807e6 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 4 Jan 2025 23:42:38 -0800
Subject: [PATCH 1/2] [clang-format] Add LT_RequiresExpression and
 LT_SimpleRequirement

The new line types help to annotate */&/&& in simple requirements as binary
operators.

Fixes #121675.
---
 clang/lib/Format/TokenAnnotator.cpp   | 24 +
 clang/lib/Format/TokenAnnotator.h |  2 ++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 27 ++-
 3 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 945174ca9c5861..fa864f4c5e943d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1582,7 +1582,10 @@ class AnnotatingParser {
 return false;
   break;
 case tok::l_brace:
-  if (Style.Language == FormatStyle::LK_TextProto) {
+  if (IsCpp) {
+if (Tok->is(TT_RequiresExpressionLBrace))
+  Line.Type = LT_RequiresExpression;
+  } else if (Style.Language == FormatStyle::LK_TextProto) {
 FormatToken *Previous = Tok->getPreviousNonComment();
 if (Previous && Previous->isNot(TT_DictLiteral))
   Previous->setType(TT_SelectorName);
@@ -2024,8 +2027,10 @@ class AnnotatingParser {
   if (!consumeToken())
 return LT_Invalid;
 }
-if (Line.Type == LT_AccessModifier)
-  return LT_AccessModifier;
+if (Line.Type == LT_AccessModifier || Line.Type == LT_RequiresExpression ||
+Line.Type == LT_SimpleRequirement) {
+  return Line.Type;
+}
 if (KeywordVirtualFound)
   return LT_VirtualFunctionDecl;
 if (ImportStatement)
@@ -3102,8 +3107,10 @@ class AnnotatingParser {
   }
 }
 
-if (!Scopes.empty() && Scopes.back() == ST_CompoundRequirement)
+if (Line.Type == LT_SimpleRequirement ||
+(!Scopes.empty() && Scopes.back() == ST_CompoundRequirement)) {
   return TT_BinaryOperator;
+}
 
 return TT_PointerOrReference;
   }
@@ -3693,8 +3700,15 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
 
   if (!Line.Children.empty()) {
 ScopeStack.push_back(ST_ChildBlock);
-for (auto &Child : Line.Children)
+const bool InRequiresExpression = Line.Type == LT_RequiresExpression;
+for (auto &Child : Line.Children) {
+  if (InRequiresExpression &&
+  !Child->First->isOneOf(tok::kw_typename, tok::kw_requires,
+ TT_CompoundRequirementLBrace)) {
+Child->Type = LT_SimpleRequirement;
+  }
   annotate(*Child);
+}
 // ScopeStack can become empty if Child has an unmatched `}`.
 if (!ScopeStack.empty())
   ScopeStack.pop_back();
diff --git a/clang/lib/Format/TokenAnnotator.h 
b/clang/lib/Format/TokenAnnotator.h
index 1a250e94d97c50..fa15517042f250 100644
--- a/clang/lib/Format/TokenAnnotator.h
+++ b/clang/lib/Format/TokenAnnotator.h
@@ -33,6 +33,8 @@ enum LineType {
   LT_VirtualFunctionDecl,
   LT_ArrayOfStructInitializer,
   LT_CommentAbovePPDirective,
+  LT_RequiresExpression,
+  LT_SimpleRequirement,
 };
 
 enum ScopeType {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index a5b2d09a9f704d..0383780c2d84a2 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -370,6 +370,21 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_CastRParen);
   EXPECT_TOKEN(Tokens[11], tok::star, TT_BinaryOperator);
+
+  Tokens = annotate("template \n"
+"concept C = requires(T a, T b) { a && b; };");
+  ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+  EXPECT_TOKEN(Tokens[16], tok::l_brace, TT_RequiresExpressionLBrace);
+  EXPECT_TOKEN(Tokens[18], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template \n"
+"concept CheckMultiplicableBy = requires(T a, V b) {\n"
+"  { a * b } -> std::same_as;\n"
+"};");
+  ASSERT_EQ(Tokens.size(), 36u) << Tokens;
+  EXPECT_TOKEN(Tokens[19], tok::l_brace, TT_RequiresExpressionLBrace);
+  EXPECT_TOKEN(Tokens[20], tok::l_brace, TT_CompoundRequirementLBrace);
+  EXPECT_TOKEN(Tokens[22], tok::star, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
@@ -1456,18 +1471,6 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresExpressions) {
   EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_RequiresExpressionLBrace);
 }
 
-TEST_F(TokenAnnotatorTest, CompoundRequirement) {
-  auto Tokens = annotate("template \n"
- "concept CheckMultiplicableBy = requires(T a, V b) 
{\n"
- "  { a * b } -> std::same_as;\n"
- "};");
-  ASSERT_EQ(Tokens

[clang] [analyzer] Retry UNDEF Z3 queries at most "crosscheck-with-z3-retries-on-timeout" times (PR #120239)

2025-01-06 Thread Donát Nagy via cfe-commits


@@ -213,6 +215,15 @@ ANALYZER_OPTION(
 "400'000 should on average make Z3 queries run for up to 100ms on modern "
 "hardware. Set 0 for unlimited.", 0)
 
+ANALYZER_OPTION(
+unsigned, Z3CrosscheckRetriesOnTimeout,
+"crosscheck-with-z3-retries-on-timeout",
+"Set how many times the oracle is allowed to retry a Z3 query. "
+"Set 0 for not allowing retries, in which case each Z3 query would be "
+"attempted only once. Increasing the number of retries is often more "

NagyDonat wrote:

I would suggest using `crosscheck-with-z3-attempts-on-timeout` (because this is 
the "natural quantity"), documenting that _this must be a positive integer_ and 
reporting a clear error in the unlikely case when an user still tries to 
specify `crosscheck-with-z3-attempts-on-timeout=0`.

I don't think that this would "trap" too many users (because when they read 
about the existence of this option, they immediately see that its value is a 
positive integer) -- and even if they somehow end up with specifying 0, they 
get a visible error message that asks them to clarify their intentions.

On the other hand, the `crosscheck-with-z3-retries-on-timeout` option _is_ a 
trap, because if the user misunderstands its meaning (and does not notice the 
pedantic details that 'number of _retries_' does not count the first attempt), 
the analyzer will silently do the wrong thing.

Among the two options that you listed, I think 1. is acceptable but not ideal 
(when the user just wants to simply enable/disable this crosscheck feature, 
they should not bother with technical details like retries). About option 2. 
(keep the current state of the commit) I'd say that I still dislike it, but if 
another reviewer accepts your reasoning and favors that solution, then I won't 
block merging it.

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


[clang-tools-extra] [clang-tidy] Fix modernize-use-integer-sign-comparison comparison (PR #121506)

2025-01-06 Thread via cfe-commits

qt-tatiana wrote:

> Missing:
> 
> * Documentation entry to tell user about this behavior (single sentence)
> 
> To be considered:
> 
> * Configuration option to enable/disable this behavior

done

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


[clang] [OpenMP] Codegen support for masked combined construct (PR #120520)

2025-01-06 Thread CHANDRA GHALE via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix modernize-use-integer-sign-comparison comparison (PR #121506)

2025-01-06 Thread via cfe-commits

qt-tatiana wrote:

> Please update release note. I agree to enable this feature by default if 
> adding an option.

Done

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


[clang] [OpenMP] Codegen support for masked combined construct (PR #120520)

2025-01-06 Thread CHANDRA GHALE via cfe-commits

chandraghale wrote:

closing this PR . Splitting into separate patches for each directives.

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


[clang-tools-extra] [clang-tidy] Fix modernize-use-integer-sign-comparison comparison (PR #121506)

2025-01-06 Thread via cfe-commits

https://github.com/qt-tatiana updated 
https://github.com/llvm/llvm-project/pull/121506

>From 0591e8b7be49299e2b73634a6ad4f2330557b37a Mon Sep 17 00:00:00 2001
From: Tatiana Borisova 
Date: Thu, 2 Jan 2025 18:08:26 +0100
Subject: [PATCH 1/2] [clang-tidy] Fix modernize-use-integer-sign-comparison
 comparison

- modernize-use-integer-sign-comparison should ignore a comparison between
the signed wide type and the unsigned narrow type, see #120867
---
 .../UseIntegerSignComparisonCheck.cpp | 14 ++-
 .../modernize/use-integer-sign-comparison.cpp | 24 +--
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
index 8f807bc0a96d56..ebcfafcd391145 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -89,7 +89,8 @@ void UseIntegerSignComparisonCheck::storeOptions(
 
 void UseIntegerSignComparisonCheck::registerMatchers(MatchFinder *Finder) {
   const auto SignedIntCastExpr = intCastExpression(true, "sIntCastExpression");
-  const auto UnSignedIntCastExpr = intCastExpression(false);
+  const auto UnSignedIntCastExpr =
+  intCastExpression(false, "uIntCastExpression");
 
   // Flag all operators "==", "<=", ">=", "<", ">", "!="
   // that are used between signed/unsigned
@@ -111,7 +112,10 @@ void UseIntegerSignComparisonCheck::check(
 const MatchFinder::MatchResult &Result) {
   const auto *SignedCastExpression =
   Result.Nodes.getNodeAs("sIntCastExpression");
+  const auto *UnSignedCastExpression =
+  Result.Nodes.getNodeAs("uIntCastExpression");
   assert(SignedCastExpression);
+  assert(UnSignedCastExpression);
 
   // Ignore the match if we know that the signed int value is not negative.
   Expr::EvalResult EVResult;
@@ -134,6 +138,13 @@ void UseIntegerSignComparisonCheck::check(
   const Expr *RHS = BinaryOp->getRHS()->IgnoreImpCasts();
   if (LHS == nullptr || RHS == nullptr)
 return;
+
+  if (Result.Context->getTypeSize(
+  SignedCastExpression->getSubExpr()->getType()) >
+  Result.Context->getTypeSize(
+  UnSignedCastExpression->getSubExpr()->getType()))
+return;
+
   const Expr *SubExprLHS = nullptr;
   const Expr *SubExprRHS = nullptr;
   SourceRange R1 = SourceRange(LHS->getBeginLoc());
@@ -151,6 +162,7 @@ void UseIntegerSignComparisonCheck::check(
 SubExprRHS = RHSCast->getSubExpr();
 R2.setEnd(SubExprRHS->getBeginLoc().getLocWithOffset(-1));
   }
+
   DiagnosticBuilder Diag =
   diag(BinaryOp->getBeginLoc(),
"comparison between 'signed' and 'unsigned' integers");
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
index 99f00444c2d3f3..85eda925d5903c 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
@@ -32,7 +32,7 @@ int TemplateFuncParameters(T1 val1, T2 val2) {
 
 int AllComparisons() {
 unsigned int uVar = 42;
-unsigned short uArray[7] = {0, 1, 2, 3, 9, 7, 9};
+unsigned int uArray[7] = {0, 1, 2, 3, 9, 7, 9};
 
 int sVar = -42;
 short sArray[7] = {-1, -2, -8, -94, -5, -4, -6};
@@ -113,10 +113,30 @@ int AllComparisons() {
 // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
 // CHECK-FIXES: if (std::cmp_greater(uArray[6] , VALUE))
 
-
 FuncParameters(uVar);
 TemplateFuncParameter(sVar);
 TemplateFuncParameters(uVar, sVar);
 
 return 0;
 }
+
+bool foo1(int x, unsigned char y) {
+return x == y;
+// CHECK-MESSAGES-NOT: warning:
+}
+
+bool foo2(int x, unsigned short y) {
+return x == y;
+// CHECK-MESSAGES-NOT: warning:
+}
+
+bool bar1(unsigned int x, char y) {
+return x == y;
+// CHECK-MESSAGES-NOT: warning:
+}
+
+bool bar2(unsigned int x, short y) {
+return x == y;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: std::cmp_equal(x , y);
+}

>From c4694f4fd8bfffba3ad062f4bdd5dd69e6548bf1 Mon Sep 17 00:00:00 2001
From: Tatiana Borisova 
Date: Mon, 6 Jan 2025 12:53:55 +0100
Subject: [PATCH 2/2] [clang-tidy] Fix modernize-use-integer-sign-comparison
 comparison

- add ``ConsideringIntegerSize`` option, that ignores a comparison
between a signed wide and an unsigned narrow integer types, add
documentation.
---
 .../clang-tidy/modernize/ModernizeTidyModule.cpp|  8 
 .../modernize/UseIntegerSignComparisonCheck.cpp | 13 -
 .../modernize/UseIntegerSignComparisonCheck.h   |  1 +
 clang-tools-extra/docs/R

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

2025-01-06 Thread Fraser Cormack via cfe-commits


@@ -14585,11 +14585,18 @@ void Sema::CheckAddressOfPackedMember(Expr *rhs) {
  _2, _3, _4));
 }
 
+static ExprResult UsualUnaryConversionsNoPromoteInt(Sema &S, Expr *E) {
+  // Don't promote integer types
+  if (QualType Ty = E->getType(); 
S.getASTContext().isPromotableIntegerType(Ty))
+return S.DefaultFunctionArrayLvalueConversion(E);
+  return S.UsualUnaryConversions(E);

frasercrmck wrote:

Yes, pretty much. `UsualUnaryConversions` does 
`DefaultFunctionArrayLvalueConversion` first, then floating-point specific 
logic. However, it also handles `isPromotableBitField`s.

In your other comment you ask about enums, and perhaps bitfields also falls 
into that category? Do we really need to support these types in vector 
maths/arithmetic builtins? There are tests for them, so I preserved the 
existing logic (though seemingly not for bitfields) but I see the argument for 
removing that support.

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] Fix missing check for nullptr in CallExpr::getUnusedResultAttr (PR #118636)

2025-01-06 Thread Yihe Li via cfe-commits

Mick235711 wrote:

Gentle ping @cor3ntin @Sirraide

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


[clang] d8d4c18 - [AArch64][SME] Disable inlining of callees with new ZT0 state (#121338)

2025-01-06 Thread via cfe-commits

Author: Kerry McLaughlin
Date: 2025-01-06T12:02:28Z
New Revision: d8d4c187619098ee7b0497b4f40311e3ee1f9259

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

LOG: [AArch64][SME] Disable inlining of callees with new ZT0 state (#121338)

Inlining must be disabled for new-ZT0 callees as the callee is required
to save ZT0 and toggle PSTATE.ZA on entry.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/lib/CodeGen/Targets/AArch64.cpp
clang/test/CodeGen/AArch64/sme-inline-callees-streaming-attrs.c
clang/test/CodeGen/AArch64/sme-inline-streaming-attrs.c
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
llvm/test/Transforms/Inline/AArch64/sme-pstateza-attrs.ll

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 1ed379c76c8ea2..f3593f5313340b 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -291,6 +291,8 @@ def warn_function_always_inline_attribute_mismatch : 
Warning<
   "inlining may change runtime behaviour">, InGroup;
 def err_function_always_inline_new_za : Error<
   "always_inline function %0 has new za state">;
+def err_function_always_inline_new_zt0
+: Error<"always_inline function %0 has new zt0 state">;
 
 def warn_avx_calling_convention
 : Warning<"AVX vector %select{return|argument}0 of type %1 without '%2' "

diff  --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index 0680b4828b6daf..7db67ecba07c8f 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -1169,8 +1169,9 @@ void AArch64TargetCodeGenInfo::checkFunctionABI(
 enum class ArmSMEInlinability : uint8_t {
   Ok = 0,
   ErrorCalleeRequiresNewZA = 1 << 0,
-  WarnIncompatibleStreamingModes = 1 << 1,
-  ErrorIncompatibleStreamingModes = 1 << 2,
+  ErrorCalleeRequiresNewZT0 = 1 << 1,
+  WarnIncompatibleStreamingModes = 1 << 2,
+  ErrorIncompatibleStreamingModes = 1 << 3,
 
   IncompatibleStreamingModes =
   WarnIncompatibleStreamingModes | ErrorIncompatibleStreamingModes,
@@ -1198,9 +1199,12 @@ static ArmSMEInlinability GetArmSMEInlinability(const 
FunctionDecl *Caller,
 else
   Inlinability |= ArmSMEInlinability::WarnIncompatibleStreamingModes;
   }
-  if (auto *NewAttr = Callee->getAttr())
+  if (auto *NewAttr = Callee->getAttr()) {
 if (NewAttr->isNewZA())
   Inlinability |= ArmSMEInlinability::ErrorCalleeRequiresNewZA;
+if (NewAttr->isNewZT0())
+  Inlinability |= ArmSMEInlinability::ErrorCalleeRequiresNewZT0;
+  }
 
   return Inlinability;
 }
@@ -1227,6 +1231,11 @@ void 
AArch64TargetCodeGenInfo::checkFunctionCallABIStreaming(
   ArmSMEInlinability::ErrorCalleeRequiresNewZA)
 CGM.getDiags().Report(CallLoc, diag::err_function_always_inline_new_za)
 << Callee->getDeclName();
+
+  if ((Inlinability & ArmSMEInlinability::ErrorCalleeRequiresNewZT0) ==
+  ArmSMEInlinability::ErrorCalleeRequiresNewZT0)
+CGM.getDiags().Report(CallLoc, diag::err_function_always_inline_new_zt0)
+<< Callee->getDeclName();
 }
 
 // If the target does not have floating-point registers, but we are using a

diff  --git a/clang/test/CodeGen/AArch64/sme-inline-callees-streaming-attrs.c 
b/clang/test/CodeGen/AArch64/sme-inline-callees-streaming-attrs.c
index ce6f203631fc5c..2071e66e0d652c 100644
--- a/clang/test/CodeGen/AArch64/sme-inline-callees-streaming-attrs.c
+++ b/clang/test/CodeGen/AArch64/sme-inline-callees-streaming-attrs.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -target-feature 
+sme %s -DUSE_FLATTEN -o - | FileCheck %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -target-feature 
+sme %s -DUSE_ALWAYS_INLINE_STMT -o - | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -target-feature 
+sme -target-feature +sme2 %s -DUSE_FLATTEN -o - | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -target-feature 
+sme -target-feature +sme2 %s -DUSE_ALWAYS_INLINE_STMT -o - | FileCheck %s
 
 // REQUIRES: aarch64-registered-target
 
@@ -20,6 +20,7 @@ void fn_streaming_compatible(void) __arm_streaming_compatible 
{ was_inlined(); }
 void fn_streaming(void) __arm_streaming { was_inlined(); }
 __arm_locally_streaming void fn_locally_streaming(void) { was_inlined(); }
 __arm_new("za") void fn_streaming_new_za(void) __arm_streaming { 
was_inlined(); }
+__arm_new("zt0") void fn_streaming_new_zt0(void) __arm_streaming { 
was_inlined(); }
 
 FN_ATTR
 void caller(void) {
@@ -28,6 +29,7 @@ void caller(void) {
 STMT_ATTR fn_streaming();
 STMT_ATTR fn_locally_streaming();
 STMT_ATTR fn_

[clang] [llvm] [AArch64][SME] Disable inlining of callees with new ZT0 state (PR #121338)

2025-01-06 Thread Kerry McLaughlin via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix modernize-use-integer-sign-comparison comparison (PR #121506)

2025-01-06 Thread via cfe-commits

https://github.com/qt-tatiana updated 
https://github.com/llvm/llvm-project/pull/121506

>From 0591e8b7be49299e2b73634a6ad4f2330557b37a Mon Sep 17 00:00:00 2001
From: Tatiana Borisova 
Date: Thu, 2 Jan 2025 18:08:26 +0100
Subject: [PATCH 1/2] [clang-tidy] Fix modernize-use-integer-sign-comparison
 comparison

- modernize-use-integer-sign-comparison should ignore a comparison between
the signed wide type and the unsigned narrow type, see #120867
---
 .../UseIntegerSignComparisonCheck.cpp | 14 ++-
 .../modernize/use-integer-sign-comparison.cpp | 24 +--
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
index 8f807bc0a96d56..ebcfafcd391145 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -89,7 +89,8 @@ void UseIntegerSignComparisonCheck::storeOptions(
 
 void UseIntegerSignComparisonCheck::registerMatchers(MatchFinder *Finder) {
   const auto SignedIntCastExpr = intCastExpression(true, "sIntCastExpression");
-  const auto UnSignedIntCastExpr = intCastExpression(false);
+  const auto UnSignedIntCastExpr =
+  intCastExpression(false, "uIntCastExpression");
 
   // Flag all operators "==", "<=", ">=", "<", ">", "!="
   // that are used between signed/unsigned
@@ -111,7 +112,10 @@ void UseIntegerSignComparisonCheck::check(
 const MatchFinder::MatchResult &Result) {
   const auto *SignedCastExpression =
   Result.Nodes.getNodeAs("sIntCastExpression");
+  const auto *UnSignedCastExpression =
+  Result.Nodes.getNodeAs("uIntCastExpression");
   assert(SignedCastExpression);
+  assert(UnSignedCastExpression);
 
   // Ignore the match if we know that the signed int value is not negative.
   Expr::EvalResult EVResult;
@@ -134,6 +138,13 @@ void UseIntegerSignComparisonCheck::check(
   const Expr *RHS = BinaryOp->getRHS()->IgnoreImpCasts();
   if (LHS == nullptr || RHS == nullptr)
 return;
+
+  if (Result.Context->getTypeSize(
+  SignedCastExpression->getSubExpr()->getType()) >
+  Result.Context->getTypeSize(
+  UnSignedCastExpression->getSubExpr()->getType()))
+return;
+
   const Expr *SubExprLHS = nullptr;
   const Expr *SubExprRHS = nullptr;
   SourceRange R1 = SourceRange(LHS->getBeginLoc());
@@ -151,6 +162,7 @@ void UseIntegerSignComparisonCheck::check(
 SubExprRHS = RHSCast->getSubExpr();
 R2.setEnd(SubExprRHS->getBeginLoc().getLocWithOffset(-1));
   }
+
   DiagnosticBuilder Diag =
   diag(BinaryOp->getBeginLoc(),
"comparison between 'signed' and 'unsigned' integers");
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
index 99f00444c2d3f3..85eda925d5903c 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
@@ -32,7 +32,7 @@ int TemplateFuncParameters(T1 val1, T2 val2) {
 
 int AllComparisons() {
 unsigned int uVar = 42;
-unsigned short uArray[7] = {0, 1, 2, 3, 9, 7, 9};
+unsigned int uArray[7] = {0, 1, 2, 3, 9, 7, 9};
 
 int sVar = -42;
 short sArray[7] = {-1, -2, -8, -94, -5, -4, -6};
@@ -113,10 +113,30 @@ int AllComparisons() {
 // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
 // CHECK-FIXES: if (std::cmp_greater(uArray[6] , VALUE))
 
-
 FuncParameters(uVar);
 TemplateFuncParameter(sVar);
 TemplateFuncParameters(uVar, sVar);
 
 return 0;
 }
+
+bool foo1(int x, unsigned char y) {
+return x == y;
+// CHECK-MESSAGES-NOT: warning:
+}
+
+bool foo2(int x, unsigned short y) {
+return x == y;
+// CHECK-MESSAGES-NOT: warning:
+}
+
+bool bar1(unsigned int x, char y) {
+return x == y;
+// CHECK-MESSAGES-NOT: warning:
+}
+
+bool bar2(unsigned int x, short y) {
+return x == y;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: std::cmp_equal(x , y);
+}

>From da44d04b05501ce6646bd578d55ecf30f7f83a85 Mon Sep 17 00:00:00 2001
From: Tatiana Borisova 
Date: Mon, 6 Jan 2025 12:53:55 +0100
Subject: [PATCH 2/2] [clang-tidy] Fix modernize-use-integer-sign-comparison
 comparison

- add ``ConsideringIntegerSize`` option, that ignores a comparison
between a signed wide and an unsigned narrow integer types, add
documentation.
---
 .../clang-tidy/modernize/ModernizeTidyModule.cpp|  8 
 .../modernize/UseIntegerSignComparisonCheck.cpp | 13 -
 .../modernize/UseIntegerSignComparisonCheck.h   |  1 +
 clang-tools-extra/docs/R

[clang] [analyzer] Retry UNDEF Z3 queries at most "crosscheck-with-z3-retries-on-timeout" times (PR #120239)

2025-01-06 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

> I adjusted the first commit message to highlight my answer to these 
> questions. I hope that's clear enough.

Ok, I'd say that this explanation is _good enough_ to claim that "this change 
may be helpful" -- which is sufficient to merge this change, because it's 
conservative, non-disruptive and close to being an NFC change. (The only cost 
is that it increases code complexity, which is a pity IMO, but isn't a high 
priority problem...)

I think it would be good to include this reasoning in the final commit message 
of the merged commit that will be eventually placed on the main branch (unless 
you're strongly opposed to this).
 
> > To check this question, it would be nice to have measurements that compare 
> > the total analysis time and flakiness [...]
> 
> I think we discussed this under the RFC, but I want to make sure you confirm 
> this before I'd discard this point.

As I said on discourse, think that the measurements (that I know of) are too 
noisy:
> Due to this noise in the measurement results, I feel that these eight runs 
> are not enough to definitely demonstrate the usefulness of the suggested 
> patch (i.e. that multiple small queries are better than just one query with 
> an appropriately longer timeout). (At least their trend points in the right 
> direction, but this trend is weaker than the definitely-just-noise trend that 
> lower timeouts reduce the flakiness…)

However, I understand if you don't want to do more measurements (and want to 
merge this based on your good intuitions + the knowledge that it doesn't cause 
problems), then I'm not opposed and ready to accept this PR.

> @NagyDonat I think I'm ready for the next round of review.

Thanks for the updates! My only remaining open question is the bikeshedding 
about the name of the option, where I explained my position in an inline 
comment.

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


[clang] [NFC][analyzer][docs] Document MallocChecker's ownership attributes (PR #121759)

2025-01-06 Thread Kristóf Umann via cfe-commits

https://github.com/Szelethus created 
https://github.com/llvm/llvm-project/pull/121759

Exactly what it says on the tin! These were written ages ago (2010s), but are 
still functional, only the docs are missing.

![image](https://github.com/user-attachments/assets/e119d995-27c2-43b7-bbd5-39275129a8e1)


From 24b15119f476bf8c981618132b05357a87d98476 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Krist=C3=B3f=20Umann?= 
Date: Mon, 6 Jan 2025 13:14:37 +0100
Subject: [PATCH] [analyzer][docs] Document MallocChecker's ownership
 attributes

Exactly what it says on the tin! These were written ages ago (2010s),
but are still functional, only the docs are missing.
---
 clang/include/clang/Basic/Attr.td |  2 +-
 clang/include/clang/Basic/AttrDocs.td | 62 +++
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 90d2a2056fe1ba..0454642b52cf35 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2776,7 +2776,7 @@ def Ownership : InheritableAttr {
   let Args = [IdentifierArgument<"Module">,
   VariadicParamIdxArgument<"Args">];
   let Subjects = SubjectList<[HasFunctionProto]>;
-  let Documentation = [Undocumented];
+  let Documentation = [OwnershipDocs];
 }
 
 def Packed : InheritableAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fdad4c9a3ea191..b1b4685ae9259b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1389,6 +1389,68 @@ Query for this attribute with 
``__has_attribute(overloadable)``.
   }];
 }
 
+def OwnershipDocs : Documentation {
+  let Heading = "ownership_holds, ownership_returns, ownership_takes (Clang "
+"Static Analyzer)";
+  let Category = DocCatFunction;
+  let Content = [{
+
+.. note::
+
+  In order for the Clang Static Analyzer to acknowledge these attributes, the
+  ``Optimistic`` config needs to be set to true for the checker
+  ``unix.DynamicMemoryModeling``:
+
+  ``-Xclang -analyzer-config -Xclang 
unix.DynamicMemoryModeling:Optimistic=true``
+
+These attributes are used by the Clang Static Analyzer's dynamic memory 
modeling
+facilities to mark custom allocating/deallocating functions.
+
+All 3 attributes' first parameter of type string is the type of the allocation:
+``malloc``, ``new``, etc. to allow for catching mismatched deallocation bugs to
+be found.
+
+* Use ``ownership_returns`` to mark a function as an allocating function. Takes
+  1 parameter to denote the allocation type.
+* Use ``ownership_takes`` to mark a function as a deallocating function. Takes 
2
+  parameters: the allocation type, and the index of the parameter that is being
+  deallocated (counting from 1).
+* Use ``ownership_holds`` to mark that a function takes over the ownership of a
+  piece of memory. The analyzer will assume that the memory is not leaked even
+  if it finds that the last pointer referencing it went out of scope (almost as
+  if it was freed). Takes 2 parameters: the allocation type, and the index of
+  the parameter whose ownership will be taken over (counting from 1).
+
+Example:
+
+.. code-block:: c
+
+  // Denotes that my_malloc will return with adynamically allocated piece of
+  // memory using malloc().
+  void __attribute((ownership_returns(malloc))) *my_malloc(size_t);
+
+  // Denotes that my_free will deallocate its parameter using free().
+  void __attribute((ownership_takes(malloc, 1))) my_free(void *);
+
+  // Denotes that my_hold will take over the ownership of its parameter that 
was
+  // allocated via malloc().
+  void __attribute((ownership_holds(malloc, 1))) my_hold(void *);
+
+Further reading about dynamic memory modeling in the Clang Static Analyzer is
+found in these checker docs:
+:ref:`unix.Malloc `, :ref:`unix.MallocSizeof `,
+:ref:`unix.MismatchedDeallocator `,
+:ref:`cplusplus.NewDelete `,
+:ref:`cplusplus.NewDeleteLeaks `,
+:ref:`optin.taint.TaintedAlloc `.
+Mind that many more checkers are affected by dynamic memory modeling changes to
+some extent.
+
+Further reading for other annotations:
+`Source Annotations in the Clang Static Analyzer 
`_.
+}];
+}
+
 def ObjCMethodFamilyDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

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


[clang] [NFC][analyzer][docs] Document MallocChecker's ownership attributes (PR #121759)

2025-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Kristóf Umann (Szelethus)


Changes

Exactly what it says on the tin! These were written ages ago (2010s), but are 
still functional, only the docs are missing.

![image](https://github.com/user-attachments/assets/e119d995-27c2-43b7-bbd5-39275129a8e1)


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


2 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (+1-1) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+62) 


``diff
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 90d2a2056fe1ba..0454642b52cf35 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2776,7 +2776,7 @@ def Ownership : InheritableAttr {
   let Args = [IdentifierArgument<"Module">,
   VariadicParamIdxArgument<"Args">];
   let Subjects = SubjectList<[HasFunctionProto]>;
-  let Documentation = [Undocumented];
+  let Documentation = [OwnershipDocs];
 }
 
 def Packed : InheritableAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fdad4c9a3ea191..b1b4685ae9259b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1389,6 +1389,68 @@ Query for this attribute with 
``__has_attribute(overloadable)``.
   }];
 }
 
+def OwnershipDocs : Documentation {
+  let Heading = "ownership_holds, ownership_returns, ownership_takes (Clang "
+"Static Analyzer)";
+  let Category = DocCatFunction;
+  let Content = [{
+
+.. note::
+
+  In order for the Clang Static Analyzer to acknowledge these attributes, the
+  ``Optimistic`` config needs to be set to true for the checker
+  ``unix.DynamicMemoryModeling``:
+
+  ``-Xclang -analyzer-config -Xclang 
unix.DynamicMemoryModeling:Optimistic=true``
+
+These attributes are used by the Clang Static Analyzer's dynamic memory 
modeling
+facilities to mark custom allocating/deallocating functions.
+
+All 3 attributes' first parameter of type string is the type of the allocation:
+``malloc``, ``new``, etc. to allow for catching mismatched deallocation bugs to
+be found.
+
+* Use ``ownership_returns`` to mark a function as an allocating function. Takes
+  1 parameter to denote the allocation type.
+* Use ``ownership_takes`` to mark a function as a deallocating function. Takes 
2
+  parameters: the allocation type, and the index of the parameter that is being
+  deallocated (counting from 1).
+* Use ``ownership_holds`` to mark that a function takes over the ownership of a
+  piece of memory. The analyzer will assume that the memory is not leaked even
+  if it finds that the last pointer referencing it went out of scope (almost as
+  if it was freed). Takes 2 parameters: the allocation type, and the index of
+  the parameter whose ownership will be taken over (counting from 1).
+
+Example:
+
+.. code-block:: c
+
+  // Denotes that my_malloc will return with adynamically allocated piece of
+  // memory using malloc().
+  void __attribute((ownership_returns(malloc))) *my_malloc(size_t);
+
+  // Denotes that my_free will deallocate its parameter using free().
+  void __attribute((ownership_takes(malloc, 1))) my_free(void *);
+
+  // Denotes that my_hold will take over the ownership of its parameter that 
was
+  // allocated via malloc().
+  void __attribute((ownership_holds(malloc, 1))) my_hold(void *);
+
+Further reading about dynamic memory modeling in the Clang Static Analyzer is
+found in these checker docs:
+:ref:`unix.Malloc `, :ref:`unix.MallocSizeof `,
+:ref:`unix.MismatchedDeallocator `,
+:ref:`cplusplus.NewDelete `,
+:ref:`cplusplus.NewDeleteLeaks `,
+:ref:`optin.taint.TaintedAlloc `.
+Mind that many more checkers are affected by dynamic memory modeling changes to
+some extent.
+
+Further reading for other annotations:
+`Source Annotations in the Clang Static Analyzer 
`_.
+}];
+}
+
 def ObjCMethodFamilyDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

``




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


[clang] [clang] Fix missing check for nullptr in CallExpr::getUnusedResultAttr (PR #118636)

2025-01-06 Thread via cfe-commits

cor3ntin wrote:

Sorry about that, it fell in the cracks. (in the future, feel free to ping 
every week if no one replies)

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


[clang] 8f17c90 - [clang] Expose -f(no-)wrapv as clang-cl option (#120787)

2025-01-06 Thread via cfe-commits

Author: Nico Weber
Date: 2025-01-06T07:50:11-05:00
New Revision: 8f17c908e3858c0a2a9b1bed3f6506fec3c6f910

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

LOG: [clang] Expose -f(no-)wrapv as clang-cl option (#120787)

Also move the -fno-wrapv option definition next to the -fwrapv one while
here.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/cl-options.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 12edfbb171d34c..640cf1412dd981 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3508,8 +3508,6 @@ def fno_verbose_asm : Flag<["-"], "fno-verbose-asm">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
   MarshallingInfoNegativeFlag>;
 def fno_working_directory : Flag<["-"], "fno-working-directory">, 
Group;
-def fno_wrapv : Flag<["-"], "fno-wrapv">, Group,
-  Visibility<[ClangOption, FlangOption]>;
 def fobjc_arc : Flag<["-"], "fobjc-arc">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Synthesize retain and release calls for Objective-C pointers">;
@@ -4280,8 +4278,10 @@ defm virtual_function_elimination : 
BoolFOption<"virtual-function-elimination",
   NegFlag, BothFlags<[], [ClangOption, CLOption]>>;
 
 def fwrapv : Flag<["-"], "fwrapv">, Group,
-  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
+  Visibility<[ClangOption, CLOption, CC1Option, FlangOption, FC1Option]>,
   HelpText<"Treat signed integer overflow as two's complement">;
+def fno_wrapv : Flag<["-"], "fno-wrapv">, Group,
+  Visibility<[ClangOption, CLOption, FlangOption]>;
 def fwritable_strings : Flag<["-"], "fwritable-strings">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Store string literals as writable data">,

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index c975727839c0bf..29a0fcbc17ac60 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -739,6 +739,8 @@
 // RUN: -fimplicit-modules \
 // RUN: -fno-implicit-modules \
 // RUN: -ftrivial-auto-var-init=zero \
+// RUN: -fwrapv \
+// RUN: -fno-wrapv \
 // RUN: --version \
 // RUN: -Werror /Zs -- %s 2>&1
 



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


[clang] [clang] Expose -f(no-)wrapv as clang-cl option (PR #120787)

2025-01-06 Thread Nico Weber via cfe-commits

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


[clang] [NFC][analyzer][docs] Document MallocChecker's ownership attributes (PR #121759)

2025-01-06 Thread Balazs Benics via cfe-commits


@@ -1389,6 +1389,68 @@ Query for this attribute with 
``__has_attribute(overloadable)``.
   }];
 }
 
+def OwnershipDocs : Documentation {
+  let Heading = "ownership_holds, ownership_returns, ownership_takes (Clang "
+"Static Analyzer)";
+  let Category = DocCatFunction;
+  let Content = [{
+
+.. note::
+
+  In order for the Clang Static Analyzer to acknowledge these attributes, the
+  ``Optimistic`` config needs to be set to true for the checker
+  ``unix.DynamicMemoryModeling``:
+
+  ``-Xclang -analyzer-config -Xclang 
unix.DynamicMemoryModeling:Optimistic=true``
+
+These attributes are used by the Clang Static Analyzer's dynamic memory 
modeling
+facilities to mark custom allocating/deallocating functions.
+
+All 3 attributes' first parameter of type string is the type of the allocation:
+``malloc``, ``new``, etc. to allow for catching mismatched deallocation bugs to
+be found.
+
+* Use ``ownership_returns`` to mark a function as an allocating function. Takes
+  1 parameter to denote the allocation type.
+* Use ``ownership_takes`` to mark a function as a deallocating function. Takes 
2
+  parameters: the allocation type, and the index of the parameter that is being
+  deallocated (counting from 1).
+* Use ``ownership_holds`` to mark that a function takes over the ownership of a
+  piece of memory. The analyzer will assume that the memory is not leaked even
+  if it finds that the last pointer referencing it went out of scope (almost as
+  if it was freed). Takes 2 parameters: the allocation type, and the index of
+  the parameter whose ownership will be taken over (counting from 1).
+
+Example:
+
+.. code-block:: c
+
+  // Denotes that my_malloc will return with adynamically allocated piece of
+  // memory using malloc().

steakhal wrote:

```suggestion
  // Denotes that my_malloc will return with a dynamically allocated piece of
  // memory using malloc().
```

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


  1   2   3   4   5   6   >