[clang] [llvm] Intrinsic: introduce minimumnum and maximumnum (PR #93841)

2024-06-10 Thread YunQiang Su via cfe-commits


@@ -16055,6 +16145,90 @@ of the two arguments. -0.0 is considered to be less 
than +0.0 for this
 intrinsic. Note that these are the semantics specified in the draft of
 IEEE 754-2019.
 
+.. _i_minimumnum:
+
+'``llvm.minimumnum.*``' Intrinsic
+^
+
+Syntax:
+"""
+
+This is an overloaded intrinsic. You can use ``llvm.minimumnum`` on any
+floating-point or vector of floating-point type. Not all targets support
+all types however.
+
+::
+
+  declare float @llvm.minimumnum.f32(float %Val0, float %Val1)
+  declare double@llvm.minimumnum.f64(double %Val0, double %Val1)
+  declare x86_fp80  @llvm.minimumnum.f80(x86_fp80 %Val0, x86_fp80 %Val1)
+  declare fp128 @llvm.minimumnum.f128(fp128 %Val0, fp128 %Val1)
+  declare ppc_fp128 @llvm.minimumnum.ppcf128(ppc_fp128 %Val0, ppc_fp128 
%Val1)
+
+Overview:
+"
+
+The '``llvm.minimumnum.*``' intrinsics return the minimum of the two
+arguments, not propagating NaNs and treating -0.0 as less than +0.0.
+
+
+Arguments:
+""
+
+The arguments and return value are floating-point numbers of the same
+type.
+
+Semantics:
+""
+If both operands are NaNs (including sNaN), returns qNaN. If one operand
+is NaN (including sNaN) and another operand is a number, return the number.
+Otherwise returns the lesser of the two arguments. -0.0 is considered to
+be less than +0.0 for this intrinsic.
+
+Note that these are the semantics of minimumNumber specified in IEEE 754-2019.

wzssyqa wrote:

No. minimumNumber returns NaN only when both are NaN.

```
minimumNumber(x, y) is x if x < y, y if y < x, and the number if one operand is 
a number and the
other is a NaN. For this operation, −0 compares less than +0. If x = y and 
signs are the same it is
either x or y. If both operands are NaNs, a quiet NaN is returned, according to 
6.2. If either
operand is a signaling NaN, an invalid operation exception is signaled, but 
unless both operands
are NaNs, the signaling NaN is otherwise ignored and not converted to a quiet 
NaN as stated in
6.2 for other operations.
```

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


[clang] [CodeGen] Simplify codegen for array initialization (PR #93956)

2024-06-10 Thread Nikita Popov via cfe-commits

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


[clang] [Driver] Add winsysroot alias to the GNU driver (PR #94731)

2024-06-10 Thread via cfe-commits

https://github.com/Andarwinux updated 
https://github.com/llvm/llvm-project/pull/94731

>From e200e1683c2e56fc9014fbdd3bd99006e3d56b92 Mon Sep 17 00:00:00 2001
From: Andarwinux <144242044+andarwi...@users.noreply.github.com>
Date: Fri, 7 Jun 2024 07:07:40 +
Subject: [PATCH] [Driver] Add winsysroot alias to the GNU driver

fixes #91216
---
 clang/include/clang/Driver/Options.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..1cce7a5146dd8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8569,6 +8569,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">,
 Alias<_SLASH_winsdkdir>;
 def : Separate<["-"], "Xmicrosoft-windows-sdk-version">,
 Alias<_SLASH_winsdkversion>;
+def : Separate<["-"], "Xmicrosoft-windows-sys-root">,
+Alias<_SLASH_winsysroot>;
 
 // Ignored:
 

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


[clang] [Clang][C++23] update constexpr diagnostics for missing return statements per P2448 (PR #94123)

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

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

>From 90eeafc82ee08129c2d290e6382f42ec89680049 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 2 Jun 2024 00:07:35 +0300
Subject: [PATCH 1/3] feat(92583): [C++23] update constexpr diagnostics for
 missing return statements per P2448

---
 clang/lib/Sema/SemaDeclCXX.cpp| 34 ---
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp |  2 +-
 .../SemaCXX/constant-expression-cxx14.cpp |  2 +-
 .../constexpr-return-non-void-cxx2b.cpp   |  7 
 4 files changed, 31 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 631fd4e354927..d4401a427282c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1806,6 +1806,7 @@ static unsigned getRecordDiagFromTagKind(TagTypeKind Tag) 
{
 static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl,
Stmt *Body,
Sema::CheckConstexprKind Kind);
+static bool CheckConstexprMissingReturn(Sema &SemaRef, const FunctionDecl 
*Dcl);
 
 // Check whether a function declaration satisfies the requirements of a
 // constexpr function definition or a constexpr constructor definition. If so,
@@ -2411,20 +2412,9 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, 
const FunctionDecl *Dcl,
 }
   } else {
 if (ReturnStmts.empty()) {
-  // C++1y doesn't require constexpr functions to contain a 'return'
-  // statement. We still do, unless the return type might be void, because
-  // otherwise if there's no return statement, the function cannot
-  // be used in a core constant expression.
-  bool OK = SemaRef.getLangOpts().CPlusPlus14 &&
-(Dcl->getReturnType()->isVoidType() ||
- Dcl->getReturnType()->isDependentType());
   switch (Kind) {
   case Sema::CheckConstexprKind::Diagnose:
-SemaRef.Diag(Dcl->getLocation(),
- OK ? diag::warn_cxx11_compat_constexpr_body_no_return
-: diag::err_constexpr_body_no_return)
-<< Dcl->isConsteval();
-if (!OK)
+if (!CheckConstexprMissingReturn(SemaRef, Dcl))
   return false;
 break;
 
@@ -2487,6 +2477,26 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, 
const FunctionDecl *Dcl,
   return true;
 }
 
+static bool CheckConstexprMissingReturn(Sema &SemaRef,
+const FunctionDecl *Dcl) {
+  bool IsVoidOrDependentType = Dcl->getReturnType()->isVoidType() ||
+   Dcl->getReturnType()->isDependentType();
+
+  if (SemaRef.getLangOpts().CPlusPlus23 && !IsVoidOrDependentType)
+return true;
+
+  // C++1y doesn't require constexpr functions to contain a 'return'
+  // statement. We still do, unless the return type might be void, because
+  // otherwise if there's no return statement, the function cannot
+  // be used in a core constant expression.
+  bool OK = SemaRef.getLangOpts().CPlusPlus14 && IsVoidOrDependentType;
+  SemaRef.Diag(Dcl->getLocation(),
+   OK ? diag::warn_cxx11_compat_constexpr_body_no_return
+  : diag::err_constexpr_body_no_return)
+  << Dcl->isConsteval();
+  return OK;
+}
+
 bool Sema::CheckImmediateEscalatingFunctionDefinition(
 FunctionDecl *FD, const sema::FunctionScopeInfo *FSI) {
   if (!getLangOpts().CPlusPlus20 || !FD->isImmediateEscalating())
diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp 
b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
index 4416c82522649..51990ee4341d2 100644
--- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
@@ -212,7 +212,7 @@ constexpr int ClassDecl3() {
   return 0;
 }
 
-constexpr int NoReturn() {} // expected-error {{no return statement in 
constexpr function}}
+constexpr int NoReturn() {} // beforecxx23-error {{no return statement in 
constexpr function}}
 constexpr int MultiReturn() {
   return 0; // beforecxx14-note {{return statement}}
   return 0; // beforecxx14-warning {{multiple return statements in constexpr 
function}}
diff --git a/clang/test/SemaCXX/constant-expression-cxx14.cpp 
b/clang/test/SemaCXX/constant-expression-cxx14.cpp
index 80a7a2dd31531..70ab5dcd357c1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx14.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx14.cpp
@@ -82,7 +82,7 @@ constexpr void k() {
 
 // If the return type is not 'void', no return statements => never a constant
 // expression, so still diagnose that case.
-[[noreturn]] constexpr int fn() { // expected-error {{no return statement in 
constexpr function}}
+[[noreturn]] constexpr int fn() { // cxx14_20-error {{no return statement in 
constexpr function}}
   fn();
 }
 
diff -

[clang] [clang] NFCI: improve TemplateArgument and TemplateName dump methods (PR #94905)

2024-06-10 Thread via cfe-commits


@@ -360,3 +360,34 @@ LLVM_DUMP_METHOD void ConceptReference::dump(raw_ostream 
&OS) const {
   ASTDumper P(OS, Ctx, Ctx.getDiagnostics().getShowColors());
   P.Visit(this);
 }
+
+//===--===//
+// TemplateName method implementations
+//===--===//
+
+// FIXME: These are using the TemplateArgument dumper.

cor3ntin wrote:

I don't think this is a bug, right? Arguably less optimal than it could be.
I think if there is room for improvement the fixme comment should be more 
detailed

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


[clang] [clang] NFCI: improve TemplateArgument and TemplateName dump methods (PR #94905)

2024-06-10 Thread via cfe-commits

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

I'd like to see a more detailed comment, otherwise LGTM.
It's clearly an improvement

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


[clang] [clang][analyzer] Improved PointerSubChecker (PR #93676)

2024-06-10 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/93676

From a896030e71d09ebe7239d6fab343606918ee4c1b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Wed, 29 May 2024 14:28:43 +0200
Subject: [PATCH 1/5] [clang][analyzer] Improved PointerSubChecker

The checker is made more exact (only pointer into array is allowed)
and more tests are added.
---
 .../Checkers/PointerSubChecker.cpp| 34 +
 clang/test/Analysis/pointer-sub.c | 74 +++
 clang/test/Analysis/ptr-arith.c   | 14 +---
 3 files changed, 96 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/Analysis/pointer-sub.c

diff --git a/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
index 2438cf30b39b5..4caa9ded93ed4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
@@ -35,7 +35,7 @@ class PointerSubChecker
 void PointerSubChecker::checkPreStmt(const BinaryOperator *B,
  CheckerContext &C) const {
   // When doing pointer subtraction, if the two pointers do not point to the
-  // same memory chunk, emit a warning.
+  // same array, emit a warning.
   if (B->getOpcode() != BO_Sub)
 return;
 
@@ -44,24 +44,30 @@ void PointerSubChecker::checkPreStmt(const BinaryOperator 
*B,
 
   const MemRegion *LR = LV.getAsRegion();
   const MemRegion *RR = RV.getAsRegion();
-
-  if (!(LR && RR))
-return;
-
-  const MemRegion *BaseLR = LR->getBaseRegion();
-  const MemRegion *BaseRR = RR->getBaseRegion();
-
-  if (BaseLR == BaseRR)
+  if (!LR || !RR)
 return;
 
-  // Allow arithmetic on different symbolic regions.
-  if (isa(BaseLR) || isa(BaseRR))
-return;
+  const auto *ElemLR = dyn_cast(LR);
+  const auto *ElemRR = dyn_cast(RR);
+  // FIXME: We want to verify that these are elements of an array.
+  // Because behavior of ElementRegion it may be confused with a cast.
+  // There is not a simple way to distinguish it from array element (check the
+  // types?). Because this missing check a warning is missing in the rare case
+  // when two casted pointers to the same region (variable) are subtracted.
+  if (ElemLR && ElemRR) {
+const MemRegion *SuperLR = ElemLR->getSuperRegion();
+const MemRegion *SuperRR = ElemRR->getSuperRegion();
+if (SuperLR == SuperRR)
+  return;
+// Allow arithmetic on different symbolic regions.
+if (isa(SuperLR) || isa(SuperRR))
+  return;
+  }
 
   if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
 constexpr llvm::StringLiteral Msg =
-"Subtraction of two pointers that do not point to the same memory "
-"chunk may cause incorrect result.";
+"Subtraction of two pointers that do not point into the same array "
+"is undefined behavior.";
 auto R = std::make_unique(BT, Msg, N);
 R->addRange(B->getSourceRange());
 C.emitReport(std::move(R));
diff --git a/clang/test/Analysis/pointer-sub.c 
b/clang/test/Analysis/pointer-sub.c
new file mode 100644
index 0..010c739d6ad10
--- /dev/null
+++ b/clang/test/Analysis/pointer-sub.c
@@ -0,0 +1,74 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.PointerSub -verify %s
+
+void f1(void) {
+  int x, y, z[10];
+  int d = &y - &x; // expected-warning{{Subtraction of two pointers that do 
not point into the same array is undefined behavior}}
+  d = z - &y; // expected-warning{{Subtraction of two pointers that do not 
point into the same array is undefined behavior}}
+  d = &x - &x; // expected-warning{{Subtraction of two pointers that do not 
point into the same array is undefined behavior}}
+  d = (long*)&x - (long*)&x;
+}
+
+void f2(void) {
+  int a[10], b[10], c;
+  int *p = &a[2];
+  int *q = &a[8];
+  int d = q - p; // no-warning
+
+  q = &b[3];
+  d = q - p; // expected-warning{{Subtraction of two pointers that}}
+
+  q = a + 10;
+  d = q - p; // no warning (use of pointer to one after the end is allowed)
+  d = &a[4] - a; // no warning
+
+  q = a + 11;
+  d = q - a; // ?
+
+  d = &c - p; // expected-warning{{Subtraction of two pointers that}}
+}
+
+void f3(void) {
+  int a[3][4];
+  int d;
+
+  d = &(a[2]) - &(a[1]);
+  d = a[2] - a[1]; // expected-warning{{Subtraction of two pointers that}}
+  d = a[1] - a[1];
+  d = &(a[1][2]) - &(a[1][0]);
+  d = &(a[1][2]) - &(a[0][0]); // expected-warning{{Subtraction of two 
pointers that}}
+}
+
+void f4(void) {
+  int n = 4, m = 3;
+  int a[n][m];
+  int (*p)[m] = a; // p == &a[0]
+  p += 1; // p == &a[1]
+  int d = p - a; // d == 1 // expected-warning{{subtraction of pointers to 
type 'int[m]' of zero size has undefined behavior}}
+
+  d = &(a[2]) - &(a[1]); // expected-warning{{subtraction of pointers to type 
'int[m]' of zero size has undefined behavior}}
+  d = a[2] - a[1]; // expected-warning{{Subtraction of two pointers that}}
+}
+
+typedef struct {
+ 

[clang] [Clang][C++23] update constexpr diagnostics for missing return statements per P2448 (PR #94123)

2024-06-10 Thread Timm Baeder via cfe-commits

tbaederr wrote:

@a-tarasyuk Do you need someone else to merge this?

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


[clang] [Clang] Fix two issues of CTAD for aggregates (PR #94889)

2024-06-10 Thread via cfe-commits

https://github.com/cor3ntin commented:

I think the commit message / release notes message need work (" Fix handling of 
brace ellison when building deduction guides",

But the general direction look good

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


[clang] [Clang] Fix two issues of CTAD for aggregates (PR #94889)

2024-06-10 Thread via cfe-commits


@@ -506,14 +508,19 @@ class InitListChecker {
   Sema &S, const InitializedEntity &Entity, InitListExpr *IL, QualType &T,
   bool VerifyOnly, bool TreatUnavailableAsInvalid,
   bool InOverloadResolution = false,
-  SmallVectorImpl *AggrDeductionCandidateParamTypes = nullptr);
+  SmallVectorImpl *AggrDeductionCandidateParamTypes = nullptr,
+  SmallVectorImpl
+  *AggrDeductionCandidateParamTypesWithoutBraceElision = nullptr);
   InitListChecker(Sema &S, const InitializedEntity &Entity, InitListExpr *IL,
   QualType &T,
-  SmallVectorImpl &AggrDeductionCandidateParamTypes)
+  SmallVectorImpl &AggrDeductionCandidateParamTypes,
+  SmallVectorImpl
+  &AggrDeductionCandidateParamTypesWithoutBraceElision)
   : InitListChecker(S, Entity, IL, T, /*VerifyOnly=*/true,
 /*TreatUnavailableAsInvalid=*/false,
 /*InOverloadResolution=*/false,
-&AggrDeductionCandidateParamTypes){};
+&AggrDeductionCandidateParamTypes,
+&AggrDeductionCandidateParamTypesWithoutBraceElision) 
{}

cor3ntin wrote:

Maybe we need a struct that holds both vector, I think it would be a bit cleaner

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


[clang-tools-extra] [clang-tidy] Add WarnOnSizeOfPointer mode to bugprone-sizeof-expression (PR #94356)

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

https://github.com/NagyDonat updated 
https://github.com/llvm/llvm-project/pull/94356

From c94feff726b48e7e3b5a46d5028cc5a6d0ac9beb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Wed, 22 May 2024 11:57:50 +0200
Subject: [PATCH 1/6] [clang-tidy] Add WarnOnSizeOfPointer mode to
 bugprone-sizeof-expression

This commit reimplements the functionality of the Clang Static Analyzer
checker `alpha.core.SizeofPointer` within clang-tidy by adding a new
(off-by-default) option to bugprone-sizeof-expression which activates
reporting all the `sizeof(ptr)` expressions (where ptr is an expression
that produces a pointer).

The main motivation for this change is that `alpha.core.SizeofPointer`
was an AST-based checker, which did not rely on the path sensitive
capabilities of the Static Analyzer, so there was no reason to keep it
in the Static Analyzer instead of the more lightweight clang-tidy.

After this commit I'm planning to create a separate commit that deletes
`alpha.core.SizeofPointer` from Clang Static Analyzer.

It was natural to place this moved logic in bugprone-sizeof-expression,
because that check already provided several heuristics that reported
various especially suspicious classes of `sizeof(ptr)` expressions.

The new mode `WarnOnSizeOfPointer` is off-by-default, so it won't
surprise the existing users; but it can provide a more through coverage
for the vulnerability CWE-467 ("Use of sizeof() on a Pointer Type") than
the existing partial heuristics.

I preserved the exception that the RHS of an expression that looks like
`sizeof(array) / sizeof(array[0])` is not reported; and I added another
exception which ensures that `sizeof(*pp)` is not reported when `pp` is
a pointer-to-pointer expression.

This second exception (which I also apply in the "old" on-by-default mode
`WarnOnSizeOfPointerToAggregate`) was present in the CSA checker
`alpha.core.SizeofPoionter` and I decided to copy it because it helped
to avoid several false positives on open-source code.

This commit also replaces the old message "suspicious usage of
'sizeof(A*)'; pointer to aggregate" with two more concrete messages; but
I feel that this tidy check would deserve a through cleanup of all the
diagnostic messages that it can produce. (I added a FIXME to mark one
outright misleading message.)
---
 .../bugprone/SizeofExpressionCheck.cpp|  95 ---
 .../bugprone/SizeofExpressionCheck.h  |   1 +
 .../checks/bugprone/sizeof-expression.rst |   5 +
 .../checkers/bugprone/sizeof-expression-2.c   |  12 +-
 .../sizeof-expression-any-pointer.cpp | 231 ++
 .../checkers/bugprone/sizeof-expression.cpp   |  63 +++--
 6 files changed, 351 insertions(+), 56 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-any-pointer.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index 5e64d23874ec1..05ef666d4f01e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -67,7 +67,8 @@ SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
   WarnOnSizeOfCompareToConstant(
   Options.get("WarnOnSizeOfCompareToConstant", true)),
   WarnOnSizeOfPointerToAggregate(
-  Options.get("WarnOnSizeOfPointerToAggregate", true)) {}
+  Options.get("WarnOnSizeOfPointerToAggregate", true)),
+  WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)) {}
 
 void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfConstant", WarnOnSizeOfConstant);
@@ -78,6 +79,7 @@ void 
SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 WarnOnSizeOfCompareToConstant);
   Options.store(Opts, "WarnOnSizeOfPointerToAggregate",
 WarnOnSizeOfPointerToAggregate);
+  Options.store(Opts, "WarnOnSizeOfPointer", WarnOnSizeOfPointer);
 }
 
 void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
@@ -127,17 +129,30 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder 
*Finder) {
   const auto ConstStrLiteralDecl =
   varDecl(isDefinition(), hasType(hasCanonicalType(CharPtrType)),
   hasInitializer(ignoringParenImpCasts(stringLiteral(;
+  const auto VarWithConstStrLiteralDecl = expr(
+  hasType(hasCanonicalType(CharPtrType)),
+  ignoringParenImpCasts(declRefExpr(hasDeclaration(ConstStrLiteralDecl;
   Finder->addMatcher(
-  sizeOfExpr(has(ignoringParenImpCasts(
- expr(hasType(hasCanonicalType(CharPtrType)),
-  ignoringParenImpCasts(declRefExpr(
-  hasDeclaration(ConstStrLiteralDecl)))
+  sizeOfExpr(has(ignoringParenImpCasts(VarWithConstStrLiteralDecl)))
   .bind("sizeof-charp"),
   this);
 
-  // Detect size

[clang-tools-extra] [clangd] Use clang_target_link_libraries() for clang libs (PR #94937)

2024-06-10 Thread Nikita Popov via cfe-commits

https://github.com/nikic created https://github.com/llvm/llvm-project/pull/94937

Use clang_target_link_libraries() instead of LINK_LIBS when linking clang 
libraries. This ensures that in CLANG_LINK_CLANG_DYLIB mode we link against 
libclang-cpp.so (instead of linking against both it and the static libraries).

Most places were already doing this correctly, there were just a handful of 
leftovers.

>From 09c5b73a981c4092d2479c9c50da9299ad43cccb Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Mon, 10 Jun 2024 10:07:04 +0200
Subject: [PATCH] [clangd] Use clang_target_link_libraries() for clang libs

Use clang_target_link_libraries() instead of LINK_LIBS when
linking clang libraries. This ensures that in CLANG_LINK_CLANG_DYLIB
mode we link against libclang-cpp.so (instead of linking against
both it and the static libraries).

Most places were already doing this correctly, there were just
a handful of leftovers.
---
 clang-tools-extra/clangd/index/remote/CMakeLists.txt | 6 +-
 clang-tools-extra/pseudo/lib/CMakeLists.txt  | 8 ++--
 clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt  | 6 +-
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clangd/index/remote/CMakeLists.txt 
b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
index ed6269d2ccaa9..106bbeff84ccf 100644
--- a/clang-tools-extra/clangd/index/remote/CMakeLists.txt
+++ b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
@@ -26,7 +26,6 @@ if (CLANGD_ENABLE_REMOTE)
 clangdRemoteIndexProto
 clangdRemoteIndexServiceProto
 clangdRemoteMarshalling
-clangBasic
 clangDaemon
 clangdSupport
 
@@ -35,6 +34,11 @@ if (CLANGD_ENABLE_REMOTE)
 clangdRemoteIndexServiceProto
 )
 
+  clang_target_link_libraries(clangdRemoteIndex
+PRIVATE
+clangBasic
+)
+
   add_subdirectory(marshalling)
   add_subdirectory(server)
   add_subdirectory(monitor)
diff --git a/clang-tools-extra/pseudo/lib/CMakeLists.txt 
b/clang-tools-extra/pseudo/lib/CMakeLists.txt
index f92f79be12150..a13b5d20cf7c3 100644
--- a/clang-tools-extra/pseudo/lib/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/lib/CMakeLists.txt
@@ -14,8 +14,6 @@ add_clang_library(clangPseudo
   Token.cpp
 
   LINK_LIBS
-  clangBasic
-  clangLex
   clangPseudoGrammar
 
   DEPENDS
@@ -25,3 +23,9 @@ add_clang_library(clangPseudo
   target_include_directories(clangPseudo INTERFACE
   $
   )
+
+clang_target_link_libraries(clangPseudo
+  PRIVATE
+  clangBasic
+  clangLex
+  )
diff --git a/clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt 
b/clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
index d56d16c893c3d..2fecdce6a10f9 100644
--- a/clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
@@ -9,7 +9,11 @@ add_clang_library(clangPseudoCXX
   cxx_gen
 
   LINK_LIBS
-  clangBasic
   clangPseudo
   clangPseudoGrammar
   )
+
+clang_target_link_libraries(clangPseudoCXX
+  PRIVATE
+  clangBasic
+  )

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


[clang-tools-extra] [clangd] Use clang_target_link_libraries() for clang libs (PR #94937)

2024-06-10 Thread via cfe-commits

llvmbot wrote:




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

Author: Nikita Popov (nikic)


Changes

Use clang_target_link_libraries() instead of LINK_LIBS when linking clang 
libraries. This ensures that in CLANG_LINK_CLANG_DYLIB mode we link against 
libclang-cpp.so (instead of linking against both it and the static libraries).

Most places were already doing this correctly, there were just a handful of 
leftovers.

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


3 Files Affected:

- (modified) clang-tools-extra/clangd/index/remote/CMakeLists.txt (+5-1) 
- (modified) clang-tools-extra/pseudo/lib/CMakeLists.txt (+6-2) 
- (modified) clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt (+5-1) 


``diff
diff --git a/clang-tools-extra/clangd/index/remote/CMakeLists.txt 
b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
index ed6269d2ccaa9..106bbeff84ccf 100644
--- a/clang-tools-extra/clangd/index/remote/CMakeLists.txt
+++ b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
@@ -26,7 +26,6 @@ if (CLANGD_ENABLE_REMOTE)
 clangdRemoteIndexProto
 clangdRemoteIndexServiceProto
 clangdRemoteMarshalling
-clangBasic
 clangDaemon
 clangdSupport
 
@@ -35,6 +34,11 @@ if (CLANGD_ENABLE_REMOTE)
 clangdRemoteIndexServiceProto
 )
 
+  clang_target_link_libraries(clangdRemoteIndex
+PRIVATE
+clangBasic
+)
+
   add_subdirectory(marshalling)
   add_subdirectory(server)
   add_subdirectory(monitor)
diff --git a/clang-tools-extra/pseudo/lib/CMakeLists.txt 
b/clang-tools-extra/pseudo/lib/CMakeLists.txt
index f92f79be12150..a13b5d20cf7c3 100644
--- a/clang-tools-extra/pseudo/lib/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/lib/CMakeLists.txt
@@ -14,8 +14,6 @@ add_clang_library(clangPseudo
   Token.cpp
 
   LINK_LIBS
-  clangBasic
-  clangLex
   clangPseudoGrammar
 
   DEPENDS
@@ -25,3 +23,9 @@ add_clang_library(clangPseudo
   target_include_directories(clangPseudo INTERFACE
   $
   )
+
+clang_target_link_libraries(clangPseudo
+  PRIVATE
+  clangBasic
+  clangLex
+  )
diff --git a/clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt 
b/clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
index d56d16c893c3d..2fecdce6a10f9 100644
--- a/clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
@@ -9,7 +9,11 @@ add_clang_library(clangPseudoCXX
   cxx_gen
 
   LINK_LIBS
-  clangBasic
   clangPseudo
   clangPseudoGrammar
   )
+
+clang_target_link_libraries(clangPseudoCXX
+  PRIVATE
+  clangBasic
+  )

``




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


[clang] [Driver] Add winsysroot alias to the GNU driver (PR #94731)

2024-06-10 Thread via cfe-commits

https://github.com/Andarwinux updated 
https://github.com/llvm/llvm-project/pull/94731

>From ead3de5bed1f2ef00e1e9e69755a8a171e20bb46 Mon Sep 17 00:00:00 2001
From: Andarwinux <144242044+andarwi...@users.noreply.github.com>
Date: Fri, 7 Jun 2024 07:07:40 +
Subject: [PATCH] [Driver] Add winsysroot alias to the GNU driver

fixes #91216
---
 clang/include/clang/Driver/Options.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..1cce7a5146dd8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8569,6 +8569,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">,
 Alias<_SLASH_winsdkdir>;
 def : Separate<["-"], "Xmicrosoft-windows-sdk-version">,
 Alias<_SLASH_winsdkversion>;
+def : Separate<["-"], "Xmicrosoft-windows-sys-root">,
+Alias<_SLASH_winsysroot>;
 
 // Ignored:
 

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


[clang] [clang] deprecate alias, class templates without arg list after template kw (PR #94789)

2024-06-10 Thread via cfe-commits

cor3ntin wrote:

Ideally, i think the warning would only happen by default in pedantic modes, in 
C++23 and later (This was deprecated as part of P1787R6). It's a pretty noisy 
warning for an harmless construct.

However it would make sense than one should be able to opt-in the warning 
unconditionally. 

I'm not sure whether there is a good way to do that @AaronBallman 

I would also update most of our tests not to use `template` where it's 
deprecated, except in tests where we are explicitly testing that warning 

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


[clang] c0b65a2 - [clang][Interp] Diagnose casts from void pointers

2024-06-10 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-06-10T10:18:57+02:00
New Revision: c0b65a2491be44f0b162d55563c305c514c01d90

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

LOG: [clang][Interp] Diagnose casts from void pointers

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/c.c
clang/test/Sema/constexpr-void-cast.c

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index ac245e7a0f24c..6654a27c92168 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -325,8 +325,11 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 
 assert(isPtrType(*FromT));
 assert(isPtrType(*ToT));
-if (FromT == ToT)
+if (FromT == ToT) {
+  if (SubExpr->getType()->isVoidPointerType())
+return this->visit(SubExpr) && this->emitVoidPtrCast(CE);
   return this->delegate(SubExpr);
+}
 
 if (!this->visit(SubExpr))
   return false;

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 4bb9e7f0d22ea..0ad710c5ec1af 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1980,6 +1980,13 @@ static inline bool CastPointerIntegralAPS(InterpState 
&S, CodePtr OpPC,
   return true;
 }
 
+static inline bool VoidPtrCast(InterpState &S, CodePtr OpPC) {
+  const SourceInfo &E = S.Current->getSource(OpPC);
+  S.CCEDiag(E, diag::note_constexpr_invalid_cast)
+  << 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
+  return true;
+}
+
 
//===--===//
 // Zero, Nullptr
 
//===--===//

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index a5ac8206104c8..ac5426c87c212 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -665,6 +665,7 @@ def CastPointerIntegralAPS : Opcode {
   let HasGroup = 0;
   let Args = [ArgUint32];
 }
+def VoidPtrCast : Opcode;
 
 def DecayPtr : Opcode {
   let Types = [PtrTypeClass, PtrTypeClass];

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index f4c7bf16f2f95..1cc450e48def0 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -66,12 +66,10 @@ _Static_assert((&a - 100) != 0, ""); // 
pedantic-ref-warning {{is a GNU extensio
  // pedantic-ref-note {{-100 of 
non-array}} \
  // pedantic-expected-note {{-100 of 
non-array}}
 /// extern variable of a composite type.
-/// FIXME: The 'this conversion is not allowed' note is missing in the new 
interpreter.
 extern struct Test50S Test50;
 _Static_assert(&Test50 != (void*)0, ""); // all-warning {{always true}} \
- // pedantic-ref-warning {{is a GNU 
extension}} \
- // pedantic-ref-note {{this 
conversion is not allowed in a constant expression}} \
- // pedantic-expected-warning {{is a 
GNU extension}}
+ // pedantic-warning {{is a GNU 
extension}} \
+ // pedantic-note {{this conversion is 
not allowed in a constant expression}}
 
 struct y {int x,y;};
 int a2[(intptr_t)&((struct y*)0)->y]; // all-warning {{folded to constant 
array}}

diff  --git a/clang/test/Sema/constexpr-void-cast.c 
b/clang/test/Sema/constexpr-void-cast.c
index 91e4027f67fe3..2ffc59f509b4b 100644
--- a/clang/test/Sema/constexpr-void-cast.c
+++ b/clang/test/Sema/constexpr-void-cast.c
@@ -1,8 +1,12 @@
 // RUN: %clang_cc1 -x c -fsyntax-only %s -verify=c -std=c11
 // RUN: %clang_cc1 -x c -fsyntax-only %s -pedantic -verify=c-pedantic -std=c11
+// RUN: %clang_cc1 -x c -fsyntax-only %s -verify=c -std=c11 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -x c -fsyntax-only %s -pedantic -verify=c-pedantic -std=c11 
-fexperimental-new-constant-interpreter
 //
 // RUN: %clang_cc1 -x c++ -fsyntax-only %s -verify=cxx
 // RUN: %clang_cc1 -x c++ -fsyntax-only %s -pedantic -verify=cxx-pedantic
+// RUN: %clang_cc1 -x c++ -fsyntax-only %s -verify=cxx 
-fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -x c++ -fsyntax-only %s -pedantic -verify=cxx-pedantic 
-fexperimental-new-constant-interpreter
 
 // c-no-diagnostics
 // cxx-no-diagnostics



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


[clang] [clang-tools-extra] [clangd] Support parsing comments without ASTContext (PR #78491)

2024-06-10 Thread Shikhar Jayswal via cfe-commits

tfninjadoom wrote:

I'm new to the processes of open-source software, so pardon my confusion. I 
just read through [this](https://github.com/clangd/clangd/issues/529) issue and 
am wondering: 
What's preventing this PR from being merged right now? All checks seem to have 
passed.

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


[clang] 26224ca - [clang][analyzer] Improved PointerSubChecker (#93676)

2024-06-10 Thread via cfe-commits

Author: Balázs Kéri
Date: 2024-06-10T10:21:14+02:00
New Revision: 26224ca2de193dcfd21ede7a846c28ea892b77e3

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

LOG: [clang][analyzer] Improved PointerSubChecker (#93676)

The checker is made more exact
(only pointer into array is allowed, check array index)
and more tests are added.

Added: 
clang/test/Analysis/pointer-sub.c

Modified: 
clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
clang/test/Analysis/casts.c
clang/test/Analysis/ptr-arith.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
index 2438cf30b39b5..b73534136fdf0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
@@ -17,6 +17,7 @@
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h"
 #include "llvm/ADT/StringRef.h"
 
 using namespace clang;
@@ -26,16 +27,88 @@ namespace {
 class PointerSubChecker
   : public Checker< check::PreStmt > {
   const BugType BT{this, "Pointer subtraction"};
+  const llvm::StringLiteral Msg_MemRegionDifferent =
+  "Subtraction of two pointers that do not point into the same array "
+  "is undefined behavior.";
+  const llvm::StringLiteral Msg_LargeArrayIndex =
+  "Using an array index greater than the array size at pointer subtraction 
"
+  "is undefined behavior.";
+  const llvm::StringLiteral Msg_NegativeArrayIndex =
+  "Using a negative array index at pointer subtraction "
+  "is undefined behavior.";
+  const llvm::StringLiteral Msg_BadVarIndex =
+  "Indexing the address of a variable with other than 1 at this place "
+  "is undefined behavior.";
+
+  bool checkArrayBounds(CheckerContext &C, const Expr *E,
+const ElementRegion *ElemReg,
+const MemRegion *Reg) const;
+  void reportBug(CheckerContext &C, const Expr *E,
+ const llvm::StringLiteral &Msg) const;
 
 public:
   void checkPreStmt(const BinaryOperator *B, CheckerContext &C) const;
 };
 }
 
+bool PointerSubChecker::checkArrayBounds(CheckerContext &C, const Expr *E,
+ const ElementRegion *ElemReg,
+ const MemRegion *Reg) const {
+  if (!ElemReg)
+return true;
+
+  ProgramStateRef State = C.getState();
+  const MemRegion *SuperReg = ElemReg->getSuperRegion();
+  SValBuilder &SVB = C.getSValBuilder();
+
+  if (SuperReg == Reg) {
+if (const llvm::APSInt *I = SVB.getKnownValue(State, ElemReg->getIndex());
+I && (!I->isOne() && !I->isZero()))
+  reportBug(C, E, Msg_BadVarIndex);
+return false;
+  }
+
+  DefinedOrUnknownSVal ElemCount =
+  getDynamicElementCount(State, SuperReg, SVB, ElemReg->getElementType());
+  auto IndexTooLarge = SVB.evalBinOp(C.getState(), BO_GT, ElemReg->getIndex(),
+ ElemCount, SVB.getConditionType())
+   .getAs();
+  if (IndexTooLarge) {
+ProgramStateRef S1, S2;
+std::tie(S1, S2) = C.getState()->assume(*IndexTooLarge);
+if (S1 && !S2) {
+  reportBug(C, E, Msg_LargeArrayIndex);
+  return false;
+}
+  }
+  auto IndexTooSmall = SVB.evalBinOp(State, BO_LT, ElemReg->getIndex(),
+ SVB.makeZeroVal(SVB.getArrayIndexType()),
+ SVB.getConditionType())
+   .getAs();
+  if (IndexTooSmall) {
+ProgramStateRef S1, S2;
+std::tie(S1, S2) = State->assume(*IndexTooSmall);
+if (S1 && !S2) {
+  reportBug(C, E, Msg_NegativeArrayIndex);
+  return false;
+}
+  }
+  return true;
+}
+
+void PointerSubChecker::reportBug(CheckerContext &C, const Expr *E,
+  const llvm::StringLiteral &Msg) const {
+  if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
+auto R = std::make_unique(BT, Msg, N);
+R->addRange(E->getSourceRange());
+C.emitReport(std::move(R));
+  }
+}
+
 void PointerSubChecker::checkPreStmt(const BinaryOperator *B,
  CheckerContext &C) const {
   // When doing pointer subtraction, if the two pointers do not point to the
-  // same memory chunk, emit a warning.
+  // same array, emit a warning.
   if (B->getOpcode() != BO_Sub)
 return;
 
@@ -44,28 +117,36 @@ void PointerSubChecker::checkPreStmt(const BinaryOperator 
*B,
 
   const MemRegion *LR = LV.getAsRegion();
   const MemRegion *RR = RV.getAsRegion();
-
-  if (!(LR && RR))

[clang] [clang][analyzer] Improved PointerSubChecker (PR #93676)

2024-06-10 Thread Balázs Kéri via cfe-commits

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


[clang] [Clang][C++23] update constexpr diagnostics for missing return statements per P2448 (PR #94123)

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

a-tarasyuk wrote:

@tbaederr Yes, I do. I don't have access to merge… 

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


[clang] [clang-repl] Lay the foundation of pretty printing for C. (PR #89811)

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

DavidSpickett wrote:

You can debug it by cross-compiling a debug build, then running the unit tests 
binary and connecting to qemu's built in gdbserver. The Arm toolchain might 
have a copy of gdb in it already, but if not, gdb multiarch and lldb would also 
work (which are both installable from apt).

I'm going to try looking in a debugger myself today.

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


[clang] [clang-repl] Lay the foundation of pretty printing for C. (PR #89811)

2024-06-10 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> You can debug it by cross-compiling a debug build, then running the unit 
> tests binary and connecting to qemu's built in gdbserver. The Arm toolchain 
> might have a copy of gdb in it already, but if not, gdb multiarch and lldb 
> would also work (which are both installable from apt).
> 
> I'm going to try looking in a debugger myself today.

Ok, this sounds good. I've never thought about that setup and perhaps is just 
fine to suppress that test.

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


[clang] [clang][ExtractAPI][NFC] pass params by const reference (PR #94820)

2024-06-10 Thread Daniel Grumberg via cfe-commits


@@ -199,7 +199,8 @@ class DeclarationFragments {
 return *this;
   }
 
-  DeclarationFragments &replace(std::string NewSpelling, unsigned Position) {

daniel-grumberg wrote:

I would prefer to keep the value semantics version and instead move assign the 
value, that way callers can move the string in and avoid any copies.

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


[clang] [clang][ExtractAPI][NFC] pass params by const reference (PR #94820)

2024-06-10 Thread Daniel Grumberg via cfe-commits


@@ -240,7 +241,7 @@ class DeclarationFragments {
 
 class AccessControl {
 public:
-  AccessControl(std::string Access) : Access(Access) {}

daniel-grumberg wrote:

Again I would prefer if we kept the value semantic ones and use `std::move`

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


[clang] [clang][ExtractAPI][NFC] pass params by const reference (PR #94820)

2024-06-10 Thread Daniel Grumberg via cfe-commits

daniel-grumberg wrote:

Thanks for looking at these, I think it would be best to try and leverage move 
semantics where possible if we are going to change this code.

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


[clang] [clang] SourceLocIdentKind::Function should not be dependent (PR #94942)

2024-06-10 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky created 
https://github.com/llvm/llvm-project/pull/94942

Consider the testcase, return type of `construct_at` is
```cpp
DecltypeType 0x5570d8c0 'decltype(new struct BasicPersistent(declval()))' sugar dependent
|-CXXNewExpr 0x5570d880 'struct BasicPersistent *' Function 0x5570ace0 
'operator new' 'void *(unsigned long)'
| `-CXXConstructExpr 0x5570d848 'struct BasicPersistent' 'void 
(BasicPersistent &&, SourceLocation)'
|   |-CallExpr 0x5570aae8 'BasicPersistent':'struct BasicPersistent' xvalue
|   | `-ImplicitCastExpr 0x5570aad0 'auto (*)(void) -> 
decltype(__declval(0))' 
|   |   `-DeclRefExpr 0x5570aa18 'auto (void) -> decltype(__declval(0))' lvalue Function 0x5570a908 'declval' 'auto (void) -> 
decltype(__declval(0))' (FunctionTemplate 0x556d0548 
'declval') non_odr_use_unevaluated
|   `-CXXDefaultArgExpr 0x5570d820 'SourceLocation':'struct SourceLocation' 
has rewritten init
| `-CallExpr 0x5570d7b0 'SourceLocation':'struct SourceLocation'
|   |-ImplicitCastExpr 0x5570d798 'SourceLocation (*)(const char *)' 

|   | `-DeclRefExpr 0x556fe5c8 'SourceLocation (const char *)' lvalue 
CXXMethod 0x556fdb28 'Current' 'SourceLocation (const char *)'
|   |   `-NestedNameSpecifier TypeSpec 'struct SourceLocation'
|   `-CXXDefaultArgExpr 0x5570d7f8 'const char *' has rewritten init
| `-SourceLocExpr 0x5570d7d8 'const char *'
`-PointerType 0x55704800 'struct BasicPersistent *'
  `-SubstTemplateTypeParmType 0x557047d0 'struct BasicPersistent' sugar 
typename depth 0 index 0 _Tp
|-FunctionTemplate 0x556ee048 'construct_at'
`-RecordType 0x556cfd10 'struct BasicPersistent'
  `-CXXRecord 0x556fdc98 'BasicPersistent'
```
when in the process of instantiation. This type is dependent due to the 
dependency of `SourceLocExpr` which leads to the crash(only crash in codegen 
stage and `clang-check -ast-dump` is OK). `SourceLocExpr` is created in a 
dependent context when transforming the return type of `construct_at` because 
its context(`Sema.CurContext`) is a dependent `FunctionDecl`. But 
`SourceLocExpr` should not be dependent when we finish the transformation.  
Removing `SourceLocIdentKind::Function` makes `SourceLocExpr` independent.
attempt to fix https://github.com/llvm/llvm-project/issues/80210

>From 8ad1b50f267b24693189e3a401d5970308a09f83 Mon Sep 17 00:00:00 2001
From: Qizhi Hu <836744...@qq.com>
Date: Mon, 10 Jun 2024 16:53:54 +0800
Subject: [PATCH] [clang] SourceLocIdentKind::Function should not be dependent

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/AST/Expr.h|  1 -
 clang/test/CodeGenCXX/PR80210.cpp | 34 +++
 3 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/PR80210.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cf1ba02cbc4b2..efe78139de6fa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -846,6 +846,7 @@ Bug Fixes to C++ Support
 - Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
 - Fixed several bugs in capturing variables within unevaluated contexts. 
(#GH63845), (#GH67260), (#GH69307),
   (#GH88081), (#GH89496), (#GH90669) and (#GH91633).
+- Fix a crash when SourceLocExpr instantiated in a dependent context. 
(GH80210).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index f2bf667636dc9..92bd7940bdba9 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -4786,7 +4786,6 @@ class SourceLocExpr final : public Expr {
 
   static bool MayBeDependent(SourceLocIdentKind Kind) {
 switch (Kind) {
-case SourceLocIdentKind::Function:
 case SourceLocIdentKind::FuncSig:
 case SourceLocIdentKind::SourceLocStruct:
   return true;
diff --git a/clang/test/CodeGenCXX/PR80210.cpp 
b/clang/test/CodeGenCXX/PR80210.cpp
new file mode 100644
index 0..fdd3beb99209e
--- /dev/null
+++ b/clang/test/CodeGenCXX/PR80210.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=c++20 %s -emit-llvm -o /dev/null -verify -triple 
%itanium_abi_triple
+// RUN: %clang_cc1 -std=c++20 %s -emit-llvm -o /dev/null -verify -triple 
%ms_abi_triple
+
+// expected-no-diagnostics
+
+struct BasicPersistent;
+template  BasicPersistent &&__declval(int);
+template  auto declval() -> decltype(__declval<_Tp>(0));
+template  _Tp forward;
+template 
+auto construct_at(_Tp *, _Args...) -> decltype(new _Tp(declval<_Args>()...)) 
{return 0;}
+template  struct allocator;
+template  struct allocator_traits;
+template  struct allocator_traits> {
+  using pointer = _Tp *;
+  template 
+  static void construct(_Up __p, _Args...) {
+construct_at(__p, forward<_Args>...);
+  }
+};
+struct __alloc_traits : allocator_traits> {
+} push_back___x;
+__alloc_traits::pointer _M_impl_0;
+template  void emplace_back(_

[clang] [clang] SourceLocIdentKind::Function should not be dependent (PR #94942)

2024-06-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qizhi Hu (jcsxky)


Changes

Consider the testcase, return type of `construct_at` is
```cpp
DecltypeType 0x5570d8c0 'decltype(new struct 
BasicPersistent(declval()))' sugar dependent
|-CXXNewExpr 0x5570d880 'struct BasicPersistent *' Function 0x5570ace0 
'operator new' 'void *(unsigned long)'
| `-CXXConstructExpr 0x5570d848 'struct BasicPersistent' 'void 
(BasicPersistent &&, SourceLocation)'
|   |-CallExpr 0x5570aae8 'BasicPersistent':'struct BasicPersistent' xvalue
|   | `-ImplicitCastExpr 0x5570aad0 'auto (*)(void) -> 
decltype(__declval(0))' 

|   |   `-DeclRefExpr 0x5570aa18 'auto (void) -> 
decltype(__declval(0))' lvalue Function 
0x5570a908 'declval' 'auto (void) -> decltype(__declval(0))' (FunctionTemplate 0x556d0548 'declval') 
non_odr_use_unevaluated
|   `-CXXDefaultArgExpr 0x5570d820 'SourceLocation':'struct SourceLocation' 
has rewritten init
| `-CallExpr 0x5570d7b0 'SourceLocation':'struct SourceLocation'
|   |-ImplicitCastExpr 0x5570d798 'SourceLocation (*)(const char *)' 

|   | `-DeclRefExpr 0x556fe5c8 'SourceLocation (const char *)' lvalue 
CXXMethod 0x556fdb28 'Current' 'SourceLocation (const char *)'
|   |   `-NestedNameSpecifier TypeSpec 'struct SourceLocation'
|   `-CXXDefaultArgExpr 0x5570d7f8 'const char *' has rewritten init
| `-SourceLocExpr 0x5570d7d8 'const char *'
`-PointerType 0x55704800 'struct BasicPersistent *'
  `-SubstTemplateTypeParmType 0x557047d0 'struct BasicPersistent' sugar 
typename depth 0 index 0 _Tp
|-FunctionTemplate 0x556ee048 'construct_at'
`-RecordType 0x556cfd10 'struct BasicPersistent'
  `-CXXRecord 0x556fdc98 'BasicPersistent'
```
when in the process of instantiation. This type is dependent due to the 
dependency of `SourceLocExpr` which leads to the crash(only crash in codegen 
stage and `clang-check -ast-dump` is OK). `SourceLocExpr` is created in a 
dependent context when transforming the return type of `construct_at` because 
its context(`Sema.CurContext`) is a dependent `FunctionDecl`. But 
`SourceLocExpr` should not be dependent when we finish the transformation.  
Removing `SourceLocIdentKind::Function` makes `SourceLocExpr` independent.
attempt to fix https://github.com/llvm/llvm-project/issues/80210

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/AST/Expr.h (-1) 
- (added) clang/test/CodeGenCXX/PR80210.cpp (+34) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cf1ba02cbc4b2..efe78139de6fa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -846,6 +846,7 @@ Bug Fixes to C++ Support
 - Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
 - Fixed several bugs in capturing variables within unevaluated contexts. 
(#GH63845), (#GH67260), (#GH69307),
   (#GH88081), (#GH89496), (#GH90669) and (#GH91633).
+- Fix a crash when SourceLocExpr instantiated in a dependent context. 
(GH80210).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index f2bf667636dc9..92bd7940bdba9 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -4786,7 +4786,6 @@ class SourceLocExpr final : public Expr {
 
   static bool MayBeDependent(SourceLocIdentKind Kind) {
 switch (Kind) {
-case SourceLocIdentKind::Function:
 case SourceLocIdentKind::FuncSig:
 case SourceLocIdentKind::SourceLocStruct:
   return true;
diff --git a/clang/test/CodeGenCXX/PR80210.cpp 
b/clang/test/CodeGenCXX/PR80210.cpp
new file mode 100644
index 0..fdd3beb99209e
--- /dev/null
+++ b/clang/test/CodeGenCXX/PR80210.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=c++20 %s -emit-llvm -o /dev/null -verify -triple 
%itanium_abi_triple
+// RUN: %clang_cc1 -std=c++20 %s -emit-llvm -o /dev/null -verify -triple 
%ms_abi_triple
+
+// expected-no-diagnostics
+
+struct BasicPersistent;
+template  BasicPersistent &&__declval(int);
+template  auto declval() -> decltype(__declval<_Tp>(0));
+template  _Tp forward;
+template 
+auto construct_at(_Tp *, _Args...) -> decltype(new _Tp(declval<_Args>()...)) 
{return 0;}
+template  struct allocator;
+template  struct allocator_traits;
+template  struct allocator_traits> {
+  using pointer = _Tp *;
+  template 
+  static void construct(_Up __p, _Args...) {
+construct_at(__p, forward<_Args>...);
+  }
+};
+struct __alloc_traits : allocator_traits> {
+} push_back___x;
+__alloc_traits::pointer _M_impl_0;
+template  void emplace_back(_Args...) {
+  __alloc_traits::construct(_M_impl_0, forward<_Args>...);
+}
+struct SourceLo

[clang-tools-extra] 415a82c - [clang-tidy] `doesNotMutateObject`: Handle calls to member functions … (#94362)

2024-06-10 Thread via cfe-commits

Author: Clement Courbet
Date: 2024-06-10T11:15:11+02:00
New Revision: 415a82c64afa0047383caf471aa872fdb0e2658d

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

LOG: [clang-tidy] `doesNotMutateObject`: Handle calls to member functions … 
(#94362)

…and operators that have non-const overloads.

This allows  `unnecessary-copy-initialization` to warn on more cases.

The common case is a class with a a set of const/non-sconst overloads
(e.g. std::vector::operator[]).

```
void F() {
  std::vector v;
  // ...

  const Expensive e = v[i];
}
```

Added: 


Modified: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp 
b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
index 9beb185cba929..61240fa4b0eb8 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -75,16 +75,16 @@ void recordRemoval(const DeclStmt &Stmt, ASTContext 
&Context,
   }
 }
 
-AST_MATCHER_FUNCTION_P(StatementMatcher, isConstRefReturningMethodCall,
+AST_MATCHER_FUNCTION_P(StatementMatcher,
+   isRefReturningMethodCallWithConstOverloads,
std::vector, ExcludedContainerTypes) {
   // Match method call expressions where the `this` argument is only used as
-  // const, this will be checked in `check()` part. This returned const
-  // reference is highly likely to outlive the local const reference of the
-  // variable being declared. The assumption is that the const reference being
-  // returned either points to a global static variable or to a member of the
-  // called object.
+  // const, this will be checked in `check()` part. This returned reference is
+  // highly likely to outlive the local const reference of the variable being
+  // declared. The assumption is that the reference being returned either 
points
+  // to a global static variable or to a member of the called object.
   const auto MethodDecl =
-  cxxMethodDecl(returns(hasCanonicalType(matchers::isReferenceToConst(
+  cxxMethodDecl(returns(hasCanonicalType(referenceType(
   .bind(MethodDeclId);
   const auto ReceiverExpr =
   ignoringParenImpCasts(declRefExpr(to(varDecl().bind(ObjectArgId;
@@ -121,7 +121,7 @@ AST_MATCHER_FUNCTION_P(StatementMatcher, 
initializerReturnsReferenceToConst,
   declRefExpr(to(varDecl(hasLocalStorage()).bind(OldVarDeclId)));
   return expr(
   anyOf(isConstRefReturningFunctionCall(),
-isConstRefReturningMethodCall(ExcludedContainerTypes),
+isRefReturningMethodCallWithConstOverloads(ExcludedContainerTypes),
 ignoringImpCasts(OldVarDeclRef),
 ignoringImpCasts(unaryOperator(hasOperatorName("&"),
hasUnaryOperand(OldVarDeclRef);
@@ -259,10 +259,11 @@ void 
UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
 .bind("blockStmt");
   };
 
-  
Finder->addMatcher(LocalVarCopiedFrom(anyOf(isConstRefReturningFunctionCall(),
-  isConstRefReturningMethodCall(
-  ExcludedContainerTypes))),
- this);
+  Finder->addMatcher(
+  LocalVarCopiedFrom(anyOf(
+  isConstRefReturningFunctionCall(),
+  isRefReturningMethodCallWithConstOverloads(ExcludedContainerTypes))),
+  this);
 
   Finder->addMatcher(LocalVarCopiedFrom(declRefExpr(
  to(varDecl(hasLocalStorage()).bind(OldVarDeclId,

diff  --git a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp 
b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
index a48e45e135681..a6062ccf42230 100644
--- a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -36,6 +36,116 @@ void extractNodesByIdTo(ArrayRef Matches, 
StringRef ID,
 Nodes.insert(Match.getNodeAs(ID));
 }
 
+// Returns true if both types refer to the same type,
+// ignoring the const-qualifier.
+bool isSameTypeIgnoringConst(QualType A, QualType B) {
+  A = A.getCanonicalType();
+  B = B.getCanonicalType();
+  A.addConst();
+  B.addConst();
+  return A == B;
+}
+
+// Returns true if `D` and `O` have the same parameter types.
+bool hasSameParameterTypes(const CXXMethodDecl &

[clang-tools-extra] [clang-tidy] `doesNotMutateObject`: Handle calls to member functions … (PR #94362)

2024-06-10 Thread Clement Courbet via cfe-commits

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


[clang] [Driver] Add winsysroot alias to the GNU driver (PR #94731)

2024-06-10 Thread via cfe-commits

https://github.com/Andarwinux updated 
https://github.com/llvm/llvm-project/pull/94731

>From ed7aebc1362e20661283592fc1034224b645420e Mon Sep 17 00:00:00 2001
From: Andarwinux <144242044+andarwi...@users.noreply.github.com>
Date: Fri, 7 Jun 2024 07:07:40 +
Subject: [PATCH] [Driver] Add winsysroot alias to the GNU driver

fixes #91216
---
 clang/include/clang/Driver/Options.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..1cce7a5146dd8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8569,6 +8569,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">,
 Alias<_SLASH_winsdkdir>;
 def : Separate<["-"], "Xmicrosoft-windows-sdk-version">,
 Alias<_SLASH_winsdkversion>;
+def : Separate<["-"], "Xmicrosoft-windows-sys-root">,
+Alias<_SLASH_winsysroot>;
 
 // Ignored:
 

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


[clang] [clang] Implement -Wmissing-include-dirs (PR #94827)

2024-06-10 Thread via cfe-commits


@@ -809,4 +809,7 @@ def warn_android_unversioned_fallback : Warning<
 
 def err_drv_triple_version_invalid : Error<
   "version '%0' in target triple '%1' is invalid">;
+
+def warn_missing_include_dirs : Warning <

zmodem wrote:

nit: no space between `Warning` and `<`, and two spaces for indentation on the 
next line

This makes the warning enabled by default. I'm not sure whether that's 
desirable. Maybe it should be under `-Wall` or `-Wextra` (what does gcc do?)

To achieve that, add the `DefaultIgnore` mark to this definition, and add 
`InGroup` or `Extra` to the `DiagGroup` definition.

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


[clang] [clang] Implement -Wmissing-include-dirs (PR #94827)

2024-06-10 Thread via cfe-commits


@@ -1271,6 +1271,12 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 if (VFS->setCurrentWorkingDirectory(WD->getValue()))
   Diag(diag::err_drv_unable_to_set_working_directory) << WD->getValue();
 
+  // Check for missing include directories

zmodem wrote:

nit: period at the end

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


[clang] [clang] Implement -Wmissing-include-dirs (PR #94827)

2024-06-10 Thread via cfe-commits

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


[clang] [clang] Implement -Wmissing-include-dirs (PR #94827)

2024-06-10 Thread via cfe-commits

https://github.com/zmodem commented:

Thanks! The main missing thing is a test for this. Have a look in 
`clang/test/Driver/` to see what the tests can look like.

---

Some existing tests are failing, see 
https://buildkite.com/llvm-project/github-pull-requests/builds/70953#018ff782-9ba1-426b-bb3e-7c0e93533ba4

For example it seems clang/test/Frontend/warning-poison-system-directories.c is 
failing because it builds with -Werror and passes -I flags with directories 
that don't exist on Windows.

clang/test/Driver/cl-pch.c also failed, but it's not clear to me why.

Maybe if the flag is not enabled by default, these test failures will go away.

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


[clang] [clang] Implement -Wmissing-include-dirs (PR #94827)

2024-06-10 Thread via cfe-commits


@@ -1271,6 +1271,12 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
 if (VFS->setCurrentWorkingDirectory(WD->getValue()))
   Diag(diag::err_drv_unable_to_set_working_directory) << WD->getValue();
 
+  // Check for missing include directories
+  for (auto IncludeDir : Args.getAllArgValues(options::OPT_I_Group)) {
+if (!llvm::sys::fs::is_directory(IncludeDir))

zmodem wrote:

I think we should go through the VFS here, something like 
`VFS.exist(IncludeDir)`

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


[clang] ae9d89d - [Clang][C++23] update constexpr diagnostics for missing return statements per P2448 (#94123)

2024-06-10 Thread via cfe-commits

Author: Oleksandr T
Date: 2024-06-10T11:58:56+02:00
New Revision: ae9d89d53e64bad514171c99f16d553febfbac12

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

LOG: [Clang][C++23] update constexpr diagnostics for missing return statements 
per P2448 (#94123)

Fixes #92583

Added: 
clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp

Modified: 
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
clang/test/SemaCXX/constant-expression-cxx14.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e224e79fdb8ea..37f0df2a6a27d 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1806,6 +1806,7 @@ static unsigned getRecordDiagFromTagKind(TagTypeKind Tag) 
{
 static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl,
Stmt *Body,
Sema::CheckConstexprKind Kind);
+static bool CheckConstexprMissingReturn(Sema &SemaRef, const FunctionDecl 
*Dcl);
 
 // Check whether a function declaration satisfies the requirements of a
 // constexpr function definition or a constexpr constructor definition. If so,
@@ -2411,20 +2412,9 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, 
const FunctionDecl *Dcl,
 }
   } else {
 if (ReturnStmts.empty()) {
-  // C++1y doesn't require constexpr functions to contain a 'return'
-  // statement. We still do, unless the return type might be void, because
-  // otherwise if there's no return statement, the function cannot
-  // be used in a core constant expression.
-  bool OK = SemaRef.getLangOpts().CPlusPlus14 &&
-(Dcl->getReturnType()->isVoidType() ||
- Dcl->getReturnType()->isDependentType());
   switch (Kind) {
   case Sema::CheckConstexprKind::Diagnose:
-SemaRef.Diag(Dcl->getLocation(),
- OK ? diag::warn_cxx11_compat_constexpr_body_no_return
-: diag::err_constexpr_body_no_return)
-<< Dcl->isConsteval();
-if (!OK)
+if (!CheckConstexprMissingReturn(SemaRef, Dcl))
   return false;
 break;
 
@@ -2494,6 +2484,28 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, 
const FunctionDecl *Dcl,
   return true;
 }
 
+static bool CheckConstexprMissingReturn(Sema &SemaRef,
+const FunctionDecl *Dcl) {
+  bool IsVoidOrDependentType = Dcl->getReturnType()->isVoidType() ||
+   Dcl->getReturnType()->isDependentType();
+  // Skip emitting a missing return error diagnostic for non-void functions
+  // since C++23 no longer mandates constexpr functions to yield constant
+  // expressions.
+  if (SemaRef.getLangOpts().CPlusPlus23 && !IsVoidOrDependentType)
+return true;
+
+  // C++14 doesn't require constexpr functions to contain a 'return'
+  // statement. We still do, unless the return type might be void, because
+  // otherwise if there's no return statement, the function cannot
+  // be used in a core constant expression.
+  bool OK = SemaRef.getLangOpts().CPlusPlus14 && IsVoidOrDependentType;
+  SemaRef.Diag(Dcl->getLocation(),
+   OK ? diag::warn_cxx11_compat_constexpr_body_no_return
+  : diag::err_constexpr_body_no_return)
+  << Dcl->isConsteval();
+  return OK;
+}
+
 bool Sema::CheckImmediateEscalatingFunctionDefinition(
 FunctionDecl *FD, const sema::FunctionScopeInfo *FSI) {
   if (!getLangOpts().CPlusPlus20 || !FD->isImmediateEscalating())

diff  --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp 
b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
index 4416c82522649..51990ee4341d2 100644
--- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
@@ -212,7 +212,7 @@ constexpr int ClassDecl3() {
   return 0;
 }
 
-constexpr int NoReturn() {} // expected-error {{no return statement in 
constexpr function}}
+constexpr int NoReturn() {} // beforecxx23-error {{no return statement in 
constexpr function}}
 constexpr int MultiReturn() {
   return 0; // beforecxx14-note {{return statement}}
   return 0; // beforecxx14-warning {{multiple return statements in constexpr 
function}}

diff  --git a/clang/test/SemaCXX/constant-expression-cxx14.cpp 
b/clang/test/SemaCXX/constant-expression-cxx14.cpp
index 80a7a2dd31531..70ab5dcd357c1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx14.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx14.cpp
@@ -82,7 +82,7 @@ constexpr void k() {
 
 // If the return type is not 'void', no return statements => never a constant
 // expression, so still diagnose that case.
-[[noreturn]

[clang] [Clang][C++23] update constexpr diagnostics for missing return statements per P2448 (PR #94123)

2024-06-10 Thread Timm Baeder via cfe-commits

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


[clang] [llvm] [AArch64] set AppleA14 architecture version to v8.4-a (PR #92600)

2024-06-10 Thread Tomas Matheson via cfe-commits

https://github.com/tmatheson-arm updated 
https://github.com/llvm/llvm-project/pull/92600

>From 518b83ab69c4852f7e7ea71c17df3f58e8ff50ef Mon Sep 17 00:00:00 2001
From: Tomas Matheson 
Date: Fri, 17 May 2024 21:39:17 +0100
Subject: [PATCH 1/5] [AArch64] set AppleA14 architecture version to 8.5

---
 llvm/lib/Target/AArch64/AArch64Processors.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AArch64/AArch64Processors.td 
b/llvm/lib/Target/AArch64/AArch64Processors.td
index f2286ae17dba5..96422758bc618 100644
--- a/llvm/lib/Target/AArch64/AArch64Processors.td
+++ b/llvm/lib/Target/AArch64/AArch64Processors.td
@@ -718,7 +718,7 @@ def ProcessorFeatures {
   list AppleA13 = [HasV8_4aOps, FeatureCrypto, 
FeatureFPARMv8,
  FeatureNEON, FeaturePerfMon, 
FeatureFullFP16,
  FeatureFP16FML, FeatureSHA3];
-  list AppleA14 = [HasV8_4aOps, FeatureCrypto, 
FeatureFPARMv8,
+  list AppleA14 = [HasV8_5aOps, FeatureCrypto, 
FeatureFPARMv8,
  FeatureNEON, FeaturePerfMon, 
FeatureFRInt3264,
  FeatureSpecRestrict, FeatureSSBS, 
FeatureSB,
  FeaturePredRes, FeatureCacheDeepPersist,

>From 74f6d426fa67b1f794a8ba2ac7c864830ee9c2b2 Mon Sep 17 00:00:00 2001
From: Tomas Matheson 
Date: Mon, 20 May 2024 12:38:52 +0100
Subject: [PATCH 2/5] make m1+a14 v8.4 instead

---
 clang/lib/Basic/Targets/AArch64.cpp|  4 +++-
 clang/test/Driver/aarch64-mac-cpus.c   |  2 +-
 clang/test/Preprocessor/aarch64-target-features.c  |  8 +++-
 .../llvm/TargetParser/AArch64TargetParser.h|  4 ++--
 llvm/lib/Target/AArch64/AArch64Processors.td   | 14 +-
 llvm/test/DebugInfo/debug_frame_symbol.ll  |  2 +-
 .../AddressSanitizer/calls-only-smallfn.ll |  2 +-
 .../Instrumentation/AddressSanitizer/calls-only.ll |  2 +-
 llvm/unittests/TargetParser/TargetParserTest.cpp   |  8 
 9 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 5db1ce78c657f..692ec58235efe 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -286,7 +286,6 @@ void AArch64TargetInfo::getTargetDefinesARMV84A(const 
LangOptions &Opts,
 void AArch64TargetInfo::getTargetDefinesARMV85A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_FRINT", "1");
-  Builder.defineMacro("__ARM_FEATURE_BTI", "1");
   // Also include the Armv8.4 defines
   getTargetDefinesARMV84A(Opts, Builder);
 }
@@ -499,6 +498,9 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasPAuthLR)
 Builder.defineMacro("__ARM_FEATURE_PAUTH_LR", "1");
 
+  if (HasBTI)
+Builder.defineMacro("__ARM_FEATURE_BTI", "1");
+
   if (HasUnalignedAccess)
 Builder.defineMacro("__ARM_FEATURE_UNALIGNED", "1");
 
diff --git a/clang/test/Driver/aarch64-mac-cpus.c 
b/clang/test/Driver/aarch64-mac-cpus.c
index 5179731268950..488298cfd2d24 100644
--- a/clang/test/Driver/aarch64-mac-cpus.c
+++ b/clang/test/Driver/aarch64-mac-cpus.c
@@ -16,7 +16,7 @@
 // RUN: %clang --target=arm64-apple-macos -mcpu=apple-m1 -### -c %s 2>&1 | 
FileCheck --check-prefix=EXPLICIT-M1 %s
 
 // CHECK: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "apple-m1"
-// CHECK-SAME: "-target-feature" "+v8.5a"
+// CHECK-SAME: "-target-feature" "+v8.4a"
 
 // EXPLICIT-A11: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "apple-a11"
 // EXPLICIT-A7: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "apple-a7"
diff --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index 82304a15a04a3..3f2c2929c7129 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -335,7 +335,7 @@
 // CHECK-MCPU-CARMEL: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-feature" 
"+v8.2a" "-target-feature" "+aes" "-target-feature" "+crc" "-target-feature" 
"+fp-armv8" "-target-feature" "+fullfp16" "-target-feature" "+lse" 
"-target-feature" "+ras" "-target-feature" "+rdm" "-target-feature" "+sha2" 
"-target-feature" "+neon"
 
 // RUN: %clang -target x86_64-apple-macosx -arch arm64 -### -c %s 2>&1 | 
FileCheck --check-prefix=CHECK-ARCH-ARM64 %s
-// CHECK-ARCH-ARM64: "-target-cpu" "apple-m1" "-target-feature" "+zcm" 
"-target-feature" "+zcz" "-target-feature" "+v8.5a" "-target-feature" "+aes" 
"-target-feature" "+crc" "-target-feature" "+dotprod" "-target-feature" 
"+complxnum" "-target-feature" "+fp-armv8" "-target-feature" "+fullfp16" 
"-target-feature" "+fp16fml" "-target-feature" "+jsconv" "-target-feature" 
"+lse" "-target-feature" "+pauth" "-target-feature" "+ras" "-target-feature" 
"+rcpc" "-target-feature" "+rdm" "-target-feature" "+sha2" "-

[clang] [llvm] [AArch64] Decouple feature dependency expansion. (PR #94279)

2024-06-10 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/94279

>From a413428bb0fdcd45b4a251e385b6cc00ff6a0a2c Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Mon, 3 Jun 2024 19:57:49 +0100
Subject: [PATCH 1/4] [AArch64] Decouple feature dependency expansion.

The dependency expansion step which was introduced by FMV has been
erroneously used for non-FMV features, for example when parsing the
target attribute. The PR #93695 has rectified most of the tests which
were relying on dependency expansion of target features specified on
the -cc1 command line. In this patch I am decoupling the dependency
expansion of features specified on the target attribute from FMV.

To do that first I am expanding FMV dependencies before passing the
list of target features to initFeatureMap(). Similarly when parsing
the target attribute I am reconstructing an ExtensionSet from the
list of target features which was created during the command line
option parsing. The attribute parsing may toggle bits of that
ExtensionSet and at the end it is converted to a list of target
features. Those are passed to initFeatureMap(), which no longer
requires an override.

A side effect of this refactoring is that features specified on the
target_version attribute now supersede the command line options,
which is what should be happening in the first place.
---
 clang/include/clang/AST/ASTContext.h  |   3 -
 clang/lib/AST/ASTContext.cpp  |  53 -
 clang/lib/Basic/Targets/AArch64.cpp   |  99 +
 clang/lib/Basic/Targets/AArch64.h |   4 -
 .../CodeGen/aarch64-cpu-supports-target.c |   2 +-
 .../aarch64-sme-attrs.cpp |   2 +-
 clang/test/CodeGen/aarch64-targetattr.c   |  41 ---
 clang/test/CodeGen/attr-target-version.c  |  46 
 clang/test/Sema/aarch64-neon-target.c |   4 +-
 clang/test/Sema/builtin-cpu-supports.c|   2 +-
 .../llvm/TargetParser/AArch64TargetParser.h   | 104 +++---
 llvm/lib/Target/AArch64/AArch64Features.td|   2 +-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  53 ++---
 13 files changed, 201 insertions(+), 214 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a1d1d1c51cd41..8bce4812f0d48 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -3203,9 +3203,6 @@ class ASTContext : public RefCountedBase {
   /// valid feature names.
   ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD) const;
 
-  std::vector
-  filterFunctionTargetVersionAttrs(const TargetVersionAttr *TV) const;
-
   void getFunctionFeatureMap(llvm::StringMap &FeatureMap,
  const FunctionDecl *) const;
   void getFunctionFeatureMap(llvm::StringMap &FeatureMap,
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 73d3b152c49f1..6b7cfbe48796a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -87,6 +87,7 @@
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 #include 
@@ -13663,17 +13664,18 @@ QualType 
ASTContext::getCorrespondingSignedFixedPointType(QualType Ty) const {
   }
 }
 
-std::vector ASTContext::filterFunctionTargetVersionAttrs(
-const TargetVersionAttr *TV) const {
-  assert(TV != nullptr);
-  llvm::SmallVector Feats;
-  std::vector ResFeats;
-  TV->getFeatures(Feats);
-  for (auto &Feature : Feats)
-if (Target->validateCpuSupports(Feature.str()))
-  // Use '?' to mark features that came from TargetVersion.
-  ResFeats.push_back("?" + Feature.str());
-  return ResFeats;
+// Given a list of FMV features, add each of their backend features to the 
list.
+static void
+getFMVBackendFeaturesFor(const llvm::SmallVectorImpl 
&FMVFeatStrings,
+ std::vector &BackendFeats) {
+  for (StringRef F : FMVFeatStrings) {
+if (auto FMVExt = llvm::AArch64::parseArchExtension(F)) {
+  SmallVector Feats;
+  FMVExt->DependentFeatures.split(Feats, ',', -1, false);
+  for (StringRef F : Feats)
+BackendFeats.push_back(F.str());
+}
+  }
 }
 
 ParsedTargetAttr
@@ -13708,10 +13710,12 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
 
 // Make a copy of the features as passed on the command line into the
 // beginning of the additional features from the function to override.
-ParsedAttr.Features.insert(
-ParsedAttr.Features.begin(),
-Target->getTargetOpts().FeaturesAsWritten.begin(),
-Target->getTargetOpts().FeaturesAsWritten.end());
+// AArch64 handles command line option features in parseTargetAttr().
+if (!Target->getTriple().isAArch64())
+  ParsedAttr.Features.insert(
+  ParsedAttr.Features.begin(),
+ 

[clang] [clang] SourceLocIdentKind::Function should not be dependent (PR #94942)

2024-06-10 Thread Timm Baeder via cfe-commits


@@ -846,6 +846,7 @@ Bug Fixes to C++ Support
 - Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
 - Fixed several bugs in capturing variables within unevaluated contexts. 
(#GH63845), (#GH67260), (#GH69307),
   (#GH88081), (#GH89496), (#GH90669) and (#GH91633).
+- Fix a crash when SourceLocExpr instantiated in a dependent context. 
(GH80210).

tbaederr wrote:

```suggestion
- Fix a crash when SourceLocExpr instantiated in a dependent context. 
(#GH80210).
```

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


[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer created 
https://github.com/llvm/llvm-project/pull/94956

CGDebugInfo::EmitPseudoVariable currently uses detailed logic to exactly 
collect llvm.dbg.declare users of an alloca. This patch replaces this with an 
LLVM function for finding debug declares intrinsics and also adds the same for 
debug records, simplifying the code and adding record support.

No tests added in this commit because it is NFC for intrinsics, and there is no 
way to make clang emit records directly yet - one of the existing tests however 
will switch to covering debug records once 
https://github.com/llvm/llvm-project/pull/89799 relands.

>From 56109f5f411523967ffef5a32a507d6472eebdaf Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Mon, 10 Jun 2024 11:35:02 +0100
Subject: [PATCH] [Clang] Extend EmitPseudoVariable to support debug records

CGDebugInfo::EmitPseudoVariable currently uses detailed logic to exactly
collect llvm.dbg.declare users of an alloca. This patch replaces this
with an LLVM function for finding debug declares intrinsics and also adds
the same for debug records, simplifying the code and adding record
support.
---
 clang/lib/CodeGen/CGDebugInfo.cpp | 32 ++-
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 681a475f9e4be..d5676be0e8742 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5766,28 +5766,16 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy 
&Builder,
   // it is loaded upon use, so we identify such pattern here.
   if (llvm::LoadInst *Load = dyn_cast(Value)) {
 llvm::Value *Var = Load->getPointerOperand();
-if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) {
-  if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists(
-  CGM.getLLVMContext(), MDValue)) {
-for (llvm::User *U : DbgValue->users()) {
-  if (llvm::CallInst *DbgDeclare = dyn_cast(U)) {
-if (DbgDeclare->getCalledFunction()->getIntrinsicID() ==
-llvm::Intrinsic::dbg_declare &&
-DbgDeclare->getArgOperand(0) == DbgValue) {
-  // There can be implicit type cast applied on a variable if it is
-  // an opaque ptr, in this case its debug info may not match the
-  // actual type of object being used as in the next instruction, 
so
-  // we will need to emit a pseudo variable for type-casted value.
-  llvm::DILocalVariable *MDNode = cast(
-  cast(DbgDeclare->getOperand(1))
-  ->getMetadata());
-  if (MDNode->getType() == Type)
-return;
-}
-  }
-}
-  }
-}
+// There can be implicit type cast applied on a variable if it is an opaque
+// ptr, in this case its debug info may not match the actual type of object
+// being used as in the next instruction, so we will need to emit a pseudo
+// variable for type-casted value.
+auto DeclareTypeMatches = [&](auto *DbgDeclare) {
+  return DbgDeclare->getVariable()->getType() == Type;
+};
+if (any_of(llvm::findDbgDeclares(Var), DeclareMatches) ||
+any_of(llvm::findDVRDeclares(Var), DeclareMatches))
+  return;
   }
 
   // Find the correct location to insert a sequence of instructions to

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


[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Stephen Tozer (SLTozer)


Changes

CGDebugInfo::EmitPseudoVariable currently uses detailed logic to exactly 
collect llvm.dbg.declare users of an alloca. This patch replaces this with an 
LLVM function for finding debug declares intrinsics and also adds the same for 
debug records, simplifying the code and adding record support.

No tests added in this commit because it is NFC for intrinsics, and there is no 
way to make clang emit records directly yet - one of the existing tests however 
will switch to covering debug records once 
https://github.com/llvm/llvm-project/pull/89799 relands.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+10-22) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 681a475f9e4be..d5676be0e8742 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5766,28 +5766,16 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy 
&Builder,
   // it is loaded upon use, so we identify such pattern here.
   if (llvm::LoadInst *Load = dyn_cast(Value)) {
 llvm::Value *Var = Load->getPointerOperand();
-if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) {
-  if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists(
-  CGM.getLLVMContext(), MDValue)) {
-for (llvm::User *U : DbgValue->users()) {
-  if (llvm::CallInst *DbgDeclare = dyn_cast(U)) {
-if (DbgDeclare->getCalledFunction()->getIntrinsicID() ==
-llvm::Intrinsic::dbg_declare &&
-DbgDeclare->getArgOperand(0) == DbgValue) {
-  // There can be implicit type cast applied on a variable if it is
-  // an opaque ptr, in this case its debug info may not match the
-  // actual type of object being used as in the next instruction, 
so
-  // we will need to emit a pseudo variable for type-casted value.
-  llvm::DILocalVariable *MDNode = cast(
-  cast(DbgDeclare->getOperand(1))
-  ->getMetadata());
-  if (MDNode->getType() == Type)
-return;
-}
-  }
-}
-  }
-}
+// There can be implicit type cast applied on a variable if it is an opaque
+// ptr, in this case its debug info may not match the actual type of object
+// being used as in the next instruction, so we will need to emit a pseudo
+// variable for type-casted value.
+auto DeclareTypeMatches = [&](auto *DbgDeclare) {
+  return DbgDeclare->getVariable()->getType() == Type;
+};
+if (any_of(llvm::findDbgDeclares(Var), DeclareMatches) ||
+any_of(llvm::findDVRDeclares(Var), DeclareMatches))
+  return;
   }
 
   // Find the correct location to insert a sequence of instructions to

``




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


[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Stephen Tozer (SLTozer)


Changes

CGDebugInfo::EmitPseudoVariable currently uses detailed logic to exactly 
collect llvm.dbg.declare users of an alloca. This patch replaces this with an 
LLVM function for finding debug declares intrinsics and also adds the same for 
debug records, simplifying the code and adding record support.

No tests added in this commit because it is NFC for intrinsics, and there is no 
way to make clang emit records directly yet - one of the existing tests however 
will switch to covering debug records once 
https://github.com/llvm/llvm-project/pull/89799 relands.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+10-22) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 681a475f9e4be..d5676be0e8742 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5766,28 +5766,16 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy 
&Builder,
   // it is loaded upon use, so we identify such pattern here.
   if (llvm::LoadInst *Load = dyn_cast(Value)) {
 llvm::Value *Var = Load->getPointerOperand();
-if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) {
-  if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists(
-  CGM.getLLVMContext(), MDValue)) {
-for (llvm::User *U : DbgValue->users()) {
-  if (llvm::CallInst *DbgDeclare = dyn_cast(U)) {
-if (DbgDeclare->getCalledFunction()->getIntrinsicID() ==
-llvm::Intrinsic::dbg_declare &&
-DbgDeclare->getArgOperand(0) == DbgValue) {
-  // There can be implicit type cast applied on a variable if it is
-  // an opaque ptr, in this case its debug info may not match the
-  // actual type of object being used as in the next instruction, 
so
-  // we will need to emit a pseudo variable for type-casted value.
-  llvm::DILocalVariable *MDNode = cast(
-  cast(DbgDeclare->getOperand(1))
-  ->getMetadata());
-  if (MDNode->getType() == Type)
-return;
-}
-  }
-}
-  }
-}
+// There can be implicit type cast applied on a variable if it is an opaque
+// ptr, in this case its debug info may not match the actual type of object
+// being used as in the next instruction, so we will need to emit a pseudo
+// variable for type-casted value.
+auto DeclareTypeMatches = [&](auto *DbgDeclare) {
+  return DbgDeclare->getVariable()->getType() == Type;
+};
+if (any_of(llvm::findDbgDeclares(Var), DeclareMatches) ||
+any_of(llvm::findDVRDeclares(Var), DeclareMatches))
+  return;
   }
 
   // Find the correct location to insert a sequence of instructions to

``




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


[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-debuginfo

Author: Stephen Tozer (SLTozer)


Changes

CGDebugInfo::EmitPseudoVariable currently uses detailed logic to exactly 
collect llvm.dbg.declare users of an alloca. This patch replaces this with an 
LLVM function for finding debug declares intrinsics and also adds the same for 
debug records, simplifying the code and adding record support.

No tests added in this commit because it is NFC for intrinsics, and there is no 
way to make clang emit records directly yet - one of the existing tests however 
will switch to covering debug records once 
https://github.com/llvm/llvm-project/pull/89799 relands.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+10-22) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 681a475f9e4be..d5676be0e8742 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5766,28 +5766,16 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy 
&Builder,
   // it is loaded upon use, so we identify such pattern here.
   if (llvm::LoadInst *Load = dyn_cast(Value)) {
 llvm::Value *Var = Load->getPointerOperand();
-if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) {
-  if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists(
-  CGM.getLLVMContext(), MDValue)) {
-for (llvm::User *U : DbgValue->users()) {
-  if (llvm::CallInst *DbgDeclare = dyn_cast(U)) {
-if (DbgDeclare->getCalledFunction()->getIntrinsicID() ==
-llvm::Intrinsic::dbg_declare &&
-DbgDeclare->getArgOperand(0) == DbgValue) {
-  // There can be implicit type cast applied on a variable if it is
-  // an opaque ptr, in this case its debug info may not match the
-  // actual type of object being used as in the next instruction, 
so
-  // we will need to emit a pseudo variable for type-casted value.
-  llvm::DILocalVariable *MDNode = cast(
-  cast(DbgDeclare->getOperand(1))
-  ->getMetadata());
-  if (MDNode->getType() == Type)
-return;
-}
-  }
-}
-  }
-}
+// There can be implicit type cast applied on a variable if it is an opaque
+// ptr, in this case its debug info may not match the actual type of object
+// being used as in the next instruction, so we will need to emit a pseudo
+// variable for type-casted value.
+auto DeclareTypeMatches = [&](auto *DbgDeclare) {
+  return DbgDeclare->getVariable()->getType() == Type;
+};
+if (any_of(llvm::findDbgDeclares(Var), DeclareMatches) ||
+any_of(llvm::findDVRDeclares(Var), DeclareMatches))
+  return;
   }
 
   // Find the correct location to insert a sequence of instructions to

``




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


[clang] [clang] SourceLocIdentKind::Function should not be dependent (PR #94942)

2024-06-10 Thread via cfe-commits

cor3ntin wrote:

SourceLocation needs to be dependent because we want to make the name of the 
function and any template parameter
refers to the instantiated function rather than that of the function template.
This was changed in https://github.com/llvm/llvm-project/pull/78436 

The issue is that SourceLocation then is a dependent expression that does not 
depend on any parameters and its never re-transformed (hence the crash).

I have so far been unable to find a solution. I wonder if we should attach the 
template parameters to the source location expression, but that seems a bit 
involved.



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


[clang] [clang-format] Add option to remove leading blank lines (PR #91221)

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


@@ -208,6 +208,9 @@ RawStringFormatStyleManager::RawStringFormatStyleManager(
   LanguageStyle = PredefinedStyle;
 }
 LanguageStyle->ColumnLimit = CodeStyle.ColumnLimit;
+// This way the first line of the string does not have to follow the code
+// before the string.
+LanguageStyle->KeepEmptyLines.AtStartOfFile = true;

HazardyKnusperkeks wrote:

Why exactly is this necessary?

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


[clang] [analyzer] Add an ownership change visitor to StreamChecker (PR #94957)

2024-06-10 Thread Kristóf Umann via cfe-commits

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

This is very similar to https://reviews.llvm.org/D105553, in fact, I barely 
made any changes from MallocChecker's ownership visitor to this one.

The new visitor emits a diagnostic note for function where a change in stream 
ownership was expected (for example, it had a fclose() call), but the ownership 
remained unchanged. This is similar to messages regarding ordinary values 
("Returning without writing to x").

Change-Id: I7621c178dd35713d860d27bfc644fb56a42b0946

From faf00d0e1286e053ba9fb457513bd8309eb541ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Krist=C3=B3f=20Umann?= 
Date: Fri, 7 Jun 2024 12:07:35 +0200
Subject: [PATCH] [analyzer] Add an ownership change visitor to StreamChecker

This is very similar to https://reviews.llvm.org/D105553, in fact, I
barely made any changes from MallocChecker's ownership visitor to this
one.

The new visitor emits a diagnostic note for function where a change in
stream ownership was expected (for example, it had a fclose() call), but
the ownership remained unchanged. This is similar to messages regarding
ordinary values ("Returning without writing to x").

Change-Id: I7621c178dd35713d860d27bfc644fb56a42b0946
---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 106 ++-
 clang/test/Analysis/stream-visitor.cpp| 179 ++
 2 files changed, 282 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Analysis/stream-visitor.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index d4e020f7a72a0..d726ab5eaa599 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -10,6 +10,9 @@
 //
 
//===--===//
 
+#include "NoOwnershipChangeVisitor.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -74,6 +77,12 @@ struct StreamErrorState {
   /// Returns if the StreamErrorState is a valid object.
   operator bool() const { return NoError || FEof || FError; }
 
+  LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
+  LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &os) const {
+os << "NoError: " << NoError << ", FEof: " << FEof
+   << ", FError: " << FError;
+  }
+
   void Profile(llvm::FoldingSetNodeID &ID) const {
 ID.AddBoolean(NoError);
 ID.AddBoolean(FEof);
@@ -98,6 +107,19 @@ struct StreamState {
 OpenFailed /// The last open operation has failed.
   } State;
 
+  StringRef getKindStr() const {
+switch (State) {
+case Opened:
+  return "Opened";
+case Closed:
+  return "Closed";
+case OpenFailed:
+  return "OpenFailed";
+default:
+  llvm_unreachable("Unknown StreamState!");
+}
+  }
+
   /// State of the error flags.
   /// Ignored in non-opened stream state but must be NoError.
   StreamErrorState const ErrorState;
@@ -146,6 +168,9 @@ struct StreamState {
 return StreamState{L, OpenFailed, {}, false};
   }
 
+  LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
+  LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &os) const;
+
   void Profile(llvm::FoldingSetNodeID &ID) const {
 ID.AddPointer(LastOperation);
 ID.AddInteger(State);
@@ -168,8 +193,9 @@ REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, 
StreamState)
 namespace {
 
 class StreamChecker;
-using FnCheck = std::function;
+using FnCheckTy = void(const StreamChecker *, const FnDescription *,
+   const CallEvent &, CheckerContext &);
+using FnCheck = std::function;
 
 using ArgNoTy = unsigned int;
 static const ArgNoTy ArgNone = std::numeric_limits::max();
@@ -183,6 +209,14 @@ struct FnDescription {
   ArgNoTy StreamArgNo;
 };
 
+LLVM_DUMP_METHOD void StreamState::dumpToStream(llvm::raw_ostream &os) const {
+  os << "{Kind: " << getKindStr() << ", Last operation: " << LastOperation
+ << ", ErrorState: ";
+  ErrorState.dumpToStream(os);
+  os << ", FilePos: " << (FilePositionIndeterminate ? "Indeterminate" : "OK")
+ << '}';
+}
+
 /// Get the value of the stream argument out of the passed call event.
 /// The call should contain a function that is described by Desc.
 SVal getStreamArg(const FnDescription *Desc, const CallEvent &Call) {
@@ -300,6 +334,8 @@ class StreamChecker : public Checker FnDescriptions = {
   {{CDM::CLibrary, {"fopen"}, 2},
@@ -310,7 +346,7 @@ class StreamChecker : public Checker(&Checker);
+if (StreamChk->FCloseDesc.matchesAsWritten(Call))
+  return true;
+
+return false;
+  }
+
+  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+ ASTContext &ACtx

[clang] [analyzer] Add an ownership change visitor to StreamChecker (PR #94957)

2024-06-10 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

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

Author: Kristóf Umann (Szelethus)


Changes

This is very similar to https://reviews.llvm.org/D105553, in fact, I barely 
made any changes from MallocChecker's ownership visitor to this one.

The new visitor emits a diagnostic note for function where a change in stream 
ownership was expected (for example, it had a fclose() call), but the ownership 
remained unchanged. This is similar to messages regarding ordinary values 
("Returning without writing to x").

Change-Id: I7621c178dd35713d860d27bfc644fb56a42b0946

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+103-3) 
- (added) clang/test/Analysis/stream-visitor.cpp (+179) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index d4e020f7a72a0..d726ab5eaa599 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -10,6 +10,9 @@
 //
 
//===--===//
 
+#include "NoOwnershipChangeVisitor.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -74,6 +77,12 @@ struct StreamErrorState {
   /// Returns if the StreamErrorState is a valid object.
   operator bool() const { return NoError || FEof || FError; }
 
+  LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
+  LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &os) const {
+os << "NoError: " << NoError << ", FEof: " << FEof
+   << ", FError: " << FError;
+  }
+
   void Profile(llvm::FoldingSetNodeID &ID) const {
 ID.AddBoolean(NoError);
 ID.AddBoolean(FEof);
@@ -98,6 +107,19 @@ struct StreamState {
 OpenFailed /// The last open operation has failed.
   } State;
 
+  StringRef getKindStr() const {
+switch (State) {
+case Opened:
+  return "Opened";
+case Closed:
+  return "Closed";
+case OpenFailed:
+  return "OpenFailed";
+default:
+  llvm_unreachable("Unknown StreamState!");
+}
+  }
+
   /// State of the error flags.
   /// Ignored in non-opened stream state but must be NoError.
   StreamErrorState const ErrorState;
@@ -146,6 +168,9 @@ struct StreamState {
 return StreamState{L, OpenFailed, {}, false};
   }
 
+  LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
+  LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &os) const;
+
   void Profile(llvm::FoldingSetNodeID &ID) const {
 ID.AddPointer(LastOperation);
 ID.AddInteger(State);
@@ -168,8 +193,9 @@ REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, 
StreamState)
 namespace {
 
 class StreamChecker;
-using FnCheck = std::function;
+using FnCheckTy = void(const StreamChecker *, const FnDescription *,
+   const CallEvent &, CheckerContext &);
+using FnCheck = std::function;
 
 using ArgNoTy = unsigned int;
 static const ArgNoTy ArgNone = std::numeric_limits::max();
@@ -183,6 +209,14 @@ struct FnDescription {
   ArgNoTy StreamArgNo;
 };
 
+LLVM_DUMP_METHOD void StreamState::dumpToStream(llvm::raw_ostream &os) const {
+  os << "{Kind: " << getKindStr() << ", Last operation: " << LastOperation
+ << ", ErrorState: ";
+  ErrorState.dumpToStream(os);
+  os << ", FilePos: " << (FilePositionIndeterminate ? "Indeterminate" : "OK")
+ << '}';
+}
+
 /// Get the value of the stream argument out of the passed call event.
 /// The call should contain a function that is described by Desc.
 SVal getStreamArg(const FnDescription *Desc, const CallEvent &Call) {
@@ -300,6 +334,8 @@ class StreamChecker : public Checker FnDescriptions = {
   {{CDM::CLibrary, {"fopen"}, 2},
@@ -310,7 +346,7 @@ class StreamChecker : public Checker(&Checker);
+if (StreamChk->FCloseDesc.matchesAsWritten(Call))
+  return true;
+
+return false;
+  }
+
+  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+ ASTContext &ACtx) override {
+using namespace clang::ast_matchers;
+const FunctionDecl *FD = dyn_cast(Callee);
+
+auto Matches =
+match(findAll(callExpr().bind("call")), *FD->getBody(), ACtx);
+for (BoundNodes Match : Matches) {
+  if (const auto *Call = Match.getNodeAs("call"))
+if (isFreeingCallAsWritten(*Call))
+  return true;
+}
+// TODO: Ownership might change with an attempt to store stream object, not
+// only through freeing it. Check for attempted stores as well.
+return false;
+  }
+
+  virtual bool hasResourceStateChanged(ProgramStateRef CallEnterState,
+   Prog

[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-10 Thread Jannick Kremer via cfe-commits

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


[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread Carlos Alberto Enciso via cfe-commits


@@ -5766,28 +5766,16 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy 
&Builder,
   // it is loaded upon use, so we identify such pattern here.
   if (llvm::LoadInst *Load = dyn_cast(Value)) {
 llvm::Value *Var = Load->getPointerOperand();
-if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) {
-  if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists(
-  CGM.getLLVMContext(), MDValue)) {
-for (llvm::User *U : DbgValue->users()) {
-  if (llvm::CallInst *DbgDeclare = dyn_cast(U)) {
-if (DbgDeclare->getCalledFunction()->getIntrinsicID() ==
-llvm::Intrinsic::dbg_declare &&
-DbgDeclare->getArgOperand(0) == DbgValue) {
-  // There can be implicit type cast applied on a variable if it is
-  // an opaque ptr, in this case its debug info may not match the
-  // actual type of object being used as in the next instruction, 
so
-  // we will need to emit a pseudo variable for type-casted value.
-  llvm::DILocalVariable *MDNode = cast(
-  cast(DbgDeclare->getOperand(1))
-  ->getMetadata());
-  if (MDNode->getType() == Type)
-return;
-}
-  }
-}
-  }
-}
+// There can be implicit type cast applied on a variable if it is an opaque
+// ptr, in this case its debug info may not match the actual type of object
+// being used as in the next instruction, so we will need to emit a pseudo
+// variable for type-casted value.
+auto DeclareTypeMatches = [&](auto *DbgDeclare) {
+  return DbgDeclare->getVariable()->getType() == Type;
+};
+if (any_of(llvm::findDbgDeclares(Var), DeclareMatches) ||

CarlosAlbertoEnciso wrote:

`DeclareMatches` or `DeclareTypeMatches`?

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


[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread Orlando Cazalet-Hyams via cfe-commits

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

LGTM

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


[clang] [analyzer] Add an ownership change visitor to StreamChecker (PR #94957)

2024-06-10 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff e622996eddfb2826d258b3a3760eed195f97aabe 
faf00d0e1286e053ba9fb457513bd8309eb541ed -- 
clang/test/Analysis/stream-visitor.cpp 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index d726ab5eaa..b5681ad83d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -11,8 +11,8 @@
 
//===--===//
 
 #include "NoOwnershipChangeVisitor.h"
-#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -194,7 +194,7 @@ namespace {
 
 class StreamChecker;
 using FnCheckTy = void(const StreamChecker *, const FnDescription *,
-   const CallEvent &, CheckerContext &);
+   const CallEvent &, CheckerContext &);
 using FnCheck = std::function;
 
 using ArgNoTy = unsigned int;
@@ -346,8 +346,7 @@ private:
{&StreamChecker::preFreopen, &StreamChecker::evalFreopen, 2}},
   {{CDM::CLibrary, {"tmpfile"}, 0},
{nullptr, &StreamChecker::evalFopen, ArgNone}},
-  {FCloseDesc,
-   {&StreamChecker::preDefault, &StreamChecker::evalFclose, 0}},
+  {FCloseDesc, {&StreamChecker::preDefault, &StreamChecker::evalFclose, 
0}},
   {{CDM::CLibrary, {"fread"}, 4},
{&StreamChecker::preRead,
 std::bind(&StreamChecker::evalFreadFwrite, _1, _2, _3, _4, true), 3}},

``




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


[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread Stephen Tozer via cfe-commits


@@ -5766,28 +5766,16 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy 
&Builder,
   // it is loaded upon use, so we identify such pattern here.
   if (llvm::LoadInst *Load = dyn_cast(Value)) {
 llvm::Value *Var = Load->getPointerOperand();
-if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) {
-  if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists(
-  CGM.getLLVMContext(), MDValue)) {
-for (llvm::User *U : DbgValue->users()) {
-  if (llvm::CallInst *DbgDeclare = dyn_cast(U)) {
-if (DbgDeclare->getCalledFunction()->getIntrinsicID() ==
-llvm::Intrinsic::dbg_declare &&
-DbgDeclare->getArgOperand(0) == DbgValue) {
-  // There can be implicit type cast applied on a variable if it is
-  // an opaque ptr, in this case its debug info may not match the
-  // actual type of object being used as in the next instruction, 
so
-  // we will need to emit a pseudo variable for type-casted value.
-  llvm::DILocalVariable *MDNode = cast(
-  cast(DbgDeclare->getOperand(1))
-  ->getMetadata());
-  if (MDNode->getType() == Type)
-return;
-}
-  }
-}
-  }
-}
+// There can be implicit type cast applied on a variable if it is an opaque
+// ptr, in this case its debug info may not match the actual type of object
+// being used as in the next instruction, so we will need to emit a pseudo
+// variable for type-casted value.
+auto DeclareTypeMatches = [&](auto *DbgDeclare) {
+  return DbgDeclare->getVariable()->getType() == Type;
+};
+if (any_of(llvm::findDbgDeclares(Var), DeclareMatches) ||

SLTozer wrote:

Oops!

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


[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-10 Thread Jannick Kremer via cfe-commits

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


[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/94956

>From 56109f5f411523967ffef5a32a507d6472eebdaf Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Mon, 10 Jun 2024 11:35:02 +0100
Subject: [PATCH 1/2] [Clang] Extend EmitPseudoVariable to support debug
 records

CGDebugInfo::EmitPseudoVariable currently uses detailed logic to exactly
collect llvm.dbg.declare users of an alloca. This patch replaces this
with an LLVM function for finding debug declares intrinsics and also adds
the same for debug records, simplifying the code and adding record
support.
---
 clang/lib/CodeGen/CGDebugInfo.cpp | 32 ++-
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 681a475f9e4be..d5676be0e8742 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5766,28 +5766,16 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy 
&Builder,
   // it is loaded upon use, so we identify such pattern here.
   if (llvm::LoadInst *Load = dyn_cast(Value)) {
 llvm::Value *Var = Load->getPointerOperand();
-if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) {
-  if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists(
-  CGM.getLLVMContext(), MDValue)) {
-for (llvm::User *U : DbgValue->users()) {
-  if (llvm::CallInst *DbgDeclare = dyn_cast(U)) {
-if (DbgDeclare->getCalledFunction()->getIntrinsicID() ==
-llvm::Intrinsic::dbg_declare &&
-DbgDeclare->getArgOperand(0) == DbgValue) {
-  // There can be implicit type cast applied on a variable if it is
-  // an opaque ptr, in this case its debug info may not match the
-  // actual type of object being used as in the next instruction, 
so
-  // we will need to emit a pseudo variable for type-casted value.
-  llvm::DILocalVariable *MDNode = cast(
-  cast(DbgDeclare->getOperand(1))
-  ->getMetadata());
-  if (MDNode->getType() == Type)
-return;
-}
-  }
-}
-  }
-}
+// There can be implicit type cast applied on a variable if it is an opaque
+// ptr, in this case its debug info may not match the actual type of object
+// being used as in the next instruction, so we will need to emit a pseudo
+// variable for type-casted value.
+auto DeclareTypeMatches = [&](auto *DbgDeclare) {
+  return DbgDeclare->getVariable()->getType() == Type;
+};
+if (any_of(llvm::findDbgDeclares(Var), DeclareMatches) ||
+any_of(llvm::findDVRDeclares(Var), DeclareMatches))
+  return;
   }
 
   // Find the correct location to insert a sequence of instructions to

>From d1fe1a5aa3d1b5d6eb6097ae8313d8620126c5a5 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Mon, 10 Jun 2024 11:55:36 +0100
Subject: [PATCH 2/2] Update lambda name

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index d5676be0e8742..11e2d549d8a45 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5773,8 +5773,8 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy &Builder,
 auto DeclareTypeMatches = [&](auto *DbgDeclare) {
   return DbgDeclare->getVariable()->getType() == Type;
 };
-if (any_of(llvm::findDbgDeclares(Var), DeclareMatches) ||
-any_of(llvm::findDVRDeclares(Var), DeclareMatches))
+if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) ||
+any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
   return;
   }
 

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


[clang] 5c268cf - [Clang] Extend EmitPseudoVariable to support debug records (#94956)

2024-06-10 Thread via cfe-commits

Author: Stephen Tozer
Date: 2024-06-10T11:57:53+01:00
New Revision: 5c268cfaae521dc2db1af58085e3c8d66a5533fe

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

LOG: [Clang] Extend EmitPseudoVariable to support debug records (#94956)

CGDebugInfo::EmitPseudoVariable currently uses detailed logic to exactly
collect llvm.dbg.declare users of an alloca. This patch replaces this
with an LLVM function for finding debug declares intrinsics and also
adds the same for debug records, simplifying the code and adding record
support.

No tests added in this commit because it is NFC for intrinsics, and
there is no way to make clang emit records directly yet - one of the
existing tests however will switch to covering debug records once
https://github.com/llvm/llvm-project/pull/89799 relands.

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 681a475f9e4be..11e2d549d8a45 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5766,28 +5766,16 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy 
&Builder,
   // it is loaded upon use, so we identify such pattern here.
   if (llvm::LoadInst *Load = dyn_cast(Value)) {
 llvm::Value *Var = Load->getPointerOperand();
-if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) {
-  if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists(
-  CGM.getLLVMContext(), MDValue)) {
-for (llvm::User *U : DbgValue->users()) {
-  if (llvm::CallInst *DbgDeclare = dyn_cast(U)) {
-if (DbgDeclare->getCalledFunction()->getIntrinsicID() ==
-llvm::Intrinsic::dbg_declare &&
-DbgDeclare->getArgOperand(0) == DbgValue) {
-  // There can be implicit type cast applied on a variable if it is
-  // an opaque ptr, in this case its debug info may not match the
-  // actual type of object being used as in the next instruction, 
so
-  // we will need to emit a pseudo variable for type-casted value.
-  llvm::DILocalVariable *MDNode = cast(
-  cast(DbgDeclare->getOperand(1))
-  ->getMetadata());
-  if (MDNode->getType() == Type)
-return;
-}
-  }
-}
-  }
-}
+// There can be implicit type cast applied on a variable if it is an opaque
+// ptr, in this case its debug info may not match the actual type of object
+// being used as in the next instruction, so we will need to emit a pseudo
+// variable for type-casted value.
+auto DeclareTypeMatches = [&](auto *DbgDeclare) {
+  return DbgDeclare->getVariable()->getType() == Type;
+};
+if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) ||
+any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
+  return;
   }
 
   // Find the correct location to insert a sequence of instructions to



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


[clang] [Clang] Extend EmitPseudoVariable to support debug records (PR #94956)

2024-06-10 Thread Stephen Tozer via cfe-commits

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


[clang] [analyzer] Add an ownership change visitor to StreamChecker (PR #94957)

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


@@ -696,6 +732,69 @@ struct StreamOperationEvaluator {
 
 } // end anonymous namespace
 
+//===--===//
+// Definition of NoStreamStateChangeVisitor.
+//===--===//
+
+namespace {
+class NoStreamStateChangeVisitor final : public NoOwnershipChangeVisitor {
+protected:
+  /// Syntactically checks whether the callee is a freeing function. Since
+  /// we have no path-sensitive information on this call (we would need a
+  /// CallEvent instead of a CallExpr for that), its possible that a
+  /// freeing function was called indirectly through a function pointer,
+  /// but we are not able to tell, so this is a best effort analysis.
+  bool isFreeingCallAsWritten(const CallExpr &Call) const {
+const auto *StreamChk = static_cast(&Checker);
+if (StreamChk->FCloseDesc.matchesAsWritten(Call))
+  return true;
+
+return false;
+  }
+
+  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+ ASTContext &ACtx) override {
+using namespace clang::ast_matchers;
+const FunctionDecl *FD = dyn_cast(Callee);
+
+auto Matches =
+match(findAll(callExpr().bind("call")), *FD->getBody(), ACtx);
+for (BoundNodes Match : Matches) {
+  if (const auto *Call = Match.getNodeAs("call"))
+if (isFreeingCallAsWritten(*Call))
+  return true;
+}
+// TODO: Ownership might change with an attempt to store stream object, not
+// only through freeing it. Check for attempted stores as well.
+return false;
+  }
+
+  virtual bool hasResourceStateChanged(ProgramStateRef CallEnterState,
+   ProgramStateRef CallExitEndState) final 
{
+return CallEnterState->get(Sym) !=
+   CallExitEndState->get(Sym);
+  }
+
+  PathDiagnosticPieceRef emitNote(const ExplodedNode *N) override {
+PathDiagnosticLocation L = PathDiagnosticLocation::create(
+N->getLocation(),
+N->getState()->getStateManager().getContext().getSourceManager());
+return std::make_shared(
+L, "Returning without freeing stream object or storing the pointer for 
"

NagyDonat wrote:

```suggestion
L, "Returning without freeing stream object or storing it for "
```
The current phrasing is technically correct, because the stream object is a 
`FILE *` _pointer_, but IMO "it" would be both shorter and easier to understand

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


[clang] [analyzer] Add an ownership change visitor to StreamChecker (PR #94957)

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

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

Nice improvement, LGTM overall. I only have one phrasing nitpick and one very 
minor question about a tangential change. 

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


[clang] [analyzer] Add an ownership change visitor to StreamChecker (PR #94957)

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

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


[clang] [analyzer] Add an ownership change visitor to StreamChecker (PR #94957)

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


@@ -168,8 +193,9 @@ REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, 
StreamState)
 namespace {
 
 class StreamChecker;
-using FnCheck = std::function;
+using FnCheckTy = void(const StreamChecker *, const FnDescription *,
+   const CallEvent &, CheckerContext &);
+using FnCheck = std::function;

NagyDonat wrote:

What is the goal of this change?

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


[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-10 Thread Pavel Samolysov via cfe-commits


@@ -8777,6 +8777,9 @@ def err_typecheck_incomplete_type_not_modifiable_lvalue : 
Error<
 def err_typecheck_lvalue_casts_not_supported : Error<
   "assignment to cast is illegal, lvalue casts are not supported">;
 
+def note_typecheck_expression_not_modifiable_lvalue : Note<

samolisov wrote:

I believe this is very general naming for the note: 
`note_typecheck_expression_not_modifiable_lvalue`. Actually, we only suggest to 
add a star to dereference some not modifiable lvalue here (`this`, I think). 
What about to rename it to better reflect the suggested change? 
`note_typecheck_add_star_to_not_modifiable_this` or something like this. 
Unfortunately, I'm not familiar well with the widespread naming for notes, and 
am not able to make a good suggestion, sorry.

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


[clang] [clang][dataflow] Handle `AtomicExpr` in `ResultObjectVisitor`. (PR #94963)

2024-06-10 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/94963

This is one of the node kinds that should be considered an "original
initializer". The patch adds a test that was causing an assertion failure in
`assert(Children.size() == 1)` without the fix.


>From 41dd82683caa0db38918c98d68b721493c0070d5 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 10 Jun 2024 11:18:22 +
Subject: [PATCH] [clang][dataflow] Handle `AtomicExpr` in
 `ResultObjectVisitor`.

This is one of the node kinds that should be considered an "original
initializer". The patch adds a test that was causing an assertion failure in
`assert(Children.size() == 1)` without the fix.
---
 .../FlowSensitive/DataflowEnvironment.cpp |  2 +-
 .../Analysis/FlowSensitive/TransferTest.cpp   | 26 +++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 0d7967c8b9344..7c88917faf9c6 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -415,7 +415,7 @@ class ResultObjectVisitor : public 
AnalysisASTVisitor {
 // below them can initialize the same object (or part of it).
 if (isa(E) || isa(E) || isa(E) ||
 isa(E) || isa(E) ||
-isa(E) ||
+isa(E) || isa(E) ||
 // We treat `BuiltinBitCastExpr` as an "original initializer" too as
 // it may not even be casting from a record type -- and even if it is,
 // the two objects are in general of unrelated type.
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index f7e6b0c22e8db..2a74d7fa63fd7 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3345,6 +3345,32 @@ TEST(TransferTest, 
ResultObjectLocationForBuiltinBitCastExpr) {
   });
 }
 
+TEST(TransferTest, ResultObjectLocationForAtomicExpr) {
+  std::string Code = R"(
+struct S {};
+void target(_Atomic(S) *ptr) {
+  S s = __c11_atomic_load(ptr, __ATOMIC_SEQ_CST);
+  // [[p]]
+}
+  )";
+  using ast_matchers::atomicExpr;
+  using ast_matchers::match;
+  using ast_matchers::selectFirst;
+  using ast_matchers::traverse;
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+auto *Atomic = selectFirst(
+"atomic", match(atomicExpr().bind("atomic"), ASTCtx));
+
+EXPECT_EQ(&Env.getResultObjectLocation(*Atomic),
+  &getLocForDecl(ASTCtx, Env, "s"));
+  });
+}
+
 TEST(TransferTest, ResultObjectLocationPropagatesThroughConditionalOperator) {
   std::string Code = R"(
 struct A {

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


[clang] [clang][dataflow] Handle `AtomicExpr` in `ResultObjectVisitor`. (PR #94963)

2024-06-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-analysis

Author: None (martinboehme)


Changes

This is one of the node kinds that should be considered an "original
initializer". The patch adds a test that was causing an assertion failure in
`assert(Children.size() == 1)` without the fix.


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


2 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+1-1) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+26) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 0d7967c8b9344..7c88917faf9c6 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -415,7 +415,7 @@ class ResultObjectVisitor : public 
AnalysisASTVisitor {
 // below them can initialize the same object (or part of it).
 if (isa(E) || isa(E) || isa(E) ||
 isa(E) || isa(E) ||
-isa(E) ||
+isa(E) || isa(E) ||
 // We treat `BuiltinBitCastExpr` as an "original initializer" too as
 // it may not even be casting from a record type -- and even if it is,
 // the two objects are in general of unrelated type.
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index f7e6b0c22e8db..2a74d7fa63fd7 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3345,6 +3345,32 @@ TEST(TransferTest, 
ResultObjectLocationForBuiltinBitCastExpr) {
   });
 }
 
+TEST(TransferTest, ResultObjectLocationForAtomicExpr) {
+  std::string Code = R"(
+struct S {};
+void target(_Atomic(S) *ptr) {
+  S s = __c11_atomic_load(ptr, __ATOMIC_SEQ_CST);
+  // [[p]]
+}
+  )";
+  using ast_matchers::atomicExpr;
+  using ast_matchers::match;
+  using ast_matchers::selectFirst;
+  using ast_matchers::traverse;
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+auto *Atomic = selectFirst(
+"atomic", match(atomicExpr().bind("atomic"), ASTCtx));
+
+EXPECT_EQ(&Env.getResultObjectLocation(*Atomic),
+  &getLocForDecl(ASTCtx, Env, "s"));
+  });
+}
+
 TEST(TransferTest, ResultObjectLocationPropagatesThroughConditionalOperator) {
   std::string Code = R"(
 struct A {

``




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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() (PR #90043)

2024-06-10 Thread Paul Heidekrüger via cfe-commits

PBHDK wrote:

> Check if you can commit to sebwolf-de:avoid-bounds-error-check

Unfortunately, we can't. We do not have access to Sebastian's LLVM fork.
Since Sebastian is out of office right now - this is one of the reasons we're 
involved - would you be ok with us submitting a new PR with our changes where 
we reference the current PR?



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


[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-10 Thread Rajveer Singh Bharadwaj via cfe-commits


@@ -8777,6 +8777,9 @@ def err_typecheck_incomplete_type_not_modifiable_lvalue : 
Error<
 def err_typecheck_lvalue_casts_not_supported : Error<
   "assignment to cast is illegal, lvalue casts are not supported">;
 
+def note_typecheck_expression_not_modifiable_lvalue : Note<

Rajveer100 wrote:

Yeah, I will do that.

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


[clang] [clang-tools-extra] [clangd] Support parsing comments without ASTContext (PR #78491)

2024-06-10 Thread Aaron Liu via cfe-commits

aaronliu0130 wrote:

LLVM has 2.5k PRs to review while working on their own changes

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


[clang] [clang-repl] Teach clang-repl how to load PCHs. (PR #94166)

2024-06-10 Thread Lang Hames via cfe-commits


@@ -0,0 +1,14 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+
+// RUN: rm -f %t.pch
+// RUN: %clang_cc1 -fmax-type-align=16 -pic-level 2 -fdeprecated-macro 
-stack-protector 1 -fblocks -fskip-odr-check-in-gmf -fexceptions 
-fcxx-exceptions -fgnuc-version=0 -triple=%target_triple -DPCH 
-fincremental-extensions -emit-pch -x c++-header -o %t.pch %s
+// RUN: clang-repl -Xcc -fgnuc-version=0 -Xcc -triple=%target_triple -Xcc 
-include-pch -Xcc %t.pch '#include "%s"' | FileCheck %s

lhames wrote:

When `-triple` is passed explicitly I'd expect it to override the process 
triple. Is there a reason not to do that?

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


[clang] [analyzer] Add an ownership change visitor to StreamChecker (PR #94957)

2024-06-10 Thread Kristóf Umann via cfe-commits

https://github.com/Szelethus updated 
https://github.com/llvm/llvm-project/pull/94957

From faf00d0e1286e053ba9fb457513bd8309eb541ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Krist=C3=B3f=20Umann?= 
Date: Fri, 7 Jun 2024 12:07:35 +0200
Subject: [PATCH 1/2] [analyzer] Add an ownership change visitor to
 StreamChecker

This is very similar to https://reviews.llvm.org/D105553, in fact, I
barely made any changes from MallocChecker's ownership visitor to this
one.

The new visitor emits a diagnostic note for function where a change in
stream ownership was expected (for example, it had a fclose() call), but
the ownership remained unchanged. This is similar to messages regarding
ordinary values ("Returning without writing to x").

Change-Id: I7621c178dd35713d860d27bfc644fb56a42b0946
---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 106 ++-
 clang/test/Analysis/stream-visitor.cpp| 179 ++
 2 files changed, 282 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Analysis/stream-visitor.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index d4e020f7a72a0..d726ab5eaa599 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -10,6 +10,9 @@
 //
 
//===--===//
 
+#include "NoOwnershipChangeVisitor.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -74,6 +77,12 @@ struct StreamErrorState {
   /// Returns if the StreamErrorState is a valid object.
   operator bool() const { return NoError || FEof || FError; }
 
+  LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
+  LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &os) const {
+os << "NoError: " << NoError << ", FEof: " << FEof
+   << ", FError: " << FError;
+  }
+
   void Profile(llvm::FoldingSetNodeID &ID) const {
 ID.AddBoolean(NoError);
 ID.AddBoolean(FEof);
@@ -98,6 +107,19 @@ struct StreamState {
 OpenFailed /// The last open operation has failed.
   } State;
 
+  StringRef getKindStr() const {
+switch (State) {
+case Opened:
+  return "Opened";
+case Closed:
+  return "Closed";
+case OpenFailed:
+  return "OpenFailed";
+default:
+  llvm_unreachable("Unknown StreamState!");
+}
+  }
+
   /// State of the error flags.
   /// Ignored in non-opened stream state but must be NoError.
   StreamErrorState const ErrorState;
@@ -146,6 +168,9 @@ struct StreamState {
 return StreamState{L, OpenFailed, {}, false};
   }
 
+  LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
+  LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &os) const;
+
   void Profile(llvm::FoldingSetNodeID &ID) const {
 ID.AddPointer(LastOperation);
 ID.AddInteger(State);
@@ -168,8 +193,9 @@ REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, 
StreamState)
 namespace {
 
 class StreamChecker;
-using FnCheck = std::function;
+using FnCheckTy = void(const StreamChecker *, const FnDescription *,
+   const CallEvent &, CheckerContext &);
+using FnCheck = std::function;
 
 using ArgNoTy = unsigned int;
 static const ArgNoTy ArgNone = std::numeric_limits::max();
@@ -183,6 +209,14 @@ struct FnDescription {
   ArgNoTy StreamArgNo;
 };
 
+LLVM_DUMP_METHOD void StreamState::dumpToStream(llvm::raw_ostream &os) const {
+  os << "{Kind: " << getKindStr() << ", Last operation: " << LastOperation
+ << ", ErrorState: ";
+  ErrorState.dumpToStream(os);
+  os << ", FilePos: " << (FilePositionIndeterminate ? "Indeterminate" : "OK")
+ << '}';
+}
+
 /// Get the value of the stream argument out of the passed call event.
 /// The call should contain a function that is described by Desc.
 SVal getStreamArg(const FnDescription *Desc, const CallEvent &Call) {
@@ -300,6 +334,8 @@ class StreamChecker : public Checker FnDescriptions = {
   {{CDM::CLibrary, {"fopen"}, 2},
@@ -310,7 +346,7 @@ class StreamChecker : public Checker(&Checker);
+if (StreamChk->FCloseDesc.matchesAsWritten(Call))
+  return true;
+
+return false;
+  }
+
+  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+ ASTContext &ACtx) override {
+using namespace clang::ast_matchers;
+const FunctionDecl *FD = dyn_cast(Callee);
+
+auto Matches =
+match(findAll(callExpr().bind("call")), *FD->getBody(), ACtx);
+for (BoundNodes Match : Matches) {
+  if (const auto *Call = Match.getNodeAs("call"))
+if (isFreeingCallAsWritten(*Call))
+  return true;
+}
+// TODO: Ownership might change with an attempt to store stream object, not
+// only through

[clang] [clang][dataflow] Handle `AtomicExpr` in `ResultObjectVisitor`. (PR #94963)

2024-06-10 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.

LGTM!

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


[clang] [analyzer] Add an ownership change visitor to StreamChecker (PR #94957)

2024-06-10 Thread Kristóf Umann via cfe-commits

https://github.com/Szelethus updated 
https://github.com/llvm/llvm-project/pull/94957

From faf00d0e1286e053ba9fb457513bd8309eb541ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Krist=C3=B3f=20Umann?= 
Date: Fri, 7 Jun 2024 12:07:35 +0200
Subject: [PATCH 1/3] [analyzer] Add an ownership change visitor to
 StreamChecker

This is very similar to https://reviews.llvm.org/D105553, in fact, I
barely made any changes from MallocChecker's ownership visitor to this
one.

The new visitor emits a diagnostic note for function where a change in
stream ownership was expected (for example, it had a fclose() call), but
the ownership remained unchanged. This is similar to messages regarding
ordinary values ("Returning without writing to x").

Change-Id: I7621c178dd35713d860d27bfc644fb56a42b0946
---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 106 ++-
 clang/test/Analysis/stream-visitor.cpp| 179 ++
 2 files changed, 282 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Analysis/stream-visitor.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index d4e020f7a72a0..d726ab5eaa599 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -10,6 +10,9 @@
 //
 
//===--===//
 
+#include "NoOwnershipChangeVisitor.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -74,6 +77,12 @@ struct StreamErrorState {
   /// Returns if the StreamErrorState is a valid object.
   operator bool() const { return NoError || FEof || FError; }
 
+  LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
+  LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &os) const {
+os << "NoError: " << NoError << ", FEof: " << FEof
+   << ", FError: " << FError;
+  }
+
   void Profile(llvm::FoldingSetNodeID &ID) const {
 ID.AddBoolean(NoError);
 ID.AddBoolean(FEof);
@@ -98,6 +107,19 @@ struct StreamState {
 OpenFailed /// The last open operation has failed.
   } State;
 
+  StringRef getKindStr() const {
+switch (State) {
+case Opened:
+  return "Opened";
+case Closed:
+  return "Closed";
+case OpenFailed:
+  return "OpenFailed";
+default:
+  llvm_unreachable("Unknown StreamState!");
+}
+  }
+
   /// State of the error flags.
   /// Ignored in non-opened stream state but must be NoError.
   StreamErrorState const ErrorState;
@@ -146,6 +168,9 @@ struct StreamState {
 return StreamState{L, OpenFailed, {}, false};
   }
 
+  LLVM_DUMP_METHOD void dump() const { dumpToStream(llvm::errs()); }
+  LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &os) const;
+
   void Profile(llvm::FoldingSetNodeID &ID) const {
 ID.AddPointer(LastOperation);
 ID.AddInteger(State);
@@ -168,8 +193,9 @@ REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, 
StreamState)
 namespace {
 
 class StreamChecker;
-using FnCheck = std::function;
+using FnCheckTy = void(const StreamChecker *, const FnDescription *,
+   const CallEvent &, CheckerContext &);
+using FnCheck = std::function;
 
 using ArgNoTy = unsigned int;
 static const ArgNoTy ArgNone = std::numeric_limits::max();
@@ -183,6 +209,14 @@ struct FnDescription {
   ArgNoTy StreamArgNo;
 };
 
+LLVM_DUMP_METHOD void StreamState::dumpToStream(llvm::raw_ostream &os) const {
+  os << "{Kind: " << getKindStr() << ", Last operation: " << LastOperation
+ << ", ErrorState: ";
+  ErrorState.dumpToStream(os);
+  os << ", FilePos: " << (FilePositionIndeterminate ? "Indeterminate" : "OK")
+ << '}';
+}
+
 /// Get the value of the stream argument out of the passed call event.
 /// The call should contain a function that is described by Desc.
 SVal getStreamArg(const FnDescription *Desc, const CallEvent &Call) {
@@ -300,6 +334,8 @@ class StreamChecker : public Checker FnDescriptions = {
   {{CDM::CLibrary, {"fopen"}, 2},
@@ -310,7 +346,7 @@ class StreamChecker : public Checker(&Checker);
+if (StreamChk->FCloseDesc.matchesAsWritten(Call))
+  return true;
+
+return false;
+  }
+
+  bool doesFnIntendToHandleOwnership(const Decl *Callee,
+ ASTContext &ACtx) override {
+using namespace clang::ast_matchers;
+const FunctionDecl *FD = dyn_cast(Callee);
+
+auto Matches =
+match(findAll(callExpr().bind("call")), *FD->getBody(), ACtx);
+for (BoundNodes Match : Matches) {
+  if (const auto *Call = Match.getNodeAs("call"))
+if (isFreeingCallAsWritten(*Call))
+  return true;
+}
+// TODO: Ownership might change with an attempt to store stream object, not
+// only through

[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)

2024-06-10 Thread Rajveer Singh Bharadwaj via cfe-commits

https://github.com/Rajveer100 updated 
https://github.com/llvm/llvm-project/pull/94159

>From 3b25887966d1846a7c3d8f0c95fa1be73282b267 Mon Sep 17 00:00:00 2001
From: Rajveer 
Date: Sun, 2 Jun 2024 18:33:37 +0530
Subject: [PATCH] [clang] Fix-it hint for `++this` -> `++*this` when deref is
 modifiable

Resolves #93066
---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Sema/SemaExpr.cpp   | 23 --
 clang/test/C/drs/dr1xx.c  |  1 +
 clang/test/Sema/debug-93066.cpp   | 31 +++
 clang/test/Sema/exprs.c   |  2 ++
 clang/test/Sema/va_arg_x86_32.c   |  1 +
 clang/test/SemaObjCXX/sel-address.mm  |  8 +
 7 files changed, 67 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Sema/debug-93066.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 270b0a1e01307..986d454decab6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8777,6 +8777,9 @@ def err_typecheck_incomplete_type_not_modifiable_lvalue : 
Error<
 def err_typecheck_lvalue_casts_not_supported : Error<
   "assignment to cast is illegal, lvalue casts are not supported">;
 
+def note_typecheck_add_deref_star_not_modifiable_lvalue : Note<
+  "add '*' to dereference it">; 
+
 def err_typecheck_duplicate_vector_components_not_mlvalue : Error<
   "vector is not assignable (contains duplicate components)">;
 def err_block_decl_ref_not_modifiable_lvalue : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ff9c5ead36dcf..b585d1c0270b9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13273,6 +13273,22 @@ enum {
   ConstUnknown,  // Keep as last element
 };
 
+static void MaybeSuggestDerefFixIt(Sema &S, const Expr *E, SourceLocation Loc) 
{
+  ExprResult Deref;
+  Expr *TE = const_cast(E);
+  {
+Sema::TentativeAnalysisScope Trap(S);
+Deref = S.ActOnUnaryOp(S.getCurScope(), Loc, tok::star, TE);
+  }
+  if (Deref.isUsable() &&
+  Deref.get()->isModifiableLvalue(S.Context, &Loc) == Expr::MLV_Valid &&
+  !E->getType()->isObjCObjectPointerType()) {
+S.Diag(Loc, diag::note_typecheck_add_deref_star_not_modifiable_lvalue)
+<< E->getSourceRange()
+<< FixItHint::CreateInsertion(E->getBeginLoc(), "*");
+  }
+}
+
 /// Emit the "read-only variable not assignable" error and print notes to give
 /// more information about why the variable is not assignable, such as pointing
 /// to the declaration of a const variable, showing that a method is const, or
@@ -13367,6 +13383,7 @@ static void DiagnoseConstAssignment(Sema &S, const Expr 
*E,
 if (!DiagnosticEmitted) {
   S.Diag(Loc, diag::err_typecheck_assign_const)
   << ExprRange << ConstVariable << VD << VD->getType();
+  MaybeSuggestDerefFixIt(S, E, Loc);
   DiagnosticEmitted = true;
 }
 S.Diag(VD->getLocation(), diag::note_typecheck_assign_const)
@@ -13587,10 +13604,12 @@ static bool CheckForModifiableLvalue(Expr *E, 
SourceLocation Loc, Sema &S) {
   SourceRange Assign;
   if (Loc != OrigLoc)
 Assign = SourceRange(OrigLoc, OrigLoc);
-  if (NeedType)
+  if (NeedType) {
 S.Diag(Loc, DiagID) << E->getType() << E->getSourceRange() << Assign;
-  else
+  } else {
 S.Diag(Loc, DiagID) << E->getSourceRange() << Assign;
+MaybeSuggestDerefFixIt(S, E, Loc);
+  }
   return true;
 }
 
diff --git a/clang/test/C/drs/dr1xx.c b/clang/test/C/drs/dr1xx.c
index 47538e44428c3..20e953b2c20ac 100644
--- a/clang/test/C/drs/dr1xx.c
+++ b/clang/test/C/drs/dr1xx.c
@@ -296,6 +296,7 @@ void dr126(void) {
*/
   *object = 12; /* ok */
   ++object; /* expected-error {{cannot assign to variable 'object' with 
const-qualified type 'const IP' (aka 'int *const')}} */
+  /* expected-note@-1 {{add '*' to dereference it}} */
 }
 
 /* WG14 DR128: yes
diff --git a/clang/test/Sema/debug-93066.cpp b/clang/test/Sema/debug-93066.cpp
new file mode 100644
index 0..8e9c382a63bbe
--- /dev/null
+++ b/clang/test/Sema/debug-93066.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
+
+struct S {
+  void f() {
+++this; // expected-error {{expression is not assignable}}
+// expected-note@-1 {{add '*' to dereference it}}
+  }
+
+  void g() const {
+++this; // expected-error {{expression is not assignable}}
+  }
+};
+
+void f(int* a, int* const b, const int* const c, __UINTPTR_TYPE__ d) {
+  (int*)d = 4; // expected-error {{assignment to cast is illegal, lvalue casts 
are not supported}}
+  // expected-note@-1 {{add '*' to dereference it}}
+
+  ++a;
+  ++b; // expected-error {{cannot assign to variable 'b' with const-qualified 
type 'int *const'}}
+  // expected-note@-1 {{add '*' to dereference it}}
+  // expected-note@* {{variable 'b' declared const here}}
+  ++c; // expected-erro

[clang] [Clang][AMDGPU] Add a new builtin type for buffer rsrc (PR #94830)

2024-06-10 Thread Matt Arsenault via cfe-commits


@@ -2200,6 +2206,9 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const 
{
 Align = 8; 
\
 break;
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
+case BuiltinType::AMDGPUBufferRsrc:
+  Width = 128;
+  Align = 128;

arsenm wrote:

Sizeless object is probably the safest option for now. It shouldn't be a 
vector. I foresee more difficulty introducing a wide pointer, and if we change 
our minds on how fat pointers should work it's harder to change the size later 

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


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-10 Thread NAKAMURA Takumi via cfe-commits

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


[clang] [llvm] [MC/DC][Coverage] Loosen the limit of NumConds from 6 (PR #82448)

2024-06-10 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

I am certain this is ready for land.

Could I update release notes later? I am afraid since I have been always 
missing release schedules.

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


[clang] c5aeca7 - Reapply#3 "[RemoveDIs] Load into new debug info format by default in LLVM (#89799)"

2024-06-10 Thread Stephen Tozer via cfe-commits

Author: Stephen Tozer
Date: 2024-06-10T13:04:40+01:00
New Revision: c5aeca732d1ff6769b0659efebd1cfb5f60487e4

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

LOG: Reapply#3 "[RemoveDIs] Load into new debug info format by default in LLVM 
(#89799)"

Reapplies commit 91446e2, which was reverted due to a downstream error,
discussed on the pull request. The error could not be reproduced
upstream, and cannot be reproduced downstream as-of current main, so
until the error can be confirmed to still exist this patch should
return.

This reverts commit 23f8fac745bdde70ed4f9c585d19c4913734f1b8.

Added: 


Modified: 
clang/test/CodeGen/instrument-objc-method.m
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/AsmParser/LLParser.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/IR/BasicBlock.cpp
llvm/lib/IR/DebugProgramInstruction.cpp
llvm/lib/IR/Function.cpp
llvm/lib/IR/Module.cpp
llvm/tools/llvm-as/llvm-as.cpp
llvm/tools/llvm-dis/llvm-dis.cpp
llvm/tools/llvm-link/llvm-link.cpp
llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp
llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
llvm/unittests/IR/DebugInfoTest.cpp
llvm/unittests/IR/IRBuilderTest.cpp
llvm/unittests/IR/InstructionsTest.cpp
llvm/unittests/IR/ValueTest.cpp
llvm/unittests/Transforms/Utils/CloningTest.cpp
llvm/unittests/Transforms/Utils/LocalTest.cpp

Removed: 




diff  --git a/clang/test/CodeGen/instrument-objc-method.m 
b/clang/test/CodeGen/instrument-objc-method.m
index cfc0a0a98bec6..2c9d1fc88554b 100644
--- a/clang/test/CodeGen/instrument-objc-method.m
+++ b/clang/test/CodeGen/instrument-objc-method.m
@@ -11,16 +11,16 @@ @implementation ObjCClass
 + (void)initialize {
 }
 
-// PREINLINE: declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
-// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #2
+// BARE: @"\01+[ObjCClass load]"{{\(.*\)}} #1
 + (void)load __attribute__((no_instrument_function)) {
 }
 
-// PREINLINE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #2
-// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #2
+// PREINLINE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #1
+// BARE: @"\01-[ObjCClass dealloc]"{{\(.*\)}} #1
 - (void)dealloc __attribute__((no_instrument_function)) {
 }
 
+// PREINLINE: declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
 // PREINLINE: attributes #0 = { 
{{.*}}"instrument-function-entry"="__cyg_profile_func_enter"
 // PREINLINE-NOT: attributes #0 = { 
{{.*}}"instrument-function-entry"="__cyg_profile_func_enter_bare"
 // PREINLINE-NOT: attributes #2 = { {{.*}}"__cyg_profile_func_enter"

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index f86f9430201f8..8cdb9db087c77 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -225,6 +225,13 @@ Changes to the Metadata Info
 Changes to the Debug Info
 -
 
+* LLVM has switched from using debug intrinsics internally to using debug
+  records by default. This should happen transparently when using the DIBuilder
+  to construct debug variable information, but will require changes for any 
code
+  that interacts with debug intrinsics directly. Debug intrinsics will only be
+  supported on a best-effort basis from here onwards; for more information, see
+  the `migration docs `_.
+
 Changes to the LLVM tools
 -
 * llvm-nm and llvm-objdump can now print symbol information from linked

diff  --git a/llvm/include/llvm/AsmParser/LLParser.h 
b/llvm/include/llvm/AsmParser/LLParser.h
index b2dcdfad0a04b..e687254f6c4c7 100644
--- a/llvm/include/llvm/AsmParser/LLParser.h
+++ b/llvm/include/llvm/AsmParser/LLParser.h
@@ -337,7 +337,6 @@ namespace llvm {
 
 // Top-Level Entities
 bool parseTopLevelEntities();
-bool finalizeDebugInfoFormat(Module *M);
 void dropUnknownMetadataReferences();
 bool validateEndOfModule(bool UpgradeDebugInfo);
 bool validateEndOfIndex();

diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index f0fde9ae4df5c..eb1e3e494a42f 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -74,23 +74,6 @@ static std::string getTypeString(Type *T) {
   return Tmp.str();
 }
 
-// Whatever debug info format we parsed, we should convert to the expected 
debug
-// info format immediately afterwards.
-bool LLParser::finalizeDebugInfoFormat(Module *M) {
-  // We should have already returned an error if we observed both intrinsics 
and
-  // records in this IR.
-  assert(!(SeenNewDbgInfoFormat && SeenOldDbgInfoFormat) &&
- "Mixed debug intrinsics/records seen without a parsing error?");
-  if (PreserveInputDbgFormat == 

[clang] Support [[guarded_by(mutex)]] attribute inside C struct (PR #94216)

2024-06-10 Thread Pierre d'Herbemont via cfe-commits

https://github.com/pdherbemont updated 
https://github.com/llvm/llvm-project/pull/94216

>From a9da7c1287142025d8a54e569f6c5f8ecb411961 Mon Sep 17 00:00:00 2001
From: Pierre d'Herbemont 
Date: Wed, 29 May 2024 11:11:03 +0200
Subject: [PATCH] Support [[guarded_by(mutex)]] and friends attributes inside C
 struct

Today, it's only supported inside C++ classes or top level C/C++
declaration.

I mostly copied and adapted over the code from the
[[counted_by(value)]] lookup.

I had to change ast-dump-color.cpp because of the way the expression
marking now marks the mutex as "used" instead of "referenced". If I
change the expression parsing to use
`ExpressionEvaluationContext::Unevaluated` then I get the mutex as
"referenced" but I lose the C++ check for "invalid use of non-static
data member".

Then I enabled the use of the experimental late parsing used by
[[counted_by]] because that will enable the adoption of attributes
without restructuring the data layout as requested by @rapidsna.
---
 clang/docs/ReleaseNotes.rst   |   4 +
 clang/docs/ThreadSafetyAnalysis.rst   |   6 -
 clang/include/clang/Basic/Attr.td |   8 +-
 clang/include/clang/Parse/Parser.h|  14 +++
 clang/include/clang/Sema/Sema.h   |   7 +-
 clang/lib/Parse/ParseDecl.cpp | 118 +-
 clang/lib/Sema/SemaExpr.cpp   |   4 +-
 clang/test/AST/ast-dump-color.cpp |   4 +-
 clang/test/Sema/warn-thread-safety-analysis.c |  68 +-
 .../SemaCXX/warn-thread-safety-parsing.cpp|   6 +-
 10 files changed, 213 insertions(+), 26 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 99580c0d28a4f..c6bcf25d95dab 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -451,6 +451,10 @@ Attribute Changes in Clang
size_t count;
  };
 
+- The ``guarded_by``, ``pt_guarded_by``, ``acquired_after``, 
``acquired_before``
+  attributes now support referencing struct members in C. The arguments are 
also
+  now late parsed when ``-fexperimental-late-parse-attributes`` is passed like
+  for ``counted_by``.
 
 Improvements to Clang's diagnostics
 ---
diff --git a/clang/docs/ThreadSafetyAnalysis.rst 
b/clang/docs/ThreadSafetyAnalysis.rst
index dcde0c706c704..6eefa306e3c89 100644
--- a/clang/docs/ThreadSafetyAnalysis.rst
+++ b/clang/docs/ThreadSafetyAnalysis.rst
@@ -764,12 +764,6 @@ doesn't know that munl.mu == mutex.  The SCOPED_CAPABILITY 
attribute handles
 aliasing for MutexLocker, but does so only for that particular pattern.
 
 
-ACQUIRED_BEFORE(...) and ACQUIRED_AFTER(...) are currently unimplemented.
--
-
-To be fixed in a future update.
-
-
 .. _mutexheader:
 
 mutex.h
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index c6f08860f203a..cb424965732b3 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3633,7 +3633,7 @@ def NoThreadSafetyAnalysis : InheritableAttr {
 def GuardedBy : InheritableAttr {
   let Spellings = [GNU<"guarded_by">];
   let Args = [ExprArgument<"Arg">];
-  let LateParsed = LateAttrParseStandard;
+  let LateParsed = LateAttrParseExperimentalExt;
   let TemplateDependent = 1;
   let ParseArgumentsAsUnevaluated = 1;
   let InheritEvenIfAlreadyPresent = 1;
@@ -3644,7 +3644,7 @@ def GuardedBy : InheritableAttr {
 def PtGuardedBy : InheritableAttr {
   let Spellings = [GNU<"pt_guarded_by">];
   let Args = [ExprArgument<"Arg">];
-  let LateParsed = LateAttrParseStandard;
+  let LateParsed = LateAttrParseExperimentalExt;
   let TemplateDependent = 1;
   let ParseArgumentsAsUnevaluated = 1;
   let InheritEvenIfAlreadyPresent = 1;
@@ -3655,7 +3655,7 @@ def PtGuardedBy : InheritableAttr {
 def AcquiredAfter : InheritableAttr {
   let Spellings = [GNU<"acquired_after">];
   let Args = [VariadicExprArgument<"Args">];
-  let LateParsed = LateAttrParseStandard;
+  let LateParsed = LateAttrParseExperimentalExt;
   let TemplateDependent = 1;
   let ParseArgumentsAsUnevaluated = 1;
   let InheritEvenIfAlreadyPresent = 1;
@@ -3666,7 +3666,7 @@ def AcquiredAfter : InheritableAttr {
 def AcquiredBefore : InheritableAttr {
   let Spellings = [GNU<"acquired_before">];
   let Args = [VariadicExprArgument<"Args">];
-  let LateParsed = LateAttrParseStandard;
+  let LateParsed = LateAttrParseExperimentalExt;
   let TemplateDependent = 1;
   let ParseArgumentsAsUnevaluated = 1;
   let InheritEvenIfAlreadyPresent = 1;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index d054b8cf0d240..9e11078382756 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3128,6 +3128,20 @@ class Parser : public CodeCompletionHandler {
 IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
 ParsedA

[clang] Support [[guarded_by(mutex)]] attribute inside C struct (PR #94216)

2024-06-10 Thread Pierre d'Herbemont via cfe-commits


@@ -74,6 +83,15 @@ int get_value(int *p) SHARED_LOCKS_REQUIRED(foo_.mu_){
 
 void unlock_scope(struct Mutex *const *mu) 
__attribute__((release_capability(**mu)));
 
+// Verify late parsing:
+#ifdef LATE_PARSING
+struct LateParsing {
+  int a_value_defined_before GUARDED_BY(a_mutex_defined_late);
+  struct Mutex *a_mutex_defined_late ACQUIRED_AFTER(a_mutex_defined_very_late);
+  struct Mutex *a_mutex_defined_very_late;

pdherbemont wrote:

Done!

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


[clang] [clang-tools-extra] [clangd] Support parsing comments without ASTContext (PR #78491)

2024-06-10 Thread via cfe-commits

cor3ntin wrote:

PRs need to be reviewed before they can be merged.
Feel free to ping PR once a week (at most) if no one gets to it.
This seem to have flown under the radar. sorry about that

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


[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #94664)

2024-06-10 Thread via cfe-commits

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


[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #94664)

2024-06-10 Thread via cfe-commits


@@ -4509,6 +4509,19 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   return Resolver;
 }
 
+bool CodeGenModule::shouldDropDLLAttribute(const Decl *D,

zmodem wrote:

This doesn't access any members of CodeGenModule, so making it a static 
non-member function would be better.

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


[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #94664)

2024-06-10 Thread via cfe-commits

https://github.com/zmodem commented:

Thank you, I think this is much better.

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


[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #94664)

2024-06-10 Thread via cfe-commits


@@ -4509,6 +4509,19 @@ llvm::Constant 
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
   return Resolver;
 }
 
+bool CodeGenModule::shouldDropDLLAttribute(const Decl *D,

zmodem wrote:

Never mind, shouldMapVisibilityToDLLExport() is a member, so this makes sense.

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


[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #94664)

2024-06-10 Thread via cfe-commits

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

lgtm

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


[clang] [clang-format] fix incorrectly indents lambda trailing return (PR #94560)

2024-06-10 Thread via cfe-commits

c8ef wrote:

Dear reviewers, is there anything else I need to do for this PR? If not, could 
you please assist me in merging it? Thank you!

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


[clang] [Driver] Add winsysroot alias to the GNU driver (PR #94731)

2024-06-10 Thread via cfe-commits

https://github.com/Andarwinux updated 
https://github.com/llvm/llvm-project/pull/94731

>From 510aff7501ccf78440e9b959b8913d2604d65c49 Mon Sep 17 00:00:00 2001
From: Andarwinux <144242044+andarwi...@users.noreply.github.com>
Date: Fri, 7 Jun 2024 07:07:40 +
Subject: [PATCH] [Driver] Add winsysroot alias to the GNU driver

fixes #91216
---
 clang/include/clang/Driver/Options.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..1cce7a5146dd8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8569,6 +8569,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">,
 Alias<_SLASH_winsdkdir>;
 def : Separate<["-"], "Xmicrosoft-windows-sdk-version">,
 Alias<_SLASH_winsdkversion>;
+def : Separate<["-"], "Xmicrosoft-windows-sys-root">,
+Alias<_SLASH_winsysroot>;
 
 // Ignored:
 

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


[clang] [clang] Cover CWG issues about `export template` (PR #94876)

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

Endilll wrote:

Me and Corentin discussed this offline. Two points emerged there:
1) He's more concerned with the fact that 204 and other Core issues are 
highlighted green, inheriting the status of the issue that superseded them, 
than with the fact that they are marked as superseded. Styles we use in 
`cxx_dr_status.html` can be changed in a subsequent PR.
2) In previous discussions on this topic, I remember that we together with 
@AaronBallman agreed that statuses on our page should follow the official 
statuses. This PR goes against it, because I know from experience that the 
current CWG chair is not interested in revisiting Core issues that were closed 
long ago, and mark them as superseded where appropriate. We might need to 
revisit out previous consensus in the light of this PR and aforementioned 
experience talking to Core.

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


[clang] [clang-repl] Teach clang-repl how to load PCHs. (PR #94166)

2024-06-10 Thread Vassil Vassilev via cfe-commits


@@ -0,0 +1,14 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+
+// RUN: rm -f %t.pch
+// RUN: %clang_cc1 -fmax-type-align=16 -pic-level 2 -fdeprecated-macro 
-stack-protector 1 -fblocks -fskip-odr-check-in-gmf -fexceptions 
-fcxx-exceptions -fgnuc-version=0 -triple=%target_triple -DPCH 
-fincremental-extensions -emit-pch -x c++-header -o %t.pch %s
+// RUN: clang-repl -Xcc -fgnuc-version=0 -Xcc -triple=%target_triple -Xcc 
-include-pch -Xcc %t.pch '#include "%s"' | FileCheck %s

vgvassilev wrote:

How we can get the “right” triple from clang? And yes, sometimes the build can 
be configured in an odd way (we have some bots) where the triple from clang is 
different from the triple of the JIT. Unfortunately, we did not find a way to 
suppress these cases with a good lit clause last time we dealt with them. 

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


[clang] [clang][dataflow] Handle `AtomicExpr` in `ResultObjectVisitor`. (PR #94963)

2024-06-10 Thread Yitzhak Mandelbaum via cfe-commits

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


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


[clang] [clang] SourceLocIdentKind::Function should not be dependent (PR #94942)

2024-06-10 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> because we want to make the name of the function and any template parameter
refers to the instantiated function rather than that of the function template.

Does that mean we should transform the `SourceLocExpr` into a certain function 
name when instantiating  if it is `__builtin_FUNCTION`? 

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


[clang] [Clang][Comments] Add argument parsing for @throw @throws @exception (PR #84726)

2024-06-10 Thread via cfe-commits

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

LGTM, Thanks
Will you need us to merge that for you?

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


[clang] 2cf1439 - [AArch64] Decouple feature dependency expansion. (#94279)

2024-06-10 Thread via cfe-commits

Author: Alexandros Lamprineas
Date: 2024-06-10T13:53:14+01:00
New Revision: 2cf14398c9341feddb419e7ff9c8c5623a3da3db

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

LOG: [AArch64] Decouple feature dependency expansion. (#94279)

The dependency expansion step which was introduced by FMV has been
erroneously used for non-FMV features, for example when parsing the
target attribute. The PR #93695 has rectified most of the tests which
were relying on dependency expansion of target features specified on the
-cc1 command line. In this patch I am decoupling the dependency
expansion of features specified on the target attribute from FMV.

To do that first I am expanding FMV dependencies before passing the list
of target features to initFeatureMap(). Similarly when parsing the
target attribute I am reconstructing an ExtensionSet from the list of
target features which was created during the command line option
parsing. The attribute parsing may toggle bits of that ExtensionSet and
at the end it is converted to a list of target features. Those are
passed to initFeatureMap(), which no longer requires an override.

A side effect of this refactoring is that features specified on the
target_version attribute now supersede the command line options, which
is what should be happening in the first place.

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/test/CodeGen/aarch64-cpu-supports-target.c
clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp
clang/test/CodeGen/aarch64-targetattr.c
clang/test/CodeGen/attr-target-version.c
clang/test/Sema/aarch64-neon-target.c
llvm/include/llvm/TargetParser/AArch64TargetParser.h
llvm/lib/TargetParser/AArch64TargetParser.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a1d1d1c51cd41..8bce4812f0d48 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -3203,9 +3203,6 @@ class ASTContext : public RefCountedBase {
   /// valid feature names.
   ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD) const;
 
-  std::vector
-  filterFunctionTargetVersionAttrs(const TargetVersionAttr *TV) const;
-
   void getFunctionFeatureMap(llvm::StringMap &FeatureMap,
  const FunctionDecl *) const;
   void getFunctionFeatureMap(llvm::StringMap &FeatureMap,

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index bf74e56a14799..cd76b8aa271da 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -87,6 +87,7 @@
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 #include 
@@ -13663,17 +13664,20 @@ QualType 
ASTContext::getCorrespondingSignedFixedPointType(QualType Ty) const {
   }
 }
 
-std::vector ASTContext::filterFunctionTargetVersionAttrs(
-const TargetVersionAttr *TV) const {
-  assert(TV != nullptr);
-  llvm::SmallVector Feats;
-  std::vector ResFeats;
-  TV->getFeatures(Feats);
-  for (auto &Feature : Feats)
-if (Target->validateCpuSupports(Feature.str()))
-  // Use '?' to mark features that came from TargetVersion.
-  ResFeats.push_back("?" + Feature.str());
-  return ResFeats;
+// Given a list of FMV features, return a concatenated list of the
+// corresponding backend features (which may contain duplicates).
+static std::vector getFMVBackendFeaturesFor(
+const llvm::SmallVectorImpl &FMVFeatStrings) {
+  std::vector BackendFeats;
+  for (StringRef F : FMVFeatStrings) {
+if (auto FMVExt = llvm::AArch64::parseArchExtension(F)) {
+  SmallVector Feats;
+  FMVExt->DependentFeatures.split(Feats, ',', -1, false);
+  for (StringRef F : Feats)
+BackendFeats.push_back(F.str());
+}
+  }
+  return BackendFeats;
 }
 
 ParsedTargetAttr
@@ -13708,10 +13712,12 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
 
 // Make a copy of the features as passed on the command line into the
 // beginning of the additional features from the function to override.
-ParsedAttr.Features.insert(
-ParsedAttr.Features.begin(),
-Target->getTargetOpts().FeaturesAsWritten.begin(),
-Target->getTargetOpts().FeaturesAsWritten.end());
+// AArch64 handles command line option features in parseTargetAttr().
+if (!Target->getTriple().isAArch64())
+  ParsedAttr.Features.insert(
+  ParsedAttr.Features.begin(),
+  Target->getTargetOpts().FeaturesAsWritten.begin(),
+  T

[clang] [llvm] [AArch64] Decouple feature dependency expansion. (PR #94279)

2024-06-10 Thread Alexandros Lamprineas via cfe-commits

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


[clang] [llvm] [clang][OpenMP] Shorten directive classification in ParseOpenMP (PR #94691)

2024-06-10 Thread Krzysztof Parzyszek via cfe-commits

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


[clang] [AArch64] Extend SVE diagnostics. (PR #94976)

2024-06-10 Thread Harald van Dijk via cfe-commits

https://github.com/hvdijk created 
https://github.com/llvm/llvm-project/pull/94976

The SVE diagnostics were guarded by a FD->hasBody() check that prevented the 
diagnostic from being emitted for code that still triggered the backend crashes 
that the errors were meant to avoid, because FD->hasBody() returns false for a 
function that Clang is currently processing. This is not done for the 
equivalent RISC-V code, and is not needed for AArch64 either, so remove it.

Errors were also emitted in the wrong location, errors were emitted at the 
called function's location, rather than at the caller's, which meant that just 
removing the FD->hasBody() check resulted in incomprehensible errors. Change 
this as well.

The aarch64-mangle-sve-vectors.cpp test was using -target-feature wrong which 
was exposed as a result of these changes. Different target features need to be 
passed in as different -target-feature options.

aarch64-targetattr-arch.c has a test_errors() function that needs to be split 
in two. Now that svundef_s8() is diagnosed for its use of svint8_t, the "needs 
target feature sve" diagnostic is no longer emitted, but this affects all calls 
in the same function. To ensure we still check this for its __crc32cd call, 
move that into a separate function.

Fixes #94766.

>From 9bd0b577a3a70abb6e27b389c3bc7cc1e0191cc3 Mon Sep 17 00:00:00 2001
From: Harald van Dijk 
Date: Mon, 10 Jun 2024 14:14:46 +0100
Subject: [PATCH] [AArch64] Extend SVE diagnostics.

The SVE diagnostics were guarded by a FD->hasBody() check that prevented
the diagnostic from being emitted for code that still triggered the
backend crashes that the errors were meant to avoid, because
FD->hasBody() returns false for a function that Clang is currently
processing. This is not done for the equivalent RISC-V code, and is not
needed for AArch64 either, so remove it.

Errors were also emitted in the wrong location, errors were emitted at
the called function's location, rather than at the caller's, which meant
that just removing the FD->hasBody() check resulted in incomprehensible
errors. Change this as well.

The aarch64-mangle-sve-vectors.cpp test was using -target-feature wrong
which was exposed as a result of these changes. Different target
features need to be passed in as different -target-feature options.

aarch64-targetattr-arch.c has a test_errors() function that needs to be
split in two. Now that svundef_s8() is diagnosed for its use of
svint8_t, the "needs target feature sve" diagnostic is no longer
emitted, but this affects all calls in the same function. To ensure we
still check this for its __crc32cd call, move that into a separate
function.

Fixes #94766.
---
 clang/lib/Sema/Sema.cpp   |  7 ++---
 clang/test/CodeGen/aarch64-targetattr-arch.c  |  8 --
 .../target.c  | 28 ---
 .../CodeGenCXX/aarch64-mangle-sve-vectors.cpp |  4 +--
 .../Sema/aarch64-sme2-sve2p1-diagnostics.c|  3 ++
 clang/test/Sema/arm-sve-target.cpp|  2 +-
 6 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index a612dcd4b4d03..907a05a5d1b49 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2093,16 +2093,15 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 }
 
 // Don't allow SVE types in functions without a SVE target.
-if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) {
+if (Ty->isSVESizelessBuiltinType() && FD) {
   llvm::StringMap CallerFeatureMap;
   Context.getFunctionFeatureMap(CallerFeatureMap, FD);
   if (!Builtin::evaluateRequiredTargetFeatures("sve", CallerFeatureMap)) {
 if (!Builtin::evaluateRequiredTargetFeatures("sme", CallerFeatureMap))
-  Diag(D->getLocation(), diag::err_sve_vector_in_non_sve_target) << Ty;
+  Diag(Loc, diag::err_sve_vector_in_non_sve_target) << Ty;
 else if (!IsArmStreamingFunction(FD,
  /*IncludeLocallyStreaming=*/true)) {
-  Diag(D->getLocation(), 
diag::err_sve_vector_in_non_streaming_function)
-  << Ty;
+  Diag(Loc, diag::err_sve_vector_in_non_streaming_function) << Ty;
 }
   }
 }
diff --git a/clang/test/CodeGen/aarch64-targetattr-arch.c 
b/clang/test/CodeGen/aarch64-targetattr-arch.c
index ed731d0378625..5de73d6027845 100644
--- a/clang/test/CodeGen/aarch64-targetattr-arch.c
+++ b/clang/test/CodeGen/aarch64-targetattr-arch.c
@@ -29,14 +29,18 @@ float16_t test_fp16_on_v9(float16_t x, float16_t y)
   return vabdh_f16(x, y);
 }
 
-void test_errors()
+void test_error1()
 {
 #ifdef HAS8
 // expected-error@+2{{always_inline function '__crc32cd' requires target 
feature 'crc'}}
 #endif
   __crc32cd(1, 1);
+}
+
+void test_error2()
+{
 #if defined(HAS8) || defined(HAS81)
-// expected-error@+2{{'svundef_s8' needs target feature sve}}
+// expected-error@+2{{SVE vector type 'svint8_t'

[clang] [AArch64] Extend SVE diagnostics. (PR #94976)

2024-06-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Harald van Dijk (hvdijk)


Changes

The SVE diagnostics were guarded by a FD->hasBody() check that prevented the 
diagnostic from being emitted for code that still triggered the backend crashes 
that the errors were meant to avoid, because FD->hasBody() returns false for 
a function that Clang is currently processing. This is not done for the 
equivalent RISC-V code, and is not needed for AArch64 either, so remove it.

Errors were also emitted in the wrong location, errors were emitted at the 
called function's location, rather than at the caller's, which meant that just 
removing the FD->hasBody() check resulted in incomprehensible errors. Change 
this as well.

The aarch64-mangle-sve-vectors.cpp test was using -target-feature wrong which 
was exposed as a result of these changes. Different target features need to be 
passed in as different -target-feature options.

aarch64-targetattr-arch.c has a test_errors() function that needs to be split 
in two. Now that svundef_s8() is diagnosed for its use of svint8_t, the "needs 
target feature sve" diagnostic is no longer emitted, but this affects all calls 
in the same function. To ensure we still check this for its __crc32cd call, 
move that into a separate function.

Fixes #94766.

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


6 Files Affected:

- (modified) clang/lib/Sema/Sema.cpp (+3-4) 
- (modified) clang/test/CodeGen/aarch64-targetattr-arch.c (+6-2) 
- (modified) clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/target.c 
(+18-10) 
- (modified) clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp (+2-2) 
- (modified) clang/test/Sema/aarch64-sme2-sve2p1-diagnostics.c (+3) 
- (modified) clang/test/Sema/arm-sve-target.cpp (+1-1) 


``diff
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index a612dcd4b4d03..907a05a5d1b49 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2093,16 +2093,15 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 }
 
 // Don't allow SVE types in functions without a SVE target.
-if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) {
+if (Ty->isSVESizelessBuiltinType() && FD) {
   llvm::StringMap CallerFeatureMap;
   Context.getFunctionFeatureMap(CallerFeatureMap, FD);
   if (!Builtin::evaluateRequiredTargetFeatures("sve", CallerFeatureMap)) {
 if (!Builtin::evaluateRequiredTargetFeatures("sme", CallerFeatureMap))
-  Diag(D->getLocation(), diag::err_sve_vector_in_non_sve_target) << Ty;
+  Diag(Loc, diag::err_sve_vector_in_non_sve_target) << Ty;
 else if (!IsArmStreamingFunction(FD,
  /*IncludeLocallyStreaming=*/true)) {
-  Diag(D->getLocation(), 
diag::err_sve_vector_in_non_streaming_function)
-  << Ty;
+  Diag(Loc, diag::err_sve_vector_in_non_streaming_function) << Ty;
 }
   }
 }
diff --git a/clang/test/CodeGen/aarch64-targetattr-arch.c 
b/clang/test/CodeGen/aarch64-targetattr-arch.c
index ed731d0378625..5de73d6027845 100644
--- a/clang/test/CodeGen/aarch64-targetattr-arch.c
+++ b/clang/test/CodeGen/aarch64-targetattr-arch.c
@@ -29,14 +29,18 @@ float16_t test_fp16_on_v9(float16_t x, float16_t y)
   return vabdh_f16(x, y);
 }
 
-void test_errors()
+void test_error1()
 {
 #ifdef HAS8
 // expected-error@+2{{always_inline function '__crc32cd' requires target 
feature 'crc'}}
 #endif
   __crc32cd(1, 1);
+}
+
+void test_error2()
+{
 #if defined(HAS8) || defined(HAS81)
-// expected-error@+2{{'svundef_s8' needs target feature sve}}
+// expected-error@+2{{SVE vector type 'svint8_t' (aka '__SVInt8_t') cannot be 
used in a target without sve}}
 #endif
   svundef_s8();
 }
diff --git a/clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/target.c 
b/clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/target.c
index a08c452fdc7fe..bc5f01e7ce0ff 100644
--- a/clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/target.c
+++ b/clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/target.c
@@ -18,15 +18,23 @@ void target_svebf16(svbfloat16_t t, bfloat16x8_t m) {
 }
 
 void base(int8x16_t n, bfloat16x8_t m) {
-  // expected-error@+1 {{'svundef_s8' needs target feature sve}}
-  svset_neonq_s8(svundef_s8(), n); // expected-error {{'svset_neonq_s8' needs 
target feature sve}}
-  // expected-error@+1 {{'svundef_s8' needs target feature sve}}
-  svget_neonq_s8(svundef_s8()); // expected-error {{'svget_neonq_s8' needs 
target feature sve}}
-  svdup_neonq_s8(n); // expected-error {{'svdup_neonq_s8' needs target feature 
sve}}
+  // expected-error@+3 {{SVE vector type 'svint8_t' (aka '__SVInt8_t') cannot 
be used in a target without sve}}
+  // expected-error@+2 {{SVE vector type 'svint8_t' (aka '__SVInt8_t') cannot 
be used in a target without sve}}
+  // expected-error@+1 {{SVE vector type 'svint8_t' (aka '__SVInt8_t') cannot 
be used in a target without

[clang] [ObjC] Add support for finally blocks (PR #82934)

2024-06-10 Thread via cfe-commits

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


[clang] [ObjC] Add support for finally blocks (PR #82934)

2024-06-10 Thread via cfe-commits

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


[clang] [clang] NFCI: improve TemplateArgument and TemplateName dump methods (PR #94905)

2024-06-10 Thread Matheus Izvekov via cfe-commits


@@ -360,3 +360,34 @@ LLVM_DUMP_METHOD void ConceptReference::dump(raw_ostream 
&OS) const {
   ASTDumper P(OS, Ctx, Ctx.getDiagnostics().getShowColors());
   P.Visit(this);
 }
+
+//===--===//
+// TemplateName method implementations
+//===--===//
+
+// FIXME: These are using the TemplateArgument dumper.

mizvekov wrote:

Well you are going to hit dump on a TemplateName, and it's going to dump a 
TemplateArgument of template kind, which is misleading and incorrect, but still 
helpful in the narrow context this is a debugging aid not actually used in 
production.

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


[clang] [clang] NFCI: improve TemplateArgument and TemplateName dump methods (PR #94905)

2024-06-10 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/94905

>From f918649a9208c2250873eb63641e106478371b43 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sat, 8 Jun 2024 11:07:27 -0300
Subject: [PATCH] [clang] improve TemplateArgument and TemplateName dump
 methods

These will work as AST Text node dumpers, as usual, instead of AST
printers.

Note that for now, the TemplateName dumper is using the TemplateArgument
dumper through an implicit conversion.
This can be fixed in a later pass.
---
 clang/include/clang/AST/TemplateBase.h |  2 +-
 clang/include/clang/AST/TemplateName.h |  2 +-
 clang/lib/AST/ASTDumper.cpp| 34 ++
 clang/lib/AST/TemplateBase.cpp |  9 ---
 clang/lib/AST/TemplateName.cpp | 11 -
 5 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/clang/include/clang/AST/TemplateBase.h 
b/clang/include/clang/AST/TemplateBase.h
index fea2c8ccfee67..0eaa4b0eedb35 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@ -459,7 +459,7 @@ class TemplateArgument {
  bool IncludeType) const;
 
   /// Debugging aid that dumps the template argument.
-  void dump(raw_ostream &Out) const;
+  void dump(raw_ostream &Out, const ASTContext &Context) const;
 
   /// Debugging aid that dumps the template argument to standard error.
   void dump() const;
diff --git a/clang/include/clang/AST/TemplateName.h 
b/clang/include/clang/AST/TemplateName.h
index 489fccb2ef74d..988a55acd2252 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -340,7 +340,7 @@ class TemplateName {
  Qualified Qual = Qualified::AsWritten) const;
 
   /// Debugging aid that dumps the template name.
-  void dump(raw_ostream &OS) const;
+  void dump(raw_ostream &OS, const ASTContext &Context) const;
 
   /// Debugging aid that dumps the template name to standard
   /// error.
diff --git a/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp
index c8973fdeda352..f0603880c32dd 100644
--- a/clang/lib/AST/ASTDumper.cpp
+++ b/clang/lib/AST/ASTDumper.cpp
@@ -360,3 +360,37 @@ LLVM_DUMP_METHOD void ConceptReference::dump(raw_ostream 
&OS) const {
   ASTDumper P(OS, Ctx, Ctx.getDiagnostics().getShowColors());
   P.Visit(this);
 }
+
+//===--===//
+// TemplateName method implementations
+//===--===//
+
+// FIXME: These are actually using the TemplateArgument dumper, through
+// an implicit conversion. The dump will claim this is a template argument,
+// which is misleading.
+
+LLVM_DUMP_METHOD void TemplateName::dump() const {
+  ASTDumper Dumper(llvm::errs(), /*ShowColors=*/false);
+  Dumper.Visit(*this);
+}
+
+LLVM_DUMP_METHOD void TemplateName::dump(llvm::raw_ostream &OS,
+ const ASTContext &Context) const {
+  ASTDumper Dumper(OS, Context, Context.getDiagnostics().getShowColors());
+  Dumper.Visit(*this);
+}
+
+//===--===//
+// TemplateArgument method implementations
+//===--===//
+
+LLVM_DUMP_METHOD void TemplateArgument::dump() const {
+  ASTDumper Dumper(llvm::errs(), /*ShowColors=*/false);
+  Dumper.Visit(*this);
+}
+
+LLVM_DUMP_METHOD void TemplateArgument::dump(llvm::raw_ostream &OS,
+ const ASTContext &Context) const {
+  ASTDumper Dumper(OS, Context, Context.getDiagnostics().getShowColors());
+  Dumper.Visit(*this);
+}
diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 46f7b79b272ef..2e6839e948d9d 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -577,15 +577,6 @@ void TemplateArgument::print(const PrintingPolicy &Policy, 
raw_ostream &Out,
   }
 }
 
-void TemplateArgument::dump(raw_ostream &Out) const {
-  LangOptions LO; // FIXME! see also TemplateName::dump().
-  LO.CPlusPlus = true;
-  LO.Bool = true;
-  print(PrintingPolicy(LO), Out, /*IncludeType*/ true);
-}
-
-LLVM_DUMP_METHOD void TemplateArgument::dump() const { dump(llvm::errs()); }
-
 
//===--===//
 // TemplateArgumentLoc Implementation
 
//===--===//
diff --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp
index 4fc25cb34803e..11544dbb56e31 100644
--- a/clang/lib/AST/TemplateName.cpp
+++ b/clang/lib/AST/TemplateName.cpp
@@ -360,14 +360,3 @@ const StreamingDiagnostic &clang::operator<<(const 
StreamingDiagnostic &DB,
   OS.flush();
   return DB << NameStr;
 }
-
-void TemplateName::dump(raw_ostream &OS) const {
-  LangOptions LO;  // FIXME!
-  LO.CPlusPlus = true;
-  LO.Bool = true;
-  print(OS, Pri

  1   2   3   4   5   >