[clang] [clang][analyzer] Split NullDereferenceChecker into a modeling and checker part (PR #122139)

2025-01-09 Thread Balázs Kéri via cfe-commits


@@ -155,22 +155,27 @@ static bool isDeclRefExprToReference(const Expr *E) {
 
 void DereferenceChecker::reportBug(DerefKind K, ProgramStateRef State,
const Stmt *S, CheckerContext &C) const {
+  if (!CheckNullDereference) {
+C.addSink();

balazske wrote:

It will have no tag. Even if a `Tag` is passed to `addSink` it is ignored by 
the implementation: 
https://clang.llvm.org/doxygen/classclang_1_1ento_1_1CheckerContext.html#ab85fa7cc6b81e482f2565ff4cdb0a728
This code looks incorrect, the tag argument is not used and `addTransition` is 
not needed (`generateSink` does it already).

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


[clang] [clang] Refine the temporay object member access filtering for GSL pointer (PR #122088)

2025-01-09 Thread Haojian Wu via cfe-commits

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

>From 8c4f9bcb00c56f564abf6cfa115854681b48f7d9 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Tue, 17 Dec 2024 14:28:00 +0100
Subject: [PATCH 1/2] [clang] Refine the temporay object member access
 filtering for GSL pointer.

---
 clang/lib/Sema/CheckExprLifetime.cpp  | 42 +--
 clang/test/Sema/Inputs/lifetime-analysis.h|  2 +-
 .../Sema/warn-lifetime-analysis-nocfg.cpp | 28 +
 3 files changed, 58 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 7109de03cadd12..d0d05e4ed980d5 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -200,6 +200,7 @@ struct IndirectLocalPathEntry {
 LifetimeBoundCall,
 TemporaryCopy,
 LambdaCaptureInit,
+MemberExpr,
 GslReferenceInit,
 GslPointerInit,
 GslPointerAssignment,
@@ -578,19 +579,6 @@ static void visitFunctionCallArguments(IndirectLocalPath 
&Path, Expr *Call,
 Path.pop_back();
   };
   auto VisitGSLPointerArg = [&](const FunctionDecl *Callee, Expr *Arg) {
-// We are not interested in the temporary base objects of gsl Pointers:
-//   Temp().ptr; // Here ptr might not dangle.
-if (isa(Arg->IgnoreImpCasts()))
-  return;
-// Avoid false positives when the object is constructed from a conditional
-// operator argument. A common case is:
-//   // 'ptr' might not be owned by the Owner object.
-//   std::string_view s = cond() ? Owner().ptr : sv;
-if (const auto *Cond =
-dyn_cast(Arg->IgnoreImpCasts());
-Cond && isPointerLikeType(Cond->getType()))
-  return;
-
 auto ReturnType = Callee->getReturnType();
 
 // Once we initialized a value with a non gsl-owner reference, it can no
@@ -710,6 +698,9 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path,
 Init = ILE->getInit(0);
 }
 
+if (MemberExpr *ME = dyn_cast(Init->IgnoreImpCasts()))
+  Path.push_back(
+  {IndirectLocalPathEntry::MemberExpr, ME, ME->getMemberDecl()});
 // Step over any subobject adjustments; we may have a materialized
 // temporary inside them.
 Init = const_cast(Init->skipRValueSubobjectAdjustments());
@@ -1103,6 +1094,8 @@ shouldLifetimeExtendThroughPath(const IndirectLocalPath 
&Path) {
   for (auto Elem : Path) {
 if (Elem.Kind == IndirectLocalPathEntry::DefaultInit)
   return PathLifetimeKind::Extend;
+if (Elem.Kind == IndirectLocalPathEntry::MemberExpr)
+  continue;
 if (Elem.Kind != IndirectLocalPathEntry::LambdaCaptureInit)
   return PathLifetimeKind::NoExtend;
   }
@@ -1122,6 +1115,7 @@ static SourceRange nextPathEntryRange(const 
IndirectLocalPath &Path, unsigned I,
 case IndirectLocalPathEntry::GslPointerInit:
 case IndirectLocalPathEntry::GslPointerAssignment:
 case IndirectLocalPathEntry::ParenAggInit:
+case IndirectLocalPathEntry::MemberExpr:
   // These exist primarily to mark the path as not permitting or
   // supporting lifetime extension.
   break;
@@ -1151,6 +1145,7 @@ static bool pathOnlyHandlesGslPointer(const 
IndirectLocalPath &Path) {
 case IndirectLocalPathEntry::VarInit:
 case IndirectLocalPathEntry::AddressOf:
 case IndirectLocalPathEntry::LifetimeBoundCall:
+case IndirectLocalPathEntry::MemberExpr:
   continue;
 case IndirectLocalPathEntry::GslPointerInit:
 case IndirectLocalPathEntry::GslReferenceInit:
@@ -1184,6 +1179,26 @@ static AnalysisResult analyzePathForGSLPointer(const 
IndirectLocalPath &Path,
   // At this point, Path represents a series of operations involving a
   // GSLPointer, either in the process of initialization or assignment.
 
+  // Process  temporary base objects for MemberExpr cases, e.g. Temp().field.
+  for (const auto &E : Path) {
+if (E.Kind == IndirectLocalPathEntry::MemberExpr) {
+  // Avoid interfering  with the local base object.
+  if (pathContainsInit(Path))
+return Abandon;
+
+  // We are not interested in the temporary base objects of gsl Pointers:
+  //   auto p1 = Temp().ptr; // Here p1 might not dangle.
+  // However, we want to diagnose for gsl owner fields:
+  //   auto p2 = Temp().owner; // Here p2 is dangling.
+  if (const auto *FD = llvm::dyn_cast_or_null(E.D);
+  FD && !FD->getType()->isReferenceType() &&
+  isRecordWithAttr(FD->getType())) {
+return Report;
+  }
+  return Abandon;
+}
+  }
+
   // Note: A LifetimeBoundCall can appear interleaved in this sequence.
   // For example:
   //const std::string& Ref(const std::string& a [[clang::lifetimebound]]);
@@ -1510,6 +1525,7 @@ checkExprLifetimeImpl(Sema &SemaRef, const 
InitializedEntity *InitEntity,
 
   case IndirectLocalPathEntry::LifetimeBoundCall:
   case IndirectLocalPathEntry::TemporaryCopy:
+  case Indi

[clang] [clang] Refine the temporay object member access filtering for GSL pointer (PR #122088)

2025-01-09 Thread Haojian Wu via cfe-commits


@@ -806,3 +806,31 @@ std::string_view test2(int c, std::string_view sv) {
 }
 
 } // namespace GH120206
+
+namespace GH120543 {
+struct S {
+  std::string_view sv;
+  std::string s;
+};
+struct Q {
+  const S* get() const [[clang::lifetimebound]];
+};
+void test1() {
+  std::string_view k1 = S().sv; // OK
+  std::string_view k2 = S().s; // expected-warning {{object backing the 
pointer will}}
+  
+  std::string_view k3 = Q().get()->sv; // OK
+  std::string_view k4  = Q().get()->s; // expected-warning {{object backing 
the pointer will}}
+}

hokein wrote:

Done.

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


[clang] [clang] Refine the temporay object member access filtering for GSL pointer (PR #122088)

2025-01-09 Thread Haojian Wu via cfe-commits


@@ -1103,6 +1094,8 @@ shouldLifetimeExtendThroughPath(const IndirectLocalPath 
&Path) {
   for (auto Elem : Path) {
 if (Elem.Kind == IndirectLocalPathEntry::DefaultInit)
   return PathLifetimeKind::Extend;
+if (Elem.Kind == IndirectLocalPathEntry::MemberExpr)
+  continue;

hokein wrote:

This is necessary for the standard lifetime extension case. Since we add a new 
`MemberExpr` to the path, we need to skip it to maintain the existing behavior; 
otherwise, cases like `const int &x = A().i;` would incorrectly trigger 
diagnostics.

The case `const Bar& bar = foo.v.back();` is already handled on Line 1186.  

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


[clang] 397ac44 - [Coverage] Introduce the type `CounterPair` for RegionCounterMap. NFC. (#112724)

2025-01-09 Thread via cfe-commits

Author: NAKAMURA Takumi
Date: 2025-01-09T17:11:07+09:00
New Revision: 397ac44f623f891d8f05d6673a95984ac0a26671

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

LOG: [Coverage] Introduce the type `CounterPair` for RegionCounterMap. NFC. 
(#112724)

`CounterPair` can hold `` instead of current
`unsigned`, to hold also the counter number of SkipPath. For now, this
change provides the skeleton and only `CounterPair::Executed` is used.

Each counter number can have `None` to suppress emitting counter
increment. 2nd element `Skipped` is initialized as `None` by default,
since most `Stmt*` don't have a pair of counters.

This change also provides stubs for the verifier. I'll provide the impl
of verifier for `+Asserts` later.

`markStmtAsUsed(bool, Stmt*)` may be used to inform that other side
counter may not emitted.

`markStmtMaybeUsed(S)` may be used for the `Stmt` and its inner will be
excluded for emission in the case of skipping by constant folding. I put
it into places where I found.

`verifyCounterMap()` will check the coverage map and the counter map,
and can be used to report inconsistency.

These verifier methods shall be eliminated in `-Asserts`.


https://discourse.llvm.org/t/rfc-integrating-singlebytecoverage-with-branch-coverage/82492

Added: 


Modified: 
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/CodeGenPGO.cpp
clang/lib/CodeGen/CodeGenPGO.h
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/lib/CodeGen/CoverageMappingGen.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 47b21bc9f63f04..6f3ff050cb6978 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -361,6 +361,8 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const 
VarDecl &D,
 return GV;
   }
 
+  PGO.markStmtMaybeUsed(D.getInit()); // FIXME: Too lazy
+
 #ifndef NDEBUG
   CharUnits VarSize = CGM.getContext().getTypeSizeInChars(D.getType()) +
   D.getFlexibleArrayInitChars(getContext());
@@ -1868,7 +1870,10 @@ void CodeGenFunction::EmitAutoVarInit(const 
AutoVarEmission &emission) {
   // If we are at an unreachable point, we don't need to emit the initializer
   // unless it contains a label.
   if (!HaveInsertPoint()) {
-if (!Init || !ContainsLabel(Init)) return;
+if (!Init || !ContainsLabel(Init)) {
+  PGO.markStmtMaybeUsed(Init);
+  return;
+}
 EnsureInsertPoint();
   }
 
@@ -1979,6 +1984,8 @@ void CodeGenFunction::EmitAutoVarInit(const 
AutoVarEmission &emission) {
 return EmitExprAsInit(Init, &D, lv, capturedByInit);
   }
 
+  PGO.markStmtMaybeUsed(Init);
+
   if (!emission.IsConstantAggregate) {
 // For simple scalar/complex initialization, store the value directly.
 LValue lv = MakeAddrLValue(Loc, type);

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index ba1cba291553b0..1bad7a722da07a 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5148,6 +5148,7 @@ std::optional 
HandleConditionalOperatorLValueSimpleCase(
   // If the true case is live, we need to track its region.
   if (CondExprBool)
 CGF.incrementProfileCounter(E);
+  CGF.markStmtMaybeUsed(Dead);
   // If a throw expression we emit it and return an undefined lvalue
   // because it can't be used.
   if (auto *ThrowExpr = dyn_cast(Live->IgnoreParens())) {

diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index b282d4e0b32f05..0f27bd00422dce 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -5003,7 +5003,8 @@ Value *ScalarExprEmitter::VisitBinLAnd(const 
BinaryOperator *E) {
 CGF.incrementProfileCounter(E->getRHS());
 CGF.EmitBranch(FBlock);
 CGF.EmitBlock(FBlock);
-  }
+  } else
+CGF.markStmtMaybeUsed(E->getRHS());
 
   CGF.MCDCLogOpStack.pop_back();
   // If the top of the logical operator nest, update the MCDC bitmap.
@@ -5015,8 +5016,10 @@ Value *ScalarExprEmitter::VisitBinLAnd(const 
BinaryOperator *E) {
 }
 
 // 0 && RHS: If it is safe, just elide the RHS, and return 0/false.
-if (!CGF.ContainsLabel(E->getRHS()))
+if (!CGF.ContainsLabel(E->getRHS())) {
+  CGF.markStmtMaybeUsed(E->getRHS());
   return llvm::Constant::getNullValue(ResTy);
+}
   }
 
   // If the top of the logical operator nest, reset the MCDC temp to 0.
@@ -5143,7 +5146,8 @@ Value *ScalarExprEmitter::VisitBinLOr(const 
BinaryOperator *E) {
 CGF.incrementProf

[clang] [Coverage] Introduce the type `CounterPair` for RegionCounterMap. NFC. (PR #112724)

2025-01-09 Thread NAKAMURA Takumi via cfe-commits

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


[clang] -ftime-report: reorganize timers (PR #122225)

2025-01-09 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/15

>From 586f1fa8fb02431a962ca606fd546c2310427c80 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Wed, 8 Jan 2025 23:19:56 -0800
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/include/clang/CodeGen/BackendUtil.h | 10 ++
 .../include/clang/Frontend/CompilerInstance.h |  4 +++
 clang/lib/CodeGen/BackendConsumer.h   |  4 +--
 clang/lib/CodeGen/BackendUtil.cpp | 34 +++
 clang/lib/CodeGen/CodeGenAction.cpp   | 34 ++-
 .../CodeGen/ObjectFilePCHContainerWriter.cpp  | 15 
 .../Frontend/ftime-report-template-decl.cpp   | 14 
 7 files changed, 59 insertions(+), 56 deletions(-)

diff --git a/clang/include/clang/CodeGen/BackendUtil.h 
b/clang/include/clang/CodeGen/BackendUtil.h
index 7aa4f9db6c2e42..78d1e5ee8e6d59 100644
--- a/clang/include/clang/CodeGen/BackendUtil.h
+++ b/clang/include/clang/CodeGen/BackendUtil.h
@@ -25,11 +25,9 @@ class FileSystem;
 } // namespace llvm
 
 namespace clang {
+class CompilerInstance;
 class DiagnosticsEngine;
-class HeaderSearchOptions;
 class CodeGenOptions;
-class TargetOptions;
-class LangOptions;
 class BackendConsumer;
 
 enum BackendAction {
@@ -41,10 +39,8 @@ enum BackendAction {
   Backend_EmitObj   ///< Emit native object files
 };
 
-void EmitBackendOutput(DiagnosticsEngine &Diags, const HeaderSearchOptions &,
-   const CodeGenOptions &CGOpts, const TargetOptions 
&TOpts,
-   const LangOptions &LOpts, StringRef TDesc,
-   llvm::Module *M, BackendAction Action,
+void emitBackendOutput(CompilerInstance &CI, StringRef TDesc, llvm::Module *M,
+   BackendAction Action,
llvm::IntrusiveRefCntPtr VFS,
std::unique_ptr OS,
BackendConsumer *BC = nullptr);
diff --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 1220a4e29471d1..3cec57abae4445 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -630,6 +630,10 @@ class CompilerInstance : public ModuleLoader {
   /// @name Frontend timer
   /// @{
 
+  llvm::TimerGroup &getFrontendTimerGroup() const {
+return *FrontendTimerGroup;
+  }
+
   bool hasFrontendTimer() const { return (bool)FrontendTimer; }
 
   llvm::Timer &getFrontendTimer() const {
diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
index d932a78f469b95..ad3adfca367858 100644
--- a/clang/lib/CodeGen/BackendConsumer.h
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -28,8 +28,8 @@ class BackendConsumer : public ASTConsumer {
   using LinkModule = CodeGenAction::LinkModule;
 
   virtual void anchor();
+  CompilerInstance &CI;
   DiagnosticsEngine &Diags;
-  const HeaderSearchOptions &HeaderSearchOpts;
   const CodeGenOptions &CodeGenOpts;
   const TargetOptions &TargetOpts;
   const LangOptions &LangOpts;
@@ -70,7 +70,7 @@ class BackendConsumer : public ASTConsumer {
   llvm::Module *CurLinkModule = nullptr;
 
 public:
-  BackendConsumer(const CompilerInstance &CI, BackendAction Action,
+  BackendConsumer(CompilerInstance &CI, BackendAction Action,
   IntrusiveRefCntPtr VFS,
   llvm::LLVMContext &C, SmallVector LinkModules,
   StringRef InFile, std::unique_ptr OS,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 2dbab785658aa4..bcb14a9a166077 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -137,8 +137,6 @@ class EmitAssemblyHelper {
   llvm::Module *TheModule;
   IntrusiveRefCntPtr VFS;
 
-  Timer CodeGenerationTime;
-
   std::unique_ptr OS;
 
   Triple TargetTriple;
@@ -211,7 +209,6 @@ class EmitAssemblyHelper {
  IntrusiveRefCntPtr VFS)
   : Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
 TargetOpts(TOpts), LangOpts(LOpts), TheModule(M), VFS(std::move(VFS)),
-CodeGenerationTime("codegen", "Code Generation Time"),
 TargetTriple(TheModule->getTargetTriple()) {}
 
   ~EmitAssemblyHelper() {
@@ -222,8 +219,8 @@ class EmitAssemblyHelper {
   std::unique_ptr TM;
 
   // Emit output using the new pass manager for the optimization pipeline.
-  void EmitAssembly(BackendAction Action, std::unique_ptr 
OS,
-BackendConsumer *BC);
+  void emitAssembly(const CompilerInstance &CI, BackendAction Action,
+std::unique_ptr OS, BackendConsumer 
*BC);
 };
 } // namespace
 
@@ -1212,10 +1209,14 @@ void EmitAssemblyHelper::RunCodegenPipeline(
   }
 }
 
-void EmitAssemblyHelper::EmitAssembly(BackendAct

[clang] -ftime-report: reorganize timers (PR #122225)

2025-01-09 Thread Fangrui Song via cfe-commits

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


[clang] [compiler-rt] [Clang] Adjust pointer-overflow sanitizer for N3322 (PR #120719)

2025-01-09 Thread Nikita Popov via cfe-commits

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


[clang] 4847395 - [Clang] Adjust pointer-overflow sanitizer for N3322 (#120719)

2025-01-09 Thread via cfe-commits

Author: Nikita Popov
Date: 2025-01-09T09:23:23+01:00
New Revision: 4847395c5459f9c476808f9337abdae7fbd78a23

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

LOG: [Clang] Adjust pointer-overflow sanitizer for N3322 (#120719)

N3322 makes NULL + 0 well-defined in C, matching the C++ semantics.
Adjust the pointer-overflow sanitizer to no longer report NULL + 0 as a
pointer overflow in any language mode. NULL + nonzero will of course
continue to be reported.

As N3322 is part of
https://www.open-std.org/jtc1/sc22/wg14/www/previous.html, and we never
performed any optimizations based on NULL + 0 being undefined in the
first place, I'm applying this change to all C versions.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/UndefinedBehaviorSanitizer.rst
clang/lib/CodeGen/CGExprScalar.cpp

clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c
clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
clang/test/CodeGen/catch-pointer-overflow-volatile.c
clang/test/CodeGen/catch-pointer-overflow.c
clang/test/CodeGen/ubsan-pointer-overflow.c

compiler-rt/test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-constants.cpp

compiler-rt/test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-summary.cpp

compiler-rt/test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-variable.cpp
compiler-rt/test/ubsan_minimal/TestCases/nullptr-and-nonzero-offset.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2258452d07ec5a..ba522e310c9e44 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1283,6 +1283,12 @@ Sanitizers
   by the compiler (for example,
   ``-fno-sanitize-merge=bool,enum,array-bounds,local-bounds``).
 
+- Changed ``-fsanitize=pointer-overflow`` to no longer report ``NULL + 0`` as
+  undefined behavior in C, in line with
+  `N3322 `_,
+  and matching the previous behavior for C++.
+  ``NULL + non_zero`` continues to be reported as undefined behavior.
+
 Python Binding Changes
 --
 - Fixed an issue that led to crashes when calling 
``Type.get_exception_specification_kind``.

diff  --git a/clang/docs/UndefinedBehaviorSanitizer.rst 
b/clang/docs/UndefinedBehaviorSanitizer.rst
index b9ee4484fb9aec..c4895fb9722bfa 100644
--- a/clang/docs/UndefinedBehaviorSanitizer.rst
+++ b/clang/docs/UndefinedBehaviorSanitizer.rst
@@ -177,7 +177,7 @@ Available checks are:
  problems at higher optimization levels.
   -  ``-fsanitize=pointer-overflow``: Performing pointer arithmetic which
  overflows, or where either the old or new pointer value is a null pointer
- (or in C, when they both are).
+ (excluding the case where both are null pointers).
   -  ``-fsanitize=return``: In C++, reaching the end of a
  value-returning function without returning a value.
   -  ``-fsanitize=returns-nonnull-attribute``: Returning null pointer

diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 0f27bd00422dce..090c4fb3ea39ee 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -5841,9 +5841,8 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type 
*ElemTy, Value *Ptr,
 
   auto *Zero = llvm::ConstantInt::getNullValue(IntPtrTy);
 
-  // Common case: if the total offset is zero, and we are using C++ semantics,
-  // where nullptr+0 is defined, don't emit a check.
-  if (EvaluatedGEP.TotalOffset == Zero && CGM.getLangOpts().CPlusPlus)
+  // Common case: if the total offset is zero, don't emit a check.
+  if (EvaluatedGEP.TotalOffset == Zero)
 return GEPVal;
 
   // Now that we've computed the total offset, add it to the base pointer (with
@@ -5854,23 +5853,16 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type 
*ElemTy, Value *Ptr,
   llvm::SmallVector, 2> Checks;
 
   if (PerformNullCheck) {
-// In C++, if the base pointer evaluates to a null pointer value,
+// If the base pointer evaluates to a null pointer value,
 // the only valid  pointer this inbounds GEP can produce is also
 // a null pointer, so the offset must also evaluate to zero.
 // Likewise, if we have non-zero base pointer, we can not get null pointer
 // as a result, so the offset can not be -intptr_t(BasePtr).
 // In other words, both pointers are either null, or both are non-null,
 // or the behaviour is undefined.
-//
-// C, however, is more strict in this regard, and gives more
-// optimization opportunities: in C, additionally, nullptr+0 is undefined.
-// So both the input to the 'gep inbounds' AND the output must not be null.
 auto *BaseIsNotNullptr = Builder.CreateIsNotNull

[clang] [clang-format] Stop fixing indentation on namespace closing brace (PR #122234)

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

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/122234

Fixes #119790.

>From 38b8ebca922a7511d9f2bc048f3df0c9863cafc8 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 9 Jan 2025 00:16:30 -0800
Subject: [PATCH] [clang-format] Stop fixing indentation on namespace closing
 brace

Fixes #119790.
---
 clang/lib/Format/UnwrappedLineFormatter.cpp|  2 +-
 clang/unittests/Format/FormatTestSelective.cpp | 11 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index ec65fea6ec3df9..cee84fb1191abb 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1460,7 +1460,7 @@ unsigned UnwrappedLineFormatter::format(
 bool ContinueFormatting =
 TheLine.Level > RangeMinLevel ||
 (TheLine.Level == RangeMinLevel && !PreviousRBrace &&
- !TheLine.startsWith(tok::r_brace));
+ !TheLine.startsWith(TT_NamespaceRBrace));
 
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;
diff --git a/clang/unittests/Format/FormatTestSelective.cpp 
b/clang/unittests/Format/FormatTestSelective.cpp
index 3ae70a15d359b2..624684c7a079b8 100644
--- a/clang/unittests/Format/FormatTestSelective.cpp
+++ b/clang/unittests/Format/FormatTestSelective.cpp
@@ -388,6 +388,17 @@ TEST_F(FormatTestSelective, WrongIndent) {
"  int j;\n" // Format here.
"}",
24, 0));
+  EXPECT_EQ("namespace {\n"
+"class C {\n"
+"  int i;\n"
+"};\n"
+"} // namespace",
+format("namespace {\n" // Format here.
+   "  class C {\n"
+   "int i;\n"
+   "  };\n"
+   "}",
+   1, 0));
 }
 
 TEST_F(FormatTestSelective, AlwaysFormatsEntireMacroDefinitions) {

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


[clang] [clang-format] Stop fixing indentation on namespace closing brace (PR #122234)

2025-01-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #119790.

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


2 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+1-1) 
- (modified) clang/unittests/Format/FormatTestSelective.cpp (+11) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index ec65fea6ec3df9..cee84fb1191abb 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1460,7 +1460,7 @@ unsigned UnwrappedLineFormatter::format(
 bool ContinueFormatting =
 TheLine.Level > RangeMinLevel ||
 (TheLine.Level == RangeMinLevel && !PreviousRBrace &&
- !TheLine.startsWith(tok::r_brace));
+ !TheLine.startsWith(TT_NamespaceRBrace));
 
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;
diff --git a/clang/unittests/Format/FormatTestSelective.cpp 
b/clang/unittests/Format/FormatTestSelective.cpp
index 3ae70a15d359b2..624684c7a079b8 100644
--- a/clang/unittests/Format/FormatTestSelective.cpp
+++ b/clang/unittests/Format/FormatTestSelective.cpp
@@ -388,6 +388,17 @@ TEST_F(FormatTestSelective, WrongIndent) {
"  int j;\n" // Format here.
"}",
24, 0));
+  EXPECT_EQ("namespace {\n"
+"class C {\n"
+"  int i;\n"
+"};\n"
+"} // namespace",
+format("namespace {\n" // Format here.
+   "  class C {\n"
+   "int i;\n"
+   "  };\n"
+   "}",
+   1, 0));
 }
 
 TEST_F(FormatTestSelective, AlwaysFormatsEntireMacroDefinitions) {

``




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


[clang] -ftime-report: reorganize timers (PR #122225)

2025-01-09 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/15

>From 586f1fa8fb02431a962ca606fd546c2310427c80 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Wed, 8 Jan 2025 23:19:56 -0800
Subject: [PATCH 1/4] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/include/clang/CodeGen/BackendUtil.h | 10 ++
 .../include/clang/Frontend/CompilerInstance.h |  4 +++
 clang/lib/CodeGen/BackendConsumer.h   |  4 +--
 clang/lib/CodeGen/BackendUtil.cpp | 34 +++
 clang/lib/CodeGen/CodeGenAction.cpp   | 34 ++-
 .../CodeGen/ObjectFilePCHContainerWriter.cpp  | 15 
 .../Frontend/ftime-report-template-decl.cpp   | 14 
 7 files changed, 59 insertions(+), 56 deletions(-)

diff --git a/clang/include/clang/CodeGen/BackendUtil.h 
b/clang/include/clang/CodeGen/BackendUtil.h
index 7aa4f9db6c2e42..78d1e5ee8e6d59 100644
--- a/clang/include/clang/CodeGen/BackendUtil.h
+++ b/clang/include/clang/CodeGen/BackendUtil.h
@@ -25,11 +25,9 @@ class FileSystem;
 } // namespace llvm
 
 namespace clang {
+class CompilerInstance;
 class DiagnosticsEngine;
-class HeaderSearchOptions;
 class CodeGenOptions;
-class TargetOptions;
-class LangOptions;
 class BackendConsumer;
 
 enum BackendAction {
@@ -41,10 +39,8 @@ enum BackendAction {
   Backend_EmitObj   ///< Emit native object files
 };
 
-void EmitBackendOutput(DiagnosticsEngine &Diags, const HeaderSearchOptions &,
-   const CodeGenOptions &CGOpts, const TargetOptions 
&TOpts,
-   const LangOptions &LOpts, StringRef TDesc,
-   llvm::Module *M, BackendAction Action,
+void emitBackendOutput(CompilerInstance &CI, StringRef TDesc, llvm::Module *M,
+   BackendAction Action,
llvm::IntrusiveRefCntPtr VFS,
std::unique_ptr OS,
BackendConsumer *BC = nullptr);
diff --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 1220a4e29471d1..3cec57abae4445 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -630,6 +630,10 @@ class CompilerInstance : public ModuleLoader {
   /// @name Frontend timer
   /// @{
 
+  llvm::TimerGroup &getFrontendTimerGroup() const {
+return *FrontendTimerGroup;
+  }
+
   bool hasFrontendTimer() const { return (bool)FrontendTimer; }
 
   llvm::Timer &getFrontendTimer() const {
diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
index d932a78f469b95..ad3adfca367858 100644
--- a/clang/lib/CodeGen/BackendConsumer.h
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -28,8 +28,8 @@ class BackendConsumer : public ASTConsumer {
   using LinkModule = CodeGenAction::LinkModule;
 
   virtual void anchor();
+  CompilerInstance &CI;
   DiagnosticsEngine &Diags;
-  const HeaderSearchOptions &HeaderSearchOpts;
   const CodeGenOptions &CodeGenOpts;
   const TargetOptions &TargetOpts;
   const LangOptions &LangOpts;
@@ -70,7 +70,7 @@ class BackendConsumer : public ASTConsumer {
   llvm::Module *CurLinkModule = nullptr;
 
 public:
-  BackendConsumer(const CompilerInstance &CI, BackendAction Action,
+  BackendConsumer(CompilerInstance &CI, BackendAction Action,
   IntrusiveRefCntPtr VFS,
   llvm::LLVMContext &C, SmallVector LinkModules,
   StringRef InFile, std::unique_ptr OS,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 2dbab785658aa4..bcb14a9a166077 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -137,8 +137,6 @@ class EmitAssemblyHelper {
   llvm::Module *TheModule;
   IntrusiveRefCntPtr VFS;
 
-  Timer CodeGenerationTime;
-
   std::unique_ptr OS;
 
   Triple TargetTriple;
@@ -211,7 +209,6 @@ class EmitAssemblyHelper {
  IntrusiveRefCntPtr VFS)
   : Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
 TargetOpts(TOpts), LangOpts(LOpts), TheModule(M), VFS(std::move(VFS)),
-CodeGenerationTime("codegen", "Code Generation Time"),
 TargetTriple(TheModule->getTargetTriple()) {}
 
   ~EmitAssemblyHelper() {
@@ -222,8 +219,8 @@ class EmitAssemblyHelper {
   std::unique_ptr TM;
 
   // Emit output using the new pass manager for the optimization pipeline.
-  void EmitAssembly(BackendAction Action, std::unique_ptr 
OS,
-BackendConsumer *BC);
+  void emitAssembly(const CompilerInstance &CI, BackendAction Action,
+std::unique_ptr OS, BackendConsumer 
*BC);
 };
 } // namespace
 
@@ -1212,10 +1209,14 @@ void EmitAssemblyHelper::RunCodegenPipeline(
   }
 }
 
-void EmitAssemblyHelper::EmitAssembly(BackendAct

[clang] -ftime-report: reorganize timers (PR #122225)

2025-01-09 Thread Fangrui Song via cfe-commits

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


[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-01-09 Thread Matt Arsenault via cfe-commits


@@ -446,10 +448,11 @@ ABIArgInfo SystemZABIInfo::classifyArgumentType(QualType 
Ty) const {
 
 // The structure is passed as an unextended integer, a float, or a double.
 if (isFPArgumentType(SingleElementTy)) {
-  assert(Size == 32 || Size == 64);
+  assert(Size == 16 || Size == 32 || Size == 64);
   return ABIArgInfo::getDirect(
-  Size == 32 ? llvm::Type::getFloatTy(getVMContext())
- : llvm::Type::getDoubleTy(getVMContext()));
+  Size == 16   ? llvm::Type::getHalfTy(getVMContext())

arsenm wrote:

This will break on bfloat, don't assume type size -> fp type 

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


[clang] [llvm] [BasicAA] Do not decompose past casts with different index width (PR #119365)

2025-01-09 Thread Björn Pettersson via cfe-commits

bjope wrote:

But isn't it still a bit weird that if I change the datalayout to set the same 
pointer size for the two address spaces, then BasicAA is able to derive that 
there is NoAlias (https://godbolt.org/z/vhcG4jx7a), and the same goes even if 
using same address space for both accesses (https://godbolt.org/z/GoEM7zx68).

So this patch kind of messed things up for targets that have multiple address 
spaces, but with different pointer sizes, since the early out for "index size 
mismatch" is making it skip some checks that could help identify NoAlias.

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


[clang] [Headers][X86] amxintrin.h - fix attributes according to Intel SDM (PR #122204)

2025-01-09 Thread Phoebe Wang via cfe-commits

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

LGTM, thanks!

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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqciint (Interrupts) extension (PR #122256)

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


@@ -742,8 +742,8 @@ Error RISCVISAInfo::checkDependency() {
   bool HasZvl = MinVLen != 0;
   bool HasZcmt = Exts.count("zcmt") != 0;
   static constexpr StringLiteral XqciExts[] = {
-  {"xqcia"},  {"xqciac"},  {"xqcicli"}, {"xqcicm"},
-  {"xqcics"}, {"xqcicsr"}, {"xqcilsm"}, {"xqcisls"}};
+  {"xqcia"},   {"xqciac"},  {"xqcicli"}, {"xqcicm"}, {"xqcics"},

svs-quic wrote:

Nit: Remove the extra space here

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


[clang] [clang-tools-extra] Remove `StringLiteral` in favor of `StringRef` (PR #122366)

2025-01-09 Thread Jakub Kuderski via cfe-commits

https://github.com/kuhar commented:

Note that now we also have a new type for string tables: 
https://github.com/llvm/llvm-project/pull/119488 which doesn't result in 
relocations

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


[clang] [clang-tools-extra] Remove `StringLiteral` in favor of `StringRef` (PR #122366)

2025-01-09 Thread via cfe-commits


@@ -57,7 +57,7 @@ class DeclarationFragments {
 Keyword,
 Attribute,
 NumberLiteral,
-StringLiteral,
+StringRef,

QuietMisdreavus wrote:

This is an unnecessary find-and-replace. This enum constant specifically 
references a string literal, not the `StringLiteral` type.

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


[clang] [clang-tools-extra] Remove `StringLiteral` in favor of `StringRef` (PR #122366)

2025-01-09 Thread Benoit Jacob via cfe-commits


@@ -57,7 +57,7 @@ class DeclarationFragments {
 Keyword,
 Attribute,
 NumberLiteral,
-StringLiteral,
+StringRef,

bjacob wrote:

good catch! i'll pore over the actual diff line by line to catch more things 
like this, but I wanted to first see if this PR would be shot down at a higher 
level :-)

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


[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #120149)

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


@@ -8265,6 +8265,11 @@ def internal_externc_isystem : Separate<["-"], 
"internal-externc-isystem">,
"implicit extern \"C\" semantics; these are assumed to not be "
"user-provided and are used to model system and standard headers' "
"paths.">;
+def internal_iframework : Separate<["-"], "internal-iframework">,

ian-twilightcoder wrote:

I think it's handled here? 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/CompilerInvocation.cpp#L3327

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


[clang] [CMake] Add a cache file for building a highly-optimized LLVM toolchain (PR #117802)

2025-01-09 Thread Tom Stellard via cfe-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/117802

>From 3bddb3c6d25efbfcc901a42a8367be85599d1f7e Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Mon, 23 Sep 2024 13:34:46 +
Subject: [PATCH 1/4] [CMake] Add a cache file for building a highly-optimized
 LLVM toolchain

The goal of these cache files is to provide a toolchain that:

1. Relies on only LLVM components (as much as possible).
2. Is highly optimized.

These cache files will produce a full toolchain
(clang/compiler-rt/libcxx/lld) where clang is built with LTO, PGO, and
BOLT optimizations, and is statically linked with an LTO optimized
libc++ and compiler-rt.

I would eventually like to use these as the basis for the release
builds.
---
 .../cmake/caches/llvm-toolchain/stage1.cmake  | 13 
 .../cmake/caches/llvm-toolchain/stage2.cmake  | 20 +++
 .../llvm-toolchain/stage3-instrumented.cmake  | 10 ++
 .../cmake/caches/llvm-toolchain/stage3.cmake  | 16 +++
 clang/cmake/caches/llvm-toolchain/usage.rst   | 20 +++
 5 files changed, 79 insertions(+)
 create mode 100644 clang/cmake/caches/llvm-toolchain/stage1.cmake
 create mode 100644 clang/cmake/caches/llvm-toolchain/stage2.cmake
 create mode 100644 clang/cmake/caches/llvm-toolchain/stage3-instrumented.cmake
 create mode 100644 clang/cmake/caches/llvm-toolchain/stage3.cmake
 create mode 100644 clang/cmake/caches/llvm-toolchain/usage.rst

diff --git a/clang/cmake/caches/llvm-toolchain/stage1.cmake 
b/clang/cmake/caches/llvm-toolchain/stage1.cmake
new file mode 100644
index 00..13a0a7871dcd26
--- /dev/null
+++ b/clang/cmake/caches/llvm-toolchain/stage1.cmake
@@ -0,0 +1,13 @@
+# Stage 1:
+# * Build the prerequisites for stage 2.
+# * We will be building an LTO optimized libcxx in stage 2, so we need to
+#   build clang and lld.
+
+
+set(CMAKE_BUILD_TYPE Release CACHE STRING "")
+set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+set(LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "")
+
+set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
+set(CLANG_BOOTSTRAP_CMAKE_ARGS -C ${CMAKE_CURRENT_LIST_DIR}/stage2.cmake CACHE 
BOOL "")
+set(CLANG_BOOTSTRAP_TARGETS stage3-check-all stage3-distribution 
stage3-install-distribution stage3-clang stage3-clang-bolt CACHE BOOL "")
diff --git a/clang/cmake/caches/llvm-toolchain/stage2.cmake 
b/clang/cmake/caches/llvm-toolchain/stage2.cmake
new file mode 100644
index 00..87ac7899b205ef
--- /dev/null
+++ b/clang/cmake/caches/llvm-toolchain/stage2.cmake
@@ -0,0 +1,20 @@
+# Stage 2:
+# * Build an LTO optimized libcxx, so we can staticially link it into stage 3
+#   clang.
+# * Stage 3 will be PGO optimized, so we need to build clang, lld, and
+#   compiler-rt in stage 2.
+
+
+set(CMAKE_BUILD_TYPE Release CACHE STRING "")
+set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING 
"" FORCE)
+set(LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "" FORCE)
+
+set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
+set(CLANG_BOOTSTRAP_CMAKE_ARGS -C 
${CMAKE_CURRENT_LIST_DIR}/stage3-instrumented.cmake CACHE BOOL "")
+set(BOOTSTRAP_LLVM_BUILD_INSTRUMENTED IR CACHE BOOL "")
+set(CLANG_BOOTSTRAP_TARGETS stage3-check-all stage3-distribution 
stage3-install-distribution stage3-clang stage3-clang-bolt CACHE BOOL "")
+set(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE STRING "")
+set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON" CACHE STRING 
"")
+set(LLVM_ENABLE_LLD ON CACHE STRING "")
+#set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
diff --git a/clang/cmake/caches/llvm-toolchain/stage3-instrumented.cmake 
b/clang/cmake/caches/llvm-toolchain/stage3-instrumented.cmake
new file mode 100644
index 00..4570a6c758ccda
--- /dev/null
+++ b/clang/cmake/caches/llvm-toolchain/stage3-instrumented.cmake
@@ -0,0 +1,10 @@
+# Stage 3 instrumented:
+# * Build an instrumented clang, so we can generate profile data for stage 3.
+
+
+set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
+set(CLANG_BOOTSTRAP_CMAKE_ARGS -C ${CMAKE_CURRENT_LIST_DIR}/stage3.cmake CACHE 
BOOL "")
+set(CLANG_BOOTSTRAP_TARGETS clang check-all distribution install-distribution 
clang-bolt CACHE BOOL "")
+set(CLANG_BOLT OFF CACHE STRING "")
+
+include(${CMAKE_CURRENT_LIST_DIR}/stage3.cmake)
diff --git a/clang/cmake/caches/llvm-toolchain/stage3.cmake 
b/clang/cmake/caches/llvm-toolchain/stage3.cmake
new file mode 100644
index 00..a9050a64d8f633
--- /dev/null
+++ b/clang/cmake/caches/llvm-toolchain/stage3.cmake
@@ -0,0 +1,16 @@
+# Stage 3:
+# * This is the final stage.
+# * The goals is to have a clang that is LTO, PGO, and bolt optimized and also
+#   statically linked to libcxx and compiler-rt.
+
+set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING 
"" FORCE)
+set(LLVM_ENABLE_PROJECTS "clang;lld;bolt;" CACHE STRING "" FORCE)
+set(LLVM_ENAB

[clang] [CMake] Add a cache file for building a highly-optimized LLVM toolchain (PR #117802)

2025-01-09 Thread Tom Stellard via cfe-commits


@@ -0,0 +1,17 @@
+# Stage 1
+# * Build an LTO optimized libcxx, so we can staticially link it into stage 2
+#   clang.
+
+
+set(CMAKE_BUILD_TYPE Release CACHE STRING "")
+set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING 
"" FORCE)

tstellar wrote:

FORCE isn't required in the stage1 spec, so I'll remove it.

https://github.com/llvm/llvm-project/pull/117802
___
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-09 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/6] [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-tools-extra] [clang-tidy] Add C++ member function support to custom bugprone-unsafe-functions matches (PR #117165)

2025-01-09 Thread Julian Schmidt via cfe-commits


@@ -139,6 +150,12 @@ Options
 function, and an optional reason, separated by comma. For more information,
 see :ref:`Custom functions`.
 
+.. option:: ShowFullyQualifiedNames
+
+When `true`, the fully qualified name of all functions matched by the 
custom
+function matchers will be shown.
+Default is `false`.
+

5chmidti wrote:

This can be removed, now that the option is no longer part of this PR

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


[clang] [clang-tools-extra] Remove `StringLiteral` in favor of `StringRef` (PR #122366)

2025-01-09 Thread Benoit Jacob via cfe-commits


@@ -57,7 +57,7 @@ class DeclarationFragments {
 Keyword,
 Attribute,
 NumberLiteral,
-StringLiteral,
+StringRef,

bjacob wrote:

Thanks for the heads up -- will fix one by one.

Also, note to self:  let's leep `StringLiteral` around as deprecated to give 
downstreams a smoother transition.

https://github.com/llvm/llvm-project/pull/122366
___
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 -fsanitize-skip-hot-cutoff (PR #121619)

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

https://github.com/thurstond edited 
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] [HLSL] Implement the HLSL distance intrinsic (PR #122357)

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


@@ -871,6 +871,34 @@ float3 degrees(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
 float4 degrees(float4);
 
+//===--===//
+// distance builtins
+//===--===//
+
+/// \fn K distance(T X, T Y)
+/// \brief Returns a distance scalar between two vectors of \a X and \a Y.
+/// \param X The X input value.
+/// \param Y The Y input value.
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)

farzonl wrote:

its only 6.2 for half data types. implementations.

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


[clang] [clang-tools-extra] Remove `StringLiteral` in favor of `StringRef` (PR #122366)

2025-01-09 Thread Nikita Popov via cfe-commits


@@ -57,7 +57,7 @@ class DeclarationFragments {
 Keyword,
 Attribute,
 NumberLiteral,
-StringLiteral,
+StringRef,

nikic wrote:

Generally a lot of clang changes are wrong. There's a StringLiteral AST node, 
without relation to StringRef...

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


[clang] Fix print module manifest file for macos (PR #122370)

2025-01-09 Thread Bill Hoffman via cfe-commits

https://github.com/billhoffman created 
https://github.com/llvm/llvm-project/pull/122370

This commit fixes -print-library-module-manifest-path on macos. Currently, this 
only works on linux systems. This is because on macos systems the library and 
header files are installed in a different location. The module manifest is next 
to the libraries and the search function was not looking in both places.  There 
is also a test included.


>From 225287dabef0f72e5703c1b872a962c452d6d775 Mon Sep 17 00:00:00 2001
From: Bill Hoffman 
Date: Thu, 9 Jan 2025 15:52:40 -0500
Subject: [PATCH] Fix print module manifest file for macos

---
 clang/lib/Driver/Driver.cpp   |  5 
 ...les-print-library-module-manifest-path.cpp | 26 +++
 2 files changed, 31 insertions(+)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 04f2664ffeaddb..15de7b62adb235 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6380,6 +6380,11 @@ std::string Driver::GetFilePath(StringRef Name, const 
ToolChain &TC) const {
   if (llvm::sys::fs::exists(Twine(R)))
 return std::string(R);
 
+  SmallString<128> R2(ResourceDir);
+  llvm::sys::path::append(R2, "..", "..", Name);
+  if (llvm::sys::fs::exists(Twine(R2)))
+return std::string(R2);
+
   SmallString<128> P(TC.getCompilerRTPath());
   llvm::sys::path::append(P, Name);
   if (llvm::sys::fs::exists(Twine(P)))
diff --git a/clang/test/Driver/modules-print-library-module-manifest-path.cpp 
b/clang/test/Driver/modules-print-library-module-manifest-path.cpp
index 3ba2709ad95cc8..8d17fe1549e34b 100644
--- a/clang/test/Driver/modules-print-library-module-manifest-path.cpp
+++ b/clang/test/Driver/modules-print-library-module-manifest-path.cpp
@@ -18,6 +18,28 @@
 // RUN: --target=x86_64-linux-gnu 2>&1 \
 // RUN:   | FileCheck libcxx.cpp
 
+// for macos there is a different directory structure
+// where the library and libc++.modules.json file are in lib
+// directly but headers are in clang/ver directory which
+// is the resource directory
+// RUN: mkdir -p %t/Inputs/usr/lib/clang/20
+// RUN: touch %t/Inputs/usr/lib/libc++.so
+// RUN: touch %t/Inputs/usr/lib/libc++.modules.json
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: -resource-dir=%t/Inputs/usr/lib/clang/20 \
+// RUN: --target=arm64-apple-darwin24.1.0 2>&1 \
+// RUN:   | FileCheck libcxx.cpp.macos
+
+// RUN: rm %t/Inputs/usr/lib/libc++.so
+// RUN: touch %t/Inputs/usr/lib/libc++.a
+// RUN: touch %t/Inputs/usr/lib/libc++.modules.json
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: -resource-dir=%t/Inputs/usr/lib/clang/20 \
+// RUN: --target=arm64-apple-darwin24.1.0 2>&1 \
+// RUN:   | FileCheck libcxx.cpp.macos
+
 // RUN: rm %t/Inputs/usr/lib/x86_64-linux-gnu/libc++.so
 // RUN: touch %t/Inputs/usr/lib/x86_64-linux-gnu/libc++.a
 // RUN: %clang -print-library-module-manifest-path \
@@ -40,6 +62,10 @@
 
 // CHECK: {{.*}}/Inputs/usr/lib/x86_64-linux-gnu{{/|\\}}libc++.modules.json
 
+//--- libcxx.cpp.macos
+
+// CHECK: {{.*}}libc++.modules.json
+
 //--- libcxx-no-shared-lib.cpp
 
 // Note this might find a different path depending whether search path

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


[clang] [HLSL] Implement the HLSL distance intrinsic (PR #122357)

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


@@ -871,6 +871,34 @@ float3 degrees(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_degrees)
 float4 degrees(float4);
 
+//===--===//
+// distance builtins
+//===--===//
+
+/// \fn K distance(T X, T Y)
+/// \brief Returns a distance scalar between two vectors of \a X and \a Y.

bob80905 wrote:

The scalar overload conflicts with the comment. Wouldn't
"Returns a distance scalar between two vectors or scalars X and Y" be better?

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


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

2025-01-09 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-sles-build-only` running on `rocm-worker-hw-04-sles` while 
building `clang` at step 6 "Add check check-clang".

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


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

```
Step 6 (Add check check-clang) failure: test (failure)
 TEST 'Clang :: 
SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang -cc1 
-internal-isystem 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/20/include
 -nostdsysteminc -triple x86_64-linux-gnu -std=c++17 -fsyntax-only 
-fsycl-is-device -verify 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp
+ /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang 
-cc1 -internal-isystem 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/20/include
 -nostdsysteminc -triple x86_64-linux-gnu -std=c++17 -fsyntax-only 
-fsycl-is-device -verify 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp
error: 'expected-error' diagnostics expected but not seen: 
  File 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp
 Line 173 (directive at 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp:172):
 'sycl_kernel_entry_point' attribute only applies to functions
error: 'expected-error' diagnostics seen but not expected: 
  File 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp
 Line 173: an attribute list cannot appear here
2 errors generated.

--




```



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


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

2025-01-09 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff d01ae567742c4d83b67483e15eb74c0ecd2e8270 
7173a486d82a3959fc6157a58488b10ece492821 --extensions cpp,h -- 
clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGHLSLRuntime.h 
clang/lib/Headers/hlsl/hlsl_detail.h clang/lib/Headers/hlsl/hlsl_intrinsics.h 
clang/lib/Sema/SemaHLSL.cpp llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index f4470d5de6..e5ff7531d2 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1301,7 +1301,7 @@ _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 const inline half length(half X) { return __detail::length_impl(X); }
 const inline float length(float X) { return __detail::length_impl(X); }
 
-template  
+template 
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 const inline half length(vector X) {
   return __detail::length_vec_impl(X);

``




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


[clang] [Clang][counted_by] Refactor __builtin_dynamic_object_size on FAMs (PR #122198)

2025-01-09 Thread Bill Wendling via cfe-commits


@@ -1060,238 +1061,331 @@ 
CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type,
   return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true);
 }
 
-const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberFieldAndOffset(
-ASTContext &Ctx, const RecordDecl *RD, const FieldDecl *FAMDecl,
-uint64_t &Offset) {
+namespace {
+
+/// StructFieldAccess is a simple visitor class to grab the first MemberExpr
+/// from an Expr. It records any ArraySubscriptExpr we meet along the way.
+struct StructFieldAccess
+: public ConstStmtVisitor {
+  const ArraySubscriptExpr *ASE = nullptr;
+
+  const MemberExpr *VisitMemberExpr(const MemberExpr *E) { return E; }
+
+  const MemberExpr *VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
+ASE = E;
+return Visit(E->getBase());
+  }
+  const MemberExpr *VisitCastExpr(const CastExpr *E) {
+return Visit(E->getSubExpr());
+  }
+  const MemberExpr *VisitParenExpr(const ParenExpr *E) {
+return Visit(E->getSubExpr());
+  }
+  const MemberExpr *VisitUnaryAddrOf(const clang::UnaryOperator *E) {
+return Visit(E->getSubExpr());
+  }
+  const MemberExpr *VisitUnaryDeref(const clang::UnaryOperator *E) {
+return Visit(E->getSubExpr());
+  }
+};
+
+} // end anonymous namespace
+
+/// Find a struct's flexible array member. It may be embedded inside multiple
+/// sub-structs, but must still be the last field.
+static const FieldDecl *FindFlexibleArrayMemberField(CodeGenFunction &CGF,
+ ASTContext &Ctx,
+ const RecordDecl *RD) {
   const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
-  getLangOpts().getStrictFlexArraysLevel();
-  uint32_t FieldNo = 0;
+  CGF.getLangOpts().getStrictFlexArraysLevel();
 
   if (RD->isImplicit())
 return nullptr;
 
   for (const FieldDecl *FD : RD->fields()) {
-if ((!FAMDecl || FD == FAMDecl) &&
-Decl::isFlexibleArrayMemberLike(
+if (Decl::isFlexibleArrayMemberLike(
 Ctx, FD, FD->getType(), StrictFlexArraysLevel,
-/*IgnoreTemplateOrMacroSubstitution=*/true)) {
-  const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
-  Offset += Layout.getFieldOffset(FieldNo);
+/*IgnoreTemplateOrMacroSubstitution=*/true))
   return FD;
+
+if (auto RT = FD->getType()->getAs())
+  if (const FieldDecl *FD =
+  FindFlexibleArrayMemberField(CGF, Ctx, RT->getAsRecordDecl()))
+return FD;
+  }
+
+  return nullptr;
+}
+
+/// Calculate the offset of a struct field. It may be embedded inside multiple
+/// sub-structs.
+static bool GetFieldOffset(ASTContext &Ctx, const RecordDecl *RD,
+   const FieldDecl *FD, int64_t &Offset) {
+  if (RD->isImplicit())
+return false;
+
+  const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
+  uint32_t FieldNo = 0;
+
+  for (const FieldDecl *Field : RD->fields()) {
+if (Field == FD) {
+  Offset += Layout.getFieldOffset(FieldNo);
+  return true;
 }
 
-QualType Ty = FD->getType();
-if (Ty->isRecordType()) {
-  if (const FieldDecl *Field = FindFlexibleArrayMemberFieldAndOffset(
-  Ctx, Ty->getAsRecordDecl(), FAMDecl, Offset)) {
-const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
+if (auto RT = Field->getType()->getAs()) {
+  if (GetFieldOffset(Ctx, RT->getAsRecordDecl(), FD, Offset)) {
 Offset += Layout.getFieldOffset(FieldNo);
-return Field;
+return true;
   }
 }
 
 if (!RD->isUnion())
   ++FieldNo;
   }
 
-  return nullptr;
+  return false;
 }
 
-static unsigned CountCountedByAttrs(const RecordDecl *RD) {
-  unsigned Num = 0;
+llvm::Value *
+CodeGenFunction::emitCountedByMemberSize(const Expr *E, llvm::Value *EmittedE,
+ unsigned Type,
+ llvm::IntegerType *ResType) {
+  ASTContext &Ctx = getContext();
 
-  for (const FieldDecl *FD : RD->fields()) {
-if (FD->getType()->isCountAttributedType())
-  return ++Num;
+  // Note: If the whole struct is specificed in the __bdos (i.e. Visitor
+  // returns a DeclRefExpr). The calculation of the whole size of the structure
+  // with a flexible array member can be done in two ways:
+  //
+  // 1) sizeof(struct S) + count * sizeof(typeof(fam))
+  // 2) offsetof(struct S, fam) + count * sizeof(typeof(fam))
+  //
+  // The first will add additional padding after the end of the array
+  // allocation while the second method is more precise, but not quite expected
+  // from programmers. See
+  // https://lore.kernel.org/lkml/ZvV6X5FPBBW7CO1f@archlinux/ for a discussion
+  // of the topic.
+  //
+  // GCC isn't (currently) able to calculate __bdos on a pointer to the whole
+  // structure. Therefore, because of the above issue, we choose to match what
+  // GCC does for consistency's s

[clang] [Clang][counted_by] Refactor __builtin_dynamic_object_size on FAMs (PR #122198)

2025-01-09 Thread Bill Wendling via cfe-commits


@@ -1060,238 +1061,331 @@ 
CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type,
   return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true);
 }
 
-const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberFieldAndOffset(
-ASTContext &Ctx, const RecordDecl *RD, const FieldDecl *FAMDecl,
-uint64_t &Offset) {
+namespace {
+
+/// StructFieldAccess is a simple visitor class to grab the first MemberExpr
+/// from an Expr. It records any ArraySubscriptExpr we meet along the way.
+struct StructFieldAccess
+: public ConstStmtVisitor {
+  const ArraySubscriptExpr *ASE = nullptr;
+
+  const MemberExpr *VisitMemberExpr(const MemberExpr *E) { return E; }
+
+  const MemberExpr *VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
+ASE = E;
+return Visit(E->getBase());
+  }
+  const MemberExpr *VisitCastExpr(const CastExpr *E) {
+return Visit(E->getSubExpr());
+  }
+  const MemberExpr *VisitParenExpr(const ParenExpr *E) {
+return Visit(E->getSubExpr());
+  }
+  const MemberExpr *VisitUnaryAddrOf(const clang::UnaryOperator *E) {
+return Visit(E->getSubExpr());
+  }
+  const MemberExpr *VisitUnaryDeref(const clang::UnaryOperator *E) {
+return Visit(E->getSubExpr());
+  }
+};
+
+} // end anonymous namespace
+
+/// Find a struct's flexible array member. It may be embedded inside multiple
+/// sub-structs, but must still be the last field.
+static const FieldDecl *FindFlexibleArrayMemberField(CodeGenFunction &CGF,
+ ASTContext &Ctx,
+ const RecordDecl *RD) {
   const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
-  getLangOpts().getStrictFlexArraysLevel();
-  uint32_t FieldNo = 0;
+  CGF.getLangOpts().getStrictFlexArraysLevel();
 
   if (RD->isImplicit())
 return nullptr;
 
   for (const FieldDecl *FD : RD->fields()) {
-if ((!FAMDecl || FD == FAMDecl) &&
-Decl::isFlexibleArrayMemberLike(
+if (Decl::isFlexibleArrayMemberLike(
 Ctx, FD, FD->getType(), StrictFlexArraysLevel,
-/*IgnoreTemplateOrMacroSubstitution=*/true)) {
-  const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
-  Offset += Layout.getFieldOffset(FieldNo);
+/*IgnoreTemplateOrMacroSubstitution=*/true))
   return FD;
+
+if (auto RT = FD->getType()->getAs())
+  if (const FieldDecl *FD =
+  FindFlexibleArrayMemberField(CGF, Ctx, RT->getAsRecordDecl()))
+return FD;
+  }
+
+  return nullptr;
+}
+
+/// Calculate the offset of a struct field. It may be embedded inside multiple
+/// sub-structs.
+static bool GetFieldOffset(ASTContext &Ctx, const RecordDecl *RD,
+   const FieldDecl *FD, int64_t &Offset) {
+  if (RD->isImplicit())
+return false;
+
+  const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
+  uint32_t FieldNo = 0;
+
+  for (const FieldDecl *Field : RD->fields()) {
+if (Field == FD) {
+  Offset += Layout.getFieldOffset(FieldNo);
+  return true;
 }
 
-QualType Ty = FD->getType();
-if (Ty->isRecordType()) {
-  if (const FieldDecl *Field = FindFlexibleArrayMemberFieldAndOffset(
-  Ctx, Ty->getAsRecordDecl(), FAMDecl, Offset)) {
-const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
+if (auto RT = Field->getType()->getAs()) {
+  if (GetFieldOffset(Ctx, RT->getAsRecordDecl(), FD, Offset)) {
 Offset += Layout.getFieldOffset(FieldNo);
-return Field;
+return true;
   }
 }
 
 if (!RD->isUnion())
   ++FieldNo;
   }
 
-  return nullptr;
+  return false;
 }
 
-static unsigned CountCountedByAttrs(const RecordDecl *RD) {
-  unsigned Num = 0;
+llvm::Value *
+CodeGenFunction::emitCountedByMemberSize(const Expr *E, llvm::Value *EmittedE,
+ unsigned Type,
+ llvm::IntegerType *ResType) {
+  ASTContext &Ctx = getContext();
 
-  for (const FieldDecl *FD : RD->fields()) {
-if (FD->getType()->isCountAttributedType())
-  return ++Num;
+  // Note: If the whole struct is specificed in the __bdos (i.e. Visitor
+  // returns a DeclRefExpr). The calculation of the whole size of the structure
+  // with a flexible array member can be done in two ways:
+  //
+  // 1) sizeof(struct S) + count * sizeof(typeof(fam))
+  // 2) offsetof(struct S, fam) + count * sizeof(typeof(fam))
+  //
+  // The first will add additional padding after the end of the array
+  // allocation while the second method is more precise, but not quite expected
+  // from programmers. See
+  // https://lore.kernel.org/lkml/ZvV6X5FPBBW7CO1f@archlinux/ for a discussion
+  // of the topic.
+  //
+  // GCC isn't (currently) able to calculate __bdos on a pointer to the whole
+  // structure. Therefore, because of the above issue, we choose to match what
+  // GCC does for consistency's s

[clang] [Clang][counted_by] Refactor __builtin_dynamic_object_size on FAMs (PR #122198)

2025-01-09 Thread Bill Wendling via cfe-commits


@@ -1343,6 +1430,12 @@ CodeGenFunction::emitBuiltinObjectSize(const Expr *E, 
unsigned Type,
   assert(Ptr->getType()->isPointerTy() &&
  "Non-pointer passed to __builtin_object_size?");
 
+  if (IsDynamic)

bwendling wrote:

At this point, we know that `EmittedE` has a value. See line 1429.

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


[clang] [Clang][counted_by] Refactor __builtin_dynamic_object_size on FAMs (PR #122198)

2025-01-09 Thread Bill Wendling via cfe-commits


@@ -1060,238 +1061,331 @@ 
CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type,
   return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true);
 }
 
-const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberFieldAndOffset(
-ASTContext &Ctx, const RecordDecl *RD, const FieldDecl *FAMDecl,
-uint64_t &Offset) {
+namespace {
+
+/// StructFieldAccess is a simple visitor class to grab the first MemberExpr
+/// from an Expr. It records any ArraySubscriptExpr we meet along the way.
+struct StructFieldAccess
+: public ConstStmtVisitor {
+  const ArraySubscriptExpr *ASE = nullptr;
+
+  const MemberExpr *VisitMemberExpr(const MemberExpr *E) { return E; }
+
+  const MemberExpr *VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
+ASE = E;
+return Visit(E->getBase());
+  }
+  const MemberExpr *VisitCastExpr(const CastExpr *E) {
+return Visit(E->getSubExpr());
+  }
+  const MemberExpr *VisitParenExpr(const ParenExpr *E) {
+return Visit(E->getSubExpr());
+  }
+  const MemberExpr *VisitUnaryAddrOf(const clang::UnaryOperator *E) {
+return Visit(E->getSubExpr());
+  }
+  const MemberExpr *VisitUnaryDeref(const clang::UnaryOperator *E) {
+return Visit(E->getSubExpr());
+  }
+};
+
+} // end anonymous namespace
+
+/// Find a struct's flexible array member. It may be embedded inside multiple
+/// sub-structs, but must still be the last field.
+static const FieldDecl *FindFlexibleArrayMemberField(CodeGenFunction &CGF,
+ ASTContext &Ctx,
+ const RecordDecl *RD) {
   const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
-  getLangOpts().getStrictFlexArraysLevel();
-  uint32_t FieldNo = 0;
+  CGF.getLangOpts().getStrictFlexArraysLevel();
 
   if (RD->isImplicit())
 return nullptr;
 
   for (const FieldDecl *FD : RD->fields()) {
-if ((!FAMDecl || FD == FAMDecl) &&
-Decl::isFlexibleArrayMemberLike(
+if (Decl::isFlexibleArrayMemberLike(
 Ctx, FD, FD->getType(), StrictFlexArraysLevel,
-/*IgnoreTemplateOrMacroSubstitution=*/true)) {
-  const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
-  Offset += Layout.getFieldOffset(FieldNo);
+/*IgnoreTemplateOrMacroSubstitution=*/true))
   return FD;
+
+if (auto RT = FD->getType()->getAs())
+  if (const FieldDecl *FD =
+  FindFlexibleArrayMemberField(CGF, Ctx, RT->getAsRecordDecl()))
+return FD;
+  }
+
+  return nullptr;
+}
+
+/// Calculate the offset of a struct field. It may be embedded inside multiple
+/// sub-structs.
+static bool GetFieldOffset(ASTContext &Ctx, const RecordDecl *RD,
+   const FieldDecl *FD, int64_t &Offset) {
+  if (RD->isImplicit())
+return false;
+
+  const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
+  uint32_t FieldNo = 0;
+
+  for (const FieldDecl *Field : RD->fields()) {
+if (Field == FD) {
+  Offset += Layout.getFieldOffset(FieldNo);
+  return true;
 }
 
-QualType Ty = FD->getType();
-if (Ty->isRecordType()) {
-  if (const FieldDecl *Field = FindFlexibleArrayMemberFieldAndOffset(
-  Ctx, Ty->getAsRecordDecl(), FAMDecl, Offset)) {
-const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
+if (auto RT = Field->getType()->getAs()) {
+  if (GetFieldOffset(Ctx, RT->getAsRecordDecl(), FD, Offset)) {
 Offset += Layout.getFieldOffset(FieldNo);
-return Field;
+return true;
   }
 }
 
 if (!RD->isUnion())
   ++FieldNo;
   }
 
-  return nullptr;
+  return false;
 }
 
-static unsigned CountCountedByAttrs(const RecordDecl *RD) {
-  unsigned Num = 0;
+llvm::Value *
+CodeGenFunction::emitCountedByMemberSize(const Expr *E, llvm::Value *EmittedE,
+ unsigned Type,
+ llvm::IntegerType *ResType) {
+  ASTContext &Ctx = getContext();
 
-  for (const FieldDecl *FD : RD->fields()) {
-if (FD->getType()->isCountAttributedType())
-  return ++Num;
+  // Note: If the whole struct is specificed in the __bdos (i.e. Visitor
+  // returns a DeclRefExpr). The calculation of the whole size of the structure
+  // with a flexible array member can be done in two ways:
+  //
+  // 1) sizeof(struct S) + count * sizeof(typeof(fam))
+  // 2) offsetof(struct S, fam) + count * sizeof(typeof(fam))
+  //
+  // The first will add additional padding after the end of the array
+  // allocation while the second method is more precise, but not quite expected
+  // from programmers. See
+  // https://lore.kernel.org/lkml/ZvV6X5FPBBW7CO1f@archlinux/ for a discussion
+  // of the topic.
+  //
+  // GCC isn't (currently) able to calculate __bdos on a pointer to the whole
+  // structure. Therefore, because of the above issue, we choose to match what
+  // GCC does for consistency's s

[clang] [Clang][counted_by] Refactor __builtin_dynamic_object_size on FAMs (PR #122198)

2025-01-09 Thread Bill Wendling via cfe-commits


@@ -1060,238 +1061,331 @@ 
CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type,
   return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true);
 }
 
-const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberFieldAndOffset(
-ASTContext &Ctx, const RecordDecl *RD, const FieldDecl *FAMDecl,
-uint64_t &Offset) {
+namespace {
+
+/// StructFieldAccess is a simple visitor class to grab the first MemberExpr
+/// from an Expr. It records any ArraySubscriptExpr we meet along the way.
+struct StructFieldAccess

bwendling wrote:

Both GCC and Clang return the same value for `__bdos(*ptr->array)` with my new 
change. For `__bdos(&ptr->array)` GCC returns -1 and Clang returns the 
calculated value (it does that even without this patch). So it's behavior that 
existed before the advent of `__counted_by` and is probably wrong, but maybe 
not? People have different expectations for `__bdos` in various situations it 
seems...

I'm tempted to leave it as is since it isn't a regression, unless you have 
strong feelings about it.

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


[clang] [InstrProf] Add frontend temporal profiling flag (PR #122385)

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

https://github.com/ellishg created 
https://github.com/llvm/llvm-project/pull/122385

As discussed in https://github.com/llvm/llvm-project/pull/121514 add the 
frontent flag `-fprofile-generate-temporal-instrumentation` to enable temporal 
profiling 
(https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068) 
as a replacement for `-forder-file-instrumentation` 
(https://discourse.llvm.org/t/deprecate-forder-file-instrumentation-in-favor-of-temporal-profiling/83903)

>From 28e1eb2d0383bf417f8f769f6964eacb02a45477 Mon Sep 17 00:00:00 2001
From: Ellis Hoag 
Date: Thu, 9 Jan 2025 14:51:13 -0800
Subject: [PATCH] [InstrProf] Add frontent temporal profiling flag

---
 clang/include/clang/Driver/Options.td |  5 -
 clang/lib/Driver/ToolChains/Clang.cpp | 11 ++-
 clang/test/Driver/clang_f_opts.c  |  2 +-
 .../fprofile-generate-temporal-instrumentation.c  |  7 +++
 4 files changed, 22 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/Driver/fprofile-generate-temporal-instrumentation.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 52823430919de4..7df5141499552c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1796,6 +1796,9 @@ def fprofile_generate_cold_function_coverage : 
Flag<["-"], "fprofile-generate-co
 def fprofile_generate_cold_function_coverage_EQ : Joined<["-"], 
"fprofile-generate-cold-function-coverage=">,
 Group, Visibility<[ClangOption, CLOption]>, 
MetaVarName<"">,
 HelpText<"Generate instrumented code to collect coverage info for cold 
functions into /default.profraw (overridden by LLVM_PROFILE_FILE env 
var)">;
+def fprofile_generate_temporal_instrumentation : Flag<["-"], 
"fprofile-generate-temporal-instrumentation">,
+Group, Visibility<[ClangOption, CLOption]>,
+HelpText<"Generate instrumented code to collect temporal information. See 
this RFC for details: 
https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068";>;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Visibility<[ClangOption, CLOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;
@@ -1891,7 +1894,7 @@ defm pseudo_probe_for_profiling : 
BoolFOption<"pseudo-probe-for-profiling",
   " pseudo probes for sample profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Visibility<[ClangOption, CC1Option, CLOption]>,
-HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var). Deprecated, please use temporal profiling.">;
+HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var). Deprecated, please use -fprofile-generate-temporal-instrumentation">;
 def fprofile_list_EQ : Joined<["-"], "fprofile-list=">,
 Group, Visibility<[ClangOption, CC1Option, CLOption]>,
 HelpText<"Filename defining the list of functions/files to instrument. "
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index a0002371da2f1b..a196bceba1f2d3 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -662,6 +662,15 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
 CmdArgs.push_back("--pgo-function-entry-coverage");
   }
 
+  if (auto *A = Args.getLastArg(
+  options::OPT_fprofile_generate_temporal_instrumentation)) {
+if (!PGOGenerateArg && !CSPGOGenerateArg)
+  D.Diag(clang::diag::err_drv_argument_only_allowed_with)
+  << A->getSpelling() << "-fprofile-generate or -fcs-profile-generate";
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("--pgo-temporal-instrumentation");
+  }
+
   Arg *PGOGenArg = nullptr;
   if (PGOGenerateArg) {
 assert(!CSPGOGenerateArg);
@@ -8050,7 +8059,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Args.getLastArg(options::OPT_forder_file_instrumentation)) {
 D.Diag(diag::warn_drv_deprecated_arg)
 << A->getAsString(Args) << /*hasReplacement=*/true
-<< "-mllvm -pgo-temporal-instrumentation";
+<< "-fprofile-generate-temporal-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
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index 2b72068eae1eeb..7448076cf367e5 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -424,7 +424,7 @@
 // CHECK-WARNING-DA

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

2025-01-09 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:

Added the flag in https://github.com/llvm/llvm-project/pull/122385

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] [InstrProf] Add frontend temporal profiling flag (PR #122385)

2025-01-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ellis Hoag (ellishg)


Changes

As discussed in https://github.com/llvm/llvm-project/pull/121514 add the 
frontent flag `-fprofile-generate-temporal-instrumentation` to enable temporal 
profiling 
(https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068) 
as a replacement for `-forder-file-instrumentation` 
(https://discourse.llvm.org/t/deprecate-forder-file-instrumentation-in-favor-of-temporal-profiling/83903)

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


4 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+4-1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+10-1) 
- (modified) clang/test/Driver/clang_f_opts.c (+1-1) 
- (added) clang/test/Driver/fprofile-generate-temporal-instrumentation.c (+7) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 52823430919de4..7df5141499552c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1796,6 +1796,9 @@ def fprofile_generate_cold_function_coverage : 
Flag<["-"], "fprofile-generate-co
 def fprofile_generate_cold_function_coverage_EQ : Joined<["-"], 
"fprofile-generate-cold-function-coverage=">,
 Group, Visibility<[ClangOption, CLOption]>, 
MetaVarName<"">,
 HelpText<"Generate instrumented code to collect coverage info for cold 
functions into /default.profraw (overridden by LLVM_PROFILE_FILE env 
var)">;
+def fprofile_generate_temporal_instrumentation : Flag<["-"], 
"fprofile-generate-temporal-instrumentation">,
+Group, Visibility<[ClangOption, CLOption]>,
+HelpText<"Generate instrumented code to collect temporal information. See 
this RFC for details: 
https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068";>;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Visibility<[ClangOption, CLOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;
@@ -1891,7 +1894,7 @@ defm pseudo_probe_for_profiling : 
BoolFOption<"pseudo-probe-for-profiling",
   " pseudo probes for sample profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Visibility<[ClangOption, CC1Option, CLOption]>,
-HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var). Deprecated, please use temporal profiling.">;
+HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var). Deprecated, please use -fprofile-generate-temporal-instrumentation">;
 def fprofile_list_EQ : Joined<["-"], "fprofile-list=">,
 Group, Visibility<[ClangOption, CC1Option, CLOption]>,
 HelpText<"Filename defining the list of functions/files to instrument. "
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index a0002371da2f1b..a196bceba1f2d3 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -662,6 +662,15 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
 CmdArgs.push_back("--pgo-function-entry-coverage");
   }
 
+  if (auto *A = Args.getLastArg(
+  options::OPT_fprofile_generate_temporal_instrumentation)) {
+if (!PGOGenerateArg && !CSPGOGenerateArg)
+  D.Diag(clang::diag::err_drv_argument_only_allowed_with)
+  << A->getSpelling() << "-fprofile-generate or -fcs-profile-generate";
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("--pgo-temporal-instrumentation");
+  }
+
   Arg *PGOGenArg = nullptr;
   if (PGOGenerateArg) {
 assert(!CSPGOGenerateArg);
@@ -8050,7 +8059,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Args.getLastArg(options::OPT_forder_file_instrumentation)) {
 D.Diag(diag::warn_drv_deprecated_arg)
 << A->getAsString(Args) << /*hasReplacement=*/true
-<< "-mllvm -pgo-temporal-instrumentation";
+<< "-fprofile-generate-temporal-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
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index 2b72068eae1eeb..7448076cf367e5 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -424,7 +424,7 @@
 // CHECK-WARNING-DAG: optimization flag '-fno-devirtualize-speculatively' is 
not supported
 // CHECK-WARNING-DAG: the flag '-fslp-vectorize-aggressive' has been 
deprecated and will be ignored
 // CHECK-WARNING-DAG: the flag '-fno-slp-vectorize-aggressive' has 

[clang] [InstrProf] Add frontend temporal profiling flag (PR #122385)

2025-01-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Ellis Hoag (ellishg)


Changes

As discussed in https://github.com/llvm/llvm-project/pull/121514 add the 
frontent flag `-fprofile-generate-temporal-instrumentation` to enable temporal 
profiling 
(https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068) 
as a replacement for `-forder-file-instrumentation` 
(https://discourse.llvm.org/t/deprecate-forder-file-instrumentation-in-favor-of-temporal-profiling/83903)

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


4 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+4-1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+10-1) 
- (modified) clang/test/Driver/clang_f_opts.c (+1-1) 
- (added) clang/test/Driver/fprofile-generate-temporal-instrumentation.c (+7) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 52823430919de4..7df5141499552c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1796,6 +1796,9 @@ def fprofile_generate_cold_function_coverage : 
Flag<["-"], "fprofile-generate-co
 def fprofile_generate_cold_function_coverage_EQ : Joined<["-"], 
"fprofile-generate-cold-function-coverage=">,
 Group, Visibility<[ClangOption, CLOption]>, 
MetaVarName<"">,
 HelpText<"Generate instrumented code to collect coverage info for cold 
functions into /default.profraw (overridden by LLVM_PROFILE_FILE env 
var)">;
+def fprofile_generate_temporal_instrumentation : Flag<["-"], 
"fprofile-generate-temporal-instrumentation">,
+Group, Visibility<[ClangOption, CLOption]>,
+HelpText<"Generate instrumented code to collect temporal information. See 
this RFC for details: 
https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068";>;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Visibility<[ClangOption, CLOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;
@@ -1891,7 +1894,7 @@ defm pseudo_probe_for_profiling : 
BoolFOption<"pseudo-probe-for-profiling",
   " pseudo probes for sample profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Visibility<[ClangOption, CC1Option, CLOption]>,
-HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var). Deprecated, please use temporal profiling.">;
+HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var). Deprecated, please use -fprofile-generate-temporal-instrumentation">;
 def fprofile_list_EQ : Joined<["-"], "fprofile-list=">,
 Group, Visibility<[ClangOption, CC1Option, CLOption]>,
 HelpText<"Filename defining the list of functions/files to instrument. "
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index a0002371da2f1b..a196bceba1f2d3 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -662,6 +662,15 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
 CmdArgs.push_back("--pgo-function-entry-coverage");
   }
 
+  if (auto *A = Args.getLastArg(
+  options::OPT_fprofile_generate_temporal_instrumentation)) {
+if (!PGOGenerateArg && !CSPGOGenerateArg)
+  D.Diag(clang::diag::err_drv_argument_only_allowed_with)
+  << A->getSpelling() << "-fprofile-generate or -fcs-profile-generate";
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("--pgo-temporal-instrumentation");
+  }
+
   Arg *PGOGenArg = nullptr;
   if (PGOGenerateArg) {
 assert(!CSPGOGenerateArg);
@@ -8050,7 +8059,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Args.getLastArg(options::OPT_forder_file_instrumentation)) {
 D.Diag(diag::warn_drv_deprecated_arg)
 << A->getAsString(Args) << /*hasReplacement=*/true
-<< "-mllvm -pgo-temporal-instrumentation";
+<< "-fprofile-generate-temporal-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
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index 2b72068eae1eeb..7448076cf367e5 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -424,7 +424,7 @@
 // CHECK-WARNING-DAG: optimization flag '-fno-devirtualize-speculatively' is 
not supported
 // CHECK-WARNING-DAG: the flag '-fslp-vectorize-aggressive' has been 
deprecated and will be ignored
 // CHECK-WARNING-DAG: the flag '-fno-slp-vectorize-aggressiv

[clang] [libclang] Allow using PrintingPolicy with types (PR #122386)

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

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

This allows controlling pretty-printing of types the same way it works with 
cursors.

>From a96fbe38f697f77c12c712f5573c2158072a8d2f Mon Sep 17 00:00:00 2001
From: Eli Friedman 
Date: Tue, 17 Dec 2024 17:46:09 -0800
Subject: [PATCH] [libclang] Allow using PrintingPolicy with types

This allows controlling pretty-printing of types the same way it works
with cursors.
---
 clang/bindings/python/clang/cindex.py |  6 ++
 .../bindings/python/tests/cindex/test_type.py | 19 ++-
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang-c/Index.h |  7 +++
 clang/tools/libclang/CXType.cpp   | 14 ++
 clang/tools/libclang/libclang.map |  1 +
 6 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 7caf0bbfd722af..e01285e27fcdf9 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -2701,6 +2701,11 @@ def spelling(self):
 """Retrieve the spelling of this Type."""
 return _CXString.from_result(conf.lib.clang_getTypeSpelling(self))
 
+def pretty_printed(self, policy):
+"""Pretty-prints this Type with the given PrintingPolicy"""
+return _CXString.from_result(conf.lib.clang_getTypePrettyPrinted(self, 
policy))
+
+
 def __eq__(self, other):
 if type(other) != type(self):
 return False
@@ -3955,6 +3960,7 @@ def set_property(self, property, value):
 ("clang_getTypedefDeclUnderlyingType", [Cursor], Type),
 ("clang_getTypedefName", [Type], _CXString),
 ("clang_getTypeKindSpelling", [c_uint], _CXString),
+("clang_getTypePrettyPrinted", [Type, PrintingPolicy], _CXString),
 ("clang_getTypeSpelling", [Type], _CXString),
 ("clang_hashCursor", [Cursor], c_uint),
 ("clang_isAttribute", [CursorKind], bool),
diff --git a/clang/bindings/python/tests/cindex/test_type.py 
b/clang/bindings/python/tests/cindex/test_type.py
index e1d8c2aad1c3a4..da27ba5bda3ee0 100644
--- a/clang/bindings/python/tests/cindex/test_type.py
+++ b/clang/bindings/python/tests/cindex/test_type.py
@@ -1,6 +1,14 @@
 import os
 
-from clang.cindex import Config, CursorKind, RefQualifierKind, 
TranslationUnit, TypeKind
+from clang.cindex import (
+Config,
+CursorKind,
+PrintingPolicy,
+PrintingPolicyProperty,
+RefQualifierKind,
+TranslationUnit,
+TypeKind
+)
 
 if "CLANG_LIBRARY_PATH" in os.environ:
 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
@@ -517,3 +525,12 @@ class Template {
 # Variable without a template argument.
 cursor = get_cursor(tu, "bar")
 self.assertEqual(cursor.get_num_template_arguments(), -1)
+
+def test_pretty(self):
+tu = get_tu("struct X {}; X x;", lang="cpp")
+f = get_cursor(tu, "x")
+
+pp = PrintingPolicy.create(f)
+self.assertEqual(f.type.get_canonical().pretty_printed(pp), "X")
+pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False)
+self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X")
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 07a1a4195427d8..d0479a94bd67ce 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1158,6 +1158,8 @@ libclang
 
 - Add ``clang_isBeforeInTranslationUnit``. Given two source locations, it 
determines
   whether the first one comes strictly before the second in the source code.
+- Add ``clang_getTypePrettyPrinted``.  It allows controlling the 
PrintingPolicy used
+  to pretty-print a type.
 
 Static Analyzer
 ---
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 63d266dc60ec73..e1f3759bb53e85 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -4182,6 +4182,13 @@ CINDEX_LINKAGE void 
clang_PrintingPolicy_dispose(CXPrintingPolicy Policy);
 CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor,
  CXPrintingPolicy Policy);
 
+/**
+ * Pretty-print the underlying type using a custom printing policy.
+ *
+ * If the type is invalid, an empty string is returned.
+ */
+CINDEX_LINKAGE CXString clang_getTypePrettyPrinted(CXType CT, CXPrintingPolicy 
cxPolicy);
+
 /**
  * Retrieve the display name for the entity referenced by this cursor.
  *
diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp
index b4df12405cf356..f97023c429bfae 100644
--- a/clang/tools/libclang/CXType.cpp
+++ b/clang/tools/libclang/CXType.cpp
@@ -313,6 +313,20 @@ CXString clang_getTypeSpelling(CXType CT) {
   return cxstring::createDup(OS.str());
 }
 
+CXString clang_getTypePrettyPrinted(CXType CT, CXPrintingPolicy cxPolicy) {
+  QualType T = GetQualType(CT);
+  if (T.isNull(

[clang] [libclang] Allow using PrintingPolicy with types (PR #122386)

2025-01-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Eli Friedman (efriedma-quic)


Changes

This allows controlling pretty-printing of types the same way it works with 
cursors.

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


6 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+6) 
- (modified) clang/bindings/python/tests/cindex/test_type.py (+18-1) 
- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang-c/Index.h (+7) 
- (modified) clang/tools/libclang/CXType.cpp (+14) 
- (modified) clang/tools/libclang/libclang.map (+1) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 7caf0bbfd722af..e01285e27fcdf9 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -2701,6 +2701,11 @@ def spelling(self):
 """Retrieve the spelling of this Type."""
 return _CXString.from_result(conf.lib.clang_getTypeSpelling(self))
 
+def pretty_printed(self, policy):
+"""Pretty-prints this Type with the given PrintingPolicy"""
+return _CXString.from_result(conf.lib.clang_getTypePrettyPrinted(self, 
policy))
+
+
 def __eq__(self, other):
 if type(other) != type(self):
 return False
@@ -3955,6 +3960,7 @@ def set_property(self, property, value):
 ("clang_getTypedefDeclUnderlyingType", [Cursor], Type),
 ("clang_getTypedefName", [Type], _CXString),
 ("clang_getTypeKindSpelling", [c_uint], _CXString),
+("clang_getTypePrettyPrinted", [Type, PrintingPolicy], _CXString),
 ("clang_getTypeSpelling", [Type], _CXString),
 ("clang_hashCursor", [Cursor], c_uint),
 ("clang_isAttribute", [CursorKind], bool),
diff --git a/clang/bindings/python/tests/cindex/test_type.py 
b/clang/bindings/python/tests/cindex/test_type.py
index e1d8c2aad1c3a4..da27ba5bda3ee0 100644
--- a/clang/bindings/python/tests/cindex/test_type.py
+++ b/clang/bindings/python/tests/cindex/test_type.py
@@ -1,6 +1,14 @@
 import os
 
-from clang.cindex import Config, CursorKind, RefQualifierKind, 
TranslationUnit, TypeKind
+from clang.cindex import (
+Config,
+CursorKind,
+PrintingPolicy,
+PrintingPolicyProperty,
+RefQualifierKind,
+TranslationUnit,
+TypeKind
+)
 
 if "CLANG_LIBRARY_PATH" in os.environ:
 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
@@ -517,3 +525,12 @@ class Template {
 # Variable without a template argument.
 cursor = get_cursor(tu, "bar")
 self.assertEqual(cursor.get_num_template_arguments(), -1)
+
+def test_pretty(self):
+tu = get_tu("struct X {}; X x;", lang="cpp")
+f = get_cursor(tu, "x")
+
+pp = PrintingPolicy.create(f)
+self.assertEqual(f.type.get_canonical().pretty_printed(pp), "X")
+pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False)
+self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X")
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 07a1a4195427d8..d0479a94bd67ce 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1158,6 +1158,8 @@ libclang
 
 - Add ``clang_isBeforeInTranslationUnit``. Given two source locations, it 
determines
   whether the first one comes strictly before the second in the source code.
+- Add ``clang_getTypePrettyPrinted``.  It allows controlling the 
PrintingPolicy used
+  to pretty-print a type.
 
 Static Analyzer
 ---
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 63d266dc60ec73..e1f3759bb53e85 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -4182,6 +4182,13 @@ CINDEX_LINKAGE void 
clang_PrintingPolicy_dispose(CXPrintingPolicy Policy);
 CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor,
  CXPrintingPolicy Policy);
 
+/**
+ * Pretty-print the underlying type using a custom printing policy.
+ *
+ * If the type is invalid, an empty string is returned.
+ */
+CINDEX_LINKAGE CXString clang_getTypePrettyPrinted(CXType CT, CXPrintingPolicy 
cxPolicy);
+
 /**
  * Retrieve the display name for the entity referenced by this cursor.
  *
diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp
index b4df12405cf356..f97023c429bfae 100644
--- a/clang/tools/libclang/CXType.cpp
+++ b/clang/tools/libclang/CXType.cpp
@@ -313,6 +313,20 @@ CXString clang_getTypeSpelling(CXType CT) {
   return cxstring::createDup(OS.str());
 }
 
+CXString clang_getTypePrettyPrinted(CXType CT, CXPrintingPolicy cxPolicy) {
+  QualType T = GetQualType(CT);
+  if (T.isNull())
+return cxstring::createEmpty();
+
+  SmallString<64> Str;
+  llvm::raw_svector_ostream OS(Str);
+  PrintingPolicy *UserPolicy = static_cast(cxPolicy);
+
+  T.print(OS, *UserPolicy);
+
+  return cxstring::createDup(OS.str());
+}
+
 CXType clang_getTypedefDecl

[clang] [clang] fix wrong result of pointers comparison between unknown and stack (PR #122404)

2025-01-09 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang

Author: Exile (mzyKi)


Changes

Related Issue #122403 

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (+6) 
- (added) clang/test/Analysis/stream_issue122403.c (+48) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 455621739f6935..1fb51ef403fa12 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -952,6 +952,12 @@ SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state,
 const MemSpaceRegion *RightMS = RightBase->getMemorySpace();
 const MemSpaceRegion *UnknownMS = MemMgr.getUnknownRegion();
 
+if (LeftMS != RightMS &&
+((isa(LeftMS) && isa(RightMS)) ||
+ (isa(LeftMS) && isa(RightMS 
{
+  return UnknownVal();
+}
+
 // If the two regions are from different known memory spaces they cannot be
 // equal. Also, assume that no symbolic region (whose memory space is
 // unknown) is on the stack.
diff --git a/clang/test/Analysis/stream_issue122403.c 
b/clang/test/Analysis/stream_issue122403.c
new file mode 100644
index 00..b9582a1cf7e95e
--- /dev/null
+++ b/clang/test/Analysis/stream_issue122403.c
@@ -0,0 +1,48 @@
+// RUN: %clang_analyze_cc1 -triple=x86_64-pc-linux-gnu 
-analyzer-checker=core,unix.Stream,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false,unix.Stream:Pedantic=true 
-verify %s
+// RUN: %clang_analyze_cc1 -triple=armv8-none-linux-eabi 
-analyzer-checker=core,unix.Stream,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false,unix.Stream:Pedantic=true 
-verify %s
+// RUN: %clang_analyze_cc1 -triple=aarch64-linux-gnu 
-analyzer-checker=core,unix.Stream,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false,unix.Stream:Pedantic=true 
-verify %s
+// RUN: %clang_analyze_cc1 -triple=hexagon 
-analyzer-checker=core,unix.Stream,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false,unix.Stream:Pedantic=true 
-verify %s
+
+#include "Inputs/system-header-simulator.h"
+
+char *get_str(char *Input);
+
+void check_f_leak() {
+  FILE *fp = fopen("test", "rb");
+  if (NULL == fp) {
+return;
+  }
+  char str[64];
+  if (get_str(str) != str) {
+fclose(fp);
+  }
+}// expected-warning {{Opened stream never closed. Potential resource leak}}
+
+void check_f_leak_2() {
+  FILE *fp = fopen("test", "rb");
+  if (NULL == fp) {
+return;
+  }
+  char str[64];
+  if (get_str(str) != NULL) {
+fclose(fp);
+  }
+}// expected-warning {{Opened stream never closed. Potential resource leak}}
+
+
+char *get_str_other(char *Input) {return Input;}
+
+void check_f_leak_3() {
+  FILE *fp = fopen("test", "rb");
+  if (NULL == fp) {
+return;
+  }
+  char str[64];
+  if (get_str_other(str) != str) {
+fclose(fp);
+  }
+}// expected-warning {{Opened stream never closed. Potential resource leak}}
\ No newline at end of file

``




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


[clang] [clang] fix wrong result of pointers comparison between unknown and stack (PR #122404)

2025-01-09 Thread via cfe-commits

https://github.com/mzyKi created 
https://github.com/llvm/llvm-project/pull/122404

Related Issue #122403 

>From 777965f3149c0ec09bc9e71424e7d42e5721d11f Mon Sep 17 00:00:00 2001
From: miaozhiyuan 
Date: Fri, 10 Jan 2025 09:55:20 +0800
Subject: [PATCH] [clang] fix wrong result of pointers comparison between
 unknown and stack

---
 .../StaticAnalyzer/Core/SimpleSValBuilder.cpp |  6 +++
 clang/test/Analysis/stream_issue122403.c  | 48 +++
 2 files changed, 54 insertions(+)
 create mode 100644 clang/test/Analysis/stream_issue122403.c

diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 455621739f6935..1fb51ef403fa12 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -952,6 +952,12 @@ SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state,
 const MemSpaceRegion *RightMS = RightBase->getMemorySpace();
 const MemSpaceRegion *UnknownMS = MemMgr.getUnknownRegion();
 
+if (LeftMS != RightMS &&
+((isa(LeftMS) && isa(RightMS)) ||
+ (isa(LeftMS) && isa(RightMS 
{
+  return UnknownVal();
+}
+
 // If the two regions are from different known memory spaces they cannot be
 // equal. Also, assume that no symbolic region (whose memory space is
 // unknown) is on the stack.
diff --git a/clang/test/Analysis/stream_issue122403.c 
b/clang/test/Analysis/stream_issue122403.c
new file mode 100644
index 00..b9582a1cf7e95e
--- /dev/null
+++ b/clang/test/Analysis/stream_issue122403.c
@@ -0,0 +1,48 @@
+// RUN: %clang_analyze_cc1 -triple=x86_64-pc-linux-gnu 
-analyzer-checker=core,unix.Stream,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false,unix.Stream:Pedantic=true 
-verify %s
+// RUN: %clang_analyze_cc1 -triple=armv8-none-linux-eabi 
-analyzer-checker=core,unix.Stream,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false,unix.Stream:Pedantic=true 
-verify %s
+// RUN: %clang_analyze_cc1 -triple=aarch64-linux-gnu 
-analyzer-checker=core,unix.Stream,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false,unix.Stream:Pedantic=true 
-verify %s
+// RUN: %clang_analyze_cc1 -triple=hexagon 
-analyzer-checker=core,unix.Stream,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false,unix.Stream:Pedantic=true 
-verify %s
+
+#include "Inputs/system-header-simulator.h"
+
+char *get_str(char *Input);
+
+void check_f_leak() {
+  FILE *fp = fopen("test", "rb");
+  if (NULL == fp) {
+return;
+  }
+  char str[64];
+  if (get_str(str) != str) {
+fclose(fp);
+  }
+}// expected-warning {{Opened stream never closed. Potential resource leak}}
+
+void check_f_leak_2() {
+  FILE *fp = fopen("test", "rb");
+  if (NULL == fp) {
+return;
+  }
+  char str[64];
+  if (get_str(str) != NULL) {
+fclose(fp);
+  }
+}// expected-warning {{Opened stream never closed. Potential resource leak}}
+
+
+char *get_str_other(char *Input) {return Input;}
+
+void check_f_leak_3() {
+  FILE *fp = fopen("test", "rb");
+  if (NULL == fp) {
+return;
+  }
+  char str[64];
+  if (get_str_other(str) != str) {
+fclose(fp);
+  }
+}// expected-warning {{Opened stream never closed. Potential resource leak}}
\ No newline at end of file

___
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 -fsanitize-skip-hot-cutoff (PR #121619)

2025-01-09 Thread Fangrui Song via cfe-commits

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


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 -fsanitize-skip-hot-cutoff (PR #121619)

2025-01-09 Thread Fangrui Song via cfe-commits


@@ -14,10 +14,35 @@
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Format.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
 
 using namespace clang;
 
+static const double SanitizerMaskCutoffsEps = 0.1f;
+
+void SanitizerMaskCutoffs::set(SanitizerMask K, double V) {
+  if (V < SanitizerMaskCutoffsEps && Cutoffs.empty())
+return;
+  for (unsigned int i = 0; i < SanitizerKind::SO_Count; i++)

MaskRay wrote:

llvm prefer ++i

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] -ftime-report: reorganize timers (PR #122225)

2025-01-09 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/15

>From 586f1fa8fb02431a962ca606fd546c2310427c80 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Wed, 8 Jan 2025 23:19:56 -0800
Subject: [PATCH 1/4] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/include/clang/CodeGen/BackendUtil.h | 10 ++
 .../include/clang/Frontend/CompilerInstance.h |  4 +++
 clang/lib/CodeGen/BackendConsumer.h   |  4 +--
 clang/lib/CodeGen/BackendUtil.cpp | 34 +++
 clang/lib/CodeGen/CodeGenAction.cpp   | 34 ++-
 .../CodeGen/ObjectFilePCHContainerWriter.cpp  | 15 
 .../Frontend/ftime-report-template-decl.cpp   | 14 
 7 files changed, 59 insertions(+), 56 deletions(-)

diff --git a/clang/include/clang/CodeGen/BackendUtil.h 
b/clang/include/clang/CodeGen/BackendUtil.h
index 7aa4f9db6c2e42..78d1e5ee8e6d59 100644
--- a/clang/include/clang/CodeGen/BackendUtil.h
+++ b/clang/include/clang/CodeGen/BackendUtil.h
@@ -25,11 +25,9 @@ class FileSystem;
 } // namespace llvm
 
 namespace clang {
+class CompilerInstance;
 class DiagnosticsEngine;
-class HeaderSearchOptions;
 class CodeGenOptions;
-class TargetOptions;
-class LangOptions;
 class BackendConsumer;
 
 enum BackendAction {
@@ -41,10 +39,8 @@ enum BackendAction {
   Backend_EmitObj   ///< Emit native object files
 };
 
-void EmitBackendOutput(DiagnosticsEngine &Diags, const HeaderSearchOptions &,
-   const CodeGenOptions &CGOpts, const TargetOptions 
&TOpts,
-   const LangOptions &LOpts, StringRef TDesc,
-   llvm::Module *M, BackendAction Action,
+void emitBackendOutput(CompilerInstance &CI, StringRef TDesc, llvm::Module *M,
+   BackendAction Action,
llvm::IntrusiveRefCntPtr VFS,
std::unique_ptr OS,
BackendConsumer *BC = nullptr);
diff --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 1220a4e29471d1..3cec57abae4445 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -630,6 +630,10 @@ class CompilerInstance : public ModuleLoader {
   /// @name Frontend timer
   /// @{
 
+  llvm::TimerGroup &getFrontendTimerGroup() const {
+return *FrontendTimerGroup;
+  }
+
   bool hasFrontendTimer() const { return (bool)FrontendTimer; }
 
   llvm::Timer &getFrontendTimer() const {
diff --git a/clang/lib/CodeGen/BackendConsumer.h 
b/clang/lib/CodeGen/BackendConsumer.h
index d932a78f469b95..ad3adfca367858 100644
--- a/clang/lib/CodeGen/BackendConsumer.h
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -28,8 +28,8 @@ class BackendConsumer : public ASTConsumer {
   using LinkModule = CodeGenAction::LinkModule;
 
   virtual void anchor();
+  CompilerInstance &CI;
   DiagnosticsEngine &Diags;
-  const HeaderSearchOptions &HeaderSearchOpts;
   const CodeGenOptions &CodeGenOpts;
   const TargetOptions &TargetOpts;
   const LangOptions &LangOpts;
@@ -70,7 +70,7 @@ class BackendConsumer : public ASTConsumer {
   llvm::Module *CurLinkModule = nullptr;
 
 public:
-  BackendConsumer(const CompilerInstance &CI, BackendAction Action,
+  BackendConsumer(CompilerInstance &CI, BackendAction Action,
   IntrusiveRefCntPtr VFS,
   llvm::LLVMContext &C, SmallVector LinkModules,
   StringRef InFile, std::unique_ptr OS,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 2dbab785658aa4..bcb14a9a166077 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -137,8 +137,6 @@ class EmitAssemblyHelper {
   llvm::Module *TheModule;
   IntrusiveRefCntPtr VFS;
 
-  Timer CodeGenerationTime;
-
   std::unique_ptr OS;
 
   Triple TargetTriple;
@@ -211,7 +209,6 @@ class EmitAssemblyHelper {
  IntrusiveRefCntPtr VFS)
   : Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
 TargetOpts(TOpts), LangOpts(LOpts), TheModule(M), VFS(std::move(VFS)),
-CodeGenerationTime("codegen", "Code Generation Time"),
 TargetTriple(TheModule->getTargetTriple()) {}
 
   ~EmitAssemblyHelper() {
@@ -222,8 +219,8 @@ class EmitAssemblyHelper {
   std::unique_ptr TM;
 
   // Emit output using the new pass manager for the optimization pipeline.
-  void EmitAssembly(BackendAction Action, std::unique_ptr 
OS,
-BackendConsumer *BC);
+  void emitAssembly(const CompilerInstance &CI, BackendAction Action,
+std::unique_ptr OS, BackendConsumer 
*BC);
 };
 } // namespace
 
@@ -1212,10 +1209,14 @@ void EmitAssemblyHelper::RunCodegenPipeline(
   }
 }
 
-void EmitAssemblyHelper::EmitAssembly(BackendAct

[clang] -ftime-report: reorganize timers (PR #122225)

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

vitalybuka wrote:

Probably from the prev patch I have:

```
/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/clang/test/Frontend/ftime-report-template-decl.cpp:155:15:
 error: CHECK-DAG: expected string not found in input
// CHECK-DAG: Code Generation Time
  ^
:75:32: note: scanning from here
 Miscellaneous Ungrouped Timers
   ^
:79:69: note: possible intended match here
 0.0003 (100.0%) 0.0002 (100.0%) 0.0004 (100.0%) 0.0004 (100.0%) LLVM IR 
Generation Time
^

Input file: 
Check file: 
/usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/clang/test/Frontend/ftime-report-template-decl.cpp

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

Input was:
<<
   .
   .
   .
  70:  0. ( 1.8%) 0. ( 1.8%) 0. ( 2.2%) 
InnerAnalysisManagerProxy 
  71:  0. ( 3.6%) 0. ( 3.6%) 0. ( 2.2%) 
ProfileSummaryAnalysis 
  72:  0.0001 (100.0%) 0.0001 (100.0%) 0.0001 (100.0%) Total 
  73:  
  74: 
===-=== 
  75:  Miscellaneous Ungrouped Timers 
dag:155'0X error: no match found
  76: 
===-=== 
dag:155'0 

  77:  
dag:155'0 ~
  78:  ---User Time--- --System Time-- --User+System-- ---Wall Time--- 
--- Name --- 
dag:155'0 
~~
  79:  0.0003 (100.0%) 0.0002 (100.0%) 0.0004 (100.0%) 0.0004 (100.0%) 
LLVM IR Generation Time 
dag:155'0 
~
dag:155'1   
  ? possible intended match
  80:  0.0003 (100.0%) 0.0002 (100.0%) 0.0004 (100.0%) 0.0004 (100.0%) 
Total 
dag:155'0 
~~~
  81:  
dag:155'0 ~
  82: 
===-=== 
dag:155'0 

  83:  Clang front-end time report 
dag:155'0 ~
  84: 
===-=== 
dag:155'0 

   .
   .
   .
>>

--


^C  interrupted by user, skipping remaining tests

Failed Tests (1):
  Clang :: Frontend/ftime-report-template-decl.cpp


Testing Time: 17.23s
```

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


[clang] 186bd8e - [CodeGen] Restore CodeGenerationTime

2025-01-09 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2025-01-09T21:47:20-08:00
New Revision: 186bd8e4cd8d239be67172448c53e92be396359a

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

LOG: [CodeGen] Restore CodeGenerationTime

Fixes 48d0eb5181065a3d086de2e30f5c619fe407e4ce

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 29478f6829e396..2863887fd4d2f9 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -208,6 +208,7 @@ class EmitAssemblyHelper {
   : CI(CI), Diags(CI.getDiagnostics()), CodeGenOpts(CI.getCodeGenOpts()),
 TargetOpts(CI.getTargetOpts()), LangOpts(CI.getLangOpts()),
 TheModule(M), VFS(std::move(VFS)),
+CodeGenerationTime("codegen", "Code Generation Time"),
 TargetTriple(TheModule->getTargetTriple()) {}
 
   ~EmitAssemblyHelper() {



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


[clang] 76fac9c - [sanitizer] Parse weighted sanitizer args and -fsanitize-skip-hot-cutoff (#121619)

2025-01-09 Thread via cfe-commits

Author: Thurston Dang
Date: 2025-01-09T21:52:30-08:00
New Revision: 76fac9c01736b1254e42427f8e0910c0f1d01fba

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

LOG: [sanitizer] Parse weighted sanitizer args and -fsanitize-skip-hot-cutoff 
(#121619)

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, `-fsanitize-skip-hot-cutoff`.

`-fsanitize-skip-hot-cutoff` currently has no effect; future work will
use it to generalize ubsan-guard-checks (originally introduced in
5f9ed2ff8364ff3e4fac410472f421299dafa793).

-

Co-authored-by: Vitaly Buka 

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Basic/Sanitizers.h
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/SanitizerArgs.h
clang/lib/Basic/Sanitizers.cpp
clang/lib/Driver/SanitizerArgs.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Driver/fsanitize.c

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index c555fb3b72d648..b64ad74d711c60 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -384,6 +384,11 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// the expense of debuggability).
   SanitizerSet SanitizeMergeHandlers;
 
+  /// Set of thresholds in a range [0.0, 1.0]: the top hottest code responsible
+  /// for the given fraction of PGO counters will be excluded from sanitization
+  /// (0.0 [default] to skip none, 1.0 to skip all).
+  SanitizerMaskCutoffs SanitizeSkipHotCutoffs;
+
   /// 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..2ff1acb7720949 100644
--- a/clang/include/clang/Basic/Sanitizers.h
+++ b/clang/include/clang/Basic/Sanitizers.h
@@ -154,6 +154,16 @@ struct SanitizerKind {
 #include "clang/Basic/Sanitizers.def"
 }; // SanitizerKind
 
+class SanitizerMaskCutoffs {
+  std::vector Cutoffs;
+
+public:
+  std::optional operator[](unsigned Kind) const;
+
+  void set(SanitizerMask K, double V);
+  void clear(SanitizerMask K = SanitizerKind::All);
+};
+
 struct SanitizerSet {
   /// Check if a certain (single) sanitizer is enabled.
   bool has(SanitizerMask K) const {
@@ -186,10 +196,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.
+/// The relevant weight(s) are updated in the passed Cutoffs parameter.
+/// Individual Cutoffs are never reset to zero unless explicitly set
+/// (e.g., 'null=0.0').
+/// Returns \c false if \p Value is not known or the weight is not valid.
+bool 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 eb860f73121fd7..41a7e8c3728066 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2652,6 +2652,14 @@ 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 fsanitize_skip_hot_cutoff_EQ
+: CommaJoined<["-"], "fsanitize-skip-hot-cutoff=">,
+  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..a54995e2b153b2 100644
--- a/clang/include/clang/Driver/Saniti

[clang] [clang-tools-extra] [clang][Sema] Upstream HeuristicResolver from clangd (PR #121314)

2025-01-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Nathan Ridge (HighCommander4)


Changes

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

**EDIT**: See accompanying RFC at 
https://discourse.llvm.org/t/rfc-upstream-heuristicresolver-from-clangd-to-libsema/84004

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


14 Files Affected:

- (modified) clang-tools-extra/clangd/CMakeLists.txt (-1) 
- (modified) clang-tools-extra/clangd/FindTarget.cpp (+1-1) 
- (modified) clang-tools-extra/clangd/FindTarget.h (+3-1) 
- (modified) clang-tools-extra/clangd/InlayHints.cpp (+1-1) 
- (modified) clang-tools-extra/clangd/ParsedAST.cpp (+1-1) 
- (modified) clang-tools-extra/clangd/ParsedAST.h (+1-1) 
- (modified) clang-tools-extra/clangd/SemanticHighlighting.cpp (+1-1) 
- (modified) clang-tools-extra/clangd/XRefs.cpp (+1-1) 
- (modified) clang-tools-extra/clangd/unittests/CMakeLists.txt (-1) 
- (renamed) clang/include/clang/Sema/HeuristicResolver.h (+2-5) 
- (modified) clang/lib/Sema/CMakeLists.txt (+1) 
- (renamed) clang/lib/Sema/HeuristicResolver.cpp (+1-3) 
- (modified) clang/unittests/Sema/CMakeLists.txt (+1) 
- (renamed) clang/unittests/Sema/HeuristicResolverTest.cpp (+1-2) 


``diff
diff --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index d797ddce8c44d1..6f10afe4a5625f 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -91,7 +91,6 @@ add_clang_library(clangDaemon STATIC
   GlobalCompilationDatabase.cpp
   Headers.cpp
   HeaderSourceSwitch.cpp
-  HeuristicResolver.cpp
   Hover.cpp
   IncludeCleaner.cpp
   IncludeFixer.cpp
diff --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index e702c6b3537a09..04fd6d437b7bdd 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -8,7 +8,6 @@
 
 #include "FindTarget.h"
 #include "AST.h"
-#include "HeuristicResolver.h"
 #include "support/Logger.h"
 #include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTTypeTraits.h"
@@ -35,6 +34,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Specifiers.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
diff --git a/clang-tools-extra/clangd/FindTarget.h 
b/clang-tools-extra/clangd/FindTarget.h
index b41c5470951001..a7706804ce7ece 100644
--- a/clang-tools-extra/clangd/FindTarget.h
+++ b/clang-tools-extra/clangd/FindTarget.h
@@ -33,9 +33,11 @@
 #include 
 
 namespace clang {
-namespace clangd {
+
 class HeuristicResolver;
 
+namespace clangd {
+
 /// Describes the link between an AST node and a Decl it refers to.
 enum class DeclRelation : unsigned;
 /// A bitfield of DeclRelations.
diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index fefffeb4efc1a2..1b1bcf78c9855e 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -9,7 +9,6 @@
 #include "../clang-tidy/utils/DesignatedInitializers.h"
 #include "AST.h"
 #include "Config.h"
-#include "HeuristicResolver.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "SourceCode.h"
@@ -27,6 +26,7 @@
 #include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index 725cbeb154cb84..89d6f26d0f150e 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -20,7 +20,6 @@
 #include "Feature.h"
 #include "FeatureModule.h"
 #include "Headers.h"
-#include "HeuristicResolver.h"
 #include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
@@ -53,6 +52,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "clang/Serialization/ASTWriter.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Diagnostic.h"
diff --git a/clang-tools-extra/clangd/ParsedAST.h 
b/clang-tools-extra/clangd/ParsedAST.h
index 8d9d1e64569267..82fac96360488e 100644
--- a/clang-tools-extra/clangd/ParsedAST.h
+++ b/clang-tools-extra/clangd/ParsedAST.h
@@ -38,9 +38,9 @@
 #include 
 
 namespace clang {
+class HeuristicResolver;
 class Sema;
 namespace clangd {
-class HeuristicResolver;
 
 /// Stores and provides access to parsed AST.
 class ParsedAST {
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index e6d16af2495fec..86ca05644c7031 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tool

[clang] [sanitizer] Parse weighted sanitizer args and -fsanitize-skip-hot-cutoff (PR #121619)

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

https://github.com/thurstond closed 
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-tools-extra] [clang][Sema] Upstream HeuristicResolver from clangd (PR #121314)

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

https://github.com/HighCommander4 ready_for_review 
https://github.com/llvm/llvm-project/pull/121314
___
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 -fsanitize-skip-hot-cutoff (PR #121619)

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


@@ -14,10 +14,35 @@
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Format.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
 
 using namespace clang;
 
+static const double SanitizerMaskCutoffsEps = 0.1f;
+
+void SanitizerMaskCutoffs::set(SanitizerMask K, double V) {
+  if (V < SanitizerMaskCutoffsEps && Cutoffs.empty())
+return;
+  for (unsigned int i = 0; i < SanitizerKind::SO_Count; i++)

thurstond wrote:

Fixed in 
https://github.com/llvm/llvm-project/pull/121619/commits/10e0a5512ed09ce5972668f457fe202d885f2e77.
 Thanks for the 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] -ftime-report: reorganize timers (PR #122225)

2025-01-09 Thread Fangrui Song via cfe-commits


@@ -1346,14 +1344,30 @@ static void runThinLTOBackend(
   }
 }
 
-void clang::EmitBackendOutput(
-DiagnosticsEngine &Diags, const HeaderSearchOptions &HeaderOpts,
-const CodeGenOptions &CGOpts, const clang::TargetOptions &TOpts,
-const LangOptions &LOpts, StringRef TDesc, llvm::Module *M,
-BackendAction Action, IntrusiveRefCntPtr VFS,
-std::unique_ptr OS, BackendConsumer *BC) {
-
+void clang::emitBackendOutput(CompilerInstance &CI, StringRef TDesc,
+  llvm::Module *M, BackendAction Action,
+  IntrusiveRefCntPtr VFS,
+  std::unique_ptr OS,
+  BackendConsumer *BC) {
   llvm::TimeTraceScope TimeScope("Backend");
+  DiagnosticsEngine &Diags = CI.getDiagnostics();
+  const auto &HeaderOpts = CI.getHeaderSearchOpts();
+  const auto &CGOpts = CI.getCodeGenOpts();
+  const auto &TOpts = CI.getTargetOpts();
+  const auto &LOpts = CI.getLangOpts();
+
+  Timer timer;
+  if (CGOpts.TimePasses) {
+CI.getFrontendTimer().stopTimer();
+timer.init("backend", "Backend", CI.getTimerGroup());
+timer.startTimer();
+  }
+  auto _ = llvm::make_scope_exit([&] {

MaskRay wrote:

This is difficult Parsing and codegen are interleaved in clang.`ParseAST` 
calls  BackendConsumer::HandleTopLevelDecl and  
BackendConsumer::HandleTranslationUnit ([call 
stack](https://maskray.me/blog/2023-09-24-a-deep-dive-into-clang-source-file-compilation),
 which do code generation.

I've introduced `yieldTo` and changed the timers. Updated the description.

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


[clang] [clang-tools-extra] [clang][Sema] Upstream HeuristicResolver from clangd (PR #121314)

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

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


[clang] -ftime-report: reorganize timers (PR #122225)

2025-01-09 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> Probably from the prev patch I have:
> 
> ```
> /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/clang/test/Frontend/ftime-report-template-decl.cpp:155:15:
>  error: CHECK-DAG: expected string not found in input
> // CHECK-DAG: Code Generation Time
>   ^
> :75:32: note: scanning from here
>  Miscellaneous Ungrouped Timers
>^
> :79:69: note: possible intended match here
>  0.0003 (100.0%) 0.0002 (100.0%) 0.0004 (100.0%) 0.0004 (100.0%) LLVM IR 
> Generation Time
> ^
> 
> Input file: 
> Check file: 
> /usr/local/google/home/vitalybuka/src/llvm.git/llvm-project/clang/test/Frontend/ftime-report-template-decl.cpp
> 
> -dump-input=help explains the following input dump.
> 
> Input was:
> <<
>.
>.
>.
>   70:  0. ( 1.8%) 0. ( 1.8%) 0. ( 2.2%) 
> InnerAnalysisManagerProxy 
>   71:  0. ( 3.6%) 0. ( 3.6%) 0. ( 2.2%) 
> ProfileSummaryAnalysis 
>   72:  0.0001 (100.0%) 0.0001 (100.0%) 0.0001 (100.0%) Total 
>   73:  
>   74: 
> ===-===
>  
>   75:  Miscellaneous Ungrouped Timers 
> dag:155'0X error: no match found
>   76: 
> ===-===
>  
> dag:155'0 
> 
>   77:  
> dag:155'0 ~
>   78:  ---User Time--- --System Time-- --User+System-- ---Wall 
> Time--- --- Name --- 
> dag:155'0 
> ~~
>   79:  0.0003 (100.0%) 0.0002 (100.0%) 0.0004 (100.0%) 0.0004 
> (100.0%) LLVM IR Generation Time 
> dag:155'0 
> ~
> dag:155'1 
> ? possible intended match
>   80:  0.0003 (100.0%) 0.0002 (100.0%) 0.0004 (100.0%) 0.0004 
> (100.0%) Total 
> dag:155'0 
> ~~~
>   81:  
> dag:155'0 ~
>   82: 
> ===-===
>  
> dag:155'0 
> 
>   83:  Clang front-end time report 
> dag:155'0 ~
>   84: 
> ===-===
>  
> dag:155'0 
> 
>.
>.
>.
> >>
> 
> --
> 
> 
> ^C  interrupted by user, skipping remaining tests
> 
> Failed Tests (1):
>   Clang :: Frontend/ftime-report-template-decl.cpp
> 
> 
> Testing Time: 17.23s
> ```

Sorry, my fault. Should have been fixed by 
186bd8e4cd8d239be67172448c53e92be396359a

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


[clang] [clang-tools-extra] [clang][Sema] Upstream HeuristicResolver from clangd (PR #121314)

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

HighCommander4 wrote:

Now that the dependent PR #121313 has merged, I've posted an RFC at 
https://discourse.llvm.org/t/rfc-upstream-heuristicresolver-from-clangd-to-libsema/84004,
 and I'm publishing this PR for review.

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


[clang] [nfc][ubsan] Use O1 in test to remove more unrelated stuff (PR #122408)

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

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


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


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2025-01-09 Thread Fangrui Song via cfe-commits


@@ -81,6 +81,16 @@
 
 using namespace Fortran::frontend;
 
+static constexpr llvm::StringLiteral timingIdParse = "Parse";

MaskRay wrote:

constexpr at namespace level implies static

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


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2025-01-09 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,22 @@
+! Check that -ftime-report flag is passed as-is to fc1. The value of the flag
+! is only checked there. This behavior intentionally mirrors that of clang.
+!
+! RUN: %flang -### -c -ftime-report %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-DRIVER

MaskRay wrote:

do you need -mllvm -sort-timers=0 to prevent reordering of timers in the 
TimerGroup?

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


[clang] [HLSL] Implement D3DCOLORtoUBYTE4 intrinsic (PR #122202)

2025-01-09 Thread Deric Cheung via cfe-commits

https://github.com/Icohedron updated 
https://github.com/llvm/llvm-project/pull/122202

>From 07112471edfc569eb12b2a6178ddc28b4f3a36d5 Mon Sep 17 00:00:00 2001
From: Icohedron 
Date: Thu, 9 Jan 2025 01:14:52 +
Subject: [PATCH 1/5] Implement D3DCOLORtoUBYTE4 intrinsic

---
 clang/lib/Headers/hlsl/hlsl_detail.h|  8 
 clang/lib/Headers/hlsl/hlsl_intrinsics.h| 17 +
 .../CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl  | 12 
 .../BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl   | 13 +
 4 files changed, 50 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl

diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 8d5fd941331531..470fa4214a12f8 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -33,6 +33,14 @@ constexpr enable_if_t bit_cast(T 
F) {
   return __builtin_bit_cast(U, F);
 }
 
+constexpr vector d3d_color_to_ubyte4(vector V) {
+  // Use the same scaling factor used by FXC (i.e., 255.001953)
+  // Excerpt from stackoverflow discussion:
+  // "Built-in rounding, necessary because of truncation. 0.001953 * 256 = 0.5"
+  // 
https://stackoverflow.com/questions/52103720/why-does-d3dcolortoubyte4-multiplies-components-by-255-001953f
+  return V.zyxw * 255.001953f;
+}
+
 } // namespace __detail
 } // namespace hlsl
 #endif //_HLSL_HLSL_DETAILS_H_
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index b745997f1d5a2b..e44403c6c802e0 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1857,6 +1857,23 @@ half3 cross(half3, half3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_cross)
 float3 cross(float3, float3);
 
+//===--===//
+// D3DCOLORtoUBYTE4 builtins
+//===--===//
+
+/// \fn T D3DCOLORtoUBYTE4(T x)
+/// \brief Converts a floating-point, 4D vector set by a D3DCOLOR to a UBYTE4.
+/// \param x [in] The floating-point vector4 to convert.
+///
+/// The return value is the UBYTE4 representation of the \a x parameter.
+///
+/// This function swizzles and scales components of the \a x parameter. Use 
this
+/// function to compensate for the lack of UBYTE4 support in some hardware.
+
+constexpr vector D3DCOLORtoUBYTE4(vector V) {
+  return __detail::d3d_color_to_ubyte4(V);
+}
+
 
//===--===//
 // rcp builtins
 
//===--===//
diff --git a/clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl 
b/clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl
new file mode 100644
index 00..6e48800dae6698
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK
+
+// CHECK-LABEL: D3DCOLORtoUBYTE4
+int4 test_D3DCOLORtoUBYTE4 ( float4 p1 ) {
+  // CHECK: %[[SCALED:.*]] = fmul <4 x float> %{{.*}}, splat (float 
0x406FE010)
+  // CHECK: %[[CONVERTED:.*]] = fptoui <4 x float> %[[SCALED]] to <4 x i32>
+  // CHECK: %[[SHUFFLED:.*]] = shufflevector <4 x i32> %{{.*}}, <4 x i32> 
poison, <4 x i32> 
+  // CHECK: ret <4 x i32> %[[SHUFFLED]]
+  return D3DCOLORtoUBYTE4 ( p1 );
+}
diff --git a/clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl
new file mode 100644
index 00..fb41c212bd0be3
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify
+
+int4 test_too_few_arg() {
+  return D3DCOLORtoUBYTE4();
+  // expected-error@-1 {{no matching function for call to 'D3DCOLORtoUBYTE4'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires single argument 'V', but no arguments were provided}}
+}
+
+int4 test_too_many_arg(float4 v) {
+  return D3DCOLORtoUBYTE4(v, v);
+  // expected-error@-1 {{no matching function for call to 'D3DCOLORtoUBYTE4'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires single argument 'V', but 2 arguments were provided}}
+}

>From d8632ec0526536afb5ce9c3d242079be777c15c0 Mon Sep 17 00:00:00 2001
From: Icohedron 
Date: Thu, 9 Jan 2025 17:30:45 +
Subject: [PATCH 2/5] Add additional sema tests for D3DCOLORtoUBYTE4 for
 invalid arg types

---
 .../BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl| 16 
 1 file changed, 16 insertions(+)

diff --

[clang] [clang] Rename ReadPCHAndPreprocessAction (NFC) (PR #122390)

2025-01-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Steven Wu (cachemeifyoucan)


Changes

Rename `ReadPCHAndPreprocessAction` class. This frontend action is used
for dependency scanning only and the current name is confusing for what
it actually does. Rename the class to `DependencyScanningFrontendAction`
to be clear for its usage.


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


3 Files Affected:

- (modified) clang/include/clang/Frontend/FrontendActions.h (+2-2) 
- (modified) clang/lib/Frontend/FrontendActions.cpp (+2-2) 
- (modified) clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
(+1-1) 


``diff
diff --git a/clang/include/clang/Frontend/FrontendActions.h 
b/clang/include/clang/Frontend/FrontendActions.h
index a620ddfc40447d..f16c68344479e4 100644
--- a/clang/include/clang/Frontend/FrontendActions.h
+++ b/clang/include/clang/Frontend/FrontendActions.h
@@ -32,8 +32,8 @@ class InitOnlyAction : public FrontendAction {
   bool usesPreprocessorOnly() const override { return false; }
 };
 
-/// Preprocessor-based frontend action that also loads PCH files.
-class ReadPCHAndPreprocessAction : public FrontendAction {
+/// Preprocessor-based frontend action that is used for dependency scanning.
+class DependencyScanningFrontendAction : public FrontendAction {
   void ExecuteAction() override;
 
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
diff --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 30dfa5481d070a..f2a9602bdcafaf 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -69,7 +69,7 @@ void InitOnlyAction::ExecuteAction() {
 }
 
 // Basically PreprocessOnlyAction::ExecuteAction.
-void ReadPCHAndPreprocessAction::ExecuteAction() {
+void DependencyScanningFrontendAction::ExecuteAction() {
   Preprocessor &PP = getCompilerInstance().getPreprocessor();
 
   // Ignore unknown pragmas.
@@ -84,7 +84,7 @@ void ReadPCHAndPreprocessAction::ExecuteAction() {
 }
 
 std::unique_ptr
-ReadPCHAndPreprocessAction::CreateASTConsumer(CompilerInstance &CI,
+DependencyScanningFrontendAction::CreateASTConsumer(CompilerInstance &CI,
   StringRef InFile) {
   return std::make_unique();
 }
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 5a648df05e4fd3..6db5a1cb41da1f 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -439,7 +439,7 @@ class DependencyScanningAction : public tooling::ToolAction 
{
 else if (ModuleName)
   Action = 
std::make_unique(*ModuleName);
 else
-  Action = std::make_unique();
+  Action = std::make_unique();
 
 if (ScanInstance.getDiagnostics().hasErrorOccurred())
   return false;

``




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


[clang] [clang] Rename ReadPCHAndPreprocessAction (NFC) (PR #122390)

2025-01-09 Thread Steven Wu via cfe-commits

https://github.com/cachemeifyoucan created 
https://github.com/llvm/llvm-project/pull/122390

Rename `ReadPCHAndPreprocessAction` class. This frontend action is used
for dependency scanning only and the current name is confusing for what
it actually does. Rename the class to `DependencyScanningFrontendAction`
to be clear for its usage.


>From 1796a6e4fa0492b9676637245a394d3029474d4e Mon Sep 17 00:00:00 2001
From: Steven Wu 
Date: Thu, 9 Jan 2025 15:46:06 -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.5
---
 clang/include/clang/Frontend/FrontendActions.h| 4 ++--
 clang/lib/Frontend/FrontendActions.cpp| 4 ++--
 .../Tooling/DependencyScanning/DependencyScanningWorker.cpp   | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Frontend/FrontendActions.h 
b/clang/include/clang/Frontend/FrontendActions.h
index a620ddfc40447d..f16c68344479e4 100644
--- a/clang/include/clang/Frontend/FrontendActions.h
+++ b/clang/include/clang/Frontend/FrontendActions.h
@@ -32,8 +32,8 @@ class InitOnlyAction : public FrontendAction {
   bool usesPreprocessorOnly() const override { return false; }
 };
 
-/// Preprocessor-based frontend action that also loads PCH files.
-class ReadPCHAndPreprocessAction : public FrontendAction {
+/// Preprocessor-based frontend action that is used for dependency scanning.
+class DependencyScanningFrontendAction : public FrontendAction {
   void ExecuteAction() override;
 
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
diff --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 30dfa5481d070a..f2a9602bdcafaf 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -69,7 +69,7 @@ void InitOnlyAction::ExecuteAction() {
 }
 
 // Basically PreprocessOnlyAction::ExecuteAction.
-void ReadPCHAndPreprocessAction::ExecuteAction() {
+void DependencyScanningFrontendAction::ExecuteAction() {
   Preprocessor &PP = getCompilerInstance().getPreprocessor();
 
   // Ignore unknown pragmas.
@@ -84,7 +84,7 @@ void ReadPCHAndPreprocessAction::ExecuteAction() {
 }
 
 std::unique_ptr
-ReadPCHAndPreprocessAction::CreateASTConsumer(CompilerInstance &CI,
+DependencyScanningFrontendAction::CreateASTConsumer(CompilerInstance &CI,
   StringRef InFile) {
   return std::make_unique();
 }
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 5a648df05e4fd3..6db5a1cb41da1f 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -439,7 +439,7 @@ class DependencyScanningAction : public tooling::ToolAction 
{
 else if (ModuleName)
   Action = 
std::make_unique(*ModuleName);
 else
-  Action = std::make_unique();
+  Action = std::make_unique();
 
 if (ScanInstance.getDiagnostics().hasErrorOccurred())
   return false;

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


[clang] [clang] Rename ReadPCHAndPreprocessAction (NFC) (PR #122390)

2025-01-09 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff c1c50c7a3ef9ced4a9b01e0afd83b83d7060fff9 
1796a6e4fa0492b9676637245a394d3029474d4e --extensions h,cpp -- 
clang/include/clang/Frontend/FrontendActions.h 
clang/lib/Frontend/FrontendActions.cpp 
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index f2a9602bdc..1b4899e6cd 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -85,7 +85,7 @@ void DependencyScanningFrontendAction::ExecuteAction() {
 
 std::unique_ptr
 DependencyScanningFrontendAction::CreateASTConsumer(CompilerInstance &CI,
-  StringRef InFile) {
+StringRef InFile) {
   return std::make_unique();
 }
 

``




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


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

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

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

>From f98e5113bc83cae2118552466288a874d5e5d63d Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Fri, 18 Oct 2024 10:49:18 -0700
Subject: [PATCH 1/8] [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 468c16050e2bf0..12b96672ce466f 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4793,6 +4793,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 d4e897868f1a9a..e74efd560fd329 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9287,6 +9287,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 ca03fb665d423d..8770c8f4953fce 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19186,6 +19186,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) {
@@ -19505,6 +19522,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] [clang] Rename ReadPCHAndPreprocessAction (NFC) (PR #122390)

2025-01-09 Thread Steven Wu via cfe-commits

https://github.com/cachemeifyoucan updated 
https://github.com/llvm/llvm-project/pull/122390

>From 1796a6e4fa0492b9676637245a394d3029474d4e Mon Sep 17 00:00:00 2001
From: Steven Wu 
Date: Thu, 9 Jan 2025 15:46:06 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 clang/include/clang/Frontend/FrontendActions.h| 4 ++--
 clang/lib/Frontend/FrontendActions.cpp| 4 ++--
 .../Tooling/DependencyScanning/DependencyScanningWorker.cpp   | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Frontend/FrontendActions.h 
b/clang/include/clang/Frontend/FrontendActions.h
index a620ddfc40447d..f16c68344479e4 100644
--- a/clang/include/clang/Frontend/FrontendActions.h
+++ b/clang/include/clang/Frontend/FrontendActions.h
@@ -32,8 +32,8 @@ class InitOnlyAction : public FrontendAction {
   bool usesPreprocessorOnly() const override { return false; }
 };
 
-/// Preprocessor-based frontend action that also loads PCH files.
-class ReadPCHAndPreprocessAction : public FrontendAction {
+/// Preprocessor-based frontend action that is used for dependency scanning.
+class DependencyScanningFrontendAction : public FrontendAction {
   void ExecuteAction() override;
 
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
diff --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 30dfa5481d070a..f2a9602bdcafaf 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -69,7 +69,7 @@ void InitOnlyAction::ExecuteAction() {
 }
 
 // Basically PreprocessOnlyAction::ExecuteAction.
-void ReadPCHAndPreprocessAction::ExecuteAction() {
+void DependencyScanningFrontendAction::ExecuteAction() {
   Preprocessor &PP = getCompilerInstance().getPreprocessor();
 
   // Ignore unknown pragmas.
@@ -84,7 +84,7 @@ void ReadPCHAndPreprocessAction::ExecuteAction() {
 }
 
 std::unique_ptr
-ReadPCHAndPreprocessAction::CreateASTConsumer(CompilerInstance &CI,
+DependencyScanningFrontendAction::CreateASTConsumer(CompilerInstance &CI,
   StringRef InFile) {
   return std::make_unique();
 }
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 5a648df05e4fd3..6db5a1cb41da1f 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -439,7 +439,7 @@ class DependencyScanningAction : public tooling::ToolAction 
{
 else if (ModuleName)
   Action = 
std::make_unique(*ModuleName);
 else
-  Action = std::make_unique();
+  Action = std::make_unique();
 
 if (ScanInstance.getDiagnostics().hasErrorOccurred())
   return false;

>From b2ca9d5a749fa6a5048c7b41199b4a767decdf6b Mon Sep 17 00:00:00 2001
From: Steven Wu 
Date: Thu, 9 Jan 2025 15:52:58 -0800
Subject: [PATCH 2/2] clang-format

Created using spr 1.3.5
---
 clang/lib/Frontend/FrontendActions.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index f2a9602bdcafaf..1b4899e6cdcc59 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -85,7 +85,7 @@ void DependencyScanningFrontendAction::ExecuteAction() {
 
 std::unique_ptr
 DependencyScanningFrontendAction::CreateASTConsumer(CompilerInstance &CI,
-  StringRef InFile) {
+StringRef InFile) {
   return std::make_unique();
 }
 

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


[clang] [HLSL] Implement D3DCOLORtoUBYTE4 intrinsic (PR #122202)

2025-01-09 Thread Deric Cheung via cfe-commits

https://github.com/Icohedron updated 
https://github.com/llvm/llvm-project/pull/122202

>From 5610b225e76b046e911c1a7a0c1e4ccc128d35a1 Mon Sep 17 00:00:00 2001
From: Icohedron 
Date: Thu, 9 Jan 2025 01:14:52 +
Subject: [PATCH] [HLSL] Implement the D3DCOLORtoUBYTE4 intrinsic

---
 clang/lib/Headers/hlsl/hlsl_detail.h  |  8 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 17 +++
 .../builtins/D3DCOLORtoUBYTE4.hlsl| 12 
 .../BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl | 29 +++
 4 files changed, 66 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl

diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 8d5fd941331531..470fa4214a12f8 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -33,6 +33,14 @@ constexpr enable_if_t bit_cast(T 
F) {
   return __builtin_bit_cast(U, F);
 }
 
+constexpr vector d3d_color_to_ubyte4(vector V) {
+  // Use the same scaling factor used by FXC (i.e., 255.001953)
+  // Excerpt from stackoverflow discussion:
+  // "Built-in rounding, necessary because of truncation. 0.001953 * 256 = 0.5"
+  // 
https://stackoverflow.com/questions/52103720/why-does-d3dcolortoubyte4-multiplies-components-by-255-001953f
+  return V.zyxw * 255.001953f;
+}
+
 } // namespace __detail
 } // namespace hlsl
 #endif //_HLSL_HLSL_DETAILS_H_
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index b745997f1d5a2b..e44403c6c802e0 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1857,6 +1857,23 @@ half3 cross(half3, half3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_cross)
 float3 cross(float3, float3);
 
+//===--===//
+// D3DCOLORtoUBYTE4 builtins
+//===--===//
+
+/// \fn T D3DCOLORtoUBYTE4(T x)
+/// \brief Converts a floating-point, 4D vector set by a D3DCOLOR to a UBYTE4.
+/// \param x [in] The floating-point vector4 to convert.
+///
+/// The return value is the UBYTE4 representation of the \a x parameter.
+///
+/// This function swizzles and scales components of the \a x parameter. Use 
this
+/// function to compensate for the lack of UBYTE4 support in some hardware.
+
+constexpr vector D3DCOLORtoUBYTE4(vector V) {
+  return __detail::d3d_color_to_ubyte4(V);
+}
+
 
//===--===//
 // rcp builtins
 
//===--===//
diff --git a/clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl 
b/clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl
new file mode 100644
index 00..7021de7192b5e5
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK
+
+// CHECK-LABEL: D3DCOLORtoUBYTE4
+int4 test_D3DCOLORtoUBYTE4(float4 p1) {
+  // CHECK: %[[SCALED:.*]] = fmul [[FMFLAGS:.*]]<4 x float> %{{.*}}, splat 
(float 0x406FE010)
+  // CHECK: %[[CONVERTED:.*]] = fptoui <4 x float> %[[SCALED]] to <4 x i32>
+  // CHECK: %[[SHUFFLED:.*]] = shufflevector <4 x i32> %{{.*}}, <4 x i32> 
poison, <4 x i32> 
+  // CHECK: ret <4 x i32> %[[SHUFFLED]]
+  return D3DCOLORtoUBYTE4(p1);
+}
diff --git a/clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl
new file mode 100644
index 00..e9ba851007c941
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify
+
+int4 test_too_few_arg() {
+  return D3DCOLORtoUBYTE4();
+  // expected-error@-1 {{no matching function for call to 'D3DCOLORtoUBYTE4'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires single argument 'V', but no arguments were provided}}
+}
+
+int4 test_too_many_arg(float4 v) {
+  return D3DCOLORtoUBYTE4(v, v);
+  // expected-error@-1 {{no matching function for call to 'D3DCOLORtoUBYTE4'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
requires single argument 'V', but 2 arguments were provided}}
+}
+
+int4 float2_arg(float2 v) {
+return D3DCOLORtoUBYTE4(v);
+// expected-error@-1 {{no matching function for call to 
'D3DCOLORtoUBYTE4'}}
+// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: 
no known conversion from 'vector<[...], 2>' to 'vector<[...], 4>' for 1st 
argument}}
+}
+
+struct S {
+  flo

[clang] [analyzer] Widen loops: Augment assignment note when values invalidated at the start of a loop (PR #122398)

2025-01-09 Thread via cfe-commits

https://github.com/dgg5503 created 
https://github.com/llvm/llvm-project/pull/122398

This PR attempts to improve the value assignment diagnostic specifically for 
the case where `widen-loops` is enabled during Clang static analysis.

The motivation behind this diagnostic is the fact that the current diagnostic 
is a bit confusing at first glance. For example:
```cpp
class A {
public:
  void m_fn1();
};
void fn1() {
  A a;
  A *b = &a;
  for (;;) {
(void)!b;
b->m_fn1();
  }
}
```

```
> clang -cc1 -internal-isystem C:\...\lib\clang\include -nostdsysteminc 
> -analyze -analyzer-constraints=range -setup-static-analyzer 
> -analyzer-checker=core -analyzer-max-loop 2 -analyzer-config widen-loops=true 
> -analyzer-output=text loop-widening-notes-best.cpp

loop-widening-notes-best.cpp:10:5: warning: Called C++ object pointer is null 
[core.CallAndMessage]
   10 | b->m_fn1();
  | ^
loop-widening-notes-best.cpp:8:3: note: Loop condition is true.  Entering loop 
body
8 |   for (;;) {
  |   ^
loop-widening-notes-best.cpp:8:3: note: Value assigned to 'b'
loop-widening-notes-best.cpp:8:3: note: Loop condition is true.  Entering loop 
body
loop-widening-notes-best.cpp:9:11: note: Assuming 'b' is null
9 | (void)!b;
  |   ^~
loop-widening-notes-best.cpp:10:5: note: Called C++ object pointer is null
   10 | b->m_fn1();
  | ^
1 warning generated.
```

The message `loop-widening-notes-best.cpp:8:3: note: Value assigned to 'b'` 
appearing where it is makes technical sense if you understand what 
`widen-loops` does behind the scenes. In short, `widen-loops` invalidates 
nearly all values in the current state before the start of the loop. At least 
in this example, the variable `b` is invalidated at the start of the for loop 
and, as part of the process of invalidation, is reassigned a conjured symbol 
hence `Value assigned to 'b'`. Without that knowledge, it is not intuitive from 
the diagnostic why the assignment message appears where it does.

In such cases, I'd like to make the diagnostic a bit more verbose. I propose 
something like:
```
loop-widening-notes-best.cpp:8:3: note: Value assigned to 'b' (invalidation as 
part of widen-loops made this symbolic here)
```

This indicates to the user that `b` has been invalidated and turned into a 
symbolic representation because of actions taken by `widen-loops`.

The implementation I present in this PR minimally passes all Clang static 
analysis LIT tests, however, I am not confident the approach I've taken is 
idiomatic with respect to the design of Clang's static analysis. I have what I 
think is a slightly more general solution 
[here](https://github.com/llvm/llvm-project/compare/main...dgg5503:llvm-project:dgg5503/main/invalidation-diagnostic-b)
 where `MemRegion` invalidations are tracked for each `ProgramState`, but it 
also has its own pitfalls (see TODO comments in the 
[diff](https://github.com/llvm/llvm-project/compare/main...dgg5503:llvm-project:dgg5503/main/invalidation-diagnostic-b)).
 I'd be curious to know if there's a preference in either approach, or, if a 
different approach should be taken.

I am open to any and all suggestions as my knowledge in the Clang static 
analyzer is limited.


>From f42c02647f1ecc7ae5cdbda56ab9a5bd6495a0e1 Mon Sep 17 00:00:00 2001
From: Douglas Gliner 
Date: Thu, 9 Jan 2025 11:27:26 -0800
Subject: [PATCH] [analyzer] Widen loops: Augment assignment note when values
 invalidated at the start of a loop

This patch augments the assignment note to inform the user when a value
is invalidated and reassigned a conjured symbol as part of loop
widening.
---
 .../Core/PathSensitive/ExprEngine.h   |  4 ++
 .../Core/BugReporterVisitors.cpp  | 43 +++
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |  7 ++-
 clang/test/Analysis/loop-widening-notes.cpp   | 10 ++---
 clang/test/Analysis/loop-widening.cpp |  2 +-
 5 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
index 20c446e33ef9a5..6017b7e0ea8f81 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -290,6 +290,10 @@ class ExprEngine {
   /// This tag applies to a node created after removeDead.
   static const ProgramPointTag *cleanupNodeTag();
 
+  /// A tag to track when loop widening occurs.
+  /// This tag applies to a node created after getWidenedLoopState.
+  static const ProgramPointTag *loopWideningNodeTag();
+
   /// processCFGElement - Called by CoreEngine. Used to generate new successor
   ///  nodes by processing the 'effects' of a CFG element.
   void processCFGElement(const CFGElement E, ExplodedNode *Pred,
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index

[clang] [analyzer] Widen loops: Augment assignment note when values invalidated at the start of a loop (PR #122398)

2025-01-09 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang

Author: Douglas (dgg5503)


Changes

This PR attempts to improve the value assignment diagnostic specifically for 
the case where `widen-loops` is enabled during Clang static analysis.

The motivation behind this diagnostic is the fact that the current diagnostic 
is a bit confusing at first glance. For example:
```cpp
class A {
public:
  void m_fn1();
};
void fn1() {
  A a;
  A *b = &a;
  for (;;) {
(void)!b;
b->m_fn1();
  }
}
```

```
> clang -cc1 -internal-isystem C:\...\lib\clang\include -nostdsysteminc 
-analyze -analyzer-constraints=range -setup-static-analyzer 
-analyzer-checker=core -analyzer-max-loop 2 -analyzer-config widen-loops=true 
-analyzer-output=text loop-widening-notes-best.cpp

loop-widening-notes-best.cpp:10:5: warning: Called C++ object pointer is null 
[core.CallAndMessage]
   10 | b->m_fn1();
  | ^
loop-widening-notes-best.cpp:8:3: note: Loop condition is true.  Entering loop 
body
8 |   for (;;) {
  |   ^
loop-widening-notes-best.cpp:8:3: note: Value assigned to 'b'
loop-widening-notes-best.cpp:8:3: note: Loop condition is true.  Entering loop 
body
loop-widening-notes-best.cpp:9:11: note: Assuming 'b' is null
9 | (void)!b;
  |   ^~
loop-widening-notes-best.cpp:10:5: note: Called C++ object pointer is null
   10 | b->m_fn1();
  | ^
1 warning generated.
```

The message `loop-widening-notes-best.cpp:8:3: note: Value assigned to 'b'` 
appearing where it is makes technical sense if you understand what 
`widen-loops` does behind the scenes. In short, `widen-loops` invalidates 
nearly all values in the current state before the start of the loop. At least 
in this example, the variable `b` is invalidated at the start of the for loop 
and, as part of the process of invalidation, is reassigned a conjured symbol 
hence `Value assigned to 'b'`. Without that knowledge, it is not intuitive from 
the diagnostic why the assignment message appears where it does.

In such cases, I'd like to make the diagnostic a bit more verbose. I propose 
something like:
```
loop-widening-notes-best.cpp:8:3: note: Value assigned to 'b' (invalidation as 
part of widen-loops made this symbolic here)
```

This indicates to the user that `b` has been invalidated and turned into a 
symbolic representation because of actions taken by `widen-loops`.

The implementation I present in this PR minimally passes all Clang static 
analysis LIT tests, however, I am not confident the approach I've taken is 
idiomatic with respect to the design of Clang's static analysis. I have what I 
think is a slightly more general solution 
[here](https://github.com/llvm/llvm-project/compare/main...dgg5503:llvm-project:dgg5503/main/invalidation-diagnostic-b)
 where `MemRegion` invalidations are tracked for each `ProgramState`, but it 
also has its own pitfalls (see TODO comments in the 
[diff](https://github.com/llvm/llvm-project/compare/main...dgg5503:llvm-project:dgg5503/main/invalidation-diagnostic-b)).
 I'd be curious to know if there's a preference in either approach, or, if a 
different approach should be taken.

I am open to any and all suggestions as my knowledge in the Clang static 
analyzer is limited.


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


5 Files Affected:

- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
(+4) 
- (modified) clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (+43) 
- (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+6-1) 
- (modified) clang/test/Analysis/loop-widening-notes.cpp (+5-5) 
- (modified) clang/test/Analysis/loop-widening.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
index 20c446e33ef9a5..6017b7e0ea8f81 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -290,6 +290,10 @@ class ExprEngine {
   /// This tag applies to a node created after removeDead.
   static const ProgramPointTag *cleanupNodeTag();
 
+  /// A tag to track when loop widening occurs.
+  /// This tag applies to a node created after getWidenedLoopState.
+  static const ProgramPointTag *loopWideningNodeTag();
+
   /// processCFGElement - Called by CoreEngine. Used to generate new successor
   ///  nodes by processing the 'effects' of a CFG element.
   void processCFGElement(const CFGElement E, ExplodedNode *Pred,
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index a9b4dbb39b5bd6..53494b5cf9cca8 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1353,6 +1353,49 @@ static void 
showBRDefaultDiagnostics(llvm::raw_svector_ostream &O

[clang] [SYCL] AST support for SYCL kernel entry point functions. (PR #122379)

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

https://github.com/tahonermann updated 
https://github.com/llvm/llvm-project/pull/122379

>From d021c2ba6a5b3f501b2f87317cb9072781069d73 Mon Sep 17 00:00:00 2001
From: Tom Honermann 
Date: Wed, 8 May 2024 14:31:36 -0700
Subject: [PATCH 1/2] [SYCL] AST support for SYCL kernel entry point functions.

A SYCL kernel entry point function is a non-member function or a static member
function declared with the `sycl_kernel_entry_point` attribute. Such functions
define a pattern for an offload kernel entry point function to be generated to
enable execution of a SYCL kernel on a device. A SYCL library implementation
orchestrates the invocation of these functions with corresponding SYCL kernel
arguments in response to calls to SYCL kernel invocation functions specified
by the SYCL 2020 specification.

The offload kernel entry point function (sometimes referred to as the SYCL
kernel caller function) is generated from the SYCL kernel entry point function
by a transformation of the function parameters followed by a transformation of
the function body to replace references to the original parameters with
references to the transformed ones. Exactly how parameters are transformed will
be explained in a future change that implements non-trivial transformations.
For now, it suffices to state that a given parameter of the SYCL kernel entry
point function may be transformed to multiple parameters of the offload kernel
entry point as needed to satisfy offload kernel argument passing requirements.
Parameters that are decomposed in this way are reconstituted as local variables
in the body of the generated offload kernel entry point function.

For example, given the following SYCL kernel entry point function definition:

  template
  [[clang::sycl_kernel_entry_point(KernelNameType)]]
  void sycl_kernel_entry_point(KernelType kernel) {
kernel();
  }

and the following call:

  struct Kernel {
int dm1;
int dm2;
void operator()() const;
  };
  Kernel k;
  sycl_kernel_entry_point(k);

the corresponding offload kernel entry point function that is generated might
look as follows (assuming `Kernel` is a type that requires decomposition):

  void offload_kernel_entry_point_for_kernel_name(int dm1, int dm2) {
Kernel kernel{dm1, dm2};
kernel();
  }

Other details of the generated offload kernel entry point function, such as
its name and callng convention, are implementation details that need not be
reflected in the AST and may differ across target devices. For that reason,
only the transformation described above is represented in the AST; other
details will be filled in during code generation.

These transformations are represented using new AST nodes introduced with this
change. `OutlinedFunctionDecl` holds a sequence of `ImplicitParamDecl` nodes
and a sequence of statement nodes that correspond to the transformed
parameters and function body. `SYCLKernelCallStmt` wraps the original function
body and associates it with an `OutlinedFunctionDecl` instance. For the example
above, the AST generated for the `sycl_kernel_entry_point`
specialization would look as follows:

  FunctionDecl 'sycl_kernel_entry_point(Kernel)'
TemplateArgument type 'kernel_name'
TemplateArgument type 'Kernel'
ParmVarDecl kernel 'Kernel'
SYCLKernelCallStmt
  CompoundStmt

  OutlinedFunctionDecl
ImplicitParamDecl 'dm1' 'int'
ImplicitParamDecl 'dm2' 'int'
CompoundStmt
  VarDecl 'kernel' 'Kernel'

  

Any ODR-use of the SYCL kernel entry point function will (with future changes)
suffice for the offload kernel entry point to be emitted. An actual call to
the SYCL kernel entry point function will result in a call to the function.
However, evaluation of a `SYCLKernelCallStmt` statement is a no-op, so such
calls will have no effect other than to trigger emission of the offload kernel
entry point.
---
 clang/include/clang/AST/ASTNodeTraverser.h|  16 +-
 clang/include/clang/AST/Decl.h|  90 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |  14 +
 clang/include/clang/AST/StmtSYCL.h|  95 ++
 clang/include/clang/AST/StmtVisitor.h |   1 +
 clang/include/clang/Basic/DeclNodes.td|   1 +
 clang/include/clang/Basic/StmtNodes.td|   1 +
 clang/include/clang/Sema/SemaSYCL.h   |   1 +
 clang/include/clang/Sema/Template.h   |   5 +-
 .../include/clang/Serialization/ASTBitCodes.h |   6 +
 clang/lib/AST/ASTStructuralEquivalence.cpp|   1 +
 clang/lib/AST/Decl.cpp|  25 ++
 clang/lib/AST/DeclBase.cpp|   4 +
 clang/lib/AST/Stmt.cpp|   1 +
 clang/lib/AST/StmtPrinter.cpp |   5 +
 clang/lib/AST/StmtProfile.cpp |   4 +
 clang/lib/CodeGen/CGDecl.cpp  |   1 +
 clang/lib/CodeGen/CGStmt.cpp  |  18 ++
 clang/lib/CodeGen/CodeGenFunction.h   |   1 +
 clang/lib/Sema/JumpDiagnostics

[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-01-09 Thread Jonas Paulsson via cfe-commits

JonPsson1 wrote:

Thanks for help - I think I found the way to enable the building of these 
functions - patch updated.

I could now (for the first time? :D ) compile and run a program on SystemZ with 
_Float16 variables, by using `--rtlib=compiler-rt `with clang.

As I am not the expert on FP semantics, I wonder if anyone could confirm that 
these routines are safe and correct to use as far as FP exceptions, rounding 
modes, (..?) goes?

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


[clang] [analyzer] Widen loops: Augment assignment note when values invalidated at the start of a loop (PR #122398)

2025-01-09 Thread via cfe-commits


@@ -1353,6 +1353,49 @@ static void 
showBRDefaultDiagnostics(llvm::raw_svector_ostream &OS,
 OS << " to ";
 SI.Dest->printPretty(OS);
   }
+
+  // If the value was part of a loop widening node and its value was
+  // invalidated (i.e. replaced with a conjured symbol) then let the user know
+  // that it was due to loop widening.
+  if (SI.StoreSite && SI.Dest &&
+  SI.StoreSite->getLocation().getTag() ==
+  ExprEngine::loopWideningNodeTag()) {
+
+// TODO: Is it always the case that there's only one predecessor?
+assert(SI.StoreSite->hasSinglePred() &&
+   "more than one predecessor found, this needs to be handled...");
+if (const ExplodedNode *previous = SI.StoreSite->getFirstPred()) {
+  // Was the associated memory region for this variable changed from
+  // non-Symbolic to Symbolic because of invalidation?
+  // TODO: Better yet, if there was simply a way to know if a given
+  // SVal / MemRegion was invalidated as part of the current state,
+  // then that should be more robust than what's going on here.
+  // Could we somehow make use of "RegionChanges" /
+  // "runCheckersForRegionChanges" and the ExplicitRegions parameter.
+  // Still need to somehow know when a particular Global
+  // Variable is invalidated. I have not found this to be possible with
+  // "RegionChanges" unless I'm missing something...

dgg5503 wrote:

I tried to implement this in 
https://github.com/llvm/llvm-project/compare/main...dgg5503:llvm-project:dgg5503/main/invalidation-diagnostic-b
 but all `MemRegion`s from the `ProgramState` and before are tracked. I'm 
wondering if there's a way to clear `InvalidatedMemoryRegionSet` at the start 
of each `ProgramState`, or, if there's a different approach I should be 
taking...

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


[clang] [SYCL] AST support for SYCL kernel entry point functions. (PR #122379)

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

https://github.com/tahonermann updated 
https://github.com/llvm/llvm-project/pull/122379

>From d021c2ba6a5b3f501b2f87317cb9072781069d73 Mon Sep 17 00:00:00 2001
From: Tom Honermann 
Date: Wed, 8 May 2024 14:31:36 -0700
Subject: [PATCH 1/2] [SYCL] AST support for SYCL kernel entry point functions.

A SYCL kernel entry point function is a non-member function or a static member
function declared with the `sycl_kernel_entry_point` attribute. Such functions
define a pattern for an offload kernel entry point function to be generated to
enable execution of a SYCL kernel on a device. A SYCL library implementation
orchestrates the invocation of these functions with corresponding SYCL kernel
arguments in response to calls to SYCL kernel invocation functions specified
by the SYCL 2020 specification.

The offload kernel entry point function (sometimes referred to as the SYCL
kernel caller function) is generated from the SYCL kernel entry point function
by a transformation of the function parameters followed by a transformation of
the function body to replace references to the original parameters with
references to the transformed ones. Exactly how parameters are transformed will
be explained in a future change that implements non-trivial transformations.
For now, it suffices to state that a given parameter of the SYCL kernel entry
point function may be transformed to multiple parameters of the offload kernel
entry point as needed to satisfy offload kernel argument passing requirements.
Parameters that are decomposed in this way are reconstituted as local variables
in the body of the generated offload kernel entry point function.

For example, given the following SYCL kernel entry point function definition:

  template
  [[clang::sycl_kernel_entry_point(KernelNameType)]]
  void sycl_kernel_entry_point(KernelType kernel) {
kernel();
  }

and the following call:

  struct Kernel {
int dm1;
int dm2;
void operator()() const;
  };
  Kernel k;
  sycl_kernel_entry_point(k);

the corresponding offload kernel entry point function that is generated might
look as follows (assuming `Kernel` is a type that requires decomposition):

  void offload_kernel_entry_point_for_kernel_name(int dm1, int dm2) {
Kernel kernel{dm1, dm2};
kernel();
  }

Other details of the generated offload kernel entry point function, such as
its name and callng convention, are implementation details that need not be
reflected in the AST and may differ across target devices. For that reason,
only the transformation described above is represented in the AST; other
details will be filled in during code generation.

These transformations are represented using new AST nodes introduced with this
change. `OutlinedFunctionDecl` holds a sequence of `ImplicitParamDecl` nodes
and a sequence of statement nodes that correspond to the transformed
parameters and function body. `SYCLKernelCallStmt` wraps the original function
body and associates it with an `OutlinedFunctionDecl` instance. For the example
above, the AST generated for the `sycl_kernel_entry_point`
specialization would look as follows:

  FunctionDecl 'sycl_kernel_entry_point(Kernel)'
TemplateArgument type 'kernel_name'
TemplateArgument type 'Kernel'
ParmVarDecl kernel 'Kernel'
SYCLKernelCallStmt
  CompoundStmt

  OutlinedFunctionDecl
ImplicitParamDecl 'dm1' 'int'
ImplicitParamDecl 'dm2' 'int'
CompoundStmt
  VarDecl 'kernel' 'Kernel'

  

Any ODR-use of the SYCL kernel entry point function will (with future changes)
suffice for the offload kernel entry point to be emitted. An actual call to
the SYCL kernel entry point function will result in a call to the function.
However, evaluation of a `SYCLKernelCallStmt` statement is a no-op, so such
calls will have no effect other than to trigger emission of the offload kernel
entry point.
---
 clang/include/clang/AST/ASTNodeTraverser.h|  16 +-
 clang/include/clang/AST/Decl.h|  90 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |  14 +
 clang/include/clang/AST/StmtSYCL.h|  95 ++
 clang/include/clang/AST/StmtVisitor.h |   1 +
 clang/include/clang/Basic/DeclNodes.td|   1 +
 clang/include/clang/Basic/StmtNodes.td|   1 +
 clang/include/clang/Sema/SemaSYCL.h   |   1 +
 clang/include/clang/Sema/Template.h   |   5 +-
 .../include/clang/Serialization/ASTBitCodes.h |   6 +
 clang/lib/AST/ASTStructuralEquivalence.cpp|   1 +
 clang/lib/AST/Decl.cpp|  25 ++
 clang/lib/AST/DeclBase.cpp|   4 +
 clang/lib/AST/Stmt.cpp|   1 +
 clang/lib/AST/StmtPrinter.cpp |   5 +
 clang/lib/AST/StmtProfile.cpp |   4 +
 clang/lib/CodeGen/CGDecl.cpp  |   1 +
 clang/lib/CodeGen/CGStmt.cpp  |  18 ++
 clang/lib/CodeGen/CodeGenFunction.h   |   1 +
 clang/lib/Sema/JumpDiagnostics

[clang] [clang][AST] Assert that DependentNameType::Name is not null (PR #122418)

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

HighCommander4 wrote:

Context: I was confused by the comment above 
`DependentNameType::getIdentifier()`, which suggested the function only 
sometimes returns non-null, but I couldn't find any case where it would.

It turns out the comment dates back to a time when the type stored a 
`PointerUnion`, and 
only returned non-null if an `IdentifierInfo *` was stored. That was changed in 
https://github.com/llvm/llvm-project/commit/c392f37ae81d99a29c95dafb964e52492f2e0f37.

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


[clang] [clang][AST] Assert that DependentNameType::Name is not null (PR #122418)

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

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/122418

Also clarify the comment above DependentNameType::getIdentifier()

>From a1e3dcc6063cafa2f79aed88090dcc6f14be0ed7 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Thu, 9 Jan 2025 23:55:35 -0500
Subject: [PATCH] [clang][AST] Assert that DependentNameType::Name is not null

Also clarify the comment above DependentNameType::getIdentifier()
---
 clang/include/clang/AST/Type.h | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 09c98f642852fc..2ec59c2cb9a8f6 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -7035,17 +7035,16 @@ class DependentNameType : public TypeWithKeyword, 
public llvm::FoldingSetNode {
   : TypeWithKeyword(Keyword, DependentName, CanonType,
 TypeDependence::DependentInstantiation |
 toTypeDependence(NNS->getDependence())),
-NNS(NNS), Name(Name) {}
+NNS(NNS), Name(Name) {
+assert(Name);
+  }
 
 public:
   /// Retrieve the qualification on this type.
   NestedNameSpecifier *getQualifier() const { return NNS; }
 
-  /// Retrieve the type named by the typename specifier as an identifier.
-  ///
-  /// This routine will return a non-NULL identifier pointer when the
-  /// form of the original typename was terminated by an identifier,
-  /// e.g., "typename T::type".
+  /// Retrieve the identifier that terminates this type name.
+  /// For example, "type" in "typename T::type".
   const IdentifierInfo *getIdentifier() const {
 return Name;
   }

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


[clang] [clang][AST] Assert that DependentNameType::Name is not null (PR #122418)

2025-01-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nathan Ridge (HighCommander4)


Changes

Also clarify the comment above DependentNameType::getIdentifier()

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


1 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+5-6) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 09c98f642852fc..2ec59c2cb9a8f6 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -7035,17 +7035,16 @@ class DependentNameType : public TypeWithKeyword, 
public llvm::FoldingSetNode {
   : TypeWithKeyword(Keyword, DependentName, CanonType,
 TypeDependence::DependentInstantiation |
 toTypeDependence(NNS->getDependence())),
-NNS(NNS), Name(Name) {}
+NNS(NNS), Name(Name) {
+assert(Name);
+  }
 
 public:
   /// Retrieve the qualification on this type.
   NestedNameSpecifier *getQualifier() const { return NNS; }
 
-  /// Retrieve the type named by the typename specifier as an identifier.
-  ///
-  /// This routine will return a non-NULL identifier pointer when the
-  /// form of the original typename was terminated by an identifier,
-  /// e.g., "typename T::type".
+  /// Retrieve the identifier that terminates this type name.
+  /// For example, "type" in "typename T::type".
   const IdentifierInfo *getIdentifier() const {
 return Name;
   }

``




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


[clang] [Clang] Remove 3-element vector load and store special handling (PR #104661)

2025-01-09 Thread Matt Arsenault via cfe-commits


@@ -94,43 +94,43 @@ typedef double __attribute__((ext_vector_type(16))) 
double16;
 // CHECK-LABEL: @local_memory_alignment_global(
 // CHECK: store volatile i8 0, ptr addrspace(3) 
@local_memory_alignment_global.lds_i8, align 1
 // CHECK: store volatile <2 x i8> zeroinitializer, ptr addrspace(3) 
@local_memory_alignment_global.lds_v2i8, align 2
-// CHECK: store volatile <4 x i8> , ptr 
addrspace(3) @local_memory_alignment_global.lds_v3i8, align 4
+// CHECK: store volatile <3 x i8> zeroinitializer, ptr addrspace(3) 
@local_memory_alignment_global.lds_v3i8, align 4
 // CHECK: store volatile <4 x i8> zeroinitializer, ptr addrspace(3) 
@local_memory_alignment_global.lds_v4i8, align 4
 // CHECK: store volatile <8 x i8> zeroinitializer, ptr addrspace(3) 
@local_memory_alignment_global.lds_v8i8, align 8
 // CHECK: store volatile <16 x i8> zeroinitializer, ptr addrspace(3) 
@local_memory_alignment_global.lds_v16i8, align 16
 // CHECK: store volatile i16 0, ptr addrspace(3) 
@local_memory_alignment_global.lds_i16, align 2
 // CHECK: store volatile <2 x i16> zeroinitializer, ptr addrspace(3) 
@local_memory_alignment_global.lds_v2i16, align 4
-// CHECK: store volatile <4 x i16> , ptr 
addrspace(3) @local_memory_alignment_global.lds_v3i16, align 8
+// CHECK: store volatile <3 x i16> zeroinitializer, ptr addrspace(3) 
@local_memory_alignment_global.lds_v3i16, align 8
 // CHECK: store volatile <4 x i16> zeroinitializer, ptr addrspace(3) 
@local_memory_alignment_global.lds_v4i16, align 8
 // CHECK: store volatile <8 x i16> zeroinitializer, ptr addrspace(3) 
@local_memory_alignment_global.lds_v8i16, align 16
 // CHECK: store volatile <16 x i16> zeroinitializer, ptr addrspace(3) 
@local_memory_alignment_global.lds_v16i16, align 32
 // CHECK: store volatile i32 0, ptr addrspace(3) 
@local_memory_alignment_global.lds_i32, align 4
 // CHECK: store volatile <2 x i32> zeroinitializer, ptr addrspace(3) 
@local_memory_alignment_global.lds_v2i32, align 8
-// CHECK: store volatile <4 x i32> , ptr 
addrspace(3) @local_memory_alignment_global.lds_v3i32, align 16
+// CHECK: store volatile <3 x i32> zeroinitializer, ptr addrspace(3) 
@local_memory_alignment_global.lds_v3i32, align 16

arsenm wrote:

`error: invalid vector element type '__private char *'`

I guess it doesn't let you use pointers for no real reason 

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


[clang] [InstrProf] Add frontend temporal profiling flag (PR #122385)

2025-01-09 Thread David Li via cfe-commits


@@ -3035,6 +3035,38 @@ indexed format, regardeless whether it is produced by 
frontend or the IR pass.
   overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported
   by the target, or ``single`` otherwise.
 
+.. option:: -fprofile-generate-temporal

david-xl wrote:

Since this option is used together with the primary option -fprofile-generate, 
the naming consistency is not important. I suggest making it even simpler: 
-ftemporal-profile

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


[clang] [Clang] Remove 3-element vector load and store special handling (PR #104661)

2025-01-09 Thread Matt Arsenault via cfe-commits


@@ -52,6 +52,12 @@ class AMDGPUABIInfo final : public DefaultABIInfo {
   void computeInfo(CGFunctionInfo &FI) const override;
   RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
AggValueSlot Slot) const override;
+
+  llvm::FixedVectorType *
+  getOptimalVectorType(llvm::FixedVectorType *T,
+   const LangOptions &) const override {
+return T;

arsenm wrote:

With a direct instruction, yes. We can't widen the stores in the other odd 
cases so we need the hint that it's OK by using the wider type 

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


[clang] [Clang] Remove 3-element vector load and store special handling (PR #104661)

2025-01-09 Thread Matt Arsenault via cfe-commits


@@ -1,77 +0,0 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown 
-fpreserve-vec3-type | FileCheck %s
-
-typedef char char3 __attribute__((ext_vector_type(3)));

arsenm wrote:

I'm not sure we have adequate coverage of the 3 element vector types elsewhere. 
You could remove the flag 

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


[clang] [clang-tools-extra] [clang][Sema] Upstream HeuristicResolver from clangd (PR #121314)

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

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/121314

>From 4f0e828af34144412c42d8dda6e6a91c44f6b1fa Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Thu, 26 Dec 2024 00:40:48 -0500
Subject: [PATCH] [clang][Sema] Upstream HeuristicResolver from clangd

Fixes https://github.com/llvm/llvm-project/issues/121310
---
 clang-tools-extra/clangd/CMakeLists.txt| 1 -
 clang-tools-extra/clangd/FindTarget.cpp| 2 +-
 clang-tools-extra/clangd/FindTarget.h  | 4 +++-
 clang-tools-extra/clangd/InlayHints.cpp| 2 +-
 clang-tools-extra/clangd/ParsedAST.cpp | 2 +-
 clang-tools-extra/clangd/ParsedAST.h   | 2 +-
 clang-tools-extra/clangd/SemanticHighlighting.cpp  | 2 +-
 clang-tools-extra/clangd/XRefs.cpp | 2 +-
 clang-tools-extra/clangd/unittests/CMakeLists.txt  | 1 -
 .../include/clang/Sema}/HeuristicResolver.h| 7 ++-
 clang/lib/Sema/CMakeLists.txt  | 1 +
 .../clangd => clang/lib/Sema}/HeuristicResolver.cpp| 4 +---
 clang/unittests/Sema/CMakeLists.txt| 1 +
 .../unittests/Sema/HeuristicResolverTest.cpp   | 3 +--
 14 files changed, 15 insertions(+), 19 deletions(-)
 rename {clang-tools-extra/clangd => 
clang/include/clang/Sema}/HeuristicResolver.h (95%)
 rename {clang-tools-extra/clangd => clang/lib/Sema}/HeuristicResolver.cpp (99%)
 rename clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp => 
clang/unittests/Sema/HeuristicResolverTest.cpp (99%)

diff --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index d797ddce8c44d1..6f10afe4a5625f 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -91,7 +91,6 @@ add_clang_library(clangDaemon STATIC
   GlobalCompilationDatabase.cpp
   Headers.cpp
   HeaderSourceSwitch.cpp
-  HeuristicResolver.cpp
   Hover.cpp
   IncludeCleaner.cpp
   IncludeFixer.cpp
diff --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index e702c6b3537a09..04fd6d437b7bdd 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -8,7 +8,6 @@
 
 #include "FindTarget.h"
 #include "AST.h"
-#include "HeuristicResolver.h"
 #include "support/Logger.h"
 #include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTTypeTraits.h"
@@ -35,6 +34,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Specifiers.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
diff --git a/clang-tools-extra/clangd/FindTarget.h 
b/clang-tools-extra/clangd/FindTarget.h
index b41c5470951001..a7706804ce7ece 100644
--- a/clang-tools-extra/clangd/FindTarget.h
+++ b/clang-tools-extra/clangd/FindTarget.h
@@ -33,9 +33,11 @@
 #include 
 
 namespace clang {
-namespace clangd {
+
 class HeuristicResolver;
 
+namespace clangd {
+
 /// Describes the link between an AST node and a Decl it refers to.
 enum class DeclRelation : unsigned;
 /// A bitfield of DeclRelations.
diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index fefffeb4efc1a2..1b1bcf78c9855e 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -9,7 +9,6 @@
 #include "../clang-tidy/utils/DesignatedInitializers.h"
 #include "AST.h"
 #include "Config.h"
-#include "HeuristicResolver.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "SourceCode.h"
@@ -27,6 +26,7 @@
 #include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index 725cbeb154cb84..89d6f26d0f150e 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -20,7 +20,6 @@
 #include "Feature.h"
 #include "FeatureModule.h"
 #include "Headers.h"
-#include "HeuristicResolver.h"
 #include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
@@ -53,6 +52,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Sema/HeuristicResolver.h"
 #include "clang/Serialization/ASTWriter.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Diagnostic.h"
diff --git a/clang-tools-extra/clangd/ParsedAST.h 
b/clang-tools-extra/clangd/ParsedAST.h
index 8d9d1e64569267..82fac96360488e 100644
--- a/clang-tools-extra/clangd/ParsedAST.h
+++ b/clang-tools-extra/clangd/ParsedAST.h
@@ -38,9 +38,9 @@
 #include 
 

[clang] [Clang] Remove 3-element vector load and store special handling (PR #104661)

2025-01-09 Thread Matt Arsenault via cfe-commits


@@ -52,6 +52,14 @@ class AMDGPUABIInfo final : public DefaultABIInfo {
   void computeInfo(CGFunctionInfo &FI) const override;
   RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
AggValueSlot Slot) const override;
+
+  llvm::FixedVectorType *
+  getOptimalVectorType(llvm::FixedVectorType *T,
+   const LangOptions &Opt) const override {
+if (T->getNumElements() == 3 && T->getScalarSizeInBits() == 32)

arsenm wrote:

Should use the datalayout to get the size 

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


[clang] [clang-tools-extra] [clang][Sema] Upstream HeuristicResolver from clangd (PR #121314)

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

HighCommander4 wrote:

Rebased.

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


[clang] [Clang] Remove 3-element vector load and store special handling (PR #104661)

2025-01-09 Thread Matt Arsenault via cfe-commits


@@ -52,6 +52,14 @@ class AMDGPUABIInfo final : public DefaultABIInfo {
   void computeInfo(CGFunctionInfo &FI) const override;
   RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
AggValueSlot Slot) const override;
+
+  llvm::FixedVectorType *
+  getOptimalVectorType(llvm::FixedVectorType *T,
+   const LangOptions &Opt) const override {
+if (T->getNumElements() == 3 && T->getScalarSizeInBits() == 32)

arsenm wrote:

Comment why. Also should add a fixme that we should check subtarget feature. 
Technically SI didn't have these 

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


[clang] a4394d9 - [NFC][ubsan] Rename prefixes in test

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

Author: Vitaly Buka
Date: 2025-01-09T21:12:36-08:00
New Revision: a4394d9d42fb6e60e3702588fb56bec243038c49

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

LOG: [NFC][ubsan] Rename prefixes in test

Looks like update_cc_test_checks is being confused if
it creates vars with the name matching prefix.

Issue triggered with #122415

Added: 


Modified: 
clang/test/CodeGen/allow-ubsan-check.c

Removed: 




diff  --git a/clang/test/CodeGen/allow-ubsan-check.c 
b/clang/test/CodeGen/allow-ubsan-check.c
index 5232d240854666..e3860784e716f1 100644
--- a/clang/test/CodeGen/allow-ubsan-check.c
+++ b/clang/test/CodeGen/allow-ubsan-check.c
@@ -1,7 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s 
-fsanitize=signed-integer-overflow,integer-divide-by-zero,null -mllvm 
-ubsan-guard-checks | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s 
-fsanitize=signed-integer-overflow,integer-divide-by-zero,null -mllvm 
-ubsan-guard-checks 
-fsanitize-trap=signed-integer-overflow,integer-divide-by-zero,null | FileCheck 
%s --check-prefixes=TRAP
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s 
-fsanitize=signed-integer-overflow,integer-divide-by-zero,null -mllvm 
-ubsan-guard-checks 
-fsanitize-recover=signed-integer-overflow,integer-divide-by-zero,null | 
FileCheck %s --check-prefixes=RECOVER
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s 
-fsanitize=signed-integer-overflow,integer-divide-by-zero,null -mllvm 
-ubsan-guard-checks 
-fsanitize-trap=signed-integer-overflow,integer-divide-by-zero,null | FileCheck 
%s --check-prefixes=TR
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s 
-fsanitize=signed-integer-overflow,integer-divide-by-zero,null -mllvm 
-ubsan-guard-checks 
-fsanitize-recover=signed-integer-overflow,integer-divide-by-zero,null | 
FileCheck %s --check-prefixes=REC
 
 
 // CHECK-LABEL: define dso_local i32 @div(
@@ -31,57 +31,57 @@
 // CHECK-NEXT:[[DIV:%.*]] = sdiv i32 [[TMP0]], [[TMP1]]
 // CHECK-NEXT:ret i32 [[DIV]]
 //
-// TRAP-LABEL: define dso_local i32 @div(
-// TRAP-SAME: i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR0:[0-9]+]] {
-// TRAP-NEXT:  entry:
-// TRAP-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
-// TRAP-NEXT:[[Y_ADDR:%.*]] = alloca i32, align 4
-// TRAP-NEXT:store i32 [[X]], ptr [[X_ADDR]], align 4
-// TRAP-NEXT:store i32 [[Y]], ptr [[Y_ADDR]], align 4
-// TRAP-NEXT:[[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
-// TRAP-NEXT:[[TMP1:%.*]] = load i32, ptr [[Y_ADDR]], align 4
-// TRAP-NEXT:[[TMP2:%.*]] = icmp ne i32 [[TMP1]], 0, !nosanitize 
[[META2:![0-9]+]]
-// TRAP-NEXT:[[TMP3:%.*]] = icmp ne i32 [[TMP0]], -2147483648, !nosanitize 
[[META2]]
-// TRAP-NEXT:[[TMP4:%.*]] = icmp ne i32 [[TMP1]], -1, !nosanitize [[META2]]
-// TRAP-NEXT:[[OR:%.*]] = or i1 [[TMP3]], [[TMP4]], !nosanitize [[META2]]
-// TRAP-NEXT:[[TMP5:%.*]] = and i1 [[TMP2]], [[OR]], !nosanitize [[META2]]
-// TRAP-NEXT:[[TMP6:%.*]] = call i1 @llvm.allow.ubsan.check(i8 3), 
!nosanitize [[META2]]
-// TRAP-NEXT:[[TMP7:%.*]] = xor i1 [[TMP6]], true, !nosanitize [[META2]]
-// TRAP-NEXT:[[TMP8:%.*]] = or i1 [[TMP5]], [[TMP7]], !nosanitize [[META2]]
-// TRAP-NEXT:br i1 [[TMP8]], label [[CONT:%.*]], label [[TRAP:%.*]], 
!nosanitize [[META2]]
-// TRAP:   trap:
-// TRAP-NEXT:call void @llvm.ubsantrap(i8 3) #[[ATTR4:[0-9]+]], 
!nosanitize [[META2]]
-// TRAP-NEXT:unreachable, !nosanitize [[META2]]
-// TRAP:   cont:
-// TRAP-NEXT:[[DIV:%.*]] = sdiv i32 [[TMP0]], [[TMP1]]
-// TRAP-NEXT:ret i32 [[DIV]]
+// TR-LABEL: define dso_local i32 @div(
+// TR-SAME: i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR0:[0-9]+]] {
+// TR-NEXT:  entry:
+// TR-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
+// TR-NEXT:[[Y_ADDR:%.*]] = alloca i32, align 4
+// TR-NEXT:store i32 [[X]], ptr [[X_ADDR]], align 4
+// TR-NEXT:store i32 [[Y]], ptr [[Y_ADDR]], align 4
+// TR-NEXT:[[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// TR-NEXT:[[TMP1:%.*]] = load i32, ptr [[Y_ADDR]], align 4
+// TR-NEXT:[[TMP2:%.*]] = icmp ne i32 [[TMP1]], 0, !nosanitize 
[[META2:![0-9]+]]
+// TR-NEXT:[[TMP3:%.*]] = icmp ne i32 [[TMP0]], -2147483648, !nosanitize 
[[META2]]
+// TR-NEXT:[[TMP4:%.*]] = icmp ne i32 [[TMP1]], -1, !nosanitize [[META2]]
+// TR-NEXT:[[OR:%.*]] = or i1 [[TMP3]], [[TMP4]], !nosanitize [[META2]]
+// TR-NEXT:[[TMP5:%.*]] = and i1 [[TMP2]], [[OR]], !nosanitize [[META2]]
+// TR-NEXT:[[TMP6:%.*]] = call i1 @llvm.allow.ubsan.check(i8 3), 
!nosanitize [[META2]]
+// TR-NEXT:[[TMP7:%.*]] = xor i1 [[TMP

[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-01-09 Thread Matt Arsenault via cfe-commits


@@ -446,10 +448,11 @@ ABIArgInfo SystemZABIInfo::classifyArgumentType(QualType 
Ty) const {
 
 // The structure is passed as an unextended integer, a float, or a double.
 if (isFPArgumentType(SingleElementTy)) {
-  assert(Size == 32 || Size == 64);
+  assert(Size == 16 || Size == 32 || Size == 64);
   return ABIArgInfo::getDirect(
-  Size == 32 ? llvm::Type::getFloatTy(getVMContext())
- : llvm::Type::getDoubleTy(getVMContext()));
+  Size == 16   ? llvm::Type::getHalfTy(getVMContext())

arsenm wrote:

I don't think it matters if it's reachable or not, should write future proof 
code and avoid repeating this pattern 

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


[clang] [Darwin][Driver][clang] arm64-apple-none-macho is missing the Apple macros from arm-apple-none-macho (PR #122427)

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

https://github.com/ian-twilightcoder created 
https://github.com/llvm/llvm-project/pull/122427

arm-apple-none-macho uses DarwinTargetInfo which provides several Apple 
specific macros. arm64-apple-none-macho however just uses the generic 
AArch64leTargetInfo and doesn't get any of those macros. It's not clear if 
everything from DarwinTargetInfo is desirable for arm64-apple-none-macho, so 
make an AppleMachOTargetInfo to hold the generic Apple macros and a few other 
basic things.

>From 0fa656d2c9ea1b789f898b10bd5ff6706c03205d Mon Sep 17 00:00:00 2001
From: Ian Anderson 
Date: Thu, 9 Jan 2025 22:50:52 -0800
Subject: [PATCH] [Darwin][Driver][clang] arm64-apple-none-macho is missing the
 Apple macros from arm-apple-none-macho

arm-apple-none-macho uses DarwinTargetInfo which provides several Apple 
specific macros. arm64-apple-none-macho however just uses the generic 
AArch64leTargetInfo and doesn't get any of those macros. It's not clear if 
everything from DarwinTargetInfo is desirable for arm64-apple-none-macho, so 
make an AppleMachOTargetInfo to hold the generic Apple macros and a few other 
basic things.
---
 clang/lib/Basic/Targets.cpp   |  8 
 clang/lib/Basic/Targets/AArch64.cpp   | 23 +--
 clang/lib/Basic/Targets/AArch64.h | 13 +++
 clang/lib/Basic/Targets/ARM.cpp   | 10 +
 clang/lib/Basic/Targets/ARM.h | 11 ++
 clang/lib/Basic/Targets/OSTargets.cpp | 25 +---
 clang/lib/Basic/Targets/OSTargets.h   | 38 +++
 clang/lib/Basic/Targets/X86.h |  8 
 clang/lib/Frontend/InitPreprocessor.cpp   |  5 ---
 .../Preprocessor/macho-embedded-predefines.c  | 15 
 10 files changed, 134 insertions(+), 22 deletions(-)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index be5dedbe8044e2..f61beb98e0ac0e 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -135,11 +135,15 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   case llvm::Triple::aarch64_32:
 if (Triple.isOSDarwin())
   return std::make_unique(Triple, Opts);
+else if (Triple.isAppleMachO())
+  return std::make_unique(Triple, Opts);
 
 return nullptr;
   case llvm::Triple::aarch64:
 if (Triple.isOSDarwin())
   return std::make_unique(Triple, Opts);
+else if (Triple.isAppleMachO())
+  return std::make_unique(Triple, Opts);
 
 switch (os) {
 case llvm::Triple::FreeBSD:
@@ -243,6 +247,8 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   case llvm::Triple::thumbeb:
 if (Triple.isOSDarwin())
   return std::make_unique(Triple, Opts);
+else if (Triple.isAppleMachO())
+  return std::make_unique(Triple, Opts);
 
 switch (os) {
 case llvm::Triple::Linux:
@@ -531,6 +537,8 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   case llvm::Triple::x86:
 if (Triple.isOSDarwin())
   return std::make_unique(Triple, Opts);
+else if (Triple.isAppleMachO())
+  return std::make_unique(Triple, Opts);
 
 switch (os) {
 case llvm::Triple::Linux: {
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 2b4b954d0c27ad..1bf58661d0efcd 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1671,6 +1671,10 @@ MinGWARM64TargetInfo::MinGWARM64TargetInfo(const 
llvm::Triple &Triple,
   TheCXXABI.set(TargetCXXABI::GenericAArch64);
 }
 
+AppleMachOAArch64TargetInfo::AppleMachOAArch64TargetInfo(
+const llvm::Triple &Triple, const TargetOptions &Opts)
+: AppleMachOTargetInfo(Triple, Opts) {}
+
 DarwinAArch64TargetInfo::DarwinAArch64TargetInfo(const llvm::Triple &Triple,
  const TargetOptions &Opts)
 : DarwinTargetInfo(Triple, Opts) {
@@ -1695,9 +1699,9 @@ DarwinAArch64TargetInfo::DarwinAArch64TargetInfo(const 
llvm::Triple &Triple,
 TheCXXABI.set(TargetCXXABI::AppleARM64);
 }
 
-void DarwinAArch64TargetInfo::getOSDefines(const LangOptions &Opts,
-   const llvm::Triple &Triple,
-   MacroBuilder &Builder) const {
+void clang::targets::getAppleMachOAArch64Defines(MacroBuilder &Builder,
+ const LangOptions &Opts,
+ const llvm::Triple &Triple) {
   Builder.defineMacro("__AARCH64_SIMD__");
   if (Triple.isArch32Bit())
 Builder.defineMacro("__ARM64_ARCH_8_32__");
@@ -1710,7 +1714,20 @@ void DarwinAArch64TargetInfo::getOSDefines(const 
LangOptions &Opts,
 
   if (Triple.isArm64e())
 Builder.defineMacro("__arm64e__", "1");
+}
 
+void AppleMachOAArch64TargetInfo::getOSDefines(const LangOptions &Opts,
+   const llvm::Triple &Triple,
+   MacroBuilder &Builder) con

[clang] [Darwin][Driver][clang] arm64-apple-none-macho is missing the Apple macros from arm-apple-none-macho (PR #122427)

2025-01-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-arm

Author: Ian Anderson (ian-twilightcoder)


Changes

arm-apple-none-macho uses DarwinTargetInfo which provides several Apple 
specific macros. arm64-apple-none-macho however just uses the generic 
AArch64leTargetInfo and doesn't get any of those macros. It's not clear if 
everything from DarwinTargetInfo is desirable for arm64-apple-none-macho, so 
make an AppleMachOTargetInfo to hold the generic Apple macros and a few other 
basic things.

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


10 Files Affected:

- (modified) clang/lib/Basic/Targets.cpp (+8) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+20-3) 
- (modified) clang/lib/Basic/Targets/AArch64.h (+13) 
- (modified) clang/lib/Basic/Targets/ARM.cpp (+10) 
- (modified) clang/lib/Basic/Targets/ARM.h (+11) 
- (modified) clang/lib/Basic/Targets/OSTargets.cpp (+19-6) 
- (modified) clang/lib/Basic/Targets/OSTargets.h (+30-8) 
- (modified) clang/lib/Basic/Targets/X86.h (+8) 
- (modified) clang/lib/Frontend/InitPreprocessor.cpp (-5) 
- (modified) clang/test/Preprocessor/macho-embedded-predefines.c (+15) 


``diff
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index be5dedbe8044e2..f61beb98e0ac0e 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -135,11 +135,15 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   case llvm::Triple::aarch64_32:
 if (Triple.isOSDarwin())
   return std::make_unique(Triple, Opts);
+else if (Triple.isAppleMachO())
+  return std::make_unique(Triple, Opts);
 
 return nullptr;
   case llvm::Triple::aarch64:
 if (Triple.isOSDarwin())
   return std::make_unique(Triple, Opts);
+else if (Triple.isAppleMachO())
+  return std::make_unique(Triple, Opts);
 
 switch (os) {
 case llvm::Triple::FreeBSD:
@@ -243,6 +247,8 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   case llvm::Triple::thumbeb:
 if (Triple.isOSDarwin())
   return std::make_unique(Triple, Opts);
+else if (Triple.isAppleMachO())
+  return std::make_unique(Triple, Opts);
 
 switch (os) {
 case llvm::Triple::Linux:
@@ -531,6 +537,8 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   case llvm::Triple::x86:
 if (Triple.isOSDarwin())
   return std::make_unique(Triple, Opts);
+else if (Triple.isAppleMachO())
+  return std::make_unique(Triple, Opts);
 
 switch (os) {
 case llvm::Triple::Linux: {
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 2b4b954d0c27ad..1bf58661d0efcd 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1671,6 +1671,10 @@ MinGWARM64TargetInfo::MinGWARM64TargetInfo(const 
llvm::Triple &Triple,
   TheCXXABI.set(TargetCXXABI::GenericAArch64);
 }
 
+AppleMachOAArch64TargetInfo::AppleMachOAArch64TargetInfo(
+const llvm::Triple &Triple, const TargetOptions &Opts)
+: AppleMachOTargetInfo(Triple, Opts) {}
+
 DarwinAArch64TargetInfo::DarwinAArch64TargetInfo(const llvm::Triple &Triple,
  const TargetOptions &Opts)
 : DarwinTargetInfo(Triple, Opts) {
@@ -1695,9 +1699,9 @@ DarwinAArch64TargetInfo::DarwinAArch64TargetInfo(const 
llvm::Triple &Triple,
 TheCXXABI.set(TargetCXXABI::AppleARM64);
 }
 
-void DarwinAArch64TargetInfo::getOSDefines(const LangOptions &Opts,
-   const llvm::Triple &Triple,
-   MacroBuilder &Builder) const {
+void clang::targets::getAppleMachOAArch64Defines(MacroBuilder &Builder,
+ const LangOptions &Opts,
+ const llvm::Triple &Triple) {
   Builder.defineMacro("__AARCH64_SIMD__");
   if (Triple.isArch32Bit())
 Builder.defineMacro("__ARM64_ARCH_8_32__");
@@ -1710,7 +1714,20 @@ void DarwinAArch64TargetInfo::getOSDefines(const 
LangOptions &Opts,
 
   if (Triple.isArm64e())
 Builder.defineMacro("__arm64e__", "1");
+}
 
+void AppleMachOAArch64TargetInfo::getOSDefines(const LangOptions &Opts,
+   const llvm::Triple &Triple,
+   MacroBuilder &Builder) const {
+  getAppleMachOAArch64Defines(Builder, Opts, Triple);
+  AppleMachOTargetInfo::getOSDefines(Opts, Triple,
+  Builder);
+}
+
+void DarwinAArch64TargetInfo::getOSDefines(const LangOptions &Opts,
+   const llvm::Triple &Triple,
+   MacroBuilder &Builder) const {
+  getAppleMachOAArch64Defines(Builder, Opts, Triple);
   DarwinTargetInfo::getOSDefines(Opts, Triple, Builder);
 }
 
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 4e927c0953b1fc..9b2acc

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

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

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

>From f98e5113bc83cae2118552466288a874d5e5d63d Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Fri, 18 Oct 2024 10:49:18 -0700
Subject: [PATCH 1/7] [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 468c16050e2bf0..12b96672ce466f 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4793,6 +4793,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 d4e897868f1a9a..e74efd560fd329 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9287,6 +9287,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 ca03fb665d423d..8770c8f4953fce 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19186,6 +19186,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) {
@@ -19505,6 +19522,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] [ubsan] Assert that each check only has one SanitizerKind (PR #122392)

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

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


[clang] [llvm] [Clang] Add __builtin_assume_dereferenceable to encode deref assumption. (PR #121789)

2025-01-09 Thread Johannes Doerfert via cfe-commits


@@ -2761,6 +2761,47 @@ etc.).
 
 Query for this feature with 
``__has_builtin(__builtin_assume_separate_storage)``.
 
+``__builtin_assume_dereferenceable``
+-
+
+``__builtin_assume_dereferenceable`` is used to provide the optimizer with the
+knowledge that the pointer argument P is dereferenceable up to the specified

jdoerfert wrote:

```suggestion
knowledge that the pointer argument P is dereferenceable at least up to the 
specified
```

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


[clang] [llvm] [Clang] Add __builtin_assume_dereferenceable to encode deref assumption. (PR #121789)

2025-01-09 Thread Johannes Doerfert via cfe-commits

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

LG, one suggestion for the docs.

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


[clang] [llvm] [Clang] Add __builtin_assume_dereferenceable to encode deref assumption. (PR #121789)

2025-01-09 Thread Johannes Doerfert via cfe-commits

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


[clang] [ubsan] Assert that each check only has one SanitizerKind (PR #122392)

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

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


[clang] [ubsan] Assert that each check only has one SanitizerKind (PR #122392)

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


@@ -3603,6 +3603,8 @@ void CodeGenFunction::EmitCheck(
   llvm::Value *TrapCond = nullptr;
   bool NoMerge = false;
   for (int i = 0, n = Checked.size(); i < n; ++i) {

vitalybuka wrote:

Maybe instead switch SanitizerMask -> SanitizerOrdinal?

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


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

2025-01-09 Thread Tom Stellard via cfe-commits


@@ -44,7 +44,7 @@ jobs:
 uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # 
v4.1.1
 
   - name: Setup ccache
-uses: hendrikmuhs/ccache-action@v1
+uses: 
hendrikmuhs/ccache-action@ed74d11c0b343532753ecead8a951bb09bb34bc9 # v1.2

tstellar wrote:

The ccache-action changes seem unrelated to the rest of the patch, can you 
split these out into a separate PR.

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


  1   2   3   4   5   6   >