[clang] 5480be1 - [clang][NFC] Refactor Sema::DiagnoseSentinelCalls

2023-11-14 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-11-15T08:37:01+01:00
New Revision: 5480be13d5bff9df8d306cd948ff975ed577c054

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

LOG: [clang][NFC] Refactor Sema::DiagnoseSentinelCalls

Fix indentation, naming and capitalization to match current style
guides.

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 38377f01a10086f..a35a3c2c26c22ad 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5452,7 +5452,7 @@ class Sema final {
   bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
 ObjCMethodDecl *Getter,
 SourceLocation Loc);
-  void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
+  void DiagnoseSentinelCalls(const NamedDecl *D, SourceLocation Loc,
  ArrayRef Args);
 
   void PushExpressionEvaluationContext(

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5b0c4439fd1710c..fc39d6149c1cc65 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -414,80 +414,83 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, 
ArrayRef Locs,
 /// message-send is to a declaration with the sentinel attribute, and
 /// if so, it checks that the requirements of the sentinel are
 /// satisfied.
-void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
+void Sema::DiagnoseSentinelCalls(const NamedDecl *D, SourceLocation Loc,
  ArrayRef Args) {
-  const SentinelAttr *attr = D->getAttr();
-  if (!attr)
+  const SentinelAttr *Attr = D->getAttr();
+  if (!Attr)
 return;
 
   // The number of formal parameters of the declaration.
-  unsigned numFormalParams;
+  unsigned NumFormalParams;
 
   // The kind of declaration.  This is also an index into a %select in
   // the diagnostic.
-  enum CalleeType { CT_Function, CT_Method, CT_Block } calleeType;
-
-  if (ObjCMethodDecl *MD = dyn_cast(D)) {
-numFormalParams = MD->param_size();
-calleeType = CT_Method;
-  } else if (FunctionDecl *FD = dyn_cast(D)) {
-numFormalParams = FD->param_size();
-calleeType = CT_Function;
-  } else if (isa(D)) {
-QualType type = cast(D)->getType();
-const FunctionType *fn = nullptr;
-if (const PointerType *ptr = type->getAs()) {
-  fn = ptr->getPointeeType()->getAs();
-  if (!fn) return;
-  calleeType = CT_Function;
-} else if (const BlockPointerType *ptr = type->getAs()) {
-  fn = ptr->getPointeeType()->castAs();
-  calleeType = CT_Block;
+  enum { CK_Function, CK_Method, CK_Block } CalleeKind;
+
+  if (const auto *MD = dyn_cast(D)) {
+NumFormalParams = MD->param_size();
+CalleeKind = CK_Method;
+  } else if (const auto *FD = dyn_cast(D)) {
+NumFormalParams = FD->param_size();
+CalleeKind = CK_Function;
+  } else if (const auto *VD = dyn_cast(D)) {
+QualType Ty = VD->getType();
+const FunctionType *Fn = nullptr;
+if (const auto *PtrTy = Ty->getAs()) {
+  Fn = PtrTy->getPointeeType()->getAs();
+  if (!Fn)
+return;
+  CalleeKind = CK_Function;
+} else if (const auto *PtrTy = Ty->getAs()) {
+  Fn = PtrTy->getPointeeType()->castAs();
+  CalleeKind = CK_Block;
 } else {
   return;
 }
 
-if (const FunctionProtoType *proto = dyn_cast(fn)) {
-  numFormalParams = proto->getNumParams();
-} else {
-  numFormalParams = 0;
-}
+if (const auto *proto = dyn_cast(Fn))
+  NumFormalParams = proto->getNumParams();
+else
+  NumFormalParams = 0;
   } else {
 return;
   }
 
-  // "nullPos" is the number of formal parameters at the end which
+  // "NullPos" is the number of formal parameters at the end which
   // effectively count as part of the variadic arguments.  This is
   // useful if you would prefer to not have *any* formal parameters,
   // but the language forces you to have at least one.
-  unsigned nullPos = attr->getNullPos();
-  assert((nullPos == 0 || nullPos == 1) && "invalid null position on 
sentinel");
-  numFormalParams = (nullPos > numFormalParams ? 0 : numFormalParams - 
nullPos);
+  unsigned NullPos = Attr->getNullPos();
+  assert((NullPos == 0 || NullPos == 1) && "invalid null position on 
sentinel");
+  NumFormalParams = (NullPos > NumFormalParams ? 0 : NumFormalParams - 
NullPos);
 
   // The number of arguments which should follow the sentinel.
-  unsigned numArgsAfterSentinel = attr->getSentinel();
+  unsigned NumArgsAfterSentinel = Attr->getSentinel();
 
   // If there aren't enough arguments for all the formal parameters,
   // the sentinel, and the args

[clang] [clang][Interp] Implement inc/dec for IntegralAP (PR #69597)

2023-11-14 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] Implement bitwise operations for IntegralAP (PR #71807)

2023-11-14 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] Implement IntegralAP subtraction (PR #71648)

2023-11-14 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] Implement builtin_expect (PR #69713)

2023-11-14 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Ping

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


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-14 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/72213

>From bc9e06ea87dca046227faf2996eb8de521863d57 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Fri, 20 Oct 2023 14:40:25 +0200
Subject: [PATCH 1/4] [clang] Handle templated operators with reversed
 arguments (#69595)

https://github.com/llvm/llvm-project/pull/68999 correctly computed
conversion sequence for reversed args to a template operators. This was
a breaking change as code, previously accepted in C++17, starts to break
in C++20.

Example:
```cpp
struct P {};
template bool operator==(const P&, const S &);

struct A : public P {};
struct B : public P {};
bool check(A a, B b) { return a == b; }  // This is now ambiguous in C++20.
```

In order to minimise widespread breakages, as a clang extension, we had
previously accepted such ambiguities with a warning
(`-Wambiguous-reversed-operator`) for non-template operators. Due to the
same reasons, we extend this relaxation for template operators.

Fixes https://github.com/llvm/llvm-project/issues/53954
---
 clang/docs/ReleaseNotes.rst   | 21 +++
 clang/lib/Sema/SemaOverload.cpp   | 28 ++---
 .../over.match.oper/p3-2a.cpp | 61 +++
 3 files changed, 100 insertions(+), 10 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7a131cb520aa600..5c974eec9ed67d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -37,6 +37,27 @@ These changes are ones which we think may surprise users 
when upgrading to
 Clang |release| because of the opportunity they pose for disruption to existing
 code bases.
 
+- Fix a bug in reversed argument for templated operators.
+  This breaks code in C++20 which was previously accepted in C++17. Eg:
+
+  .. code-block:: cpp
+
+struct P {};
+template bool operator==(const P&, const S&);
+
+struct A : public P {};
+struct B : public P {};
+
+// This equality is now ambiguous in C++20.
+bool ambiguous(A a, B b) { return a == b; }
+
+template bool operator!=(const P&, const S&);
+// Ok. Found a matching operator!=.
+bool fine(A a, B b) { return a == b; }
+
+  To reduce such widespread breakages, as an extension, Clang accepts this code
+  with an existing warning ``-Wambiguous-reversed-operator`` warning.
+  Fixes `GH `_.
 
 C/C++ Language Potentially Breaking Changes
 ---
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index f97e244120612e3..73f417cc8bd4024 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7685,7 +7685,7 @@ bool Sema::CheckNonDependentConversions(
 QualType ParamType = ParamTypes[I + Offset];
 if (!ParamType->isDependentType()) {
   unsigned ConvIdx = PO == OverloadCandidateParamOrder::Reversed
- ? 0
+ ? Args.size() - 1 - (ThisConversions + I)
  : (ThisConversions + I);
   Conversions[ConvIdx]
 = TryCopyInitialization(*this, Args[I], ParamType,
@@ -10082,11 +10082,19 @@ getImplicitObjectParamType(ASTContext &Context, const 
FunctionDecl *F) {
   return M->getFunctionObjectParameterReferenceType();
 }
 
-static bool haveSameParameterTypes(ASTContext &Context, const FunctionDecl *F1,
-   const FunctionDecl *F2) {
+// As a Clang extension, allow ambiguity among F1 and F2 if they represent
+// represent the same entity.
+static bool allowAmbiguity(ASTContext &Context, const FunctionDecl *F1,
+   const FunctionDecl *F2) {
   if (declaresSameEntity(F1, F2))
 return true;
-
+  if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation() &&
+  declaresSameEntity(F1->getPrimaryTemplate(), F2->getPrimaryTemplate())) {
+return true;
+  }
+  // TODO: It is not clear whether comparing parameters is necessary (i.e.
+  // different functions with same params). Consider removing this (as no test
+  // fail w/o it).
   auto NextParam = [&](const FunctionDecl *F, unsigned &I, bool First) {
 if (First) {
   if (std::optional T = getImplicitObjectParamType(Context, F))
@@ -10271,14 +10279,14 @@ bool clang::isBetterOverloadCandidate(
 case ImplicitConversionSequence::Worse:
   if (Cand1.Function && Cand2.Function &&
   Cand1.isReversed() != Cand2.isReversed() &&
-  haveSameParameterTypes(S.Context, Cand1.Function, Cand2.Function)) {
+  allowAmbiguity(S.Context, Cand1.Function, Cand2.Function)) {
 // Work around large-scale breakage caused by considering reversed
 // forms of operator== in C++20:
 //
-// When comparing a function against a reversed function with the same
-// parameter types, if we have a better conversion for one argument and
-// a worse conversion for the ot

[clang] [clang] Use new interpreter in EvaluateAsConstantExpr if requested (PR #70763)

2023-11-14 Thread Timm Baeder via cfe-commits

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


[clang] f5b378b - [clang] Use new interpreter in EvaluateAsConstantExpr if requested (#70763)

2023-11-14 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-11-15T08:29:22+01:00
New Revision: f5b378b0d6e516a55fceee79d97c2cbfe58e7845

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

LOG: [clang] Use new interpreter in EvaluateAsConstantExpr if requested (#70763)

EvaluateAsConstantExpr() uses ::EvaluateInPlace() directly, which does
not use the new interpreter if requested. Do it here, which is the same
pattern we use in EvaluateAsInitializer.

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 4aa8045bc93be71..373972eb6cab11b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15672,12 +15672,14 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   // this doesn't escape.
   MaterializeTemporaryExpr BaseMTE(T, const_cast(this), true);
   APValue::LValueBase Base(&BaseMTE);
-
   Info.setEvaluatingDecl(Base, Result.Val);
-  LValue LVal;
-  LVal.set(Base);
 
-  {
+  if (Info.EnableNewConstInterp) {
+if (!Info.Ctx.getInterpContext().evaluateAsRValue(Info, this, Result.Val))
+  return false;
+  } else {
+LValue LVal;
+LVal.set(Base);
 // C++23 [intro.execution]/p5
 // A full-expression is [...] a constant-expression
 // So we need to make sure temporary objects are destroyed after having
@@ -15686,10 +15688,10 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
 if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
 Result.HasSideEffects || !Scope.destroy())
   return false;
-  }
 
-  if (!Info.discardCleanups())
-llvm_unreachable("Unhandled cleanup; missing full expression marker?");
+if (!Info.discardCleanups())
+  llvm_unreachable("Unhandled cleanup; missing full expression marker?");
+  }
 
   if (!CheckConstantExpression(Info, getExprLoc(), getStorageType(Ctx, this),
Result.Val, Kind))

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 0e1952104da36e5..85adfe551384d27 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -276,15 +276,13 @@ namespace SizeOf {
 #if __cplusplus >= 202002L
   /// FIXME: The following code should be accepted.
   consteval int foo(int n) { // ref-error {{consteval function never produces 
a constant expression}}
-return sizeof(int[n]); // ref-note 3{{not valid in a constant expression}} 
\
-   // expected-note {{not valid in a constant 
expression}}
+return sizeof(int[n]); // ref-note 3{{not valid in a constant expression}}
   }
   constinit int var = foo(5); // ref-error {{not a constant expression}} \
   // ref-note 2{{in call to}} \
   // ref-error {{does not have a constant 
initializer}} \
   // ref-note {{required by 'constinit' 
specifier}} \
   // expected-error  {{is not a constant 
expression}} \
-  // expected-note {{in call to}} \
   // expected-error {{does not have a constant 
initializer}} \
   // expected-note {{required by 'constinit' 
specifier}} \
 



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


[libunwind] [libunwind] Fix an inconsistent indentation (NFC) (PR #72314)

2023-11-14 Thread Alexander Richardson via cfe-commits

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


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


[libunwind] [libunwind] Fix an inconsistent indentation (NFC) (PR #72314)

2023-11-14 Thread Alexander Richardson via cfe-commits

arichardson wrote:

> > Making it consistent is good, but it sounds like we should update the 
> > .clang-format config file or reformat this whole file to not be indented.
> 
> I'm not sure what the clang-format policy for libunwind is. How about landing 
> this as is and updating `.clang-format` or excluding this file as a 
> follow-up, in a way you and other libunwind maintainers think is appropriate?

Sorry if that wasn't obvious, I think your change should be merged. I just 
noticed that the current style does not match the configured one which should 
eventually be fixed as a follow up change.

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


[clang] [clang][Analyzer][NFC] Use condition type for comparison in several checkers (PR #72358)

2023-11-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes



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


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (+2-2) 
- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+2-2) 
- (modified) clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp (+2-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index b1bc98e93a27995..31f5b03dcdeba80 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -881,8 +881,8 @@ SVal 
CStringChecker::getCStringLengthForRegion(CheckerContext &C,
   const llvm::APSInt *maxLengthInt = BVF.evalAPSInt(BO_Div, maxValInt,
 fourInt);
   NonLoc maxLength = svalBuilder.makeIntVal(*maxLengthInt);
-  SVal evalLength = svalBuilder.evalBinOpNN(state, BO_LE, *strLn,
-maxLength, sizeTy);
+  SVal evalLength = svalBuilder.evalBinOpNN(state, BO_LE, *strLn, 
maxLength,
+
svalBuilder.getConditionType());
   state = state->assume(evalLength.castAs(), true);
 }
 state = state->set(MR, strLength);
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 69610029beb0a9e..2b5c1dc4c99affa 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -719,9 +719,9 @@ void StreamChecker::evalFreadFwrite(const FnDescription 
*Desc,
   NonLoc RetVal = makeRetVal(C, CE).castAs();
   ProgramStateRef StateFailed =
   State->BindExpr(CE, C.getLocationContext(), RetVal);
+  SValBuilder &SVB = C.getSValBuilder();
   auto Cond =
-  C.getSValBuilder()
-  .evalBinOpNN(State, BO_LT, RetVal, *NMembVal, 
C.getASTContext().IntTy)
+  SVB.evalBinOpNN(State, BO_LT, RetVal, *NMembVal, SVB.getConditionType())
   .getAs();
   if (!Cond)
 return;
diff --git a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
index b195d912cadfe9b..1d03d1656b3cb14 100644
--- a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -188,7 +188,8 @@ ProgramStateRef 
VLASizeChecker::checkVLAIndexSize(CheckerContext &C,
   QualType SizeTy = SizeE->getType();
   DefinedOrUnknownSVal Zero = SVB.makeZeroVal(SizeTy);
 
-  SVal LessThanZeroVal = SVB.evalBinOp(State, BO_LT, SizeD, Zero, SizeTy);
+  SVal LessThanZeroVal =
+  SVB.evalBinOp(State, BO_LT, SizeD, Zero, SVB.getConditionType());
   if (std::optional LessThanZeroDVal =
   LessThanZeroVal.getAs()) {
 ConstraintManager &CM = C.getConstraintManager();

``




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


[clang] [clang][Analyzer][NFC] Use condition type for comparison in several checkers (PR #72358)

2023-11-14 Thread Ben Shi via cfe-commits

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/72358

None

>From b2abb3ff72a2a9f57a3fc4b71d19daefd436410b Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Wed, 15 Nov 2023 15:16:18 +0800
Subject: [PATCH] [clang][Analyzer][NFC] Use condition type for comparison in
 several checkers

---
 clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp | 4 ++--
 clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp  | 4 ++--
 clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp | 3 ++-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index b1bc98e93a27995..31f5b03dcdeba80 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -881,8 +881,8 @@ SVal 
CStringChecker::getCStringLengthForRegion(CheckerContext &C,
   const llvm::APSInt *maxLengthInt = BVF.evalAPSInt(BO_Div, maxValInt,
 fourInt);
   NonLoc maxLength = svalBuilder.makeIntVal(*maxLengthInt);
-  SVal evalLength = svalBuilder.evalBinOpNN(state, BO_LE, *strLn,
-maxLength, sizeTy);
+  SVal evalLength = svalBuilder.evalBinOpNN(state, BO_LE, *strLn, 
maxLength,
+
svalBuilder.getConditionType());
   state = state->assume(evalLength.castAs(), true);
 }
 state = state->set(MR, strLength);
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 69610029beb0a9e..2b5c1dc4c99affa 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -719,9 +719,9 @@ void StreamChecker::evalFreadFwrite(const FnDescription 
*Desc,
   NonLoc RetVal = makeRetVal(C, CE).castAs();
   ProgramStateRef StateFailed =
   State->BindExpr(CE, C.getLocationContext(), RetVal);
+  SValBuilder &SVB = C.getSValBuilder();
   auto Cond =
-  C.getSValBuilder()
-  .evalBinOpNN(State, BO_LT, RetVal, *NMembVal, 
C.getASTContext().IntTy)
+  SVB.evalBinOpNN(State, BO_LT, RetVal, *NMembVal, SVB.getConditionType())
   .getAs();
   if (!Cond)
 return;
diff --git a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
index b195d912cadfe9b..1d03d1656b3cb14 100644
--- a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -188,7 +188,8 @@ ProgramStateRef 
VLASizeChecker::checkVLAIndexSize(CheckerContext &C,
   QualType SizeTy = SizeE->getType();
   DefinedOrUnknownSVal Zero = SVB.makeZeroVal(SizeTy);
 
-  SVal LessThanZeroVal = SVB.evalBinOp(State, BO_LT, SizeD, Zero, SizeTy);
+  SVal LessThanZeroVal =
+  SVB.evalBinOp(State, BO_LT, SizeD, Zero, SVB.getConditionType());
   if (std::optional LessThanZeroDVal =
   LessThanZeroVal.getAs()) {
 ConstraintManager &CM = C.getConstraintManager();

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


[clang] [Clang] Fix finding instantiated decls for class template specializations during instantiation (PR #72346)

2023-11-14 Thread Yuxuan Chen via cfe-commits

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


[clang] [clang][Interp] Fix variables referring to their own address (PR #70587)

2023-11-14 Thread Timm Baeder via cfe-commits

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


[clang] e2f8ec7 - [clang][Interp] Fix variables referring to their own address (#70587)

2023-11-14 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-11-15T08:03:06+01:00
New Revision: e2f8ec72555cf42fc74468c9ff686d29434780af

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

LOG: [clang][Interp] Fix variables referring to their own address (#70587)

This was a combination of issues:
  1) We can subtract pointers that don't point into arrays.
  2) In C, everything is possible.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/c.c
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index a133318cab50b25..026a95d65488da9 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1453,7 +1453,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T 
&Offset,
   DiagInvalidOffset();
   }
 
-  if (Invalid && !Ptr.isDummy())
+  if (Invalid && !Ptr.isDummy() && S.getLangOpts().CPlusPlus)
 return false;
 
   // Offset is valid - compute it on unsigned.
@@ -1531,7 +1531,7 @@ inline bool SubPtr(InterpState &S, CodePtr OpPC) {
   const Pointer &LHS = S.Stk.pop();
   const Pointer &RHS = S.Stk.pop();
 
-  if (!Pointer::hasSameArray(LHS, RHS)) {
+  if (!Pointer::hasSameBase(LHS, RHS) && S.getLangOpts().CPlusPlus) {
 // TODO: Diagnose.
 return false;
   }

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 6bfcded0a78646c..2bc3d906bcc5ef9 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -pedantic -verify=pedantic-ref -std=c11 %s
 
 typedef __INTPTR_TYPE__ intptr_t;
+typedef __PTRDIFF_TYPE__ ptr
diff _t;
 
 _Static_assert(1, "");
 _Static_assert(0 != 1, "");
@@ -81,3 +82,6 @@ const intptr_t L = (intptr_t)(&(yy->y)); // expected-error 
{{not a compile-time
  // pedantic-expected-error {{not a 
compile-time constant}} \
  // ref-error {{not a compile-time 
constant}} \
  // pedantic-ref-error {{not a 
compile-time constant}}
+const ptr
diff _t m = &m + 137 - &m;
+_Static_assert(m == 137, ""); // pedantic-ref-warning {{GNU extension}} \
+  // pedantic-expected-warning {{GNU extension}}

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 68833ec2dc48adf..0e1952104da36e5 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -7,6 +7,7 @@
 #define INT_MAX __INT_MAX__
 
 typedef __INTPTR_TYPE__ intptr_t;
+typedef __PTRDIFF_TYPE__ ptr
diff _t;
 
 
 static_assert(true, "");
@@ -198,6 +199,20 @@ namespace PointerComparison {
  // ref-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
 
   constexpr bool v7 = qv <= (void*)&s.b; // ok
+
+  constexpr ptr
diff _t m = &m - &m;
+  static_assert(m == 0, "");
+
+  constexpr ptr
diff _t m2 = (&m2 + 1) - (&m2 + 1);
+  static_assert(m2 == 0, "");
+
+  constexpr long m3 = (&m3 + 1) - (&m3);
+  static_assert(m3 == 1, "");
+
+  constexpr long m4 = &m4 + 2 - &m4; // ref-error {{must be initialized by a 
constant expression}} \
+ // ref-note {{cannot refer to element 2 
of non-array object}} \
+ // expected-error {{must be initialized 
by a constant expression}} \
+ // expected-note {{cannot refer to 
element 2 of non-array object}}
 }
 
 namespace SizeOf {



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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-14 Thread Matt Arsenault via cfe-commits


@@ -904,6 +904,32 @@ BUILTIN(__atomic_signal_fence, "vi", "n")
 BUILTIN(__atomic_always_lock_free, "bzvCD*", "nE")
 BUILTIN(__atomic_is_lock_free, "bzvCD*", "nE")
 
+// GNU atomic builtins with atomic scopes.
+ATOMIC_BUILTIN(__scoped_atomic_load, "v.", "t")

arsenm wrote:

I wonder if it would be better to preserve __atomic as the prefix, and move the 
_scope part to the name suffix 

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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-14 Thread Matt Arsenault via cfe-commits


@@ -54,6 +59,16 @@ enum class SyncScope {
 
 inline llvm::StringRef getAsString(SyncScope S) {

arsenm wrote:

I guess this is a pre-existing problem, but why don't these just match the 
backend string names?

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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-14 Thread Matt Arsenault via cfe-commits


@@ -205,6 +220,56 @@ class AtomicScopeHIPModel : public AtomicScopeModel {
   }
 };
 
+/// Defines the generic atomic scope model.
+class AtomicScopeGenericModel : public AtomicScopeModel {
+public:
+  /// The enum values match predefined built-in macros __ATOMIC_SCOPE_*.
+  enum ID {
+System = 0,
+Device = 1,
+Workgroup = 2,
+Wavefront = 3,
+Single = 4,
+Last = Single
+  };
+
+  AtomicScopeGenericModel() = default;
+
+  SyncScope map(unsigned S) const override {
+switch (static_cast(S)) {
+case Device:
+  return SyncScope::DeviceScope;
+case System:
+  return SyncScope::SystemScope;
+case Workgroup:
+  return SyncScope::WorkgroupScope;
+case Wavefront:
+  return SyncScope::WavefrontScope;
+case Single:
+  return SyncScope::SingleScope;
+}
+llvm_unreachable("Invalid language sync scope value");

arsenm wrote:

Maybe it would be better to just assume anything else is system?

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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-14 Thread Matt Arsenault via cfe-commits

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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-14 Thread Matt Arsenault via cfe-commits


@@ -798,6 +798,13 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   Builder.defineMacro("__ATOMIC_ACQ_REL", "4");
   Builder.defineMacro("__ATOMIC_SEQ_CST", "5");
 
+  // Define macros for the clang atomic scopes.
+  Builder.defineMacro("__MEMORY_SCOPE_SYSTEM", "0");
+  Builder.defineMacro("__MEMORY_SCOPE_DEVICE", "1");
+  Builder.defineMacro("__MEMORY_SCOPE_WRKGRP", "2");
+  Builder.defineMacro("__MEMORY_SCOPE_WVFRNT", "3");
+  Builder.defineMacro("__MEMORY_SCOPE_SINGLE", "4");
+

arsenm wrote:

Should the HIP flavors be defined in terms of these?

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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-14 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm commented:

Is there any actual difference now between these and the HIP/OpenCL flavors 
other than dropping the language from the name? 

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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-14 Thread Matt Arsenault via cfe-commits

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


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-14 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

I ran this change internally and noticed a crash for 
```cpp
template 
class Foo {
 public:
  template 
  bool operator==(const Foo& other) const;
};

bool x = Foo{} == Foo{};
```

stacktrace

```
F 00:00:1700029943.3152478971 logging.cc:57] assert.h assertion failed 
at third_party/llvm/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:443 in T 
&llvm::MutableArrayRef::operator[](size_t) 
const [T = clang::ImplicitConversionSequence]: Index < this->size() && "Invalid 
index!"
*** Check failure stack trace: ***
@ 0x55598a5f6a44  absl::log_internal::LogMessage::SendToLog()
@ 0x55598a5f68a2  absl::log_internal::LogMessage::Flush()
@ 0x55598a5f6da9  
absl::log_internal::LogMessageFatal::~LogMessageFatal()
@ 0x55598a5e70c4  __assert_fail
@ 0x555986a73209  clang::Sema::CheckNonDependentConversions()
@ 0x555986a9db52  llvm::function_ref<>::callback_fn<>()
@ 0x555986c6bc08  llvm::function_ref<>::callback_fn<>()
@ 0x555986bf70b3  clang::Sema::FinishTemplateArgumentDeduction()
@ 0x555986c6bb56  llvm::function_ref<>::callback_fn<>()
@ 0x5559862dbc2f  clang::Sema::runWithSufficientStackSpace()
@ 0x555986bf8f8d  clang::Sema::DeduceTemplateArguments()
@ 0x555986a7229a  clang::Sema::AddMethodTemplateCandidate()
@ 0x555986a72c6f  clang::Sema::AddMethodCandidate()
@ 0x555986a751dd  clang::Sema::AddMemberOperatorCandidates()
@ 0x555986a881f6  clang::Sema::LookupOverloadedBinOp()
@ 0x555986a88673  clang::Sema::CreateOverloadedBinOp()
@ 0x5559866ff91a  BuildOverloadedBinOp()
@ 0x5559866c643e  clang::Sema::ActOnBinOp()
@ 0x555986050faf  clang::Parser::ParseRHSOfBinaryExpression()
@ 0x55598604fcac  clang::Parser::ParseAssignmentExpression()
@ 0x555
```



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


[clang] [clang][analyzer] Support `fputc` in StreamChecker (PR #71518)

2023-11-14 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/71518

>From 15367bae9f129b20885f13e5ca5ae816271d7214 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Tue, 7 Nov 2023 16:44:05 +0800
Subject: [PATCH] [clang][analyzer] Support `fputc` in StreamChecker

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 61 ---
 clang/test/Analysis/stream-error.c| 35 +++
 clang/test/Analysis/stream.c  |  6 ++
 3 files changed, 94 insertions(+), 8 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 69610029beb0a9e..df0865e85eaefda 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -245,11 +245,14 @@ class StreamChecker : public CheckerStreamArgNo), C,
@@ -650,7 +656,7 @@ void StreamChecker::preFreadFwrite(const FnDescription 
*Desc,
   if (!State)
 return;
 
-  if (!IsFread) {
+  if (!IsRead) {
 C.addTransition(State);
 return;
   }
@@ -745,6 +751,45 @@ void StreamChecker::evalFreadFwrite(const FnDescription 
*Desc,
 C.addTransition(StateFailed);
 }
 
+void StreamChecker::evalFputc(const FnDescription *Desc, const CallEvent &Call,
+  CheckerContext &C) const {
+  ProgramStateRef State = C.getState();
+  SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
+  if (!StreamSym)
+return;
+
+  const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  // `fputc` returns the written character on success, otherwise returns EOF.
+
+  // Generate a transition for the success state.
+  std::optional PutVal = Call.getArgSVal(0).getAs();
+  if (!PutVal)
+return;
+  ProgramStateRef StateNotFailed =
+  State->BindExpr(CE, C.getLocationContext(), *PutVal);
+  StateNotFailed =
+  StateNotFailed->set(StreamSym, StreamState::getOpened(Desc));
+  C.addTransition(StateNotFailed);
+
+  // Add transition for the failed state.
+  // If a (non-EOF) error occurs, the resulting value of the file position
+  // indicator for the stream is indeterminate.
+  ProgramStateRef StateFailed = bindInt(*EofVal, State, C, CE);
+  StreamState NewSS = StreamState::getOpened(
+  Desc, ErrorFError, /*IsFilePositionIndeterminate*/ true);
+  StateFailed = StateFailed->set(StreamSym, NewSS);
+  C.addTransition(StateFailed);
+}
+
 void StreamChecker::preFseek(const FnDescription *Desc, const CallEvent &Call,
  CheckerContext &C) const {
   ProgramStateRef State = C.getState();
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 3c00e59bb6bd19d..5ebdc32bb1b92ff 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -101,6 +101,24 @@ void error_fwrite(void) {
   Ret = fwrite(0, 1, 10, F); // expected-warning {{Stream might be already 
closed}}
 }
 
+void error_fputc(void) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  int Ret = fputc('X', F);
+  if (Ret == EOF) {
+clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+fputc('Y', F); // expected-warning {{might be 'indeterminate'}}
+  } else {
+clang_analyzer_eval(Ret == 'X'); // expected-warning {{TRUE}}
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
+fputc('Y', F); // no-warning
+  }
+  fclose(F);
+  fputc('A', F); // expected-warning {{Stream might be already closed}}
+}
+
 void freadwrite_zerosize(FILE *F) {
   size_t Ret;
   Ret = fwrite(0, 1, 0, F);
@@ -241,6 +259,23 @@ void error_indeterminate_clearerr(void) {
   fclose(F);
 }
 
+void error_indeterminate_fputc(void) {
+  FILE *F = fopen("file", "r+");
+  if (!F)
+return;
+  int rc = fseek(F, 0, SEEK_SET);
+  if (rc) {
+if (feof(F)) {
+  fputc('X', F); // no warning
+} else if (ferror(F)) {
+  fputc('C', F); // expected-warning {{might be 'indeterminate'}}
+} else {
+  fputc('E', F); // expected-warning {{might be 'indeterminate'}}
+}
+  }
+  fclose(F);
+}
+
 void error_indeterminate_feof1(void) {
   FILE *F = fopen("file", "r+");
   if (!F)
diff --git a/clang/test/Analysis/stream.c b/clang/test/Analysis/stream.c
index a01310cfef5dd8a..9b6a31738d6e0b8 100644
--- a/clang/test/Analysis/stream.c
+++ b/clang/test/Analysis/stream.c
@@ -14,6 +14,12 @@ void check_fwrite(void) {
   fclose(fp);
 }
 
+void check_fputc(void) {
+  FILE *fp = tmpfile();
+  fputc('A', fp); // expected-warning {{Stream pointer might be NULL}}
+  fclose(fp);
+}
+
 void check_fseek(void) {
   FILE *fp = tmpfile();
   fseek(fp, 0, 0); // expected-warning {{Stream pointer might be NULL}}

___
cfe-commits mailing list
cfe-commits@lists.llvm.

[clang] [clang][analyzer] Restrict 'fopen' modeling to POSIX versions in SimpleStreamChecker (PR #72016)

2023-11-14 Thread Ben Shi via cfe-commits

benshi001 wrote:

> The functional change looks good but the reformatting should be put into a 
> separate change.

Done. Thanks.

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


[clang] [clang][analyzer] Restrict 'fopen' modeling to POSIX versions in SimpleStreamChecker (PR #72016)

2023-11-14 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/72016

>From dfcae6556ea05d72f871f13cc76984a0745fff26 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Wed, 15 Nov 2023 14:02:46 +0800
Subject: [PATCH] [clang][analyzer] Restrict 'fopen' modeling to POSIX versions
 in SimpleStreamChecker

---
 clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp | 2 +-
 clang/test/Analysis/stream-non-posix-function.c   | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
index 32d95e944195390..2ac9f65c9793f45 100644
--- a/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
@@ -90,7 +90,7 @@ class SimpleStreamChecker : public Checkerhttps://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)

2023-11-14 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja updated 
https://github.com/llvm/llvm-project/pull/68846

>From b2ec5be2a9eb80a4aeaf329ea4aed727b36501a1 Mon Sep 17 00:00:00 2001
From: "A. Jiang" 
Date: Tue, 17 Oct 2023 10:41:18 +0800
Subject: [PATCH] [Docs][Clang] DR status in cxx_status.html

---
 clang/www/cxx_status.html | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 621439d0bae9666..a1e9b51c25905b9 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -207,7 +207,7 @@ C++23 implementation status
 
 
   Allow duplicate attributes
-  https://wg21.link/P2156R1";>P2156R1
+  https://wg21.link/P2156R1";>P2156R1 (DR)
   Clang 13
 
 
@@ -227,7 +227,7 @@ C++23 implementation status
 
 
   C++ identifier syntax using UAX 31
-  https://wg21.link/P1949R7";>P1949R7
+  https://wg21.link/P1949R7";>P1949R7 (DR)
   Clang 14
 
 
@@ -247,11 +247,11 @@ C++23 implementation status
 
 
   Change scope of lambda trailing-return-type
-  https://wg21.link/P2036R3";>P2036R3
+  https://wg21.link/P2036R3";>P2036R3 (DR)
   Clang 17
 
 
-  https://wg21.link/P2579R0";>P2579R0
+  https://wg21.link/P2579R0";>P2579R0 (DR)
 
 
   Multidimensional subscript operator
@@ -320,12 +320,12 @@ C++23 implementation status
 
 
   The Equality Operator You Are Looking For
-  https://wg21.link/P2468R2";>P2468R2
+  https://wg21.link/P2468R2";>P2468R2 (DR)
   Clang 16
 
 
   De-deprecating volatile compound operations
-  https://wg21.link/P2327R1";>P2327R1
+  https://wg21.link/P2327R1";>P2327R1 (DR)
   Clang 15
 
 
@@ -397,7 +397,7 @@ C++23 implementation status
 
 
   char8_t Compatibility and Portability Fix
-  https://wg21.link/P2513R3";>P2513R3
+  https://wg21.link/P2513R3";>P2513R3 (DR)
   Clang 16
 
 
@@ -539,7 +539,7 @@ C++20 implementation status
 https://wg21.link/p2103r0";>P2103R0
   

-https://wg21.link/p2493r0";>P2493R0
+https://wg21.link/p2493r0";>P2493R0 (DR)
   
   
 https://wg21.link/p2092r0";>P2092R0

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


[clang] 8434b0b - [Clang][RISCV] Introduce tuple types for RVV bfloat16 (#72216)

2023-11-14 Thread via cfe-commits

Author: Yueh-Ting (eop) Chen
Date: 2023-11-15T13:50:14+08:00
New Revision: 8434b0b9d39b7ffcd1f7f7b5746151e293620e0d

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

LOG: [Clang][RISCV] Introduce tuple types for RVV bfloat16 (#72216)

The first commit extends the capacity from the compiler infrastructure,
and the second commit continues the effort in #71140 to introduce tuple
types for bfloat16.

Added: 


Modified: 
clang/include/clang/Basic/RISCVVTypes.def
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Support/RISCVVIntrinsicUtils.h
clang/lib/Support/RISCVVIntrinsicUtils.cpp

clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-intrinsic-datatypes.cpp
clang/utils/TableGen/RISCVVEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/RISCVVTypes.def 
b/clang/include/clang/Basic/RISCVVTypes.def
index af44cdcd53e5bd0..6620de8ad50e01e 100644
--- a/clang/include/clang/Basic/RISCVVTypes.def
+++ b/clang/include/clang/Basic/RISCVVTypes.def
@@ -452,6 +452,62 @@ RVV_VECTOR_TYPE_FLOAT("__rvv_float64m2x4_t", 
RvvFloat64m2x4, RvvFloat64m2x4Ty, 2
 
 RVV_VECTOR_TYPE_FLOAT("__rvv_float64m4x2_t", RvvFloat64m4x2, RvvFloat64m4x2Ty, 
4, 64, 2)
 
+//===- BFloat16 tuple types 
-===//
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x2_t", RvvBFloat16mf4x2, 
RvvBFloat16mf4x2Ty,
+   1, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x3_t", RvvBFloat16mf4x3, 
RvvBFloat16mf4x3Ty,
+   1, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x4_t", RvvBFloat16mf4x4, 
RvvBFloat16mf4x4Ty,
+   1, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x5_t", RvvBFloat16mf4x5, 
RvvBFloat16mf4x5Ty,
+   1, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x6_t", RvvBFloat16mf4x6, 
RvvBFloat16mf4x6Ty,
+   1, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x7_t", RvvBFloat16mf4x7, 
RvvBFloat16mf4x7Ty,
+   1, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf4x8_t", RvvBFloat16mf4x8, 
RvvBFloat16mf4x8Ty,
+   1, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x2_t", RvvBFloat16mf2x2, 
RvvBFloat16mf2x2Ty,
+   2, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x3_t", RvvBFloat16mf2x3, 
RvvBFloat16mf2x3Ty,
+   2, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x4_t", RvvBFloat16mf2x4, 
RvvBFloat16mf2x4Ty,
+   2, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x5_t", RvvBFloat16mf2x5, 
RvvBFloat16mf2x5Ty,
+   2, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x6_t", RvvBFloat16mf2x6, 
RvvBFloat16mf2x6Ty,
+   2, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x7_t", RvvBFloat16mf2x7, 
RvvBFloat16mf2x7Ty,
+   2, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16mf2x8_t", RvvBFloat16mf2x8, 
RvvBFloat16mf2x8Ty,
+   2, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x2_t", RvvBFloat16m1x2, 
RvvBFloat16m1x2Ty,
+   4, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x3_t", RvvBFloat16m1x3, 
RvvBFloat16m1x3Ty,
+   4, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x4_t", RvvBFloat16m1x4, 
RvvBFloat16m1x4Ty,
+   4, 16, 4)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x5_t", RvvBFloat16m1x5, 
RvvBFloat16m1x5Ty,
+   4, 16, 5)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x6_t", RvvBFloat16m1x6, 
RvvBFloat16m1x6Ty,
+   4, 16, 6)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x7_t", RvvBFloat16m1x7, 
RvvBFloat16m1x7Ty,
+   4, 16, 7)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m1x8_t", RvvBFloat16m1x8, 
RvvBFloat16m1x8Ty,
+   4, 16, 8)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x2_t", RvvBFloat16m2x2, 
RvvBFloat16m2x2Ty,
+   8, 16, 2)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x3_t", RvvBFloat16m2x3, 
RvvBFloat16m2x3Ty,
+   8, 16, 3)
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m2x4_t", RvvBFloat16m2x4, 
RvvBFloat16m2x4Ty,
+   8, 16, 4)
+
+RVV_VECTOR_TYPE_BFLOAT("__rvv_bfloat16m4x2_t", RvvBFloat16m4x2, 
RvvBFloat16m4x2Ty,
+   16, 16, 2)
+
 #undef RVV_VECTOR_TYPE_BFLOAT
 #undef RVV_VECTOR_TYPE_FLOAT
 #undef RVV_VECTOR_TYPE_INT

diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 5c32fbc079c9a65..9044c46fc671963 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1101,7 +1101,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will

[clang] [Clang][RISCV] Introduce tuple types for RVV bfloat16 (PR #72216)

2023-11-14 Thread Yueh-Ting Chen via cfe-commits

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


[lldb] [clang-tools-extra] [clang] [llvm] Add new API in SBTarget for loading core from SBFile (PR #71769)

2023-11-14 Thread via cfe-commits

https://github.com/GeorgeHuyubo updated 
https://github.com/llvm/llvm-project/pull/71769

>From fd42e87a663754ca7273715ea40f397df41e3da0 Mon Sep 17 00:00:00 2001
From: George Hu 
Date: Wed, 8 Nov 2023 16:25:34 -0800
Subject: [PATCH] Add new API in SBTarget for loading core from SBFile

---
 lldb/include/lldb/API/SBTarget.h  |  1 +
 lldb/include/lldb/Target/PostMortemProcess.h  | 15 
 lldb/include/lldb/Target/Process.h| 10 +-
 lldb/include/lldb/Target/ProcessTrace.h   |  5 +--
 lldb/include/lldb/Target/Target.h |  3 +-
 lldb/include/lldb/lldb-private-interfaces.h   |  7 ++--
 lldb/source/API/SBTarget.cpp  | 34 +--
 lldb/source/Commands/CommandObjectTarget.cpp  | 11 +-
 lldb/source/Core/IOHandlerCursesGUI.cpp   | 13 +--
 .../FreeBSDKernel/ProcessFreeBSDKernel.cpp| 27 +--
 .../FreeBSDKernel/ProcessFreeBSDKernel.h  |  8 ++---
 .../Process/MacOSX-Kernel/ProcessKDP.cpp  |  4 +--
 .../Process/MacOSX-Kernel/ProcessKDP.h|  9 ++---
 .../Process/elf-core/ProcessElfCore.cpp   | 22 ++--
 .../Plugins/Process/elf-core/ProcessElfCore.h | 12 +++
 .../Process/gdb-remote/ProcessGDBRemote.cpp   |  9 ++---
 .../Process/gdb-remote/ProcessGDBRemote.h |  3 +-
 .../Process/mach-core/ProcessMachCore.cpp | 23 +++--
 .../Process/mach-core/ProcessMachCore.h   | 11 +++---
 .../Process/minidump/ProcessMinidump.cpp  | 16 +
 .../Process/minidump/ProcessMinidump.h|  6 ++--
 .../Process/scripted/ScriptedProcess.cpp  |  2 +-
 .../Process/scripted/ScriptedProcess.h|  2 +-
 lldb/source/Target/Process.cpp| 11 +++---
 lldb/source/Target/ProcessTrace.cpp   | 11 +++---
 lldb/source/Target/Target.cpp |  2 +-
 .../postmortem/elf-core/TestLinuxCore.py  | 16 +
 .../Target/LocateModuleCallbackTest.cpp   |  3 +-
 28 files changed, 200 insertions(+), 96 deletions(-)

diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 83087623088c5b4..afc949390ac3379 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -184,6 +184,7 @@ class LLDB_API SBTarget {
 
   SBProcess LoadCore(const char *core_file);
   SBProcess LoadCore(const char *core_file, lldb::SBError &error);
+  SBProcess LoadCore(SBFile &file, lldb::SBError &error);
 
   /// Launch a new process with sensible defaults.
   ///
diff --git a/lldb/include/lldb/Target/PostMortemProcess.h 
b/lldb/include/lldb/Target/PostMortemProcess.h
index 7207fc99ef29a41..2bd775c9e2c5196 100644
--- a/lldb/include/lldb/Target/PostMortemProcess.h
+++ b/lldb/include/lldb/Target/PostMortemProcess.h
@@ -10,6 +10,8 @@
 #define LLDB_TARGET_POSTMORTEMPROCESS_H
 
 #include "lldb/Target/Process.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/lldb-forward.h"
 
 namespace lldb_private {
 
@@ -24,7 +26,20 @@ class PostMortemProcess : public Process {
   using Process::Process;
 
 public:
+  PostMortemProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
+lldb::FileSP file_sp)
+  : Process(target_sp, listener_sp), m_core_file(file_sp) {}
+
   bool IsLiveDebugSession() const override { return false; }
+
+  FileSpec GetCoreFile() const override {
+FileSpec file_spec;
+m_core_file->GetFileSpec(file_spec);
+return file_spec;
+  }
+
+protected:
+  lldb::FileSP m_core_file;
 };
 
 } // namespace lldb_private
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index a6d3e6c2d16926e..6e2cafbfce9698e 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -52,6 +52,7 @@
 #include "lldb/Utility/TraceGDBRemotePackets.h"
 #include "lldb/Utility/UnimplementedError.h"
 #include "lldb/Utility/UserIDResolver.h"
+#include "lldb/lldb-forward.h"
 #include "lldb/lldb-private.h"
 
 #include "llvm/ADT/ArrayRef.h"
@@ -507,7 +508,7 @@ class Process : public 
std::enable_shared_from_this,
   static lldb::ProcessSP FindPlugin(lldb::TargetSP target_sp,
 llvm::StringRef plugin_name,
 lldb::ListenerSP listener_sp,
-const FileSpec *crash_file_path,
+lldb::FileSP crash_file_sp,
 bool can_connect);
 
   /// Static function that can be used with the \b host function
@@ -1469,6 +1470,13 @@ class Process : public 
std::enable_shared_from_this,
 
   virtual bool IsLiveDebugSession() const { return true; };
 
+  /// Provide a way to retrieve the core dump file that is loaded for 
debugging.
+  /// Only available if IsLiveDebugSession() returns false.
+  ///
+  /// \return
+  /// File path to the core file.
+  virtual FileSpec GetCoreFile() const { return {}; }
+
   /// Before lldb detaches from a process, it warns the user that they are
   /// about to los

[clang] [Clang] Correct handling of negative and out-of-bounds indices (PR #71877)

2023-11-14 Thread Bill Wendling via cfe-commits

bwendling wrote:

Friendly ping to @rapidsna and @nickdesaulniers 

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


[clang] [Clang] counted_by attr can apply only to C99 flexible array members (PR #72347)

2023-11-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Bill Wendling (bwendling)


Changes

Ensure that we're dealing only with C99 flexible array members. I.e. ones with 
incomplete types:

  struct s {
int count;
char array[]; /* note: no size specified */
  };

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


4 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1) 
- (modified) clang/lib/AST/DeclBase.cpp (-3) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+1-1) 
- (modified) clang/test/Sema/attr-counted-by.c (+7-2) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4614324babb1c91..f9dec60cf990784 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6412,7 +6412,7 @@ def warn_superclass_variable_sized_type_not_at_end : 
Warning<
   " in superclass %3">, InGroup;
 
 def err_counted_by_attr_not_on_flexible_array_member : Error<
-  "'counted_by' only applies to flexible array members">;
+  "'counted_by' only applies to C99 flexible array members">;
 def err_counted_by_attr_refers_to_flexible_array : Error<
   "'counted_by' cannot refer to the flexible array %0">;
 def err_counted_by_must_be_in_structure : Error<
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 4fcc2e7302c034c..e4d7169752bc857 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -421,9 +421,6 @@ bool Decl::isFlexibleArrayMemberLike(
 using FAMKind = LangOptions::StrictFlexArraysLevelKind;
 
 llvm::APInt Size = CAT->getSize();
-FAMKind StrictFlexArraysLevel =
-Ctx.getLangOpts().getStrictFlexArraysLevel();
-
 if (StrictFlexArraysLevel == FAMKind::IncompleteOnly)
   return false;
 
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index cdb769a883550d0..fd778793346f502 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -8430,7 +8430,7 @@ bool Sema::CheckCountedByAttr(Scope *S, const FieldDecl 
*FD) {
   }
 
   LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
-  Context.getLangOpts().getStrictFlexArraysLevel();
+  LangOptions::StrictFlexArraysLevelKind::IncompleteOnly;
 
   if (!Decl::isFlexibleArrayMemberLike(Context, FD, FD->getType(),
StrictFlexArraysLevel, true)) {
diff --git a/clang/test/Sema/attr-counted-by.c 
b/clang/test/Sema/attr-counted-by.c
index 654ddb7f1b42b1a..ab3b6e6d710b503 100644
--- a/clang/test/Sema/attr-counted-by.c
+++ b/clang/test/Sema/attr-counted-by.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fstrict-flex-arrays=3 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s
 
 #define __counted_by(f)  __attribute__((counted_by(f)))
 
@@ -38,7 +38,12 @@ struct array_of_ints_count {
 
 struct not_a_fam {
   int count;
-  struct bar *non_fam __counted_by(count); // expected-error {{'counted_by' 
only applies to flexible array members}}
+  struct bar *non_fam __counted_by(count); // expected-error {{'counted_by' 
only applies to C99 flexible array members}}
+};
+
+struct not_a_c99_fam {
+  int count;
+  struct bar *non_c99_fam[0] __counted_by(count); // expected-error 
{{'counted_by' only applies to C99 flexible array members}}
 };
 
 struct annotated_with_anon_struct {

``




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


[clang] [Clang] counted_by attr can apply only to C99 flexible array members (PR #72347)

2023-11-14 Thread Bill Wendling via cfe-commits

https://github.com/bwendling created 
https://github.com/llvm/llvm-project/pull/72347

Ensure that we're dealing only with C99 flexible array members. I.e. ones with 
incomplete types:

  struct s {
int count;
char array[]; /* note: no size specified */
  };

>From 21bea1699d80e53d857bf2656e75e56d98350dea Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Tue, 14 Nov 2023 10:33:58 -0500
Subject: [PATCH] [Clang] counted_by attr can apply only to C99 flexible array
 members

Ensure that we're dealing only with C99 flexible array members. I.e.
ones with incomplete types:

  struct s {
int count;
char array[]; /* note: no size specified */
  };
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 clang/lib/AST/DeclBase.cpp   | 3 ---
 clang/lib/Sema/SemaDeclAttr.cpp  | 2 +-
 clang/test/Sema/attr-counted-by.c| 9 +++--
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4614324babb1c91..f9dec60cf990784 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6412,7 +6412,7 @@ def warn_superclass_variable_sized_type_not_at_end : 
Warning<
   " in superclass %3">, InGroup;
 
 def err_counted_by_attr_not_on_flexible_array_member : Error<
-  "'counted_by' only applies to flexible array members">;
+  "'counted_by' only applies to C99 flexible array members">;
 def err_counted_by_attr_refers_to_flexible_array : Error<
   "'counted_by' cannot refer to the flexible array %0">;
 def err_counted_by_must_be_in_structure : Error<
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 4fcc2e7302c034c..e4d7169752bc857 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -421,9 +421,6 @@ bool Decl::isFlexibleArrayMemberLike(
 using FAMKind = LangOptions::StrictFlexArraysLevelKind;
 
 llvm::APInt Size = CAT->getSize();
-FAMKind StrictFlexArraysLevel =
-Ctx.getLangOpts().getStrictFlexArraysLevel();
-
 if (StrictFlexArraysLevel == FAMKind::IncompleteOnly)
   return false;
 
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index cdb769a883550d0..fd778793346f502 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -8430,7 +8430,7 @@ bool Sema::CheckCountedByAttr(Scope *S, const FieldDecl 
*FD) {
   }
 
   LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
-  Context.getLangOpts().getStrictFlexArraysLevel();
+  LangOptions::StrictFlexArraysLevelKind::IncompleteOnly;
 
   if (!Decl::isFlexibleArrayMemberLike(Context, FD, FD->getType(),
StrictFlexArraysLevel, true)) {
diff --git a/clang/test/Sema/attr-counted-by.c 
b/clang/test/Sema/attr-counted-by.c
index 654ddb7f1b42b1a..ab3b6e6d710b503 100644
--- a/clang/test/Sema/attr-counted-by.c
+++ b/clang/test/Sema/attr-counted-by.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fstrict-flex-arrays=3 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s
 
 #define __counted_by(f)  __attribute__((counted_by(f)))
 
@@ -38,7 +38,12 @@ struct array_of_ints_count {
 
 struct not_a_fam {
   int count;
-  struct bar *non_fam __counted_by(count); // expected-error {{'counted_by' 
only applies to flexible array members}}
+  struct bar *non_fam __counted_by(count); // expected-error {{'counted_by' 
only applies to C99 flexible array members}}
+};
+
+struct not_a_c99_fam {
+  int count;
+  struct bar *non_c99_fam[0] __counted_by(count); // expected-error 
{{'counted_by' only applies to C99 flexible array members}}
 };
 
 struct annotated_with_anon_struct {

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


[clang] [Clang] Fix finding instantiated decls for class template specializations during instantiation (PR #72346)

2023-11-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yuxuan Chen (yuxuanchen1997)


Changes

This change aims to fix https://github.com/llvm/llvm-project/issues/70375

It appears to me that the logic here should be handling specializations in 
general. Not just partial specialization. It also seems that both the comment 
before the block and the `isInstantiationOf(ClassTemplate, SpecTemplate)` below 
agree with my judgement. 

The issue might just be a mistake that someone mistaken specialization as a 
special case of partial specializations, while it's actually the other way 
around.

Needs some experts to comment here if this is the right fix. 

The code that caused clang ICE is added as a test case. 

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+3-3) 
- (added) clang/test/SemaCXX/member-template-specialization.cpp (+33) 


``diff
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 011356e08a04297..07b3488a21e670b 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -6211,9 +6211,9 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, 
NamedDecl *D,
 ClassTemplateDecl *ClassTemplate = Record->getDescribedClassTemplate();
 if (ClassTemplate)
   ClassTemplate = ClassTemplate->getCanonicalDecl();
-else if (ClassTemplatePartialSpecializationDecl *PartialSpec
-   = dyn_cast(Record))
-  ClassTemplate = 
PartialSpec->getSpecializedTemplate()->getCanonicalDecl();
+else if (ClassTemplateSpecializationDecl *Spec =
+ dyn_cast(Record))
+  ClassTemplate = Spec->getSpecializedTemplate()->getCanonicalDecl();
 
 // Walk the current context to find either the record or an instantiation 
of
 // it.
diff --git a/clang/test/SemaCXX/member-template-specialization.cpp 
b/clang/test/SemaCXX/member-template-specialization.cpp
new file mode 100644
index 000..29d46ec9c1e44fc
--- /dev/null
+++ b/clang/test/SemaCXX/member-template-specialization.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+// expected-no-diagnostics
+
+// Verify that the inner template specialization can be found
+
+template 
+struct S {
+  static void bar() {
+Ty t;
+t.foo();
+  }
+
+  static void take(Ty&) {}
+};
+
+template 
+struct Outer {
+  template 
+  struct Inner;
+
+  using U = S>;
+
+  template <>
+  struct Inner {
+void foo() {
+  U::take(*this);
+}
+  };
+};
+
+int main() {
+  Outer::U::bar();
+}

``




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


[clang] [Clang] Fix finding instantiated decls for class template specializations during instantiation (PR #72346)

2023-11-14 Thread Yuxuan Chen via cfe-commits

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


[clang] [Clang] Fix finding instantiated decls for class template specializations during instantiation (PR #72346)

2023-11-14 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 created 
https://github.com/llvm/llvm-project/pull/72346

This change aims to fix https://github.com/llvm/llvm-project/issues/70375

It appears to me that the logic here should be handling specializations in 
general. Not just partial specialization. It also seems that both the comment 
before the block and the `isInstantiationOf(ClassTemplate, SpecTemplate)` below 
agree with my judgement. 

The issue might just be a mistake that someone mistaken specialization as a 
special case of partial specializations, while it's actually the other way 
around.

Needs some experts to comment here if this is the right fix. 

The code that caused clang ICE is added as a test case. 

>From f238608b792f69b93eb445ee596125f3e20acf39 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 14 Nov 2023 20:52:21 -0800
Subject: [PATCH 1/4] [Clang] Fix ICE caused by mishandling template
 specialization in instantiation lookup

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

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 011356e08a04297..2ef0986dd4d2235 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -6211,9 +6211,8 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, 
NamedDecl *D,
 ClassTemplateDecl *ClassTemplate = Record->getDescribedClassTemplate();
 if (ClassTemplate)
   ClassTemplate = ClassTemplate->getCanonicalDecl();
-else if (ClassTemplatePartialSpecializationDecl *PartialSpec
-   = dyn_cast(Record))
-  ClassTemplate = 
PartialSpec->getSpecializedTemplate()->getCanonicalDecl();
+else if (ClassTemplateSpecializationDecl *Spec = 
dyn_cast(Record))
+  ClassTemplate = Spec->getSpecializedTemplate()->getCanonicalDecl();
 
 // Walk the current context to find either the record or an instantiation 
of
 // it.

>From 9a79db980951299c93cc4530230717af6f4668b3 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 14 Nov 2023 20:55:10 -0800
Subject: [PATCH 2/4] formatting

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

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 2ef0986dd4d2235..07b3488a21e670b 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -6211,7 +6211,8 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, 
NamedDecl *D,
 ClassTemplateDecl *ClassTemplate = Record->getDescribedClassTemplate();
 if (ClassTemplate)
   ClassTemplate = ClassTemplate->getCanonicalDecl();
-else if (ClassTemplateSpecializationDecl *Spec = 
dyn_cast(Record))
+else if (ClassTemplateSpecializationDecl *Spec =
+ dyn_cast(Record))
   ClassTemplate = Spec->getSpecializedTemplate()->getCanonicalDecl();
 
 // Walk the current context to find either the record or an instantiation 
of

>From df884c7127bb2f0956521adc479a923c62220d7c Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 14 Nov 2023 21:04:00 -0800
Subject: [PATCH 3/4] Provide test case

---
 .../member-template-specialization.cpp| 31 +++
 1 file changed, 31 insertions(+)
 create mode 100644 clang/test/SemaCXX/member-template-specialization.cpp

diff --git a/clang/test/SemaCXX/member-template-specialization.cpp 
b/clang/test/SemaCXX/member-template-specialization.cpp
new file mode 100644
index 000..baf5bd6ae7bb544
--- /dev/null
+++ b/clang/test/SemaCXX/member-template-specialization.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+// Verify that the inner template specialization can be found
+
+template 
+struct S {
+  static void bar() {
+Ty t;
+t.foo();
+  }
+
+  static void take(Ty&) {}
+};
+
+template 
+struct Outer {
+  template 
+  struct Inner;
+
+  using U = S>;
+
+  template <>
+  struct Inner {
+void foo() {
+  U::take(*this);
+}
+  };
+};
+
+int main() {
+  Outer::U::bar();
+}

>From 7cdbce7944e051aed5b1f8ab789ce1e43f3e58b3 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Tue, 14 Nov 2023 21:13:23 -0800
Subject: [PATCH 4/4] missing expected-no-diagnostics

---
 clang/test/SemaCXX/member-template-specialization.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/test/SemaCXX/member-template-specialization.cpp 
b/clang/test/SemaCXX/member-template-specialization.cpp
index baf5bd6ae7bb544..29d46ec9c1e44fc 100644
--- a/clang/test/SemaCXX/member-template-specialization.cpp
+++ b/clang/test/SemaCXX/member-template-specialization.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -verify -fsyntax-only %s
+// expected-no-diagnostics
+
 // Verify that the inner template specialization can be found
 
 template 

___
cfe-commits mailing list
cfe

[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-14 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/72213

>From bc9e06ea87dca046227faf2996eb8de521863d57 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Fri, 20 Oct 2023 14:40:25 +0200
Subject: [PATCH 1/3] [clang] Handle templated operators with reversed
 arguments (#69595)

https://github.com/llvm/llvm-project/pull/68999 correctly computed
conversion sequence for reversed args to a template operators. This was
a breaking change as code, previously accepted in C++17, starts to break
in C++20.

Example:
```cpp
struct P {};
template bool operator==(const P&, const S &);

struct A : public P {};
struct B : public P {};
bool check(A a, B b) { return a == b; }  // This is now ambiguous in C++20.
```

In order to minimise widespread breakages, as a clang extension, we had
previously accepted such ambiguities with a warning
(`-Wambiguous-reversed-operator`) for non-template operators. Due to the
same reasons, we extend this relaxation for template operators.

Fixes https://github.com/llvm/llvm-project/issues/53954
---
 clang/docs/ReleaseNotes.rst   | 21 +++
 clang/lib/Sema/SemaOverload.cpp   | 28 ++---
 .../over.match.oper/p3-2a.cpp | 61 +++
 3 files changed, 100 insertions(+), 10 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7a131cb520aa600..5c974eec9ed67d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -37,6 +37,27 @@ These changes are ones which we think may surprise users 
when upgrading to
 Clang |release| because of the opportunity they pose for disruption to existing
 code bases.
 
+- Fix a bug in reversed argument for templated operators.
+  This breaks code in C++20 which was previously accepted in C++17. Eg:
+
+  .. code-block:: cpp
+
+struct P {};
+template bool operator==(const P&, const S&);
+
+struct A : public P {};
+struct B : public P {};
+
+// This equality is now ambiguous in C++20.
+bool ambiguous(A a, B b) { return a == b; }
+
+template bool operator!=(const P&, const S&);
+// Ok. Found a matching operator!=.
+bool fine(A a, B b) { return a == b; }
+
+  To reduce such widespread breakages, as an extension, Clang accepts this code
+  with an existing warning ``-Wambiguous-reversed-operator`` warning.
+  Fixes `GH `_.
 
 C/C++ Language Potentially Breaking Changes
 ---
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index f97e244120612e3..73f417cc8bd4024 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7685,7 +7685,7 @@ bool Sema::CheckNonDependentConversions(
 QualType ParamType = ParamTypes[I + Offset];
 if (!ParamType->isDependentType()) {
   unsigned ConvIdx = PO == OverloadCandidateParamOrder::Reversed
- ? 0
+ ? Args.size() - 1 - (ThisConversions + I)
  : (ThisConversions + I);
   Conversions[ConvIdx]
 = TryCopyInitialization(*this, Args[I], ParamType,
@@ -10082,11 +10082,19 @@ getImplicitObjectParamType(ASTContext &Context, const 
FunctionDecl *F) {
   return M->getFunctionObjectParameterReferenceType();
 }
 
-static bool haveSameParameterTypes(ASTContext &Context, const FunctionDecl *F1,
-   const FunctionDecl *F2) {
+// As a Clang extension, allow ambiguity among F1 and F2 if they represent
+// represent the same entity.
+static bool allowAmbiguity(ASTContext &Context, const FunctionDecl *F1,
+   const FunctionDecl *F2) {
   if (declaresSameEntity(F1, F2))
 return true;
-
+  if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation() &&
+  declaresSameEntity(F1->getPrimaryTemplate(), F2->getPrimaryTemplate())) {
+return true;
+  }
+  // TODO: It is not clear whether comparing parameters is necessary (i.e.
+  // different functions with same params). Consider removing this (as no test
+  // fail w/o it).
   auto NextParam = [&](const FunctionDecl *F, unsigned &I, bool First) {
 if (First) {
   if (std::optional T = getImplicitObjectParamType(Context, F))
@@ -10271,14 +10279,14 @@ bool clang::isBetterOverloadCandidate(
 case ImplicitConversionSequence::Worse:
   if (Cand1.Function && Cand2.Function &&
   Cand1.isReversed() != Cand2.isReversed() &&
-  haveSameParameterTypes(S.Context, Cand1.Function, Cand2.Function)) {
+  allowAmbiguity(S.Context, Cand1.Function, Cand2.Function)) {
 // Work around large-scale breakage caused by considering reversed
 // forms of operator== in C++20:
 //
-// When comparing a function against a reversed function with the same
-// parameter types, if we have a better conversion for one argument and
-// a worse conversion for the ot

[clang-tools-extra] [clangd] Improve BlockEnd inlay hints presentation (PR #72345)

2023-11-14 Thread via cfe-commits

daiyousei-qz wrote:

@HighCommander4 @sam-mccall for opinions.

I haven't update the test because the hard-coded limit 10 makes it hard to 
write the tests. Any opinion of how to structure this?

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


[clang-tools-extra] [clangd] Improve BlockEnd inlay hints presentation (PR #72345)

2023-11-14 Thread via cfe-commits

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


[clang-tools-extra] [clangd] Improve BlockEnd inlay hints presentation (PR #72345)

2023-11-14 Thread via cfe-commits

https://github.com/daiyousei-qz created 
https://github.com/llvm/llvm-project/pull/72345

Including:
1. Explicitly state a function call
2. Print literal nullptr
3. Escape for abbreviated string
4. Adjust min line limit to 10

Fixes issue [clangd/clangd#1807](https://github.com/clangd/clangd/issues/1807)

>From 1a196e908998e9ba1edf9a9c0a48877138b1a223 Mon Sep 17 00:00:00 2001
From: daiyousei-qz 
Date: Tue, 14 Nov 2023 20:42:10 -0800
Subject: [PATCH] Improve BlockEnd presentation including: 1. Explicitly state
 a function call 2. Print literal nullptr 3. Escape for abbreviated string 4.
 Adjust min line limit to 10

---
 clang-tools-extra/clangd/InlayHints.cpp | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 3da047f95421385..97b467fbb519dbd 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -266,7 +266,9 @@ std::string summarizeExpr(const Expr *E) {
   return getSimpleName(*E->getFoundDecl()).str();
 }
 std::string VisitCallExpr(const CallExpr *E) {
-  return Visit(E->getCallee());
+  std::string Result = Visit(E->getCallee());
+  Result += E->getNumArgs() == 0 ? "()" : "(...)";
+  return Result;
 }
 std::string
 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
@@ -301,6 +303,9 @@ std::string summarizeExpr(const Expr *E) {
 }
 
 // Literals are just printed
+std::string VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E) {
+  return "nullptr";
+}
 std::string VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) {
   return E->getValue() ? "true" : "false";
 }
@@ -319,12 +324,14 @@ std::string summarizeExpr(const Expr *E) {
   std::string Result = "\"";
   if (E->containsNonAscii()) {
 Result += "...";
-  } else if (E->getLength() > 10) {
-Result += E->getString().take_front(7);
-Result += "...";
   } else {
 llvm::raw_string_ostream OS(Result);
-llvm::printEscapedString(E->getString(), OS);
+if (E->getLength() > 10) {
+  llvm::printEscapedString(E->getString().take_front(7), OS);
+  Result += "...";
+} else {
+  llvm::printEscapedString(E->getString(), OS);
+}
   }
   Result.push_back('"');
   return Result;
@@ -1193,7 +1200,7 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   // Otherwise, the hint shouldn't be shown.
   std::optional computeBlockEndHintRange(SourceRange BraceRange,
 StringRef OptionalPunctuation) 
{
-constexpr unsigned HintMinLineLimit = 2;
+constexpr unsigned HintMinLineLimit = 10;
 
 auto &SM = AST.getSourceManager();
 auto [BlockBeginFileId, BlockBeginOffset] =

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


[clang] [MS-ABI] create unique vftable name for vftable defined with internal alias. (PR #71748)

2023-11-14 Thread Eli Friedman via cfe-commits

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

I see unrelated changes on the branch?  Otherwise LGTM

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


[clang] [clang-tools-extra] [llvm] [polly] Reduction series : Refactor reduction detection code (PR #72343)

2023-11-14 Thread Karthika Devi C via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [polly] Reduction series : Refactor reduction detection code (PR #72343)

2023-11-14 Thread Karthika Devi C via cfe-commits

https://github.com/kartcq created 
https://github.com/llvm/llvm-project/pull/72343

None

>From 3a8c2b0b7485ea6ee3d45b87132554a2b812aa50 Mon Sep 17 00:00:00 2001
From: kartcq 
Date: Mon, 6 Nov 2023 03:42:09 -0800
Subject: [PATCH] [polly][NFC] Refactor reduction detection code for modularity

This patch pulls out the memory checks from the base reduction detection
algorithm. This is the first one in the reduction patch series, to
reduce diff in future patches.
---
 polly/lib/Analysis/ScopBuilder.cpp | 78 ++
 1 file changed, 48 insertions(+), 30 deletions(-)

diff --git a/polly/lib/Analysis/ScopBuilder.cpp 
b/polly/lib/Analysis/ScopBuilder.cpp
index c34413812d9464e..0af0f6915b14585 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -2510,6 +2510,48 @@ static MemoryAccess::ReductionType 
getReductionType(const BinaryOperator *BinOp,
   }
 }
 
+///  True if @p AllAccs intersects with @p MemAccs execpt @p LoadMA and @p
+///  StoreMA
+bool hasIntersectingAccesses(isl::set AllAccs, MemoryAccess *LoadMA,
+ MemoryAccess *StoreMA, isl::set Domain,
+ SmallVector &MemAccs) {
+  bool HasIntersectingAccs = false;
+  for (MemoryAccess *MA : MemAccs) {
+if (MA == LoadMA || MA == StoreMA)
+  continue;
+
+isl::map AccRel = MA->getAccessRelation().intersect_domain(Domain);
+isl::set Accs = AccRel.range();
+
+if (AllAccs.has_equal_space(Accs)) {
+  isl::set OverlapAccs = Accs.intersect(AllAccs);
+  bool DoesIntersect = !OverlapAccs.is_empty();
+  HasIntersectingAccs |= DoesIntersect;
+}
+  }
+  return HasIntersectingAccs;
+}
+
+///  Test if the accesses of @p LoadMA and @p StoreMA can form a reduction
+bool checkCandidatePairAccesses(MemoryAccess *LoadMA, MemoryAccess *StoreMA,
+isl::set Domain,
+SmallVector &MemAccs) {
+  isl::map LoadAccs = LoadMA->getAccessRelation();
+  isl::map StoreAccs = StoreMA->getAccessRelation();
+
+  // Skip those with obviously unequal base addresses.
+  bool Valid = LoadAccs.has_equal_space(StoreAccs);
+
+  // And check if the remaining for overlap with other memory accesses.
+  if (Valid) {
+isl::map AllAccsRel = LoadAccs.unite(StoreAccs);
+AllAccsRel = AllAccsRel.intersect_domain(Domain);
+isl::set AllAccs = AllAccsRel.range();
+Valid = !hasIntersectingAccesses(AllAccs, LoadMA, StoreMA, Domain, 
MemAccs);
+  }
+  return Valid;
+}
+
 void ScopBuilder::checkForReductions(ScopStmt &Stmt) {
   SmallVector Loads;
   SmallVector, 4> Candidates;
@@ -2528,34 +2570,10 @@ void ScopBuilder::checkForReductions(ScopStmt &Stmt) {
 
   // Then check each possible candidate pair.
   for (const auto &CandidatePair : Candidates) {
-bool Valid = true;
-isl::map LoadAccs = CandidatePair.first->getAccessRelation();
-isl::map StoreAccs = CandidatePair.second->getAccessRelation();
-
-// Skip those with obviously unequal base addresses.
-if (!LoadAccs.has_equal_space(StoreAccs)) {
-  continue;
-}
-
-// And check if the remaining for overlap with other memory accesses.
-isl::map AllAccsRel = LoadAccs.unite(StoreAccs);
-AllAccsRel = AllAccsRel.intersect_domain(Stmt.getDomain());
-isl::set AllAccs = AllAccsRel.range();
-
-for (MemoryAccess *MA : Stmt) {
-  if (MA == CandidatePair.first || MA == CandidatePair.second)
-continue;
-
-  isl::map AccRel =
-  MA->getAccessRelation().intersect_domain(Stmt.getDomain());
-  isl::set Accs = AccRel.range();
-
-  if (AllAccs.has_equal_space(Accs)) {
-isl::set OverlapAccs = Accs.intersect(AllAccs);
-Valid = Valid && OverlapAccs.is_empty();
-  }
-}
-
+MemoryAccess *LoadMA = CandidatePair.first;
+MemoryAccess *StoreMA = CandidatePair.second;
+bool Valid = checkCandidatePairAccesses(LoadMA, StoreMA, Stmt.getDomain(),
+Stmt.MemAccs);
 if (!Valid)
   continue;
 
@@ -2566,8 +2584,8 @@ void ScopBuilder::checkForReductions(ScopStmt &Stmt) {
 
 // If no overlapping access was found we mark the load and store as
 // reduction like.
-CandidatePair.first->markAsReductionLike(RT);
-CandidatePair.second->markAsReductionLike(RT);
+LoadMA->markAsReductionLike(RT);
+StoreMA->markAsReductionLike(RT);
   }
 }
 

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


[clang] Supports viewing class member variables in lambda when using the vs debugger (PR #71564)

2023-11-14 Thread via cfe-commits

https://github.com/GkvJwa updated 
https://github.com/llvm/llvm-project/pull/71564

>From 696560f25a8d3ac36c6c1614628cd91353409ea0 Mon Sep 17 00:00:00 2001
From: GkvJwa 
Date: Wed, 8 Nov 2023 01:37:19 +0800
Subject: [PATCH] Supports viewing class member in lambda when using the vs
 debugger

Use "__this" in the DataMemberRecord when generating pdb, so that the vs 
debugger can parse the  member vars in lambda normally
---
 clang/lib/CodeGen/CGDebugInfo.cpp  |  4 +-
 clang/test/CodeGenCXX/lambda-this-info.cpp | 48 ++
 2 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/lambda-this-info.cpp

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 84a166d3ac3659c..774bc0eae157f49 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1657,8 +1657,10 @@ void CGDebugInfo::CollectRecordLambdaFields(
   FieldDecl *f = *Field;
   llvm::DIFile *VUnit = getOrCreateFile(f->getLocation());
   QualType type = f->getType();
+  StringRef ThisName =
+  CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this";
   llvm::DIType *fieldType = createFieldType(
-  "this", type, f->getLocation(), f->getAccess(),
+  ThisName, type, f->getLocation(), f->getAccess(),
   layout.getFieldOffset(fieldno), VUnit, RecordTy, CXXDecl);
 
   elements.push_back(fieldType);
diff --git a/clang/test/CodeGenCXX/lambda-this-info.cpp 
b/clang/test/CodeGenCXX/lambda-this-info.cpp
new file mode 100644
index 000..4ecd96a67152f44
--- /dev/null
+++ b/clang/test/CodeGenCXX/lambda-this-info.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -o %t.obj -- %s
+// RUN: llvm-pdbutil dump -all %t.obj | FileCheck %s
+
+class Foo {
+ public:
+  void foo() {
+int aa = 4;
+int bb = 5;
+int cc = 6;
+auto f = [=] {
+  int aaa = a + aa;
+  int bbb = b + bb;
+  int ccc = c + cc;
+};
+f();
+  }
+
+ private:
+  int a = 1;
+  int b = 2;
+  int c = 3;
+};
+
+int main() {
+  Foo f;
+  f.foo();
+
+  return 0;
+}
+
+// CHECK:   Types (.debug$T)
+// CHECK-NEXT: 
+// CHECK: [[FooClassIndex:0x[^ ]*]] | LF_CLASS [size = 36] `Foo`
+// CHECK-NEXT:   unique name: `.?AVFoo@@`
+// CHECK: 0x{{.*}} | LF_FIELDLIST [size = 52]
+// CHECK-NEXT:  - LF_MEMBER [name = `a`, Type = 0x0074 (int), offset = 
0, attrs = private]
+// CHECK-NEXT:  - LF_MEMBER [name = `b`, Type = 0x0074 (int), offset = 
4, attrs = private]
+// CHECK-NEXT:  - LF_MEMBER [name = `c`, Type = 0x0074 (int), offset = 
8, attrs = private]
+// CHECK-NEXT:  - LF_ONEMETHOD [name = `foo`]
+// CHECK: [[FooPointerIndex:0x[^ ]*]] | LF_POINTER [size = 12]
+// CHECK-NEXT:  referent = [[FooClassIndex]], mode = pointer, opts = 
None, kind = ptr64
+// CHECK: 0x{{.*}} | LF_CLASS [size = 80] `Foo::foo::`
+// CHECK-NEXT:  unique name: `.?AV@?0??foo@Foo@@QEAAXXZ@`
+// CHECK: 0x{{.*}} | LF_FIELDLIST [size = 72]
+// CHECK-NEXT:  - LF_MEMBER [name = `__this`, Type = 
[[FooPointerIndex]], offset = 0, attrs = private]
+// CHECK-NEXT:  - LF_MEMBER [name = `aa`, Type = 0x0074 (int), offset 
= 8, attrs = private]
+// CHECK-NEXT:  - LF_MEMBER [name = `bb`, Type = 0x0074 (int), offset 
= 12, attrs = private]
+// CHECK-NEXT:  - LF_MEMBER [name = `cc`, Type = 0x0074 (int), offset 
= 16, attrs = private]

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


[clang] Supports viewing class member variables in lambda when using the vs debugger (PR #71564)

2023-11-14 Thread via cfe-commits

https://github.com/GkvJwa updated 
https://github.com/llvm/llvm-project/pull/71564

>From abbecea6a3cfbc3cf34b0c0935a6c1cfcf3a97b7 Mon Sep 17 00:00:00 2001
From: GkvJwa 
Date: Wed, 8 Nov 2023 01:37:19 +0800
Subject: [PATCH] Supports viewing class member in lambda when using the vs
 debugger

Use "__this" in the DataMemberRecord when generating pdb, so that the vs 
debugger can parse the  member vars in lambda normally
---
 clang/lib/CodeGen/CGDebugInfo.cpp  |  4 +-
 clang/test/CodeGenCXX/lambda-this-info.cpp | 48 ++
 2 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/lambda-this-info.cpp

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 84a166d3ac3659c..774bc0eae157f49 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1657,8 +1657,10 @@ void CGDebugInfo::CollectRecordLambdaFields(
   FieldDecl *f = *Field;
   llvm::DIFile *VUnit = getOrCreateFile(f->getLocation());
   QualType type = f->getType();
+  StringRef ThisName =
+  CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this";
   llvm::DIType *fieldType = createFieldType(
-  "this", type, f->getLocation(), f->getAccess(),
+  ThisName, type, f->getLocation(), f->getAccess(),
   layout.getFieldOffset(fieldno), VUnit, RecordTy, CXXDecl);
 
   elements.push_back(fieldType);
diff --git a/clang/test/CodeGenCXX/lambda-this-info.cpp 
b/clang/test/CodeGenCXX/lambda-this-info.cpp
new file mode 100644
index 000..68288b8ba71d8c1
--- /dev/null
+++ b/clang/test/CodeGenCXX/lambda-this-info.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -o %t.obj -- %s
+// RUN: llvm-pdbutil dump -all %t.obj | FileCheck %s
+
+class Foo {
+ public:
+  void foo() {
+int aa = 4;
+int bb = 5;
+int cc = 6;
+auto f = [=] {
+  int aaa = a + aa;
+  int bbb = b + bb;
+  int ccc = c + cc;
+};
+f();
+  }
+
+ private:
+  int a = 1;
+  int b = 2;
+  int c = 3;
+};
+
+int main() {
+  Foo f;
+  f.foo();
+
+  return 0;
+}
+
+// CHECK:   Types (.debug$T)
+// CHECK-NEXT: 
+// CHECK: [[FooClassIndex:0x[^ ]*]] | LF_CLASS [size = 36] `Foo`
+// CHECK:   unique name: `.?AVFoo@@`
+// CHECK: 0x{{.*}} | LF_FIELDLIST [size = 52]
+// CHECK:  - LF_MEMBER [name = `a`, Type = 0x0074 (int), offset = 0, 
attrs = private]
+// CHECK:  - LF_MEMBER [name = `b`, Type = 0x0074 (int), offset = 4, 
attrs = private]
+// CHECK:  - LF_MEMBER [name = `c`, Type = 0x0074 (int), offset = 8, 
attrs = private]
+// CHECK:  - LF_ONEMETHOD [name = `foo`]
+// CHECK: [[FooPointerIndex:0x[^ ]*]] | LF_POINTER [size = 12]
+// CHECK:  referent = [[FooClassIndex]], mode = pointer, opts = None, 
kind = ptr64
+// CHECK: 0x{{.*}} | LF_CLASS [size = 80] `Foo::foo::`
+// CHECK:  unique name: `.?AV@?0??foo@Foo@@QEAAXXZ@`
+// CHECK: 0x{{.*}} | LF_FIELDLIST [size = 72]
+// CHECK:  - LF_MEMBER [name = `__this`, Type = [[FooPointerIndex]], 
offset = 0, attrs = private]
+// CHECK:  - LF_MEMBER [name = `aa`, Type = 0x0074 (int), offset = 8, 
attrs = private]
+// CHECK:  - LF_MEMBER [name = `bb`, Type = 0x0074 (int), offset = 12, 
attrs = private]
+// CHECK:  - LF_MEMBER [name = `cc`, Type = 0x0074 (int), offset = 16, 
attrs = private]

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


[clang] [clang-format] Fix more bugs in isStartOfName() (PR #72336)

2023-11-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixed #72264.

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


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+2-5) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+14) 


``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 03f3c3583f2ec44..b71f6daa4e14392 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2018,10 +2018,6 @@ class AnnotatingParser {
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
   Contexts.back().FirstStartOfName = &Current;
   Current.setType(TT_StartOfName);
-  if (auto *PrevNonComment = Current.getPreviousNonComment();
-  PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
-PrevNonComment->setType(TT_Unknown);
-  }
 } else if (Current.is(tok::semi)) {
   // Reset FirstStartOfName after finding a semicolon so that a for loop
   // with multiple increment statements is not confused with a for loop
@@ -2210,7 +2206,8 @@ class AnnotatingParser {
   return false;
 
 if (const auto *NextNonComment = Tok.getNextNonComment();
-!NextNonComment || NextNonComment->isPointerOrReference()) {
+!NextNonComment || NextNonComment->isPointerOrReference() ||
+NextNonComment->isOneOf(tok::identifier, tok::string_literal)) {
   return false;
 }
 
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index ed730307074963f..1c0fe60c45c7a87 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2373,6 +2373,20 @@ TEST_F(TokenAnnotatorTest, UnderstandsDoWhile) {
   EXPECT_TOKEN(Tokens[4], tok::kw_while, TT_DoWhile);
 }
 
+TEST_F(TokenAnnotatorTest, NotStartOfName) {
+  auto Tokens = annotate("#pragma clang diagnostic push");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_Unknown);
+
+  Tokens = annotate("#pragma clang diagnostic ignored 
\"-Wzero-length-array\"");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_Unknown);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang

``




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


[clang] [clang-format] Fix more bugs in isStartOfName() (PR #72336)

2023-11-14 Thread Owen Pan via cfe-commits

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

Fixed #72264.

>From 832b6dccb1a8b0d3af4c3970c6c85f97e9cf3283 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 14 Nov 2023 19:21:11 -0800
Subject: [PATCH] [clang-format] Fix more bugs in isStartOfName()

Fixed #72264.
---
 clang/lib/Format/TokenAnnotator.cpp   |  7 ++-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 14 ++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 03f3c3583f2ec44..b71f6daa4e14392 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2018,10 +2018,6 @@ class AnnotatingParser {
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
   Contexts.back().FirstStartOfName = &Current;
   Current.setType(TT_StartOfName);
-  if (auto *PrevNonComment = Current.getPreviousNonComment();
-  PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
-PrevNonComment->setType(TT_Unknown);
-  }
 } else if (Current.is(tok::semi)) {
   // Reset FirstStartOfName after finding a semicolon so that a for loop
   // with multiple increment statements is not confused with a for loop
@@ -2210,7 +2206,8 @@ class AnnotatingParser {
   return false;
 
 if (const auto *NextNonComment = Tok.getNextNonComment();
-!NextNonComment || NextNonComment->isPointerOrReference()) {
+!NextNonComment || NextNonComment->isPointerOrReference() ||
+NextNonComment->isOneOf(tok::identifier, tok::string_literal)) {
   return false;
 }
 
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index ed730307074963f..1c0fe60c45c7a87 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2373,6 +2373,20 @@ TEST_F(TokenAnnotatorTest, UnderstandsDoWhile) {
   EXPECT_TOKEN(Tokens[4], tok::kw_while, TT_DoWhile);
 }
 
+TEST_F(TokenAnnotatorTest, NotStartOfName) {
+  auto Tokens = annotate("#pragma clang diagnostic push");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_Unknown);
+
+  Tokens = annotate("#pragma clang diagnostic ignored 
\"-Wzero-length-array\"");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_Unknown);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang

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


[clang] [-Wunsafe-buffer-usage] Add FixableGadget for AddAssign in UnspecifiedUntypedContext (PR #71862)

2023-11-14 Thread Artem Dergachev via cfe-commits


@@ -1312,21 +1353,29 @@ PointerInitGadget::getFixits(const Strategy &S) const {
   return std::nullopt;
 }
 
+static bool isNonNegativeIntegerExpr(const Expr *Expr, const VarDecl *VD,
+ const ASTContext &Ctx) {
+  if (auto ConstVal = Expr->getIntegerConstantExpr(Ctx)) {
+if (ConstVal->isNegative())
+  return false;
+  } else if (!Expr->getType()->isUnsignedIntegerType())
+return false;
+  return true;
+}
+
 std::optional
 ULCArraySubscriptGadget::getFixits(const Strategy &S) const {
   if (const auto *DRE =
   dyn_cast(Node->getBase()->IgnoreImpCasts()))
 if (const auto *VD = dyn_cast(DRE->getDecl())) {
   switch (S.lookup(VD)) {
   case Strategy::Kind::Span: {
+
 // If the index has a negative constant value, we give up as no valid
 // fix-it can be generated:
 const ASTContext &Ctx = // FIXME: we need ASTContext to be passed in!
 VD->getASTContext();
-if (auto ConstVal = Node->getIdx()->getIntegerConstantExpr(Ctx)) {
-  if (ConstVal->isNegative())
-return std::nullopt;
-} else if (!Node->getIdx()->getType()->isUnsignedIntegerType())
+if (!isNonNegativeIntegerExpr(Node->getIdx(), VD, Ctx))

haoNoQ wrote:

I'm starting to like how these checks live in `getFixits()`, as opposed to the 
matcher. It's not like we'll ever be able to fix the signed case, but this way 
they'll show up in debug statistics as "gadget refused to produce a fix", which 
is better than the generic "it never matched". We could even make a dedicated 
debug message for this failure specifically!

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


[clang] [-Wunsafe-buffer-usage] Add FixableGadget for AddAssign in UnspecifiedUntypedContext (PR #71862)

2023-11-14 Thread Artem Dergachev via cfe-commits

https://github.com/haoNoQ commented:

Yay I like this!

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


[clang] [-Wunsafe-buffer-usage] Add FixableGadget for AddAssign in UnspecifiedUntypedContext (PR #71862)

2023-11-14 Thread Artem Dergachev via cfe-commits


@@ -1766,6 +1815,52 @@ fixUPCAddressofArraySubscriptWithSpan(const 
UnaryOperator *Node) {
   FixItHint::CreateReplacement(Node->getSourceRange(), SS.str())};
 }
 
+std::optional
+UUCAddAssignGadget::getFixits(const Strategy &S) const {
+  DeclUseList DREs = getClaimedVarUseSites();
+
+  if (DREs.size() != 1)
+return std::nullopt; // In cases of `Ptr += n` where `Ptr` is not a DRE, we
+ // give up
+  if (const VarDecl *VD = dyn_cast(DREs.front()->getDecl())) {
+if (S.lookup(VD) == Strategy::Kind::Span) {
+  FixItList Fixes;
+  std::stringstream SS;
+  const Stmt *AddAssignNode = getBaseStmt();
+  StringRef varName = VD->getName();
+  const ASTContext &Ctx = VD->getASTContext();
+
+  if (!isNonNegativeIntegerExpr(Offset, VD, Ctx))
+return std::nullopt;
+
+  std::string SubSpanOffset;
+  const SourceManager &SM = Ctx.getSourceManager();
+  const LangOptions &LangOpts = Ctx.getLangOpts();
+  std::optional ExtentString = getExprText(Offset, SM, 
LangOpts);
+  
+  if (ExtentString)
+SubSpanOffset = ExtentString->str();
+  else
+SubSpanOffset = 
+getUserFillPlaceHolder(); // FIXME: When does this happen?

haoNoQ wrote:

Would it make any sense to simply preserve the extent expression as-is, without 
trying to stash the text? Just fix the code _around_ it instead?

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


[clang] [-Wunsafe-buffer-usage] Add FixableGadget for AddAssign in UnspecifiedUntypedContext (PR #71862)

2023-11-14 Thread Artem Dergachev via cfe-commits


@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
+// RUN:-fsafe-buffer-usage-suggestions \
+// RUN:-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+void foo(int * , int *);
+
+void add_assign_test(unsigned int n, int *a, int y) {
+  int *p = new int[10];
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+  p += 2;
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"p = p.subspan(2)"

haoNoQ wrote:

I suspect it needs to be like `p.subspan(0, 2)`. The first argument is offset, 
the second argument is count. (I wrote it weirdly on the wideboard many times 
because I never memorized any of this.)

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


[clang] [-Wunsafe-buffer-usage] Add FixableGadget for AddAssign in UnspecifiedUntypedContext (PR #71862)

2023-11-14 Thread Artem Dergachev via cfe-commits

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


[clang] [MS-ABI] create unique vftable name for vftable defined with internal alias. (PR #71748)

2023-11-14 Thread via cfe-commits

jyu2-git wrote:

Thanks @efriedma-quic and @rnk, both ideas should fix our problem.

I am choosing @efriedma-quic's idea, since this has less impact for
compile.

I also tried @rnk's idea, I don't fell comfort by adding
getAnonymousNamespaceHash’s string
for all lambda name mangling.

Thanks all!


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


[clang] [MS-ABI] create unique vftable name for vftable defined with internal alias. (PR #71748)

2023-11-14 Thread via cfe-commits

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


[clang] [MS-ABI] create unique vftable name for vftable defined with internal alias. (PR #71748)

2023-11-14 Thread via cfe-commits

https://github.com/jyu2-git updated 
https://github.com/llvm/llvm-project/pull/71748

>From 3313aca0622da3882a9e5bf304b89f28fecce7fe Mon Sep 17 00:00:00 2001
From: Jennifer Yu 
Date: Mon, 6 Nov 2023 20:51:39 -0800
Subject: [PATCH 1/3] [SEH] Fix assertin when return scalar value from __try
 block.

Current compler assert with `!SI->isAtomic() && !SI->isVolatile()' failed

This due to following rule:
First, no exception can move in or out of _try region., i.e., no "potential
faulty instruction can be moved across _try boundary.
Second, the order of exceptions for instructions 'directly' under a _try
must be preserved (not applied to those in callees).
Finally, global states (local/global/heap variables) that can be read
outside of _try region must be updated in memory (not just in register)
before the subsequent exception occurs.

All memory instructions inside a _try are considered as 'volatile' to assure
2nd and 3rd rules for C-code above. This is a little sub-optimized. But it's
acceptable as the amount of code directly under _try is very small.
However during findDominatingStoreToReturnValue: those are not allowed.

To fix just skip the assertion when current function has seh try.
---
 clang/lib/CodeGen/CGCall.cpp  |  3 +++
 .../CodeGen/windows-seh-EHa-TryInFinally.cpp  | 23 +++
 2 files changed, 26 insertions(+)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index e7951b3a3f4d855..bc367b89992bbd9 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3507,6 +3507,9 @@ static llvm::StoreInst 
*findDominatingStoreToReturnValue(CodeGenFunction &CGF) {
   return nullptr;
 // These aren't actually possible for non-coerced returns, and we
 // only care about non-coerced returns on this code path.
+// All memory instructions inside __try block are volatile.
+if (CGF.currentFunctionUsesSEHTry() && SI->isVolatile())
+  return SI;
 assert(!SI->isAtomic() && !SI->isVolatile());
 return SI;
   };
diff --git a/clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp 
b/clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
index fab567e763df443..ce2a9528e1908a9 100644
--- a/clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
+++ b/clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
@@ -67,3 +67,26 @@ void foo()
 }
   }
 }
+
+// CHECK-LABEL:@"?bar@@YAHXZ"()
+// CHECK: invoke.cont:
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK: invoke.cont1:
+// CHECK: store volatile i32 1, ptr %cleanup.dest.slot
+// CHECK: invoke void @llvm.seh.try.end()
+// CHECK: invoke.cont2:
+// CHECK: call void @"?fin$0@0@bar@@"
+// CHECK: %cleanup.dest3 = load i32, ptr %cleanup.dest.slot
+// CHECK: return:
+// CHECK: ret i32 11
+int bar()
+{
+  int x;
+  __try {
+return 11;
+  } __finally {
+if (_abnormal_termination()) {
+  x = 9;
+}
+  }
+}

>From 52981cb76b510593c7b20bafc0d65a756b1ccd32 Mon Sep 17 00:00:00 2001
From: Jennifer Yu 
Date: Tue, 7 Nov 2023 10:05:41 -0800
Subject: [PATCH 2/3] [MSABI] create unique vftable name for vftable defined
 with internal alias.

We got a error:
LLVM ERROR: Associative COMDAT symbol '??_7?$T@V6B@' is not a key 
for its COMDAT

Current we create internal alias for vftable when lambd is used.
For the test, IR generate:

$"??_7?$T@V@@$0A@@@6b@" = comdat any

@0 = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr 
@"??_R4?$T@V@@$0A@@@6b@", ptr @"?c@b@@UEAAXXZ"] }, 
comdat($"??_7?$T@V@@$0A@@@6b@")

@"??_7?$T@V@@$0A@@@6b@" = internal unnamed_addr alias ptr, 
getelementptr inbounds ({ [2 x ptr] }, ptr @0, i32 0, i32 0, i32 1)

According LLVM language reference manual section on COMDATs:
There are some restrictions on the properties of the global object. It,
or an alias to it, must have the same name as the COMDAT group when
targeting COFF. The contents and size of this object may be used during
link-time to determine which COMDAT groups get selected depending on the
selection kind. Because the name of the object must match the name of the
COMDAT group, the linkage of the global object must not be local; local
symbols can get renamed if a collision occurs in the symbol table.

So one way to fix this is to generate unqiue virtual function table name,
to aviod local symbol renaming.

My fix is to generate unqiue vftable name for every TU where encoded file
name in addition.

after the change:

before:

---
 clang/include/clang/AST/Mangle.h  |  3 +-
 clang/lib/AST/MicrosoftMangle.cpp | 16 --
 clang/lib/CodeGen/MicrosoftCXXABI.cpp | 15 ++---
 .../CodeGenCXX/ms-local-vft-alias-comdat.cpp  | 31 +++
 4 files changed, 57 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/ms-local-vft-alias-comdat.cpp

diff --git a/clang/include/clang/AST/Mangle.h b/clang/include/clang/AST/Mangle.h
index e586b0cec43dfd6..420ba52f255eb2c 100644
--- a/clang/include/clang/AST/Mangle.h
+++ b/clang/include/clang/AST

[llvm] [clang] [clang-tools-extra] [InstCombine] Convert or concat to fshl if opposite or concat exists (PR #68502)

2023-11-14 Thread via cfe-commits

https://github.com/HaohaiWen updated 
https://github.com/llvm/llvm-project/pull/68502

>From 5b3b1bbb5b263bc5711adde031d85b1461ccbab6 Mon Sep 17 00:00:00 2001
From: Haohai Wen 
Date: Sat, 7 Oct 2023 13:48:32 +0800
Subject: [PATCH 1/5] [InstCombine] Refactor matchFunnelShift to allow more
 pattern (NFC)

Current implementation of matchFunnelShift only allows opposite shift
pattern. Refactor it to allow more pattern.
---
 .../InstCombine/InstCombineAndOrXor.cpp   | 172 ++
 1 file changed, 93 insertions(+), 79 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index cbdab3e9c5fb91d..b04e070fd19d7d1 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2732,100 +2732,114 @@ static Instruction *matchFunnelShift(Instruction &Or, 
InstCombinerImpl &IC) {
   // rotate matching code under visitSelect and visitTrunc?
   unsigned Width = Or.getType()->getScalarSizeInBits();
 
-  // First, find an or'd pair of opposite shifts:
-  // or (lshr ShVal0, ShAmt0), (shl ShVal1, ShAmt1)
-  BinaryOperator *Or0, *Or1;
-  if (!match(Or.getOperand(0), m_BinOp(Or0)) ||
-  !match(Or.getOperand(1), m_BinOp(Or1)))
-return nullptr;
-
-  Value *ShVal0, *ShVal1, *ShAmt0, *ShAmt1;
-  if (!match(Or0, m_OneUse(m_LogicalShift(m_Value(ShVal0), m_Value(ShAmt0 
||
-  !match(Or1, m_OneUse(m_LogicalShift(m_Value(ShVal1), m_Value(ShAmt1 
||
-  Or0->getOpcode() == Or1->getOpcode())
+  Instruction *Or0, *Or1;
+  if (!match(Or.getOperand(0), m_Instruction(Or0)) ||
+  !match(Or.getOperand(1), m_Instruction(Or1)))
 return nullptr;
 
-  // Canonicalize to or(shl(ShVal0, ShAmt0), lshr(ShVal1, ShAmt1)).
-  if (Or0->getOpcode() == BinaryOperator::LShr) {
-std::swap(Or0, Or1);
-std::swap(ShVal0, ShVal1);
-std::swap(ShAmt0, ShAmt1);
-  }
-  assert(Or0->getOpcode() == BinaryOperator::Shl &&
- Or1->getOpcode() == BinaryOperator::LShr &&
- "Illegal or(shift,shift) pair");
-
-  // Match the shift amount operands for a funnel shift pattern. This always
-  // matches a subtraction on the R operand.
-  auto matchShiftAmount = [&](Value *L, Value *R, unsigned Width) -> Value * {
-// Check for constant shift amounts that sum to the bitwidth.
-const APInt *LI, *RI;
-if (match(L, m_APIntAllowUndef(LI)) && match(R, m_APIntAllowUndef(RI)))
-  if (LI->ult(Width) && RI->ult(Width) && (*LI + *RI) == Width)
-return ConstantInt::get(L->getType(), *LI);
-
-Constant *LC, *RC;
-if (match(L, m_Constant(LC)) && match(R, m_Constant(RC)) &&
-match(L, m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, APInt(Width, Width))) 
&&
-match(R, m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, APInt(Width, Width))) 
&&
-match(ConstantExpr::getAdd(LC, RC), m_SpecificIntAllowUndef(Width)))
-  return ConstantExpr::mergeUndefsWith(LC, RC);
-
-// (shl ShVal, X) | (lshr ShVal, (Width - x)) iff X < Width.
-// We limit this to X < Width in case the backend re-expands the intrinsic,
-// and has to reintroduce a shift modulo operation (InstCombine might 
remove
-// it after this fold). This still doesn't guarantee that the final codegen
-// will match this original pattern.
-if (match(R, m_OneUse(m_Sub(m_SpecificInt(Width), m_Specific(L) {
-  KnownBits KnownL = IC.computeKnownBits(L, /*Depth*/ 0, &Or);
-  return KnownL.getMaxValue().ult(Width) ? L : nullptr;
-}
+  bool IsFshl = true; // Sub on LSHR.
+  SmallVector FShiftArgs;
 
-// For non-constant cases, the following patterns currently only work for
-// rotation patterns.
-// TODO: Add general funnel-shift compatible patterns.
-if (ShVal0 != ShVal1)
+  // First, find an or'd pair of opposite shifts:
+  // or (lshr ShVal0, ShAmt0), (shl ShVal1, ShAmt1)
+  if (isa(Or0) && isa(Or1)) {
+Value *ShVal0, *ShVal1, *ShAmt0, *ShAmt1;
+if (!match(Or0,
+   m_OneUse(m_LogicalShift(m_Value(ShVal0), m_Value(ShAmt0 ||
+!match(Or1,
+   m_OneUse(m_LogicalShift(m_Value(ShVal1), m_Value(ShAmt1 ||
+Or0->getOpcode() == Or1->getOpcode())
   return nullptr;
 
-// For non-constant cases we don't support non-pow2 shift masks.
-// TODO: Is it worth matching urem as well?
-if (!isPowerOf2_32(Width))
-  return nullptr;
+// Canonicalize to or(shl(ShVal0, ShAmt0), lshr(ShVal1, ShAmt1)).
+if (Or0->getOpcode() == BinaryOperator::LShr) {
+  std::swap(Or0, Or1);
+  std::swap(ShVal0, ShVal1);
+  std::swap(ShAmt0, ShAmt1);
+}
+assert(Or0->getOpcode() == BinaryOperator::Shl &&
+   Or1->getOpcode() == BinaryOperator::LShr &&
+   "Illegal or(shift,shift) pair");
+
+// Match the shift amount operands for a funnel shift pattern. This always
+// matches a subtraction on the R operand.
+auto matchShiftAmount = [&](Value *L

[compiler-rt] [flang] [clang] [clang-tools-extra] [llvm] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-14 Thread via cfe-commits

https://github.com/smanna12 updated 
https://github.com/llvm/llvm-project/pull/70762

>From 93d46d40f46663cfa30fc01da965887508684e25 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Mon, 30 Oct 2023 21:41:00 -0700
Subject: [PATCH 01/20] [clang] Add support for new loop attribute
 [[clang::code_align()]]

---
 clang/include/clang/Basic/Attr.td |   9 ++
 clang/include/clang/Basic/AttrDocs.td |  43 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/CodeGen/CGLoopInfo.cpp  |  29 +++-
 clang/lib/CodeGen/CGLoopInfo.h|   6 +
 clang/lib/Sema/SemaStmtAttr.cpp   |  53 
 clang/lib/Sema/SemaTemplateInstantiate.cpp|   8 +-
 clang/test/CodeGen/code_align.c   |  61 +
 clang/test/Sema/code_align.c  | 124 ++
 clang/test/Sema/code_align_ast.c  |  91 +
 11 files changed, 426 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CodeGen/code_align.c
 create mode 100644 clang/test/Sema/code_align.c
 create mode 100644 clang/test/Sema/code_align_ast.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 25231c5b82b907c..e25bea67bf9e86e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4280,3 +4280,12 @@ def PreferredType: InheritableAttr {
   let Args = [TypeArgument<"Type", 1>];
   let Documentation = [PreferredTypeDocumentation];
 }
+
+def CodeAlign: StmtAttr {
+  let Spellings = [CXX11<"clang", "code_align">,
+   C23<"clang", "code_align">];
+  let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
+  ErrorDiag, "'for', 'while', and 'do' 
statements">;
+  let Args = [ExprArgument<"NExpr">];
+  let Documentation = [CodeAlignAttrDocs];
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 05703df2129f612..5ee224e117d049c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7416,3 +7416,46 @@ that ``p->array`` must have at least ``p->count`` number 
of elements available:
 
   }];
 }
+
+def CodeAlignAttrDocs : Documentation {
+  let Category = DocCatVariable;
+  let Heading = "clang::code_align";
+  let Content = [{
+The ``clang::code_align(N)`` attribute applies to a loop and it specifies the
+byte alignment for a loop. The attribute accepts a positive integer constant
+initialization expression indicating the number of bytes for the minimum
+alignment boundary. Its value must be a power of 2, between 1 and 4096, such as
+1, 2, 4, 8, and so on. This attribute sets ``llvm.loop.align`` loop metadata
+when it applies on a loop statement.
+
+.. code-block:: c++
+
+  void foo() {
+int var = 0;
+[[clang::code_align(16)]] for (int i = 0; i < 10; ++i) var++;
+  }
+
+  void Array(int *array, size_t n) {
+[[clang::code_align(64)]] for (int i = 0; i < n; ++i) array[i] = 0;
+  }
+
+  void count () {
+  int a1[10], int i = 0;
+  [[clang::code_align(32)]] while (i < 10) {
+a1[i] += 3;
+  }
+
+  void check() {
+int a = 10;
+[[clang::code_align(8)]] do {
+  a = a + 1;
+} while (a < 20);
+  }
+
+  template
+  void func() {
+[[clang::code_align(A)]] for(;;) { }
+  }
+
+  }];
+}
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 224c0df7f1fb71f..4b0f24d25e3e902 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10026,6 +10026,10 @@ def err_duplicate_case_differing_expr : Error<
 def warn_case_empty_range : Warning<"empty case range specified">;
 def warn_missing_case_for_condition :
   Warning<"no case matching constant switch condition '%0'">;
+def err_loop_attr_duplication : Error<
+  "duplicate loop attribute %0">;
+def err_attribute_argument_not_power_of_two : Error<
+  "%0 attribute argument must be a constant power of two greater than zero">;
 
 def warn_def_missing_case : Warning<"%plural{"
   "1:enumeration value %1 not explicitly handled in switch|"
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1e9752345ffd173..376335e9bbe70ca 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2096,6 +2096,8 @@ class Sema final {
   QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace,
  SourceLocation AttrLoc);
 
+  CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E);
+
   bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc);
 
   bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index e5d9db273c2d336..a7cae301ba7bfda 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/li

[clang] [Driver][BoundsSafety] Add -fexperimental-bounds-safety flag (PR #70480)

2023-11-14 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> > In addition, I think our convention is to add the option when the feature 
> > is ready, rather than add a no-op option, than build functional patches on 
> > top of it.
> 
> @MaskRay This feature will involve a lot of incremental patches. And we will 
> still need an experimental flag to test the incremental functionalities that 
> we will be adding. I can make it a CC1 only flag for now. Would it work for 
> you better?

Yes. This sound good to me.

You will need to remove the lib/Driver change and the language compatibility 
check, then.

I think the patch should still be held off until the first patch that does some 
basic functionality is ready.

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


[flang] [clang-tools-extra] [clang] [compiler-rt] [llvm] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-14 Thread via cfe-commits

https://github.com/smanna12 updated 
https://github.com/llvm/llvm-project/pull/70762

>From 93d46d40f46663cfa30fc01da965887508684e25 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Mon, 30 Oct 2023 21:41:00 -0700
Subject: [PATCH 01/19] [clang] Add support for new loop attribute
 [[clang::code_align()]]

---
 clang/include/clang/Basic/Attr.td |   9 ++
 clang/include/clang/Basic/AttrDocs.td |  43 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/CodeGen/CGLoopInfo.cpp  |  29 +++-
 clang/lib/CodeGen/CGLoopInfo.h|   6 +
 clang/lib/Sema/SemaStmtAttr.cpp   |  53 
 clang/lib/Sema/SemaTemplateInstantiate.cpp|   8 +-
 clang/test/CodeGen/code_align.c   |  61 +
 clang/test/Sema/code_align.c  | 124 ++
 clang/test/Sema/code_align_ast.c  |  91 +
 11 files changed, 426 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CodeGen/code_align.c
 create mode 100644 clang/test/Sema/code_align.c
 create mode 100644 clang/test/Sema/code_align_ast.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 25231c5b82b907c..e25bea67bf9e86e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4280,3 +4280,12 @@ def PreferredType: InheritableAttr {
   let Args = [TypeArgument<"Type", 1>];
   let Documentation = [PreferredTypeDocumentation];
 }
+
+def CodeAlign: StmtAttr {
+  let Spellings = [CXX11<"clang", "code_align">,
+   C23<"clang", "code_align">];
+  let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
+  ErrorDiag, "'for', 'while', and 'do' 
statements">;
+  let Args = [ExprArgument<"NExpr">];
+  let Documentation = [CodeAlignAttrDocs];
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 05703df2129f612..5ee224e117d049c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7416,3 +7416,46 @@ that ``p->array`` must have at least ``p->count`` number 
of elements available:
 
   }];
 }
+
+def CodeAlignAttrDocs : Documentation {
+  let Category = DocCatVariable;
+  let Heading = "clang::code_align";
+  let Content = [{
+The ``clang::code_align(N)`` attribute applies to a loop and it specifies the
+byte alignment for a loop. The attribute accepts a positive integer constant
+initialization expression indicating the number of bytes for the minimum
+alignment boundary. Its value must be a power of 2, between 1 and 4096, such as
+1, 2, 4, 8, and so on. This attribute sets ``llvm.loop.align`` loop metadata
+when it applies on a loop statement.
+
+.. code-block:: c++
+
+  void foo() {
+int var = 0;
+[[clang::code_align(16)]] for (int i = 0; i < 10; ++i) var++;
+  }
+
+  void Array(int *array, size_t n) {
+[[clang::code_align(64)]] for (int i = 0; i < n; ++i) array[i] = 0;
+  }
+
+  void count () {
+  int a1[10], int i = 0;
+  [[clang::code_align(32)]] while (i < 10) {
+a1[i] += 3;
+  }
+
+  void check() {
+int a = 10;
+[[clang::code_align(8)]] do {
+  a = a + 1;
+} while (a < 20);
+  }
+
+  template
+  void func() {
+[[clang::code_align(A)]] for(;;) { }
+  }
+
+  }];
+}
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 224c0df7f1fb71f..4b0f24d25e3e902 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10026,6 +10026,10 @@ def err_duplicate_case_differing_expr : Error<
 def warn_case_empty_range : Warning<"empty case range specified">;
 def warn_missing_case_for_condition :
   Warning<"no case matching constant switch condition '%0'">;
+def err_loop_attr_duplication : Error<
+  "duplicate loop attribute %0">;
+def err_attribute_argument_not_power_of_two : Error<
+  "%0 attribute argument must be a constant power of two greater than zero">;
 
 def warn_def_missing_case : Warning<"%plural{"
   "1:enumeration value %1 not explicitly handled in switch|"
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1e9752345ffd173..376335e9bbe70ca 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2096,6 +2096,8 @@ class Sema final {
   QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace,
  SourceLocation AttrLoc);
 
+  CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E);
+
   bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc);
 
   bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index e5d9db273c2d336..a7cae301ba7bfda 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/li

[clang] [clang] Make `-fvisibility={}` and `-ftype-visibility={}` benign options. (PR #71985)

2023-11-14 Thread Chuanqi Xu via cfe-commits

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

LGTM. Thanks.

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


[libcxx] [flang] [clang-tools-extra] [libc] [clang] [compiler-rt] [llvm] [libc++] Implement ranges::iota (PR #68494)

2023-11-14 Thread James E T Smith via cfe-commits

https://github.com/jamesETsmith updated 
https://github.com/llvm/llvm-project/pull/68494

>From c4a3ccfbad090ad8314aa8ad53092edc8d5432bc Mon Sep 17 00:00:00 2001
From: James Smith 
Date: Thu, 28 Sep 2023 10:11:15 -0400
Subject: [PATCH 01/17] [libc++] Implement ranges::iota and
 ranges::out_value_result

---
 libcxx/include/CMakeLists.txt |   2 +
 libcxx/include/__algorithm/out_value_result.h |  52 +
 libcxx/include/__numeric/ranges_iota.h|  53 +
 libcxx/include/algorithm  |   4 +
 libcxx/include/numeric|   1 +
 libcxx/include/version|   2 +-
 .../out_value_result.pass.cpp | 102 ++
 .../numeric.iota/ranges.iota.pass.cpp |  52 +
 8 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__algorithm/out_value_result.h
 create mode 100644 libcxx/include/__numeric/ranges_iota.h
 create mode 100644 
libcxx/test/std/algorithms/algorithms.results/out_value_result.pass.cpp
 create mode 100644 
libcxx/test/std/numerics/numeric.ops/numeric.iota/ranges.iota.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..c6eb03f1d68e984 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -63,6 +63,7 @@ set(files
   __algorithm/next_permutation.h
   __algorithm/none_of.h
   __algorithm/nth_element.h
+  __algorithm/out_value_result.h
   __algorithm/partial_sort.h
   __algorithm/partial_sort_copy.h
   __algorithm/partition.h
@@ -561,6 +562,7 @@ set(files
   __numeric/partial_sum.h
   __numeric/pstl_reduce.h
   __numeric/pstl_transform_reduce.h
+  __numeric/ranges_iota.h
   __numeric/reduce.h
   __numeric/transform_exclusive_scan.h
   __numeric/transform_inclusive_scan.h
diff --git a/libcxx/include/__algorithm/out_value_result.h 
b/libcxx/include/__algorithm/out_value_result.h
new file mode 100644
index 000..8baffec7b9ef4da
--- /dev/null
+++ b/libcxx/include/__algorithm/out_value_result.h
@@ -0,0 +1,52 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+template 
+struct out_value_result {
+  _LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out;
+  _LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value;
+
+  template 
+requires convertible_to && 
convertible_to
+  constexpr operator out_value_result<_OutIter2, _ValType2>() const& { return 
{out, value}; }
+
+  template 
+requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, 
_ValType2>
+  constexpr operator out_value_result<_OutIter2, _ValType2>() && { return 
{std::move(out), std::move(value)}; }
+};
+
+} // namespace ranges
+
+#endif // _LIBCPP_STD_VER >= 23
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H
diff --git a/libcxx/include/__numeric/ranges_iota.h 
b/libcxx/include/__numeric/ranges_iota.h
new file mode 100644
index 000..20311a68c2a348c
--- /dev/null
+++ b/libcxx/include/__numeric/ranges_iota.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = static_cast(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), std::move(__valu

[flang] [clang-tools-extra] [clang] [compiler-rt] [llvm] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-14 Thread via cfe-commits


@@ -0,0 +1,126 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c-local -x c %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cpp-local -pedantic -x c++ 
-std=c++11 %s
+
+void foo() {
+  int i;
+  int a[10], b[10];
+
+  [[clang::code_align(8)]]
+  for (i = 0; i < 10; ++i) {  // this is OK
+a[i] = b[i] = 0;
+  }
+  // expected-error@+1{{'code_align' attribute only applies to 'for', 'while', 
and 'do' statements}}
+  [[clang::code_align(4)]]
+  i = 7;
+  for (i = 0; i < 10; ++i) {
+a[i] = b[i] = 0;
+  }
+
+  // expected-error@+1{{'code_align' attribute cannot be applied to a 
declaration}}
+  [[clang::code_align(12)]] int n[10];
+}
+
+void bar(int);
+// cpp-local-note@+1{{declared here}}
+void foo1(int A)
+{
+  // expected-error@+1{{'code_align' attribute requires an integer argument 
which is a constant power of two between 1 and 4096 inclusive; provided 
argument was 0}}
+  [[clang::code_align(0)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // expected-error@+1{{'code_align' attribute requires an integer argument 
which is a constant power of two between 1 and 4096 inclusive; provided 
argument was -4}}
+  [[clang::code_align(-4)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+// cpp-local-error@+2{{integral constant expression must have integral or 
unscoped enumeration type, not 'double'}}
+// c-local-error@+1{{integer constant expression must have integer type, 
not 'double'}}
+  [[clang::code_align(64.0)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // expected-error@+1{{'code_align' attribute takes one argument}}
+  [[clang::code_align()]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // expected-error@+1{{'code_align' attribute takes one argument}}
+  [[clang::code_align(4,8)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // no diagnostic is expected
+  [[clang::code_align(32)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // cpp-local-error@+2{{integral constant expression must have integral or 
unscoped enumeration type, not 'const char[4]'}}
+  // c-local-error@+1{{integer constant expression must have integer type, not 
'char[4]'}}
+  [[clang::code_align("abc")]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  [[clang::code_align(64)]] // expected-note{{previous attribute is here}}
+  [[clang::code_align(64)]] // expected-error{{duplicate loop attribute 
'code_align'}}
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // expected-error@+1{{'code_align' attribute requires an integer argument 
which is a constant power of two between 1 and 4096 inclusive; provided 
argument was 7}}
+  [[clang::code_align(7)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // expected-error@+1{{'code_align' attribute requires an integer argument 
which is a constant power of two between 1 and 4096 inclusive; provided 
argument was 5000}}
+  [[clang::code_align(5000)]]
+  for(int I=0; I<128; ++I) { bar(I); }
+
+  // expected-warning@+2 {{integer literal is too large to be represented in a 
signed integer type, interpreting as unsigned}}
+  // expected-error@+1 {{'code_align' attribute requires an integer argument 
which is a constant power of two between 1 and 4096 inclusive; provided 
argument was 9223372036854775808}}
+  [[clang::code_align(9223372036854775808)]]
+  for(int I=0; I<256; ++I) { bar(I); }
+
+  // expected-error@+1 {{'code_align' attribute requires an integer argument 
which is a constant power of two between 1 and 4096 inclusive; provided 
argument was 0}}

smanna12 wrote:

@erichkeane, i have fixed the issue with commit 
https://github.com/llvm/llvm-project/pull/70762/commits/8bec3c455b5f55b40a8a3d8c9180c0e3d52765fa

Now This is returning a better value:
'code_align' attribute requires an integer argument which is a constant power 
of two between 1 and 4096 inclusive; provided argument was 2147483647
This represents the value of the provided argument truncated to an int (instead 
of a 128bit float).

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


[flang] [clang-tools-extra] [clang] [compiler-rt] [llvm] [clang] Add support for new loop attribute [[clang::code_align()]] (PR #70762)

2023-11-14 Thread via cfe-commits

https://github.com/smanna12 updated 
https://github.com/llvm/llvm-project/pull/70762

>From 93d46d40f46663cfa30fc01da965887508684e25 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Mon, 30 Oct 2023 21:41:00 -0700
Subject: [PATCH 01/18] [clang] Add support for new loop attribute
 [[clang::code_align()]]

---
 clang/include/clang/Basic/Attr.td |   9 ++
 clang/include/clang/Basic/AttrDocs.td |  43 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/CodeGen/CGLoopInfo.cpp  |  29 +++-
 clang/lib/CodeGen/CGLoopInfo.h|   6 +
 clang/lib/Sema/SemaStmtAttr.cpp   |  53 
 clang/lib/Sema/SemaTemplateInstantiate.cpp|   8 +-
 clang/test/CodeGen/code_align.c   |  61 +
 clang/test/Sema/code_align.c  | 124 ++
 clang/test/Sema/code_align_ast.c  |  91 +
 11 files changed, 426 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CodeGen/code_align.c
 create mode 100644 clang/test/Sema/code_align.c
 create mode 100644 clang/test/Sema/code_align_ast.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 25231c5b82b907c..e25bea67bf9e86e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4280,3 +4280,12 @@ def PreferredType: InheritableAttr {
   let Args = [TypeArgument<"Type", 1>];
   let Documentation = [PreferredTypeDocumentation];
 }
+
+def CodeAlign: StmtAttr {
+  let Spellings = [CXX11<"clang", "code_align">,
+   C23<"clang", "code_align">];
+  let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
+  ErrorDiag, "'for', 'while', and 'do' 
statements">;
+  let Args = [ExprArgument<"NExpr">];
+  let Documentation = [CodeAlignAttrDocs];
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 05703df2129f612..5ee224e117d049c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7416,3 +7416,46 @@ that ``p->array`` must have at least ``p->count`` number 
of elements available:
 
   }];
 }
+
+def CodeAlignAttrDocs : Documentation {
+  let Category = DocCatVariable;
+  let Heading = "clang::code_align";
+  let Content = [{
+The ``clang::code_align(N)`` attribute applies to a loop and it specifies the
+byte alignment for a loop. The attribute accepts a positive integer constant
+initialization expression indicating the number of bytes for the minimum
+alignment boundary. Its value must be a power of 2, between 1 and 4096, such as
+1, 2, 4, 8, and so on. This attribute sets ``llvm.loop.align`` loop metadata
+when it applies on a loop statement.
+
+.. code-block:: c++
+
+  void foo() {
+int var = 0;
+[[clang::code_align(16)]] for (int i = 0; i < 10; ++i) var++;
+  }
+
+  void Array(int *array, size_t n) {
+[[clang::code_align(64)]] for (int i = 0; i < n; ++i) array[i] = 0;
+  }
+
+  void count () {
+  int a1[10], int i = 0;
+  [[clang::code_align(32)]] while (i < 10) {
+a1[i] += 3;
+  }
+
+  void check() {
+int a = 10;
+[[clang::code_align(8)]] do {
+  a = a + 1;
+} while (a < 20);
+  }
+
+  template
+  void func() {
+[[clang::code_align(A)]] for(;;) { }
+  }
+
+  }];
+}
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 224c0df7f1fb71f..4b0f24d25e3e902 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10026,6 +10026,10 @@ def err_duplicate_case_differing_expr : Error<
 def warn_case_empty_range : Warning<"empty case range specified">;
 def warn_missing_case_for_condition :
   Warning<"no case matching constant switch condition '%0'">;
+def err_loop_attr_duplication : Error<
+  "duplicate loop attribute %0">;
+def err_attribute_argument_not_power_of_two : Error<
+  "%0 attribute argument must be a constant power of two greater than zero">;
 
 def warn_def_missing_case : Warning<"%plural{"
   "1:enumeration value %1 not explicitly handled in switch|"
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1e9752345ffd173..376335e9bbe70ca 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2096,6 +2096,8 @@ class Sema final {
   QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace,
  SourceLocation AttrLoc);
 
+  CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E);
+
   bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc);
 
   bool CheckFunctionReturnType(QualType T, SourceLocation Loc);
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index e5d9db273c2d336..a7cae301ba7bfda 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/li

[clang] [llvm] Add RunTimeLang to Class and Enumeration DIBuilder functions (PR #72011)

2023-11-14 Thread Felipe de Azevedo Piovezan via cfe-commits


@@ -424,6 +424,7 @@ namespace llvm {
 /// \param OffsetInBits Member offset.
 /// \param FlagsFlags to encode member attribute, e.g. private
 /// \param Elements class members.
+/// \param RunTimeLang  Optional parameter, Objective-C runtime version.

felipepiovezan wrote:

Ah, that's fair then

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


[clang] [llvm] Add RunTimeLang to Class and Enumeration DIBuilder functions (PR #72011)

2023-11-14 Thread Felipe de Azevedo Piovezan via cfe-commits

felipepiovezan wrote:

> @felipepiovezan I don't this patch as it is has any changes that are 
> testable. I haven't added any code that will emit a RuntimeLang, only added 
> the option to do that so I can add those callers downstream. In retrospect I 
> should've marked it as NFC.

I see. I think this is yet another argument for flipping the argument order: if 
the new thing were the last argument, it would have been even more evident this 
is NFC :) 

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


[llvm] [clang] Add RunTimeLang to Class and Enumeration DIBuilder functions (PR #72011)

2023-11-14 Thread Augusto Noronha via cfe-commits

augusto2112 wrote:

@felipepiovezan I don't this patch as it is has any changes that are testable. 
I haven't added any code that will emit a RuntimeLang, only added the option to 
do that so I can add those callers downstream. In retrospect I should've marked 
it as NFC.

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


[compiler-rt] [clang-tools-extra] [llvm] [flang] [clang] [clang] Add `::_placement_new` expression for built-in global placement new (PR #72209)

2023-11-14 Thread via cfe-commits

https://github.com/MaxEW707 updated 
https://github.com/llvm/llvm-project/pull/72209

>From 75cf305fe732d00be910a6aa0afe79953c5b7186 Mon Sep 17 00:00:00 2001
From: MaxEW707 <82551778+maxew...@users.noreply.github.com>
Date: Sun, 12 Nov 2023 11:36:58 -0500
Subject: [PATCH 1/3] Implement `::_placement_new` expression for built-in
 global placement new without header includes, overload resolution or dealing
 with std libraries that declare the global placement new with attributes that
 cannot be redeclared.

---
 clang/include/clang/AST/ExprCXX.h | 23 +
 clang/include/clang/AST/Stmt.h|  4 ++
 .../clang/Basic/DiagnosticParseKinds.td   |  2 +
 clang/include/clang/Basic/TokenKinds.def  |  1 +
 clang/include/clang/Sema/Sema.h   |  4 +-
 clang/lib/AST/ASTImporter.cpp | 18 ---
 clang/lib/AST/ExprCXX.cpp | 34 +
 clang/lib/AST/ExprConstant.cpp|  7 ++-
 clang/lib/AST/JSONNodeDumper.cpp  |  1 +
 clang/lib/AST/StmtPrinter.cpp |  5 +-
 clang/lib/AST/StmtProfile.cpp |  1 +
 clang/lib/AST/TextNodeDumper.cpp  |  2 +
 clang/lib/CodeGen/CGExprCXX.cpp   |  8 ++--
 clang/lib/CodeGen/CodeGenModule.cpp   |  5 +-
 clang/lib/Interpreter/Interpreter.cpp |  4 +-
 clang/lib/Parse/ParseDecl.cpp |  6 ++-
 clang/lib/Parse/ParseExpr.cpp |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp  | 19 ++--
 clang/lib/Parse/ParseObjc.cpp |  1 +
 clang/lib/Parse/ParseTentative.cpp|  3 +-
 clang/lib/Sema/SemaExprCXX.cpp| 48 ++-
 clang/lib/Sema/TreeTransform.h|  6 +--
 clang/lib/Serialization/ASTReaderStmt.cpp |  2 +
 clang/lib/Serialization/ASTWriterStmt.cpp |  2 +
 .../Checkers/CheckPlacementNew.cpp|  2 +-
 .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp |  9 ++--
 clang/test/AST/ast-dump-expr.cpp  | 14 ++
 clang/test/CodeGenCXX/new.cpp | 44 -
 clang/test/SemaCXX/new-delete.cpp |  7 +++
 29 files changed, 234 insertions(+), 50 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 24278016431837b..d760af796aea28f 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2282,6 +2282,13 @@ class CXXNewExpr final
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
+  /// Build a c++ builtin placement new expression
+  CXXNewExpr(Expr *PlacementArg,
+ SourceRange TypeIdParens, std::optional ArraySize,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
+ QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
+ SourceRange DirectInitRange);
+
   /// Build an empty c++ new expression.
   CXXNewExpr(EmptyShell Empty, bool IsArray, unsigned NumPlacementArgs,
  bool IsParenTypeId);
@@ -2297,6 +2304,14 @@ class CXXNewExpr final
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
+  /// Create a c++ builtin placement new expression.
+  static CXXNewExpr *
+  CreatePlacementNew(const ASTContext &Ctx, Expr *PlacementArg,
+ SourceRange TypeIdParens, std::optional ArraySize,
+ CXXNewInitializationStyle InitializationStyle, Expr 
*Initializer,
+ QualType Ty, TypeSourceInfo *AllocatedTypeInfo, 
SourceRange Range,
+ SourceRange DirectInitRange);
+
   /// Create an empty c++ new expression.
   static CXXNewExpr *CreateEmpty(const ASTContext &Ctx, bool IsArray,
  bool HasInit, unsigned NumPlacementArgs,
@@ -2332,6 +2347,12 @@ class CXXNewExpr final
   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
   void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
 
+  bool isReservedPlacementNew() const {
+if (CXXNewExprBits.IsPlacementNewExpr)
+  return true;
+return OperatorNew->isReservedGlobalPlacementOperator();
+  }
+
   bool isArray() const { return CXXNewExprBits.IsArray; }
 
   /// This might return std::nullopt even if isArray() returns true,
@@ -2387,6 +2408,8 @@ class CXXNewExpr final
 
   bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; }
 
+  bool isPlacementNewExpr() const { return CXXNewExprBits.IsPlacementNewExpr; }
+
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
 switch (getInitializationStyle()) {
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index da7b37ce0e1211f..2dc3746aee4fd71 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -878,6 +878,10 @@ class alignas(void *) Stmt {
  

[llvm] [clang] Add RunTimeLang to Class and Enumeration DIBuilder functions (PR #72011)

2023-11-14 Thread Felipe de Azevedo Piovezan via cfe-commits

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


[clang] [llvm] Add RunTimeLang to Class and Enumeration DIBuilder functions (PR #72011)

2023-11-14 Thread Augusto Noronha via cfe-commits


@@ -424,6 +424,7 @@ namespace llvm {
 /// \param OffsetInBits Member offset.
 /// \param FlagsFlags to encode member attribute, e.g. private
 /// \param Elements class members.
+/// \param RunTimeLang  Optional parameter, Objective-C runtime version.

augusto2112 wrote:

> I think your entire patch would be a lot simpler if this were the last 
> parameter of the function, as you wouldn't need to change as many callsites 
> and have inline comments explaining the parameter. Did you have a motivation 
> in mind for placing the argument here?

I'm following the pattern on the ordering from the existing functions, for 
example:
```
DICompositeType *createStructType(
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang = 0,
DIType *VTableHolder = nullptr, StringRef UniqueIdentifier = "");

DICompositeType *createUnionType(DIScope *Scope, StringRef Name,
 DIFile *File, unsigned LineNumber,
 uint64_t SizeInBits, uint32_t AlignInBits,
 DINode::DIFlags Flags,
 DINodeArray Elements,
 unsigned RunTimeLang = 0,
 StringRef UniqueIdentifier = "");
```


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


[clang] [llvm] [compiler-rt] [NFC, sanitizer_symbolizer] Split Fuchsia and Markup. (PR #72305)

2023-11-14 Thread Andres Villegas via cfe-commits
=?utf-8?q?Andrés?= Villegas ,
=?utf-8?q?Andrés?= Villegas 
Message-ID:
In-Reply-To: 


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


[clang] 3dc098d - [NFC, sanitizer_symbolizer] Split Fuchsia and Markup. (#72305)

2023-11-14 Thread via cfe-commits

Author: Andres Villegas
Date: 2023-11-14T16:39:04-08:00
New Revision: 3dc098d39215228ca78e99c100ed31b87e5bbdd6

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

LOG: [NFC, sanitizer_symbolizer] Split Fuchsia and Markup. (#72305)

This PR separates parts of the symbolizer markup
implementation that are Fuchsia OS specific. This
is in preparation of enabling symbolizer markup
in other OSs.

Added: 
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup_constants.h
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report_fuchsia.cpp
compiler-rt/lib/sanitizer_common/sanitizer_unwind_fuchsia.cpp

Modified: 
clang/docs/tools/clang-formatted-files.txt
compiler-rt/lib/sanitizer_common/CMakeLists.txt
compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
compiler-rt/lib/xray/xray_utils.cpp
llvm/utils/gn/secondary/compiler-rt/lib/sanitizer_common/BUILD.gn

Removed: 
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_fuchsia.h



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index 48cd800bffd0046..18512b1a7bf6b58 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -1837,7 +1837,7 @@ compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
 compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h
 compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_fuchsia.h
 compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_win.cpp
-compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_fuchsia.h
+compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup_constants.h
 compiler-rt/lib/sanitizer_common/sanitizer_thread_safety.h
 compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.h
 compiler-rt/lib/sanitizer_common/sanitizer_type_traits.cpp

diff  --git a/compiler-rt/lib/sanitizer_common/CMakeLists.txt 
b/compiler-rt/lib/sanitizer_common/CMakeLists.txt
index ce6d4cf80919b25..61e832a30eb3767 100644
--- a/compiler-rt/lib/sanitizer_common/CMakeLists.txt
+++ b/compiler-rt/lib/sanitizer_common/CMakeLists.txt
@@ -90,8 +90,10 @@ set(SANITIZER_SYMBOLIZER_SOURCES
   sanitizer_symbolizer_markup.cpp
   sanitizer_symbolizer_posix_libcdep.cpp
   sanitizer_symbolizer_report.cpp
+  sanitizer_symbolizer_report_fuchsia.cpp
   sanitizer_symbolizer_win.cpp
   sanitizer_unwind_linux_libcdep.cpp
+  sanitizer_unwind_fuchsia.cpp
   sanitizer_unwind_win.cpp
   )
 
@@ -189,7 +191,7 @@ set(SANITIZER_IMPL_HEADERS
   sanitizer_stoptheworld.h
   sanitizer_suppressions.h
   sanitizer_symbolizer.h
-  sanitizer_symbolizer_fuchsia.h
+  sanitizer_symbolizer_markup_constants.h
   sanitizer_symbolizer_internal.h
   sanitizer_symbolizer_libbacktrace.h
   sanitizer_symbolizer_mac.h

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp
index 35c325359148ab7..73668a56218cf0f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_fuchsia.cpp
@@ -35,7 +35,7 @@
 #include "sanitizer_common.h"
 #include "sanitizer_interface_internal.h"
 #include "sanitizer_internal_defs.h"
-#include "sanitizer_symbolizer_fuchsia.h"
+#  include "sanitizer_symbolizer_markup_constants.h"
 
 using namespace __sanitizer;
 

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
index d1b0f46004efaff..6402cfd7c36e443 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp
@@ -12,18 +12,13 @@
 
//===--===//
 
 #include "sanitizer_platform.h"
-#if SANITIZER_SYMBOLIZER_MARKUP
-
-#if SANITIZER_FUCHSIA
-#include "sanitizer_symbolizer_fuchsia.h"
-#  endif
 
-#  include 
-#  include 
+#if SANITIZER_SYMBOLIZER_MARKUP
 
-#  include "sanitizer_stacktrace.h"
+#  include "sanitizer_common.h"
 #  include "sanitizer_stacktrace_printer.h"
 #  include "sanitizer_symbolizer.h"
+#  include "sanitizer_symbolizer_markup_constants.h"
 
 namespace __sanitizer {
 
@@ -110,49 +105,6 @@ Symbolizer *Symbolizer::PlatformInit() {
 
 void Symbolizer::LateInitialize() { Symbolizer::GetOrInit(); }
 
-void StartReportDeadlySignal() {}
-void ReportDeadlySignal(const SignalContext &sig, u32 tid,
-UnwindSignalStackCallbackType unwind,
-const void *unwind_context) {}
-
-#if SANITIZER_CAN_SLOW_UNWIND
-struct UnwindTraceArg {
-  BufferedStackTrace *stack;
-  u32 max_depth;
-};
-
-_Unwind_Reason_Code Unwind_

[clang] [llvm] Add RunTimeLang to Class and Enumeration DIBuilder functions (PR #72011)

2023-11-14 Thread Felipe de Azevedo Piovezan via cfe-commits

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


[clang] [llvm] Add RunTimeLang to Class and Enumeration DIBuilder functions (PR #72011)

2023-11-14 Thread Felipe de Azevedo Piovezan via cfe-commits


@@ -424,6 +424,7 @@ namespace llvm {
 /// \param OffsetInBits Member offset.
 /// \param FlagsFlags to encode member attribute, e.g. private
 /// \param Elements class members.
+/// \param RunTimeLang  Optional parameter, Objective-C runtime version.

felipepiovezan wrote:

let's use an `optional` type to denote an optional value

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


[clang] [llvm] Add RunTimeLang to Class and Enumeration DIBuilder functions (PR #72011)

2023-11-14 Thread Felipe de Azevedo Piovezan via cfe-commits


@@ -424,6 +424,7 @@ namespace llvm {
 /// \param OffsetInBits Member offset.
 /// \param FlagsFlags to encode member attribute, e.g. private
 /// \param Elements class members.
+/// \param RunTimeLang  Optional parameter, Objective-C runtime version.

felipepiovezan wrote:

I think your entire patch would be a lot simpler if this were the last 
parameter of the function, as you wouldn't need to change as many callsites and 
have inline comments explaining the parameter. Did you have a motivation in 
mind for placing the argument here?

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


[llvm] [clang] Add RunTimeLang to Class and Enumeration DIBuilder functions (PR #72011)

2023-11-14 Thread Felipe de Azevedo Piovezan via cfe-commits

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


[llvm] [clang] Add RunTimeLang to Class and Enumeration DIBuilder functions (PR #72011)

2023-11-14 Thread Felipe de Azevedo Piovezan via cfe-commits

https://github.com/felipepiovezan commented:

Let's add the `[DebugInfo][CGDebugInfo]` tags the commit message so that the 
git log  is more searchable.

I think we should have at least one test in this patch as well

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


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2023-11-14 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/72298

>From 333916a07e90955564d03f14e004695802d9f618 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Tue, 14 Nov 2023 17:27:37 +
Subject: [PATCH] [AVR] make the AVR ABI Swift compatible

This patch is needed to add support to clang's AVR ABI for the Swift
language. It is a pre-requisite for upstreaming AVR patches to the Swift
compiler itself.

@benshi001 @rjmccall
---
 clang/lib/CodeGen/Targets/AVR.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/AVR.cpp 
b/clang/lib/CodeGen/Targets/AVR.cpp
index 50547dd6dec5e7d..ae141d3f485139c 100644
--- a/clang/lib/CodeGen/Targets/AVR.cpp
+++ b/clang/lib/CodeGen/Targets/AVR.cpp
@@ -112,7 +112,10 @@ class AVRABIInfo : public DefaultABIInfo {
 class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   AVRTargetCodeGenInfo(CodeGenTypes &CGT, unsigned NPR, unsigned NRR)
-  : TargetCodeGenInfo(std::make_unique(CGT, NPR, NRR)) {}
+  : TargetCodeGenInfo(std::make_unique(CGT, NPR, NRR)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
+  }
 
   LangAS getGlobalVarAddressSpace(CodeGenModule &CGM,
   const VarDecl *D) const override {

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


[clang] [clang] Add `::_placement_new` expression for built-in global placement new (PR #72209)

2023-11-14 Thread via cfe-commits

https://github.com/MaxEW707 updated 
https://github.com/llvm/llvm-project/pull/72209

>From 75cf305fe732d00be910a6aa0afe79953c5b7186 Mon Sep 17 00:00:00 2001
From: MaxEW707 <82551778+maxew...@users.noreply.github.com>
Date: Sun, 12 Nov 2023 11:36:58 -0500
Subject: [PATCH 1/3] Implement `::_placement_new` expression for built-in
 global placement new without header includes, overload resolution or dealing
 with std libraries that declare the global placement new with attributes that
 cannot be redeclared.

---
 clang/include/clang/AST/ExprCXX.h | 23 +
 clang/include/clang/AST/Stmt.h|  4 ++
 .../clang/Basic/DiagnosticParseKinds.td   |  2 +
 clang/include/clang/Basic/TokenKinds.def  |  1 +
 clang/include/clang/Sema/Sema.h   |  4 +-
 clang/lib/AST/ASTImporter.cpp | 18 ---
 clang/lib/AST/ExprCXX.cpp | 34 +
 clang/lib/AST/ExprConstant.cpp|  7 ++-
 clang/lib/AST/JSONNodeDumper.cpp  |  1 +
 clang/lib/AST/StmtPrinter.cpp |  5 +-
 clang/lib/AST/StmtProfile.cpp |  1 +
 clang/lib/AST/TextNodeDumper.cpp  |  2 +
 clang/lib/CodeGen/CGExprCXX.cpp   |  8 ++--
 clang/lib/CodeGen/CodeGenModule.cpp   |  5 +-
 clang/lib/Interpreter/Interpreter.cpp |  4 +-
 clang/lib/Parse/ParseDecl.cpp |  6 ++-
 clang/lib/Parse/ParseExpr.cpp |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp  | 19 ++--
 clang/lib/Parse/ParseObjc.cpp |  1 +
 clang/lib/Parse/ParseTentative.cpp|  3 +-
 clang/lib/Sema/SemaExprCXX.cpp| 48 ++-
 clang/lib/Sema/TreeTransform.h|  6 +--
 clang/lib/Serialization/ASTReaderStmt.cpp |  2 +
 clang/lib/Serialization/ASTWriterStmt.cpp |  2 +
 .../Checkers/CheckPlacementNew.cpp|  2 +-
 .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp |  9 ++--
 clang/test/AST/ast-dump-expr.cpp  | 14 ++
 clang/test/CodeGenCXX/new.cpp | 44 -
 clang/test/SemaCXX/new-delete.cpp |  7 +++
 29 files changed, 234 insertions(+), 50 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 24278016431837b..d760af796aea28f 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2282,6 +2282,13 @@ class CXXNewExpr final
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
+  /// Build a c++ builtin placement new expression
+  CXXNewExpr(Expr *PlacementArg,
+ SourceRange TypeIdParens, std::optional ArraySize,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
+ QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
+ SourceRange DirectInitRange);
+
   /// Build an empty c++ new expression.
   CXXNewExpr(EmptyShell Empty, bool IsArray, unsigned NumPlacementArgs,
  bool IsParenTypeId);
@@ -2297,6 +2304,14 @@ class CXXNewExpr final
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
+  /// Create a c++ builtin placement new expression.
+  static CXXNewExpr *
+  CreatePlacementNew(const ASTContext &Ctx, Expr *PlacementArg,
+ SourceRange TypeIdParens, std::optional ArraySize,
+ CXXNewInitializationStyle InitializationStyle, Expr 
*Initializer,
+ QualType Ty, TypeSourceInfo *AllocatedTypeInfo, 
SourceRange Range,
+ SourceRange DirectInitRange);
+
   /// Create an empty c++ new expression.
   static CXXNewExpr *CreateEmpty(const ASTContext &Ctx, bool IsArray,
  bool HasInit, unsigned NumPlacementArgs,
@@ -2332,6 +2347,12 @@ class CXXNewExpr final
   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
   void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
 
+  bool isReservedPlacementNew() const {
+if (CXXNewExprBits.IsPlacementNewExpr)
+  return true;
+return OperatorNew->isReservedGlobalPlacementOperator();
+  }
+
   bool isArray() const { return CXXNewExprBits.IsArray; }
 
   /// This might return std::nullopt even if isArray() returns true,
@@ -2387,6 +2408,8 @@ class CXXNewExpr final
 
   bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; }
 
+  bool isPlacementNewExpr() const { return CXXNewExprBits.IsPlacementNewExpr; }
+
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
 switch (getInitializationStyle()) {
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index da7b37ce0e1211f..2dc3746aee4fd71 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -878,6 +878,10 @@ class alignas(void *) Stmt {
  

[mlir] [llvm] [clang] [llvm] Improve implementation of StringRef::find_last_of and cie (PR #71865)

2023-11-14 Thread Mehdi Amini via cfe-commits


@@ -274,6 +278,23 @@ StringRef::size_type 
StringRef::find_first_not_of(StringRef Chars,
 /// Note: O(size() + Chars.size())
 StringRef::size_type StringRef::find_last_of(StringRef Chars,
  size_t From) const {
+#ifdef __SSE2__
+  if (Chars.size() == 2) {
+__m128i Needle0 = _mm_set1_epi8(Chars[0]);
+__m128i Needle1 = _mm_set1_epi8(Chars[1]);
+size_type Sz = std::min(From, Length);
+do {
+  Sz = Sz < 16 ? 0 : Sz - 16;
+  __m128i Buffer = _mm_loadu_si128((const __m128i *)(Data + Sz));
+  unsigned Mask = _mm_movemask_epi8(_mm_or_si128(
+  _mm_cmpeq_epi8(Buffer, Needle0), _mm_cmpeq_epi8(Buffer, Needle1)));
+  if (Mask != 0) {
+return Sz + sizeof(Mask) * CHAR_BIT - llvm::countl_zero(Mask);
+  }
+} while (Sz);
+return npos;
+  }
+#endif

joker-eph wrote:

Can this be abstracted or made out-of-line?
I'm wondering about the scalability of HW-specific intrinsics in-line 
(anticipating for the incoming `#elif defined(ARM64)`...)

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


[clang] [clang] Add `::_placement_new` expression for built-in global placement new (PR #72209)

2023-11-14 Thread via cfe-commits

https://github.com/MaxEW707 updated 
https://github.com/llvm/llvm-project/pull/72209

>From 75cf305fe732d00be910a6aa0afe79953c5b7186 Mon Sep 17 00:00:00 2001
From: MaxEW707 <82551778+maxew...@users.noreply.github.com>
Date: Sun, 12 Nov 2023 11:36:58 -0500
Subject: [PATCH 1/2] Implement `::_placement_new` expression for built-in
 global placement new without header includes, overload resolution or dealing
 with std libraries that declare the global placement new with attributes that
 cannot be redeclared.

---
 clang/include/clang/AST/ExprCXX.h | 23 +
 clang/include/clang/AST/Stmt.h|  4 ++
 .../clang/Basic/DiagnosticParseKinds.td   |  2 +
 clang/include/clang/Basic/TokenKinds.def  |  1 +
 clang/include/clang/Sema/Sema.h   |  4 +-
 clang/lib/AST/ASTImporter.cpp | 18 ---
 clang/lib/AST/ExprCXX.cpp | 34 +
 clang/lib/AST/ExprConstant.cpp|  7 ++-
 clang/lib/AST/JSONNodeDumper.cpp  |  1 +
 clang/lib/AST/StmtPrinter.cpp |  5 +-
 clang/lib/AST/StmtProfile.cpp |  1 +
 clang/lib/AST/TextNodeDumper.cpp  |  2 +
 clang/lib/CodeGen/CGExprCXX.cpp   |  8 ++--
 clang/lib/CodeGen/CodeGenModule.cpp   |  5 +-
 clang/lib/Interpreter/Interpreter.cpp |  4 +-
 clang/lib/Parse/ParseDecl.cpp |  6 ++-
 clang/lib/Parse/ParseExpr.cpp |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp  | 19 ++--
 clang/lib/Parse/ParseObjc.cpp |  1 +
 clang/lib/Parse/ParseTentative.cpp|  3 +-
 clang/lib/Sema/SemaExprCXX.cpp| 48 ++-
 clang/lib/Sema/TreeTransform.h|  6 +--
 clang/lib/Serialization/ASTReaderStmt.cpp |  2 +
 clang/lib/Serialization/ASTWriterStmt.cpp |  2 +
 .../Checkers/CheckPlacementNew.cpp|  2 +-
 .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp |  9 ++--
 clang/test/AST/ast-dump-expr.cpp  | 14 ++
 clang/test/CodeGenCXX/new.cpp | 44 -
 clang/test/SemaCXX/new-delete.cpp |  7 +++
 29 files changed, 234 insertions(+), 50 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 24278016431837b..d760af796aea28f 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2282,6 +2282,13 @@ class CXXNewExpr final
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
+  /// Build a c++ builtin placement new expression
+  CXXNewExpr(Expr *PlacementArg,
+ SourceRange TypeIdParens, std::optional ArraySize,
+ CXXNewInitializationStyle InitializationStyle, Expr *Initializer,
+ QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
+ SourceRange DirectInitRange);
+
   /// Build an empty c++ new expression.
   CXXNewExpr(EmptyShell Empty, bool IsArray, unsigned NumPlacementArgs,
  bool IsParenTypeId);
@@ -2297,6 +2304,14 @@ class CXXNewExpr final
  QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
  SourceRange DirectInitRange);
 
+  /// Create a c++ builtin placement new expression.
+  static CXXNewExpr *
+  CreatePlacementNew(const ASTContext &Ctx, Expr *PlacementArg,
+ SourceRange TypeIdParens, std::optional ArraySize,
+ CXXNewInitializationStyle InitializationStyle, Expr 
*Initializer,
+ QualType Ty, TypeSourceInfo *AllocatedTypeInfo, 
SourceRange Range,
+ SourceRange DirectInitRange);
+
   /// Create an empty c++ new expression.
   static CXXNewExpr *CreateEmpty(const ASTContext &Ctx, bool IsArray,
  bool HasInit, unsigned NumPlacementArgs,
@@ -2332,6 +2347,12 @@ class CXXNewExpr final
   FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
   void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
 
+  bool isReservedPlacementNew() const {
+if (CXXNewExprBits.IsPlacementNewExpr)
+  return true;
+return OperatorNew->isReservedGlobalPlacementOperator();
+  }
+
   bool isArray() const { return CXXNewExprBits.IsArray; }
 
   /// This might return std::nullopt even if isArray() returns true,
@@ -2387,6 +2408,8 @@ class CXXNewExpr final
 
   bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; }
 
+  bool isPlacementNewExpr() const { return CXXNewExprBits.IsPlacementNewExpr; }
+
   /// Whether this new-expression has any initializer at all.
   bool hasInitializer() const {
 switch (getInitializationStyle()) {
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index da7b37ce0e1211f..2dc3746aee4fd71 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -878,6 +878,10 @@ class alignas(void *) Stmt {
  

[clang] 8dfac29 - [CodeGen] [riscv] Remove no-op ptr-to-ptr bitcasts (NFC)

2023-11-14 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2023-11-15T01:09:23+01:00
New Revision: 8dfac290a441de21a24faccca6110bc738ebf1b7

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

LOG: [CodeGen] [riscv] Remove no-op ptr-to-ptr bitcasts (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CodeGenFunction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 0f2b9055b88eb04..64521ce7182eee6 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2486,10 +2486,8 @@ llvm::Value 
*CodeGenFunction::EmitAnnotationCall(llvm::Function *AnnotationFn,
  const AnnotateAttr *Attr) {
   SmallVector Args = {
   AnnotatedVal,
-  Builder.CreateBitCast(CGM.EmitAnnotationString(AnnotationStr),
-ConstGlobalsPtrTy),
-  Builder.CreateBitCast(CGM.EmitAnnotationUnit(Location),
-ConstGlobalsPtrTy),
+  CGM.EmitAnnotationString(AnnotationStr),
+  CGM.EmitAnnotationUnit(Location),
   CGM.EmitAnnotationLineNo(Location),
   };
   if (Attr)
@@ -2499,15 +2497,10 @@ llvm::Value 
*CodeGenFunction::EmitAnnotationCall(llvm::Function *AnnotationFn,
 
 void CodeGenFunction::EmitVarAnnotations(const VarDecl *D, llvm::Value *V) {
   assert(D->hasAttr() && "no annotate attribute");
-  // FIXME We create a new bitcast for every annotation because that's what
-  // llvm-gcc was doing.
-  unsigned AS = V->getType()->getPointerAddressSpace();
-  llvm::Type *I8PtrTy = Builder.getPtrTy(AS);
   for (const auto *I : D->specific_attrs())
 EmitAnnotationCall(CGM.getIntrinsic(llvm::Intrinsic::var_annotation,
-{I8PtrTy, CGM.ConstGlobalsPtrTy}),
-   Builder.CreateBitCast(V, I8PtrTy, V->getName()),
-   I->getAnnotation(), D->getLocation(), I);
+{V->getType(), CGM.ConstGlobalsPtrTy}),
+   V, I->getAnnotation(), D->getLocation(), I);
 }
 
 Address CodeGenFunction::EmitFieldAnnotations(const FieldDecl *D,



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


[clang] [Driver][BoundsSafety] Add -fexperimental-bounds-safety flag (PR #70480)

2023-11-14 Thread Yeoul Na via cfe-commits

rapidsna wrote:

> In addition, I think our convention is to add the option when the feature is 
> ready, rather than add a no-op option, than build functional patches on top 
> of it.

@MaskRay  This feature will involve a lot of incremental patches. And we will 
still need an experimental flag to test the incremental functionalities that 
are added. I can make it a CC1 only flag for now. Would it work for you better?

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


[clang] [-Wunsafe-buffer-usage] Add FixableGadget for AddAssign in UnspecifiedUntypedContext (PR #71862)

2023-11-14 Thread Rashmi Mudduluru via cfe-commits

https://github.com/t-rasmud updated 
https://github.com/llvm/llvm-project/pull/71862

>From 6636745d1c444747a33c91b366a730d81ca5db5a Mon Sep 17 00:00:00 2001
From: Rashmi Mudduluru 
Date: Wed, 1 Nov 2023 13:43:12 -0700
Subject: [PATCH 1/8] [-Wunsafe-buffer-usage][WIP] Fixable gadget for AddAssign

---
 .../Analyses/UnsafeBufferUsageGadgets.def |  1 +
 clang/lib/Analysis/UnsafeBufferUsage.cpp  | 65 +++
 ...-unsafe-buffer-usage-fixits-add-assign.cpp | 38 +++
 3 files changed, 104 insertions(+)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-add-assign.cpp

diff --git a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def 
b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
index ff687a0d178bdea..757ee452ced7488 100644
--- a/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
+++ b/clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
@@ -36,6 +36,7 @@ FIXABLE_GADGET(PointerDereference)
 FIXABLE_GADGET(UPCAddressofArraySubscript) // '&DRE[any]' in an Unspecified 
Pointer Context
 FIXABLE_GADGET(UPCStandalonePointer)
 FIXABLE_GADGET(UPCPreIncrement)// '++Ptr' in an Unspecified 
Pointer Context
+FIXABLE_GADGET(UUCAddAssign)// 'Ptr += n' in an Unspecified 
Untyped Context
 FIXABLE_GADGET(PointerAssignment)
 FIXABLE_GADGET(PointerInit)
 
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index e332a3609290aac..7b79f5360c79d6e 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1028,6 +1028,42 @@ class UPCPreIncrementGadget : public FixableGadget {
   }
 };
 
+// Representing a pointer type expression of the form `Ptr += n` in an
+// Unspecified Untyped Context (UUC):
+class UUCAddAssignGadget : public FixableGadget {
+private:
+  static constexpr const char *const UUCAddAssignTag =
+"PointerAddAssignUnderUUC";
+  const BinaryOperator *Node; // the `Ptr += n` node
+
+public:
+  UUCAddAssignGadget(const MatchFinder::MatchResult &Result)
+: FixableGadget(Kind::UUCAddAssign),
+  Node(Result.Nodes.getNodeAs(UUCAddAssignTag)) {
+assert(Node != nullptr && "Expecting a non-null matching result");
+  }
+
+  static bool classof(const Gadget *G) {
+return G->getKind() == Kind::UUCAddAssign;
+  }
+
+  static Matcher matcher() {
+return stmt(isInUnspecifiedUntypedContext(expr(ignoringImpCasts(
+binaryOperator(hasOperatorName("+="),
+  hasLHS(declRefExpr(
+toSupportedVariable()))
+  ).bind(UUCAddAssignTag);
+  }
+
+  virtual std::optional getFixits(const Strategy &S) const override;
+
+  virtual const Stmt *getBaseStmt() const override { return Node; }
+
+  virtual DeclUseList getClaimedVarUseSites() const override {
+return {dyn_cast(Node->getLHS())};
+  }
+};
+
 // Representing a fixable expression of the form `*(ptr + 123)` or `*(123 +
 // ptr)`:
 class DerefSimplePtrArithFixableGadget : public FixableGadget {
@@ -1766,6 +1802,35 @@ fixUPCAddressofArraySubscriptWithSpan(const 
UnaryOperator *Node) {
   FixItHint::CreateReplacement(Node->getSourceRange(), SS.str())};
 }
 
+std::optional UUCAddAssignGadget::getFixits(const Strategy &S) 
const {
+  DeclUseList DREs = getClaimedVarUseSites();
+
+  if (DREs.size() != 1)
+return std::nullopt; // In cases of `Ptr += n` where `Ptr` is not a DRE, we
+ // give up
+  if (const VarDecl *VD = dyn_cast(DREs.front()->getDecl())) {
+if (S.lookup(VD) == Strategy::Kind::Span) {
+  FixItList Fixes;
+  std::stringstream SS;
+  const Stmt *AddAssignNode = getBaseStmt();
+  StringRef varName = VD->getName();
+  const ASTContext &Ctx = VD->getASTContext();
+
+  // To transform UUC(p += n) to UUC((p = p.subspan(1)).data()):
+  SS << varName.data() << " = " << varName.data()
+ << ".subspan(" << getUserFillPlaceHolder() << ")";
+  std::optional AddAssignLocation =
+  getEndCharLoc(AddAssignNode, Ctx.getSourceManager(), 
Ctx.getLangOpts());
+  if (!AddAssignLocation)
+return std::nullopt;
+
+  Fixes.push_back(FixItHint::CreateReplacement(
+  SourceRange(AddAssignNode->getBeginLoc(), *AddAssignLocation), 
SS.str()));
+  return Fixes;
+}
+  }
+  return std::nullopt; // Not in the cases that we can handle for now, give up.
+}
 
 std::optional UPCPreIncrementGadget::getFixits(const Strategy &S) 
const {
   DeclUseList DREs = getClaimedVarUseSites();
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-add-assign.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-add-assign.cpp
new file mode 100644
index 000..e2b9a43dee9b3c3
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-add-assign.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
+// R

[llvm] [clang] [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72234)

2023-11-14 Thread Adrian Prantl via cfe-commits

https://github.com/adrian-prantl approved this pull request.

LGTM, then

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


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2023-11-14 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/72298

>From fe214850572ba740c0027e8f2908cde0bae75517 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Tue, 14 Nov 2023 17:27:37 +
Subject: [PATCH] [AVR] make the AVR ABI Swift compatible

This patch is needed to add support to clang's AVR ABI for the Swift
language. It is a pre-requisite for upstreaming AVR patches to the Swift
compiler itself.

@benshi001 @rjmccall
---
 clang/lib/CodeGen/Targets/AVR.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/AVR.cpp 
b/clang/lib/CodeGen/Targets/AVR.cpp
index 50547dd6dec5e7d..bc6418c1e224eb4 100644
--- a/clang/lib/CodeGen/Targets/AVR.cpp
+++ b/clang/lib/CodeGen/Targets/AVR.cpp
@@ -112,7 +112,10 @@ class AVRABIInfo : public DefaultABIInfo {
 class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   AVRTargetCodeGenInfo(CodeGenTypes &CGT, unsigned NPR, unsigned NRR)
-  : TargetCodeGenInfo(std::make_unique(CGT, NPR, NRR)) {}
+  : TargetCodeGenInfo(std::make_unique(CGT, NPR, NRR)) {
+SwiftInfo =
+  std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
+  }
 
   LangAS getGlobalVarAddressSpace(CodeGenModule &CGM,
   const VarDecl *D) const override {

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


[llvm] [clang] [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72234)

2023-11-14 Thread Michael Buch via cfe-commits

Michael137 wrote:

> I think this is missing a test in clang/test/CodeGenCXX that verifies Clang 
> generates the expected LLVM IR.

I added those tests here: https://github.com/llvm/llvm-project/pull/72235

The IR doesn't change with this patch. It merely adds the necessary parameter 
to the DIBuilder API to be used from clang in the subsequent patch

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


[llvm] [clang] [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72234)

2023-11-14 Thread Adrian Prantl via cfe-commits


@@ -1681,7 +1681,8 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, 
Align);
+  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr,
+  llvm::dwarf::DW_TAG_member, Align);

adrian-prantl wrote:

Assuming this _changes_ the IR.

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


[llvm] [clang] [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72234)

2023-11-14 Thread Adrian Prantl via cfe-commits

https://github.com/adrian-prantl requested changes to this pull request.

I think this is missing a test in clang/test/CodeGenCXX that verifies Clang 
generates the expected LLVM IR.

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


[llvm] [clang] [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72234)

2023-11-14 Thread Adrian Prantl via cfe-commits


@@ -1315,17 +1315,15 @@ LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef 
Builder, const char *Name,
   return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen}));
 }
 
-LLVMMetadataRef
-LLVMDIBuilderCreateStaticMemberType(
+LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType(
 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
 LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
-uint32_t AlignInBits) {
+unsigned Tag, uint32_t AlignInBits) {

adrian-prantl wrote:

Somebody might complain if we change the C API, but I don't think we guarantee 
compatibility.

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


[clang] [llvm] [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72234)

2023-11-14 Thread Adrian Prantl via cfe-commits

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


[clang] [llvm] [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72234)

2023-11-14 Thread Adrian Prantl via cfe-commits

https://github.com/adrian-prantl approved this pull request.


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


[clang] c66844d - [CodeGenOpenCL] Remove pointer type caching

2023-11-14 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2023-11-15T00:37:44+01:00
New Revision: c66844d629d8317ed9bbd7d4049d52d56597adcc

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

LOG: [CodeGenOpenCL] Remove pointer type caching

This was important when typed LLVM pointers wanted a struct definition
for every type, but that's no longer necessary with opaque pointers.
NFCI.

Added: 


Modified: 
clang/lib/CodeGen/CGOpenCLRuntime.cpp
clang/lib/CodeGen/CGOpenCLRuntime.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenCLRuntime.cpp 
b/clang/lib/CodeGen/CGOpenCLRuntime.cpp
index 33838a6552c8d70..115b618056a445e 100644
--- a/clang/lib/CodeGen/CGOpenCLRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenCLRuntime.cpp
@@ -37,43 +37,16 @@ llvm::Type 
*CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) {
   if (llvm::Type *TransTy = CGM.getTargetCodeGenInfo().getOpenCLType(CGM, T))
 return TransTy;
 
-  switch (cast(T)->getKind()) {
-  default:
-llvm_unreachable("Unexpected opencl builtin type!");
-return nullptr;
-#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   
\
-  case BuiltinType::Id:
\
-return getPointerType(T, "opencl." #ImgType "_" #Suffix "_t");
-#include "clang/Basic/OpenCLImageTypes.def"
-  case BuiltinType::OCLSampler:
+  if (T->isSamplerT())
 return getSamplerType(T);
-  case BuiltinType::OCLEvent:
-return getPointerType(T, "opencl.event_t");
-  case BuiltinType::OCLClkEvent:
-return getPointerType(T, "opencl.clk_event_t");
-  case BuiltinType::OCLQueue:
-return getPointerType(T, "opencl.queue_t");
-  case BuiltinType::OCLReserveID:
-return getPointerType(T, "opencl.reserve_id_t");
-#define EXT_OPAQUE_TYPE(ExtType, Id, Ext)  
\
-  case BuiltinType::Id:
\
-return getPointerType(T, "opencl." #ExtType);
-#include "clang/Basic/OpenCLExtensionTypes.def"
-  }
-}
 
-llvm::PointerType *CGOpenCLRuntime::getPointerType(const Type *T,
-   StringRef Name) {
-  auto I = CachedTys.find(Name);
-  if (I != CachedTys.end())
-return I->second;
+  return getPointerType(T);
+}
 
-  llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+llvm::PointerType *CGOpenCLRuntime::getPointerType(const Type *T) {
   uint32_t AddrSpc = CGM.getContext().getTargetAddressSpace(
   CGM.getContext().getOpenCLTypeAddrSpace(T));
-  auto *PTy = llvm::PointerType::get(Ctx, AddrSpc);
-  CachedTys[Name] = PTy;
-  return PTy;
+  return llvm::PointerType::get(CGM.getLLVMContext(), AddrSpc);
 }
 
 llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) {
@@ -89,9 +62,7 @@ llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) {
 llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T, StringRef Name,
  llvm::Type *&PipeTy) {
   if (!PipeTy)
-PipeTy = llvm::PointerType::get(
-CGM.getLLVMContext(), CGM.getContext().getTargetAddressSpace(
-  CGM.getContext().getOpenCLTypeAddrSpace(T)));
+PipeTy = getPointerType(T);
   return PipeTy;
 }
 
@@ -103,10 +74,7 @@ llvm::Type *CGOpenCLRuntime::getSamplerType(const Type *T) {
   CGM, CGM.getContext().OCLSamplerTy.getTypePtr()))
 SamplerTy = TransTy;
   else
-// struct opencl.sampler_t*
-SamplerTy = llvm::PointerType::get(
-CGM.getLLVMContext(), CGM.getContext().getTargetAddressSpace(
-  CGM.getContext().getOpenCLTypeAddrSpace(T)));
+SamplerTy = getPointerType(T);
   return SamplerTy;
 }
 

diff  --git a/clang/lib/CodeGen/CGOpenCLRuntime.h 
b/clang/lib/CodeGen/CGOpenCLRuntime.h
index df8084d6008be94..34613c3516f3745 100644
--- a/clang/lib/CodeGen/CGOpenCLRuntime.h
+++ b/clang/lib/CodeGen/CGOpenCLRuntime.h
@@ -39,7 +39,6 @@ class CGOpenCLRuntime {
   llvm::Type *PipeROTy;
   llvm::Type *PipeWOTy;
   llvm::Type *SamplerTy;
-  llvm::StringMap CachedTys;
 
   /// Structure for enqueued block information.
   struct EnqueuedBlockInfo {
@@ -53,7 +52,7 @@ class CGOpenCLRuntime {
 
   virtual llvm::Type *getPipeType(const PipeType *T, StringRef Name,
   llvm::Type *&PipeTy);
-  llvm::PointerType *getPointerType(const Type *T, StringRef Name);
+  llvm::PointerType *getPointerType(const Type *T);
 
 public:
   CGOpenCLRuntime(CodeGenModule &CGM) : CGM(CGM),



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


[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)

2023-11-14 Thread Owen Pan via cfe-commits

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

>From 8e61a470fc7e4cf11a6cf285668a7f9eca72702c Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 14 Nov 2023 05:05:14 -0800
Subject: [PATCH 1/2] [clang-format] Handle constrained auto in
 QualifierAlignment

Fixed #69610.
---
 clang/lib/Format/QualifierAlignmentFixer.cpp  |  5 +
 clang/unittests/Format/QualifierFixerTest.cpp | 10 ++
 2 files changed, 15 insertions(+)

diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 7167e50ec724eab..72464d367153934 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -345,6 +345,8 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
 TypeToken = Next->getNextNonComment()->getNextNonComment();
   }
 }
+if (Next->is(tok::kw_auto))
+  TypeToken = Next;
 
 // Place the Qualifier at the end of the list of qualifiers.
 while (isQualifier(TypeToken->getNextNonComment())) {
@@ -446,6 +448,9 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeLeft(
 return false;
   }
 
+  if (Tok->endsSequence(tok::kw_auto, tok::identifier))
+return false;
+
   return true;
 };
 
diff --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 73814e7414f5e7d..a56323a88f4a04d 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -352,6 +352,11 @@ TEST_F(QualifierFixerTest, RightQualifier) {
   verifyFormat("auto const &ir = i;", "const auto &ir = i;", Style);
   verifyFormat("auto const *ip = &i;", "const auto *ip = &i;", Style);
 
+  verifyFormat("void f(Concept auto const &x);",
+   "void f(const Concept auto &x);", Style);
+  verifyFormat("void f(std::integral auto const &x);",
+   "void f(const std::integral auto &x);", Style);
+
   verifyFormat("Foo const> P;\n#if 0\n#else\n#endif",
"Foo> P;\n#if 0\n#else\n#endif", Style);
 
@@ -653,6 +658,11 @@ TEST_F(QualifierFixerTest, LeftQualifier) {
   verifyFormat("const auto &ir = i;", "auto const &ir = i;", Style);
   verifyFormat("const auto *ip = &i;", "auto const *ip = &i;", Style);
 
+  verifyFormat("void f(const Concept auto &x);",
+   "void f(Concept auto const &x);", Style);
+  verifyFormat("void f(const std::integral auto &x);",
+   "void f(std::integral auto const &x);", Style);
+
   verifyFormat("Foo> P;\n#if 0\n#else\n#endif",
"Foo const> P;\n#if 0\n#else\n#endif", Style);
 

>From 0a5a39d757400328f95ad5a851c9d247bdc8321b Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 14 Nov 2023 15:33:34 -0800
Subject: [PATCH 2/2] Update clang/lib/Format/QualifierAlignmentFixer.cpp

---
 clang/lib/Format/QualifierAlignmentFixer.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 72464d367153934..e2fab1c1e3c2a37 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -345,6 +345,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
 TypeToken = Next->getNextNonComment()->getNextNonComment();
   }
 }
+
 if (Next->is(tok::kw_auto))
   TypeToken = Next;
 

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


[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)

2023-11-14 Thread Owen Pan via cfe-commits

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


[clang] [llvm] Add RunTimeLang to Class and Enumeration DIBuilder functions (PR #72011)

2023-11-14 Thread Augusto Noronha via cfe-commits

augusto2112 wrote:

ping :) 

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


[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)

2023-11-14 Thread Owen Pan via cfe-commits


@@ -345,6 +345,8 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
 TypeToken = Next->getNextNonComment()->getNextNonComment();
   }
 }
+if (Next->is(tok::kw_auto))

owenca wrote:

```suggestion

if (Next->is(tok::kw_auto))
```

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


[clang] [clang-format] Skip alignArrayInitializers() for 1-row matrices (PR #72166)

2023-11-14 Thread Owen Pan via cfe-commits


@@ -20875,13 +20875,15 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
"};",
Style);
   // TODO: Fix the indentations below when this option is fully functional.
+#if 0

owenca wrote:

Because it's wrong as the TODO comment says.

This patch doesn't fix it and would format it as:
```
int a[][] = {
{
 {0, 2}, //
{1, 2}  //
}
};
```
Nevertheless, I just changed it to what it ought to look like.

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


[clang] [Driver][BoundsSafety] Add -fexperimental-bounds-safety flag (PR #70480)

2023-11-14 Thread Yeoul Na via cfe-commits

rapidsna wrote:

> > @MaskRay To be clear, the check is now in Driver as you suggested. It's 
> > just that the frontend also has some extra checks too. So, you want me to 
> > remove the extra checks in the frontend?
> 
> Yes, otherwise it's duplicated check.

I just removed the check in the frontend!



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


[clang] [Driver][BoundsSafety] Add -fexperimental-bounds-safety flag (PR #70480)

2023-11-14 Thread Yeoul Na via cfe-commits

rapidsna wrote:

> > -fbounds-safety-experimental is an experimental flag for -fbounds-safety,
> 
> -fexperimental-bounds-safety

Changed the description in the PR! I'll adjust the commit message too when I 
squash all the changes once I get your approval.

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


[clang] [Driver][BoundsSafety] Add -fexperimental-bounds-safety flag (PR #70480)

2023-11-14 Thread Yeoul Na via cfe-commits

https://github.com/rapidsna updated 
https://github.com/llvm/llvm-project/pull/70480

>From 99ec6e055dd32a86bf6d589a6895658dcbe1d7bd Mon Sep 17 00:00:00 2001
From: Yeoul Na 
Date: Fri, 27 Oct 2023 08:34:37 -0700
Subject: [PATCH 01/11] [Driver][BoundsSafety] Add -fbounds-safety-experimental
 flag

-fbounds-safety-experimental is an experimental flag for
-fbounds-safety, which is a bounds-safety extension for C.
-fbounds-safety will require substantial changes across the Clang
codebase. So we introduce this experimental flag is to gate our
incremental patches until we push the essential functionality of
the extension.

-fbounds-safety-experimental currently doesn't do anything but
reporting an error when the flag is used with an unsupported
source language (currently only supports C).
---
 .../clang/Basic/DiagnosticFrontendKinds.td|  3 +++
 clang/include/clang/Basic/LangOptions.def |  2 ++
 clang/include/clang/Driver/Options.td |  8 +++
 clang/lib/Driver/ToolChains/Clang.cpp |  3 +++
 clang/lib/Frontend/CompilerInvocation.cpp | 23 +++
 clang/test/BoundsSafety/Driver/driver.c   |  9 
 .../Frontend/only_c_is_supported.c| 15 
 7 files changed, 63 insertions(+)
 create mode 100644 clang/test/BoundsSafety/Driver/driver.c
 create mode 100644 clang/test/BoundsSafety/Frontend/only_c_is_supported.c

diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 715e0c0dc8fa84e..edcbbe992377e12 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -330,6 +330,9 @@ def warn_alias_with_section : Warning<
   "as the %select{aliasee|resolver}2">,
   InGroup;
 
+def error_bounds_safety_lang_not_supported : Error<
+  "bounds safety is only supported for C">;
+
 let CategoryName = "Instrumentation Issue" in {
 def warn_profile_data_out_of_date : Warning<
   "profile data may be out of date: of %0 function%s0, %1 
%plural{1:has|:have}1"
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index c0ea4ecb9806a5b..222812d876a65f8 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -470,6 +470,8 @@ VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level")
 // on large _BitInts.
 BENIGN_VALUE_LANGOPT(MaxBitIntWidth, 32, 128, "Maximum width of a _BitInt")
 
+LANGOPT(BoundsSafety, 1, 0, "Bounds safety extension for C")
+
 LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process statements"
 "on the global scope, ignore EOF token and continue later on (thus "
 "avoid tearing the Lexer and etc. down). Controlled by "
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f3f5125d42e7a9..3eb98c8ee2950a1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1732,6 +1732,14 @@ def fswift_async_fp_EQ : Joined<["-"], 
"fswift-async-fp=">,
 NormalizedValues<["Auto", "Always", "Never"]>,
 MarshallingInfoEnum, "Always">;
 
+defm bounds_safety : BoolFOption<
+  "bounds-safety-experimental",
+  LangOpts<"BoundsSafety">, DefaultFalse,
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, CC1Option],
+  " experimental bounds safety extension for C">>;
+
 defm addrsig : BoolFOption<"addrsig",
   CodeGenOpts<"Addrsig">, DefaultFalse,
   PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 43a92adbef64ba8..7482b852fb37958 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6689,6 +6689,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
  options::OPT_fno_assume_sane_operator_new);
 
+  Args.addOptInFlag(CmdArgs, options::OPT_fbounds_safety,
+options::OPT_fno_bounds_safety);
+
   // -fblocks=0 is default.
   if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks,
TC.IsBlocksDefault()) ||
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index fd6c250efeda2a8..f785bd504d63a81 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3618,6 +3618,23 @@ void CompilerInvocationBase::GenerateLangArgs(const 
LangOptions &Opts,
 GenerateArg(Consumer, OPT_frandomize_layout_seed_EQ, Opts.RandstructSeed);
 }
 
+static bool SupportsBoundsSafety(Language Lang) {
+  // Currently, bounds safety is only supported for C. However, it's also
+  // possible to pass assembly files and LLVM IR through Clang, and
+  // those should be trivially supported. This is especially important because
+  // some build systems, like xcbuild and somewhat clumsy Makefiles, will pass

  1   2   3   4   5   >