[clang] [llvm] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)

2024-10-25 Thread Ming-Yi Lai via cfe-commits


@@ -607,6 +607,9 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
 auto *Fn = cast(GV);
 
 Fn->addFnAttr("interrupt", Kind);
+
+if (CGM.getCodeGenOpts().CFProtectionReturn)

mylai-mtk wrote:

The early exit above may render this line unreachable for normal functions.

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


[clang] [FlowSensitive] Allow to dump nested RecordStorageLocation (PR #112457)

2024-10-25 Thread via cfe-commits

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


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


[clang] [clang][dataflow] Disambiguate a ref to "internal" in CachedConstAccessorsLattice (PR #113601)

2024-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jan Voung (jvoung)


Changes

Disambiguate to fix a build error (e.g., on windows with clang-cl)


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


1 Files Affected:

- (modified) 
clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h (+4-3) 


``diff
diff --git 
a/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h 
b/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h
index 3402d105746e88..48c5287367739a 100644
--- a/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h
+++ b/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h
@@ -154,11 +154,12 @@ LatticeEffect CachedConstAccessorsLattice::join(
   // are non-identical but equivalent. This is likely to be sufficient in
   // practice, and it reduces implementation complexity considerably.
 
-  ConstMethodReturnValues = internal::joinConstMethodMap(
-  ConstMethodReturnValues, Other.ConstMethodReturnValues, Effect);
+  ConstMethodReturnValues =
+  clang::dataflow::internal::joinConstMethodMap(
+  ConstMethodReturnValues, Other.ConstMethodReturnValues, Effect);
 
   ConstMethodReturnStorageLocations =
-  internal::joinConstMethodMap(
+  clang::dataflow::internal::joinConstMethodMap(
   ConstMethodReturnStorageLocations,
   Other.ConstMethodReturnStorageLocations, Effect);
 

``




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


[clang] [llvm] [AArch64] Add support for Armv9.6-A FEAT_PoPS architecture extension (PR #113496)

2024-10-25 Thread via cfe-commits

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

Thank you for the work @jthackray 

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


[clang] [flang] [flang] Add UNSIGNED (PR #113504)

2024-10-25 Thread Daniel Chen via cfe-commits

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


[clang] [analyzer] Fix a crash from element region construction during `ArrayInitLoopExpr` analysis (PR #113570)

2024-10-25 Thread Donát Nagy via cfe-commits

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

LGTM, thanks for fixing this crash!

I also happy to see that you simplify the logic and clean up the variable 
names. (I was a bit curious about the original reason that led to introduce 
this pattern matching, but I see that you're the original author of this code 
so I presume that you understand its role.)

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


[clang] [analyzer] Fix a crash from element region construction during `ArrayInitLoopExpr` analysis (PR #113570)

2024-10-25 Thread via cfe-commits

llvmbot wrote:




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

Author: None (isuckatcs)


Changes

This patch generalizes the way element regions are constructed when an 
`ArrayInitLoopExpr` is being analyzed. Previously the base region of the 
`ElementRegion` was determined with pattern matching, which led to crashes, 
when an unhandled pattern was encountered.

Fixes #112813

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (+12-57) 
- (modified) clang/test/Analysis/array-init-loop.cpp (+38) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
index c50db1e0e2f863..6ddb9b44ddcf91 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -513,70 +513,25 @@ ProgramStateRef 
ExprEngine::updateObjectsUnderConstruction(
 static ProgramStateRef
 bindRequiredArrayElementToEnvironment(ProgramStateRef State,
   const ArrayInitLoopExpr *AILE,
-  const LocationContext *LCtx, SVal Idx) {
-  // The ctor in this case is guaranteed to be a copy ctor, otherwise we hit a
-  // compile time error.
-  //
-  //  -ArrayInitLoopExpr<-- we're here
-  //   |-OpaqueValueExpr
-  //   | `-DeclRefExpr  <-- match this
-  //   `-CXXConstructExpr
-  // `-ImplicitCastExpr
-  //   `-ArraySubscriptExpr
-  // |-ImplicitCastExpr
-  // | `-OpaqueValueExpr
-  // |   `-DeclRefExpr
-  // `-ArrayInitIndexExpr
-  //
-  // The resulting expression might look like the one below in an implicit
-  // copy/move ctor.
-  //
-  //   ArrayInitLoopExpr<-- we're here
-  //   |-OpaqueValueExpr
-  //   | `-MemberExpr   <-- match this
-  //   |  (`-CXXStaticCastExpr) <-- move ctor only
-  //   | `-DeclRefExpr
-  //   `-CXXConstructExpr
-  // `-ArraySubscriptExpr
-  //   |-ImplicitCastExpr
-  //   | `-OpaqueValueExpr
-  //   |   `-MemberExpr
-  //   | `-DeclRefExpr
-  //   `-ArrayInitIndexExpr
-  //
-  // The resulting expression for a multidimensional array.
-  // ArrayInitLoopExpr  <-- we're here
-  // |-OpaqueValueExpr
-  // | `-DeclRefExpr<-- match this
-  // `-ArrayInitLoopExpr
-  //   |-OpaqueValueExpr
-  //   | `-ArraySubscriptExpr
-  //   |   |-ImplicitCastExpr
-  //   |   | `-OpaqueValueExpr
-  //   |   |   `-DeclRefExpr
-  //   |   `-ArrayInitIndexExpr
-  //   `-CXXConstructExpr <-- extract this
-  // ` ...
-
-  const auto *OVESrc = AILE->getCommonExpr()->getSourceExpr();
+  const LocationContext *LCtx, NonLoc Idx) 
{
+  SValBuilder &SVB = State->getStateManager().getSValBuilder();
+  MemRegionManager &MRMgr = SVB.getRegionManager();
+  ASTContext &Ctx = SVB.getContext();
 
   // HACK: There is no way we can put the index of the array element into the
   // CFG unless we unroll the loop, so we manually select and bind the required
   // parameter to the environment.
-  const auto *CE =
+  const Expr *SourceArray = AILE->getCommonExpr()->getSourceExpr();
+  const auto *Ctor =
   cast(extractElementInitializerFromNestedAILE(AILE));
 
-  SVal Base = UnknownVal();
-  if (const auto *ME = dyn_cast(OVESrc))
-Base = State->getSVal(ME, LCtx);
-  else if (const auto *DRE = dyn_cast(OVESrc))
-Base = State->getLValue(cast(DRE->getDecl()), LCtx);
-  else
-llvm_unreachable("ArrayInitLoopExpr contains unexpected source 
expression");
-
-  SVal NthElem = State->getLValue(CE->getType(), Idx, Base);
+  const SubRegion *SourceArrayRegion =
+  cast(State->getSVal(SourceArray, LCtx).getAsRegion());
+  const ElementRegion *ElementRegion =
+  MRMgr.getElementRegion(Ctor->getType(), Idx, SourceArrayRegion, Ctx);
 
-  return State->BindExpr(CE->getArg(0), LCtx, NthElem);
+  return State->BindExpr(Ctor->getArg(0), LCtx,
+ loc::MemRegionVal(ElementRegion));
 }
 
 void ExprEngine::handleConstructor(const Expr *E,
diff --git a/clang/test/Analysis/array-init-loop.cpp 
b/clang/test/Analysis/array-init-loop.cpp
index 4ab4489fc882f3..64b0aec1daf9d2 100644
--- a/clang/test/Analysis/array-init-loop.cpp
+++ b/clang/test/Analysis/array-init-loop.cpp
@@ -330,3 +330,41 @@ void no_crash() {
 }
 
 } // namespace crash
+
+namespace array_subscript_initializer {
+
+struct S
+{
+  int x;
+};
+
+void no_crash() {
+  S arr[][2] = {{1, 2}};
+
+  const auto [a, b] = arr[0];
+
+  clang_analyzer_eval(a.x == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(b.x == 2); // expected-warning{{TRUE}}
+}
+
+} // namespace array_subscript_initializer
+
+namespace iterator_initializer {
+
+struct S
+{
+  int x;
+};
+
+void no_crash() {
+  S arr[][2] = {{1, 2}, {3, 4}};
+
+  int i = 0;
+  for (const auto [a, b] : arr) {

[clang] [Clang][AArch64] Fix Pure Scalables Types argument passing and return (PR #112747)

2024-10-25 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov updated 
https://github.com/llvm/llvm-project/pull/112747

>From 8a29c58a9034bd9123a26448607e751ee9a6d658 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Thu, 17 Oct 2024 14:04:05 +0100
Subject: [PATCH 1/6] [Clang][AArch64] Fix Pure Scalables Types argument
 passing and return

Pure Scalable Types are defined in AAPCS64 here:
  
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#pure-scalable-types-psts

And should be passed according to Rule C.7 here:
  
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#682parameter-passing-rules

This part of the ABI is completely unimplemented in Clang, instead
it treats PSTs sometimes as HFAs/HVAs, sometime as general composite
types.

This patch implements the rules for passing PSTs by employing the
`CoerceAndExpand` method and extending it to:
  * allow array types in the `coerceToType`; Now only `[N x i8]` are
considered padding.
  * allow mismatch between the elements of the `coerceToType` and the
elements of the `unpaddedCoerceToType`; AArch64 uses this to map
fixed-length vector types to SVE vector types.

Corectly passing a PST argument needs a decision in Clang about
whether to pass it in memory or registers or, equivalently, whether
to use the `Indirect` or `Expand/CoerceAndExpand` method.
It was considered relatively harder (or not practically possible)
to make that decision in the AArch64 backend.
Hence this patch implements the register counting
from AAPCS64 (cf. "NSRN", "NPRN") to guide the Clang's decision.
---
 clang/include/clang/CodeGen/CGFunctionInfo.h  |  13 +-
 clang/lib/CodeGen/CGCall.cpp  |  85 +++--
 clang/lib/CodeGen/Targets/AArch64.cpp | 326 --
 .../test/CodeGen/aarch64-pure-scalable-args.c | 314 +
 4 files changed, 669 insertions(+), 69 deletions(-)
 create mode 100644 clang/test/CodeGen/aarch64-pure-scalable-args.c

diff --git a/clang/include/clang/CodeGen/CGFunctionInfo.h 
b/clang/include/clang/CodeGen/CGFunctionInfo.h
index d19f84d198876f..915f676d7d3905 100644
--- a/clang/include/clang/CodeGen/CGFunctionInfo.h
+++ b/clang/include/clang/CodeGen/CGFunctionInfo.h
@@ -272,11 +272,6 @@ class ABIArgInfo {
 unsigned unpaddedIndex = 0;
 for (auto eltType : coerceToType->elements()) {
   if (isPaddingForCoerceAndExpand(eltType)) continue;
-  if (unpaddedStruct) {
-assert(unpaddedStruct->getElementType(unpaddedIndex) == eltType);
-  } else {
-assert(unpaddedIndex == 0 && unpaddedCoerceToType == eltType);
-  }
   unpaddedIndex++;
 }
 
@@ -295,12 +290,8 @@ class ABIArgInfo {
   }
 
   static bool isPaddingForCoerceAndExpand(llvm::Type *eltType) {
-if (eltType->isArrayTy()) {
-  assert(eltType->getArrayElementType()->isIntegerTy(8));
-  return true;
-} else {
-  return false;
-}
+return eltType->isArrayTy() &&
+   eltType->getArrayElementType()->isIntegerTy(8);
   }
 
   Kind getKind() const { return TheKind; }
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 5f50ab6f34ff8d..6fc6ff4b7535ec 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1410,6 +1410,30 @@ static Address emitAddressAtOffset(CodeGenFunction &CGF, 
Address addr,
   return addr;
 }
 
+static std::pair
+CoerceScalableToFixed(CodeGenFunction &CGF, llvm::FixedVectorType *ToTy,
+  llvm::ScalableVectorType *FromTy, llvm::Value *V,
+  StringRef Name = "") {
+  // If we are casting a scalable i1 predicate vector to a fixed i8
+  // vector, first bitcast the source.
+  if (FromTy->getElementType()->isIntegerTy(1) &&
+  FromTy->getElementCount().isKnownMultipleOf(8) &&
+  ToTy->getElementType() == CGF.Builder.getInt8Ty()) {
+FromTy = llvm::ScalableVectorType::get(
+ToTy->getElementType(),
+FromTy->getElementCount().getKnownMinValue() / 8);
+V = CGF.Builder.CreateBitCast(V, FromTy);
+  }
+  if (FromTy->getElementType() == ToTy->getElementType()) {
+llvm::Value *Zero = llvm::Constant::getNullValue(CGF.CGM.Int64Ty);
+
+V->setName(Name + ".coerce");
+V = CGF.Builder.CreateExtractVector(ToTy, V, Zero, "cast.fixed");
+return {V, true};
+  }
+  return {V, false};
+}
+
 namespace {
 
 /// Encapsulates information about the way function arguments from
@@ -3196,26 +3220,14 @@ void CodeGenFunction::EmitFunctionProlog(const 
CGFunctionInfo &FI,
   // a VLAT at the function boundary and the types match up, use
   // llvm.vector.extract to convert back to the original VLST.
   if (auto *VecTyTo = dyn_cast(ConvertType(Ty))) {
-llvm::Value *Coerced = Fn->getArg(FirstIRArg);
+llvm::Value *ArgVal = Fn->getArg(FirstIRArg);
 if (auto *VecTyFrom =
-dyn_cast(Coerced->getType())) {
-  // If we are casting a scalable i1 predicate vector to a fixed i8
-  // vector, bitcast the sour

[clang] [Clang]: enhance handling of [[deprecated]] attribute diagnostics for local variables (PR #113575)

2024-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #90073

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaAvailability.cpp (+6) 
- (modified) clang/test/SemaCXX/deprecated.cpp (+14) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 28bb83a1c9d60f..89c97d4b6631f2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -424,6 +424,8 @@ Improvements to Clang's diagnostics
   name was a reserved name, which we improperly allowed to suppress the
   diagnostic.
 
+- Clang now diagnoses [[deprecated]] attribute usage on local variables 
(#GH90073).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaAvailability.cpp 
b/clang/lib/Sema/SemaAvailability.cpp
index 798cabaa31a476..d62b3eb1a480e7 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -182,6 +182,12 @@ static bool ShouldDiagnoseAvailabilityInContext(
   return false;
   }
 
+  if (K == AR_Deprecated) {
+if (const auto *VD = dyn_cast(OffendingDecl))
+  if (VD->isLocalVarDecl() && VD->isDeprecated())
+return true;
+  }
+
   // Checks if we should emit the availability diagnostic in the context of C.
   auto CheckContext = [&](const Decl *C) {
 if (K == AR_NotYetIntroduced) {
diff --git a/clang/test/SemaCXX/deprecated.cpp 
b/clang/test/SemaCXX/deprecated.cpp
index a93331023f7e21..02fdf0bec5c088 100644
--- a/clang/test/SemaCXX/deprecated.cpp
+++ b/clang/test/SemaCXX/deprecated.cpp
@@ -260,5 +260,19 @@ namespace ArrayComp {
   bool b7 = arr1 == +f();
 }
 
+namespace GH90073 {
+[[deprecated]] int f() { // expected-note {{'f' has been explicitly marked 
deprecated here}}
+  [[deprecated]] int a;  // expected-note {{'a' has been explicitly marked 
deprecated here}} \
+ // expected-note {{'a' has been explicitly marked 
deprecated here}}
+  a = 0;// expected-warning {{'a' is deprecated}}
+  return a; // expected-warning {{'a' is deprecated}}
+}
+
+int main() {
+  f(); // expected-warning {{'f' is deprecated}}
+  return 0;
+}
+}
+
 # 1 "/usr/include/system-header.h" 1 3
 void system_header_function(void) throw();

``




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


[clang] [Clang][AST] Store injected template arguments in TemplateParameterList (PR #113579)

2024-10-25 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian created 
https://github.com/llvm/llvm-project/pull/113579

Currently, we store injected template arguments in 
`RedeclarableTemplateDecl::CommonBase`. This approach has a couple problems:
1. We can only access the injected template arguments of 
`RedeclarableTemplateDecl` derived types, but other `Decl` kinds still make use 
of the injected arguments (e.g. `ClassTemplatePartialSpecializationDecl`, 
`VarTemplatePartialSpecializationDecl`, and `TemplateTemplateParmDecl`).
2. Accessing the injected template arguments requires the common data structure 
to be allocated. This may occur before we determine whether a previous 
declaration exists (e.g. when comparing constraints), so if the template _is_ a 
redeclaration, we end up discarding the common data structure. 

This patch moves the storage and access of injected template arguments from 
`RedeclarableTemplateDecl` to `TemplateParameterList`.

>From 69f9da551992f565ca8d839aa499aed278df55a8 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Tue, 15 Oct 2024 11:15:55 -0400
Subject: [PATCH] [Clang][AST] Store injected template arguments in
 TemplateParameterList

---
 clang/include/clang/AST/ASTContext.h | 12 ++---
 clang/include/clang/AST/DeclTemplate.h   | 41 +++-
 clang/lib/AST/ASTContext.cpp | 15 ++
 clang/lib/AST/DeclTemplate.cpp   | 62 +---
 clang/lib/Sema/SemaTemplateDeduction.cpp |  9 ++--
 5 files changed, 39 insertions(+), 100 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a4d36f2eacd5d1..07b4e36f3ef05e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -239,7 +239,7 @@ class ASTContext : public RefCountedBase {
   mutable llvm::ContextualFoldingSet
 DependentTemplateSpecializationTypes;
-  llvm::FoldingSet PackExpansionTypes;
+  mutable llvm::FoldingSet PackExpansionTypes;
   mutable llvm::FoldingSet ObjCObjectTypes;
   mutable llvm::FoldingSet ObjCObjectPointerTypes;
   mutable llvm::FoldingSet
@@ -1778,13 +1778,7 @@ class ASTContext : public RefCountedBase {
   ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
   const IdentifierInfo *Name, ArrayRef Args) const;
 
-  TemplateArgument getInjectedTemplateArg(NamedDecl *ParamDecl);
-
-  /// Get a template argument list with one argument per template parameter
-  /// in a template parameter list, such as for the injected class name of
-  /// a class template.
-  void getInjectedTemplateArgs(const TemplateParameterList *Params,
-   SmallVectorImpl &Args);
+  TemplateArgument getInjectedTemplateArg(NamedDecl *ParamDecl) const;
 
   /// Form a pack expansion type with the given pattern.
   /// \param NumExpansions The number of expansions for the pack, if known.
@@ -1795,7 +1789,7 @@ class ASTContext : public RefCountedBase {
   ///if this is the canonical type of another pack expansion type.
   QualType getPackExpansionType(QualType Pattern,
 std::optional NumExpansions,
-bool ExpectPackInType = true);
+bool ExpectPackInType = true) const;
 
   QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
 ObjCInterfaceDecl *PrevDecl = nullptr) const;
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 0f0c0bf6e4ef4f..2d2102d3280ba0 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -71,6 +71,9 @@ NamedDecl *getAsNamedDecl(TemplateParameter P);
 class TemplateParameterList final
 : private llvm::TrailingObjects {
+  /// The template argument list of the template parameter list.
+  llvm::PointerUnion InjectedArgs;
+
   /// The location of the 'template' keyword.
   SourceLocation TemplateLoc;
 
@@ -196,6 +199,9 @@ class TemplateParameterList final
 
   bool hasAssociatedConstraints() const;
 
+  /// Get the template argument lisr of the template parameter list.
+  ArrayRef getInjectedTemplateArgs();
+
   SourceLocation getTemplateLoc() const { return TemplateLoc; }
   SourceLocation getLAngleLoc() const { return LAngleLoc; }
   SourceLocation getRAngleLoc() const { return RAngleLoc; }
@@ -793,15 +799,6 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 /// The first value in the array is the number of specializations/partial
 /// specializations that follow.
 GlobalDeclID *LazySpecializations = nullptr;
-
-/// The set of "injected" template arguments used within this
-/// template.
-///
-/// This pointer refers to the template arguments (there are as
-/// many template arguments as template parameters) for the
-/// template, and is allocated lazily, since most templates do not
-/// require the use of this information.
-TemplateArgument *InjectedArgs = nullptr;
   };
 
   //

[clang] [clang] Use {} instead of std::nullopt to initialize empty ArrayRef (PR #109399)

2024-10-25 Thread Jay Foad via cfe-commits

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


[clang] [clang-format] clang-format-ignore: Add support for double asterisk patterns (PR #110560)

2024-10-25 Thread Björn Schäpers via cfe-commits


@@ -49,11 +49,29 @@ bool matchFilePath(StringRef Pattern, StringRef FilePath) {
 return false;
   break;
 case '*': {
-  while (++I < EOP && Pattern[I] == '*') { // Skip consecutive stars.
+  if (I + 1 < EOP && Pattern[I + 1] == '*') {
+// Handle '**' pattern
+while (++I < EOP && Pattern[I] == '*') { // Skip consecutive stars.

HazardyKnusperkeks wrote:

Sounds like a `find_if`.

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


[clang] [llvm] [ci] New script to generate test reports as Buildkite Annotations (PR #113447)

2024-10-25 Thread Aiden Grossman via cfe-commits

boomanaiden154 wrote:

> True, however for libc++ the benefits are smaller because we run only libc++ 
> specific job in the BuildKite job. I've never had trouble with figuring out 
> what part of a job has caused failures. Either way, like I said I'm fine with 
> the patch, it seems like an improvement.

Ah, okay. That would make sense.

> No, but someone has to remember and actually take the time to do the cleanup. 
> I also 100% support the removal of unused options and I've done things like 
> that in the past, but it doesn't happen unless someone decides to make it 
> their task.

That's true. It is definitely tech debt when things like that are suddenly not 
used, but it is theoretically not too difficult to pull out at that point.

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


[clang] [clang] Output an error when [[lifetimebound]] attribute is applied on a function parameter while the function returns void (PR #113460)

2024-10-25 Thread Boaz Brickner via cfe-commits

https://github.com/bricknerb updated 
https://github.com/llvm/llvm-project/pull/113460

>From 4405d652029081cd63094e9a81dfa31e8611aad4 Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Wed, 23 Oct 2024 15:50:43 +0200
Subject: [PATCH 1/4] [clang] Output a warning when [[lifetimebound]] attribute
 is applied on a function parameter while the function returns void.

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Sema/SemaDecl.cpp  | 14 +-
 clang/test/SemaCXX/attr-lifetimebound.cpp|  3 +--
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8e4718008ece72..a1c20b22e736ed 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10097,6 +10097,9 @@ def err_lifetimebound_no_object_param : Error<
 def err_lifetimebound_ctor_dtor : Error<
   "'lifetimebound' attribute cannot be applied to a "
   "%select{constructor|destructor}0">;
+def err_lifetimebound_void_return_type : Error<
+  "'lifetimebound' attribute cannot be applied to a parameter of a function "
+  "that returns void; did you mean 'lifetime_capture_by(X)'">;
 
 // CHECK: returning address/reference of stack memory
 def warn_ret_stack_addr_ref : Warning<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 229c9080d558ec..e611bf60718bc5 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6940,7 +6940,7 @@ static void checkAttributesAfterMerging(Sema &S, 
NamedDecl &ND) {
 }
   }
 
-  // Check the attributes on the function type, if any.
+  // Check the attributes on the function type and function params, if any.
   if (const auto *FD = dyn_cast(&ND)) {
 // Don't declare this variable in the second operand of the for-statement;
 // GCC miscompiles that by ending its lifetime before evaluating the
@@ -6970,6 +6970,18 @@ static void checkAttributesAfterMerging(Sema &S, 
NamedDecl &ND) {
 }
   }
 }
+
+for (unsigned int I = 0; I < FD->getNumParams(); ++I) {
+  const ParmVarDecl *P = FD->getParamDecl(I);
+
+  // The [[lifetimebound]] attribute can be applied to a function parameter
+  // only if the function returns a value.
+  if (auto *A = P->getAttr()) {
+if (!isa(FD) && FD->getReturnType()->isVoidType()) 
{
+  S.Diag(A->getLocation(), diag::err_lifetimebound_void_return_type);
+}
+  }
+}
   }
 }
 
diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index 1c5c79777c71c8..f790559b6b4769 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -1,8 +1,7 @@
 // RUN: %clang_cc1 -std=c++23 -verify %s
 
 namespace usage_invalid {
-  // FIXME: Should we diagnose a void return type?
-  void voidreturn(int ¶m [[clang::lifetimebound]]);
+  void voidreturn(int ¶m [[clang::lifetimebound]]); // expected-error 
{{'lifetimebound' attribute cannot be applied to a parameter of a function that 
returns void; did you mean 'lifetime_capture_by(X)'}}
 
   int *not_class_member() [[clang::lifetimebound]]; // expected-error 
{{non-member function has no implicit object parameter}}
   struct A {

>From 0a9a8629f5d188b1c1d648dc83438c33c14cc8cc Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Thu, 24 Oct 2024 09:55:01 +0200
Subject: [PATCH 2/4] [clang] Add a test for lifetimebound on a parameter when
 the return type is dependent on template argument but actually void.

---
 clang/test/SemaCXX/attr-lifetimebound.cpp | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index f790559b6b4769..33cce02936dda1 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -30,6 +30,11 @@ namespace usage_ok {
 return *(int*)param;
   }
 
+  template  R dependent_void(const T& t 
[[clang::lifetimebound]]);
+  void dependent_void_instantiation() {
+dependent_void(1);
+  }
+
   struct A {
 A();
 A(int);

>From aab99080ba2b6d990d3b56f78ffec0ea2aaea948 Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Thu, 24 Oct 2024 10:13:14 +0200
Subject: [PATCH 3/4] [clang] Test a member method marked with lifetimebound
 that returns a void. This should diagnose but currently isn't. Added a FIXME
 comment.

---
 clang/test/SemaCXX/attr-lifetimebound.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index 33cce02936dda1..a0005ec1ccf4b4 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -std=c++23 -verify %s
 
 namespace usage_invalid {
-  void voidreturn(int ¶m [[clang::lifetimebound]]);

[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-25 Thread Tex Riddell via cfe-commits


@@ -95,6 +99,133 @@ static void initializeAlloca(CodeGenFunction &CGF, 
AllocaInst *AI, Value *Size,
   I->addAnnotationMetadata("auto-init");
 }
 
+static Value *handleHlslSplitdouble(const CallExpr *E, CodeGenFunction *CGF) {
+  Value *Op0 = CGF->EmitScalarExpr(E->getArg(0));
+  const auto *OutArg1 = dyn_cast(E->getArg(1));
+  const auto *OutArg2 = dyn_cast(E->getArg(2));
+
+  CallArgList Args;
+  LValue Op1TmpLValue =
+  CGF->EmitHLSLOutArgExpr(OutArg1, Args, OutArg1->getType());
+  LValue Op2TmpLValue =
+  CGF->EmitHLSLOutArgExpr(OutArg2, Args, OutArg2->getType());
+
+  if (CGF->getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee())
+Args.reverseWritebacks();
+
+  auto EmitVectorCode =
+  [](Value *Op, CGBuilderTy *Builder,
+ FixedVectorType *DestTy) -> std::pair {
+Value *bitcast = Builder->CreateBitCast(Op, DestTy);
+
+SmallVector LowbitsIndex;
+SmallVector HighbitsIndex;
+
+for (unsigned int Idx = 0; Idx < DestTy->getNumElements(); Idx += 2) {
+  LowbitsIndex.push_back(Idx);
+  HighbitsIndex.push_back(Idx + 1);
+}
+
+Value *Arg0 = Builder->CreateShuffleVector(bitcast, LowbitsIndex);
+Value *Arg1 = Builder->CreateShuffleVector(bitcast, HighbitsIndex);
+
+return std::make_pair(Arg0, Arg1);
+  };

tex3d wrote:

Though you might want to skip this simplification if a generalized version of 
this is used to handle any size vectors with constraints being applied later 
for SPIR-V.

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


[clang] [clang][analyzer][doc] Update Clang SA www docs index.html (PR #112833)

2024-10-25 Thread Donát Nagy via cfe-commits

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


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


[clang] [libcxx] [clang] Warn about memset/memcpy to NonTriviallyCopyable types (PR #111434)

2024-10-25 Thread via cfe-commits


@@ -638,7 +638,7 @@ __uninitialized_allocator_relocate(_Alloc& __alloc, _Tp* 
__first, _Tp* __last, _
 __guard.__complete();
 std::__allocator_destroy(__alloc, __first, __last);
   } else {
-__builtin_memcpy(__result, __first, sizeof(_Tp) * (__last - __first));
+__builtin_memcpy((void*)__result, __first, sizeof(_Tp) * (__last - 
__first));

serge-sans-paille wrote:

done!

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


[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)

2024-10-25 Thread Owen Pan via cfe-commits

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


[clang] [clang] Output an error when [[lifetimebound]] attribute is applied on a function parameter while the function returns void (PR #113460)

2024-10-25 Thread Boaz Brickner via cfe-commits

https://github.com/bricknerb updated 
https://github.com/llvm/llvm-project/pull/113460

>From 4405d652029081cd63094e9a81dfa31e8611aad4 Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Wed, 23 Oct 2024 15:50:43 +0200
Subject: [PATCH 1/5] [clang] Output a warning when [[lifetimebound]] attribute
 is applied on a function parameter while the function returns void.

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  3 +++
 clang/lib/Sema/SemaDecl.cpp  | 14 +-
 clang/test/SemaCXX/attr-lifetimebound.cpp|  3 +--
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8e4718008ece72..a1c20b22e736ed 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10097,6 +10097,9 @@ def err_lifetimebound_no_object_param : Error<
 def err_lifetimebound_ctor_dtor : Error<
   "'lifetimebound' attribute cannot be applied to a "
   "%select{constructor|destructor}0">;
+def err_lifetimebound_void_return_type : Error<
+  "'lifetimebound' attribute cannot be applied to a parameter of a function "
+  "that returns void; did you mean 'lifetime_capture_by(X)'">;
 
 // CHECK: returning address/reference of stack memory
 def warn_ret_stack_addr_ref : Warning<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 229c9080d558ec..e611bf60718bc5 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6940,7 +6940,7 @@ static void checkAttributesAfterMerging(Sema &S, 
NamedDecl &ND) {
 }
   }
 
-  // Check the attributes on the function type, if any.
+  // Check the attributes on the function type and function params, if any.
   if (const auto *FD = dyn_cast(&ND)) {
 // Don't declare this variable in the second operand of the for-statement;
 // GCC miscompiles that by ending its lifetime before evaluating the
@@ -6970,6 +6970,18 @@ static void checkAttributesAfterMerging(Sema &S, 
NamedDecl &ND) {
 }
   }
 }
+
+for (unsigned int I = 0; I < FD->getNumParams(); ++I) {
+  const ParmVarDecl *P = FD->getParamDecl(I);
+
+  // The [[lifetimebound]] attribute can be applied to a function parameter
+  // only if the function returns a value.
+  if (auto *A = P->getAttr()) {
+if (!isa(FD) && FD->getReturnType()->isVoidType()) 
{
+  S.Diag(A->getLocation(), diag::err_lifetimebound_void_return_type);
+}
+  }
+}
   }
 }
 
diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index 1c5c79777c71c8..f790559b6b4769 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -1,8 +1,7 @@
 // RUN: %clang_cc1 -std=c++23 -verify %s
 
 namespace usage_invalid {
-  // FIXME: Should we diagnose a void return type?
-  void voidreturn(int ¶m [[clang::lifetimebound]]);
+  void voidreturn(int ¶m [[clang::lifetimebound]]); // expected-error 
{{'lifetimebound' attribute cannot be applied to a parameter of a function that 
returns void; did you mean 'lifetime_capture_by(X)'}}
 
   int *not_class_member() [[clang::lifetimebound]]; // expected-error 
{{non-member function has no implicit object parameter}}
   struct A {

>From 0a9a8629f5d188b1c1d648dc83438c33c14cc8cc Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Thu, 24 Oct 2024 09:55:01 +0200
Subject: [PATCH 2/5] [clang] Add a test for lifetimebound on a parameter when
 the return type is dependent on template argument but actually void.

---
 clang/test/SemaCXX/attr-lifetimebound.cpp | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index f790559b6b4769..33cce02936dda1 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -30,6 +30,11 @@ namespace usage_ok {
 return *(int*)param;
   }
 
+  template  R dependent_void(const T& t 
[[clang::lifetimebound]]);
+  void dependent_void_instantiation() {
+dependent_void(1);
+  }
+
   struct A {
 A();
 A(int);

>From aab99080ba2b6d990d3b56f78ffec0ea2aaea948 Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Thu, 24 Oct 2024 10:13:14 +0200
Subject: [PATCH 3/5] [clang] Test a member method marked with lifetimebound
 that returns a void. This should diagnose but currently isn't. Added a FIXME
 comment.

---
 clang/test/SemaCXX/attr-lifetimebound.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index 33cce02936dda1..a0005ec1ccf4b4 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -std=c++23 -verify %s
 
 namespace usage_invalid {
-  void voidreturn(int ¶m [[clang::lifetimebound]]);

[clang] [analyzer] Untangle subcheckers of CStringChecker (PR #113312)

2024-10-25 Thread Balazs Benics via cfe-commits


@@ -702,9 +702,17 @@ ProgramStateRef 
CStringChecker::CheckOverlap(CheckerContext &C,
   state->assume(svalBuilder.evalEQ(state, *firstLoc, *secondLoc));
 
   if (stateTrue && !stateFalse) {
-// If the values are known to be equal, that's automatically an overlap.
-emitOverlapBug(C, stateTrue, First.Expression, Second.Expression);
-return nullptr;
+if (Filter.CheckCStringBufferOverlap) {
+  // If the values are known to be equal, that's automatically an overlap.
+  emitOverlapBug(C, stateTrue, First.Expression, Second.Expression);
+  return nullptr;
+}
+// FIXME: We detected a fatal error here, we should stop analysis even if 
we
+// chose not to emit a report here. However, as long as our overlap checker
+// is in alpha, lets just pretend nothing happened.
+//C.addSink();

steakhal wrote:

Same about commented code.

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


[clang] [llvm] [RISCV] Add Smdbltrp and Ssdbltrp extension (PR #111837)

2024-10-25 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

@T-Tie 
Can you fill in the PR description? Then I will merge this patch :)


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


[clang] ed6ddff - [RISCV] Add Smrnmi extension (#111668)

2024-10-25 Thread via cfe-commits

Author: dong-miao
Date: 2024-10-25T18:41:21+11:00
New Revision: ed6ddffb583beb450c4b0e1747ccd14f7e063105

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

LOG: [RISCV] Add Smrnmi extension (#111668)

This commit has completed the Extension for Resumable Non Maskable
Interrupts, adding four CRSs and one Trap-Return instruction.
Specification link:["Smrnmi"
Extension](https://github.com/riscv/riscv-isa-manual/blob/main/src/rnmi.adoc)

-

Co-authored-by: Sam Elliott 

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

Modified: 
clang/test/Driver/print-supported-extensions-riscv.c
clang/test/Preprocessor/riscv-target-features.c
llvm/docs/RISCVUsage.rst
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s
llvm/test/MC/RISCV/machine-csr-names.s
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index a39c1ab36b1db0..65375b79cb680d 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -120,6 +120,7 @@
 // CHECK-NEXT: smcdeleg 1.0   'Smcdeleg' (Counter 
Delegation Machine Level)
 // CHECK-NEXT: smcsrind 1.0   'Smcsrind' (Indirect CSR 
Access Machine Level)
 // CHECK-NEXT: smepmp   1.0   'Smepmp' (Enhanced Physical 
Memory Protection)
+// CHECK-NEXT: smrnmi   1.0   'Smrnmi' (Resumable 
Non-Maskable Interrupts)
 // CHECK-NEXT: smstateen1.0   'Smstateen' (Machine-mode 
view of the state-enable extension)
 // CHECK-NEXT: ssaia1.0   'Ssaia' (Advanced Interrupt 
Architecture Supervisor Level)
 // CHECK-NEXT: ssccfg   1.0   'Ssccfg' (Counter 
Configuration Supervisor Level)

diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 05a8534ba13da1..9e986f0143aefa 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -30,6 +30,7 @@
 // CHECK-NOT: __riscv_smcdeleg {{.*$}}
 // CHECK-NOT: __riscv_smcsrind {{.*$}}
 // CHECK-NOT: __riscv_smepmp {{.*$}}
+// CHECK-NOT: __riscv_smrnmi {{.*$}}
 // CHECK-NOT: __riscv_smstateen {{.*$}}
 // CHECK-NOT: __riscv_ssaia {{.*$}}
 // CHECK-NOT: __riscv_ssccfg {{.*$}}
@@ -1449,6 +1450,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SMEPMP-EXT %s
 // CHECK-SMEPMP-EXT: __riscv_smepmp  100{{$}}
 
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32ismrnmi1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SMRNMI-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64ismrnmi1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SMRNMI-EXT %s
+// CHECK-SMRNMI-EXT: __riscv_smrnmi  100{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32izfa -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 5736f3807f131b..2135ed3b111418 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -129,6 +129,7 @@ on support follow.
  ``Smcdeleg``  Supported
  ``Smcsrind``  Supported
  ``Smepmp``Supported
+ ``Smrnmi``Assembly Support
  ``Smstateen`` Assembly Support
  ``Ssaia`` Supported
  ``Ssccfg``Supported

diff  --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 3d0e1dae801d39..7ccce2e1c70b22 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -931,6 +931,13 @@ def FeatureStdExtSmepmp
 : RISCVExtension<"smepmp", 1, 0,
  "'Smepmp' (Enhanced Physical Memory Protection)">;
 
+def FeatureStdExtSmrnmi
+: RISCVExtension<"smrnmi", 1, 0,
+ "'Smrnmi' (Resumable Non-Maskable Interrupts)">;
+def HasStdExtSmrnmi : Predicate<"Subtarget->hasStdExtSmrnmi()">,
+   AssemblerPredicate<(all_of FeatureStdExtSmrnmi),
+   "'Smrnmi' (Resumable Non-Maskable Interrupts)">; 
+
 def FeatureStdExtSmcdeleg
 : RISCVExtension<"smcdeleg", 1, 0,
  "'Smcdeleg' (Counter Delegation Machine Level)">;

diff  --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td 
b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
index 5d329dceac6519..86cc638fd04ac2 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVInst

[clang] b89f09f - [Clang] Enhance handling of [[deprecated]] attribute diagnostics for local variables (#113575)

2024-10-25 Thread via cfe-commits

Author: Oleksandr T.
Date: 2024-10-25T09:40:44+02:00
New Revision: b89f09f5cc072b927917844a5781be3600acb72a

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

LOG: [Clang] Enhance handling of [[deprecated]] attribute diagnostics for local 
variables (#113575)

Fixes #90073

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaAvailability.cpp
clang/test/SemaCXX/deprecated.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d7b47cd2e2ee26..ed0c0e369fca74 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -424,6 +424,8 @@ Improvements to Clang's diagnostics
   name was a reserved name, which we improperly allowed to suppress the
   diagnostic.
 
+- Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/lib/Sema/SemaAvailability.cpp 
b/clang/lib/Sema/SemaAvailability.cpp
index 798cabaa31a476..076d3489fa9438 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -182,6 +182,12 @@ static bool ShouldDiagnoseAvailabilityInContext(
   return false;
   }
 
+  if (K == AR_Deprecated) {
+if (const auto *VD = dyn_cast(OffendingDecl))
+  if (VD->isLocalVarDeclOrParm() && VD->isDeprecated())
+return true;
+  }
+
   // Checks if we should emit the availability diagnostic in the context of C.
   auto CheckContext = [&](const Decl *C) {
 if (K == AR_NotYetIntroduced) {

diff  --git a/clang/test/SemaCXX/deprecated.cpp 
b/clang/test/SemaCXX/deprecated.cpp
index a93331023f7e21..667f4d7d3edb03 100644
--- a/clang/test/SemaCXX/deprecated.cpp
+++ b/clang/test/SemaCXX/deprecated.cpp
@@ -260,5 +260,25 @@ namespace ArrayComp {
   bool b7 = arr1 == +f();
 }
 
+namespace GH90073 {
+[[deprecated]] int f1() { // expected-note {{'f1' has been explicitly marked 
deprecated here}}
+  [[deprecated]] int a;  // expected-note {{'a' has been explicitly marked 
deprecated here}} \
+ // expected-note {{'a' has been explicitly marked 
deprecated here}}
+  a = 0;// expected-warning {{'a' is deprecated}}
+  return a; // expected-warning {{'a' is deprecated}}
+}
+
+[[deprecated]] void f2([[deprecated]] int x) { // expected-note {{'f2' has 
been explicitly marked deprecated here}} \
+   // expected-note {{'x' has been 
explicitly marked deprecated here}}
+  x = 4; // expected-warning {{'x' is deprecated}}
+}
+
+int main() {
+  f1();  // expected-warning {{'f1' is deprecated}}
+  f2(1); // expected-warning {{'f2' is deprecated}}
+  return 0;
+}
+}
+
 # 1 "/usr/include/system-header.h" 1 3
 void system_header_function(void) throw();



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


[clang] [Clang]: enhance handling of [[deprecated]] attribute diagnostics for local variables (PR #113575)

2024-10-25 Thread via cfe-commits

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


[clang] [llvm] [RISCV] Add Smrnmi extension (PR #111668)

2024-10-25 Thread via cfe-commits

Xinlong-Wu wrote:

@dong-miao don‘t have write access, I help him to merge

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


[clang] [llvm] [RISCV] Add Smrnmi extension (PR #111668)

2024-10-25 Thread via cfe-commits

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


[clang] [llvm] [RISCV] Add Smrnmi extension (PR #111668)

2024-10-25 Thread via cfe-commits

github-actions[bot] wrote:



@dong-miao Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang-tools-extra] [clang-tidy] Create a check for signed and unsigned integers comparison (PR #113144)

2024-10-25 Thread via cfe-commits

EugeneZelenko wrote:

@qt-tatiana: Please do not forget to resolve fixed comments.

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


[clang] [clang][dataflow] Disambiguate a ref to "internal" in CachedConstAccessorsLattice (PR #113601)

2024-10-25 Thread Samira Bazuzi via cfe-commits

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


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


[clang] [libcxx] [clang] Warn about memset/memcpy to NonTriviallyCopyable types (PR #111434)

2024-10-25 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/111434

>From 3f44e29fdbf7d456040a8b3b7dd36c85e45bc2bf Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Mon, 7 Oct 2024 15:30:24 +0200
Subject: [PATCH 1/2] [clang] Warn about memset/memcpy to NonTriviallyCopyable
 types

This implements a warning that's similar to what GCC does in that
context: both memcpy and memset require their first and second operand
to be trivially copyable, let's warn if that's not the case.
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/Sema/SemaChecking.cpp   | 18 +
 clang/test/SemaCXX/constexpr-string.cpp   |  2 +
 clang/test/SemaCXX/warn-memaccess.cpp | 68 +++
 5 files changed, 96 insertions(+)
 create mode 100644 clang/test/SemaCXX/warn-memaccess.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed0c0e369fca74..3df9224c54ffbe 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -302,6 +302,10 @@ Modified Compiler Flags
   the ``promoted`` algorithm for complex division when possible rather than the
   less basic (limited range) algorithm.
 
+- The ``-Wnontrivial-memaccess`` warning has been updated to also warn about
+  passing non-trivially-copyable parameter to ``memcpy``, ``memset`` and 
similar
+  functions for which it is a documented undefined behavior.
+
 Removed Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8e4718008ece72..a7d6123d5c7e19 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -795,6 +795,10 @@ def warn_cstruct_memaccess : Warning<
   "%1 call is a pointer to record %2 that is not trivial to "
   "%select{primitive-default-initialize|primitive-copy}3">,
   InGroup;
+def warn_cxxstruct_memaccess : Warning<
+  "%select{destination for|source of|first operand of|second operand of}0 call 
to "
+  "%1 is a pointer to non-trivially copyable type %2">,
+  InGroup;
 def note_nontrivial_field : Note<
   "field is non-trivial to %select{copy|default-initialize}0">;
 def err_non_trivial_c_union_in_invalid_context : Error<
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 27b274d74ce716..b64ac3cc676bc3 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -8899,18 +8899,36 @@ void Sema::CheckMemaccessArguments(const CallExpr *Call,
   << ArgIdx << FnName << PointeeTy
   << Call->getCallee()->getSourceRange());
 else if (const auto *RT = PointeeTy->getAs()) {
+
+  bool IsTriviallyCopyableCXXRecord =
+  RT->desugar().isTriviallyCopyableType(Context);
+
   if ((BId == Builtin::BImemset || BId == Builtin::BIbzero) &&
   RT->getDecl()->isNonTrivialToPrimitiveDefaultInitialize()) {
 DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
 PDiag(diag::warn_cstruct_memaccess)
 << ArgIdx << FnName << PointeeTy << 0);
 SearchNonTrivialToInitializeField::diag(PointeeTy, Dest, *this);
+  } else if ((BId == Builtin::BImemset || BId == Builtin::BIbzero) &&
+ !IsTriviallyCopyableCXXRecord && ArgIdx == 0) {
+// FIXME: Limiting this warning to dest argument until we decide
+// whether it's valid for source argument too.
+DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
+PDiag(diag::warn_cxxstruct_memaccess)
+<< ArgIdx << FnName << PointeeTy);
   } else if ((BId == Builtin::BImemcpy || BId == Builtin::BImemmove) &&
  RT->getDecl()->isNonTrivialToPrimitiveCopy()) {
 DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
 PDiag(diag::warn_cstruct_memaccess)
 << ArgIdx << FnName << PointeeTy << 1);
 SearchNonTrivialToCopyField::diag(PointeeTy, Dest, *this);
+  } else if ((BId == Builtin::BImemcpy || BId == Builtin::BImemmove) &&
+ !IsTriviallyCopyableCXXRecord && ArgIdx == 0) {
+// FIXME: Limiting this warning to dest argument until we decide
+// whether it's valid for source argument too.
+DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
+PDiag(diag::warn_cxxstruct_memaccess)
+<< ArgIdx << FnName << PointeeTy);
   } else {
 continue;
   }
diff --git a/clang/test/SemaCXX/constexpr-string.cpp 
b/clang/test/SemaCXX/constexpr-string.cpp
index c456740ef7551f..41305e3f8bcba5 100644
--- a/clang/test/SemaCXX/constexpr-string.cpp
+++ b/clang/test/SemaCXX/constexpr-string.cpp
@@ -670,6 +670,8 @@ namespace MemcpyEtc {
   constexpr bool test_address_of_incomplete_struct_type()

[clang] [llvm] [RISCV] Add Smdbltrp and Ssdbltrp extension (PR #111837)

2024-10-25 Thread via cfe-commits

https://github.com/T-Tie updated 
https://github.com/llvm/llvm-project/pull/111837

>From 23aec55337764fc19a6b816ca238972f705dda9a Mon Sep 17 00:00:00 2001
From: T-Tie <160845405+t-...@users.noreply.github.com>
Date: Thu, 10 Oct 2024 21:11:39 +0800
Subject: [PATCH 1/9] Update riscv-target-features.c double-trap

---
 .../test/Preprocessor/riscv-target-features.c  | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 05a8534ba13da1..d25f96b66a052a 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -29,6 +29,7 @@
 // CHECK-NOT: __riscv_smaia {{.*$}}
 // CHECK-NOT: __riscv_smcdeleg {{.*$}}
 // CHECK-NOT: __riscv_smcsrind {{.*$}}
+// CHECK-NOT: __riscv_smdbltrp {{.*$}}
 // CHECK-NOT: __riscv_smepmp {{.*$}}
 // CHECK-NOT: __riscv_smstateen {{.*$}}
 // CHECK-NOT: __riscv_ssaia {{.*$}}
@@ -37,6 +38,7 @@
 // CHECK-NOT: __riscv_sscofpmf {{.*$}}
 // CHECK-NOT: __riscv_sscounterenw {{.*$}}
 // CHECK-NOT: __riscv_sscsrind {{.*$}}
+// CHECK-NOT: __riscv_ssdbltrp {{.*$}}
 // CHECK-NOT: __riscv_ssqosid{{.*$}}
 // CHECK-NOT: __riscv_ssstateen {{.*$}}
 // CHECK-NOT: __riscv_ssstrict {{.*$}}
@@ -1425,6 +1427,22 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSCSRIND-EXT %s
 // CHECK-SSCSRIND-EXT: __riscv_sscsrind  100{{$}}
 
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32ismdbltrp1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SMDBLTRP-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64ismdbltrp1p0 -E -dM %s \
+// RUN:   -o   | FileCheck --check-prefix=CHECK-SMDBLTRP-EXT %s
+// CHECK-SMDBLTRP-EXT: __riscv_smdbltrp  100{{$}}
+
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32issdbltrp1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSDBLTRP-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64issdbltrp1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SSDBLTRP-EXT %s
+// CHECK-SSDBLTRP-EXT: __riscv_ssdbltrp  100{{$}}
+
 // RUN: %clang --target=riscv32 \
 // RUN:   -march=rv32i_ssqosid1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSQOSID-EXT %s

>From 481ac24641153a117a07886184c061c09f37445f Mon Sep 17 00:00:00 2001
From: T-Tie <160845405+t-...@users.noreply.github.com>
Date: Thu, 10 Oct 2024 21:14:59 +0800
Subject: [PATCH 2/9] Update RISCVUsage.rst double-trap

---
 llvm/docs/RISCVUsage.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 5736f3807f131b..4780c20416c165 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -128,6 +128,7 @@ on support follow.
  ``Smaia`` Supported
  ``Smcdeleg``  Supported
  ``Smcsrind``  Supported
+ ``Smdbltrp``  Supported
  ``Smepmp``Supported
  ``Smstateen`` Assembly Support
  ``Ssaia`` Supported
@@ -136,6 +137,7 @@ on support follow.
  ``Sscofpmf``  Assembly Support
  ``Sscounterenw``  Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Sscsrind``  Supported
+ ``Ssdbltrp``  Supported
  ``Ssqosid``   Assembly Support
  ``Ssstateen`` Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Ssstrict``  Assembly Support (`See note 
<#riscv-profiles-extensions-note>`__)

>From 709c7f78d3a648929073c8d7439565faf13dbf76 Mon Sep 17 00:00:00 2001
From: T-Tie <160845405+t-...@users.noreply.github.com>
Date: Thu, 10 Oct 2024 21:17:46 +0800
Subject: [PATCH 3/9] Update RISCVFeatures.td double-trap

---
 llvm/lib/Target/RISCV/RISCVFeatures.td | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 3d0e1dae801d39..fc93f7c3e1fea1 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -927,6 +927,13 @@ def FeatureStdExtSscsrind
 : RISCVExtension<"sscsrind", 1, 0,
  "'Sscsrind' (Indirect CSR Access Supervisor Level)">;
 
+def FeatureStdExtSmdbltrp
+: RISCVExtension<"smdbltrp", 1, 0,
+ "'Smdbltrp' (Double Trap Machine Level)">;
+def FeatureStdExtSsdbltrp
+: RISCVExtension<"ssdbltrp", 1, 0,
+ "'Ssdbltrp' (Double Trap Supervisor Level)">;
+
 def FeatureStdExtSmepmp
 : RISCVExtension<"smepmp", 1, 0,
  "'Smepmp' (Enhanced Physical Memory Protection)">;

>From 3f503cebbac851cbb40ee08eb1b02cc2535a52b1 Mon Sep 17 00:00:00 2001
From: T-Tie <160845405+t-...@users.noreply.github.com>
Date: Thu, 10 Oct 2024 21:23:17 +0800
Subject: [PATCH 4/9] Update attributes.ll double-trap

---
 llvm/test/CodeGen/RISCV/attributes.ll | 8 
 1 file changed, 8 insertions(+)

diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll

[clang] [Clang]: enhance handling of [[deprecated]] attribute diagnostics for local variables (PR #113575)

2024-10-25 Thread via cfe-commits

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

LGTM

On the issue for this, there was some discussion about the fact that the 
standard might disallow deprecating local variables at some point, but so long 
as we (still) allow that, it only makes sense to actually diagnose the 
deprecation as well considering that it seems to be straight-forward enough to 
implement.

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


[clang] [Clang] fix range calculation for conditionals with throw expressions (PR #112081)

2024-10-25 Thread Oleksandr T. via cfe-commits

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

>From 67c41612085489a2a17eec49f98dbfa0e5bb97cf Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 12 Oct 2024 08:27:51 +0300
Subject: [PATCH 1/3] [Clang] fix range calculation for conditionals with throw
 expressions

---
 clang/docs/ReleaseNotes.rst | 1 +
 clang/lib/Sema/SemaChecking.cpp | 3 +++
 clang/test/SemaCXX/conditional-expr.cpp | 7 +++
 3 files changed, 11 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 337e3fc10bf49d..2ab13640bfa53c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -512,6 +512,7 @@ Bug Fixes to C++ Support
   and undeclared templates. (#GH107047, #GH49093)
 - Clang no longer crashes when a lambda contains an invalid block declaration 
that contains an unexpanded
   parameter pack. (#GH109148)
+- Fixed assertion failure in range calculations for conditional throw 
expressions (#GH111854)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2bcb930acdcb57..b3d88f053872c1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9827,6 +9827,9 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
 return IntRange(BitField->getBitWidthValue(C),
 BitField->getType()->isUnsignedIntegerOrEnumerationType());
 
+  if (GetExprType(E)->isVoidType())
+return IntRange{0, true};
+
   return IntRange::forValueOfType(C, GetExprType(E));
 }
 
diff --git a/clang/test/SemaCXX/conditional-expr.cpp 
b/clang/test/SemaCXX/conditional-expr.cpp
index 01effaa189322b..8f17555fd806ff 100644
--- a/clang/test/SemaCXX/conditional-expr.cpp
+++ b/clang/test/SemaCXX/conditional-expr.cpp
@@ -429,3 +429,10 @@ void g() {
   long e = a = b ? throw 0 : throw 1;
 }
 } // namespace PR46484
+
+namespace GH111854 {
+void f() {
+  (true ? throw 0 : 0) <= 0;  // expected-warning {{relational comparison 
result unused}}
+  (false ? 0 : throw 0) <= 0; // expected-warning {{relational comparison 
result unused}}
+}
+}

>From 9c2a745ed365449be45cd062f29c89cabde0f514 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 19 Oct 2024 00:00:19 +0300
Subject: [PATCH 2/3] change return type to nullable for handling invalid
 ranges in integer expression evaluation

---
 clang/lib/Sema/SemaChecking.cpp | 198 +++-
 1 file changed, 118 insertions(+), 80 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b3d88f053872c1..2ca342a6065550 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9582,8 +9582,10 @@ static QualType GetExprType(const Expr *E) {
 ///particular, assume that arithmetic on narrower types doesn't leave
 ///those types. If \c false, return a range including all possible
 ///result values.
-static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth,
- bool InConstantContext, bool Approximate) {
+static std::optional TryGetExprRange(ASTContext &C, const Expr *E,
+   unsigned MaxWidth,
+   bool InConstantContext,
+   bool Approximate) {
   E = E->IgnoreParens();
 
   // Try a full evaluation first.
@@ -9596,8 +9598,8 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
   // being of the new, wider type.
   if (const auto *CE = dyn_cast(E)) {
 if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_LValueToRValue)
-  return GetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
-  Approximate);
+  return TryGetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
+ Approximate);
 
 IntRange OutputTypeRange = IntRange::forValueOfType(C, GetExprType(CE));
 
@@ -9608,40 +9610,52 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
 if (!isIntegerCast)
   return OutputTypeRange;
 
-IntRange SubRange = GetExprRange(C, CE->getSubExpr(),
- std::min(MaxWidth, OutputTypeRange.Width),
- InConstantContext, Approximate);
+std::optional SubRange = TryGetExprRange(
+C, CE->getSubExpr(), std::min(MaxWidth, OutputTypeRange.Width),
+InConstantContext, Approximate);
+if (!SubRange)
+  return std::nullopt;
 
 // Bail out if the subexpr's range is as wide as the cast type.
-if (SubRange.Width >= OutputTypeRange.Width)
+if (SubRange->Width >= OutputTypeRange.Width)
   return OutputTypeRange;
 
 // Otherwise, we take the smaller width, and we're non-negative if
 // either the output type or the subexpr is.
-  

[clang] [flang] [flang] Add UNSIGNED (PR #113504)

2024-10-25 Thread via cfe-commits

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


[clang] 3a2c957 - [clang][analyzer][doc] Update Clang SA www docs index.html (#112833)

2024-10-25 Thread via cfe-commits

Author: Endre Fülöp
Date: 2024-10-24T17:42:54+02:00
New Revision: 3a2c957c4b11babb6c2111b8827a324ffac5bab8

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

LOG: [clang][analyzer][doc] Update Clang SA www docs index.html (#112833)

Downloads and releases sections are removed, users are advised to use
the conventional ways of acquiring the analyzer.

Added: 


Modified: 
clang/www/analyzer/index.html

Removed: 




diff  --git a/clang/www/analyzer/index.html b/clang/www/analyzer/index.html
index ea0ed4967ec7cc..736ac4aa0f6562 100644
--- a/clang/www/analyzer/index.html
+++ b/clang/www/analyzer/index.html
@@ -72,45 +72,9 @@ Clang Static Analyzer
 The Clang Static Analyzer is a source code analysis tool that finds bugs in
 C, C++, and Objective-C programs.
 
-Currently it can be run either from the command
-  line or if you use macOS then within Xcode. When
-invoked from the command line, it is intended to be run in tandem with a build
-of a codebase.
-
-The analyzer is 100% open source and is part of the https://clang.llvm.org";>Clang project. Like the rest of Clang, the
-analyzer is implemented as a C++ library that can be used by other tools and
-applications.
-
-Download
-
-
- 
- 
- 
- 
- 
- 
- 
-  
-   Mac OS X
-   
-Latest build (10.8+):
- checker-279.tar.bz2 
(built November 14, 2016)
-
-Release notes
-This build can be used both from the command line and from within 
Xcode
-Installation and usage
-   
-  
- 
- 
- 
- 
- 
- 
- 
-
+The analyzer is 100% open source and is part of the https://clang.llvm.org";>Clang
+project. Like the rest of Clang, the analyzer is implemented as a C++ library
+that can be used by other tools and applications.
 
 
  
@@ -121,10 +85,27 @@ Mac OS X
  
  
   
-   Other Platforms
-   For other platforms, please follow the instructions for building the analyzer from
-   source code.
+
+To get started with the Clang Static Analyzer, visit the
+https://releases.llvm.org/download.html";>LLVM
+releases page for download and installation instructions. The official
+releases include both the analyzer and scan-build,
+a command-line tool for running the analyzer on your codebase.
+
+If you're installing Clang from a 
diff erent source, such as
+a Linux package repository, then scan-build may be packaged
+separately as an individual package, or as part of
+a "clang tools" package.
+
+If your IDE is using Clang, it may natively integrate the static 
analyzer.
+On macOS, the easiest way to use the static analyzer is to invoke it
+https://clang.llvm.org/docs/analyzer/user-docs/UsingWithXCode.html";>directly
+from Xcode.
+
+Additionally, if you're using https://clang.llvm.org/extra/clang-tidy/";>clang-tidy,
+you can naturally make the static analyzer run alongside clang-tidy
+by enabling the https://clang.llvm.org/extra/clang-tidy/checks/list.html";>clang-analyzer
+checks.
   
  
  



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


[clang-tools-extra] [clang-tidy] Create a check for signed and unsigned integers comparison (PR #113144)

2024-10-25 Thread via cfe-commits


@@ -0,0 +1,165 @@
+//===--- UseIntegerSignComparisonCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseIntegerSignComparisonCheck.h"
+#include "clang/AST/Expr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::ast_matchers::internal;
+
+namespace clang::tidy::modernize {
+UseIntegerSignComparisonCheck::UseIntegerSignComparisonCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+   utils::IncludeSorter::IS_LLVM),
+  areDiagsSelfContained()),
+  IsQtApplication(Options.get("IsQtApplication", false)),
+  StringsMatchHeader(Options.get("StringsMatchHeader", "")) {}
+
+void UseIntegerSignComparisonCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IsQtApplication", IsQtApplication);
+  Options.store(Opts, "StringsMatchHeader", StringsMatchHeader);
+}
+
+void UseIntegerSignComparisonCheck::registerMatchers(MatchFinder *Finder) {
+  const auto SignedIntCastExpr = intCastExpression(true, "sIntCastExpression");
+  const auto UnSignedIntCastExpr =
+  intCastExpression(false, "uIntCastExpression");
+
+  // Flag all operators "==", "<=", ">=", "<", ">", "!="
+  // that are used between signed/unsigned
+  const auto CompareOperator =
+  expr(binaryOperator(hasAnyOperatorName("==", "<=", ">=", "<", ">", "!="),
+  anyOf(allOf(hasLHS(SignedIntCastExpr),
+  hasRHS(UnSignedIntCastExpr)),
+allOf(hasLHS(UnSignedIntCastExpr),
+  hasRHS(SignedIntCastExpr)
+  .bind("intComparison");
+
+  Finder->addMatcher(CompareOperator, this);
+}
+
+BindableMatcher UseIntegerSignComparisonCheck::intCastExpression(
+bool IsSigned, const std::string &CastBindName) const {
+  auto IntTypeExpr = expr();
+  if (IsSigned) {
+IntTypeExpr = expr(hasType(qualType(isInteger(), isSignedInteger(;
+  } else {
+IntTypeExpr =
+expr(hasType(qualType(isInteger(), unless(isSignedInteger();
+  }
+
+  const auto ImplicitCastExpr =
+  implicitCastExpr(hasSourceExpression(IntTypeExpr)).bind(CastBindName);
+
+  const auto CStyleCastExpr = cStyleCastExpr(has(ImplicitCastExpr));
+  const auto StaticCastExpr = cxxStaticCastExpr(has(ImplicitCastExpr));
+  const auto FunctionalCastExpr = cxxFunctionalCastExpr(has(ImplicitCastExpr));
+
+  return traverse(TK_AsIs, expr(anyOf(ImplicitCastExpr, CStyleCastExpr,
+  StaticCastExpr, FunctionalCastExpr)));
+}
+
+std::string
+UseIntegerSignComparisonCheck::parseOpCode(BinaryOperator::Opcode code) const {
+  switch (code) {
+  case BO_LT:
+return std::string("cmp_less");
+  case BO_GT:
+return std::string("cmp_greater");
+  case BO_LE:
+return std::string("cmp_less_equal");
+  case BO_GE:
+return std::string("cmp_greater_equal");
+  case BO_EQ:
+return std::string("cmp_equal");
+  case BO_NE:
+return std::string("cmp_not_equal");
+  default:
+return {};
+  }
+}
+
+void UseIntegerSignComparisonCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  IncludeInserter.registerPreprocessor(PP);
+}
+
+void UseIntegerSignComparisonCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *SignedCastExpression =
+  Result.Nodes.getNodeAs("sIntCastExpression");
+  const auto *UnSignedCastExpression =
+  Result.Nodes.getNodeAs("uIntCastExpression");
+  assert(SignedCastExpression);
+  assert(UnSignedCastExpression);
+
+  // Ignore the match if we know that the signed int value is not negative.
+  Expr::EvalResult EVResult;
+  if (!SignedCastExpression->isValueDependent() &&
+  SignedCastExpression->getSubExpr()->EvaluateAsInt(EVResult,
+*Result.Context)) {
+const llvm::APSInt SValue = EVResult.Val.getInt();
+if (SValue.isNonNegative())
+  return;
+  }
+
+  const auto *BinaryOp =
+  Result.Nodes.getNodeAs("intComparison");
+  if (BinaryOp == nullptr)
+return;
+
+  const BinaryOperator::Opcode OpCode = BinaryOp->getOpcode();
+  const auto *LHS = BinaryOp->getLHS()->IgnoreParenImpCasts();

EugeneZelenko wrote:

`auto` should bot be used, type is not spelled explicitly or iterator. Same 
below.

https://github.com/llvm/llvm-project/pull/113144
___
cfe-commits mailing

[clang] [llvm] [clang-format] Add CI check confirming ClangFormatStyleOptions.rst is up-to-date. (PR #111513)

2024-10-25 Thread Owen Pan via cfe-commits

https://github.com/owenca commented:

@ichaer I suggest that you split the workflow part to another patch so that we 
can get the cmake part approved.

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


[clang] [llvm] [HLSL][SPIRV] Added clamp intrinsic (PR #113394)

2024-10-25 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,130 @@
+; RUN: llc  -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | 
FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - 
-filetype=obj | spirv-val %}

farzonl wrote:

Thats a artifact of  the early days where we wanted to test vector support in 
`DXILIntrinsicExpansion.cpp` but we were unable to do that type of testing with 
`DXILLowering.cpp`. Now that we have the scalarizer pass. We should probably 
clean that up in the DX backend.

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


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

2024-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Vitaly Buka (vitalybuka)


Changes

Reverts llvm/llvm-project#108357

Breaks  https://lab.llvm.org/buildbot/#/builders/164/builds/3908 and similar 
bots

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


6 Files Affected:

- (modified) libcxx/cmake/config-ix.cmake (+4-8) 
- (modified) libcxxabi/cmake/config-ix.cmake (+4-8) 
- (modified) libcxxabi/src/CMakeLists.txt (+2-2) 
- (modified) libunwind/cmake/config-ix.cmake (+4-8) 
- (modified) libunwind/src/CMakeLists.txt (+1-1) 
- (modified) runtimes/CMakeLists.txt (+4-8) 


``diff
diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index 192bad7a7a7fc6..270d80575adcfd 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -38,13 +38,9 @@ check_cxx_compiler_flag(-nolibc CXX_SUPPORTS_NOLIBC_FLAG)
 # required during compilation (which has the -nostdlib++ or -nodefaultlibs). 
libc is
 # required for the link to go through. We remove sanitizers from the
 # configuration checks to avoid spurious link errors.
-#
-# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
-# compilation of C and C++. Therefore test to make sure that the flags are
-# supported by the C compiler driver, before deciding to include them.
 
-check_c_compiler_flag(-nostdlib++ C_SUPPORTS_NOSTDLIBXX_FLAG)
-if (C_SUPPORTS_NOSTDLIBXX_FLAG)
+check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
   check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
@@ -55,7 +51,7 @@ endif()
 
 # Only link against compiler-rt manually if we use -nodefaultlibs, since
 # otherwise the compiler will do the right thing on its own.
-if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (LIBCXX_USE_COMPILER_RT)
 include(HandleCompilerRT)
 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY
@@ -85,7 +81,7 @@ if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND 
C_SUPPORTS_NODEFAULTLIBS_FLAG)
   endif()
 endif()
 
-if (C_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
   endif ()
diff --git a/libcxxabi/cmake/config-ix.cmake b/libcxxabi/cmake/config-ix.cmake
index ab74ad79a654af..10f2087c68c5e7 100644
--- a/libcxxabi/cmake/config-ix.cmake
+++ b/libcxxabi/cmake/config-ix.cmake
@@ -22,13 +22,9 @@ endif ()
 # required during compilation (which has the -nodefaultlibs). libc is
 # required for the link to go through. We remove sanitizers from the
 # configuration checks to avoid spurious link errors.
-#
-# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
-# compilation of C and C++. Therefore test to make sure that the flags are
-# supported by the C compiler driver, before deciding to include them.
 
-check_c_compiler_flag(-nostdlib++ C_SUPPORTS_NOSTDLIBXX_FLAG)
-if (C_SUPPORTS_NOSTDLIBXX_FLAG)
+check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
   check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
@@ -39,7 +35,7 @@ endif()
 
 # Only link against compiler-rt manually if we use -nodefaultlibs, since
 # otherwise the compiler will do the right thing on its own.
-if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (LIBCXXABI_HAS_C_LIB)
 list(APPEND CMAKE_REQUIRED_LIBRARIES c)
   endif ()
@@ -75,7 +71,7 @@ if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND 
C_SUPPORTS_NODEFAULTLIBS_FLAG)
   endif()
 endif()
 
-if (C_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
   endif ()
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index af8071cbdc8537..84fe2784bec5ca 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -91,7 +91,7 @@ if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
 endif()
 
 # Setup flags.
-if (C_SUPPORTS_NOSTDLIBXX_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
   add_link_flags_if_supported(-nostdlib++)
 else()
   add_link_flags_if_supported(-nodefaultlibs)
@@ -167,7 +167,7 @@ if (LIBCXXABI_USE_LLVM_UNWINDER)
   endif()
 endif()
 target_link_libraries(cxxabi_shared_objects PRIVATE cxx-headers 
${LIBCXXABI_LIBRARIES})
-if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG)
+if (NOT CXX_SUPPORTS_NOSTDLIB

[clang] [llvm] [ci] New script to generate test reports as Buildkite Annotations (PR #113447)

2024-10-25 Thread David Spickett via cfe-commits

DavidSpickett wrote:

> Do we make any guarantees about supporting lit flags in the future? It's 
> mostly an internal tool, and I would personally be in support of removing 
> flags that are no longer used in tree, unless there are some extremely 
> compelling downstream use cases and there is an appropriate maintenance story.

> Overall, I'm fine with this patch, however I wonder how much effort it is 
> worth putting into the BuildKite infrastructure given that we plan on moving 
> as much as possible to Github Actions...

Louis' point is a good one given that lit is released externally 
(https://pypi.org/project/lit/). We probably don't have a contract as such 
there but if we don't add anything, there's no chance to annoy anyone when we 
remove it. The next release would be based on the 19 branch, so there is still 
time to remove the feature I added.

The alternative is to go back to changing the build scripts to do:
```
for target in targets:
   ninja target
   move result file
   accumulate return code
```
That does not require a lit feature but is more invasive. If we're going to 
throw away those scripts anyway, perhaps folks will be ok with a temporary 
increase in complexity.

I agree that a future GitHub actions pipeline should be splitting check targets 
into steps anyway, effectively doing the for loop I showed above, but using the 
pipeline structure. And if the folks doing the transition don't want to worry 
about that on top of everything else I'm sure they have to do, I will commit my 
time to doing the extra work required for that.

If that means we get useful reporting of test results by default and we can 
delete every change I've made towards this so far, I'll be very happy!

I will make another version of this PR that modifies the build scripts instead 
of using the lit feature. If that PR is preferable, I will revert the lit 
feature.

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


[clang] [clang-repl] Fix undefined lld::wasm::link symbol while building clangInterpreter for wasm (PR #113446)

2024-10-25 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-qemu` running on `sanitizer-buildbot3` while building 
`clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure) (timed out)
...
[5.337836] pci :00:00.0: [8086:29c0] type 00 class 0x06 
conventional PCI endpoint
[5.358128] pci :00:01.0: [1234:] type 00 class 0x03 
conventional PCI endpoint
[5.359836] pci :00:01.0: BAR 0 [mem 0xfd00-0xfdff pref]
[5.360973] pci :00:01.0: BAR 2 [mem 0xfebf-0xfebf0fff]
[5.370836] pci :00:01.0: ROM [mem 0xfebe-0xfebe pref]
[5.374977] pci :00:01.0: Video device with shadowed ROM at [mem 
0x000c-0x000d]
[5.380351] pci :00:02.0: [8086:100e] type 00 class 0x02 
conventional PCI endpoint
[5.380836] pci :00:02.0: BAR 0 [mem 0xfebc-0xfebd]
[5.385836] pci :00:02.0: BAR 1 [io  0xc000-0xc03f]
+ ssh -p 42942 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o 
ControlPersist=30m -M -S 
/home/b/sanitizer-x86_64-linux-qemu/build/qemu_tmp/ssh-control-socket -i 
/home/b/qemu_image/debian.id_rsa root@localhost 'uname -a'
command timed out: 1200 seconds without output running [b'python', 
b'../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'],
 attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=3489.399353
Step 29 (start LAM QEMU) failure: start LAM QEMU (failure)
...
[5.064064] cpuidle: using governor menu
[5.075836] PCI: ECAM [mem 0xb000-0xbfff] (base 0xb000) for 
domain  [bus 00-ff]
[5.077632] PCI: ECAM [mem 0xb000-0xbfff] reserved as E820 entry
[5.080800] PCI: Using configuration type 1 for base access
[5.080836] mtrr: your CPUs had inconsistent fixed MTRR settings
[5.080836] mtrr: your CPUs had inconsistent variable MTRR settings
[5.081924] mtrr: your CPUs had inconsistent MTRRdefType settings
[5.082241] mtrr: probably your BIOS does not setup all CPUs.
[5.082487] mtrr: corrected configuration.
[5.089025] kprobes: kprobe jump-optimization is enabled. All kprobes are 
optimized if possible.
[5.112267] HugeTLB: registered 2.00 MiB page size, pre-allocated 0 pages
[5.112712] HugeTLB: 28 KiB vmemmap can be freed for a 2.00 MiB page
[5.129836] ACPI: Added _OSI(Module Device)
[5.129836] ACPI: Added _OSI(Processor Device)
[5.129836] ACPI: Added _OSI(3.0 _SCP Extensions)
[5.129926] ACPI: Added _OSI(Processor Aggregator Device)
[5.175239] ACPI: 1 ACPI AML tables successfully acquired and loaded
[5.217121] ACPI: Interpreter enabled
[5.221836] ACPI: PM: (supports S0 S3 S4 S5)
[5.221836] ACPI: Using IOAPIC for interrupt routing
[5.223952] PCI: Using host bridge windows from ACPI; if necessary, use 
"pci=nocrs" and report a bug
[5.224988] PCI: Using E820 reservations for host bridge windows
[5.228451] ACPI: Enabled 2 GPEs in block 00 to 3F
[5.318836] ACPI: PCI Root Bridge [PCI0] (domain  [bus 00-ff])
[5.322285] acpi PNP0A08:00: _OSC: OS supports [ExtendedConfig ASPM ClockPM 
Segments MSI HPX-Type3]
[5.322836] acpi PNP0A08:00: _OSC: platform does not support [LTR]
[5.326658] acpi PNP0A08:00: _OSC: OS now controls [PME PCIeCapability]
[5.334364] PCI host bridge to bus :00
[5.335399] pci_bus :00: root bus resource [io  0x-0x0cf7 window]
[5.335836] pci_bus :00: root bus resource [io  0x0d00-0x window]
[5.335836] pci_bus :00: root bus resource [mem 0x000a-0x000b 
window]
[5.335836] pci_bus :00: root bus resource [mem 0x8000-0xafff 
window]
[5.335836] pci_bus :00: root bus resource [mem 0xc000-0xfebf 
window]
[5.335836] pci_bus :00: root bus resource [mem 0x48000-0xc7fff 
window]
[5.335836] pci_bus :00: root bus resource [bus 00-ff]
[5.337836] pci :00:00.0: [8086:29c0] type 00 class 0x06 
conventional PCI endpoint
[5.358128] pci :00:01.0: [1234:] type 00 class 0x03 
conventional PCI endpoint
[5.359836] pci :00:01.0: BAR 0 [mem 0xfd00-0xfdff pref]
[5.360973] pci :00:01.0: BAR 2 [mem 0xfebf-0xfebf0fff]
[5.370836] pci :00:01.0: ROM [mem 0xfebe-0xfebe pref]
[5.374977] pci :00:01.0: Video device with shadowed ROM at [mem 
0x000c-0x000d]
[5.380351] pci :00:02.0: [8086:100e] type 00 class 0x02 
conventional PCI endpoint
[5.380836] pci :00:02.0: BAR 0 [mem 0xfebc-0xfebd]
[5.385836] pci :00:02.0: BAR 1 [io  0xc000-0xc03f]
+ ssh -p 42942 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null 

[clang] [lld] [llvm] [WebAssembly] Enable nontrapping-fptoint and bulk-memory by default. (PR #112049)

2024-10-25 Thread Dan Gohman via cfe-commits

https://github.com/sunfishcode updated 
https://github.com/llvm/llvm-project/pull/112049

>From c4327c96d09b37c66efe9cf74a4bfdd3b26a98b3 Mon Sep 17 00:00:00 2001
From: Dan Gohman 
Date: Fri, 11 Oct 2024 13:31:13 -0700
Subject: [PATCH 1/7] [WebAssembly] Enable nontrapping-fptoint and bulk-memory
 by default.

We were prepared to enable these features [back in February], but they
got pulled for what appear to be unrelated reasons. So let's have another
try at enabling them!

Another motivation here is that it'd be convenient for the
[Trail1 proposal] if "trail1" is a superset of "generic".

[back in February]: 
https://github.com/WebAssembly/tool-conventions/issues/158#issuecomment-1931119512
[Trail1 proposal]: https://github.com/llvm/llvm-project/pull/112035
---
 clang/docs/ReleaseNotes.rst| 9 +
 clang/lib/Basic/Targets/WebAssembly.cpp| 2 ++
 llvm/docs/ReleaseNotes.md  | 9 +
 llvm/lib/Target/WebAssembly/WebAssembly.td | 3 ++-
 4 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 46021c9c17feac..ebeff735d2cdb5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -671,6 +671,15 @@ NetBSD Support
 WebAssembly Support
 ^^^
 
+The default target CPU, "generic", now enables the `-mnontrapping-fptoint`
+and `-mbulk-memory` flags, which correspond to the [Bulk Memory Operations]
+and [Non-trapping float-to-int Conversions] language features, which are
+[widely implemented in engines].
+
+[Bulk Memory Operations]: 
https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
+[Non-trapping float-to-int Conversions]: 
https://github.com/WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
+[widely implemented in engines]: https://webassembly.org/features/
+
 AVR Support
 ^^^
 
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 4c9df6007b7823..3afb604a8acddc 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -154,8 +154,10 @@ bool WebAssemblyTargetInfo::initFeatureMap(
 llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef CPU,
 const std::vector &FeaturesVec) const {
   auto addGenericFeatures = [&]() {
+Features["bulk-memory"] = true;
 Features["multivalue"] = true;
 Features["mutable-globals"] = true;
+Features["nontrapping-fptoint"] = true;
 Features["reference-types"] = true;
 Features["sign-ext"] = true;
   };
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 504fce4160a583..73d691fe052df1 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -175,6 +175,15 @@ Changes to the RISC-V Backend
 Changes to the WebAssembly Backend
 --
 
+The default target CPU, "generic", now enables the `-mnontrapping-fptoint`
+and `-mbulk-memory` flags, which correspond to the [Bulk Memory Operations]
+and [Non-trapping float-to-int Conversions] language features, which are
+[widely implemented in engines].
+
+[Bulk Memory Operations]: 
https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
+[Non-trapping float-to-int Conversions]: 
https://github.com/WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
+[widely implemented in engines]: https://webassembly.org/features/
+
 Changes to the Windows Target
 -
 
diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.td 
b/llvm/lib/Target/WebAssembly/WebAssembly.td
index 37d99690c25b1f..88628f2a793545 100644
--- a/llvm/lib/Target/WebAssembly/WebAssembly.td
+++ b/llvm/lib/Target/WebAssembly/WebAssembly.td
@@ -114,7 +114,8 @@ def : ProcessorModel<"mvp", NoSchedModel, []>;
 // consideration given to available support in relevant engines and tools, and
 // the importance of the features.
 def : ProcessorModel<"generic", NoSchedModel,
-  [FeatureMultivalue, FeatureMutableGlobals,
+  [FeatureBulkMemory, FeatureMultivalue,
+   FeatureMutableGlobals, FeatureNontrappingFPToInt,
FeatureReferenceTypes, FeatureSignExt]>;
 
 // Latest and greatest experimental version of WebAssembly. Bugs included!

>From 8a655bed4296793a450e2976828cdf3c49651fc6 Mon Sep 17 00:00:00 2001
From: Dan Gohman 
Date: Fri, 11 Oct 2024 16:58:39 -0700
Subject: [PATCH 2/7] Update tests.

---
 .../test/CodeGen/WebAssembly/cfg-stackify-eh-legacy.ll | 10 +-
 llvm/test/CodeGen/WebAssembly/target-features-cpus.ll  |  8 +++-
 llvm/test/MC/WebAssembly/extern-functype-intrinsic.ll  |  4 ++--
 llvm/test/MC/WebAssembly/libcall.ll|  2 +-
 4 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/llvm/test/CodeGen/WebAssembly/cfg-stackify

[clang] [llvm] [RISCV] Mark pointer masking extensions as non-experimental (PR #113618)

2024-10-25 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang-driver

Author: Alex Bradbury (asb)


Changes

These extensions were ratified very recently.
;

I've ensured we have definitions for all extensions in the document 
;.
 There are no additional CSRs.

---

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


8 Files Affected:

- (modified) clang/test/Driver/print-supported-extensions-riscv.c (+5-5) 
- (modified) clang/test/Driver/riscv-profiles.c (+1-1) 
- (modified) clang/test/Preprocessor/riscv-target-features.c (+8-8) 
- (modified) llvm/docs/RISCVUsage.rst (+5-3) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+10-10) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+10-10) 
- (modified) llvm/test/CodeGen/RISCV/rvv/pr107950.ll (+1-1) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+5-5) 


``diff
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index a39c1ab36b1db0..7b5c7c7961974d 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -120,6 +120,8 @@
 // CHECK-NEXT: smcdeleg 1.0   'Smcdeleg' (Counter 
Delegation Machine Level)
 // CHECK-NEXT: smcsrind 1.0   'Smcsrind' (Indirect CSR 
Access Machine Level)
 // CHECK-NEXT: smepmp   1.0   'Smepmp' (Enhanced Physical 
Memory Protection)
+// CHECK-NEXT: smmpm1.0   'Smmpm' (Machine-level 
Pointer Masking for M-mode)
+// CHECK-NEXT: smnpm1.0   'Smnpm' (Machine-level 
Pointer Masking for next lower privilege mode)
 // CHECK-NEXT: smstateen1.0   'Smstateen' (Machine-mode 
view of the state-enable extension)
 // CHECK-NEXT: ssaia1.0   'Ssaia' (Advanced Interrupt 
Architecture Supervisor Level)
 // CHECK-NEXT: ssccfg   1.0   'Ssccfg' (Counter 
Configuration Supervisor Level)
@@ -127,6 +129,8 @@
 // CHECK-NEXT: sscofpmf 1.0   'Sscofpmf' (Count Overflow 
and Mode-Based Filtering)
 // CHECK-NEXT: sscounterenw 1.0   'Sscounterenw' (Support 
writeable scounteren enable bit for any hpmcounter that is not read-only zero)
 // CHECK-NEXT: sscsrind 1.0   'Sscsrind' (Indirect CSR 
Access Supervisor Level)
+// CHECK-NEXT: ssnpm1.0   'Ssnpm' (Supervisor-level 
Pointer Masking for next lower privilege mode)
+// CHECK-NEXT: sspm 1.0   'Sspm' (Indicates 
Supervisor-mode Pointer Masking)
 // CHECK-NEXT: ssqosid  1.0   'Ssqosid' 
(Quality-of-Service (QoS) Identifiers)
 // CHECK-NEXT: ssstateen1.0   'Ssstateen' (Supervisor-mode 
view of the state-enable extension)
 // CHECK-NEXT: ssstrict 1.0   'Ssstrict' (No 
non-conforming extensions are present)
@@ -134,6 +138,7 @@
 // CHECK-NEXT: sstvala  1.0   'Sstvala' (stval provides 
all needed values)
 // CHECK-NEXT: sstvecd  1.0   'Sstvecd' (stvec supports 
Direct mode)
 // CHECK-NEXT: ssu64xl  1.0   'Ssu64xl' (UXLEN=64 
supported)
+// CHECK-NEXT: supm 1.0   'Supm' (Indicates User-mode 
Pointer Masking)
 // CHECK-NEXT: svade1.0   'Svade' (Raise exceptions on 
improper A/D bits)
 // CHECK-NEXT: svadu1.0   'Svadu' (Hardware A/D 
updates)
 // CHECK-NEXT: svbare   1.0   'Svbare' $(satp mode Bare 
supported)
@@ -176,12 +181,7 @@
 // CHECK-NEXT: zvbc32e  0.7   'Zvbc32e' (Vector Carryless 
Multiplication with 32-bits elements)
 // CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
 // CHECK-NEXT: smctr1.0   'Smctr' (Control Transfer 
Records Machine Level)
-// CHECK-NEXT: smmpm1.0   'Smmpm' (Machine-level 
Pointer Masking for M-mode)
-// CHECK-NEXT: smnpm1.0   'Smnpm' (Machine-level 
Pointer Masking for next lower privilege mode)
 // CHECK-NEXT: ssctr1.0   'Ssctr' (Control Transfer 
Records Supervisor Level)
-// CHECK-NEXT: ssnpm1.0   'Ssnpm' (Supervisor-level 
Pointer Masking for next lower privilege mode)
-// CHECK-NEXT: sspm 1.0   'Sspm' (Indicates 
Supervisor-mode Pointer Masking)
-// CHECK-NEXT: supm 1.0   'Supm' (Indicates User-mode 
Pointer Masking)
 // CHECK-EMPTY:
 // CHECK-NEXT: Supported Profiles
 // CHECK-NEXT: rva20s64
diff --git a/clang/test/Driver/riscv-profiles.c 
b/cl

[clang] [AST] Bump Type::NumOfBuiltinTypeBits. NFCI. (PR #113559)

2024-10-25 Thread Jay Foad via cfe-commits

https://github.com/jayfoad created 
https://github.com/llvm/llvm-project/pull/113559

BuiltinType::LastKind is currently 507 which is close to the current
limit of 511.


>From fe852c49f160d9b76e61f151bc857eb8493a47db Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Thu, 24 Oct 2024 13:41:31 +0100
Subject: [PATCH] [AST] Bump Type::NumOfBuiltinTypeBits. NFCI.

BuiltinType::LastKind is currently 507 which is close to the current
limit of 511.
---
 clang/include/clang/AST/Type.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ba3161c366f4d9..2598a794fe8796 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1930,7 +1930,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 unsigned : NumTypeBits;
 
 /// The kind (BuiltinType::Kind) of builtin type this is.
-static constexpr unsigned NumOfBuiltinTypeBits = 9;
+static constexpr unsigned NumOfBuiltinTypeBits = 10;
 unsigned Kind : NumOfBuiltinTypeBits;
   };
 

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


[clang] [clang][analyzer][doc] Migrate ClangSA www FAQ section (PR #112831)

2024-10-25 Thread Endre Fülöp via cfe-commits

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


[clang] [Clang][AArch64] Fix Pure Scalables Types argument passing and return (PR #112747)

2024-10-25 Thread Momchil Velikov via cfe-commits


@@ -303,6 +368,20 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool 
IsVariadic,
   if (EIT->getNumBits() > 128)
 return getNaturalAlignIndirect(Ty, false);
 
+if (const BuiltinType *BT = Ty->getAs()) {
+  if (BT->isSVEBool() || BT->isSVECount())
+NPRN = std::min(NPRN + 1, 4u);
+  else if (BT->getKind() == BuiltinType::SveBoolx2)
+NPRN = std::min(NPRN + 2, 4u);
+  else if (BT->getKind() == BuiltinType::SveBoolx4)
+NPRN = std::min(NPRN + 4, 4u);
+  else if (BT->isFloatingPoint() || BT->isVectorType())

momchil-velikov wrote:

Fixed and tests added.

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


[clang] [clang-tools-extra] [clang][modules] Shrink the size of `Module::Headers` (PR #113395)

2024-10-25 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/113395

>From 09246d11c8663c0b2b31317eddc297c1d29fcd60 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Tue, 22 Oct 2024 16:07:27 -0700
Subject: [PATCH 1/4] [clang][modules] Shrink the size of `Module::Headers`

This patch shrinks the size of the `Module` class from 2112B to 1624B. I wasn't 
able to get a good data on the actual impact on memory usage, but given my 
`clang-scan-deps` workload at hand (with tens of thousands of instances), I 
think there should be some win here. This also speeds up my benchmark by under 
0.1%.
---
 clang/include/clang/Basic/Module.h| 18 --
 clang/lib/Basic/Module.cpp|  2 +-
 clang/lib/Frontend/FrontendAction.cpp |  2 +-
 clang/lib/Lex/ModuleMap.cpp   | 20 +++-
 clang/lib/Serialization/ASTWriter.cpp |  4 ++--
 5 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 9c5d33fbb562cc..b8f1e00d6fac1f 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -271,8 +271,22 @@ class alignas(8) Module {
 DirectoryEntryRef Entry;
   };
 
-  /// The headers that are part of this module.
-  SmallVector Headers[5];
+private:
+  unsigned HeaderKindBeginIndex[6] = {};
+  SmallVector HeadersStorage;
+
+public:
+  ArrayRef getHeaders(HeaderKind HK) const {
+auto BeginIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK];
+auto EndIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK + 1];
+return {BeginIt, EndIt};
+  }
+  void addHeader(HeaderKind HK, Header H) {
+auto EndIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK + 1];
+HeadersStorage.insert(EndIt, std::move(H));
+for (unsigned HKI = HK + 1; HKI != 6; ++HKI)
+  ++HeaderKindBeginIndex[HKI];
+  }
 
   /// Stored information about a header directive that was found in the
   /// module map file but has not been resolved to a file.
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index ad52fccff5dc7f..a7a3f6b37efef1 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -528,7 +528,7 @@ void Module::print(raw_ostream &OS, unsigned Indent, bool 
Dump) const {
 
   for (auto &K : Kinds) {
 assert(&K == &Kinds[K.Kind] && "kinds in wrong order");
-for (auto &H : Headers[K.Kind]) {
+for (auto &H : getHeaders(K.Kind)) {
   OS.indent(Indent + 2);
   OS << K.Prefix << "header \"";
   OS.write_escaped(H.NameAsWritten);
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 81eea9c4c4dc58..8264bd702fe43f 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -358,7 +358,7 @@ static std::error_code collectModuleHeaderIncludes(
 
   // Add includes for each of these headers.
   for (auto HK : {Module::HK_Normal, Module::HK_Private}) {
-for (Module::Header &H : Module->Headers[HK]) {
+for (const Module::Header &H : Module->getHeaders(HK)) {
   Module->addTopHeader(H.Entry);
   // Use the path as specified in the module map file. We'll look for this
   // file relative to the module build directory (the directory containing
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index fd6bc17ae9cdac..23875912fa735e 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -472,12 +472,12 @@ static bool violatesPrivateInclude(Module 
*RequestingModule,
 // as obtained from the lookup and as obtained from the module.
 // This check is not cheap, so enable it only for debugging.
 bool IsPrivate = false;
-SmallVectorImpl *HeaderList[] = {
-&Header.getModule()->Headers[Module::HK_Private],
-&Header.getModule()->Headers[Module::HK_PrivateTextual]};
-for (auto *Hs : HeaderList)
+ArrayRef HeaderList[] = {
+Header.getModule()->getHeaders(Module::HK_Private),
+Header.getModule()->getHeaders(Module::HK_PrivateTextual)};
+for (auto Hs : HeaderList)
   IsPrivate |= llvm::any_of(
-  *Hs, [&](const Module::Header &H) { return H.Entry == IncFileEnt; });
+  Hs, [&](const Module::Header &H) { return H.Entry == IncFileEnt; });
 assert(IsPrivate && "inconsistent headers and roles");
   }
 #endif
@@ -1296,27 +1296,29 @@ void ModuleMap::addHeader(Module *Mod, Module::Header 
Header,
   ModuleHeaderRole Role, bool Imported) {
   KnownHeader KH(Mod, Role);
 
+  FileEntryRef HeaderEntry = Header.Entry;
+
   // Only add each header to the headers list once.
   // FIXME: Should we diagnose if a header is listed twice in the
   // same module definition?
-  auto &HeaderList = Headers[Header.Entry];
+  auto &HeaderList = Headers[HeaderEntry];
   if (llvm::is_contained(HeaderList, KH))
 return;
 
   HeaderList.push_back(KH);
-  Mod->Headers[headerRoleToKind(Role)].push_back(

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-25 Thread Dan Liew via cfe-commits


@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {
+  // Note: This implementation relies on `CountAttributedType` being unique.
+  // E.g.:
+  //
+  // struct Foo {
+  //   int count;
+  //   char* __counted_by(count) buffer;
+  //   char* __counted_by(count) buffer2;
+  // };
+  //
+  // The types of `buffer` and `buffer2` are unique. The types being
+  // unique means the SourceLocation of the `counted_by` expression can be used
+  // to find where the attribute was written.
+
+  auto Fallback = CATy->getCountExpr()->getSourceRange();
+  auto CountExprBegin = CATy->getCountExpr()->getBeginLoc();
+
+  // FIXME: We currently don't support the count expression being a macro
+  // itself. E.g.:
+  //
+  // #define ZERO 0
+  // int* __counted_by(ZERO) x;
+  //
+  if (SourceMgr.isMacroBodyExpansion(CountExprBegin))
+return Fallback;
+
+  auto FetchIdentifierTokenFromOffset =
+  [&](ssize_t Offset) -> std::optional {
+SourceLocation OffsetLoc = CountExprBegin.getLocWithOffset(Offset);
+Token Result;
+if (Lexer::getRawToken(OffsetLoc, Result, SourceMgr, getLangOpts()))
+  return std::optional(); // Failed
+
+if (!Result.isAnyIdentifier())
+  return std::optional(); // Failed
+
+return Result; // Success
+  };
+
+  auto CountExprEnd = CATy->getCountExpr()->getEndLoc();
+  auto FindRParenTokenAfter = [&]() -> std::optional {
+auto CountExprEndSpelling = SourceMgr.getSpellingLoc(CountExprEnd);
+auto MaybeRParenTok = Lexer::findNextToken(
+CountExprEndSpelling, getSourceManager(), getLangOpts());
+
+if (!MaybeRParenTok.has_value())
+  return std::nullopt;
+
+if (!MaybeRParenTok->is(tok::r_paren))
+  return std::nullopt;
+
+return *MaybeRParenTok;
+  };
+
+  // Step back two characters to point at the last character of the attribute
+  // text.
+  //
+  // __counted_by(count)
+  //^ ^
+  //| |
+  //---
+  auto MaybeLastAttrCharToken = FetchIdentifierTokenFromOffset(-2);
+  if (!MaybeLastAttrCharToken)
+return Fallback;
+
+  auto LastAttrCharToken = MaybeLastAttrCharToken.value();
+
+  if (LastAttrCharToken.getLength() > 1) {
+// Special case: When the character is part of a macro the Token we get
+// is the whole macro name (e.g. `__counted_by`).
+if (LastAttrCharToken.getRawIdentifier() !=
+CATy->GetAttributeName(/*WithMacroPrefix=*/true))
+  return Fallback;
+
+// Found the beginning of the `__counted_by` macro
+SourceLocation Begin = LastAttrCharToken.getLocation();
+// Now try to find the closing `)` of the macro.
+auto MaybeRParenTok = FindRParenTokenAfter();
+if (!MaybeRParenTok.has_value())
+  return Fallback;
+
+return SourceRange(Begin, MaybeRParenTok->getLocation());
+  }
+
+  assert(LastAttrCharToken.getLength() == 1);
+  // The Token we got back is just the last character of the identifier.
+  // This means a macro is not being used and instead the attribute is being
+  // used directly. We need to find the beginning of the identifier. We support
+  // two cases:
+  //
+  // * Non-affixed version. E.g: `counted_by`
+  // * Affixed version. E.g.: `__counted_by__`
+
+  // Try non-affixed version. E.g.:
+  //
+  // __attribute__((counted_by(count)))
+  //^  ^
+  //|  |
+  //
+
+  // +1 is for `(`
+  const ssize_t NonAffixedSkipCount =
+  CATy->GetAttributeName(/*WithMacroPrefix=*/false).size() + 1;
+  auto MaybeNonAffixedBeginToken =
+  FetchIdentifierTokenFromOffset(-NonAffixedSkipCount);
+  if (!MaybeNonAffixedBeginToken)
+return Fallback;
+
+  auto NonAffixedBeginToken = MaybeNonAffixedBeginToken.value();
+  if (NonAffixedBeginToken.getRawIdentifier() ==
+  CATy->GetAttributeName(/*WithMacroPrefix=*/false)) {
+// Found the beginning of the `counted_by`-like attribute
+auto SL = NonAffixedBeginToken.getLocation();
+
+// Now try to find the closing `)` of the attribute
+auto MaybeRParenTok = FindRParenTokenAfter();
+if (!MaybeRParenTok.has_value())
+  return Fallback;
+
+return SourceRange(SL, MaybeRParenTok->getLocation());
+  }
+
+  // Try affixed version. E.g.:
+  //
+  // __attribute__((__counted_by__(count)))
+  //^  ^
+  //|  |
+  //
+  std::string AffixedTokenStr =
+  (llvm::Twine("__") + CATy->GetAttributeName(/*WithMacroPrefix=*/false) +
+   llvm::Twine("__"))
+  .str();
+  // +1 is for `(`
+  // +4 is for the 4 `_` characters
+  const ssize_t AffixedSkipCount =
+  CATy->GetAttributeName(/*WithMacroPrefix=*/false).size() + 1 + 4;
+  auto MaybeAffixedBeginToken =
+  FetchIdentifierTokenFromOffset(-AffixedSkipCount);
+  if (!MaybeAffixedBegi

[clang] [libcxx] [clang] Warn about memset/memcpy to NonTriviallyCopyable types (PR #111434)

2024-10-25 Thread via cfe-commits

https://github.com/serge-sans-paille updated 
https://github.com/llvm/llvm-project/pull/111434

>From 24a0e9cee860f4e571a2edfa9827cc6c1436b5aa Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Mon, 7 Oct 2024 15:30:24 +0200
Subject: [PATCH 1/2] [clang] Warn about memset/memcpy to NonTriviallyCopyable
 types

This implements a warning that's similar to what GCC does in that
context: both memcpy and memset require their first and second operand
to be trivially copyable, let's warn if that's not the case.
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/Sema/SemaChecking.cpp   | 18 +
 clang/test/SemaCXX/constexpr-string.cpp   |  2 +
 clang/test/SemaCXX/warn-memaccess.cpp | 68 +++
 5 files changed, 96 insertions(+)
 create mode 100644 clang/test/SemaCXX/warn-memaccess.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 46021c9c17feac..d6de1759b47535 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -302,6 +302,10 @@ Modified Compiler Flags
   the ``promoted`` algorithm for complex division when possible rather than the
   less basic (limited range) algorithm.
 
+- The ``-Wnontrivial-memaccess`` warning has been updated to also warn about
+  passing non-trivially-copyable parameter to ``memcpy``, ``memset`` and 
similar
+  functions for which it is a documented undefined behavior.
+
 Removed Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8e4718008ece72..a7d6123d5c7e19 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -795,6 +795,10 @@ def warn_cstruct_memaccess : Warning<
   "%1 call is a pointer to record %2 that is not trivial to "
   "%select{primitive-default-initialize|primitive-copy}3">,
   InGroup;
+def warn_cxxstruct_memaccess : Warning<
+  "%select{destination for|source of|first operand of|second operand of}0 call 
to "
+  "%1 is a pointer to non-trivially copyable type %2">,
+  InGroup;
 def note_nontrivial_field : Note<
   "field is non-trivial to %select{copy|default-initialize}0">;
 def err_non_trivial_c_union_in_invalid_context : Error<
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 27b274d74ce716..b64ac3cc676bc3 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -8899,18 +8899,36 @@ void Sema::CheckMemaccessArguments(const CallExpr *Call,
   << ArgIdx << FnName << PointeeTy
   << Call->getCallee()->getSourceRange());
 else if (const auto *RT = PointeeTy->getAs()) {
+
+  bool IsTriviallyCopyableCXXRecord =
+  RT->desugar().isTriviallyCopyableType(Context);
+
   if ((BId == Builtin::BImemset || BId == Builtin::BIbzero) &&
   RT->getDecl()->isNonTrivialToPrimitiveDefaultInitialize()) {
 DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
 PDiag(diag::warn_cstruct_memaccess)
 << ArgIdx << FnName << PointeeTy << 0);
 SearchNonTrivialToInitializeField::diag(PointeeTy, Dest, *this);
+  } else if ((BId == Builtin::BImemset || BId == Builtin::BIbzero) &&
+ !IsTriviallyCopyableCXXRecord && ArgIdx == 0) {
+// FIXME: Limiting this warning to dest argument until we decide
+// whether it's valid for source argument too.
+DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
+PDiag(diag::warn_cxxstruct_memaccess)
+<< ArgIdx << FnName << PointeeTy);
   } else if ((BId == Builtin::BImemcpy || BId == Builtin::BImemmove) &&
  RT->getDecl()->isNonTrivialToPrimitiveCopy()) {
 DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
 PDiag(diag::warn_cstruct_memaccess)
 << ArgIdx << FnName << PointeeTy << 1);
 SearchNonTrivialToCopyField::diag(PointeeTy, Dest, *this);
+  } else if ((BId == Builtin::BImemcpy || BId == Builtin::BImemmove) &&
+ !IsTriviallyCopyableCXXRecord && ArgIdx == 0) {
+// FIXME: Limiting this warning to dest argument until we decide
+// whether it's valid for source argument too.
+DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
+PDiag(diag::warn_cxxstruct_memaccess)
+<< ArgIdx << FnName << PointeeTy);
   } else {
 continue;
   }
diff --git a/clang/test/SemaCXX/constexpr-string.cpp 
b/clang/test/SemaCXX/constexpr-string.cpp
index c456740ef7551f..41305e3f8bcba5 100644
--- a/clang/test/SemaCXX/constexpr-string.cpp
+++ b/clang/test/SemaCXX/constexpr-string.cpp
@@ -670,6 +670,8 @@ namespace MemcpyEtc {
   constexpr bool test_address_of_incomplete_struct_type()

[clang] [Clang] Disable use of the counted_by attribute for whole struct pointers (PR #112636)

2024-10-25 Thread Jan Hendrik Farr via cfe-commits

Cydox wrote:

I was forgetting about the padding when thinking about this part of the quote:
> it behaves as if that member were replaced with the longest array (with the 
> same element type) that would not make **the structure** larger than the 
> object being accessed

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


[clang] [Clang] fix range calculation for conditionals with throw expressions (PR #112081)

2024-10-25 Thread Oleksandr T. via cfe-commits

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

>From 67c41612085489a2a17eec49f98dbfa0e5bb97cf Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 12 Oct 2024 08:27:51 +0300
Subject: [PATCH 1/3] [Clang] fix range calculation for conditionals with throw
 expressions

---
 clang/docs/ReleaseNotes.rst | 1 +
 clang/lib/Sema/SemaChecking.cpp | 3 +++
 clang/test/SemaCXX/conditional-expr.cpp | 7 +++
 3 files changed, 11 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 337e3fc10bf49d..2ab13640bfa53c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -512,6 +512,7 @@ Bug Fixes to C++ Support
   and undeclared templates. (#GH107047, #GH49093)
 - Clang no longer crashes when a lambda contains an invalid block declaration 
that contains an unexpanded
   parameter pack. (#GH109148)
+- Fixed assertion failure in range calculations for conditional throw 
expressions (#GH111854)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2bcb930acdcb57..b3d88f053872c1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9827,6 +9827,9 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
 return IntRange(BitField->getBitWidthValue(C),
 BitField->getType()->isUnsignedIntegerOrEnumerationType());
 
+  if (GetExprType(E)->isVoidType())
+return IntRange{0, true};
+
   return IntRange::forValueOfType(C, GetExprType(E));
 }
 
diff --git a/clang/test/SemaCXX/conditional-expr.cpp 
b/clang/test/SemaCXX/conditional-expr.cpp
index 01effaa189322b..8f17555fd806ff 100644
--- a/clang/test/SemaCXX/conditional-expr.cpp
+++ b/clang/test/SemaCXX/conditional-expr.cpp
@@ -429,3 +429,10 @@ void g() {
   long e = a = b ? throw 0 : throw 1;
 }
 } // namespace PR46484
+
+namespace GH111854 {
+void f() {
+  (true ? throw 0 : 0) <= 0;  // expected-warning {{relational comparison 
result unused}}
+  (false ? 0 : throw 0) <= 0; // expected-warning {{relational comparison 
result unused}}
+}
+}

>From 9c2a745ed365449be45cd062f29c89cabde0f514 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 19 Oct 2024 00:00:19 +0300
Subject: [PATCH 2/3] change return type to nullable for handling invalid
 ranges in integer expression evaluation

---
 clang/lib/Sema/SemaChecking.cpp | 198 +++-
 1 file changed, 118 insertions(+), 80 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b3d88f053872c1..2ca342a6065550 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9582,8 +9582,10 @@ static QualType GetExprType(const Expr *E) {
 ///particular, assume that arithmetic on narrower types doesn't leave
 ///those types. If \c false, return a range including all possible
 ///result values.
-static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth,
- bool InConstantContext, bool Approximate) {
+static std::optional TryGetExprRange(ASTContext &C, const Expr *E,
+   unsigned MaxWidth,
+   bool InConstantContext,
+   bool Approximate) {
   E = E->IgnoreParens();
 
   // Try a full evaluation first.
@@ -9596,8 +9598,8 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
   // being of the new, wider type.
   if (const auto *CE = dyn_cast(E)) {
 if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_LValueToRValue)
-  return GetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
-  Approximate);
+  return TryGetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
+ Approximate);
 
 IntRange OutputTypeRange = IntRange::forValueOfType(C, GetExprType(CE));
 
@@ -9608,40 +9610,52 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
 if (!isIntegerCast)
   return OutputTypeRange;
 
-IntRange SubRange = GetExprRange(C, CE->getSubExpr(),
- std::min(MaxWidth, OutputTypeRange.Width),
- InConstantContext, Approximate);
+std::optional SubRange = TryGetExprRange(
+C, CE->getSubExpr(), std::min(MaxWidth, OutputTypeRange.Width),
+InConstantContext, Approximate);
+if (!SubRange)
+  return std::nullopt;
 
 // Bail out if the subexpr's range is as wide as the cast type.
-if (SubRange.Width >= OutputTypeRange.Width)
+if (SubRange->Width >= OutputTypeRange.Width)
   return OutputTypeRange;
 
 // Otherwise, we take the smaller width, and we're non-negative if
 // either the output type or the subexpr is.
-  

[clang] [Clang] fix range calculation for conditionals with throw expressions (PR #112081)

2024-10-25 Thread Oleksandr T. via cfe-commits

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

>From 67c41612085489a2a17eec49f98dbfa0e5bb97cf Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 12 Oct 2024 08:27:51 +0300
Subject: [PATCH 1/3] [Clang] fix range calculation for conditionals with throw
 expressions

---
 clang/docs/ReleaseNotes.rst | 1 +
 clang/lib/Sema/SemaChecking.cpp | 3 +++
 clang/test/SemaCXX/conditional-expr.cpp | 7 +++
 3 files changed, 11 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 337e3fc10bf49d..2ab13640bfa53c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -512,6 +512,7 @@ Bug Fixes to C++ Support
   and undeclared templates. (#GH107047, #GH49093)
 - Clang no longer crashes when a lambda contains an invalid block declaration 
that contains an unexpanded
   parameter pack. (#GH109148)
+- Fixed assertion failure in range calculations for conditional throw 
expressions (#GH111854)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2bcb930acdcb57..b3d88f053872c1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9827,6 +9827,9 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
 return IntRange(BitField->getBitWidthValue(C),
 BitField->getType()->isUnsignedIntegerOrEnumerationType());
 
+  if (GetExprType(E)->isVoidType())
+return IntRange{0, true};
+
   return IntRange::forValueOfType(C, GetExprType(E));
 }
 
diff --git a/clang/test/SemaCXX/conditional-expr.cpp 
b/clang/test/SemaCXX/conditional-expr.cpp
index 01effaa189322b..8f17555fd806ff 100644
--- a/clang/test/SemaCXX/conditional-expr.cpp
+++ b/clang/test/SemaCXX/conditional-expr.cpp
@@ -429,3 +429,10 @@ void g() {
   long e = a = b ? throw 0 : throw 1;
 }
 } // namespace PR46484
+
+namespace GH111854 {
+void f() {
+  (true ? throw 0 : 0) <= 0;  // expected-warning {{relational comparison 
result unused}}
+  (false ? 0 : throw 0) <= 0; // expected-warning {{relational comparison 
result unused}}
+}
+}

>From 9c2a745ed365449be45cd062f29c89cabde0f514 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 19 Oct 2024 00:00:19 +0300
Subject: [PATCH 2/3] change return type to nullable for handling invalid
 ranges in integer expression evaluation

---
 clang/lib/Sema/SemaChecking.cpp | 198 +++-
 1 file changed, 118 insertions(+), 80 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b3d88f053872c1..2ca342a6065550 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9582,8 +9582,10 @@ static QualType GetExprType(const Expr *E) {
 ///particular, assume that arithmetic on narrower types doesn't leave
 ///those types. If \c false, return a range including all possible
 ///result values.
-static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth,
- bool InConstantContext, bool Approximate) {
+static std::optional TryGetExprRange(ASTContext &C, const Expr *E,
+   unsigned MaxWidth,
+   bool InConstantContext,
+   bool Approximate) {
   E = E->IgnoreParens();
 
   // Try a full evaluation first.
@@ -9596,8 +9598,8 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
   // being of the new, wider type.
   if (const auto *CE = dyn_cast(E)) {
 if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_LValueToRValue)
-  return GetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
-  Approximate);
+  return TryGetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
+ Approximate);
 
 IntRange OutputTypeRange = IntRange::forValueOfType(C, GetExprType(CE));
 
@@ -9608,40 +9610,52 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
 if (!isIntegerCast)
   return OutputTypeRange;
 
-IntRange SubRange = GetExprRange(C, CE->getSubExpr(),
- std::min(MaxWidth, OutputTypeRange.Width),
- InConstantContext, Approximate);
+std::optional SubRange = TryGetExprRange(
+C, CE->getSubExpr(), std::min(MaxWidth, OutputTypeRange.Width),
+InConstantContext, Approximate);
+if (!SubRange)
+  return std::nullopt;
 
 // Bail out if the subexpr's range is as wide as the cast type.
-if (SubRange.Width >= OutputTypeRange.Width)
+if (SubRange->Width >= OutputTypeRange.Width)
   return OutputTypeRange;
 
 // Otherwise, we take the smaller width, and we're non-negative if
 // either the output type or the subexpr is.
-  

[clang] [flang] [flang] Add UNSIGNED (PR #113504)

2024-10-25 Thread via cfe-commits


@@ -400,6 +400,69 @@ constexpr TypeBuilderFunc getModel() {
 return fir::ReferenceType::get(f(context));
   };
 }
+template <>
+constexpr TypeBuilderFunc getModel() {
+  return getModel();

jeanPerier wrote:

I think we need to keep track of the unsigned aspect in the signature because 
the LLVM signature for unsigned short is different than for signed short 
(`zeroext` attribute vs `signext` attribute)

See  https://godbolt.org/z/Yo94sdxE9, that shows `clang -emit-llvm` output for:
```
short test_signed(short x) {return x;}
unsigned short test_unsigned(unsigned short x) {return x;}
```

LLVM:
```
define dso_local signext i16 @test_signed(i16 noundef signext)
define dso_local zeroext i16 @test_unsigned(i16 noundef zeroext)
```

These attributes are important (flang used to not generate signext for short, 
and this caused a [bug in 
gamess](https://github.com/llvm/llvm-project/commit/ff794116f9815979f9a3a1195aff9be49334da7a)).

The same concern probably applies to BIND(C) contexts.


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


[clang] [clang-linker-wrapper] Add error handling for missing linker path (PR #113613)

2024-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Arvind Sudarsanam (asudarsa)


Changes

In clang-linker-wrapper, we do not explicitly check if --linker-path is 
provided.
This PR adds a check to capture this.

Thanks

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


2 Files Affected:

- (modified) clang/test/Driver/linker-wrapper.c (+4) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+2) 


``diff
diff --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index 068ea2d7d3c663..4ab4051f37553e 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -250,3 +250,7 @@ __attribute__((visibility("protected"), used)) int x;
 //   MLLVM-SAME: -Xlinker -mllvm=-pass-remarks=foo,bar
 //  OFFLOAD-OPT-NOT: -Xlinker -mllvm=-pass-remarks=foo,bar
 // OFFLOAD-OPT-SAME: {{$}}
+
+// Error handling when --linker-path is not provided for clang-linker-wrapper
+// RUN: not clang-linker-wrapper 2>&1 | FileCheck 
--check-prefix=LINKER-PATH-NOT-PROVIDED %s
+// LINKER-PATH-NOT-PROVIDED: Host linker is not available
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 9fea1fdcd5fb46..8000d0e1f48dad 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -370,6 +370,8 @@ Error runLinker(ArrayRef Files, const ArgList 
&Args) {
   // Render the linker arguments and add the newly created image. We add it
   // after the output file to ensure it is linked with the correct libraries.
   StringRef LinkerPath = Args.getLastArgValue(OPT_linker_path_EQ);
+  if (LinkerPath.empty())
+return createStringError("Host linker is not available");
   ArgStringList NewLinkerArgs;
   for (const opt::Arg *Arg : Args) {
 // Do not forward arguments only intended for the linker wrapper.

``




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


[clang] [flang] [flang] Add UNSIGNED (PR #113504)

2024-10-25 Thread Peter Klausler via cfe-commits

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


[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-25 Thread Dan Liew via cfe-commits


@@ -2438,6 +2438,22 @@ bool Type::isIncompleteType(NamedDecl **Def) const {
   }
 }
 
+bool Type::isIncompletableIncompleteType() const {
+  if (!isIncompleteType())
+return false;
+
+  // Forward declarations of structs, classes, enums, and unions could be later
+  // completed in a compilation unit by providing a type definition.
+  if (isStructureOrClassType() || isEnumeralType() || isUnionType())
+return false;
+
+  // Other types are incompletable.
+  //
+  // E.g. `char[]` and `void`. The type is incomplete and no future
+  // type declarations can make the type complete.
+  return true;
+}
+

delcypher wrote:

I've reworked this.

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


[clang] [llvm] [ci] New script to generate test reports as Buildkite Annotations (PR #113447)

2024-10-25 Thread David Spickett via cfe-commits


@@ -0,0 +1,328 @@
+# Script to parse many JUnit XML result files and send a report to the 
buildkite
+# agent as an annotation.
+#
+# To run the unittests:
+# python3 -m unittest discover -p generate_test_report.py
+
+import argparse
+import unittest
+from io import StringIO
+from junitparser import JUnitXml, Failure
+from textwrap import dedent
+from subprocess import check_call
+
+
+def junit_from_xml(xml):
+return JUnitXml.fromfile(StringIO(xml))
+
+
+class TestReports(unittest.TestCase):
+def test_title_only(self):
+self.assertEqual(_generate_report("Foo", []), ("", None))
+
+def test_no_tests_in_testsuite(self):
+self.assertEqual(
+_generate_report(
+"Foo",
+[
+junit_from_xml(
+dedent(
+"""\
+  
+  
+  
+  
+  """
+)
+)
+],
+),
+("", None),
+)
+
+def test_no_failures(self):
+self.assertEqual(
+_generate_report(
+"Foo",
+[
+junit_from_xml(
+dedent(
+"""\
+  
+  
+  
+  
+  
+  """
+)
+)
+],
+),
+(
+dedent(
+"""\
+  # Foo
+
+  * 1 test passed"""
+),
+"success",
+),
+)
+
+def test_report_single_file_single_testsuite(self):
+self.assertEqual(
+_generate_report(
+"Foo",
+[
+junit_from_xml(
+dedent(
+"""\
+  
+  
+  
+  
+  
+
+  
+  
+
+  
+  
+
+  
+  
+  """
+)
+)
+],
+),
+(
+dedent(
+"""\
+  # Foo
+
+  * 1 test passed
+  * 1 test skipped
+  * 2 tests failed
+
+  ## Failed tests
+  (click to see output)
+
+  ### Bar
+  
+  Bar/test_3/test_3
+
+  ```
+  Output goes here
+  ```
+  
+  
+  Bar/test_4/test_4
+
+  ```
+  Other output goes here
+  ```
+  """
+),
+"error",
+),
+)
+
+MULTI_SUITE_OUTPUT = (
+dedent(
+"""\
+# ABC and DEF
+
+* 1 test passed
+* 1 test skipped
+* 2 tests failed
+
+## Failed tests
+(click to see output)
+
+### ABC
+
+ABC/test_2/test_2
+
+```
+ABC/test_2 output goes here
+```
+
+
+### DEF
+
+DEF/test_2/test_2
+
+```
+DEF/test_2 output goes here
+```
+"""
+),
+"error",
+)
+
+def test_report_single_file_multiple_testsuites(self):
+self.assertEqual(
+_generate_report(
+"ABC and DEF",
+[
+junit_from_xml(
+dedent(
+"""\
+  
+  
+  
+  
+  
+
+  
+  
+  
+  
+
+  
+  
+
+  
+  
+  """
+)
+)
+],
+),
+self.MULTI_SUITE_OUTPUT,
+)
+
+def test_report_multiple_files_multiple_testsuites(self):
+self.assertEqual(
+_generate_report(
+"ABC and DEF",
+[
+junit_from_xml(
+dedent(
+"""\
+  
+  
+  
+  
+  
+
+  
+  
+  """
+)
+),
+junit_from_xml(
+dedent(
+"""\
+  
+  
+  
+  
+
+  
+  
+
+  
+  
+  """
+)
+),
+],
+),
+self.MULTI_SUITE_OUTPUT,
+)
+
+
+def _generate_report(title, junit_objects):
+style = None
+
+if not junit_objects:
+return ("", style)
+
+failures = {}
+tests_run = 0
+tests_skipped = 0
+tests_failed = 0
+
+for results in junit_objects:
+for testsuite in result

[clang] [llvm] [HLSL] Re-implement countbits with the correct return type (PR #113189)

2024-10-25 Thread Justin Bogner via cfe-commits

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

A couple of minor style nitpicks, but otherwise this LGTM!

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


[clang] [Clang]: enhance handling of [[deprecated]] attribute diagnostics for local variables (PR #113575)

2024-10-25 Thread Oleksandr T. via cfe-commits

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

>From 67a48d3861b44bd5c37fc9740ee2c54ddd1a8d1b Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 24 Oct 2024 17:21:39 +0300
Subject: [PATCH 1/2] [Clang] enhance handling of [[deprecated]] attribute
 diagnostics for local variables

---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/lib/Sema/SemaAvailability.cpp |  6 ++
 clang/test/SemaCXX/deprecated.cpp   | 14 ++
 3 files changed, 22 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 28bb83a1c9d60f..89c97d4b6631f2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -424,6 +424,8 @@ Improvements to Clang's diagnostics
   name was a reserved name, which we improperly allowed to suppress the
   diagnostic.
 
+- Clang now diagnoses [[deprecated]] attribute usage on local variables 
(#GH90073).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaAvailability.cpp 
b/clang/lib/Sema/SemaAvailability.cpp
index 798cabaa31a476..d62b3eb1a480e7 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -182,6 +182,12 @@ static bool ShouldDiagnoseAvailabilityInContext(
   return false;
   }
 
+  if (K == AR_Deprecated) {
+if (const auto *VD = dyn_cast(OffendingDecl))
+  if (VD->isLocalVarDecl() && VD->isDeprecated())
+return true;
+  }
+
   // Checks if we should emit the availability diagnostic in the context of C.
   auto CheckContext = [&](const Decl *C) {
 if (K == AR_NotYetIntroduced) {
diff --git a/clang/test/SemaCXX/deprecated.cpp 
b/clang/test/SemaCXX/deprecated.cpp
index a93331023f7e21..02fdf0bec5c088 100644
--- a/clang/test/SemaCXX/deprecated.cpp
+++ b/clang/test/SemaCXX/deprecated.cpp
@@ -260,5 +260,19 @@ namespace ArrayComp {
   bool b7 = arr1 == +f();
 }
 
+namespace GH90073 {
+[[deprecated]] int f() { // expected-note {{'f' has been explicitly marked 
deprecated here}}
+  [[deprecated]] int a;  // expected-note {{'a' has been explicitly marked 
deprecated here}} \
+ // expected-note {{'a' has been explicitly marked 
deprecated here}}
+  a = 0;// expected-warning {{'a' is deprecated}}
+  return a; // expected-warning {{'a' is deprecated}}
+}
+
+int main() {
+  f(); // expected-warning {{'f' is deprecated}}
+  return 0;
+}
+}
+
 # 1 "/usr/include/system-header.h" 1 3
 void system_header_function(void) throw();

>From 9ae5428ad5f69b8d6b7a0923f2daf3e059b212c9 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 25 Oct 2024 10:10:15 +0300
Subject: [PATCH 2/2] handle deprecated parameter declarations

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Sema/SemaAvailability.cpp |  2 +-
 clang/test/SemaCXX/deprecated.cpp   | 10 --
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 89c97d4b6631f2..c100dacef53cd9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -424,7 +424,7 @@ Improvements to Clang's diagnostics
   name was a reserved name, which we improperly allowed to suppress the
   diagnostic.
 
-- Clang now diagnoses [[deprecated]] attribute usage on local variables 
(#GH90073).
+- Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/lib/Sema/SemaAvailability.cpp 
b/clang/lib/Sema/SemaAvailability.cpp
index d62b3eb1a480e7..076d3489fa9438 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -184,7 +184,7 @@ static bool ShouldDiagnoseAvailabilityInContext(
 
   if (K == AR_Deprecated) {
 if (const auto *VD = dyn_cast(OffendingDecl))
-  if (VD->isLocalVarDecl() && VD->isDeprecated())
+  if (VD->isLocalVarDeclOrParm() && VD->isDeprecated())
 return true;
   }
 
diff --git a/clang/test/SemaCXX/deprecated.cpp 
b/clang/test/SemaCXX/deprecated.cpp
index 02fdf0bec5c088..667f4d7d3edb03 100644
--- a/clang/test/SemaCXX/deprecated.cpp
+++ b/clang/test/SemaCXX/deprecated.cpp
@@ -261,15 +261,21 @@ namespace ArrayComp {
 }
 
 namespace GH90073 {
-[[deprecated]] int f() { // expected-note {{'f' has been explicitly marked 
deprecated here}}
+[[deprecated]] int f1() { // expected-note {{'f1' has been explicitly marked 
deprecated here}}
   [[deprecated]] int a;  // expected-note {{'a' has been explicitly marked 
deprecated here}} \
  // expected-note {{'a' has been explicitly marked 
deprecated here}}
   a = 0;// expected-warning {{'a' is deprecated}}
   return a; // expected-warning {{'a' is deprecated}}
 }
 
+[[deprecated]] void f2([[deprecated]] int x) { // expected-note {{'f2' has 
been explicitly marked deprecated here}} \
+   // expected-note {{'x' has been 
explicitly mark

[clang] [clang][analyzer][doc] Update Clang SA www docs index.html (PR #112833)

2024-10-25 Thread Endre Fülöp via cfe-commits


@@ -121,10 +80,25 @@ Mac OS X
  
  
   
-   Other Platforms
-   For other platforms, please follow the instructions for building the analyzer from
-   source code.
+The static analyzer is part of Clang. Please refer to the
+https://releases.llvm.org/download.html";>LLVM
+releases page for further instructions.

gamesh411 wrote:

True, I had the GitHub releases page in mind when I typed this, perhaps.

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


[clang] [clang][dataflow] Add a lattice to help cache const accessor methods (PR #111006)

2024-10-25 Thread Nico Weber via cfe-commits


@@ -0,0 +1,218 @@
+//===-- CachedConstAccessorsLattice.h ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the lattice mixin that additionally maintains a cache of
+// stable method call return values to model const accessor member functions.
+//===--===//
+
+#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CACHED_CONST_ACCESSORS_LATTICE_H
+#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CACHED_CONST_ACCESSORS_LATTICE_H
+
+#include "clang/AST/Expr.h"
+#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/StorageLocation.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
+
+namespace clang {
+namespace dataflow {
+
+/// A mixin for a lattice that additionally maintains a cache of stable method
+/// call return values to model const accessors methods. When a non-const 
method
+/// is called, the cache should be cleared causing the next call to a const
+/// method to be considered a different value. NOTE: The user is responsible 
for
+/// clearing the cache.
+///
+/// For example:
+///
+/// class Bar {
+/// public:
+///   const std::optional& getFoo() const;
+///   void clear();
+/// };
+//
+/// void func(Bar& s) {
+///   if (s.getFoo().has_value()) {
+/// use(s.getFoo().value()); // safe (checked earlier getFoo())
+/// s.clear();
+/// use(s.getFoo().value()); // unsafe (invalidate cache for s)
+///   }
+/// }
+template  class CachedConstAccessorsLattice : public Base {
+public:
+  using Base::Base; // inherit all constructors
+
+  /// Creates or returns a previously created `Value` associated with a const
+  /// method call `obj.getFoo()` where `RecordLoc` is the
+  /// `RecordStorageLocation` of `obj`.
+  /// Returns nullptr if unable to find or create a value.
+  ///
+  /// Requirements:
+  ///
+  ///  - `CE` should return a value (not a reference or record type)
+  Value *
+  getOrCreateConstMethodReturnValue(const RecordStorageLocation &RecordLoc,
+const CallExpr *CE, Environment &Env);
+
+  /// Creates or returns a previously created `StorageLocation` associated with
+  /// a const method call `obj.getFoo()` where `RecordLoc` is the
+  /// `RecordStorageLocation` of `obj`.
+  ///
+  /// The callback `Initialize` runs on the storage location if newly created.
+  /// Returns nullptr if unable to find or create a value.
+  ///
+  /// Requirements:
+  ///
+  ///  - `CE` should return a location (GLValue or a record type).
+  StorageLocation *getOrCreateConstMethodReturnStorageLocation(
+  const RecordStorageLocation &RecordLoc, const CallExpr *CE,
+  Environment &Env, llvm::function_ref 
Initialize);
+
+  void clearConstMethodReturnValues(const RecordStorageLocation &RecordLoc) {
+ConstMethodReturnValues.erase(&RecordLoc);
+  }
+
+  void clearConstMethodReturnStorageLocations(
+  const RecordStorageLocation &RecordLoc) {
+ConstMethodReturnStorageLocations.erase(&RecordLoc);
+  }
+
+  bool operator==(const CachedConstAccessorsLattice &Other) const {
+return Base::operator==(Other);
+  }
+
+  LatticeJoinEffect join(const CachedConstAccessorsLattice &Other);
+
+private:
+  // Maps a record storage location and const method to the value to return
+  // from that const method.
+  using ConstMethodReturnValuesType =
+  llvm::SmallDenseMap>;
+  ConstMethodReturnValuesType ConstMethodReturnValues;
+
+  // Maps a record storage location and const method to the record storage
+  // location to return from that const method.
+  using ConstMethodReturnStorageLocationsType = llvm::SmallDenseMap<
+  const RecordStorageLocation *,
+  llvm::SmallDenseMap>;
+  ConstMethodReturnStorageLocationsType ConstMethodReturnStorageLocations;
+};
+
+namespace internal {

nico wrote:

(Here's a build that needs less scrolling to find the diag: 
http://45.33.8.238/win/95994/step_3.txt)

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


[clang] [HLSL] Add RWStructuredBuffer definition to HLSLExternalSemaSource (PR #113477)

2024-10-25 Thread Helena Kotas via cfe-commits


@@ -17,7 +17,7 @@
 // EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
 
 // There should be no more occurrances of StructuredBuffer
-// EMPTY-NOT: StructuredBuffer
+// EMPTY-NOT: {{/s}}StructuredBuffer

hekota wrote:

"/s" is a space in the flavor of regex I learned years ago :) I also found it 
defined here:
https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference



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


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-10-25 Thread Victor Campos via cfe-commits

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


[clang] a291f00 - [WebKit Checkers] Make TrivialFunctionAnalysis recognize std::array::operator[] as trivial (#113377)

2024-10-25 Thread via cfe-commits

Author: Rashmi Mudduluru
Date: 2024-10-24T14:23:29-07:00
New Revision: a291f00edaeeea622a9e3e2c706e3bdb25f93f09

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

LOG: [WebKit Checkers] Make TrivialFunctionAnalysis recognize 
std::array::operator[] as trivial (#113377)

TFA wasn't recognizing `__libcpp_verbose_abort` as trivial causing 
`std::array::operator[]` also not being recognized as trivial.

Added: 
clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg-std-array.cpp

Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index e043806eadd6ac..71440e6d08a1c9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -414,7 +414,8 @@ class TrivialFunctionAnalysisVisitor
 Name == "isMainThreadOrGCThread" || Name == "isMainRunLoop" ||
 Name == "isWebThread" || Name == "isUIThread" ||
 Name == "mayBeGCThread" || Name == "compilerFenceForCrash" ||
-Name == "bitwise_cast" || Name.find("__builtin") == 0)
+Name == "bitwise_cast" || Name.find("__builtin") == 0 ||
+Name == "__libcpp_verbose_abort")
   return true;
 
 return IsFunctionTrivial(Callee);

diff  --git 
a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg-std-array.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg-std-array.cpp
new file mode 100644
index 00..ed28a64bba059c
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg-std-array.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+#include "mock-types.h"
+
+void __libcpp_verbose_abort(const char *__format, ...);
+
+using size_t = __typeof(sizeof(int));
+namespace std{
+template 
+class array {
+  T elements[N];
+  
+  public:
+  T& operator[](unsigned i) {
+if (i >= N) {
+  __libcpp_verbose_abort("%s", "aborting");
+}
+return elements[i];
+  }
+};
+}
+
+class ArrayClass {
+public:
+  void ref() const;
+  void deref() const;
+  typedef std::array, 4> Matrix;
+  double e() { return matrix[3][0]; }
+  Matrix matrix;
+};
+
+class AnotherClass {
+  RefPtr matrix;
+  void test() {
+double val = { matrix->e()};
+  }
+};
+

diff  --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 10da776f81575c..e1dacdd9e25b6d 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -238,6 +238,8 @@ class SomeType : public BaseType {
   using BaseType::BaseType;
 };
 
+void __libcpp_verbose_abort(const char *__format, ...);
+
 class RefCounted {
 public:
   void ref() const;
@@ -361,6 +363,9 @@ class RefCounted {
   void trivial62() { WTFReportBacktrace(); }
   SomeType trivial63() { return SomeType(0); }
   SomeType trivial64() { return SomeType(); }
+  void trivial65() {
+__libcpp_verbose_abort("%s", "aborting");
+  }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -544,6 +549,7 @@ class UnrelatedClass {
 getFieldTrivial().trivial62(); // no-warning
 getFieldTrivial().trivial63(); // no-warning
 getFieldTrivial().trivial64(); // no-warning
+getFieldTrivial().trivial65(); // no-warning
 
 RefCounted::singleton().trivial18(); // no-warning
 RefCounted::singleton().someFunction(); // no-warning



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


[clang] [Clang]: enhance handling of [[deprecated]] attribute diagnostics for local variables (PR #113575)

2024-10-25 Thread Oleksandr T. via cfe-commits


@@ -182,6 +182,12 @@ static bool ShouldDiagnoseAvailabilityInContext(
   return false;
   }
 
+  if (K == AR_Deprecated) {
+if (const auto *VD = dyn_cast(OffendingDecl))
+  if (VD->isLocalVarDecl() && VD->isDeprecated())

a-tarasyuk wrote:

@Sirraide thanks for the feedback. I've added changes.

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


[clang] [Clang] fix range calculation for conditionals with throw expressions (PR #112081)

2024-10-25 Thread Oleksandr T. via cfe-commits

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

>From 67c41612085489a2a17eec49f98dbfa0e5bb97cf Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 12 Oct 2024 08:27:51 +0300
Subject: [PATCH 1/3] [Clang] fix range calculation for conditionals with throw
 expressions

---
 clang/docs/ReleaseNotes.rst | 1 +
 clang/lib/Sema/SemaChecking.cpp | 3 +++
 clang/test/SemaCXX/conditional-expr.cpp | 7 +++
 3 files changed, 11 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 337e3fc10bf49d..2ab13640bfa53c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -512,6 +512,7 @@ Bug Fixes to C++ Support
   and undeclared templates. (#GH107047, #GH49093)
 - Clang no longer crashes when a lambda contains an invalid block declaration 
that contains an unexpanded
   parameter pack. (#GH109148)
+- Fixed assertion failure in range calculations for conditional throw 
expressions (#GH111854)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2bcb930acdcb57..b3d88f053872c1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9827,6 +9827,9 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
 return IntRange(BitField->getBitWidthValue(C),
 BitField->getType()->isUnsignedIntegerOrEnumerationType());
 
+  if (GetExprType(E)->isVoidType())
+return IntRange{0, true};
+
   return IntRange::forValueOfType(C, GetExprType(E));
 }
 
diff --git a/clang/test/SemaCXX/conditional-expr.cpp 
b/clang/test/SemaCXX/conditional-expr.cpp
index 01effaa189322b..8f17555fd806ff 100644
--- a/clang/test/SemaCXX/conditional-expr.cpp
+++ b/clang/test/SemaCXX/conditional-expr.cpp
@@ -429,3 +429,10 @@ void g() {
   long e = a = b ? throw 0 : throw 1;
 }
 } // namespace PR46484
+
+namespace GH111854 {
+void f() {
+  (true ? throw 0 : 0) <= 0;  // expected-warning {{relational comparison 
result unused}}
+  (false ? 0 : throw 0) <= 0; // expected-warning {{relational comparison 
result unused}}
+}
+}

>From 9c2a745ed365449be45cd062f29c89cabde0f514 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 19 Oct 2024 00:00:19 +0300
Subject: [PATCH 2/3] change return type to nullable for handling invalid
 ranges in integer expression evaluation

---
 clang/lib/Sema/SemaChecking.cpp | 198 +++-
 1 file changed, 118 insertions(+), 80 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b3d88f053872c1..2ca342a6065550 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9582,8 +9582,10 @@ static QualType GetExprType(const Expr *E) {
 ///particular, assume that arithmetic on narrower types doesn't leave
 ///those types. If \c false, return a range including all possible
 ///result values.
-static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth,
- bool InConstantContext, bool Approximate) {
+static std::optional TryGetExprRange(ASTContext &C, const Expr *E,
+   unsigned MaxWidth,
+   bool InConstantContext,
+   bool Approximate) {
   E = E->IgnoreParens();
 
   // Try a full evaluation first.
@@ -9596,8 +9598,8 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
   // being of the new, wider type.
   if (const auto *CE = dyn_cast(E)) {
 if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_LValueToRValue)
-  return GetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
-  Approximate);
+  return TryGetExprRange(C, CE->getSubExpr(), MaxWidth, InConstantContext,
+ Approximate);
 
 IntRange OutputTypeRange = IntRange::forValueOfType(C, GetExprType(CE));
 
@@ -9608,40 +9610,52 @@ static IntRange GetExprRange(ASTContext &C, const Expr 
*E, unsigned MaxWidth,
 if (!isIntegerCast)
   return OutputTypeRange;
 
-IntRange SubRange = GetExprRange(C, CE->getSubExpr(),
- std::min(MaxWidth, OutputTypeRange.Width),
- InConstantContext, Approximate);
+std::optional SubRange = TryGetExprRange(
+C, CE->getSubExpr(), std::min(MaxWidth, OutputTypeRange.Width),
+InConstantContext, Approximate);
+if (!SubRange)
+  return std::nullopt;
 
 // Bail out if the subexpr's range is as wide as the cast type.
-if (SubRange.Width >= OutputTypeRange.Width)
+if (SubRange->Width >= OutputTypeRange.Width)
   return OutputTypeRange;
 
 // Otherwise, we take the smaller width, and we're non-negative if
 // either the output type or the subexpr is.
-  

[clang] [Clang] prevent setting default lexical access specifier for missing primary declarations (PR #112424)

2024-10-25 Thread Oleksandr T. via cfe-commits

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

>From a22c6bae4f42f42e67f8e0c2b1f914e50d140099 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 15 Oct 2024 22:43:24 +0300
Subject: [PATCH 1/2] [Clang] prevent setting default lexical access specifier
 for missing primary declarations

---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/lib/Sema/SemaAccess.cpp | 3 ++-
 clang/test/SemaCXX/enum.cpp   | 8 
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 817e3abef8d566..64ffdcde045a3a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -517,6 +517,8 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
+- Fixed an assertion failure when the default lexical access specifier was set 
for missing
+  primary declarations. (#GH112208)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index df6edb21a50dee..8b4a5b70669d84 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -39,7 +39,8 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
 AccessSpecifier LexicalAS) {
   if (!PrevMemberDecl) {
 // Use the lexical access specifier.
-MemberDecl->setAccess(LexicalAS);
+if (LexicalAS != AS_none)
+  MemberDecl->setAccess(LexicalAS);
 return false;
   }
 
diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp
index 9c398cc8da886c..44042d8bf5cfc8 100644
--- a/clang/test/SemaCXX/enum.cpp
+++ b/clang/test/SemaCXX/enum.cpp
@@ -143,3 +143,11 @@ struct PR28903 {
 })
   };
 };
+
+namespace GH112208 {
+class C {
+  enum E { e = 0 };
+  void f(int, enum E;); // expected-error {{ISO C++ forbids forward references 
to 'enum' types}} \
+// expected-error {{unexpected ';' before ')'}}
+};
+}

>From 83ce02f2e0c7a4f5e8e774694240a9c2939bc2fa Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 18 Oct 2024 14:55:47 +0300
Subject: [PATCH 2/2] prevent assertion failure by handling invalid enum
 forward declarations

---
 clang/docs/ReleaseNotes.rst   | 3 +--
 clang/lib/Sema/SemaAccess.cpp | 3 +--
 clang/lib/Sema/SemaDecl.cpp   | 2 ++
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 64ffdcde045a3a..3fd37663ca7bc6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -517,8 +517,7 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
-- Fixed an assertion failure when the default lexical access specifier was set 
for missing
-  primary declarations. (#GH112208)
+- Fixed an assertion failure caused by invalid enum forward declarations. 
(#GH112208)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index 8b4a5b70669d84..df6edb21a50dee 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -39,8 +39,7 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
 AccessSpecifier LexicalAS) {
   if (!PrevMemberDecl) {
 // Use the lexical access specifier.
-if (LexicalAS != AS_none)
-  MemberDecl->setAccess(LexicalAS);
+MemberDecl->setAccess(LexicalAS);
 return false;
   }
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fece22c663d00c..9eb3d06289e88f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17942,6 +17942,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind 
TUK, SourceLocation KWLoc,
 << Name;
 Invalid = true;
   }
+  if (TUK == TagUseKind::Declaration && Name)
+Invalid = true;
 } else if (!PrevDecl) {
   Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New);
 }

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


[clang] [flang] [flang] Add UNSIGNED (PR #113504)

2024-10-25 Thread Peter Klausler via cfe-commits


@@ -135,8 +141,12 @@ static constexpr TypePattern SubscriptInt{IntType, 
KindCode::subscript};
 
 // Match any kind of some intrinsic or derived types
 static constexpr TypePattern AnyInt{IntType, KindCode::any};
+static constexpr TypePattern AnyUnsigned{UnsignedType, KindCode::any};

klausler wrote:

Thanks; removed.

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


[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)

2024-10-25 Thread Jesse Huang via cfe-commits

https://github.com/jaidTw updated 
https://github.com/llvm/llvm-project/pull/112477

>From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001
From: Jesse Huang 
Date: Sun, 13 Oct 2024 15:11:06 +0800
Subject: [PATCH 1/3] [Clang][RISCV] Support -fcf-protection=return for RISC-V

---
 clang/lib/Basic/Targets/RISCV.h   | 7 +++
 clang/lib/CodeGen/CodeGenFunction.cpp | 4 
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index bf40edb8683b3e..3f2cee72fc3731 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo {
 return true;
   }
 
+  bool
+  checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override {
+if (ISAInfo->hasExtension("zimop"))
+  return true;
+return TargetInfo::checkCFProtectionReturnSupported(Diags);
+  }
+
   CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override {
 return CFBranchLabelSchemeKind::FuncSig;
   }
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 2306043c90f406..d8f0f7c14f6b40 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (CodeGenOpts.PointerAuth.IndirectGotos)
 Fn->addFnAttr("ptrauth-indirect-gotos");
 
+  // Add return control flow integrity attributes.
+  if (CodeGenOpts.CFProtectionReturn)
+Fn->addFnAttr("hw-shadow-stack");
+
   // Apply xray attributes to the function (as a string, for now)
   bool AlwaysXRayAttr = false;
   if (const auto *XRayAttr = D ? D->getAttr() : nullptr) {

>From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001
From: Jesse Huang 
Date: Wed, 23 Oct 2024 14:42:35 +0800
Subject: [PATCH 2/3] [Clang][RISCV] Add RISCV check for hw-shadow-stack

---
 clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index d8f0f7c14f6b40..cca52f3769845e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType 
RetTy,
   if (CodeGenOpts.PointerAuth.IndirectGotos)
 Fn->addFnAttr("ptrauth-indirect-gotos");
 
-  // Add return control flow integrity attributes.
-  if (CodeGenOpts.CFProtectionReturn)
+  // Add return control flow integrity attributes for RISCV.
+  if (CodeGenOpts.CFProtectionReturn &&
+  getContext().getTargetInfo().getTriple().isRISCV())
 Fn->addFnAttr("hw-shadow-stack");
 
   // Apply xray attributes to the function (as a string, for now)

>From 11e2e6fc0e06e220ab9f089267b9f691789aa104 Mon Sep 17 00:00:00 2001
From: Jesse Huang 
Date: Thu, 24 Oct 2024 15:39:07 +0800
Subject: [PATCH 3/3] [Clang][RISCV] Add function attribute in RISC-V specific
 code

---
 clang/lib/CodeGen/CodeGenFunction.cpp | 5 -
 clang/lib/CodeGen/Targets/RISCV.cpp   | 4 
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index cca52f3769845e..2306043c90f406 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -899,11 +899,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (CodeGenOpts.PointerAuth.IndirectGotos)
 Fn->addFnAttr("ptrauth-indirect-gotos");
 
-  // Add return control flow integrity attributes for RISCV.
-  if (CodeGenOpts.CFProtectionReturn &&
-  getContext().getTargetInfo().getTriple().isRISCV())
-Fn->addFnAttr("hw-shadow-stack");
-
   // Apply xray attributes to the function (as a string, for now)
   bool AlwaysXRayAttr = false;
   if (const auto *XRayAttr = D ? D->getAttr() : nullptr) {
diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp 
b/clang/lib/CodeGen/Targets/RISCV.cpp
index fd72fe673b9b14..10779f397d1810 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -607,6 +607,10 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
 auto *Fn = cast(GV);
 
 Fn->addFnAttr("interrupt", Kind);
+
+if (CGM.getCodeGenOpts().CFProtectionReturn)
+  Fn->addFnAttr("hw-shadow-stack");
+
   }
 };
 } // namespace

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


[clang] [llvm] [clang][LLVM Demangler] Add a diagnostic that validates that all mang… (PR #111391)

2024-10-25 Thread Viktoriia Bakalova via cfe-commits

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


[clang] [rtsan][NFC] Documentation of suppression flag (PR #112727)

2024-10-25 Thread via cfe-commits


@@ -194,12 +198,43 @@ Some issues with flags can be debugged using the 
``verbosity=$NUM`` flag:
misspelled_flag
...
 
-Disabling
--
+Disabling and suppressing
+-
 
-In some circumstances, you may want to suppress error reporting in a specific 
scope.
+There are multiple ways to suppress error reporting when using 
RealtimeSanitizer.
 
-In C++, this is achieved via  ``__rtsan::ScopedDisabler``. Within the scope 
where the ``ScopedDisabler`` object is instantiated, all sanitizer error 
reports are suppressed. This suppression applies to the current scope as well 
as all invoked functions, including any functions called transitively.
+In general, ``ScopedDisabler`` should be preferred, as it is the most 
performant.
+
+.. list-table:: Suppression methods
+   :widths: 30 15 15 10 70
+   :header-rows: 1
+
+   * - Suppression method
+ - Specified at?
+ - Scope
+ - Run-time cost
+ - Description
+   * - ``ScopedDisabler``
+ - Compile-time
+ - Stack
+ - Very low
+ - Suppresses all sanitizer error reports in the current scope and all 
invoked functions.

davidtrevelyan wrote:

Nice thought. I was marginally in favour of "ignored", but your point here 
makes me lean further towards "ignored". I feel like the user's use cases mean:

- using ScopedDisabler is the user saying "turn off realtimesanitizer"
- using suppressions means "keep using rtsan - hide these errors, but keep note 
of them"

Definitely support splitting the terminology here, but not ultra-strongly if 
anyone feels otherwise

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


[clang] [clang-tools-extra] [clang][modules] Shrink the size of `Module::Headers` (PR #113395)

2024-10-25 Thread via cfe-commits


@@ -263,17 +261,36 @@ class alignas(8) Module {
 FileEntryRef Entry;
   };
 
-  /// Information about a directory name as found in the module map
-  /// file.
+private:
+  static const int NumHeaderKinds = HK_Excluded + 1;
+  // The begin index for a HeaderKind also acts the end index of HeaderKind - 
1.
+  // The extra element at the end acts as the end index of the last HeaderKind.
+  unsigned HeaderKindBeginIndex[NumHeaderKinds + 1] = {};
+  SmallVector HeadersStorage;
+
+public:
+  ArrayRef getAllHeaders() const { return HeadersStorage; }
+  ArrayRef getHeaders(HeaderKind HK) const {
+assert(HK < NumHeaderKinds && "Invalid Module::HeaderKind");
+auto BeginIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK];
+auto EndIt = HeadersStorage.begin() + HeaderKindBeginIndex[HK + 1];

cor3ntin wrote:

Could this not be `HK == NumHeaderKinds ? HeadersStorage.end() :   
HeadersStorage.begin() + HeaderKindBeginIndex[HK + 1];` ?


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


[clang] [clang-tools-extra] [clang][modules] Shrink the size of `Module::Headers` (PR #113395)

2024-10-25 Thread via cfe-commits

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


[clang] [compiler-rt] Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" (PR #113548)

2024-10-25 Thread Jan Patrick Lehr via cfe-commits

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

LGTM

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


[clang] [compiler-rt] Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" (PR #113548)

2024-10-25 Thread Jan Patrick Lehr via cfe-commits

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


[clang] e738a5d - Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" (#113548)

2024-10-25 Thread via cfe-commits

Author: Sebastian Kreutzer
Date: 2024-10-25T10:15:25+02:00
New Revision: e738a5d8e33911381dbd0e1bc5a0109e9ebb62f2

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

LOG: Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 
(#90959)" (#113548)

This fixes remaining issues in my previous PR #90959.

Changes:
- Removed dependency on LLVM header in `xray_interface.cpp`
- Fixed XRay patching for some targets due to missing changes in
architecture-specific patching functions
- Addressed some remaining compiler warnings that I missed in the
previous patch
- Formatting

I have tested these changes on `x86_64` (natively), as well as
`ppc64le`, `aarch64` and `arm32` (cross-compiled and emulated using
qemu).

**Original description:**

This PR introduces shared library (DSO) support for XRay based on a
revised version of the implementation outlined in [this
RFC](https://discourse.llvm.org/t/rfc-upstreaming-dso-instrumentation-support-for-xray/73000).
The feature enables the patching and handling of events from DSOs,
supporting both libraries linked at startup or explicitly loaded, e.g.
via `dlopen`.
This patch adds the following:
- The `-fxray-shared` flag to enable the feature (turned off by default)
- A small runtime library that is linked into every instrumented DSO,
providing position-independent trampolines and code to register with the
main XRay runtime
- Changes to the XRay runtime to support management and patching of
multiple objects

These changes are fully backward compatible, i.e. running without
instrumented DSOs will produce identical traces (in terms of recorded
function IDs) to the previous implementation.

Due to my limited ability to test on other architectures, this feature
is only implemented and tested with x86_64. Extending support to other
architectures is fairly straightforward, requiring only a
position-independent implementation of the architecture-specific
trampoline implementation (see
`compiler-rt/lib/xray/xray_trampoline_x86_64.S` for reference).

This patch does not include any functionality to resolve function IDs
from DSOs for the provided logging/tracing modes. These modes still work
and will record calls from DSOs, but symbol resolution for these
functions in not available. Getting this to work properly requires
recording information about the loaded DSOs and should IMO be discussed
in a separate RFC, as there are mulitple feasible approaches.

-

Co-authored-by: Sebastian Kreutzer 

Added: 
clang/test/Driver/XRay/xray-shared.cpp
compiler-rt/lib/xray/xray_dso_init.cpp
compiler-rt/test/xray/TestCases/Posix/basic-mode-dso.cpp
compiler-rt/test/xray/TestCases/Posix/clang-xray-shared.cpp
compiler-rt/test/xray/TestCases/Posix/dlopen.cpp
compiler-rt/test/xray/TestCases/Posix/dso-dep-chains.cpp
compiler-rt/test/xray/TestCases/Posix/patch-premain-dso.cpp
compiler-rt/test/xray/TestCases/Posix/patching-unpatching-dso.cpp

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/XRayArgs.h
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/XRayArgs.cpp
compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
compiler-rt/cmake/config-ix.cmake
compiler-rt/include/xray/xray_interface.h
compiler-rt/lib/xray/CMakeLists.txt
compiler-rt/lib/xray/xray_AArch64.cpp
compiler-rt/lib/xray/xray_arm.cpp
compiler-rt/lib/xray/xray_hexagon.cpp
compiler-rt/lib/xray/xray_init.cpp
compiler-rt/lib/xray/xray_interface.cpp
compiler-rt/lib/xray/xray_interface_internal.h
compiler-rt/lib/xray/xray_loongarch64.cpp
compiler-rt/lib/xray/xray_mips.cpp
compiler-rt/lib/xray/xray_mips64.cpp
compiler-rt/lib/xray/xray_powerpc64.cpp
compiler-rt/lib/xray/xray_trampoline_x86_64.S
compiler-rt/lib/xray/xray_x86_64.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index eac831278ee20d..e45370bde74a5d 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -136,6 +136,8 @@ CODEGENOPT(XRayIgnoreLoops , 1, 0)
 ///< Emit the XRay function index section.
 CODEGENOPT(XRayFunctionIndex , 1, 1)
 
+///< Set when -fxray-shared is enabled
+CODEGENOPT(XRayShared , 1, 0)
 
 ///< Set the minimum number of instructions in a function to determine 
selective
 ///< XRay instrumentation.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8263fe6f7d7fe6..5df6ddd5e6a0c5 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2948,6 +2948,11 @@ def fxray_selected_function_group :
   HelpText<"When using -fxray-fun

[clang] [flang] [flang] Add UNSIGNED (PR #113504)

2024-10-25 Thread via cfe-commits


@@ -213,6 +213,22 @@ def fir_IntegerType : FIR_Type<"Integer", "int"> {
   }];
 }
 
+def fir_UnsignedType : FIR_Type<"Unsigned", "unsigned"> {

jeanPerier wrote:

I understand the `AnyUnsignedInteger.predicate` is needed, but I do not 
understand why the predicate for this type is needed given I do not see where 
it is generated/used (which I may just have missed in the patch).

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


[clang] [flang] [flang] Add UNSIGNED (PR #113504)

2024-10-25 Thread via cfe-commits


@@ -400,6 +400,69 @@ constexpr TypeBuilderFunc getModel() {
 return fir::ReferenceType::get(f(context));
   };
 }
+template <>
+constexpr TypeBuilderFunc getModel() {
+  return getModel();

jeanPerier wrote:

> The existing code does not distinguish unsigned int from signed int
Oh, I see.

That is likely just because only the short case is likely problematic. The 
[code dealing with target specific 
aspects](https://github.com/llvm/llvm-project/blob/ed6ddffb583beb450c4b0e1747ccd14f7e063105/flang/lib/Optimizer/CodeGen/Target.cpp#L113
 ) that adds signext/zeroext is only triggered for integer types strictly 
smaller that the `int` type.

I think I would favor things being consistent and having the unsigned aspect 
always set here and leave it up to the target aspects to do whatever is needed 
when generating the LLVM IR (that does not have an unsigned integer type, just 
specific operations and integer extension attributes).

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


[clang] [flang] [flang] Add UNSIGNED (PR #113504)

2024-10-25 Thread via cfe-commits

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


[clang] [llvm] [AMDGPU] Add a type for the named barrier (PR #113614)

2024-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Gang Chen (cmc-rep)


Changes



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


13 Files Affected:

- (modified) clang/include/clang/Basic/AMDGPUTypes.def (+8) 
- (modified) clang/include/clang/Serialization/ASTBitCodes.h (+1-1) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+7) 
- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+4) 
- (modified) clang/test/AST/ast-dump-amdgpu-types.c (+9-4) 
- (added) clang/test/CodeGen/amdgpu-barrier-type-debug-info.c (+8) 
- (added) clang/test/CodeGenCXX/amdgpu-barrier-typeinfo.cpp (+10) 
- (added) clang/test/CodeGenHIP/amdgpu-barrier-type.hip (+42) 
- (added) clang/test/SemaCXX/amdgpu-barrier.cpp (+17) 
- (added) clang/test/SemaHIP/amdgpu-barrier.hip (+20) 
- (added) clang/test/SemaOpenCL/amdgpu-barrier.cl (+12) 
- (added) clang/test/SemaOpenMP/amdgpu-barrier.cpp (+17) 
- (modified) llvm/lib/IR/Type.cpp (+8) 


``diff
diff --git a/clang/include/clang/Basic/AMDGPUTypes.def 
b/clang/include/clang/Basic/AMDGPUTypes.def
index e47e544fdc82c1..6b98e311b4cf55 100644
--- a/clang/include/clang/Basic/AMDGPUTypes.def
+++ b/clang/include/clang/Basic/AMDGPUTypes.def
@@ -15,7 +15,15 @@
   AMDGPU_TYPE(Name, Id, SingletonId, Width, Align)
 #endif
 
+#ifndef AMDGPU_NAMED_BARRIER_TYPE
+#define AMDGPU_NAMED_BARRIER_TYPE(Name, Id, SingletonId, Width, Align, Scope) \
+  AMDGPU_TYPE(Name, Id, SingletonId, Width, Align)
+#endif
+
 AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_buffer_rsrc_t", AMDGPUBufferRsrc, 
AMDGPUBufferRsrcTy, 128, 128, 8)
 
+AMDGPU_NAMED_BARRIER_TYPE("__amdgpu_named_workgroup_barrier_t", 
AMDGPUNamedWorkgroupBarrier, AMDGPUNamedWorkgroupBarrierTy, 128, 32, 0)
+
 #undef AMDGPU_TYPE
 #undef AMDGPU_OPAQUE_PTR_TYPE
+#undef AMDGPU_NAMED_BARRIER_TYPE
\ No newline at end of file
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 13173dc96e71ae..99232fd2135790 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1149,7 +1149,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 511;
+const unsigned NUM_PREDEF_TYPE_IDS = 512;
 
 // Ensure we do not overrun the predefined types we reserved
 // in the enum PredefinedTypeIDs above.
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 27bbbfc6f531a1..3f9e14a52fc801 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -909,6 +909,13 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType 
*BT) {
  TheCU, TheCU->getFile(), 0);  
\
 return SingletonId;
\
   }
+#define AMDGPU_NAMED_BARRIER_TYPE(Name, Id, SingletonId, Width, Align, Scope)  
\
+  case BuiltinType::Id: {  
 \
+if (!SingletonId)  
\
+  SingletonId =
\
+  DBuilder.createBasicType(Name, Width, llvm::dwarf::DW_ATE_unsigned); 
\
+return SingletonId;
+  }
 #include "clang/Basic/AMDGPUTypes.def"
   case BuiltinType::UChar:
   case BuiltinType::Char_U:
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index f87184fc77832c..09191a4901f493 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -564,6 +564,10 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
 #define AMDGPU_OPAQUE_PTR_TYPE(Name, Id, SingletonId, Width, Align, AS)
\
   case BuiltinType::Id:
\
 return llvm::PointerType::get(getLLVMContext(), AS);
+#define AMDGPU_NAMED_BARRIER_TYPE(Name, Id, SingletonId, Width, Align, Scope)  
\
+  case BuiltinType::Id:
\
+return llvm::TargetExtType::get(getLLVMContext(), "amdgcn.named.barrier",  
\
+{}, {Scope});
 #include "clang/Basic/AMDGPUTypes.def"
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/HLSLIntangibleTypes.def"
diff --git a/clang/test/AST/ast-dump-amdgpu-types.c 
b/clang/test/AST/ast-dump-amdgpu-types.c
index e032d678f1a09e..f01461cdba2374 100644
--- a/clang/test/AST/ast-dump-amdgpu-types.c
+++ b/clang/test/AST/ast-dump-amdgpu-types.c
@@ -1,10 +1,15 @@
 // REQUIRES: amdgpu-registered-target
 // Test without serialization:
-// RUN: %clang_cc1 -triple amdgcn -ast-dump -ast-dump-filter 
__amdgpu_buffer_rsrc_t %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn -ast-dump -ast-dump-filter 
__amdgpu_buffer_rsrc_t %s | FileCheck %s -check-prefix=BUFFER-RSRC
+// RUN: %clang_cc1 -triple amdgcn -ast-dump -ast-dump-filter

[clang] [Clang] prevent setting default lexical access specifier for missing primary declarations (PR #112424)

2024-10-25 Thread Oleksandr T. via cfe-commits

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

>From a22c6bae4f42f42e67f8e0c2b1f914e50d140099 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 15 Oct 2024 22:43:24 +0300
Subject: [PATCH 1/2] [Clang] prevent setting default lexical access specifier
 for missing primary declarations

---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/lib/Sema/SemaAccess.cpp | 3 ++-
 clang/test/SemaCXX/enum.cpp   | 8 
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 817e3abef8d566..64ffdcde045a3a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -517,6 +517,8 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
+- Fixed an assertion failure when the default lexical access specifier was set 
for missing
+  primary declarations. (#GH112208)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index df6edb21a50dee..8b4a5b70669d84 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -39,7 +39,8 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
 AccessSpecifier LexicalAS) {
   if (!PrevMemberDecl) {
 // Use the lexical access specifier.
-MemberDecl->setAccess(LexicalAS);
+if (LexicalAS != AS_none)
+  MemberDecl->setAccess(LexicalAS);
 return false;
   }
 
diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp
index 9c398cc8da886c..44042d8bf5cfc8 100644
--- a/clang/test/SemaCXX/enum.cpp
+++ b/clang/test/SemaCXX/enum.cpp
@@ -143,3 +143,11 @@ struct PR28903 {
 })
   };
 };
+
+namespace GH112208 {
+class C {
+  enum E { e = 0 };
+  void f(int, enum E;); // expected-error {{ISO C++ forbids forward references 
to 'enum' types}} \
+// expected-error {{unexpected ';' before ')'}}
+};
+}

>From 83ce02f2e0c7a4f5e8e774694240a9c2939bc2fa Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 18 Oct 2024 14:55:47 +0300
Subject: [PATCH 2/2] prevent assertion failure by handling invalid enum
 forward declarations

---
 clang/docs/ReleaseNotes.rst   | 3 +--
 clang/lib/Sema/SemaAccess.cpp | 3 +--
 clang/lib/Sema/SemaDecl.cpp   | 2 ++
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 64ffdcde045a3a..3fd37663ca7bc6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -517,8 +517,7 @@ Bug Fixes to C++ Support
   certain situations. (#GH47400), (#GH90896)
 - Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 - During the lookup for a base class name, non-type names are ignored. 
(#GH16855)
-- Fixed an assertion failure when the default lexical access specifier was set 
for missing
-  primary declarations. (#GH112208)
+- Fixed an assertion failure caused by invalid enum forward declarations. 
(#GH112208)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index 8b4a5b70669d84..df6edb21a50dee 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -39,8 +39,7 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
 AccessSpecifier LexicalAS) {
   if (!PrevMemberDecl) {
 // Use the lexical access specifier.
-if (LexicalAS != AS_none)
-  MemberDecl->setAccess(LexicalAS);
+MemberDecl->setAccess(LexicalAS);
 return false;
   }
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fece22c663d00c..9eb3d06289e88f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17942,6 +17942,8 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind 
TUK, SourceLocation KWLoc,
 << Name;
 Invalid = true;
   }
+  if (TUK == TagUseKind::Declaration && Name)
+Invalid = true;
 } else if (!PrevDecl) {
   Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New);
 }

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-25 Thread Farzon Lotfi via cfe-commits


@@ -95,6 +99,125 @@ static void initializeAlloca(CodeGenFunction &CGF, 
AllocaInst *AI, Value *Size,
   I->addAnnotationMetadata("auto-init");
 }
 
+static Value *handleHlslSplitdouble(const CallExpr *E, CodeGenFunction *CGF) {
+  Value *Op0 = CGF->EmitScalarExpr(E->getArg(0));
+  const auto *OutArg1 = dyn_cast(E->getArg(1));
+  const auto *OutArg2 = dyn_cast(E->getArg(2));
+
+  CallArgList Args;
+  LValue Op1TmpLValue =
+  CGF->EmitHLSLOutArgExpr(OutArg1, Args, OutArg1->getType());
+  LValue Op2TmpLValue =
+  CGF->EmitHLSLOutArgExpr(OutArg2, Args, OutArg2->getType());
+
+  if (CGF->getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee())
+Args.reverseWritebacks();
+
+  Value *LowBits = nullptr;
+  Value *HighBits = nullptr;
+
+  if (CGF->CGM.getTarget().getTriple().isDXIL()) {
+
+llvm::Type *RetElementTy = CGF->Int32Ty;
+if (auto *Op0VecTy = E->getArg(0)->getType()->getAs())
+  RetElementTy = llvm::VectorType::get(
+  CGF->Int32Ty, ElementCount::getFixed(Op0VecTy->getNumElements()));
+auto *RetTy = llvm::StructType::get(RetElementTy, RetElementTy);
+
+CallInst *CI = CGF->Builder.CreateIntrinsic(
+RetTy, Intrinsic::dx_splitdouble, {Op0}, nullptr, "hlsl.splitdouble");
+
+LowBits = CGF->Builder.CreateExtractValue(CI, 0);
+HighBits = CGF->Builder.CreateExtractValue(CI, 1);
+
+  } else {
+// For Non DXIL targets we generate the instructions.
+// TODO: This code accounts for known limitations in
+// SPIR-V and splitdouble. Such should be handled,
+// in a later compilation stage. After [issue link here]

farzonl wrote:

Please add the issue you are refrencing.

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


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

2024-10-25 Thread Louis Dionne via cfe-commits

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


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


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

2024-10-25 Thread Alexey Bader via cfe-commits


@@ -767,6 +768,27 @@ Driver::OpenMPRuntimeKind Driver::getOpenMPRuntime(const 
ArgList &Args) const {
   return RT;
 }
 
+static const char *getDefaultSYCLArch(Compilation &C) {
+  // If -fsycl is supplied we will assume SPIR-V
+  if (C.getDefaultToolChain().getTriple().getArch() == llvm::Triple::x86)

bader wrote:

If I get it right, here we try to check the address size on the host to 
propagate the same size for the device compilation.
If so, I suggest we generalize it for more host targets:

```suggestion
  if (C.getDefaultToolChain().getTriple().isArch32Bit())
```

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


[clang] [llvm] [CUDA] Add a pseudo GPU sm_next which allows overriding for SM/PTX version. (PR #100247)

2024-10-25 Thread Artem Belevich via cfe-commits

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


[clang-tools-extra] [clang-tidy] Create a check for signed and unsigned integers comparison (PR #113144)

2024-10-25 Thread Congcong Cai via cfe-commits


@@ -0,0 +1,168 @@
+//===--- UseIntegerSignComparisonCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseIntegerSignComparisonCheck.h"
+#include "clang/AST/Expr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::ast_matchers::internal;
+
+namespace clang::tidy::modernize {
+
+UseIntegerSignComparisonCheck::UseIntegerSignComparisonCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+   utils::IncludeSorter::IS_LLVM),
+  areDiagsSelfContained()),
+  IsQtApplication(Options.get("IsQtApplication", false)),
+  StringsMatchHeader(Options.get("StringsMatchHeader", "")) {}
+
+void UseIntegerSignComparisonCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IsQtApplication", IsQtApplication);
+  Options.store(Opts, "StringsMatchHeader", StringsMatchHeader);
+}
+
+void UseIntegerSignComparisonCheck::registerMatchers(MatchFinder *Finder) {
+  const auto SignedIntCastExpr = intCastExpression(true, "sIntCastExpression");
+  const auto UnSignedIntCastExpr =
+  intCastExpression(false, "uIntCastExpression");
+
+  // Flag all operators "==", "<=", ">=", "<", ">", "!="
+  // that are used between signed/unsigned
+  const auto CompareOperator =
+  expr(binaryOperator(hasAnyOperatorName("==", "<=", ">=", "<", ">", "!="),
+  anyOf(allOf(hasLHS(SignedIntCastExpr),
+  hasRHS(UnSignedIntCastExpr)),
+allOf(hasLHS(UnSignedIntCastExpr),
+  hasRHS(SignedIntCastExpr)
+  .bind("intComparison");
+
+  Finder->addMatcher(CompareOperator, this);
+}
+
+BindableMatcher UseIntegerSignComparisonCheck::intCastExpression(
+bool IsSigned, const std::string &CastBindName) const {
+  auto IntTypeExpr = expr();
+  if (IsSigned) {
+IntTypeExpr = expr(hasType(qualType(isInteger(), isSignedInteger(;
+  } else {
+IntTypeExpr =
+expr(hasType(qualType(isInteger(), unless(isSignedInteger();
+  }
+
+  const auto ImplicitCastExpr =
+  implicitCastExpr(hasSourceExpression(IntTypeExpr)).bind(CastBindName);
+
+  const auto CStyleCastExpr = cStyleCastExpr(has(ImplicitCastExpr));
+  const auto StaticCastExpr = cxxStaticCastExpr(has(ImplicitCastExpr));
+  const auto FunctionalCastExpr = cxxFunctionalCastExpr(has(ImplicitCastExpr));
+
+  return traverse(TK_AsIs, expr(anyOf(ImplicitCastExpr, CStyleCastExpr,
+  StaticCastExpr, FunctionalCastExpr)));
+}
+
+std::string
+UseIntegerSignComparisonCheck::parseOpCode(BinaryOperator::Opcode code) const {
+  switch (code) {
+  case BO_LT:
+return std::string("cmp_less");
+  case BO_GT:
+return std::string("cmp_greater");
+  case BO_LE:
+return std::string("cmp_less_equal");
+  case BO_GE:
+return std::string("cmp_greater_equal");
+  case BO_EQ:
+return std::string("cmp_equal");
+  case BO_NE:
+return std::string("cmp_not_equal");
+  default:
+return {};
+  }
+}
+
+void UseIntegerSignComparisonCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  IncludeInserter.registerPreprocessor(PP);
+}
+
+void UseIntegerSignComparisonCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *SignedCastExpression =
+  Result.Nodes.getNodeAs("sIntCastExpression");
+  const auto *UnSignedCastExpression =
+  Result.Nodes.getNodeAs("uIntCastExpression");
+  assert(SignedCastExpression);
+  assert(UnSignedCastExpression);
+
+  // Ignore the match if we know that the signed int value is not negative.
+  Expr::EvalResult EVResult;
+  if (!SignedCastExpression->isValueDependent() &&
+  SignedCastExpression->getSubExpr()->EvaluateAsInt(EVResult,
+*Result.Context)) {
+const llvm::APSInt SValue = EVResult.Val.getInt();
+if (SValue.isNonNegative())
+  return;
+  }
+
+  const auto *BinaryOp =
+  Result.Nodes.getNodeAs("intComparison");
+  if (BinaryOp == nullptr)
+return;
+
+  const BinaryOperator::Opcode OpCode = BinaryOp->getOpcode();
+  const auto *Lhs = BinaryOp->getLHS()->IgnoreParenImpCasts();
+  const auto *Rhs = BinaryOp->getRHS()->IgnoreParenImpCasts();
+  if (Lhs == nullptr || Rhs == nullptr)
+return;
+
+  const StringRef LhsString(Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Lhs->getSourceRange()),
+

[clang] [clang-tools-extra] [flang] [llvm] Reland 'Update llvm::Registry to work for LLVM shared library builds on windows' (#109024) (PR #112640)

2024-10-25 Thread Nico Weber via cfe-commits

nico wrote:

This seems to break building of clang-tools-extra binaries: 
http://45.33.8.238/win/95986/step_3.txt

Please take a look and revert for now if it takes a while to fix.

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


[clang] [llvm] Ci report bash (PR #113660)

2024-10-25 Thread David Spickett via cfe-commits

https://github.com/DavidSpickett created 
https://github.com/llvm/llvm-project/pull/113660

None

>From 37886ec83bf246fb366ba2e1f14fa011891073df Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Wed, 23 Oct 2024 11:39:15 +0100
Subject: [PATCH 1/3] [ci] New script to generate test reports as Buildkite
 Annotations

The CI builds now send the results of every lit run to a unique file.
This means we can read them all to make a combined report for all
tests.

This report will be shown as an "annotation" in the build results:
https://buildkite.com/docs/agent/v3/cli-annotate#creating-an-annotation

Here is an example: 
https://buildkite.com/llvm-project/github-pull-requests/builds/112546
(make sure it is showing "All" instead of "Failures")

This is an alternative to using the existing Buildkite plugin:
https://github.com/buildkite-plugins/junit-annotate-buildkite-plugin

As the plugin is:
* Specific to Buildkite, and we may move away from Buildkite.
* Requires docker, unless we were to fork it ourselves.
* Does not let you customise the report format unless again,
  we make our own fork.

Annotations use GitHub's flavour of Markdown so the main code in the
script generates that text. There is an extra "style" argument generated
to make the formatting nicer in Buildkite.

"context" is the name of the annotation that will be created. By using
different context names for Linux and Windows results we get 2 separate
annotations.

The script also handles calling the buildkite-agent. This makes passing
extra arguments to the agent easier, rather than piping the output of
this script into the agent.

In the future we can remove the agent part of it and simply use
the report content. Either printed to stdout or as a comment on
the GitHub PR.
---
 .ci/generate_test_report.py | 328 
 .ci/monolithic-linux.sh |   8 +-
 .ci/monolithic-windows.sh   |   8 +-
 3 files changed, 340 insertions(+), 4 deletions(-)
 create mode 100644 .ci/generate_test_report.py

diff --git a/.ci/generate_test_report.py b/.ci/generate_test_report.py
new file mode 100644
index 00..f2ae116ace99af
--- /dev/null
+++ b/.ci/generate_test_report.py
@@ -0,0 +1,328 @@
+# Script to parse many JUnit XML result files and send a report to the 
buildkite
+# agent as an annotation.
+#
+# To run the unittests:
+# python3 -m unittest discover -p generate_test_report.py
+
+import argparse
+import unittest
+from io import StringIO
+from junitparser import JUnitXml, Failure
+from textwrap import dedent
+from subprocess import check_call
+
+
+def junit_from_xml(xml):
+return JUnitXml.fromfile(StringIO(xml))
+
+
+class TestReports(unittest.TestCase):
+def test_title_only(self):
+self.assertEqual(_generate_report("Foo", []), ("", None))
+
+def test_no_tests_in_testsuite(self):
+self.assertEqual(
+_generate_report(
+"Foo",
+[
+junit_from_xml(
+dedent(
+"""\
+  
+  
+  
+  
+  """
+)
+)
+],
+),
+("", None),
+)
+
+def test_no_failures(self):
+self.assertEqual(
+_generate_report(
+"Foo",
+[
+junit_from_xml(
+dedent(
+"""\
+  
+  
+  
+  
+  
+  """
+)
+)
+],
+),
+(
+dedent(
+"""\
+  # Foo
+
+  * 1 test passed"""
+),
+"success",
+),
+)
+
+def test_report_single_file_single_testsuite(self):
+self.assertEqual(
+_generate_report(
+"Foo",
+[
+junit_from_xml(
+dedent(
+"""\
+  
+  
+  
+  
+  
+
+  
+  
+
+  
+  
+
+  
+  
+  """
+)
+)
+],
+),
+(
+dedent(
+"""\
+  # Foo
+
+  * 1 test passed
+  * 1 test skipped
+  * 2 tests failed
+
+  ## Failed tests
+  (click to see output)
+
+  ### Bar
+  
+  Bar/test_3/test_3
+
+  ```
+  Output goes here
+  ```
+  
+  
+  Bar/test_4/test_4
+
+  ```
+  Other output goes here
+  ```
+  """
+),
+"error",
+),
+)
+
+MULTI_SUITE_OUTPUT = (
+dedent(
+"""\
+#

[clang] [analyzer] Untangle subcheckers of CStringChecker (PR #113312)

2024-10-25 Thread Balazs Benics via cfe-commits

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


[clang] [llvm] [HLSL][SPIRV] Added clamp intrinsic (PR #113394)

2024-10-25 Thread Farzon Lotfi via cfe-commits


@@ -40,8 +40,9 @@ def int_dx_cast_handle : Intrinsic<[llvm_any_ty], 
[llvm_any_ty]>;
 
 def int_dx_all : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_any_ty], 
[IntrNoMem]>;
 def int_dx_any : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_any_ty], 
[IntrNoMem]>;
-def int_dx_clamp : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, 
LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoMem]>;
 def int_dx_uclamp : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, 
LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoMem]>;
+def int_dx_sclamp : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, 
LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoMem]>;
+def int_dx_nclamp : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], 
[LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoMem]>;

farzonl wrote:

Were there tests in `llvm/test/CodeGen/DirectX/` that need to be updated?

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


[clang] Update std symbols mapping (fixes #113494) (PR #113612)

2024-10-25 Thread Vadim D. via cfe-commits

https://github.com/vvd170501 created 
https://github.com/llvm/llvm-project/pull/113612

None

>From 8fac50dc444eeb6c9ad19eb11f7d95457b153528 Mon Sep 17 00:00:00 2001
From: vvd170501 <36827317+vvd170...@users.noreply.github.com>
Date: Thu, 24 Oct 2024 17:36:22 +0300
Subject: [PATCH 1/2] Move assertion to detect all ungrouped mappings

---
 clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index 0832bcf66145fa..49e5765af112ff 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -115,15 +115,17 @@ static int initialize(Lang Language) {
   NSLen = 0;
 }
 
-if (SymIndex >= 0 &&
-Mapping->SymbolNames[SymIndex].qualifiedName() == QName) {
-  // Not a new symbol, use the same index.
+if (SymIndex > 0) {
   assert(llvm::none_of(llvm::ArrayRef(Mapping->SymbolNames, SymIndex),
[&QName](const SymbolHeaderMapping::SymbolName &S) {
  return S.qualifiedName() == QName;
}) &&
  "The symbol has been added before, make sure entries in the .inc "
  "file are grouped by symbol name!");
+}
+if (SymIndex >= 0 &&
+Mapping->SymbolNames[SymIndex].qualifiedName() == QName) {
+  // Not a new symbol, use the same index.
 } else {
   // First symbol or new symbol, increment next available index.
   ++SymIndex;

>From ba2d997ba87e2a5193429d3ca4900d4ae39420b7 Mon Sep 17 00:00:00 2001
From: vvd170501 <36827317+vvd170...@users.noreply.github.com>
Date: Wed, 23 Oct 2024 23:22:56 +0300
Subject: [PATCH 2/2] Update std symbol mapping to v20230810

---
 .../Inclusions/Stdlib/StdSpecialSymbolMap.inc | 130 -
 .../Inclusions/Stdlib/StdSymbolMap.inc| 171 --
 2 files changed, 194 insertions(+), 107 deletions(-)

diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
index 0d351d688a3296..156e1e8ad5321c 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -233,6 +233,23 @@ SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
 
+// Overloads for different containers, actual header depends on function arg.
+// Probably should use a special handler, like with std::move.
+SYMBOL(erase, std::, )
+SYMBOL(erase, std::, )
+SYMBOL(erase, std::, )
+SYMBOL(erase, std::, )
+SYMBOL(erase, std::, )
+SYMBOL(erase_if, std::, )
+SYMBOL(erase_if, std::, )
+SYMBOL(erase_if, std::, )
+SYMBOL(erase_if, std::, )
+SYMBOL(erase_if, std::, )
+SYMBOL(erase_if, std::, )
+SYMBOL(erase_if, std::, )
+SYMBOL(erase_if, std::, )
+SYMBOL(erase_if, std::, )
+
 // Add headers for generic integer-type abs.
 // Ignore other variants (std::complex, std::valarray, std::intmax_t)
 SYMBOL(abs, std::, )
@@ -242,9 +259,77 @@ SYMBOL(abs, None, )
 SYMBOL(abs, None, )
 SYMBOL(abs, None, )
 
-// Only add headers for the generic atomic template.
+// Same as abs - ignore variants (std::complex, std::valarray)
+SYMBOL(acos, std::, )
+SYMBOL(acos, None, )
+SYMBOL(acos, None, )
+SYMBOL(acosh, std::, )
+SYMBOL(acosh, None, )
+SYMBOL(acosh, None, )
+SYMBOL(asin, std::, )
+SYMBOL(asin, None, )
+SYMBOL(asin, None, )
+SYMBOL(asinh, std::, )
+SYMBOL(asinh, None, )
+SYMBOL(asinh, None, )
+SYMBOL(atan, std::, )
+SYMBOL(atan, None, )
+SYMBOL(atan, None, )
+SYMBOL(atan2, std::, )
+SYMBOL(atan2, None, )
+SYMBOL(atan2, None, )
+SYMBOL(atanh, std::, )
+SYMBOL(atanh, None, )
+SYMBOL(atanh, None, )
+SYMBOL(cos, std::, )
+SYMBOL(cos, None, )
+SYMBOL(cos, None, )
+SYMBOL(cosh, std::, )
+SYMBOL(cosh, None, )
+SYMBOL(cosh, None, )
+SYMBOL(exp, std::, )
+SYMBOL(exp, None, )
+SYMBOL(exp, None, )
+SYMBOL(log, std::, )
+SYMBOL(log, None, )
+SYMBOL(log, None, )
+SYMBOL(log10, std::, )
+SYMBOL(log10, None, )
+SYMBOL(log10, None, )
+SYMBOL(pow, std::, )
+SYMBOL(pow, None, )
+SYMBOL(pow, None, )
+SYMBOL(sin, std::, )
+SYMBOL(sin, None, )
+SYMBOL(sin, None, )
+SYMBOL(sinh, std::, )
+SYMBOL(sinh, None, )
+SYMBOL(sinh, None, )
+SYMBOL(sqrt, std::, )
+SYMBOL(sqrt, None, )
+SYMBOL(sqrt, None, )
+SYMBOL(tan, std::, )
+SYMBOL(tan, None, )
+SYMBOL(tan, None, )
+SYMBOL(tanh, std::, )
+SYMBOL(tanh, None, )
+SYMBOL(tanh, None, )
+
+// Only add headers for the generic atomic template and atomic_* template 
functions.
 // Ignore variants (std::weak_ptr, std::shared_ptr).
 SYMBOL(atomic, std::, )
+SYMBOL(atomic_compare_exchange_strong, std::, )
+SYMBOL(atomic_compare_exchange_strong_explicit, std::, )
+SYMBOL(atomic_compare_exchange_weak, std::, )
+SYMBOL(atomic_compare_exchange_weak_explicit, std::, )
+SYMBOL(atomic_exchange, std::, )
+SYMBOL(atomic_exchange_explicit, std::, )
+

[clang] [rtsan][NFC] Documentation of suppression flag (PR #112727)

2024-10-25 Thread Chris Apple via cfe-commits


@@ -194,12 +198,43 @@ Some issues with flags can be debugged using the 
``verbosity=$NUM`` flag:
misspelled_flag
...
 
-Disabling
--
+Disabling and suppressing
+-
 
-In some circumstances, you may want to suppress error reporting in a specific 
scope.
+There are multiple ways to suppress error reporting when using 
RealtimeSanitizer.
 
-In C++, this is achieved via  ``__rtsan::ScopedDisabler``. Within the scope 
where the ``ScopedDisabler`` object is instantiated, all sanitizer error 
reports are suppressed. This suppression applies to the current scope as well 
as all invoked functions, including any functions called transitively.
+In general, ``ScopedDisabler`` should be preferred, as it is the most 
performant.
+
+.. list-table:: Suppression methods
+   :widths: 30 15 15 10 70
+   :header-rows: 1
+
+   * - Suppression method
+ - Specified at?
+ - Scope
+ - Run-time cost
+ - Description
+   * - ``ScopedDisabler``
+ - Compile-time
+ - Stack
+ - Very low
+ - Suppresses all sanitizer error reports in the current scope and all 
invoked functions.

cjappl wrote:

How are you feeling about this a week on?

I'm fine with changing it, but wanted to check to see if your opinion had 
shifted. I think one thing that puts me in camp "ignored" is that anything 
ignored by the ScopedDisabler will not show up in our exit statistics as a 
"suppressed error count".

Therefore I think it's OK to split the terminology. If you still feel like this 
would be a good idea I would change it.

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


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

2024-10-25 Thread via cfe-commits

https://github.com/CarolineConcatto updated 
https://github.com/llvm/llvm-project/pull/97277

>From eb12648031be0f225fdd1faba08ee76f8f3bb2f0 Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Mon, 24 Jun 2024 09:59:24 +
Subject: [PATCH] [CLANG][AArch64] Add the  modal 8 bit floating-point scalar
 type

ARM ACLE PR#323[1] adds new modal types for 8-bit floating point intrinsic.

>From the PR#323:
```
ACLE defines the `__mfp8` type, which can be used for the E5M2 and E4M3
8-bit floating-point formats. It is a storage and interchange only type
with no arithmetic operations other than intrinsic calls.


The type should be an opaque type and its format in undefined in Clang.
Only defined in the backend by a status/format register, for AArch64 the FPMR.

This patch is an attempt to the add the MFloat8_t scalar type.
It has a parser and codegen for the new scalar type.

The patch it is lowering to and 8bit unsigned as it has no format.
But maybe we should add another opaque type.

[1]  https://github.com/ARM-software/acle/pull/323
---
 .../clang/Basic/AArch64SVEACLETypes.def   | 13 +++
 .../include/clang/Serialization/ASTBitCodes.h |  2 +-
 clang/lib/AST/ASTContext.cpp  | 11 +++
 clang/lib/AST/ItaniumMangle.cpp   |  5 +
 clang/lib/AST/Type.cpp|  3 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  7 ++
 clang/lib/CodeGen/CodeGenTypes.cpp|  2 +
 clang/test/AST/arm-mfp8.cpp   | 91 +++
 clang/test/CodeGen/aarch64-debug-types.c  |  9 ++
 clang/test/CodeGen/arm-mfp8.c | 34 +++
 clang/test/Modules/no-external-type-id.cppm   |  2 +-
 clang/test/Sema/arm-mfp8.c| 11 +++
 clang/test/Sema/arm-mfp8.cpp  | 34 ++-
 clang/utils/TableGen/NeonEmitter.cpp  |  1 +
 14 files changed, 222 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/AST/arm-mfp8.cpp
 create mode 100644 clang/test/CodeGen/aarch64-debug-types.c
 create mode 100644 clang/test/Sema/arm-mfp8.c

diff --git a/clang/include/clang/Basic/AArch64SVEACLETypes.def 
b/clang/include/clang/Basic/AArch64SVEACLETypes.def
index 25abf5f3f86b7d..3b5861861ef881 100644
--- a/clang/include/clang/Basic/AArch64SVEACLETypes.def
+++ b/clang/include/clang/Basic/AArch64SVEACLETypes.def
@@ -107,6 +107,15 @@
   AARCH64_VECTOR_TYPE(Name, MangledName, Id, SingletonId)
 #endif
 
+#ifndef AARCH64_SCALAR_TYPE
+#define AARCH64_SCALAR_TYPE(Name, MangledName, Id, SingletonId) \
+  SVE_TYPE(Name, Id, SingletonId)
+#endif
+
+#ifndef AARCH64_SCALAR_TYPE_MFLOAT
+#define AARCH64_SCALAR_TYPE_MFLOAT(Name, MangledName, Id, SingletonId, NumEls, 
ElBits, NF) \
+  AARCH64_SCALAR_TYPE(Name, MangledName, Id, SingletonId)
+#endif
 
 //===- Vector point types ---===//
 
@@ -204,6 +213,8 @@ SVE_OPAQUE_TYPE("__SVCount_t", "__SVCount_t", SveCount, 
SveCountTy)
 AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8x8_t", "__MFloat8x8_t", MFloat8x8, 
MFloat8x8Ty, 8, 8, 1)
 AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8x16_t", "__MFloat8x16_t", MFloat8x16, 
MFloat8x16Ty, 16, 8, 1)
 
+AARCH64_SCALAR_TYPE_MFLOAT("__MFloat8_t", "__MFloat8_t", MFloat8, MFloat8Ty, 
1, 8, 1)
+
 #undef SVE_VECTOR_TYPE
 #undef SVE_VECTOR_TYPE_BFLOAT
 #undef SVE_VECTOR_TYPE_FLOAT
@@ -213,4 +224,6 @@ AARCH64_VECTOR_TYPE_MFLOAT("__MFloat8x16_t", 
"__MFloat8x16_t", MFloat8x16, MFloa
 #undef SVE_OPAQUE_TYPE
 #undef AARCH64_VECTOR_TYPE_MFLOAT
 #undef AARCH64_VECTOR_TYPE
+#undef AARCH64_SCALAR_TYPE_MFLOAT
+#undef AARCH64_SCALAR_TYPE
 #undef SVE_TYPE
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 13173dc96e71ae..99232fd2135790 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1149,7 +1149,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 511;
+const unsigned NUM_PREDEF_TYPE_IDS = 512;
 
 // Ensure we do not overrun the predefined types we reserved
 // in the enum PredefinedTypeIDs above.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a4e8d95035b974..ea7db8acc8fc45 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2245,6 +2245,11 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) 
const {
 Width = NumEls * ElBits * NF;  
\
 Align = NumEls * ElBits;   
\
 break;
+#define AARCH64_SCALAR_TYPE(Name, MangledName, Id, SingletonId)
\
+  case BuiltinType::Id:
\
+Width = 8; 
\
+Align = 8; 
\
+break;
 #include "clang/Basic/AArch64SVEACLETy

[clang] a96c14e - [Clang] Always forward sret parameters to musttail calls

2024-10-25 Thread Oliver Stannard via cfe-commits

Author: Kiran
Date: 2024-10-25T09:34:08+01:00
New Revision: a96c14eeb8fcb1a141c0f55ed5d28dd7f1f3e38e

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

LOG: [Clang] Always forward sret parameters to musttail calls

If a call using the musttail attribute returns it's value through an
sret argument pointer, we must forward an incoming sret pointer to it,
instead of creating a new alloca. This is always possible because the
musttail attribute requires the caller and callee to have the same
argument and return types.

Added: 
clang/test/CodeGen/musttail-sret.cpp

Modified: 
clang/lib/CodeGen/CGCall.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 5f50ab6f34ff8d..1949b4ceb7f204 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5112,7 +5112,11 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   RawAddress SRetAlloca = RawAddress::invalid();
   llvm::Value *UnusedReturnSizePtr = nullptr;
   if (RetAI.isIndirect() || RetAI.isInAlloca() || RetAI.isCoerceAndExpand()) {
-if (IsVirtualFunctionPointerThunk && RetAI.isIndirect()) {
+// For virtual function pointer thunks and musttail calls, we must always
+// forward an incoming SRet pointer to the callee, because a local alloca
+// would be de-allocated before the call. These cases both guarantee that
+// there will be an incoming SRet argument of the correct type.
+if ((IsVirtualFunctionPointerThunk || IsMustTail) && RetAI.isIndirect()) {
   SRetPtr = makeNaturalAddressForPointer(CurFn->arg_begin() +
  IRFunctionArgs.getSRetArgNo(),
  RetTy, 
CharUnits::fromQuantity(1));

diff  --git a/clang/test/CodeGen/musttail-sret.cpp 
b/clang/test/CodeGen/musttail-sret.cpp
new file mode 100644
index 00..ca67c218cd67f6
--- /dev/null
+++ b/clang/test/CodeGen/musttail-sret.cpp
@@ -0,0 +1,84 @@
+// RUN: %clang_cc1 -triple=arm %s -emit-llvm -O3 -o - | FileCheck %s 
--check-prefix=CHECK-ARM
+// RUN: %clang_cc1 -triple=arm64 %s -emit-llvm -O3 -o - | FileCheck %s 
--check-prefix=CHECK-ARM64
+// RUN: %clang_cc1 -triple=i686 %s -emit-llvm -O3 -o - | FileCheck %s 
--check-prefix=CHECK-X86
+// RUN: %clang_cc1 -triple=x86_64 %s -emit-llvm -O3 -o - | FileCheck %s 
--check-prefix=CHECK-X64
+
+// Sret tests
+struct Big {
+  int a, b, c, d, e, f, g, h;
+};
+
+struct Big F1(signed short P0);
+
+struct Big F2(signed short P0) {
+  signed short P1 = 20391;
+  [[clang::musttail]] return F1(P1);
+}
+
+// CHECK-NOT: alloca
+// CHECK-ARM: musttail call arm_aapcscc void @_Z2F1s(ptr dead_on_unwind 
writable sret(%struct.Big) align 4 %agg.result, i16 noundef signext 20391)
+// CHECK-ARM64: musttail call void @_Z2F1s(ptr dead_on_unwind writable 
sret(%struct.Big) align 4 %agg.result, i16 noundef 20391)
+// CHECK-X86: musttail call void @_Z2F1s(ptr dead_on_unwind writable 
sret(%struct.Big) align 4 %agg.result, i16 noundef signext 20391)
+// CHECK-X64: musttail call void @_Z2F1s(ptr dead_on_unwind writable 
sret(%struct.Big) align 4 %agg.result, i16 noundef signext 20391)
+
+struct ReallyBig {
+  int a[100];
+};
+
+// Indirect sret tests
+// Function pointer for testing indirect musttail call.
+struct FunctionPointers {
+  ReallyBig (*F3)(int, int, int, int, float, double);
+  ReallyBig (*F4)(int, int, int, char, float, double);
+};
+
+struct ReallyBig F3(int P0, int P1, int P2, int P3, float P4, double P5);
+struct ReallyBig F4(int P0, int P1, int P2, char P3, float P4, double P5);
+
+static struct FunctionPointers FP = {F3, F4};
+
+struct ReallyBig F5 (int P0, int P1, int P2, int P3, float P4, double P5) {
+  [[clang::musttail]] return FP.F3(P0, P1, P2, P3, P4, P5);
+}
+
+// CHECK-NOT: alloca
+// CHECK-ARM: musttail call arm_aapcscc void @_Z2F3fd(ptr dead_on_unwind 
writable sret(%struct.ReallyBig) align 4 %agg.result, i32 noundef %P0, i32 
noundef %P1, i32 noundef %P2, i32 noundef %P3, float noundef %P4, double 
noundef %P5)
+// CHECK-ARM64: musttail call void @_Z2F3fd(ptr dead_on_unwind writable 
sret(%struct.ReallyBig) align 4 %agg.result, i32 noundef %P0, i32 noundef %P1, 
i32 noundef %P2, i32 noundef %P3, float noundef %P4, double noundef %P5)
+// CHECK-X86: musttail call void @_Z2F3fd(ptr dead_on_unwind writable 
sret(%struct.ReallyBig) align 4 %agg.result, i32 noundef %P0, i32 noundef %P1, 
i32 noundef %P2, i32 noundef %P3, float noundef %P4, double noundef %P5)
+// CHECK-X64: musttail call void @_Z2F3fd(ptr dead_on_unwind writable 
sret(%struct.ReallyBig) align 4 %agg.result, i32 noundef %P0, i32 noundef %P1, 
i32 noundef %P2, i32 noundef %P3, float noundef %P4, double noundef %P5)
+
+struct ReallyBig F6 (int P0, int P1, int P

[clang] [compiler-rt] [llvm] [X86] Support MOVRS and AVX10.2 instructions. (PR #113274)

2024-10-25 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lld-x86_64-win` running on 
`as-worker-93` while building `clang,compiler-rt,llvm` at step 7 
"test-build-unified-tree-check-all".

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


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

```
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'LLVM-Unit :: Support/./SupportTests.exe/37/87' 
FAILED 
Script(shard):
--
GTEST_OUTPUT=json:C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe-LLVM-Unit-22656-37-87.json
 GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=87 GTEST_SHARD_INDEX=37 
C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe
--

Script:
--
C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe 
--gtest_filter=ProgramEnvTest.CreateProcessLongPath
--
C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(160): 
error: Expected equality of these values:
  0
  RC
Which is: -2

C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(163): 
error: fs::remove(Twine(LongPath)): did not return errc::success.
error number: 13
error message: permission denied



C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:160
Expected equality of these values:
  0
  RC
Which is: -2

C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:163
fs::remove(Twine(LongPath)): did not return errc::success.
error number: 13
error message: permission denied







```



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


[clang] [clang][NFC] Add test for CWG1898 "Use of “equivalent” in overload resolution" (PR #113439)

2024-10-25 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang][NFC] Add test for CWG1898 "Use of “equivalent” in overload resolution" (PR #113439)

2024-10-25 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang][NFC] Add test for CWG1898 "Use of “equivalent” in overload resolution" (PR #113439)

2024-10-25 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang][NFC] Add test for CWG1898 "Use of “equivalent” in overload resolution" (PR #113439)

2024-10-25 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [llvm] [mlir] [OpenMP][OMPIRBuilder] Error propagation across callbacks (PR #112533)

2024-10-25 Thread Sergio Afonso via cfe-commits

https://github.com/skatrak closed 
https://github.com/llvm/llvm-project/pull/112533
___
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   >