[PATCH] D125693: [DebugInfo] Support types, imports and static locals declared in a lexical block (3/5)

2022-07-11 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

@dblaikie, could you please take a look at this and/or D113741 
? Do you see any ways to proceed?




Comment at: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll:23
   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 
x i8]* @__profn_foo, i32 0, i32 0), i64 12345678, i32 2, i32 0)
-  ret void
+  ret void, !dbg !17
 }

ellis wrote:
> krisb wrote:
> > ellis wrote:
> > > krisb wrote:
> > > > ellis wrote:
> > > > > I asked the same question in D113741, but why is this test changed?
> > > > Normally, we emit function-local entities iff a parent function has 
> > > > location information. This is done the same way for local variables, 
> > > > labels, parameters, imported entities, and, //now,// for static locals 
> > > > as well.
> > > > Before this change static locals behaved more like global variables and 
> > > > get emitted doesn't matter its parent function. This patch makes them 
> > > > handled more like local variables.
> > > > 
> > > > I believe either the call or the 'ret' (or, likely, both) had had 
> > > > DILocation attached originally, but it has been removed to simplify the 
> > > > test.
> > > I just checked and the `llvm.instrprof.increment` intrinsic does not have 
> > > debug info attached. I think you're right that I removed debug info from 
> > > the `ret` instruction to simplify the test.
> > > 
> > > This is a special case where a global and its debug info is synthesized.
> > > https://github.com/llvm/llvm-project/blob/23c2bedfd93cfacc62009425c464e659a34e92e6/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp#L976-L1001
> > > 
> > > So I don't understand why this added debug info is necessary. Does the 
> > > test fail otherwise?
> > Right, the test would fail w/o the added DILocation, because `__profc_foo` 
> > variable (which is function-local 'global' technically) would not be 
> > emitted. 
> > With this patch we emit function-local entities if and only if the parent 
> > function has LexicalScope defined (see createAndAddScopeChildren() and its 
> > call from constructSubprogramScopeDIE()), otherwise we skip emitting all 
> > function's children (including function-local 'globals').
> Got it, thanks for explaining!
> 
> I'm ok with this because `llvm.instrprof.increment` should probably be next 
> to some instruction with debug info.
Thank you for checking this is okay!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125693/new/

https://reviews.llvm.org/D125693

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


[PATCH] D128604: [RISCV] Support Zbpbo extension v0.9.11

2022-07-11 Thread Jim Lin via Phabricator via cfe-commits
Jim added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZb.td:471
+   Sched<[WriteCMix, ReadCMix, ReadCMix, ReadCMix]>;
 def FSR  : RVBTernaryR<0b10, 0b101, OPC_OP, "fsr", "$rd, $rs1, $rs3, $rs2">,
Sched<[WriteFSReg, ReadFSReg, ReadFSReg, ReadFSReg]>;

FSR and FSRI only exist on RV32 for Zbpbo.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZb.td:492
+
+let Predicates = [HasStdExtZbbOrZbpbo] in
 def CLZ  : RVBUnary<0b011, 0b0, 0b001, OPC_OP_IMM, "clz">,

CLZ only exist on RV32 for Zbpbo.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128604/new/

https://reviews.llvm.org/D128604

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


[PATCH] D129389: [clang][deps] Override dependency and serialized diag files for modules

2022-07-11 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

This looks pretty nice. My only concern is the ad-hoc command line parsing.




Comment at: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h:55
+  getCommandLine(llvm::function_ref<
+ Expected(const ModuleID &)>
+ LookupModuleOutputs) const;

I'm curious whether you have encountered situations where being able to return 
an error from `LookupModuleOutputs` is useful.



Comment at: clang/test/ClangScanDeps/preserved-args.c:1
 // RUN: rm -rf %t && mkdir %t
 // RUN: cp -r %S/Inputs/preserved-args/* %t

I think we can delete this test at this point, since we check both interesting 
cases in `generate-modules-path-args.c` and `removed-args.c`.

If I remember correctly, this test was originally checking that the scanner 
does not change `-MT` and friends before the scan and doesn't leak that into 
the resulting command lines.



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:297
+? llvm::cantFail(FD.getCommandLine(
+  [&](ModuleID MID) -> const ModuleOutputOptions & {
+return lookupModuleOutputs(MID);

Is my understanding correct that this lambda of type `const ModuleOutputOptions 
&(ModuleID)` gets implicitly converted to `llvm::function_ref(const ModuleID &)>`?

If so, I think it would be clearer to take the `ModuleID` by const ref here 
also and wrap the return type with `Expected`, to match the... expected 
`function_ref` type. WDYT?



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:397
+for (StringRef Arg : Args) {
+  if (Arg == "-serialize-diagnostics")
+SerializeDiags = true;

I think we should be avoiding ad-hoc command line parsing, it can be incorrect 
in many ways. Could we move this check somewhere where we have a properly 
constructed `CompilerInvocation`? I think we could do something like this in 
`ModuleDeps::getCanonicalCommandLine`:

```
if (!CI.getDiagnosticOpts().DiagnosticSerializationFile.empty())
  CI.getDiagnosticOpts().DiagnosticSerializationFile
= LookupModuleOutput(ID, ModuleOutputKind::DiagnosticSerializationFile);
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129389/new/

https://reviews.llvm.org/D129389

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


[PATCH] D95588: [RISCV] Implement the MC layer support of P extension

2022-07-11 Thread Jim Lin via Phabricator via cfe-commits
Jim added a comment.

In D95588#3622052 , @sunshaoce wrote:

> Hello @Jim! We are developing the P extension, are you still maintaining this 
> patch? Or would you mind co-development together?

Yes, I am still on developing the P extension. But it seems spec has the issue 
https://github.com/riscv/riscv-p-spec/issues/137 need to clarify.
And some instruction (CLZ, FSR and FSRI) in Zbpbo only be aliased to B 
extension on RV32. It is complicated if P extension are enabled on RV64.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95588/new/

https://reviews.llvm.org/D95588

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


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-07-11 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

@kees are you ok with current state?




Comment at: clang/lib/CodeGen/CGExpr.cpp:906
   // member, only a T[0] or T[] member gets that treatment.
+  // Under StrictFlexArraysLevel, obey c99+ that disallows FAM in union, 
see
+  // C11 6.7.2.1 §18

jyknight wrote:
> I believe this bit is incorrect -- it should just go back to 'return true;'. 
> The StrictFlexArraysLevel check above already eliminates the cases we want to 
> eliminate (size==1 in strictness-level 2.)
Well, if we are in strictness-level 2, with an undefined size or size = 0, we 
can still reach that path, and don't want to return 'true' because FAM in union 
are in invalid per the standard.



Comment at: clang/lib/StaticAnalyzer/Core/MemRegion.cpp:792
 
+  if (getContext().getLangOpts().StrictFlexArrays >= 2)
+return false;

jyknight wrote:
> Yuk, another place that is weird and doesn't handle StrictFlexArrays as 
> expected...
I've been able to slightly move that check below, without impacting test suite. 
Also added a FIXME because 
`Opts.ShouldConsiderSingleElementArraysAsFlexibleArrayMembers` looks redundant 
with `-fstrict-flex-arrays`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126864/new/

https://reviews.llvm.org/D126864

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


[PATCH] D128826: Go-to-type on smart_ptr now also shows Foo

2022-07-11 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd85d9aeef9b: Go-to-type on smart_ptr now also 
shows Foo (authored by tom-anders, committed by sammccall).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128826/new/

https://reviews.llvm.org/D128826

Files:
  clang-tools-extra/clangd/HeuristicResolver.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1786,11 +1786,11 @@
 
 TEST(FindType, All) {
   Annotations HeaderA(R"cpp(
-struct [[Target]] { operator int() const; };
+struct $Target[[Target]] { operator int() const; };
 struct Aggregate { Target a, b; };
 Target t;
 
-template  class smart_ptr {
+template  class $smart_ptr[[smart_ptr]] {
   T& operator*();
   T* operator->();
   T* get();
@@ -1829,11 +1829,11 @@
 ASSERT_GT(A.points().size(), 0u) << Case;
 for (auto Pos : A.points())
   EXPECT_THAT(findType(AST, Pos),
-  ElementsAre(sym("Target", HeaderA.range(), HeaderA.range(
+  ElementsAre(
+sym("Target", HeaderA.range("Target"), HeaderA.range("Target"
   << Case;
   }
 
-  // FIXME: We'd like these cases to work. Fix them and move above.
   for (const llvm::StringRef Case : {
"smart_ptr ^tsmart;",
}) {
@@ -1842,7 +1842,10 @@
 ParsedAST AST = TU.build();
 
 EXPECT_THAT(findType(AST, A.point()),
-Not(Contains(sym("Target", HeaderA.range(), HeaderA.range()
+UnorderedElementsAre(
+  sym("Target", HeaderA.range("Target"), HeaderA.range("Target")),
+  sym("smart_ptr", HeaderA.range("smart_ptr"), HeaderA.range("smart_ptr"))
+))
 << Case;
   }
 }
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -9,6 +9,7 @@
 #include "AST.h"
 #include "FindSymbols.h"
 #include "FindTarget.h"
+#include "HeuristicResolver.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Quality.h"
@@ -1907,38 +1908,54 @@
   return QualType();
 }
 
-// Given a type targeted by the cursor, return a type that's more interesting
+// Given a type targeted by the cursor, return one or more types that are more interesting
 // to target.
-static QualType unwrapFindType(QualType T) {
+static void unwrapFindType(
+QualType T, const HeuristicResolver* H, llvm::SmallVector& Out) {
   if (T.isNull())
-return T;
+return;
 
   // If there's a specific type alias, point at that rather than unwrapping.
   if (const auto* TDT = T->getAs())
-return QualType(TDT, 0);
+return Out.push_back(QualType(TDT, 0));
 
   // Pointers etc => pointee type.
   if (const auto *PT = T->getAs())
-return unwrapFindType(PT->getPointeeType());
+return unwrapFindType(PT->getPointeeType(), H, Out);
   if (const auto *RT = T->getAs())
-return unwrapFindType(RT->getPointeeType());
+return unwrapFindType(RT->getPointeeType(), H, Out);
   if (const auto *AT = T->getAsArrayTypeUnsafe())
-return unwrapFindType(AT->getElementType());
-  // FIXME: use HeuristicResolver to unwrap smart pointers?
+return unwrapFindType(AT->getElementType(), H, Out);
 
   // Function type => return type.
   if (auto *FT = T->getAs())
-return unwrapFindType(FT->getReturnType());
+return unwrapFindType(FT->getReturnType(), H, Out);
   if (auto *CRD = T->getAsCXXRecordDecl()) {
 if (CRD->isLambda())
-  return unwrapFindType(CRD->getLambdaCallOperator()->getReturnType());
+  return unwrapFindType(CRD->getLambdaCallOperator()->getReturnType(), H, Out);
 // FIXME: more cases we'd prefer the return type of the call operator?
 //std::function etc?
   }
 
-  return T;
+  // For smart pointer types, add the underlying type
+  if (H)
+if (const auto* PointeeType = H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
+unwrapFindType(QualType(PointeeType, 0), H, Out);
+return Out.push_back(T);
+}
+
+  return Out.push_back(T);
 }
 
+// Convenience overload, to allow calling this without the out-parameter
+static llvm::SmallVector unwrapFindType(
+QualType T, const HeuristicResolver* H) {
+llvm::SmallVector Result;
+unwrapFindType(T, H, Result);
+return Result;
+}
+
+
 std::vector findType(ParsedAST &AST, Position Pos) {
   const SourceManager &SM = AST.getSourceManager();
   auto Offset = positionToOffset(SM.getBufferData(SM.getMainFileID()), Pos);
@@ -1951,10 +1968,16 @@
   // The general scheme 

[clang-tools-extra] cd85d9a - Go-to-type on smart_ptr now also shows Foo

2022-07-11 Thread Sam McCall via cfe-commits

Author: Tom Praschan
Date: 2022-07-11T12:13:47+02:00
New Revision: cd85d9aeef9b7e3d6784f5d0be393b463ccc5c5c

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

LOG: Go-to-type on smart_ptr now also shows Foo

Fixes clangd/clangd#1026

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D128826

Added: 


Modified: 
clang-tools-extra/clangd/HeuristicResolver.h
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/HeuristicResolver.h 
b/clang-tools-extra/clangd/HeuristicResolver.h
index 26a5bc334c2c0..2b66e4bd9b8fe 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.h
+++ b/clang-tools-extra/clangd/HeuristicResolver.h
@@ -69,6 +69,11 @@ class HeuristicResolver {
   const Type *
   resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS) const;
 
+  // Given the type T of a dependent expression that appears of the LHS of a
+  // "->", heuristically find a corresponding pointee type in whose scope we
+  // could look up the name appearing on the RHS.
+  const Type *getPointeeType(const Type *T) const;
+
 private:
   ASTContext &Ctx;
 
@@ -89,11 +94,6 @@ class HeuristicResolver {
   // `E`.
   const Type *resolveExprToType(const Expr *E) const;
   std::vector resolveExprToDecls(const Expr *E) const;
-
-  // Given the type T of a dependent expression that appears of the LHS of a
-  // "->", heuristically find a corresponding pointee type in whose scope we
-  // could look up the name appearing on the RHS.
-  const Type *getPointeeType(const Type *T) const;
 };
 
 } // namespace clangd

diff  --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index fa8320ea96181..c620b3897f6de 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -9,6 +9,7 @@
 #include "AST.h"
 #include "FindSymbols.h"
 #include "FindTarget.h"
+#include "HeuristicResolver.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Quality.h"
@@ -1907,38 +1908,54 @@ static QualType typeForNode(const SelectionTree::Node 
*N) {
   return QualType();
 }
 
-// Given a type targeted by the cursor, return a type that's more interesting
+// Given a type targeted by the cursor, return one or more types that are more 
interesting
 // to target.
-static QualType unwrapFindType(QualType T) {
+static void unwrapFindType(
+QualType T, const HeuristicResolver* H, llvm::SmallVector& Out) {
   if (T.isNull())
-return T;
+return;
 
   // If there's a specific type alias, point at that rather than unwrapping.
   if (const auto* TDT = T->getAs())
-return QualType(TDT, 0);
+return Out.push_back(QualType(TDT, 0));
 
   // Pointers etc => pointee type.
   if (const auto *PT = T->getAs())
-return unwrapFindType(PT->getPointeeType());
+return unwrapFindType(PT->getPointeeType(), H, Out);
   if (const auto *RT = T->getAs())
-return unwrapFindType(RT->getPointeeType());
+return unwrapFindType(RT->getPointeeType(), H, Out);
   if (const auto *AT = T->getAsArrayTypeUnsafe())
-return unwrapFindType(AT->getElementType());
-  // FIXME: use HeuristicResolver to unwrap smart pointers?
+return unwrapFindType(AT->getElementType(), H, Out);
 
   // Function type => return type.
   if (auto *FT = T->getAs())
-return unwrapFindType(FT->getReturnType());
+return unwrapFindType(FT->getReturnType(), H, Out);
   if (auto *CRD = T->getAsCXXRecordDecl()) {
 if (CRD->isLambda())
-  return unwrapFindType(CRD->getLambdaCallOperator()->getReturnType());
+  return unwrapFindType(CRD->getLambdaCallOperator()->getReturnType(), H, 
Out);
 // FIXME: more cases we'd prefer the return type of the call operator?
 //std::function etc?
   }
 
-  return T;
+  // For smart pointer types, add the underlying type
+  if (H)
+if (const auto* PointeeType = 
H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
+unwrapFindType(QualType(PointeeType, 0), H, Out);
+return Out.push_back(T);
+}
+
+  return Out.push_back(T);
 }
 
+// Convenience overload, to allow calling this without the out-parameter
+static llvm::SmallVector unwrapFindType(
+QualType T, const HeuristicResolver* H) {
+llvm::SmallVector Result;
+unwrapFindType(T, H, Result);
+return Result;
+}
+
+
 std::vector findType(ParsedAST &AST, Position Pos) {
   const SourceManager &SM = AST.getSourceManager();
   auto Offset = positionToOffset(SM.getBufferData(SM.getMainFileID()), Pos);
@@ -1951,10 +1968,16 @@ std::vector findType(ParsedAST &AST, 
Position Pos) {
   // The general scheme is: position -> AST node -> type -> declaration.
   auto SymbolsFromNode =
   [&AST](const SelectionTree::Node *N) -> std::vector

[clang] 9f57b65 - [clangd] Include "final" when printing class declaration

2022-07-11 Thread Sam McCall via cfe-commits

Author: Tom Praschan
Date: 2022-07-11T12:20:23+02:00
New Revision: 9f57b65a272817752aa00e2fb94154e6eed1d0ec

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

LOG: [clangd] Include "final" when printing class declaration

Fixes https://github.com/clangd/clangd/issues/1184

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D128202

Added: 


Modified: 
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang/lib/AST/DeclPrinter.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 0f149b7242966..949ddbae58b3d 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -198,7 +198,7 @@ TEST(Hover, Structured) {
 typename = char,
 int = 0,
 bool Q = false,
-class... Ts> class Foo {};
+class... Ts> class Foo final {};
   template  class T>
   [[F^oo]] foo;
   )cpp",
@@ -209,7 +209,7 @@ TEST(Hover, Structured) {
  HI.Definition =
  R"cpp(template  class C, typename = 
char, int = 0,
   bool Q = false, class... Ts>
-class Foo {})cpp";
+class Foo final {})cpp";
  HI.TemplateParameters = {
  {{"template  class"},
   std::string("C"),

diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index c6a392c9c01b5..3f04d9b4073e9 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -1007,6 +1007,12 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
 }
   }
 
+  if (auto *Def = D->getDefinition()) {
+  if (D->hasAttr()) {
+  Out << " final";
+  }
+  }
+
   if (D->isCompleteDefinition()) {
 // Print the base classes
 if (D->getNumBases()) {



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


[PATCH] D128202: [clangd] Include "final" when printing class declaration

2022-07-11 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9f57b65a2728: [clangd] Include "final" when 
printing class declaration (authored by tom-anders, committed by sammccall).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128202/new/

https://reviews.llvm.org/D128202

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/lib/AST/DeclPrinter.cpp


Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -1007,6 +1007,12 @@
 }
   }
 
+  if (auto *Def = D->getDefinition()) {
+  if (D->hasAttr()) {
+  Out << " final";
+  }
+  }
+
   if (D->isCompleteDefinition()) {
 // Print the base classes
 if (D->getNumBases()) {
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -198,7 +198,7 @@
 typename = char,
 int = 0,
 bool Q = false,
-class... Ts> class Foo {};
+class... Ts> class Foo final {};
   template  class T>
   [[F^oo]] foo;
   )cpp",
@@ -209,7 +209,7 @@
  HI.Definition =
  R"cpp(template  class C, typename = 
char, int = 0,
   bool Q = false, class... Ts>
-class Foo {})cpp";
+class Foo final {})cpp";
  HI.TemplateParameters = {
  {{"template  class"},
   std::string("C"),


Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -1007,6 +1007,12 @@
 }
   }
 
+  if (auto *Def = D->getDefinition()) {
+  if (D->hasAttr()) {
+  Out << " final";
+  }
+  }
+
   if (D->isCompleteDefinition()) {
 // Print the base classes
 if (D->getNumBases()) {
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -198,7 +198,7 @@
 typename = char,
 int = 0,
 bool Q = false,
-class... Ts> class Foo {};
+class... Ts> class Foo final {};
   template  class T>
   [[F^oo]] foo;
   )cpp",
@@ -209,7 +209,7 @@
  HI.Definition =
  R"cpp(template  class C, typename = char, int = 0,
   bool Q = false, class... Ts>
-class Foo {})cpp";
+class Foo final {})cpp";
  HI.TemplateParameters = {
  {{"template  class"},
   std::string("C"),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128826: Go-to-type on smart_ptr now also shows Foo

2022-07-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D128826#3641093 , @tom-anders 
wrote:

> @sammccall I think you can merge this for me now (and also 
> https://reviews.llvm.org/D128202)

Done, sorry for the delay.

FWIW I think you should be able to get commit access 
 at this 
point, if you want it.
Cheers, Sam


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128826/new/

https://reviews.llvm.org/D128826

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


[PATCH] D129476: [AArch64][SVE] Prefer SIMD&FP variant of clast[ab]

2022-07-11 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes created this revision.
c-rhodes added reviewers: paulwalker-arm, bsmith, peterwaller-arm, DavidTruby.
Herald added subscribers: psnobl, hiraditya, kristof.beyls, tschuett.
Herald added a reviewer: efriedma.
Herald added a project: All.
c-rhodes requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

The scalar variant with GPR source/dest has considerably higher latency
than the SIMD&FP scalar variant across a variety of micro-architectures:

  Core   ScalarSIMD&FP
  
  Neoverse V1 9 cyc  3 cyc
  Neoverse N2 8 cyc  3 cyc
  Cortex A510 8 cyc  4 cyc


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129476

Files:
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clasta.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clastb.c
  llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
  llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-clast.ll

Index: llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-clast.ll
===
--- /dev/null
+++ llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-clast.ll
@@ -0,0 +1,44 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=instcombine -S < %s | FileCheck %s
+
+target triple = "aarch64"
+
+define i16 @clastb_n_i16( %pg, i16 %a,  %b) {
+; CHECK-LABEL: @clastb_n_i16(
+; CHECK-NEXT:[[TMP1:%.*]] = bitcast i16 [[A:%.*]] to half
+; CHECK-NEXT:[[TMP2:%.*]] = bitcast  [[B:%.*]] to 
+; CHECK-NEXT:[[TMP3:%.*]] = call half @llvm.aarch64.sve.clastb.n.nxv8f16( [[PG:%.*]], half [[TMP1]],  [[TMP2]])
+; CHECK-NEXT:[[TMP4:%.*]] = bitcast half [[TMP3]] to i16
+; CHECK-NEXT:ret i16 [[TMP4]]
+;
+  %out = call i16 @llvm.aarch64.sve.clastb.n.nxv8i16( %pg, i16 %a,  %b)
+  ret i16 %out
+}
+
+define i32 @clastb_n_i32( %pg, i32 %a,  %b) {
+; CHECK-LABEL: @clastb_n_i32(
+; CHECK-NEXT:[[TMP1:%.*]] = bitcast i32 [[A:%.*]] to float
+; CHECK-NEXT:[[TMP2:%.*]] = bitcast  [[B:%.*]] to 
+; CHECK-NEXT:[[TMP3:%.*]] = call float @llvm.aarch64.sve.clastb.n.nxv4f32( [[PG:%.*]], float [[TMP1]],  [[TMP2]])
+; CHECK-NEXT:[[TMP4:%.*]] = bitcast float [[TMP3]] to i32
+; CHECK-NEXT:ret i32 [[TMP4]]
+;
+  %out = call i32 @llvm.aarch64.sve.clastb.n.nxv4i32( %pg, i32 %a,  %b)
+  ret i32 %out
+}
+
+define i64 @clastb_n_i64( %pg, i64 %a,  %b) {
+; CHECK-LABEL: @clastb_n_i64(
+; CHECK-NEXT:[[TMP1:%.*]] = bitcast i64 [[A:%.*]] to double
+; CHECK-NEXT:[[TMP2:%.*]] = bitcast  [[B:%.*]] to 
+; CHECK-NEXT:[[TMP3:%.*]] = call double @llvm.aarch64.sve.clastb.n.nxv2f64( [[PG:%.*]], double [[TMP1]],  [[TMP2]])
+; CHECK-NEXT:[[TMP4:%.*]] = bitcast double [[TMP3]] to i64
+; CHECK-NEXT:ret i64 [[TMP4]]
+;
+  %out = call i64 @llvm.aarch64.sve.clastb.n.nxv2i64( %pg, i64 %a,  %b)
+  ret i64 %out
+}
+
+declare i16 @llvm.aarch64.sve.clastb.n.nxv8i16(, i16, )
+declare i32 @llvm.aarch64.sve.clastb.n.nxv4i32(, i32, )
+declare i64 @llvm.aarch64.sve.clastb.n.nxv2i64(, i64, )
Index: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -796,6 +796,44 @@
   return IC.replaceInstUsesWith(II, Extract);
 }
 
+static Optional instCombineSVECondLast(InstCombiner &IC,
+  IntrinsicInst &II) {
+  // Replace scalar integer CLAST[AB] intrinsic with optimal SIMD&FP variant.
+  IRBuilder<> Builder(II.getContext());
+  Builder.SetInsertPoint(&II);
+  Value *Pg = II.getArgOperand(0);
+  Value *Fallback = II.getArgOperand(1);
+  Value *Vec = II.getArgOperand(2);
+  Type *Ty = II.getType();
+
+  if (!Ty->isIntegerTy())
+return None;
+
+  Type *FPTy;
+  switch (cast(Ty)->getBitWidth()) {
+  default:
+return None;
+  case 16:
+FPTy = Builder.getHalfTy();
+break;
+  case 32:
+FPTy = Builder.getFloatTy();
+break;
+  case 64:
+FPTy = Builder.getDoubleTy();
+break;
+  }
+
+  Value *FPFallBack = Builder.CreateBitCast(Fallback, FPTy);
+  auto *FPVTy = VectorType::get(
+  FPTy, cast(Vec->getType())->getElementCount());
+  Value *FPVec = Builder.CreateBitCast(Vec, FPVTy);
+  auto *FPII = Builder.CreateIntrinsic(II.getIntrinsicID(), {FPVec->getType()},
+   {Pg, FPFallBack, FPVec});
+  Value *FPIItoInt = Builder.CreateBitCast(FPII, II.getType());
+  return IC.replaceInstUsesWith(II, FPIItoInt);
+}
+
 static Optional instCombineRDFFR(InstCombiner &IC,
 IntrinsicInst &II) {
   LLVMContext &Ctx = II.getContext();
@@ -1294,6 +1332,9 @@
   case Intrinsic::aarch64_sve_lasta:
   case Intrinsic::aarch64_sve_lastb:
 return instCombineSVELast(IC, II);
+  case Intrinsic::aarch64_sv

[PATCH] D128133: [Driver] Support linking to compiler-rt for target AVR

2022-07-11 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

ping ...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128133/new/

https://reviews.llvm.org/D128133

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


[PATCH] D129476: [AArch64][SVE] Prefer SIMD&FP variant of clast[ab]

2022-07-11 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes updated this revision to Diff 443594.
c-rhodes added a comment.

Add full patch context.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129476/new/

https://reviews.llvm.org/D129476

Files:
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clasta.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clastb.c
  llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
  llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-clast.ll

Index: llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-clast.ll
===
--- /dev/null
+++ llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-clast.ll
@@ -0,0 +1,44 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=instcombine -S < %s | FileCheck %s
+
+target triple = "aarch64"
+
+define i16 @clastb_n_i16( %pg, i16 %a,  %b) {
+; CHECK-LABEL: @clastb_n_i16(
+; CHECK-NEXT:[[TMP1:%.*]] = bitcast i16 [[A:%.*]] to half
+; CHECK-NEXT:[[TMP2:%.*]] = bitcast  [[B:%.*]] to 
+; CHECK-NEXT:[[TMP3:%.*]] = call half @llvm.aarch64.sve.clastb.n.nxv8f16( [[PG:%.*]], half [[TMP1]],  [[TMP2]])
+; CHECK-NEXT:[[TMP4:%.*]] = bitcast half [[TMP3]] to i16
+; CHECK-NEXT:ret i16 [[TMP4]]
+;
+  %out = call i16 @llvm.aarch64.sve.clastb.n.nxv8i16( %pg, i16 %a,  %b)
+  ret i16 %out
+}
+
+define i32 @clastb_n_i32( %pg, i32 %a,  %b) {
+; CHECK-LABEL: @clastb_n_i32(
+; CHECK-NEXT:[[TMP1:%.*]] = bitcast i32 [[A:%.*]] to float
+; CHECK-NEXT:[[TMP2:%.*]] = bitcast  [[B:%.*]] to 
+; CHECK-NEXT:[[TMP3:%.*]] = call float @llvm.aarch64.sve.clastb.n.nxv4f32( [[PG:%.*]], float [[TMP1]],  [[TMP2]])
+; CHECK-NEXT:[[TMP4:%.*]] = bitcast float [[TMP3]] to i32
+; CHECK-NEXT:ret i32 [[TMP4]]
+;
+  %out = call i32 @llvm.aarch64.sve.clastb.n.nxv4i32( %pg, i32 %a,  %b)
+  ret i32 %out
+}
+
+define i64 @clastb_n_i64( %pg, i64 %a,  %b) {
+; CHECK-LABEL: @clastb_n_i64(
+; CHECK-NEXT:[[TMP1:%.*]] = bitcast i64 [[A:%.*]] to double
+; CHECK-NEXT:[[TMP2:%.*]] = bitcast  [[B:%.*]] to 
+; CHECK-NEXT:[[TMP3:%.*]] = call double @llvm.aarch64.sve.clastb.n.nxv2f64( [[PG:%.*]], double [[TMP1]],  [[TMP2]])
+; CHECK-NEXT:[[TMP4:%.*]] = bitcast double [[TMP3]] to i64
+; CHECK-NEXT:ret i64 [[TMP4]]
+;
+  %out = call i64 @llvm.aarch64.sve.clastb.n.nxv2i64( %pg, i64 %a,  %b)
+  ret i64 %out
+}
+
+declare i16 @llvm.aarch64.sve.clastb.n.nxv8i16(, i16, )
+declare i32 @llvm.aarch64.sve.clastb.n.nxv4i32(, i32, )
+declare i64 @llvm.aarch64.sve.clastb.n.nxv2i64(, i64, )
Index: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -796,6 +796,44 @@
   return IC.replaceInstUsesWith(II, Extract);
 }
 
+static Optional instCombineSVECondLast(InstCombiner &IC,
+  IntrinsicInst &II) {
+  // Replace scalar integer CLAST[AB] intrinsic with optimal SIMD&FP variant.
+  IRBuilder<> Builder(II.getContext());
+  Builder.SetInsertPoint(&II);
+  Value *Pg = II.getArgOperand(0);
+  Value *Fallback = II.getArgOperand(1);
+  Value *Vec = II.getArgOperand(2);
+  Type *Ty = II.getType();
+
+  if (!Ty->isIntegerTy())
+return None;
+
+  Type *FPTy;
+  switch (cast(Ty)->getBitWidth()) {
+  default:
+return None;
+  case 16:
+FPTy = Builder.getHalfTy();
+break;
+  case 32:
+FPTy = Builder.getFloatTy();
+break;
+  case 64:
+FPTy = Builder.getDoubleTy();
+break;
+  }
+
+  Value *FPFallBack = Builder.CreateBitCast(Fallback, FPTy);
+  auto *FPVTy = VectorType::get(
+  FPTy, cast(Vec->getType())->getElementCount());
+  Value *FPVec = Builder.CreateBitCast(Vec, FPVTy);
+  auto *FPII = Builder.CreateIntrinsic(II.getIntrinsicID(), {FPVec->getType()},
+   {Pg, FPFallBack, FPVec});
+  Value *FPIItoInt = Builder.CreateBitCast(FPII, II.getType());
+  return IC.replaceInstUsesWith(II, FPIItoInt);
+}
+
 static Optional instCombineRDFFR(InstCombiner &IC,
 IntrinsicInst &II) {
   LLVMContext &Ctx = II.getContext();
@@ -1294,6 +1332,9 @@
   case Intrinsic::aarch64_sve_lasta:
   case Intrinsic::aarch64_sve_lastb:
 return instCombineSVELast(IC, II);
+  case Intrinsic::aarch64_sve_clasta_n:
+  case Intrinsic::aarch64_sve_clastb_n:
+return instCombineSVECondLast(IC, II);
   case Intrinsic::aarch64_sve_cntd:
 return instCombineSVECntElts(IC, II, 2);
   case Intrinsic::aarch64_sve_cntw:
Index: clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clastb.c
===
--- clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clastb.c
+++ clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clastb.c
@@ -215,14 +215,20 @@
 // CHECK-LABEL: @test_svclastb_n_s16(
 // CHECK-NEXT:  ent

[PATCH] D126586: [InstrProf][WIP] Implement boolean counters in coverage

2022-07-11 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

@davidxl and @vsk,
This is a WIP prototype implementation, and I would love to hear your early 
feedback on using 1-byte counters for coverage idea if possible.
I'll continue extending the prototype, but that would be great to learn if 
there is anything fundamentally wrong or missing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126586/new/

https://reviews.llvm.org/D126586

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


[PATCH] D129464: [Clang][CodeGen] Set FP options of builder at entry to compound statement

2022-07-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for looking into this! I happened to run into this same issue with 
`#pragma float_control` not behaving the way I'd expect. (FWIW, we also ran 
into an interesting issue where the floating point options were pushed but 
never popped in the TU were delayed template instantiation behaved differently 
than typical template instantiation.)




Comment at: clang/test/CodeGen/pragma-fenv_access.cpp:35
+}
+
+

There are some extra test cases I'd like to see coverage for because there are 
some interesting edge cases to consider.
```
template 
float func1(Ty) {
  float f1 = 1.0f, f2 = 3.0f;
  return f1 + f2 * 2.0f;
}

#pragma float_control(precise, on, push)
template float func1(int); 
#pragma float_control(pop)

#pragma float_control(precise, on, push)
template 
float func2(Ty) {
  float f1 = 1.0f, f2 = 3.0f;
  return f1 + f2 * 2.0f;
}
#pragma float_control(pop)

template float func2(int);

void bar() {
func1(1.1);
func2(1.1);
}
```
This gets especially interesting when you think about delayed template 
instantiation as happens by default on Windows targets. Consider this code with 
the *driver level* `-ffast-math` flag enabled (not the cc1 option, which is 
different).

I think that `func1` SHOULD be precise, because the explicit instantiation 
is, while `func1` SHOULD NOT be precise, because the definition is not. 
`func2` SHOULD NOT be precise, because the explicit instantiation is not, 
while `func2` SHOULD be precise,  because the definition is.

Partial specializations are a similar situation where the primary template and 
its related code made have different options.

WDYT?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129464/new/

https://reviews.llvm.org/D129464

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


[PATCH] D128535: [analyzer] Improve loads from reinterpret-cast fields

2022-07-11 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM (given that you remove the vague and disturbing FIXME comments).




Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:2014-2017
+  // FIXME: This is a hack, and doesn't do anything really intelligent yet.
+  // FIXME: This hack is analogous with the one present in
+  // `getBindingForElement`, maybe we should handle both in
+  // `getBindingForFieldOrElementCommon`.

steakhal wrote:
> martong wrote:
> > Could you please elaborate why this is a hack? What should be done and 
> > where to solve it properly? (Disclaimer, I did not look into 
> > `getBindingForFieldOrElementCommon`.)
> I'm not sure what Jordan was actually referring to. IMO hardcoding to look 
> for a highly specific scenario (a typed memregion, and a symbol to be exact) 
> could be thought about implementing a 'hack'. IMO this fits in the current 
> ecosystem, so for me it doesn't look like a hack; hence IMO this is the way 
> of implementing this.
> 
> To make it clear, I simply hoisted the nested `dyn_cast`s and checks into a 
> function, while preserved the 'hack' comment at the callsite; so it's not 
> added by me.
> 
> One additional note. We relay on the type information embedded into the 
> memregion - which we know might not always be present and even accurate. That 
> could be another reason why this should be considered as a 'hack'. IDK
Okay, thanks for the detailed explanation. So, seems like these `FIXME` 
comments are vague and they do not add any meaningful information, they are 
just disturbing noise. Could you please remove them?

Other than that, your change makes perfect sense to me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128535/new/

https://reviews.llvm.org/D128535

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


[PATCH] D128411: [syntax] Introduce a BaseToken class.

2022-07-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:24
 
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Token.h"

I think Token and TokenKinds are also no longer needed?



Comment at: clang/include/clang/Tooling/Syntax/SyntaxTokenManager.h:20
+/// It tracks the underlying token buffers, source manager, etc.
+class SyntaxTokenManager : public TokenManager {
+public:

I don't think "syntax" in "syntax token manager" is particularly disambiguating 
here, both TokenBuffer and TokenManager are part of syntax, so it's not clear 
what it refers to (and it doens't have any obvious plain-english meaning).

Maybe some combination like `TokenBufferTokenManager` or `BufferTokenManager`.
In fact I think best is `TokenBuffer::TokenManager`, still defined in a 
separate header, though I'm not sure if you think that's too weird.



Comment at: clang/include/clang/Tooling/Syntax/TokenManager.h:14
+// implementation. It enables producers (e.g. clang pseudoparser) to produce a
+// syntax-tree with a different underlying token implementation.
+//

unclear: different from what? it's not clear what "enables" means if there's no 
default. Maybe replace the sentence with:

"For example, a TokenBuffer captured from a clang parse may track macro 
expansions and associate tokens with clang's SourceManager, while a 
pseudo-parser would use a flat array of raw-lexed tokens in memory."



Comment at: clang/include/clang/Tooling/Syntax/TokenManager.h:38
+  using Key = uintptr_t;
+  /// Gets the text of token identified by the key.
+  virtual llvm::StringRef getText(Key K) const = 0;

This is not a useful comment, either remove it or add more content to make it 
useful.

In particular the guarantees (or lack thereof) of exactly what this text is 
would be helpful. (This is some source code that would produce this token, 
though it may differ from exactly what was spelled in the file when 
preprocessing is involved)?



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:9
 // Defines the basic structure of the syntax tree. There are two kinds of 
nodes:
-//   - leaf nodes correspond to a token in the expanded token stream,
+//   - leaf nodes correspond to a token key in the token manager
 //   - tree nodes correspond to language grammar constructs.

this is an implementation detail.
At a high level, leaf nodes correspond to tokens. I'd just delete "expanded" 
from the original comment



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:46
 private:
-  SourceManager &SourceMgr;
-  const LangOptions &LangOpts;
-  const TokenBuffer &Tokens;
-  /// IDs and storage for additional tokenized files.
-  llvm::DenseMap> ExtraTokens;
+  // Manage all token-related stuff.
+  TokenManager& TokenMgr;

this is not a helpful comment, just remove it?



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:370
+  TreeBuilder(syntax::Arena &Arena)
+  : Arena(Arena), STM(cast(Arena.getTokenManager())),
+Pending(Arena, STM.tokenBuffer()) {

need changes to the public API to make this cast valid



Comment at: clang/lib/Tooling/Syntax/ComputeReplacements.cpp:94
 const syntax::TranslationUnit &TU) {
-  const auto &Buffer = A.getTokenBuffer();
-  const auto &SM = A.getSourceManager();
+  const auto &STM = llvm::cast(A.getTokenManager());
+  const auto &Buffer = STM.tokenBuffer();

Need a change to the public interface to guarantee this cast will succeed.
The cleanest would be just to take the SyntaxTokenManager as a param (moving 
the cast to the call site - I don't think Arena is otherwise used for anything).

Failing that we at least need to update the contract


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128411/new/

https://reviews.llvm.org/D128411

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


[PATCH] D125625: Implementation of '#pragma STDC FENV_ROUND'

2022-07-11 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 443606.
sepavloff added a comment.

Rebased and addressed reviever's comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125625/new/

https://reviews.llvm.org/D125625

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Parse/ParsePragma.cpp
  clang/test/CodeGen/complex-strictfp.c
  clang/test/CodeGen/pragma-fenv_round.c
  clang/test/CodeGen/pragma-fenv_round.cpp
  clang/test/Parser/pragma-fenv_round.c

Index: clang/test/Parser/pragma-fenv_round.c
===
--- clang/test/Parser/pragma-fenv_round.c
+++ clang/test/Parser/pragma-fenv_round.c
@@ -6,6 +6,5 @@
   if (x)
 return y + 2;
   #pragma STDC FENV_ROUND FE_DOWNWARD // expected-error{{'#pragma STDC FENV_ROUND' can only appear at file scope or at the start of a compound statement}}
-  // expected-warning@-1{{pragma STDC FENV_ROUND is not supported}}
   return x + y;
 }
Index: clang/test/CodeGen/pragma-fenv_round.cpp
===
--- /dev/null
+++ clang/test/CodeGen/pragma-fenv_round.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -S -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+#pragma STDC FENV_ROUND FE_DOWNWARD
+
+float func_01(float x, float y, float z = 1.0f/3.0f) {
+  return x + y + z;
+}
+// CHECK-LABEL: @_Z7func_01fff
+// CHECK: call void @llvm.set.rounding(i32 3)
+// CHECK: call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata !"round.downward", metadata !"fpexcept.ignore")
+// CHECK: call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata !"round.downward", metadata !"fpexcept.ignore")
+// CHECK: call void @llvm.set.rounding(i32 1)
+
+float func_02() {
+#pragma STDC FENV_ROUND FE_UPWARD
+  return func_01(1.0f, 2.0f);
+}
+// CHECK-LABEL: @_Z7func_02v
+// CHECK: call void @llvm.set.rounding(i32 2)
+// CHECK: call float @llvm.experimental.constrained.fdiv.f32(float 1.00e+00, float 3.00e+00, metadata !"round.downward", metadata !"fpexcept.ignore")
+// CHECK: call noundef float @_Z7func_01fff(float noundef 1.00e+00, float noundef 2.00e+00, float noundef {{.*}})
+// CHECK: call void @llvm.set.rounding(i32 1)
+
+float func_03(float x, float y, float z = 1.0f/3.0f) {
+#pragma STDC FENV_ROUND FE_TOWARDZERO
+  return x + y + z;
+}
+// CHECK-LABEL: @_Z7func_03fff
+// CHECK: call void @llvm.set.rounding(i32 0)
+// CHECK: call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata !"round.towardzero", metadata !"fpexcept.ignore")
+// CHECK: call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata !"round.towardzero", metadata !"fpexcept.ignore")
+// CHECK: call void @llvm.set.rounding(i32 1)
+
+float func_04() {
+#pragma STDC FENV_ROUND FE_UPWARD
+  return func_01(1.0f, 2.0f);
+}
+// CHECK-LABEL: @_Z7func_04v
+// CHECK: call void @llvm.set.rounding(i32 2)
+// CHECK: call float @llvm.experimental.constrained.fdiv.f32(float 1.00e+00, float 3.00e+00, metadata !"round.downward", metadata !"fpexcept.ignore")
+// CHECK: call noundef float @_Z7func_01fff(float noundef 1.00e+00, float noundef 2.00e+00, float noundef {{.*}})
+// CHECK: call void @llvm.set.rounding(i32 1)
Index: clang/test/CodeGen/pragma-fenv_round.c
===
--- /dev/null
+++ clang/test/CodeGen/pragma-fenv_round.c
@@ -0,0 +1,205 @@
+// RUN: %clang_cc1 -S -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+float default_mode = 1.0f / 3.0f;
+// CHECK: @default_mode = global float 0x3FD56000
+
+#pragma STDC FENV_ROUND FE_UPWARD
+float upward = 1.0f / 3.0f;
+// CHECK: @upward = global float 0x3FD56000
+
+#pragma STDC FENV_ROUND FE_DOWNWARD
+float downward = 1.0f / 3.0f;
+// CHECK: @downward = global float 0x3FD54000
+
+#pragma STDC FENV_ROUND FE_DYNAMIC
+float dynamic = 1.0f / 3.0f;
+// CHECK: @dynamic = global float 0x3FD56000
+
+#pragma STDC FENV_ROUND FE_TONEAREST
+
+
+float func_1(float w, float x, float y, float z) {
+  #pragma STDC FENV_ROUND FE_TOWARDZERO
+  float result = x * y;
+  {
+#pragma STDC FENV_ROUND FE_UPWARD
+result += z;
+  }
+  return result - w;
+}
+
+// CHECK-LABEL: @func_1
+// CHECK:  call void @llvm.set.rounding(i32 0)
+// CHECK:  call float @llvm.experimental.constrained.fmul.f32({{.*}}, metadata !"round.towardzero", metadata !"fpexcept.ignore")
+// CHECK:  call void @llvm.set.rounding(i32 2)
+// CHECK:  call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata !"round.upward", metadata !"fpexcept.ignore")
+// CHECK:  call void @llvm.set.rounding(i32 0)
+// CHECK:  call float @llvm.experimental.constrained.fsub.f32({{.*}}, metadata !"round.towardzero", metadata !"fpexcept.ignore")
+// CHECK:  call void @llvm.set.rounding(i32 1)
+
+
+float func_2(float w

[PATCH] D128712: [clang-format] Handle Verilog modules

2022-07-11 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 443605.
sstwcw edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128712/new/

https://reviews.llvm.org/D128712

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/TokenAnnotator.h
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -894,6 +894,13 @@
   ASSERT_EQ(Tokens.size(), 7u);
   EXPECT_TOKEN(Tokens[1], tok::colon, TT_VerilogBlockLabelColon);
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_VerilogBlockLabelColon);
+  // Test that the dimension colon is annotated correctly.
+  Tokens = Annotate("var [1 : 0] x;");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::colon, TT_BitFieldColon);
+  Tokens = Annotate("extern function [1 : 0] x;");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_BitFieldColon);
 }
 
 } // namespace
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -139,6 +139,75 @@
 "x = x;"));
 }
 
+TEST_F(FormatTestVerilog, Hierarchy) {
+  verifyFormat("module x;\n"
+   "endmodule");
+  // Test that the end label is on the same line as the end keyword.
+  verifyFormat("module x;\n"
+   "endmodule : x");
+  // Test that things inside are indented.
+  verifyFormat("module x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endmodule");
+  verifyFormat("program x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endprogram");
+  verifyFormat("interface x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endinterface");
+  verifyFormat("task x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endtask");
+  verifyFormat("function x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endfunction");
+  verifyFormat("class x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endclass");
+  // Test that they nest.
+  verifyFormat("module x;\n"
+   "  program x;\n"
+   "program x;\n"
+   "endprogram\n"
+   "  endprogram\n"
+   "endmodule");
+  // Test that an extern declaration doesn't change the indentation.
+  verifyFormat("extern module x;\n"
+   "x = x;");
+  // Test complex headers
+  verifyFormat("extern module x\n"
+   "import x.x::x::*;\n"
+   "import x;\n"
+   "#(parameter x)\n"
+   "(output x);");
+  verifyFormat("module x\n"
+   "import x.x::x::*;\n"
+   "import x;\n"
+   "#(parameter x)\n"
+   "(output x);\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endmodule : x");
+  verifyFormat("virtual class x\n"
+   "(x)\n"
+   "extends x(x)\n"
+   "implements x, x, x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endclass : x\n");
+  verifyFormat("function automatic logic [1 : 0] x\n"
+   "(input x);\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endfunction : x");
+}
+
 TEST_F(FormatTestVerilog, If) {
   verifyFormat("if (x)\n"
"  x = x;");
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -48,6 +48,10 @@
 
   bool MustBeDeclaration;
 
+  /// \c True if this line should be indented by ContinuationIndent in
+  /// addition to the normal indention level.
+  bool IsContinuation = false;
+
   /// If this \c UnwrappedLine closes a block in a sequence of lines,
   /// \c MatchingOpeningBlockLineIndex stores the index of the corresponding
   /// opening line. Otherwise, \c MatchingOpeningBlockLineIndex must be
@@ -173,6 +177,11 @@
   bool tryToParsePropertyAccessor();
   void tryToParseJSFunction();
   bool tryToParseSimpleAttribute();
+  void parseVerilogHierarchyIdentifier();
+  void parseVerilogSensitivityList();
+  // Returns the number of levels of indentation in addition to the normal 1
+  // level for a block, use

[PATCH] D129398: [ASTMatchers] Add a new matcher for callee declarations of Obj-C message expressions

2022-07-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:3841
 
+/// matches if ObjCMessageExpr's callee declaration matches
+///

NoQ wrote:
> Nitpick carryover: needs capital letter and `.`
Don't forget to regen the docs when you fix this, too. :-)



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:3853
+/// objcMessageExpr(objcMessageCallee(objcMethodDecl(hasName("foo"
+AST_MATCHER_P(ObjCMessageExpr, objcMessageCallee,
+  internal::Matcher, InnerMatcher) {

Is there a reason why we want a separate matcher here instead of overloading 
`callee()`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129398/new/

https://reviews.llvm.org/D129398

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


[PATCH] D128713: [clang-format] Handle Verilog user-defined primitives

2022-07-11 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 443607.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128713/new/

https://reviews.llvm.org/D128713

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -441,5 +441,46 @@
   }
 }
 
+TEST_F(FormatTestVerilog, Primitive) {
+  verifyFormat("primitive multiplexer\n"
+   "(mux, control, dataA, dataB);\n"
+   "  output mux;\n"
+   "  input control, dataA, dataB;\n"
+   "  table\n"
+   "0 1 ? : 1;\n"
+   "0 0 ? : 0;\n"
+   "1 ? 1 : 1;\n"
+   "1 ? 0 : 0;\n"
+   "x 0 0 : 0;\n"
+   "x 1 1 : 1;\n"
+   "  endtable\n"
+   "endprimitive");
+  verifyFormat("primitive latch\n"
+   "(q, ena_, data);\n"
+   "  output q;\n"
+   "  reg q;\n"
+   "  input ena_, data;\n"
+   "  table\n"
+   "0 1 : ? : 1;\n"
+   "0 0 : ? : 0;\n"
+   "1 ? : ? : -;\n"
+   "? * : ? : -;\n"
+   "  endtable\n"
+   "endprimitive");
+  verifyFormat("primitive d\n"
+   "(q, clock, data);\n"
+   "  output q;\n"
+   "  reg q;\n"
+   "  input clock, data;\n"
+   "  table\n"
+   "(01) 0 : ? : 0;\n"
+   "(01) 1 : ? : 1;\n"
+   "(0?) 1 : 1 : 1;\n"
+   "(0?) 0 : 0 : 0;\n"
+   "(?0) ? : ? : -;\n"
+   "(?\?) ? : ? : -;\n"
+   "  endtable\n"
+   "endprimitive");
+}
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -182,6 +182,7 @@
   // Returns the number of levels of indentation in addition to the normal 1
   // level for a block, used for indenting case labels.
   unsigned parseVerilogHierarchyHeader();
+  void parseVerilogTable();
 
   // Used by addUnwrappedLine to denote whether to keep or remove a level
   // when resetting the line state.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1913,6 +1913,10 @@
   }
 
   if (Style.isVerilog()) {
+if (FormatTok->is(Keywords.kw_table)) {
+  parseVerilogTable();
+  return;
+}
 if (Keywords.isVerilogBegin(*FormatTok) ||
 Keywords.isVerilogHierarchy(*FormatTok)) {
   parseBlock();
@@ -4151,6 +4155,25 @@
   return AddLevels;
 }
 
+void UnwrappedLineParser::parseVerilogTable() {
+  assert(FormatTok->is(Keywords.kw_table));
+  nextToken(/*LevelDifference=*/1);
+  addUnwrappedLine();
+
+  auto InitialLevel = Line->Level++;
+  while (!eof() && !Keywords.isVerilogEnd(*FormatTok)) {
+FormatToken *Tok = FormatTok;
+nextToken();
+if (Tok->is(tok::semi))
+  addUnwrappedLine();
+else if (Tok->isOneOf(tok::star, tok::colon, tok::question, tok::minus))
+  Tok->setFinalizedType(TT_VerilogTableItem);
+  }
+  Line->Level = InitialLevel;
+  nextToken(/*LevelDifference=*/-1);
+  addUnwrappedLine();
+}
+
 LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine &Line,
  StringRef Prefix = "") {
   llvm::dbgs() << Prefix << "Line(" << Line.Level
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -917,6 +917,10 @@
   bool consumeToken() {
 FormatToken *Tok = CurrentToken;
 next();
+// In Verilog primitives' state tables, `:`, `?`, and `-` aren't normal
+// operators.
+if (Tok->is(TT_VerilogTableItem))
+  return true;
 switch (Tok->Tok.getKind()) {
 case tok::plus:
 case tok::minus:
@@ -3982,8 +3986,16 @@
   return true;
 }
   } else if (Style.isVerilog()) {
+// Add space between things in a primitive's state table unless in a
+// transition like `(0?)`.
+if ((Left.is(TT_VerilogTableItem) &&
+ !Right.isOneOf(tok::r_paren, tok::semi)) ||
+(Right.is(TT_VerilogTableItem) && Left.isNot(tok::l_paren))) {
+  const FormatToken *Next = Right.getNextNonComment();
+  retu

[PATCH] D128714: [clang-format] Handle Verilog case statements

2022-07-11 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 443608.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128714/new/

https://reviews.llvm.org/D128714

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -901,6 +901,21 @@
   Tokens = Annotate("extern function [1 : 0] x;");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_BitFieldColon);
+  // Test case labels and ternary operators.
+  Tokens = Annotate("case (x)\n"
+"  x:\n"
+"x;\n"
+"endcase\n");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_GotoLabelColon);
+  Tokens = Annotate("case (x)\n"
+"  x ? x : x:\n"
+"x;\n"
+"endcase\n");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::question, TT_ConditionalExpr);
+  EXPECT_TOKEN(Tokens[7], tok::colon, TT_ConditionalExpr);
+  EXPECT_TOKEN(Tokens[9], tok::colon, TT_GotoLabelColon);
 }
 
 } // namespace
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -116,6 +116,90 @@
"x = x;");
 }
 
+TEST_F(FormatTestVerilog, Case) {
+  verifyFormat("case (data)\n"
+   "endcase");
+  verifyFormat("casex (data)\n"
+   "endcase");
+  verifyFormat("casez (data)\n"
+   "endcase");
+  verifyFormat("case (data) inside\n"
+   "endcase");
+  verifyFormat("case (data)\n"
+   "  16'd0:\n"
+   "result = 10'b01;\n"
+   "endcase");
+  verifyFormat("case (data)\n"
+   "  :\n"
+   "result = 10'b01;\n"
+   "endcase");
+  // Test labels with multiple options.
+  verifyFormat("case (data)\n"
+   "  16'd0, 16'd1:\n"
+   "result = 10'b01;\n"
+   "endcase");
+  verifyFormat("case (data)\n"
+   "  16'd0, //\n"
+   "  16'd1:\n"
+   "result = 10'b01;\n"
+   "endcase");
+  // Test that blocks following labels are indented.
+  verifyFormat("case (data)\n"
+   "  16'd1: fork\n"
+   "result = 10'b10;\n"
+   "  join\n"
+   "endcase\n");
+  verifyFormat("case (data)\n"
+   "  16'd1: fork : x\n"
+   "result = 10'b10;\n"
+   "  join : x\n"
+   "endcase\n");
+  // Test default.
+  verifyFormat("case (data)\n"
+   "  default\n"
+   "result = 10'b10;\n"
+   "endcase");
+  verifyFormat("case (data)\n"
+   "  default:\n"
+   "result = 10'b10;\n"
+   "endcase");
+  // Test that question marks and colons don't get mistaken as labels.
+  verifyFormat("case (data)\n"
+   "  8'b1???:\n"
+   "instruction1(ir);\n"
+   "endcase");
+  verifyFormat("case (data)\n"
+   "  x ? 8'b1??? : 1:\n"
+   "instruction3(ir);\n"
+   "endcase");
+  // Test indention options.
+  auto Style = getLLVMStyle(FormatStyle::LK_Verilog);
+  Style.IndentCaseLabels = false;
+  verifyFormat("case (data)\n"
+   "16'd0:\n"
+   "  result = 10'b01;\n"
+   "endcase",
+   Style);
+  verifyFormat("case (data)\n"
+   "16'd0: begin\n"
+   "  result = 10'b01;\n"
+   "end\n"
+   "endcase",
+   Style);
+  Style.IndentCaseLabels = true;
+  verifyFormat("case (data)\n"
+   "  16'd0:\n"
+   "result = 10'b01;\n"
+   "endcase",
+   Style);
+  verifyFormat("case (data)\n"
+   "  16'd0: begin\n"
+   "result = 10'b01;\n"
+   "  end\n"
+   "endcase",
+   Style);
+}
+
 TEST_F(FormatTestVerilog, Delay) {
   // Delay by the default unit.
   verifyFormat("#0;");
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -183,6 +183,7

[PATCH] D129353: [clang-tidy] Improve check cert-dcl58-cpp.

2022-07-11 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 443609.
balazske marked 2 inline comments as done.
balazske added a comment.

address review comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129353/new/

https://reviews.llvm.org/D129353

Files:
  clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst
  
clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h
  clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s cert-dcl58-cpp %t -- -- -std=c++1z -I %clang_tidy_headers
+// RUN: %check_clang_tidy -std=c++17-or-later %s cert-dcl58-cpp %t -- -- -I %clang_tidy_headers
 
 #include "system-header-simulation.h"
 
@@ -15,14 +15,20 @@
 }
 
 namespace posix {
-// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: modification of 'posix' namespace can result in undefined behavior [cert-dcl58-cpp]
-  namespace vmi {
-  }
+// CHECK-MESSAGES: :[[@LINE+2]]:11: warning: modification of 'posix' namespace can result in undefined behavior [cert-dcl58-cpp]
+// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'posix' namespace opened here
+namespace foo {
+int foobar;
+}
 }
 
 namespace std {
-// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: modification of 'std' namespace can
-  int stdInt;
+// CHECK-MESSAGES: :[[@LINE+2]]:5: warning: modification of 'std' namespace
+// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'std' namespace opened here
+int stdInt;
+// CHECK-MESSAGES: :[[@LINE+2]]:5: warning: modification of 'std' namespace
+// CHECK-MESSAGES: :[[@LINE-5]]:11: note: 'std' namespace opened here
+int stdInt1;
 }
 
 namespace foobar {
@@ -31,37 +37,231 @@
   }
 }
 
+namespace posix {
+// CHECK-MESSAGES: :[[@LINE+2]]:11: warning: modification of 'posix' namespace
+// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'posix' namespace opened here
+namespace std {
+}
+} // namespace posix
+
 namespace posix::a {
-// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: modification of 'posix' namespace 
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: modification of 'posix' namespace
+// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'posix' namespace opened here
 }
 
+namespace std {
+// no-warning: empty
+} // namespace std
+
+namespace std {
+// Warn for non-NamedDecls as well.
+// CHECK-MESSAGES: :[[@LINE+2]]:1: warning: modification of 'std' namespace
+// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here
+static_assert(1 == 1, "non-NamedDecl");
+} // namespace std
+
 enum class MyError {
   ErrorA,
   ErrorB
 };
 
 namespace std {
+// no-warning: Class template specialized by a program-defined type.
 template <>
 struct is_error_code_enum : std::true_type {};
 
+// no-warning: Function template specialized by a program-defined type.
 template<>
 void swap(MyError &a, MyError &b);
 }
 
-enum class MyError2 {
-  Error2A,
-  Error2B
-};
+using ConstBoolPtr = const bool *;
 
 namespace std {
-// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: modification of 'std' namespace 
+// class template, builtin type
+// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace
+// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here
+template <>
+struct is_error_code_enum : std::true_type {};
+// function template, builtin type
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: modification of 'std' namespace
+// CHECK-MESSAGES: :[[@LINE-8]]:11: note: 'std' namespace opened here
 template <>
-struct is_error_code_enum : std::true_type {};
+void swap(bool &, bool &);
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: modification of 'std' namespace
+// CHECK-MESSAGES: :[[@LINE-12]]:11: note: 'std' namespace opened here
+template <>
+void swap(ConstBoolPtr &, ConstBoolPtr &);
+} // namespace std
 
-int foobar;
+namespace std {
+// class template, std type
+// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace
+// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here
+template <>
+struct is_error_code_enum : std::true_type {};
+// function template, std type
+// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: modification of 'std' namespace
+// CHECK-MESSAGES: :[[@LINE-8]]:11: note: 'std' namespace opened here
+template <>
+void swap(std::io_errc &, std::io_errc &);
+} // namespace std
+
+// parameter pack, has program-defined type
+namespace std {
+// no-warning: there is one program-defined type.
+template <>
+class tuple {};
+} // namespace std
+
+// parameter pack, only builtin or std type
+namespace std {
+// Forbid variadic specializations over only `std::` or builtin types.
+// CHECK-MESSAGES: :[[@LINE+3]]:7: warning: modification 

[PATCH] D129269: [analyzer] Fix use of length in CStringChecker

2022-07-11 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Thanks Vince for the patch! I think the implementation is correct. But I am 
worried that it might do sub-optimal computations on the string literals. I 
mean, getting the length would require O(N) steps each time, and that could be 
problematic with long literals, especially in projects that have many literals.

So, I'd rather keep your first implementation with `getLength` with the new 
test case which fails (and the failure is documented). I think, this is what 
@steakhal was also suggesting.

Then, if your time allows, in a second patch, we could have the loop based 
implementation for catching embedded null terminators. However, that change 
should have it's own measurement and maybe even it's own command line option to 
enable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129269/new/

https://reviews.llvm.org/D129269

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


[PATCH] D128709: [clang-format] Handle Verilog attributes

2022-07-11 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 443611.
sstwcw added a comment.

- don't check peeked token for null


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128709/new/

https://reviews.llvm.org/D128709

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestVerilog.cpp


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -71,6 +71,12 @@
 TEST_F(FormatTestVerilog, If) {
   verifyFormat("if (x)\n"
"  x = x;");
+  verifyFormat("unique if (x)\n"
+   "  x = x;");
+  verifyFormat("unique0 if (x)\n"
+   "  x = x;");
+  verifyFormat("priority if (x)\n"
+   "  x = x;");
   verifyFormat("if (x)\n"
"  x = x;\n"
"x = x;");
@@ -137,6 +143,14 @@
"  x = {x};\n"
"else\n"
"  {x} = {x};");
+
+  // With attributes.
+  verifyFormat("(* x *) if (x)\n"
+   "  x = x;");
+  verifyFormat("(* x = \"x\" *) if (x)\n"
+   "  x = x;");
+  verifyFormat("(* x, x = \"x\" *) if (x)\n"
+   "  x = x;");
 }
 
 TEST_F(FormatTestVerilog, Preprocessor) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1457,6 +1457,23 @@
 addUnwrappedLine();
 return;
   }
+
+  if (Style.isVerilog()) {
+// Skip things that can exist before keywords like 'if' and 'case'.
+while (true) {
+  if (FormatTok->isOneOf(Keywords.kw_priority, Keywords.kw_unique,
+ Keywords.kw_unique0)) {
+nextToken();
+  } else if (FormatTok->is(tok::l_paren) &&
+ Tokens->peekNextToken()->is(tok::star)) {
+parseParens();
+  } else {
+break;
+  }
+}
+  }
+
+  // Tokens that only make sense at the beginning of a line.
   switch (FormatTok->Tok.getKind()) {
   case tok::kw_asm:
 nextToken();
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3982,6 +3982,9 @@
   Left.MatchingParen->endsSequence(tok::l_paren, tok::at {
   return true;
 }
+// Add space in attribute like `(* ASYNC_REG = "TRUE" *)`.
+if (Left.endsSequence(tok::star, tok::l_paren) && 
Right.is(tok::identifier))
+  return true;
   }
   if (Left.is(TT_ImplicitStringLiteral))
 return Right.hasWhitespaceBefore();


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -71,6 +71,12 @@
 TEST_F(FormatTestVerilog, If) {
   verifyFormat("if (x)\n"
"  x = x;");
+  verifyFormat("unique if (x)\n"
+   "  x = x;");
+  verifyFormat("unique0 if (x)\n"
+   "  x = x;");
+  verifyFormat("priority if (x)\n"
+   "  x = x;");
   verifyFormat("if (x)\n"
"  x = x;\n"
"x = x;");
@@ -137,6 +143,14 @@
"  x = {x};\n"
"else\n"
"  {x} = {x};");
+
+  // With attributes.
+  verifyFormat("(* x *) if (x)\n"
+   "  x = x;");
+  verifyFormat("(* x = \"x\" *) if (x)\n"
+   "  x = x;");
+  verifyFormat("(* x, x = \"x\" *) if (x)\n"
+   "  x = x;");
 }
 
 TEST_F(FormatTestVerilog, Preprocessor) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1457,6 +1457,23 @@
 addUnwrappedLine();
 return;
   }
+
+  if (Style.isVerilog()) {
+// Skip things that can exist before keywords like 'if' and 'case'.
+while (true) {
+  if (FormatTok->isOneOf(Keywords.kw_priority, Keywords.kw_unique,
+ Keywords.kw_unique0)) {
+nextToken();
+  } else if (FormatTok->is(tok::l_paren) &&
+ Tokens->peekNextToken()->is(tok::star)) {
+parseParens();
+  } else {
+break;
+  }
+}
+  }
+
+  // Tokens that only make sense at the beginning of a line.
   switch (FormatTok->Tok.getKind()) {
   case tok::kw_asm:
 nextToken();
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3982,6 +3982,9 @@
   Left.MatchingParen->endsSequence(tok::l_paren, tok::at {
   return true;
 }
+

[PATCH] D125625: Implementation of '#pragma STDC FENV_ROUND'

2022-07-11 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: clang/lib/CodeGen/CGStmt.cpp:488
+  }
+  if (NewRM != llvm::RoundingMode::Dynamic)
+Builder.CreateIntrinsic(

aaron.ballman wrote:
> I was imagining that if the new rounding mode is dynamic, we still need to 
> reset the rounding mode back to what it was when the thread was created or to 
> the previous rounding mode set by a library call, but now I'm not certain. I 
> commented on one of the test cases about what I was thinking.
Yes, it is required by the standard draft (7.6.2p2):
```
... at the end of a compound statement the static rounding
mode is restored to its condition just before the compound statement.
```
Rounding mode is not set if FE_DYNAMIC is in effect, but it is restored upon 
leaving such region, see test func_4 in pragma-fenv_round.c.



Comment at: clang/test/CodeGen/pragma-fenv_round.c:54-55
+// CHECK:  call float @llvm.experimental.constrained.fmul.f32({{.*}}, metadata 
!"round.towardzero", metadata !"fpexcept.ignore")
+// CHECK:  call void @llvm.set.rounding(i32 1)
+// CHECK:  call float @llvm.experimental.constrained.fadd.f32({{.*}}, metadata 
!"round.tonearest", metadata !"fpexcept.ignore")
+// CHECK:  call void @llvm.set.rounding(i32 0)

aaron.ballman wrote:
> I was trying to figure out whether this was correct or not when I was looking 
> at the codegen logic. C2x 7.6.2p3 says "... If no FENV_ROUND pragma is in 
> effect, or the specified constant rounding mode is FE_DYNAMIC, rounding is 
> according to the mode specified by the dynamic floating-point environment, 
> which is the dynamic rounding mode that was established either at thread 
> creation time or by a call to fesetround, fesetmode, fesetenv, or 
> feupdateenv. ..." p2 says: "... When outside external declarations, the 
> pragma takes effect from its occurrence until another FENV_ROUND pragma is 
> encountered, or until the end of the translation unit. When inside a compound 
> statement, the pragma takes effect from its first occurrence until another 
> FENV_ROUND pragma is encountered (including within a nested compound 
> statement), or until the end of the compound statement; ...". Finally, p4 
> says: "... Within the scope of an FENV_ROUND pragma establishing a mode other 
> than FE_DYNAMIC, ... shall be evaluated according to the specified constant 
> rounding mode (as though no constant mode was specified and the corresponding 
> dynamic rounding mode had been established by a call to fesetround)."
> 
> I *think* this means that the rounding mode for `result += z;` should 
> actually be `FE_TOWARDZERO`, but I'm not 100% sure. We enter the compound 
> statement for the function body, then we enter a constant rounding mode of 
> FE_TOWARDZERO. Then we get into a new nested compound statement, and we enter 
> the rounding mode of FE_DYNAMIC, which says it should behave in the manner of 
> the last call to fesetround, which was (as-if) called by the earlier pragma.
> 
> Thoughts?
> 
> I would be good to have a test for the behavior at file scope as well as at 
> compound scope, e.g.,
> ```
> float default_mode = 1.0f / 3.0f;
> 
> #pragma STDC FENV_ROUND FE_UPWARD  
> float up = 1.0f / 3.0f;
> 
> #pragma STDC FENV_ROUND FE_DOWNWARD
> float down = 1.0f / 3.0f;
> 
> #pragma STDC FENV_ROUND FE_DYNAMIC
> float dynamic = 1.0f / 3.0f;
> ```
> I'd expect the `up` and `down` cases to have different values, and I'd expect 
> the `dynamic` case to either be the same as `down` or the same as 
> `default_mode`.
It is easier to rationalize effect of FENV_ROUND if target supports static 
rounding mode, like RISCV. On such target the rounding mode may be specified in 
every instruction that depends on it. Such instruction does not depend on FP 
environment, the rounding mode is known at compile-time, and it perfectly fits 
notion of constant rounding mode provided in the standard. There is also a 
special value of rounding mode that does not designates concrete rounding but 
instruct the processor to take rounding mode from a special register. This is 
dynamic rounding mode, In general it is unknown at compile-time and may be set, 
for example, by a call to `fesetround`. On such target FE_DYNAMIC means that 
instructions are created with dynamic rounding mode, while any other mode 
selected by FENV_ROUND results in concrete static rounding mode.

As for this example (func_3), the first pragma sets FE_TOWARDZERO mode. This is 
a static rounding mode, it is known in compile-time. In the nested compound 
statement pragma FENV_ROUND FE_DYNAMIC requires that FP operations use dynamic 
rounding mode. It means that actual rounding mode is known in runtime and the 
actual rounding mode must be set somewhere by a call to `fesetround` or some 
other manner. In this test no 'FENV_ACCESS` is specified, to compiler may 
assume the dynamic rounding mode is FE_TONEAREST. In the test `func_4` there is 
`pragma FENV_ACCESS ON` and roun

[PATCH] D129435: [Clang] Parse toolchain-specific offloading arguments directly

2022-07-11 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield accepted this revision.
JonChesterfield added a comment.
This revision is now accepted and ready to land.

LG, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129435/new/

https://reviews.llvm.org/D129435

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


[PATCH] D129149: [OMPIRBuilder] Add support for simdlen clause

2022-07-11 Thread Prabhdeep Soni via Phabricator via cfe-commits
psoni2628 updated this revision to Diff 443622.
psoni2628 added a comment.

- Rebase, ensuring that build bot failures are gone


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129149/new/

https://reviews.llvm.org/D129149

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/irbuilder_simd.cpp
  clang/test/OpenMP/irbuilder_simdlen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  llvm/utils/UpdateTestChecks/common.py
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -971,7 +971,7 @@
   llvm::CanonicalLoopInfo *loopInfo =
   ompBuilder->collapseLoops(ompLoc.DL, loopInfos, {});
 
-  ompBuilder->applySimd(ompLoc.DL, loopInfo);
+  ompBuilder->applySimd(loopInfo, nullptr);
 
   builder.restoreIP(afterIP);
   return success();
Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -719,18 +719,19 @@
 # Description of the different "unnamed" values we match in the IR, e.g.,
 # (local) ssa values, (debug) metadata, etc.
 ir_nameless_values = [
-NamelessValue(r'TMP'  , '%' , r'%'   , None, None   , r'[\w$.-]+?' , None , False) ,
-NamelessValue(r'ATTR' , '#' , r'#'   , None, None   , r'[0-9]+', None , False) ,
-NamelessValue(r'ATTR' , '#' , None   , r'attributes #' , r'[0-9]+'  , None , r'{[^}]*}'   , False) ,
-NamelessValue(r'GLOB' , '@' , r'@'   , None, None   , r'[0-9]+', None , False) ,
-NamelessValue(r'GLOB' , '@' , None   , r'@', r'[a-zA-Z0-9_$"\\.-]+' , None , r'.+', True)  ,
-NamelessValue(r'DBG'  , '!' , r'!dbg '   , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'PROF' , '!' , r'!prof '  , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'TBAA' , '!' , r'!tbaa '  , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'RNG'  , '!' , r'!range ' , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'LOOP' , '!' , r'!llvm.loop ' , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'META' , '!' , r'metadata '   , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'META' , '!' , None   , r'' , r'![0-9]+' , None , r'(?:distinct |)!.*' , False) ,
+NamelessValue(r'TMP' , '%' , r'%'   , None, None   , r'[\w$.-]+?' , None , False) ,
+NamelessValue(r'ATTR', '#' , r'#'   , None, None   , r'[0-9]+', None , False) ,
+NamelessValue(r'ATTR', '#' , None   , r'attributes #' , r'[0-9]+'  , None , r'{[^}]*}'   , False) ,
+NamelessValue(r'GLOB', '@' , r'@'   , None, None   , r'[0-9]+', None , False) ,
+NamelessValue(r'GLOB', '@' , None   , r'@', r'[a-zA-Z0-9_$"\\.-]+' , None , r'.+', True)  ,
+NamelessValue(r'DBG' , '!' , r'!dbg '   , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'PROF', '!' , r'!prof '  , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'TBAA', '!' , r'!tbaa '  , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'RNG' , '!' , r'!range ' , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'LOOP', '!' , r'!llvm.loop ' , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'META', '!' , r'metadata '   , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'META', '!' , None   , r'' , r

[PATCH] D129016: [PowerPC] implemented @llvm.ppc.kill.canary to corrupt stack guard

2022-07-11 Thread Paul Scoropan via Phabricator via cfe-commits
pscoro updated this revision to Diff 443630.
pscoro added a comment.

fixed lit test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129016/new/

https://reviews.llvm.org/D129016

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/test/CodeGen/PowerPC/builtins-ppc-stackprotect.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/kill-canary-intrinsic.ll

Index: llvm/test/CodeGen/PowerPC/kill-canary-intrinsic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/kill-canary-intrinsic.ll
@@ -0,0 +1,75 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN:   --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=AIX
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux \
+; RUN:   --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=LINUX
+
+declare void @llvm.ppc.kill.canary()
+define dso_local void @test_kill_canary() {
+; AIX-LABEL: test_kill_canary:
+; AIX:   # %bb.0: # %entry
+; AIX-NEXT:blr
+;
+; LINUX-LABEL: test_kill_canary:
+; LINUX:   # %bb.0: # %entry
+; LINUX-NEXT:blr
+entry:
+  call void @llvm.ppc.kill.canary()
+  ret void
+}
+
+attributes #0 = { sspreq }
+; Function Attrs: sspreq
+define dso_local void @test_kill_canary_ssp() #0 {
+; AIX-LABEL: test_kill_canary_ssp:
+; AIX:   # %bb.0: # %entry
+; AIX-NEXT:mflr r0
+; AIX-NEXT:std r0, 16(r1)
+; AIX-NEXT:stdu r1, -128(r1)
+; AIX-NEXT:ld r3, L..C0(r2) # @__ssp_canary_word
+; AIX-NEXT:ld r4, 0(r3)
+; AIX-NEXT:std r4, 120(r1)
+; AIX-NEXT:ld r4, 0(r3)
+; AIX-NEXT:not r4, r4
+; AIX-NEXT:std r4, 0(r3)
+; AIX-NEXT:ld r3, 0(r3)
+; AIX-NEXT:ld r4, 120(r1)
+; AIX-NEXT:cmpld r3, r4
+; AIX-NEXT:bne cr0, L..BB1_2
+; AIX-NEXT:  # %bb.1: # %entry
+; AIX-NEXT:addi r1, r1, 128
+; AIX-NEXT:ld r0, 16(r1)
+; AIX-NEXT:mtlr r0
+; AIX-NEXT:blr
+; AIX-NEXT:  L..BB1_2: # %entry
+; AIX-NEXT:bl .__stack_chk_fail[PR]
+; AIX-NEXT:nop
+;
+; LINUX-LABEL: test_kill_canary_ssp:
+; LINUX:   # %bb.0: # %entry
+; LINUX-NEXT:mflr r0
+; LINUX-NEXT:std r0, 16(r1)
+; LINUX-NEXT:stdu r1, -128(r1)
+; LINUX-NEXT:.cfi_def_cfa_offset 128
+; LINUX-NEXT:.cfi_offset lr, 16
+; LINUX-NEXT:ld r3, -28688(r13)
+; LINUX-NEXT:std r3, 120(r1)
+; LINUX-NEXT:ld r3, -28688(r13)
+; LINUX-NEXT:not r3, r3
+; LINUX-NEXT:std r3, 120(r1)
+; LINUX-NEXT:ld r3, 120(r1)
+; LINUX-NEXT:ld r4, -28688(r13)
+; LINUX-NEXT:cmpld r4, r3
+; LINUX-NEXT:bne cr0, .LBB1_2
+; LINUX-NEXT:  # %bb.1: # %entry
+; LINUX-NEXT:addi r1, r1, 128
+; LINUX-NEXT:ld r0, 16(r1)
+; LINUX-NEXT:mtlr r0
+; LINUX-NEXT:blr
+; LINUX-NEXT:  .LBB1_2: # %entry
+; LINUX-NEXT:bl __stack_chk_fail
+; LINUX-NEXT:nop
+entry:
+  call void @llvm.ppc.kill.canary()
+  ret void
+}
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -10695,6 +10695,72 @@
Op.getOperand(0)),
 0);
   }
+  case Intrinsic::ppc_kill_canary: {
+MachineFunction &MF = DAG.getMachineFunction();
+const Module *M = MF.getMMI().getModule();
+
+/* If SafeStack or !StackProtector, kill_canary not supported */
+if (MF.getFunction().hasFnAttribute(Attribute::SafeStack) ||
+!MF.getFunction().hasStackProtectorFnAttr()) {
+  DAG.ReplaceAllUsesOfValueWith(
+  SDValue(Op.getNode(), 0),
+  Op->getOperand(0)); // prepare node for deletion
+  break;
+}
+
+EVT VT = DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout());
+
+SDValue Load;
+SDValue Store;
+
+const uint64_t XORWord =
+0x; // XORing with 0b111...111 will never
+// result in the original word
+
+if (useLoadStackGuardNode()) { // linux uses LOAD_STACK_GUARD node instead
+   // of having a canary word global value
+  MachineSDNode *LSG =
+  DAG.getMachineNode(PPC::LOAD_STACK_GUARD, DL, VT, Op->getOperand(0));
+  Load = SDValue(LSG, 0);
+
+  /* frame index used to determine stack guard location if
+   * LOAD_STACK_GUARD is used */
+  MachineFrameInfo &MFI = MF.getFrameInfo();
+  int SPI = MFI.getStackProtectorIndex(); // should return -1
+  PPCFunctionInfo *FuncInfo = MF.getInfo();
+  SDValue FIN = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), VT);
+
+  // XOR canary word and store back
+  Store = DAG.getStore(
+  Op->getOperand(0), DL,
+  DAG.getNode(ISD::XOR, DL, VT, Load, DAG.getConstant(XORWord, DL, VT)),
+

[PATCH] D128830: [Pipelines] Introduce DAE after ArgumentPromotion

2022-07-11 Thread Pavel Samolysov via Phabricator via cfe-commits
psamolysov updated this revision to Diff 443631.
psamolysov added a comment.

@aeubanks Thank you for the great explanation.

I've applied your suggestion and re-uploaded the patch. The test 
`unused-nonnull.ll` has been fixed with keeping the `readnone` attribute.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128830/new/

https://reviews.llvm.org/D128830

Files:
  clang/test/CodeGen/thinlto-distributed-newpm.ll
  llvm/lib/Passes/PassBuilderPipelines.cpp
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-lto-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
  llvm/test/Transforms/InstCombine/unused-nonnull.ll
  llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll

Index: llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll
===
--- llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll
+++ llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll
@@ -9,7 +9,7 @@
 
 define internal void @f(%struct.ss* byval(%struct.ss) align 8 %b, i32* byval(i32) align 4 %X) noinline nounwind  {
 ; CHECK-LABEL: define {{[^@]+}}@f
-; CHECK-SAME: (i32 [[B_0:%.*]], i32 [[X:%.*]]){{[^#]*}} #[[ATTR0:[0-9]+]] {
+; CHECK-SAME: (i32 [[B_0:%.*]]){{[^#]*}} #[[ATTR0:[0-9]+]] {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:[[TEMP:%.*]] = add i32 [[B_0]], 1
 ; CHECK-NEXT:store i32 [[TEMP]], i32* [[DUMMY]], align 4
@@ -28,8 +28,7 @@
 ; CHECK-LABEL: define {{[^@]+}}@test
 ; CHECK-SAME: (i32* {{[^%]*}} [[X:%.*]]){{[^#]*}} #[[ATTR1:[0-9]+]] {
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[X_VAL:%.*]] = load i32, i32* [[X]], align 4
-; CHECK-NEXT:tail call {{.*}}void @f(i32 1, i32 [[X_VAL]])
+; CHECK-NEXT:tail call {{.*}}void @f(i32 1)
 ; CHECK-NEXT:ret i32 0
 ;
 entry:
Index: llvm/test/Transforms/InstCombine/unused-nonnull.ll
===
--- llvm/test/Transforms/InstCombine/unused-nonnull.ll
+++ llvm/test/Transforms/InstCombine/unused-nonnull.ll
@@ -37,7 +37,7 @@
 
 define i32 @compute(i8* noundef nonnull %ptr, i32 %x) #1 {
 ; CHECK-LABEL: define {{[^@]+}}@compute
-; CHECK-SAME: (i8* nocapture nonnull readnone [[PTR:%.*]], i32 returned [[X:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] {
+; CHECK-SAME: (i8* nocapture noundef nonnull readnone [[PTR:%.*]], i32 returned [[X:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] {
 ; CHECK-NEXT:ret i32 [[X]]
 ;
   ret i32 %x
Index: llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
===
--- llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
+++ llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
@@ -58,7 +58,6 @@
 ; CHECK-O-NEXT: Running pass: CalledValuePropagationPass
 ; CHECK-O-NEXT: Running pass: GlobalOptPass
 ; CHECK-O-NEXT: Running pass: PromotePass
-; CHECK-O-NEXT: Running pass: DeadArgumentEliminationPass
 ; CHECK-O-NEXT: Running pass: InstCombinePass
 ; CHECK-O-NEXT: Running analysis: BlockFrequencyAnalysis on foo
 ; These next two can appear in any order since they are accessed as parameters
@@ -81,14 +80,13 @@
 ; CHECK-O-NEXT: Running pass: DevirtSCCRepeatedPass
 ; CHECK-O-NEXT: Running pass: InlinerPass
 ; CHECK-O-NEXT: Running pass: InlinerPass
-; CHECK-O-NEXT: Running pass: PostOrderFunctionAttrsPass
-; CHECK-O-NEXT: Running analysis: AAManager
 ; CHECK-O3-NEXT: Running pass: ArgumentPromotionPass
 ; CHECK-O2-NEXT: Running pass: OpenMPOptCGSCCPass
 ; CHECK-O3-NEXT: Running pass: OpenMPOptCGSCCPass
 ; CHECK-O-NEXT: Running pass: SROAPass
 ; CHECK-O-NEXT: Running pass: EarlyCSEPass
 ; CHECK-O-NEXT: Running analysis: MemorySSAAnalysis
+; CHECK-O-NEXT: Running analysis: AAManager
 ; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass
 ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass
 ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis
@@ -160,8 +158,10 @@
 ; CHECK-O3-NEXT: Running pass: ControlHeightReductionPass on foo
 ; CHECK-O3-NEXT: Running analysis: RegionInfoAnalysis on foo
 ; CHECK-O3-NEXT: Running analysis: DominanceFrontierAnalysis on foo
+; CHECK-O-NEXT: Running pass: PostOrderFunctionAttrsPass
 ; CHECK-O-NEXT: Running pass: CoroSplitPass
 ; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis
+; CHECK-O-NEXT: Running pass: DeadArgumentEliminationPass
 ; CHECK-O-NEXT: Running pass: CoroCleanupPass
 ; CHECK-O-NEXT: Running pass: GlobalOptPass
 ; CHECK-O-NEXT: Running pass: AnnotationRemarksPass on foo
Index: llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
===
--- llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
+++ llvm/test/

[PATCH] D129269: [analyzer] Fix use of length in CStringChecker

2022-07-11 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Thanks @martong , I understand. I'll make the changes and resubmit. Best!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129269/new/

https://reviews.llvm.org/D129269

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


[PATCH] D95588: [RISCV] Implement the MC layer support of P extension

2022-07-11 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce added a comment.

In D95588#3641900 , @Jim wrote:

> In D95588#3622052 , @sunshaoce wrote:
>
>> Hello @Jim! We are developing the P extension, are you still maintaining 
>> this patch? Or would you mind co-development together?
>
> Yes, I am still on developing the P extension. But it seems spec has the 
> issue https://github.com/riscv/riscv-p-spec/issues/137 need to clarify.
> And some instruction (CLZ, FSR and FSRI) in Zbpbo only be aliased to B 
> extension on RV32. It is complicated if P extension are enabled on RV64.

Yes, this problem does exist. Thanks for your reply, looking forward to more 
cooperation!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95588/new/

https://reviews.llvm.org/D95588

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


[clang] f54ca1f - [NFC][Coroutines] Add regression test for heap allocation elision optimization

2022-07-11 Thread Dawid Jurczak via cfe-commits

Author: Dawid Jurczak
Date: 2022-07-11T16:41:05+02:00
New Revision: f54ca1f632646ee9a2a052a28e93ffb0bcc4340d

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

LOG: [NFC][Coroutines] Add regression test for heap allocation elision 
optimization

Recently C++ snippet included in this patch popped up at least twice in 
different regression contexts:
https://github.com/llvm/llvm-project/issues/56262 and 
https://reviews.llvm.org/D123300
It appears that Clang users rely on HALO so adding C++ example coming 
originally from Gor Nishanov to tests
should help in avoiding similar regressions in future.

Differential Revision: https://reviews.llvm.org/D129279

Added: 
clang/test/CodeGenCoroutines/Inputs/numeric.h
clang/test/CodeGenCoroutines/coro-halo.cpp

Modified: 


Removed: 




diff  --git a/clang/test/CodeGenCoroutines/Inputs/numeric.h 
b/clang/test/CodeGenCoroutines/Inputs/numeric.h
new file mode 100644
index 0..81f319eb7d052
--- /dev/null
+++ b/clang/test/CodeGenCoroutines/Inputs/numeric.h
@@ -0,0 +1,10 @@
+#pragma once
+
+namespace std {
+template 
+T accumulate(InputIterator first, InputIterator last, T init) {
+  for (; first != last; ++first)
+init = init + *first;
+  return init;
+}
+} // namespace std

diff  --git a/clang/test/CodeGenCoroutines/coro-halo.cpp 
b/clang/test/CodeGenCoroutines/coro-halo.cpp
new file mode 100644
index 0..14ae53c41aebe
--- /dev/null
+++ b/clang/test/CodeGenCoroutines/coro-halo.cpp
@@ -0,0 +1,102 @@
+// This tests that the coroutine heap allocation elision optimization could 
happen succesfully.
+// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-linux-gnu 
-std=c++20 -O2 -emit-llvm %s -o - | FileCheck %s
+
+#include "Inputs/coroutine.h"
+#include "Inputs/numeric.h"
+
+template  struct generator {
+  struct promise_type {
+T current_value;
+std::suspend_always yield_value(T value) {
+  this->current_value = value;
+  return {};
+}
+std::suspend_always initial_suspend() { return {}; }
+std::suspend_always final_suspend() noexcept { return {}; }
+generator get_return_object() { return generator{this}; };
+void unhandled_exception() {}
+void return_void() {}
+  };
+
+  struct iterator {
+std::coroutine_handle _Coro;
+bool _Done;
+
+iterator(std::coroutine_handle Coro, bool Done)
+: _Coro(Coro), _Done(Done) {}
+
+iterator &operator++() {
+  _Coro.resume();
+  _Done = _Coro.done();
+  return *this;
+}
+
+bool operator==(iterator const &_Right) const {
+  return _Done == _Right._Done;
+}
+
+bool operator!=(iterator const &_Right) const { return !(*this == _Right); 
}
+T const &operator*() const { return _Coro.promise().current_value; }
+T const *operator->() const { return &(operator*()); }
+  };
+
+  iterator begin() {
+p.resume();
+return {p, p.done()};
+  }
+
+  iterator end() { return {p, true}; }
+
+  generator(generator const &) = delete;
+  generator(generator &&rhs) : p(rhs.p) { rhs.p = nullptr; }
+
+  ~generator() {
+if (p)
+  p.destroy();
+  }
+
+private:
+  explicit generator(promise_type *p)
+  : p(std::coroutine_handle::from_promise(*p)) {}
+
+  std::coroutine_handle p;
+};
+
+template 
+generator seq() {
+  for (T i = {};; ++i)
+co_yield i;
+}
+
+template 
+generator take_until(generator &g, T limit) {
+  for (auto &&v : g)
+if (v < limit)
+  co_yield v;
+else
+  break;
+}
+
+template 
+generator multiply(generator &g, T factor) {
+  for (auto &&v : g)
+co_yield v *factor;
+}
+
+template 
+generator add(generator &g, T adder) {
+  for (auto &&v : g)
+co_yield v + adder;
+}
+
+int main() {
+  auto s = seq();
+  auto t = take_until(s, 10);
+  auto m = multiply(t, 2);
+  auto a = add(m, 110);
+  return std::accumulate(a.begin(), a.end(), 0);
+}
+
+// CHECK-LABEL: define{{.*}} i32 @main(
+//   CHECK: ret i32 1190
+//   CHECK-NOT: call{{.*}}_Znwm



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


[PATCH] D129279: [NFC] [Coroutines] Add regression test for heap allocation elision optimization

2022-07-11 Thread Dawid Jurczak via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf54ca1f63264: [NFC][Coroutines] Add regression test for heap 
allocation elision optimization (authored by yurai007).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129279/new/

https://reviews.llvm.org/D129279

Files:
  clang/test/CodeGenCoroutines/Inputs/numeric.h
  clang/test/CodeGenCoroutines/coro-halo.cpp

Index: clang/test/CodeGenCoroutines/coro-halo.cpp
===
--- /dev/null
+++ clang/test/CodeGenCoroutines/coro-halo.cpp
@@ -0,0 +1,102 @@
+// This tests that the coroutine heap allocation elision optimization could happen succesfully.
+// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-linux-gnu -std=c++20 -O2 -emit-llvm %s -o - | FileCheck %s
+
+#include "Inputs/coroutine.h"
+#include "Inputs/numeric.h"
+
+template  struct generator {
+  struct promise_type {
+T current_value;
+std::suspend_always yield_value(T value) {
+  this->current_value = value;
+  return {};
+}
+std::suspend_always initial_suspend() { return {}; }
+std::suspend_always final_suspend() noexcept { return {}; }
+generator get_return_object() { return generator{this}; };
+void unhandled_exception() {}
+void return_void() {}
+  };
+
+  struct iterator {
+std::coroutine_handle _Coro;
+bool _Done;
+
+iterator(std::coroutine_handle Coro, bool Done)
+: _Coro(Coro), _Done(Done) {}
+
+iterator &operator++() {
+  _Coro.resume();
+  _Done = _Coro.done();
+  return *this;
+}
+
+bool operator==(iterator const &_Right) const {
+  return _Done == _Right._Done;
+}
+
+bool operator!=(iterator const &_Right) const { return !(*this == _Right); }
+T const &operator*() const { return _Coro.promise().current_value; }
+T const *operator->() const { return &(operator*()); }
+  };
+
+  iterator begin() {
+p.resume();
+return {p, p.done()};
+  }
+
+  iterator end() { return {p, true}; }
+
+  generator(generator const &) = delete;
+  generator(generator &&rhs) : p(rhs.p) { rhs.p = nullptr; }
+
+  ~generator() {
+if (p)
+  p.destroy();
+  }
+
+private:
+  explicit generator(promise_type *p)
+  : p(std::coroutine_handle::from_promise(*p)) {}
+
+  std::coroutine_handle p;
+};
+
+template 
+generator seq() {
+  for (T i = {};; ++i)
+co_yield i;
+}
+
+template 
+generator take_until(generator &g, T limit) {
+  for (auto &&v : g)
+if (v < limit)
+  co_yield v;
+else
+  break;
+}
+
+template 
+generator multiply(generator &g, T factor) {
+  for (auto &&v : g)
+co_yield v *factor;
+}
+
+template 
+generator add(generator &g, T adder) {
+  for (auto &&v : g)
+co_yield v + adder;
+}
+
+int main() {
+  auto s = seq();
+  auto t = take_until(s, 10);
+  auto m = multiply(t, 2);
+  auto a = add(m, 110);
+  return std::accumulate(a.begin(), a.end(), 0);
+}
+
+// CHECK-LABEL: define{{.*}} i32 @main(
+//   CHECK: ret i32 1190
+//   CHECK-NOT: call{{.*}}_Znwm
Index: clang/test/CodeGenCoroutines/Inputs/numeric.h
===
--- /dev/null
+++ clang/test/CodeGenCoroutines/Inputs/numeric.h
@@ -0,0 +1,10 @@
+#pragma once
+
+namespace std {
+template 
+T accumulate(InputIterator first, InputIterator last, T init) {
+  for (; first != last; ++first)
+init = init + *first;
+  return init;
+}
+} // namespace std
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129488: [Sema] Fix evaluation context of immediate functions in default arguments

2022-07-11 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: jyknight.
Herald added a project: All.
ilya-biryukov requested review of this revision.
Herald added a project: clang.

They must be evaluated in the context where default argument is actually
used during a call, not in a parameter list where default argument is specified.
This affects correctness of `std::source_location`.

Fixes #56379.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129488

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/source_location.cpp
  clang/test/SemaCXX/source_location_consteval.cpp

Index: clang/test/SemaCXX/source_location_consteval.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/source_location_consteval.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
+
+namespace std {
+class source_location {
+  struct __impl;
+
+public:
+  static consteval source_location current(const __impl *__p = __builtin_source_location()) noexcept {
+source_location __loc;
+__loc.__m_impl = __p;
+return __loc;
+  }
+  constexpr source_location() = default;
+  constexpr source_location(source_location const &) = default;
+  constexpr unsigned int line() const noexcept { return __m_impl ? __m_impl->_M_line : 0; }
+  constexpr unsigned int column() const noexcept { return __m_impl ? __m_impl->_M_column : 0; }
+  constexpr const char *file() const noexcept { return __m_impl ? __m_impl->_M_file_name : ""; }
+  constexpr const char *function() const noexcept { return __m_impl ? __m_impl->_M_function_name : ""; }
+
+private:
+  // Note: The type name "std::source_location::__impl", and its constituent
+  // field-names are required by __builtin_source_location().
+  struct __impl {
+const char *_M_file_name;
+const char *_M_function_name;
+unsigned _M_line;
+unsigned _M_column;
+  };
+  const __impl *__m_impl = nullptr;
+
+public:
+  using public_impl_alias = __impl;
+};
+} // namespace std
+
+using SL = std::source_location;
+
+constexpr bool is_equal(const char *LHS, const char *RHS) {
+  while (*LHS != 0 && *RHS != 0) {
+if (*LHS != *RHS)
+  return false;
+++LHS;
+++RHS;
+  }
+  return *LHS == 0 && *RHS == 0;
+}
+
+constexpr SL get_sl(SL l = SL::current()) { return l; }
+
+#line 700 "CheckDefaultArg.h"
+constexpr SL l = get_sl();
+static_assert(l.line() == 700);
+static_assert(is_equal(l.file(), "CheckDefaultArg.h"));
+
+void test() {
+  static_assert(is_equal(get_sl().function(), __PRETTY_FUNCTION__));
+  static_assert(get_sl().line() ==  __LINE__);
+}
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -364,8 +364,8 @@
 template 
 void func_template_tests() {
   constexpr auto P = test_func_template(42);
-  //static_assert(is_equal(P.first.function(), __func__), "");
-  //static_assert(!is_equal(P.second.function(), __func__), "");
+  static_assert(is_equal(P.first.function(), __PRETTY_FUNCTION__), "");
+  static_assert(!is_equal(P.second.function(), __PRETTY_FUNCTION__), "");
 }
 template void func_template_tests();
 
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -17500,7 +17500,8 @@
   /*IsImmediateInvocation*/ true);
   /// Value-dependent constant expressions should not be immediately
   /// evaluated until they are instantiated.
-  if (!Res->isValueDependent())
+  /// Default arguments must be evaluated in the context of their call.
+  if (!Res->isValueDependent() && !isPotentiallyEvaluatedIfUsedContext())
 ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
   return Res;
 }
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1359,6 +1359,10 @@
   ExpressionEvaluationContext::ImmediateFunctionContext &&
   InDiscardedStatement);
 }
+
+bool isPotentiallyEvaluatedIfUsed() const {
+  return Context == ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed;
+}
   };
 
   /// A stack of expression evaluation contexts.
@@ -9406,6 +9410,12 @@
 return ExprEvalContexts.back().isImmediateFunctionContext();
   }
 
+  bool isPotentiallyEvaluatedIfUsedContext() const {
+assert(!ExprEvalContexts.empty() &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts.back().isPotentiallyEvaluatedIfUsed();
+  }
+
   /// RAII class used to determine whether SFINAE has
   /// trapped any errors that occur during template argument
   /// deduction.
___
cfe-commits mailing list
cfe-commits

[PATCH] D129435: [Clang] Parse toolchain-specific offloading arguments directly

2022-07-11 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

need a test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129435/new/

https://reviews.llvm.org/D129435

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


[PATCH] D129435: [Clang] Parse toolchain-specific offloading arguments directly

2022-07-11 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D129435#3642450 , @yaxunl wrote:

> need a test

There's a test `clang/test/Driver/openmp-offload-gpu-new.c` already making sure 
that the following works, so this patch should maintain the same functionality 
we had before.

  clang input.c -fopenmp -fopenmp-targets=nvptx64,amdgcn 
-Xopenmp-target=nvptx64 --offload-arch=sm_70 -Xopenmp-target=amdgcn 
--offload-arch=gfx908




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129435/new/

https://reviews.llvm.org/D129435

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


[PATCH] D128048: Add a new clang option "-ftime-trace="

2022-07-11 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser accepted this revision.
jamieschmeiser added a comment.
This revision is now accepted and ready to land.

LGTM.  Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128048/new/

https://reviews.llvm.org/D128048

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


[PATCH] D129492: Add missing sanitizer metadata plumbing from CFE.

2022-07-11 Thread Mitch Phillips via Phabricator via cfe-commits
hctim created this revision.
hctim added a reviewer: eugenis.
Herald added a project: All.
hctim requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

clang misses attaching sanitizer metadata for external globals.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129492

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/memtag-globals.cpp


Index: clang/test/CodeGen/memtag-globals.cpp
===
--- clang/test/CodeGen/memtag-globals.cpp
+++ clang/test/CodeGen/memtag-globals.cpp
@@ -11,10 +11,12 @@
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) 
disable_instrumentation_global;
 int ignorelisted_global;
+extern int external_global;
 
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // CHECK: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
@@ -29,6 +31,7 @@
 
 // CHECK: @{{.*}}static_var{{.*}} ={{.*}} sanitize_memtag
 // CHECK: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}} sanitize_memtag
+// CHECK: @{{.*}}external_global{{.*}} ={{.*}} sanitize_memtag
 
 // IGNORELIST: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
 
@@ -44,3 +47,5 @@
 // IGNORELIST-NOT: sanitize_memtag
 // IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}}
 // IGNORELIST-NOT: sanitize_memtag
+// IGNORELIST: @{{.*}}external_global{{.*}} =
+// IGNORELIST-NOT: sanitize_memtag
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4286,6 +4286,9 @@
   getCUDARuntime().handleVarRegistration(D, *GV);
   }
 
+  if (D)
+SanitizerMD->reportGlobal(GV, *D);
+
   LangAS ExpectedAS =
   D ? D->getType().getAddressSpace()
 : (LangOpts.OpenCL ? LangAS::opencl_global : LangAS::Default);


Index: clang/test/CodeGen/memtag-globals.cpp
===
--- clang/test/CodeGen/memtag-globals.cpp
+++ clang/test/CodeGen/memtag-globals.cpp
@@ -11,10 +11,12 @@
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
+extern int external_global;
 
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // CHECK: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
@@ -29,6 +31,7 @@
 
 // CHECK: @{{.*}}static_var{{.*}} ={{.*}} sanitize_memtag
 // CHECK: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}} sanitize_memtag
+// CHECK: @{{.*}}external_global{{.*}} ={{.*}} sanitize_memtag
 
 // IGNORELIST: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
 
@@ -44,3 +47,5 @@
 // IGNORELIST-NOT: sanitize_memtag
 // IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}}
 // IGNORELIST-NOT: sanitize_memtag
+// IGNORELIST: @{{.*}}external_global{{.*}} =
+// IGNORELIST-NOT: sanitize_memtag
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4286,6 +4286,9 @@
   getCUDARuntime().handleVarRegistration(D, *GV);
   }
 
+  if (D)
+SanitizerMD->reportGlobal(GV, *D);
+
   LangAS ExpectedAS =
   D ? D->getType().getAddressSpace()
 : (LangOpts.OpenCL ? LangAS::opencl_global : LangAS::Default);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128914: [HIP] Add support for handling HIP in the linker wrapper

2022-07-11 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield accepted this revision.
JonChesterfield added a comment.
This revision is now accepted and ready to land.

Code looks good to me. It's hard to be sure whether it works without running a 
bunch of hip test cases through it, have you already done so? If it doesn't 
work out of the box it should be close enough to fix up post commit, e.g. when 
trying to move hip over to this by default.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128914/new/

https://reviews.llvm.org/D128914

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


[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-07-11 Thread Vaibhav Yenamandra via Phabricator via cfe-commits
vaibhav.y updated this revision to Diff 443654.
vaibhav.y added a comment.

Discard most likely culprit in test code causing unexpected crash.

@aaron.ballman I was unable to reproduce the issue on my end using the buildbot
instructions and ASAN, UBSAN.

Is it possible for you to trigger a pre-merge check on the LLVM cluster?

I have suspicions that it was the `SarifResult &&` type in the test so I changed
it to a `const SarifResult &`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109701/new/

https://reviews.llvm.org/D109701

Files:
  clang/include/clang/Basic/Sarif.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Sarif.cpp
  clang/unittests/Basic/CMakeLists.txt
  clang/unittests/Basic/SarifTest.cpp

Index: clang/unittests/Basic/SarifTest.cpp
===
--- /dev/null
+++ clang/unittests/Basic/SarifTest.cpp
@@ -0,0 +1,320 @@
+//===- unittests/Basic/SarifTest.cpp - Test writing SARIF documents ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Sarif.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gmock/gmock-matchers.h"
+#include "gtest/gtest-death-test.h"
+#include "gtest/gtest-matchers.h"
+#include "gtest/gtest.h"
+
+#include 
+
+using namespace clang;
+
+namespace {
+
+using LineCol = std::pair;
+
+static std::string serializeSarifDocument(llvm::json::Object &&Doc) {
+  std::string Output;
+  llvm::json::Value value(std::move(Doc));
+  llvm::raw_string_ostream OS{Output};
+  OS << llvm::formatv("{0}", value);
+  OS.flush();
+  return Output;
+}
+
+class SarifDocumentWriterTest : public ::testing::Test {
+protected:
+  SarifDocumentWriterTest()
+  : InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem),
+FileMgr(FileSystemOptions(), InMemoryFileSystem),
+DiagID(new DiagnosticIDs()), DiagOpts(new DiagnosticOptions()),
+Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr) {}
+
+  IntrusiveRefCntPtr InMemoryFileSystem;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  IntrusiveRefCntPtr DiagOpts;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+
+  FileID registerSource(llvm::StringRef Name, const char *SourceText,
+bool IsMainFile = false) {
+std::unique_ptr SourceBuf =
+llvm::MemoryBuffer::getMemBuffer(SourceText);
+const FileEntry *SourceFile =
+FileMgr.getVirtualFile(Name, SourceBuf->getBufferSize(), 0);
+SourceMgr.overrideFileContents(SourceFile, std::move(SourceBuf));
+FileID FID = SourceMgr.getOrCreateFileID(SourceFile, SrcMgr::C_User);
+if (IsMainFile)
+  SourceMgr.setMainFileID(FID);
+return FID;
+  }
+
+  CharSourceRange getFakeCharSourceRange(FileID FID, LineCol Begin,
+ LineCol End) {
+auto BeginLoc = SourceMgr.translateLineCol(FID, Begin.first, Begin.second);
+auto EndLoc = SourceMgr.translateLineCol(FID, End.first, End.second);
+return CharSourceRange{SourceRange{BeginLoc, EndLoc}, /* ITR = */ false};
+  }
+};
+
+TEST_F(SarifDocumentWriterTest, createEmptyDocument) {
+  // GIVEN:
+  SarifDocumentWriter Writer{SourceMgr};
+
+  // WHEN:
+  const llvm::json::Object &EmptyDoc = Writer.createDocument();
+  std::vector Keys(EmptyDoc.size());
+  std::transform(EmptyDoc.begin(), EmptyDoc.end(), Keys.begin(),
+ [](auto item) { return item.getFirst(); });
+
+  // THEN:
+  ASSERT_THAT(Keys, testing::UnorderedElementsAre("$schema", "version"));
+}
+
+// Test that a newly inserted run will associate correct tool names
+TEST_F(SarifDocumentWriterTest, documentWithARun) {
+  // GIVEN:
+  SarifDocumentWriter Writer{SourceMgr};
+  const char *ShortName = "sariftest";
+  const char *LongName = "sarif writer test";
+
+  // WHEN:
+  Writer.createRun(ShortName, LongName);
+  Writer.endRun();
+  const llvm::json::Object &Doc = Writer.createDocument();
+  const llvm::json::Array *Runs = Doc.getArray("runs");
+
+  // THEN:
+  // A run was created
+  ASSERT_THAT(Runs, testing::NotNull());
+
+  // It is the only run
+  ASSERT_EQ(Runs->size(), 1UL);
+
+  // The tool associated with the run was the tool
+  const llvm::json::

[PATCH] D128914: [HIP] Add support for handling HIP in the linker wrapper

2022-07-11 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D128914#3642558 , @JonChesterfield 
wrote:

> Code looks good to me. It's hard to be sure whether it works without running 
> a bunch of hip test cases through it, have you already done so? If it doesn't 
> work out of the box it should be close enough to fix up post commit, e.g. 
> when trying to move hip over to this by default.

Thanks for the review, I ran a couple mini-apps with HIP versions (XSBench, 
RSBench, SU3Bench) using this method and they passed without issue. The only 
thing I was unsure about what whether or not the handle needed to be checked 
for null, because my testing suggested it's unnecessary. I was hoping one of 
the HIP developers would let me know. We can think about making this the 
default approach when I make the new driver work for `non-rdc` mode 
compilations.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128914/new/

https://reviews.llvm.org/D128914

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


[PATCH] D129269: [analyzer] Fix use of length in CStringChecker

2022-07-11 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 443658.
vabridgers edited the summary of this revision.
vabridgers added a comment.

update per comments from @martong


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129269/new/

https://reviews.llvm.org/D129269

Files:
  clang/docs/analyzer/checkers.rst
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/test/Analysis/string.c


Index: clang/test/Analysis/string.c
===
--- clang/test/Analysis/string.c
+++ clang/test/Analysis/string.c
@@ -1652,3 +1652,18 @@
   __builtin___memset_chk(&x, 0, sizeof(x), __builtin_object_size(&x, 0));
   clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
 }
+
+#ifndef SUPPRESS_OUT_OF_BOUND
+void strcpy_no_overflow_2(char *y) {
+  char x[3];
+  // FIXME: string literal modeling does not account for embedded NULLs.
+  //This case should not elicit a warning, but does.
+  //See discussion at https://reviews.llvm.org/D129269
+  strcpy(x, "12\0"); // expected-warning{{String copy function overflows the 
destination buffer}}
+}
+#else
+void strcpy_no_overflow_2(char *y) {
+  char x[3];
+  strcpy(x, "12\0");
+}
+#endif
Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -848,7 +848,7 @@
 SValBuilder &svalBuilder = C.getSValBuilder();
 QualType sizeTy = svalBuilder.getContext().getSizeType();
 const StringLiteral *strLit = cast(MR)->getStringLiteral();
-return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy);
+return svalBuilder.makeIntVal(strLit->getLength(), sizeTy);
   }
   case MemRegion::SymbolicRegionKind:
   case MemRegion::AllocaRegionKind:
Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -2726,6 +2726,9 @@
 ""
 Check for out-of-bounds access in string functions; applies to:`` strncopy, 
strncat``.
 
+This check also applies to string literals, except there is a known bug in that
+the analyzer cannot detect embedded NULL characters.
+
 .. code-block:: c
 
  void test() {


Index: clang/test/Analysis/string.c
===
--- clang/test/Analysis/string.c
+++ clang/test/Analysis/string.c
@@ -1652,3 +1652,18 @@
   __builtin___memset_chk(&x, 0, sizeof(x), __builtin_object_size(&x, 0));
   clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
 }
+
+#ifndef SUPPRESS_OUT_OF_BOUND
+void strcpy_no_overflow_2(char *y) {
+  char x[3];
+  // FIXME: string literal modeling does not account for embedded NULLs.
+  //This case should not elicit a warning, but does.
+  //See discussion at https://reviews.llvm.org/D129269
+  strcpy(x, "12\0"); // expected-warning{{String copy function overflows the destination buffer}}
+}
+#else
+void strcpy_no_overflow_2(char *y) {
+  char x[3];
+  strcpy(x, "12\0");
+}
+#endif
Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -848,7 +848,7 @@
 SValBuilder &svalBuilder = C.getSValBuilder();
 QualType sizeTy = svalBuilder.getContext().getSizeType();
 const StringLiteral *strLit = cast(MR)->getStringLiteral();
-return svalBuilder.makeIntVal(strLit->getByteLength(), sizeTy);
+return svalBuilder.makeIntVal(strLit->getLength(), sizeTy);
   }
   case MemRegion::SymbolicRegionKind:
   case MemRegion::AllocaRegionKind:
Index: clang/docs/analyzer/checkers.rst
===
--- clang/docs/analyzer/checkers.rst
+++ clang/docs/analyzer/checkers.rst
@@ -2726,6 +2726,9 @@
 ""
 Check for out-of-bounds access in string functions; applies to:`` strncopy, strncat``.
 
+This check also applies to string literals, except there is a known bug in that
+the analyzer cannot detect embedded NULL characters.
+
 .. code-block:: c
 
  void test() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128830: [Pipelines] Introduce DAE after ArgumentPromotion

2022-07-11 Thread Pavel Samolysov via Phabricator via cfe-commits
psamolysov updated this revision to Diff 443661.
psamolysov added a comment.

[Pipelines] Fix the Clang :: CodeGenCoroutines/coro-elide.cpp

Now, the `%_Z5task1v.Frame` type doesn't contain a field of  the
`%_Z5task0v.Frame` one.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128830/new/

https://reviews.llvm.org/D128830

Files:
  clang/test/CodeGen/thinlto-distributed-newpm.ll
  clang/test/CodeGenCoroutines/coro-elide.cpp
  llvm/lib/Passes/PassBuilderPipelines.cpp
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-lto-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
  llvm/test/Transforms/InstCombine/unused-nonnull.ll
  llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll

Index: llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll
===
--- llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll
+++ llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll
@@ -9,7 +9,7 @@
 
 define internal void @f(%struct.ss* byval(%struct.ss) align 8 %b, i32* byval(i32) align 4 %X) noinline nounwind  {
 ; CHECK-LABEL: define {{[^@]+}}@f
-; CHECK-SAME: (i32 [[B_0:%.*]], i32 [[X:%.*]]){{[^#]*}} #[[ATTR0:[0-9]+]] {
+; CHECK-SAME: (i32 [[B_0:%.*]]){{[^#]*}} #[[ATTR0:[0-9]+]] {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:[[TEMP:%.*]] = add i32 [[B_0]], 1
 ; CHECK-NEXT:store i32 [[TEMP]], i32* [[DUMMY]], align 4
@@ -28,8 +28,7 @@
 ; CHECK-LABEL: define {{[^@]+}}@test
 ; CHECK-SAME: (i32* {{[^%]*}} [[X:%.*]]){{[^#]*}} #[[ATTR1:[0-9]+]] {
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[X_VAL:%.*]] = load i32, i32* [[X]], align 4
-; CHECK-NEXT:tail call {{.*}}void @f(i32 1, i32 [[X_VAL]])
+; CHECK-NEXT:tail call {{.*}}void @f(i32 1)
 ; CHECK-NEXT:ret i32 0
 ;
 entry:
Index: llvm/test/Transforms/InstCombine/unused-nonnull.ll
===
--- llvm/test/Transforms/InstCombine/unused-nonnull.ll
+++ llvm/test/Transforms/InstCombine/unused-nonnull.ll
@@ -37,7 +37,7 @@
 
 define i32 @compute(i8* noundef nonnull %ptr, i32 %x) #1 {
 ; CHECK-LABEL: define {{[^@]+}}@compute
-; CHECK-SAME: (i8* nocapture nonnull readnone [[PTR:%.*]], i32 returned [[X:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] {
+; CHECK-SAME: (i8* nocapture noundef nonnull readnone [[PTR:%.*]], i32 returned [[X:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] {
 ; CHECK-NEXT:ret i32 [[X]]
 ;
   ret i32 %x
Index: llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
===
--- llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
+++ llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
@@ -58,7 +58,6 @@
 ; CHECK-O-NEXT: Running pass: CalledValuePropagationPass
 ; CHECK-O-NEXT: Running pass: GlobalOptPass
 ; CHECK-O-NEXT: Running pass: PromotePass
-; CHECK-O-NEXT: Running pass: DeadArgumentEliminationPass
 ; CHECK-O-NEXT: Running pass: InstCombinePass
 ; CHECK-O-NEXT: Running analysis: BlockFrequencyAnalysis on foo
 ; These next two can appear in any order since they are accessed as parameters
@@ -81,14 +80,13 @@
 ; CHECK-O-NEXT: Running pass: DevirtSCCRepeatedPass
 ; CHECK-O-NEXT: Running pass: InlinerPass
 ; CHECK-O-NEXT: Running pass: InlinerPass
-; CHECK-O-NEXT: Running pass: PostOrderFunctionAttrsPass
-; CHECK-O-NEXT: Running analysis: AAManager
 ; CHECK-O3-NEXT: Running pass: ArgumentPromotionPass
 ; CHECK-O2-NEXT: Running pass: OpenMPOptCGSCCPass
 ; CHECK-O3-NEXT: Running pass: OpenMPOptCGSCCPass
 ; CHECK-O-NEXT: Running pass: SROAPass
 ; CHECK-O-NEXT: Running pass: EarlyCSEPass
 ; CHECK-O-NEXT: Running analysis: MemorySSAAnalysis
+; CHECK-O-NEXT: Running analysis: AAManager
 ; CHECK-O23SZ-NEXT: Running pass: SpeculativeExecutionPass
 ; CHECK-O23SZ-NEXT: Running pass: JumpThreadingPass
 ; CHECK-O23SZ-NEXT: Running analysis: LazyValueAnalysis
@@ -160,8 +158,10 @@
 ; CHECK-O3-NEXT: Running pass: ControlHeightReductionPass on foo
 ; CHECK-O3-NEXT: Running analysis: RegionInfoAnalysis on foo
 ; CHECK-O3-NEXT: Running analysis: DominanceFrontierAnalysis on foo
+; CHECK-O-NEXT: Running pass: PostOrderFunctionAttrsPass
 ; CHECK-O-NEXT: Running pass: CoroSplitPass
 ; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis
+; CHECK-O-NEXT: Running pass: DeadArgumentEliminationPass
 ; CHECK-O-NEXT: Running pass: CoroCleanupPass
 ; CHECK-O-NEXT: Running pass: GlobalOptPass
 ; CHECK-O-NEXT: Running pass: AnnotationRemarksPass on foo
Index: llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
===
--- llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
+++ 

[PATCH] D128830: [Pipelines] Introduce DAE after ArgumentPromotion

2022-07-11 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

I'd tried moving func-attrs after the function simplification pipeline and 
perf-wise on internal benchmarks it looks fine, but it causes some compile time 
regressions: 
https://llvm-compile-time-tracker.com/compare.php?from=d3dd6e57fe84e90cadcdc78fa71d632f6573f156&to=592b8acec55f577713a5e1fb610a36c8742c682b&stat=instructions
My guess is something to do with caching/invalidating analyses but I'm not 100% 
sure


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128830/new/

https://reviews.llvm.org/D128830

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


[PATCH] D128830: [Pipelines] Introduce DAE after ArgumentPromotion

2022-07-11 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

(and we should definitely separate that out into its own patch first)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128830/new/

https://reviews.llvm.org/D128830

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


[PATCH] D129353: [clang-tidy] Improve check cert-dcl58-cpp.

2022-07-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM with some minor nits.




Comment at: 
clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp:80-81
+  auto BadNonTemplateSpecializationDecl =
+  decl(unless(isExpansionInSystemHeader()),
+   unless(anyOf(functionDecl(isExplicitTemplateSpecialization()),
+varDecl(isExplicitTemplateSpecialization()),

This one can go as well, right?



Comment at: clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp:209
+
+using myint = int;
 

Can you add a comment above this to mention that an alias declaration is the 
same as a typedef, and does not introduce a user-defined type, which is why the 
below fails.



Comment at: clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp:254
+
+namespace std {
+// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace

Same mention here about an alias declaration not being a user-defined type.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129353/new/

https://reviews.llvm.org/D129353

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


[PATCH] D103096: [analyzer] Implement cast for ranges of symbolic integers

2022-07-11 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov marked 10 inline comments as done.
ASDenysPetrov added a comment.

@martong Thank you for your patience. I started moving to a bit another 
direction that we can improving it iteratively.
Just spoiling, in my latest solution a single symbol will be associated to many 
classes. Here are also tricky cases:

---

Consider equalities

  a32 == (int8)b32
  b32 == c32

Class-Symbol map is:

  class1 { a32 , (int8)b32 }
  class2 { b32 , c32 }

Symbol-Class map is:

  a32 { 32 : class1 }
  b32 {  8 : class1, 32 : class2  }
  c32 { 32 : class2 }

If we know:

  (int8)c32 == -1

then what is:

  (int8)a32 - ?

Should we traverse like `a ->  32 -> class1 -> (int8)b32 -> b32 ->  class2 -> 
c32 -> (int8)c32 ` ?

---

The `x8 == y32` we can treat as a range of `int8` ( {-128, 127} or  {0, 255} ).

---

For `(int8)x32 == (int16)x32` we can eliminate one of the symbols in the class 
a s a redundant one.

---

If `x32 == 0` then we can simplify(merge) such classes `(int16)x32 == y` and 
`(int8)x32 == z` into a single class. I beleive there are more cases.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103096/new/

https://reviews.llvm.org/D103096

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


[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-07-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D109701#3642561 , @vaibhav.y wrote:

> Discard most likely culprit in test code causing unexpected crash.
>
> @aaron.ballman I was unable to reproduce the issue on my end using the 
> buildbot instructions and ASAN, UBSAN.
>
> Is it possible for you to trigger a pre-merge check on the LLVM cluster?

Unfortunately, there isn't.

> I have suspicions that it was the `SarifResult &&` type in the test so I 
> changed it to a `const SarifResult &`.
>
> I've tried running it on a RHEL 7, Darwin on my end.

If you think you've got it fixed, I think the best we can do is to re-commit 
and watch the bots to see how they react. I'll commit again for you and watch 
them.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109701/new/

https://reviews.llvm.org/D109701

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


[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-07-11 Thread Vaibhav Yenamandra via Phabricator via cfe-commits
vaibhav.y added a comment.

>> I have suspicions that it was the `SarifResult &&` type in the test so I 
>> changed it to a `const SarifResult &`.
>>
>> I've tried running it on a RHEL 7, Darwin on my end.
>
> If you think you've got it fixed, I think the best we can do is to re-commit 
> and watch the bots to see how they react. I'll commit again for you and watch 
> them.

Thank you! Let us try that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109701/new/

https://reviews.llvm.org/D109701

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


[clang] 69fcf4f - Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-07-11 Thread Aaron Ballman via cfe-commits

Author: Vaibhav Yenamandra
Date: 2022-07-11T12:18:13-04:00
New Revision: 69fcf4fd5a014b763061f13b5c4434d49c42c35a

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

LOG: Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

Create an interface for writing SARIF documents from within clang:

The primary intent of this change is to introduce the interface
clang::SarifDocumentWriter, which allows incrementally adding
diagnostic data to a JSON backed document. The proposed interface is
not yet connected to the compiler internals, which will be covered in
future work. As such this change will not change the input/output
interface of clang.

This change also introduces the clang::FullSourceRange type that is
modeled after clang::SourceRange + clang::FullSourceLoc, this is useful
for packaging a pair of clang::SourceLocation objects with their
corresponding SourceManagers.

Previous discussions:

RFC for this change: 
https://lists.llvm.org/pipermail/cfe-dev/2021-March/067907.html
https://lists.llvm.org/pipermail/cfe-dev/2021-July/068480.html
SARIF Standard (2.1.0):

https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html

Differential Revision: https://reviews.llvm.org/D109701

Added: 
clang/include/clang/Basic/Sarif.h
clang/lib/Basic/Sarif.cpp
clang/unittests/Basic/SarifTest.cpp

Modified: 
clang/lib/Basic/CMakeLists.txt
clang/unittests/Basic/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Basic/Sarif.h 
b/clang/include/clang/Basic/Sarif.h
new file mode 100644
index 0..818d78668ff15
--- /dev/null
+++ b/clang/include/clang/Basic/Sarif.h
@@ -0,0 +1,440 @@
+//== clang/Basic/Sarif.h - SARIF Diagnostics Object Model ---*- C++ 
-*--==//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// Defines clang::SarifDocumentWriter, clang::SarifRule, clang::SarifResult.
+///
+/// The document built can be accessed as a JSON Object.
+/// Several value semantic types are also introduced which represent properties
+/// of the SARIF standard, such as 'artifact', 'result', 'rule'.
+///
+/// A SARIF (Static Analysis Results Interchange Format) document is JSON
+/// document that describes in detail the results of running static analysis
+/// tools on a project. Each (non-trivial) document consists of at least one
+/// "run", which are themselves composed of details such as:
+/// * Tool: The tool that was run
+/// * Rules: The rules applied during the tool run, represented by
+///   \c reportingDescriptor objects in SARIF
+/// * Results: The matches for the rules applied against the project(s) being
+///   evaluated, represented by \c result objects in SARIF
+///
+/// Reference:
+/// 1. https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html";>The
 SARIF standard
+/// 2. https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317836";>SARIFreportingDescriptor
+/// 3. https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317638";>SARIFresult
+//===--===//
+
+#ifndef LLVM_CLANG_BASIC_SARIF_H
+#define LLVM_CLANG_BASIC_SARIF_H
+
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/Version.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace clang {
+
+class SarifDocumentWriter;
+class SourceManager;
+
+namespace detail {
+
+/// \internal
+/// An artifact location is SARIF's way of describing the complete location
+/// of an artifact encountered during analysis. The \c artifactLocation object
+/// typically consists of a URI, and/or an index to reference the artifact it
+/// locates.
+///
+/// This builder makes an additional assumption: that every artifact 
encountered
+/// by \c clang will be a physical, top-level artifact. Which is why the static
+/// creation method \ref SarifArtifactLocation::create takes a mandatory URI
+/// parameter. The official standard states that either a \c URI or \c Index
+/// must be available in the object, \c clang picks the \c URI as a reasonable
+/// default, because it intends to deal in physical artifacts for now.
+///
+/// Reference:
+/// 1. https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317427";>artifactLocation
 object
+/// 2. \ref SarifArtifact
+class SarifArtifactL

[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-07-11 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG69fcf4fd5a01: Emit SARIF Diagnostics: Create 
`clang::SarifDocumentWriter` interface (authored by vaibhav.y, committed by 
aaron.ballman).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109701/new/

https://reviews.llvm.org/D109701

Files:
  clang/include/clang/Basic/Sarif.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Sarif.cpp
  clang/unittests/Basic/CMakeLists.txt
  clang/unittests/Basic/SarifTest.cpp

Index: clang/unittests/Basic/SarifTest.cpp
===
--- /dev/null
+++ clang/unittests/Basic/SarifTest.cpp
@@ -0,0 +1,320 @@
+//===- unittests/Basic/SarifTest.cpp - Test writing SARIF documents ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Sarif.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gmock/gmock-matchers.h"
+#include "gtest/gtest-death-test.h"
+#include "gtest/gtest-matchers.h"
+#include "gtest/gtest.h"
+
+#include 
+
+using namespace clang;
+
+namespace {
+
+using LineCol = std::pair;
+
+static std::string serializeSarifDocument(llvm::json::Object &&Doc) {
+  std::string Output;
+  llvm::json::Value value(std::move(Doc));
+  llvm::raw_string_ostream OS{Output};
+  OS << llvm::formatv("{0}", value);
+  OS.flush();
+  return Output;
+}
+
+class SarifDocumentWriterTest : public ::testing::Test {
+protected:
+  SarifDocumentWriterTest()
+  : InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem),
+FileMgr(FileSystemOptions(), InMemoryFileSystem),
+DiagID(new DiagnosticIDs()), DiagOpts(new DiagnosticOptions()),
+Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr) {}
+
+  IntrusiveRefCntPtr InMemoryFileSystem;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  IntrusiveRefCntPtr DiagOpts;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+
+  FileID registerSource(llvm::StringRef Name, const char *SourceText,
+bool IsMainFile = false) {
+std::unique_ptr SourceBuf =
+llvm::MemoryBuffer::getMemBuffer(SourceText);
+const FileEntry *SourceFile =
+FileMgr.getVirtualFile(Name, SourceBuf->getBufferSize(), 0);
+SourceMgr.overrideFileContents(SourceFile, std::move(SourceBuf));
+FileID FID = SourceMgr.getOrCreateFileID(SourceFile, SrcMgr::C_User);
+if (IsMainFile)
+  SourceMgr.setMainFileID(FID);
+return FID;
+  }
+
+  CharSourceRange getFakeCharSourceRange(FileID FID, LineCol Begin,
+ LineCol End) {
+auto BeginLoc = SourceMgr.translateLineCol(FID, Begin.first, Begin.second);
+auto EndLoc = SourceMgr.translateLineCol(FID, End.first, End.second);
+return CharSourceRange{SourceRange{BeginLoc, EndLoc}, /* ITR = */ false};
+  }
+};
+
+TEST_F(SarifDocumentWriterTest, createEmptyDocument) {
+  // GIVEN:
+  SarifDocumentWriter Writer{SourceMgr};
+
+  // WHEN:
+  const llvm::json::Object &EmptyDoc = Writer.createDocument();
+  std::vector Keys(EmptyDoc.size());
+  std::transform(EmptyDoc.begin(), EmptyDoc.end(), Keys.begin(),
+ [](auto item) { return item.getFirst(); });
+
+  // THEN:
+  ASSERT_THAT(Keys, testing::UnorderedElementsAre("$schema", "version"));
+}
+
+// Test that a newly inserted run will associate correct tool names
+TEST_F(SarifDocumentWriterTest, documentWithARun) {
+  // GIVEN:
+  SarifDocumentWriter Writer{SourceMgr};
+  const char *ShortName = "sariftest";
+  const char *LongName = "sarif writer test";
+
+  // WHEN:
+  Writer.createRun(ShortName, LongName);
+  Writer.endRun();
+  const llvm::json::Object &Doc = Writer.createDocument();
+  const llvm::json::Array *Runs = Doc.getArray("runs");
+
+  // THEN:
+  // A run was created
+  ASSERT_THAT(Runs, testing::NotNull());
+
+  // It is the only run
+  ASSERT_EQ(Runs->size(), 1UL);
+
+  // The tool associated with the run was the tool
+  const llvm::json::Object *driver =
+  Runs->begin()->getAsObject()->getObject("tool")->getObject("driver");
+  ASSERT_THAT(driver, testing::NotNull());
+
+  ASSERT_TRUE

[PATCH] D129498: [analyzer] Add new function `clang_analyzer_value` to ExprInspectionChecker

2022-07-11 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: martong, steakhal, NoQ, Charusso.
ASDenysPetrov added a project: clang.
Herald added subscribers: manas, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
ASDenysPetrov requested review of this revision.
Herald added a subscriber: cfe-commits.

Introduce a new function `clang_analyzer_value`. It emits a report that in turn 
prints a `RangeSet` or `APSInt` associated with `SVal`. If there is no 
associated value, prints `n/a`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129498

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/SVals.cpp
  clang/test/Analysis/print-ranges.cpp

Index: clang/test/Analysis/print-ranges.cpp
===
--- /dev/null
+++ clang/test/Analysis/print-ranges.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config eagerly-assume=false -verify %s
+
+template 
+void clang_analyzer_value(T x);
+void clang_analyzer_value();
+template 
+void clang_analyzer_value(T1 x, T2 y);
+
+void test1(char x) {
+  clang_analyzer_value(x); // expected-warning{{8s:{ [-128, 127] }}}
+  if (x > 42)
+clang_analyzer_value(x); // expected-warning{{8s:{ [43, 127] }}}
+  if (x == 42)
+clang_analyzer_value(x); // expected-warning{{8s:42}}
+}
+
+void test2(short x) {
+  clang_analyzer_value(x); // expected-warning{{16s:{ [-32768, 32767] }}}
+  if (x < 4200)
+clang_analyzer_value(x); // expected-warning{{16s:{ [-32768, 4199] }}}
+  if (x == 4200)
+clang_analyzer_value(x); // expected-warning{{16s:4200}}
+}
+
+void test3(unsigned long long x) {
+  clang_analyzer_value(x); // expected-warning{{64u:{ [0, 18446744073709551615] }}}
+  if (x != 4200)
+clang_analyzer_value(x); // expected-warning{{64u:{ [0, 4199], [4201, 18446744073709551615] }}}
+  if (x == 18446744073709551615ull)
+clang_analyzer_value(x); // expected-warning{{64u:18446744073709551615}}
+}
+
+struct S {};
+void test4(S s) {
+  clang_analyzer_value(s); // expected-warning{{n/a}}
+}
+
+void test5() {
+  clang_analyzer_value(); // expected-warning{{Missing argument}}
+}
+
+void test6(int x, int y) {
+  if (x == 42 && y == 24)
+// Ignore 'y'.
+clang_analyzer_value(x, y); // expected-warning{{32s:42}}
+}
Index: clang/lib/StaticAnalyzer/Core/SVals.cpp
===
--- clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -109,6 +109,14 @@
   return getAsLocSymbol(IncludeBaseRegions);
 }
 
+const llvm::APSInt *SVal::getAsInteger() const {
+  if (auto CI = getAs())
+return &CI->getValue();
+  if (auto CI = getAs())
+return &CI->getValue();
+  return nullptr;
+}
+
 const MemRegion *SVal::getAsRegion() const {
   if (Optional X = getAs())
 return X->getRegion();
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1801,6 +1801,8 @@
 
   void printJson(raw_ostream &Out, ProgramStateRef State, const char *NL = "\n",
  unsigned int Space = 0, bool IsDot = false) const override;
+  void printRange(raw_ostream &Out, ProgramStateRef State,
+  SymbolRef Sym) override;
   void printConstraints(raw_ostream &Out, ProgramStateRef State,
 const char *NL = "\n", unsigned int Space = 0,
 bool IsDot = false) const;
@@ -3154,6 +3156,13 @@
   printDisequalities(Out, State, NL, Space, IsDot);
 }
 
+void RangeConstraintManager::printRange(raw_ostream &Out, ProgramStateRef State,
+SymbolRef Sym) {
+  const RangeSet RS = getRange(State, Sym);
+  Out << RS.getBitWidth() << (RS.isUnsigned() ? "u:" : "s:");
+  RS.dump(Out);
+}
+
 static std::string toString(const SymbolRef &Sym) {
   std::string S;
   llvm::raw_string_ostream O(S);
Index: clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -40,6 +40,7 @@
   void analyzerNumTimesReached(const CallExpr *CE, CheckerContext &C) const;
   void analyzerCrash(const CallExpr *CE, CheckerContext &C) const;
   void analyzerWarnOnDeadSymbol(const CallExpr *CE, CheckerContext &C) const;
+  void analyzerValue(const CallExpr *CE, CheckerContext &C) const;
   

[PATCH] D129499: [clang] Do not crash on "requires" after a fatal error occurred.

2022-07-11 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
adamcz added a reviewer: ilya-biryukov.
Herald added a project: All.
adamcz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The code would assume that SubstExpr() cannot fail on concept
specialization. This is incorret - we give up on some things after fatal
error occurred, since there's no value in doing futher work that the
user will not see anyway. In this case, this lead to crash.

The fatal error is simulated in tests with -ferror-limit=1, but this
could happen in other cases too.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129499

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/concept-fatal-error.cpp


Index: clang/test/SemaCXX/concept-fatal-error.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/concept-fatal-error.cpp
@@ -0,0 +1,11 @@
+// RUN: not %clang_cc1 -fsyntax-only -std=c++20 -ferror-limit 1 %s 2>&1 | 
FileCheck %s
+
+template 
+concept f = requires { 42; };
+struct h {
+  // The missing semicolon will trigger an error and -ferror-limit=1 will make 
it fatal
+  // We test that we do not crash in such cases (#55401)
+  int i = requires { { i } f } // expected-error {{expected ';' at end of 
declaration list}}
+
+  // CHECK: fatal error: too many errors emitted, stopping now
+};
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -8971,14 +8971,14 @@
 cast(TPL->getParam(0))->getTypeConstraint()
 ->getImmediatelyDeclaredConstraint();
 ExprResult Constraint = SubstExpr(IDC, MLTAL);
-assert(!Constraint.isInvalid() &&
-   "Substitution cannot fail as it is simply putting a type template "
-   "argument into a concept specialization expression's parameter.");
-
-SubstitutedConstraintExpr =
-cast(Constraint.get());
-if (!SubstitutedConstraintExpr->isSatisfied())
-  Status = concepts::ExprRequirement::SS_ConstraintsNotSatisfied;
+if (Constraint.isInvalid()) {
+  Status = concepts::ExprRequirement::SS_ExprSubstitutionFailure;
+} else {
+  SubstitutedConstraintExpr =
+  cast(Constraint.get());
+  if (!SubstitutedConstraintExpr->isSatisfied())
+Status = concepts::ExprRequirement::SS_ConstraintsNotSatisfied;
+}
   }
   return new (Context) concepts::ExprRequirement(E, IsSimple, NoexceptLoc,
  ReturnTypeRequirement, Status,


Index: clang/test/SemaCXX/concept-fatal-error.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/concept-fatal-error.cpp
@@ -0,0 +1,11 @@
+// RUN: not %clang_cc1 -fsyntax-only -std=c++20 -ferror-limit 1 %s 2>&1 | FileCheck %s
+
+template 
+concept f = requires { 42; };
+struct h {
+  // The missing semicolon will trigger an error and -ferror-limit=1 will make it fatal
+  // We test that we do not crash in such cases (#55401)
+  int i = requires { { i } f } // expected-error {{expected ';' at end of declaration list}}
+
+  // CHECK: fatal error: too many errors emitted, stopping now
+};
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -8971,14 +8971,14 @@
 cast(TPL->getParam(0))->getTypeConstraint()
 ->getImmediatelyDeclaredConstraint();
 ExprResult Constraint = SubstExpr(IDC, MLTAL);
-assert(!Constraint.isInvalid() &&
-   "Substitution cannot fail as it is simply putting a type template "
-   "argument into a concept specialization expression's parameter.");
-
-SubstitutedConstraintExpr =
-cast(Constraint.get());
-if (!SubstitutedConstraintExpr->isSatisfied())
-  Status = concepts::ExprRequirement::SS_ConstraintsNotSatisfied;
+if (Constraint.isInvalid()) {
+  Status = concepts::ExprRequirement::SS_ExprSubstitutionFailure;
+} else {
+  SubstitutedConstraintExpr =
+  cast(Constraint.get());
+  if (!SubstitutedConstraintExpr->isSatisfied())
+Status = concepts::ExprRequirement::SS_ConstraintsNotSatisfied;
+}
   }
   return new (Context) concepts::ExprRequirement(E, IsSimple, NoexceptLoc,
  ReturnTypeRequirement, Status,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c8a28ae - Revert "Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface"

2022-07-11 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-07-11T12:28:31-04:00
New Revision: c8a28ae214c08c8447a4eb42418585b2b3eef6fb

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

LOG: Revert "Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` 
interface"

This reverts commit 69fcf4fd5a014b763061f13b5c4434d49c42c35a.

It broke at least one bot:
https://lab.llvm.org/buildbot/#/builders/91/builds/11328

Added: 


Modified: 
clang/lib/Basic/CMakeLists.txt
clang/unittests/Basic/CMakeLists.txt

Removed: 
clang/include/clang/Basic/Sarif.h
clang/lib/Basic/Sarif.cpp
clang/unittests/Basic/SarifTest.cpp



diff  --git a/clang/include/clang/Basic/Sarif.h 
b/clang/include/clang/Basic/Sarif.h
deleted file mode 100644
index 818d78668ff15..0
--- a/clang/include/clang/Basic/Sarif.h
+++ /dev/null
@@ -1,440 +0,0 @@
-//== clang/Basic/Sarif.h - SARIF Diagnostics Object Model ---*- C++ 
-*--==//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-/// \file
-/// Defines clang::SarifDocumentWriter, clang::SarifRule, clang::SarifResult.
-///
-/// The document built can be accessed as a JSON Object.
-/// Several value semantic types are also introduced which represent properties
-/// of the SARIF standard, such as 'artifact', 'result', 'rule'.
-///
-/// A SARIF (Static Analysis Results Interchange Format) document is JSON
-/// document that describes in detail the results of running static analysis
-/// tools on a project. Each (non-trivial) document consists of at least one
-/// "run", which are themselves composed of details such as:
-/// * Tool: The tool that was run
-/// * Rules: The rules applied during the tool run, represented by
-///   \c reportingDescriptor objects in SARIF
-/// * Results: The matches for the rules applied against the project(s) being
-///   evaluated, represented by \c result objects in SARIF
-///
-/// Reference:
-/// 1. https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html";>The
 SARIF standard
-/// 2. https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317836";>SARIFreportingDescriptor
-/// 3. https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317638";>SARIFresult
-//===--===//
-
-#ifndef LLVM_CLANG_BASIC_SARIF_H
-#define LLVM_CLANG_BASIC_SARIF_H
-
-#include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/Version.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/JSON.h"
-#include 
-#include 
-#include 
-#include 
-#include 
-
-namespace clang {
-
-class SarifDocumentWriter;
-class SourceManager;
-
-namespace detail {
-
-/// \internal
-/// An artifact location is SARIF's way of describing the complete location
-/// of an artifact encountered during analysis. The \c artifactLocation object
-/// typically consists of a URI, and/or an index to reference the artifact it
-/// locates.
-///
-/// This builder makes an additional assumption: that every artifact 
encountered
-/// by \c clang will be a physical, top-level artifact. Which is why the static
-/// creation method \ref SarifArtifactLocation::create takes a mandatory URI
-/// parameter. The official standard states that either a \c URI or \c Index
-/// must be available in the object, \c clang picks the \c URI as a reasonable
-/// default, because it intends to deal in physical artifacts for now.
-///
-/// Reference:
-/// 1. https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317427";>artifactLocation
 object
-/// 2. \ref SarifArtifact
-class SarifArtifactLocation {
-private:
-  friend class clang::SarifDocumentWriter;
-
-  llvm::Optional Index;
-  std::string URI;
-
-  SarifArtifactLocation() = delete;
-  explicit SarifArtifactLocation(const std::string &URI) : URI(URI) {}
-
-public:
-  static SarifArtifactLocation create(llvm::StringRef URI) {
-return SarifArtifactLocation{URI.str()};
-  }
-
-  SarifArtifactLocation setIndex(uint32_t Idx) {
-Index = Idx;
-return *this;
-  }
-};
-
-/// \internal
-/// An artifact in SARIF is any object (a sequence of bytes) addressable by
-/// a URI (RFC 3986). The most common type of artifact for clang's use-case
-/// would be source files. SARIF's artifact object is described in detail in
-/// section 3.24.
-//
-/// Since every clang artifact MUST have a location (there being no nested
-/// artifacts), the creation met

[PATCH] D129373: [NFC] Minor cleanup of usage of FloatModeKind with bitmask enums

2022-07-11 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann accepted this revision.
tahonermann added a comment.
This revision is now accepted and ready to land.

Looks good, thank you for following up @jolanta.jensen!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129373/new/

https://reviews.llvm.org/D129373

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


[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-07-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman reopened this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Unfortunately, it still seems to be causing failures (I had to revert again):

https://lab.llvm.org/buildbot/#/builders/91/builds/11840

It looks to be the same failure as before 
(https://lab.llvm.org/buildbot/#/builders/91/builds/11328). :-(


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109701/new/

https://reviews.llvm.org/D109701

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


[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-07-11 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

This breaks TestDataFormatterLibcxxSpan.py on GreenDragon:

  Undefined symbols for architecture x86_64:
"__ZGIW10std_config", referenced from:
__GLOBAL__sub_I_main.cpp in main.o
"__ZGIW4span", referenced from:
__GLOBAL__sub_I_main.cpp in main.o
"__ZGIW5array", referenced from:
__GLOBAL__sub_I_main.cpp in main.o
"__ZGIW5stdio", referenced from:
__GLOBAL__sub_I_main.cpp in main.o
"__ZGIW6string", referenced from:
__GLOBAL__sub_I_main.cpp in main.o
"__ZGIW6vector", referenced from:
__GLOBAL__sub_I_main.cpp in main.o

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45207/


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126189/new/

https://reviews.llvm.org/D126189

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


Re: [clang] c8a28ae - Revert "Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface"

2022-07-11 Thread Aaron Ballman via cfe-commits
On Mon, Jul 11, 2022 at 12:28 PM Aaron Ballman via cfe-commits
 wrote:
>
>
> Author: Aaron Ballman
> Date: 2022-07-11T12:28:31-04:00
> New Revision: c8a28ae214c08c8447a4eb42418585b2b3eef6fb
>
> URL: 
> https://github.com/llvm/llvm-project/commit/c8a28ae214c08c8447a4eb42418585b2b3eef6fb
> DIFF: 
> https://github.com/llvm/llvm-project/commit/c8a28ae214c08c8447a4eb42418585b2b3eef6fb.diff
>
> LOG: Revert "Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` 
> interface"
>
> This reverts commit 69fcf4fd5a014b763061f13b5c4434d49c42c35a.
>
> It broke at least one bot:
> https://lab.llvm.org/buildbot/#/builders/91/builds/11328

Apologies, I managed to paste the old failure link, the new failure
is: https://lab.llvm.org/buildbot/#/builders/91/builds/11840

~Aaron

>
> Added:
>
>
> Modified:
> clang/lib/Basic/CMakeLists.txt
> clang/unittests/Basic/CMakeLists.txt
>
> Removed:
> clang/include/clang/Basic/Sarif.h
> clang/lib/Basic/Sarif.cpp
> clang/unittests/Basic/SarifTest.cpp
>
>
> 
> diff  --git a/clang/include/clang/Basic/Sarif.h 
> b/clang/include/clang/Basic/Sarif.h
> deleted file mode 100644
> index 818d78668ff15..0
> --- a/clang/include/clang/Basic/Sarif.h
> +++ /dev/null
> @@ -1,440 +0,0 @@
> -//== clang/Basic/Sarif.h - SARIF Diagnostics Object Model ---*- C++ 
> -*--==//
> -//
> -// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
> Exceptions.
> -// See https://llvm.org/LICENSE.txt for license information.
> -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
> -//
> -//===--===//
> -/// \file
> -/// Defines clang::SarifDocumentWriter, clang::SarifRule, clang::SarifResult.
> -///
> -/// The document built can be accessed as a JSON Object.
> -/// Several value semantic types are also introduced which represent 
> properties
> -/// of the SARIF standard, such as 'artifact', 'result', 'rule'.
> -///
> -/// A SARIF (Static Analysis Results Interchange Format) document is JSON
> -/// document that describes in detail the results of running static analysis
> -/// tools on a project. Each (non-trivial) document consists of at least one
> -/// "run", which are themselves composed of details such as:
> -/// * Tool: The tool that was run
> -/// * Rules: The rules applied during the tool run, represented by
> -///   \c reportingDescriptor objects in SARIF
> -/// * Results: The matches for the rules applied against the project(s) being
> -///   evaluated, represented by \c result objects in SARIF
> -///
> -/// Reference:
> -/// 1.  href="https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html";>The
>  SARIF standard
> -/// 2.  href="https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317836";>SARIFreportingDescriptor
> -/// 3.  href="https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317638";>SARIFresult
> -//===--===//
> -
> -#ifndef LLVM_CLANG_BASIC_SARIF_H
> -#define LLVM_CLANG_BASIC_SARIF_H
> -
> -#include "clang/Basic/SourceLocation.h"
> -#include "clang/Basic/Version.h"
> -#include "llvm/ADT/ArrayRef.h"
> -#include "llvm/ADT/Optional.h"
> -#include "llvm/ADT/SmallVector.h"
> -#include "llvm/ADT/StringMap.h"
> -#include "llvm/ADT/StringRef.h"
> -#include "llvm/Support/JSON.h"
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -
> -namespace clang {
> -
> -class SarifDocumentWriter;
> -class SourceManager;
> -
> -namespace detail {
> -
> -/// \internal
> -/// An artifact location is SARIF's way of describing the complete location
> -/// of an artifact encountered during analysis. The \c artifactLocation 
> object
> -/// typically consists of a URI, and/or an index to reference the artifact it
> -/// locates.
> -///
> -/// This builder makes an additional assumption: that every artifact 
> encountered
> -/// by \c clang will be a physical, top-level artifact. Which is why the 
> static
> -/// creation method \ref SarifArtifactLocation::create takes a mandatory URI
> -/// parameter. The official standard states that either a \c URI or \c Index
> -/// must be available in the object, \c clang picks the \c URI as a 
> reasonable
> -/// default, because it intends to deal in physical artifacts for now.
> -///
> -/// Reference:
> -/// 1.  href="https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317427";>artifactLocation
>  object
> -/// 2. \ref SarifArtifact
> -class SarifArtifactLocation {
> -private:
> -  friend class clang::SarifDocumentWriter;
> -
> -  llvm::Optional Index;
> -  std::string URI;
> -
> -  SarifArtifactLocation() = delete;
> -  explicit SarifArtifactLocation(const std::string &URI) : URI(URI) {}
> -
> -public:
> -  static SarifArtifactLocation create(llvm::StringRef URI) {
> -return SarifArtifactLocation{URI.str(

[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-07-11 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D126189#3642762 , @JDevlieghere 
wrote:

> This breaks TestDataFormatterLibcxxSpan.py on GreenDragon:
>
>   Undefined symbols for architecture x86_64:
> "__ZGIW10std_config", referenced from:
> __GLOBAL__sub_I_main.cpp in main.o
> "__ZGIW4span", referenced from:
> __GLOBAL__sub_I_main.cpp in main.o
> "__ZGIW5array", referenced from:
> __GLOBAL__sub_I_main.cpp in main.o
> "__ZGIW5stdio", referenced from:
> __GLOBAL__sub_I_main.cpp in main.o
> "__ZGIW6string", referenced from:
> __GLOBAL__sub_I_main.cpp in main.o
> "__ZGIW6vector", referenced from:
> __GLOBAL__sub_I_main.cpp in main.o
>
> https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45207/

ack, (I develop on macOS so usually catch these things)...
do you need me to revert the commit - or can we try to find out what's broken 
and fix it?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126189/new/

https://reviews.llvm.org/D126189

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


[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-07-11 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

In D126189#3642777 , @iains wrote:

> In D126189#3642762 , @JDevlieghere 
> wrote:
>
>> This breaks TestDataFormatterLibcxxSpan.py on GreenDragon:
>>
>>   Undefined symbols for architecture x86_64:
>> "__ZGIW10std_config", referenced from:
>> __GLOBAL__sub_I_main.cpp in main.o
>> "__ZGIW4span", referenced from:
>> __GLOBAL__sub_I_main.cpp in main.o
>> "__ZGIW5array", referenced from:
>> __GLOBAL__sub_I_main.cpp in main.o
>> "__ZGIW5stdio", referenced from:
>> __GLOBAL__sub_I_main.cpp in main.o
>> "__ZGIW6string", referenced from:
>> __GLOBAL__sub_I_main.cpp in main.o
>> "__ZGIW6vector", referenced from:
>> __GLOBAL__sub_I_main.cpp in main.o
>>
>> https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45207/
>
> ack, (I develop on macOS so usually catch these things)...
> do you need me to revert the commit - or can we try to find out what's broken 
> and fix it?

If you think you'll be able to get to the bottom of this quickly then I don't 
think we need to revert, but the bot has been red for a while (which means that 
other issues can get buried) so I'd like to get it green ASAP.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126189/new/

https://reviews.llvm.org/D126189

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


[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-07-11 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D126189#3642777 , @iains wrote:

> In D126189#3642762 , @JDevlieghere 
> wrote:
>
>> This breaks TestDataFormatterLibcxxSpan.py on GreenDragon:
>>
>>   Undefined symbols for architecture x86_64:

..

>>   "__ZGIW6vector", referenced from:
>>   __GLOBAL__sub_I_main.cpp in main.o
>>
>>   https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45207/
>
> ack, (I develop on macOS so usually catch these things)...
> do you need me to revert the commit - or can we try to find out what's broken 
> and fix it?

hmm there seems to be a compiler error, which looks somewhat unrelated to the 
active patch:

  
/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp:125:27:
 error: no type named 'size_t' in namespace 'std'
void* operator new(std::size_t, T) {
   ~^
  
/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp:132:29:
 error: no type named 'size_t' in namespace 'std'
void* operator new[](std::size_t, T) {


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126189/new/

https://reviews.llvm.org/D126189

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


[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-07-11 Thread Vaibhav Yenamandra via Phabricator via cfe-commits
vaibhav.y added a comment.

In D109701#3642748 , @aaron.ballman 
wrote:

> Unfortunately, it still seems to be causing failures (I had to revert again):
>
> https://lab.llvm.org/buildbot/#/builders/91/builds/11840
>
> It looks to be the same failure as before 
> (https://lab.llvm.org/buildbot/#/builders/91/builds/11328). :-(

Thanks, fortunately this seems to be reproducible. Perhaps there's something 
special about my environment making it work. I'll try to pare down more 
(possibly try to build inside a container).

The buildbot properties say its Linux aurora is there an official container / 
build spec I can use to mimic the environment?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109701/new/

https://reviews.llvm.org/D109701

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


[PATCH] D129068: [AST] Accept identical TypeConstraint referring to other template parameters.

2022-07-11 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

A few NITs from my side, hopefully they can improve things a bit.




Comment at: clang/include/clang/AST/ASTContext.h:2676
 
+  /// Determine whether two 'requires' expressions are similar enough.
+  /// Use of 'requires' isn't mandatory, works with constraints expressed in

NIT: maybe be more specific here?
It's not clear what "similar enough" means without context, other comments 
follow the pattern.



Comment at: clang/lib/AST/ASTContext.cpp:6254
 return false;
   if (TXTC->hasExplicitTemplateArgs() != TYTC->hasExplicitTemplateArgs())
 return false;

Do we even want to compare the template argument sizes here?
Would comparing only `getImmediatelyDeclaredConstraint` produce the same 
results?

If that's a performance optimization, we are probably better off moving it 
inside `isSameConstraintExpr`.



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129068/new/

https://reviews.llvm.org/D129068

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


[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-07-11 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D126189#3642779 , @JDevlieghere 
wrote:

> In D126189#3642777 , @iains wrote:
>
>> In D126189#3642762 , @JDevlieghere 
>> wrote:
>>
>>> This breaks TestDataFormatterLibcxxSpan.py on GreenDragon:



>>> https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45207/
>>
>> ack, (I develop on macOS so usually catch these things)...
>> do you need me to revert the commit - or can we try to find out what's 
>> broken and fix it?
>
> If you think you'll be able to get to the bottom of this quickly then I don't 
> think we need to revert, but the bot has been red for a while (which means 
> that other issues can get buried) so I'd like to get it green ASAP.

JFTR, I did not get any notification from green dragon (which is odd, AFAIR 
it's sent email before) or I would have looked right away  - kicked off a build 
will take a look as soon as that's done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126189/new/

https://reviews.llvm.org/D126189

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


[PATCH] D112621: [analyzer][solver] Introduce reasoning for not equal to operator

2022-07-11 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@manas ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112621/new/

https://reviews.llvm.org/D112621

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


[PATCH] D103313: [RISCV][Clang] Add support for Zmmul extension

2022-07-11 Thread Craig Topper via Phabricator via cfe-commits
craig.topper requested changes to this revision.
craig.topper added a comment.
This revision now requires changes to proceed.

Need to update RISCVTargetLowering::decomposeMulByConstant.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103313/new/

https://reviews.llvm.org/D103313

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


[PATCH] D129435: [Clang] Parse toolchain-specific offloading arguments directly

2022-07-11 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.

LGTM. Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129435/new/

https://reviews.llvm.org/D129435

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


[clang] ac892c7 - [OMPIRBuilder] Add support for simdlen clause

2022-07-11 Thread Arnamoy Bhattacharyya via cfe-commits

Author: Prabhdeep Singh Soni
Date: 2022-07-11T13:29:06-04:00
New Revision: ac892c70a456a443ef5d52ec886b4b6b0fae9244

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

LOG: [OMPIRBuilder] Add support for simdlen clause

This patch adds OMPIRBuilder support for the simdlen clause for the
simd directive. It uses the simdlen support in OpenMPIRBuilder when
it is enabled in Clang. Simdlen is lowered by OpenMPIRBuilder by
generating the loop.vectorize.width metadata.

Reviewed By: jdoerfert, Meinersbur

Differential Revision: https://reviews.llvm.org/D129149

Added: 
clang/test/OpenMP/irbuilder_simdlen.cpp

Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/irbuilder_simd.cpp
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
llvm/utils/UpdateTestChecks/common.py
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 63c446335c41a..db0b2ffd3a4f6 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -2591,11 +2591,12 @@ static void emitOMPSimdRegion(CodeGenFunction &CGF, 
const OMPLoopDirective &S,
   }
 }
 
-static bool isSupportedByOpenMPIRBuilder(const OMPExecutableDirective &S) {
+static bool isSupportedByOpenMPIRBuilder(const OMPSimdDirective &S) {
   // Check for unsupported clauses
-  if (!S.clauses().empty()) {
-// Currently no clause is supported
-return false;
+  for (OMPClause *C : S.clauses()) {
+// Currently only simdlen clause is supported
+if (!isa(C))
+  return false;
   }
 
   // Check if we have a statement with the ordered directive.
@@ -2630,7 +2631,6 @@ void CodeGenFunction::EmitOMPSimdDirective(const 
OMPSimdDirective &S) {
   // Use the OpenMPIRBuilder if enabled.
   if (UseOMPIRBuilder) {
 // Emit the associated statement and get its loop representation.
-llvm::DebugLoc DL = SourceLocToDebugLoc(S.getBeginLoc());
 const Stmt *Inner = S.getRawStmt();
 llvm::CanonicalLoopInfo *CLI =
 EmitOMPCollapsedCanonicalLoopNest(Inner, 1);
@@ -2638,7 +2638,15 @@ void CodeGenFunction::EmitOMPSimdDirective(const 
OMPSimdDirective &S) {
 llvm::OpenMPIRBuilder &OMPBuilder =
 CGM.getOpenMPRuntime().getOMPBuilder();
 // Add SIMD specific metadata
-OMPBuilder.applySimd(DL, CLI);
+llvm::ConstantInt *Simdlen = nullptr;
+if (const auto *C = S.getSingleClause()) {
+  RValue Len =
+  this->EmitAnyExpr(C->getSimdlen(), AggValueSlot::ignored(),
+/*ignoreResult=*/true);
+  auto *Val = cast(Len.getScalarVal());
+  Simdlen = Val;
+}
+OMPBuilder.applySimd(CLI, Simdlen);
 return;
   }
 };

diff  --git a/clang/test/OpenMP/irbuilder_simd.cpp 
b/clang/test/OpenMP/irbuilder_simd.cpp
index 2112c53049016..5fd5117f07a81 100644
--- a/clang/test/OpenMP/irbuilder_simd.cpp
+++ b/clang/test/OpenMP/irbuilder_simd.cpp
@@ -68,4 +68,4 @@ void simple(float *a, float *b, int *c) {
 // CHECK-NEXT: ![[META6]]  = !{!"llvm.loop.vectorize.enable", i1 true}
 // CHECK-NEXT: ![[META7:[0-9]+]] = distinct !{}
 // CHECK-NEXT: ![[META8]]  = distinct !{![[META8]], ![[META9:[0-9]+]], 
![[META6]]}
-// CHECK-NEXT: ![[META9]]  = !{!"llvm.loop.parallel_accesses", ![[META7]]}
\ No newline at end of file
+// CHECK-NEXT: ![[META9]]  = !{!"llvm.loop.parallel_accesses", ![[META7]]}

diff  --git a/clang/test/OpenMP/irbuilder_simdlen.cpp 
b/clang/test/OpenMP/irbuilder_simdlen.cpp
new file mode 100644
index 0..11714fac616d1
--- /dev/null
+++ b/clang/test/OpenMP/irbuilder_simdlen.cpp
@@ -0,0 +1,139 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals
+// RUN: %clang_cc1 -no-opaque-pointers -fopenmp-enable-irbuilder -verify 
-fopenmp -fopenmp-version=45 -x c++ -triple x86_64-unknown-unknown -emit-llvm 
%s -o - | FileCheck %s
+// expected-no-diagnostics
+
+struct S {
+  int a, b;
+};
+
+struct P {
+  int a, b;
+};
+
+// CHECK-LABEL: @_Z6simplePfS_Pi(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca float*, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca float*, align 8
+// CHECK-NEXT:[[C_ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NEXT:[[S:%.*]] = alloca [[STRUCT_S:%.*]], align 4
+// CHECK-NEXT:[[P:%.*]] = alloca %struct.S*, align 8
+// CHECK-NEXT:[[PP:%.*]] = alloca [[STRUCT_P:%.*]], align 4
+// CHECK-NEXT:[[I:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], align 8
+// CHECK-NEXT:[[

[PATCH] D128914: [HIP] Add support for handling HIP in the linker wrapper

2022-07-11 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D128914#3642567 , @jhuber6 wrote:

> In D128914#3642558 , 
> @JonChesterfield wrote:
>
>> Code looks good to me. It's hard to be sure whether it works without running 
>> a bunch of hip test cases through it, have you already done so? If it 
>> doesn't work out of the box it should be close enough to fix up post commit, 
>> e.g. when trying to move hip over to this by default.
>
> Thanks for the review, I ran a couple mini-apps with HIP versions (XSBench, 
> RSBench, SU3Bench) using this method and they passed without issue. The only 
> thing I was unsure about what whether or not the handle needed to be checked 
> for null, because my testing suggested it's unnecessary. I was hoping one of 
> the HIP developers would let me know. We can think about making this the 
> default approach when I make the new driver work for `non-rdc` mode 
> compilations.

There is only one fatbin for -fgpu-rdc mode but the fatbin unregister function 
is called multiple times in each TU. HIP runtime expects each fatbin is 
unregistered only once. The old embedding scheme introduced a weak symbol to 
track whether the fabin has been unregistered and to make sure it is only 
unregistered once.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128914/new/

https://reviews.llvm.org/D128914

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


[PATCH] D129149: [OMPIRBuilder] Add support for simdlen clause

2022-07-11 Thread Arnamoy B via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGac892c70a456: [OMPIRBuilder] Add support for simdlen clause 
(authored by psoni2628, committed by arnamoy10).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129149/new/

https://reviews.llvm.org/D129149

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/irbuilder_simd.cpp
  clang/test/OpenMP/irbuilder_simdlen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  llvm/utils/UpdateTestChecks/common.py
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -971,7 +971,7 @@
   llvm::CanonicalLoopInfo *loopInfo =
   ompBuilder->collapseLoops(ompLoc.DL, loopInfos, {});
 
-  ompBuilder->applySimd(ompLoc.DL, loopInfo);
+  ompBuilder->applySimd(loopInfo, nullptr);
 
   builder.restoreIP(afterIP);
   return success();
Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -719,18 +719,19 @@
 # Description of the different "unnamed" values we match in the IR, e.g.,
 # (local) ssa values, (debug) metadata, etc.
 ir_nameless_values = [
-NamelessValue(r'TMP'  , '%' , r'%'   , None, None   , r'[\w$.-]+?' , None , False) ,
-NamelessValue(r'ATTR' , '#' , r'#'   , None, None   , r'[0-9]+', None , False) ,
-NamelessValue(r'ATTR' , '#' , None   , r'attributes #' , r'[0-9]+'  , None , r'{[^}]*}'   , False) ,
-NamelessValue(r'GLOB' , '@' , r'@'   , None, None   , r'[0-9]+', None , False) ,
-NamelessValue(r'GLOB' , '@' , None   , r'@', r'[a-zA-Z0-9_$"\\.-]+' , None , r'.+', True)  ,
-NamelessValue(r'DBG'  , '!' , r'!dbg '   , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'PROF' , '!' , r'!prof '  , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'TBAA' , '!' , r'!tbaa '  , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'RNG'  , '!' , r'!range ' , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'LOOP' , '!' , r'!llvm.loop ' , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'META' , '!' , r'metadata '   , None, None   , r'![0-9]+'   , None , False) ,
-NamelessValue(r'META' , '!' , None   , r'' , r'![0-9]+' , None , r'(?:distinct |)!.*' , False) ,
+NamelessValue(r'TMP' , '%' , r'%'   , None, None   , r'[\w$.-]+?' , None , False) ,
+NamelessValue(r'ATTR', '#' , r'#'   , None, None   , r'[0-9]+', None , False) ,
+NamelessValue(r'ATTR', '#' , None   , r'attributes #' , r'[0-9]+'  , None , r'{[^}]*}'   , False) ,
+NamelessValue(r'GLOB', '@' , r'@'   , None, None   , r'[0-9]+', None , False) ,
+NamelessValue(r'GLOB', '@' , None   , r'@', r'[a-zA-Z0-9_$"\\.-]+' , None , r'.+', True)  ,
+NamelessValue(r'DBG' , '!' , r'!dbg '   , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'PROF', '!' , r'!prof '  , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'TBAA', '!' , r'!tbaa '  , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'RNG' , '!' , r'!range ' , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'LOOP', '!' , r'!llvm.loop ' , None, None   , r'![0-9]+'   , None , False) ,
+NamelessValue(r'META', '!' , r'metadata '   , Non

[PATCH] D129413: [InstrProf] Allow compiler generated functions in SCL

2022-07-11 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added a project: All.
ellis retitled this revision from "[instrprof] Allow compiler generated 
functions in SCL" to "[InstrProf] Allow compiler generated functions in SCL".
ellis edited the summary of this revision.
ellis added reviewers: kyulee, phosek.
ellis published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Allow compiler generated functions like `__clang_call_terminate` to be
blocked in the special case list (SCL) passed by the `-fprofile-list=` option.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129413

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/profile-filter-compiler-generated.cpp


Index: clang/test/CodeGen/profile-filter-compiler-generated.cpp
===
--- /dev/null
+++ clang/test/CodeGen/profile-filter-compiler-generated.cpp
@@ -0,0 +1,9 @@
+// RUN: echo "!fun:__clang_call_terminate" > %t.list
+// RUN: %clang -fprofile-generate -fprofile-list=%t.list -Wno-exceptions 
-emit-llvm -S %s -o - | FileCheck %s
+
+// CHECK-NOT: noprofile
+// CHECK-LABEL: define {{.*}} i32 @_Z3foov()
+int foo() noexcept { throw 0; }
+
+// CHECK: noprofile
+// CHECK-LABEL: define {{.*}} void @__clang_call_terminate(
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3891,6 +3891,10 @@
 F->addFnAttrs(B);
   }
 
+  if (getCodeGenOpts().getProfileInstr() != CodeGenOptions::ProfileNone)
+if (isProfileInstrExcluded(F, SourceLocation()))
+  F->addFnAttr(llvm::Attribute::NoProfile);
+
   if (!DontDefer) {
 // All MSVC dtors other than the base dtor are linkonce_odr and delegate to
 // each other bottoming out with the base dtor.  Therefore we emit non-base


Index: clang/test/CodeGen/profile-filter-compiler-generated.cpp
===
--- /dev/null
+++ clang/test/CodeGen/profile-filter-compiler-generated.cpp
@@ -0,0 +1,9 @@
+// RUN: echo "!fun:__clang_call_terminate" > %t.list
+// RUN: %clang -fprofile-generate -fprofile-list=%t.list -Wno-exceptions -emit-llvm -S %s -o - | FileCheck %s
+
+// CHECK-NOT: noprofile
+// CHECK-LABEL: define {{.*}} i32 @_Z3foov()
+int foo() noexcept { throw 0; }
+
+// CHECK: noprofile
+// CHECK-LABEL: define {{.*}} void @__clang_call_terminate(
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3891,6 +3891,10 @@
 F->addFnAttrs(B);
   }
 
+  if (getCodeGenOpts().getProfileInstr() != CodeGenOptions::ProfileNone)
+if (isProfileInstrExcluded(F, SourceLocation()))
+  F->addFnAttr(llvm::Attribute::NoProfile);
+
   if (!DontDefer) {
 // All MSVC dtors other than the base dtor are linkonce_odr and delegate to
 // each other bottoming out with the base dtor.  Therefore we emit non-base
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129456: [lldb] Add image dump pcm-info command

2022-07-11 Thread Med Ismail Bennani via Phabricator via cfe-commits
mib accepted this revision.
mib added a comment.
This revision is now accepted and ready to land.

LGTM with a comment




Comment at: lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py:37
+
+breakpoint()
+self.expect(

Left over ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129456/new/

https://reviews.llvm.org/D129456

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


[PATCH] D128465: [llvm] cmake config groundwork to have ZSTD in LLVM

2022-07-11 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 443687.
ckissane added a comment.

clean a space and make accurate


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/test/lit.cfg.py
  clang-tools-extra/clangd/test/lit.site.cfg.py.in
  clang/test/CMakeLists.txt
  clang/test/lit.site.cfg.py.in
  compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh
  compiler-rt/test/lit.common.cfg.py
  compiler-rt/test/lit.common.configured.in
  flang/CMakeLists.txt
  lld/ELF/CMakeLists.txt
  lld/test/lit.site.cfg.py.in
  lldb/source/Plugins/Process/gdb-remote/CMakeLists.txt
  lldb/test/Shell/lit.site.cfg.py.in
  llvm/CMakeLists.txt
  llvm/cmake/config-ix.cmake
  llvm/cmake/modules/FindZSTD.cmake
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/include/llvm/Config/llvm-config.h.cmake
  llvm/lib/Support/CMakeLists.txt
  llvm/test/lit.site.cfg.py.in
  utils/bazel/llvm_configs/llvm-config.h.cmake

Index: utils/bazel/llvm_configs/llvm-config.h.cmake
===
--- utils/bazel/llvm_configs/llvm-config.h.cmake
+++ utils/bazel/llvm_configs/llvm-config.h.cmake
@@ -95,6 +95,9 @@
 /* Define if zlib compression is available */
 #cmakedefine01 LLVM_ENABLE_ZLIB
 
+/* Define if zstd compression is available */
+#cmakedefine01 LLVM_ENABLE_ZSTD
+
 /* Define if LLVM was built with a dependency to the libtensorflow dynamic library */
 #cmakedefine LLVM_HAVE_TF_API
 
Index: llvm/test/lit.site.cfg.py.in
===
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -37,6 +37,7 @@
 config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.have_zstd = @LLVM_ENABLE_ZSTD@
 config.have_libxar = @LLVM_HAVE_LIBXAR@
 config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
 config.have_curl = @LLVM_ENABLE_CURL@
Index: llvm/lib/Support/CMakeLists.txt
===
--- llvm/lib/Support/CMakeLists.txt
+++ llvm/lib/Support/CMakeLists.txt
@@ -25,6 +25,10 @@
   set(imported_libs ZLIB::ZLIB)
 endif()
 
+if(LLVM_ENABLE_ZSTD)
+  list(APPEND imported_libs zstd)
+endif()
+
 if( MSVC OR MINGW )
   # libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc.
   # advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc.
Index: llvm/include/llvm/Config/llvm-config.h.cmake
===
--- llvm/include/llvm/Config/llvm-config.h.cmake
+++ llvm/include/llvm/Config/llvm-config.h.cmake
@@ -95,6 +95,9 @@
 /* Define if zlib compression is available */
 #cmakedefine01 LLVM_ENABLE_ZLIB
 
+/* Define if zstd compression is available */
+#cmakedefine01 LLVM_ENABLE_ZSTD
+
 /* Define if LLVM was built with a dependency to the libtensorflow dynamic library */
 #cmakedefine LLVM_HAVE_TF_API
 
Index: llvm/cmake/modules/LLVMConfig.cmake.in
===
--- llvm/cmake/modules/LLVMConfig.cmake.in
+++ llvm/cmake/modules/LLVMConfig.cmake.in
@@ -73,6 +73,12 @@
   find_package(ZLIB)
 endif()
 
+set(LLVM_ENABLE_ZSTD @LLVM_ENABLE_ZSTD@)
+if(LLVM_ENABLE_ZSTD)
+  set(ZSTD_ROOT @ZSTD_ROOT@)
+  find_package(ZSTD)
+endif()
+
 set(LLVM_ENABLE_LIBXML2 @LLVM_ENABLE_LIBXML2@)
 if(LLVM_ENABLE_LIBXML2)
   find_package(LibXml2)
Index: llvm/cmake/modules/FindZSTD.cmake
===
--- /dev/null
+++ llvm/cmake/modules/FindZSTD.cmake
@@ -0,0 +1,21 @@
+find_path(ZSTD_INCLUDE_DIR
+  NAMES zstd.h
+  HINTS ${ZSTD_ROOT_DIR}/include)
+
+find_library(ZSTD_LIBRARY
+  NAMES zstd
+  HINTS ${ZSTD_ROOT_DIR}/lib)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+ZSTD DEFAULT_MSG
+ZSTD_LIBRARY ZSTD_INCLUDE_DIR)
+
+if(ZSTD_FOUND)
+set(ZSTD_LIBRARIES ${ZSTD_LIBRARY})
+set(ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR})
+endif()
+
+mark_as_advanced(
+  ZSTD_INCLUDE_DIR
+  ZSTD_LIBRARY)
Index: llvm/cmake/config-ix.cmake
===
--- llvm/cmake/config-ix.cmake
+++ llvm/cmake/config-ix.cmake
@@ -136,6 +136,27 @@
   set(LLVM_ENABLE_ZLIB "${HAVE_ZLIB}")
 endif()
 
+if(LLVM_ENABLE_ZSTD)
+  if(LLVM_ENABLE_ZSTD STREQUAL FORCE_ON)
+find_package(ZSTD REQUIRED)
+  elseif(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
+find_package(ZSTD)
+  endif()
+  if(ZSTD_FOUND)
+# Check if zstd we found is usable; for example, we may have found a 32-bit
+# library on a 64-bit system which would result in a link-time failure.
+cmake_push_check_state()
+list(APPEND CMAKE_REQUIRED_INCLUDES ${ZSTD_INCLUDE_DIR})
+list(APPEND CMAKE_REQUIRED_LIBRARIES ${ZSTD_LIBRARY})
+check_symbol_exists(ZSTD

[PATCH] D129456: [lldb] Add image dump pcm-info command

2022-07-11 Thread Dave Lee via Phabricator via cfe-commits
kastiglione added a reviewer: Michael137.
kastiglione added inline comments.



Comment at: lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py:37
+
+breakpoint()
+self.expect(

mib wrote:
> Left over ?
yep thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129456/new/

https://reviews.llvm.org/D129456

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


[PATCH] D128465: [llvm] cmake config groundwork to have ZSTD in LLVM

2022-07-11 Thread Cole Kissane via Phabricator via cfe-commits
ckissane added inline comments.



Comment at: lld/test/lit.site.cfg.py.in:21
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.have_zstd = @LLVM_ENABLE_ZSTD@
 config.have_libxar = @LLVM_HAVE_LIBXAR@

MaskRay wrote:
> MaskRay wrote:
> > This needs a change in lld/test/CMakeLists.txt
> > 
> > Looks like you haven't run `ninja check-lld` as I mentioned.
> Actually I am preparing a lld patch and you probably should drop have_zstd 
> from lld/ for this patch.
I get this when I try to run that:
`ninja: error: unknown target 'check-lld', did you mean 'check-lit'?`



Comment at: lld/test/lit.site.cfg.py.in:21
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.have_zstd = @LLVM_ENABLE_ZSTD@
 config.have_libxar = @LLVM_HAVE_LIBXAR@

ckissane wrote:
> MaskRay wrote:
> > MaskRay wrote:
> > > This needs a change in lld/test/CMakeLists.txt
> > > 
> > > Looks like you haven't run `ninja check-lld` as I mentioned.
> > Actually I am preparing a lld patch and you probably should drop have_zstd 
> > from lld/ for this patch.
> I get this when I try to run that:
> `ninja: error: unknown target 'check-lld', did you mean 'check-lit'?`
Got it


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

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


[PATCH] D88299: [clang-format] Add MacroUnexpander.

2022-07-11 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.
Herald added a project: All.

OK, I think we've reached the point where:

- the impact is very clear, this solves a whole class of clang-format's biggest 
problems
- the idea clearly works (there are good tests)
- the implementation is very well-documented: I can't really improve my 
understanding further by asking for things to be better explained
- I can't make clear suggestions to simplify - you've applied all my low-level 
suggestions and my high-level understanding is poor
- I still don't feel like I really understand how it works, but that's not 
really different than the other big pieces of clang-format

So I think all that's left to do here is ship it. It makes me uneasy that the 
core of clang-format is functionally magic (could anyone other than you and 
Daniel reproduce it after nuclear apocalypse?) but this doesn't really change 
that state.




Comment at: clang/lib/Format/MacroCallReconstructor.cpp:53
+  assert(State != Finalized);
+  LLVM_DEBUG(llvm::dbgs() << "Unex: new line...\n");
+  forEachToken(Line, [&](FormatToken *Token, FormatToken *Parent, bool First) {

if you want to keep these LLVM_DEBUGs, maybe this should be "MCR" or so instead 
of "unex"?



Comment at: clang/lib/Format/MacroCallReconstructor.cpp:62
+  finalize();
+  UnwrappedLine Final =
+  createUnwrappedLine(*Result.Tokens.front()->Children.front(), Level);

you might want an assertion that Result has one token with one child (it's 
pretty obvious in finalize() but less so here)



Comment at: clang/lib/Format/MacroCallReconstructor.cpp:98
+   ActiveExpansions.size() != Token->MacroCtx->ExpandedFrom.size())) {
+if (reconstructActiveCallUntil(Token))
+  First = true;

nit: I think this would be clearer by naming the result:
`if (bool PassedMacroComma = reconstruct...)`

(because it's not clear from the name what the function returns, and 
documenting it would help only a little)



Comment at: clang/lib/Format/MacroCallReconstructor.cpp:108
+appendToken(Token);
+  } else {
+// Otherwise add the reconstructed equivalent of the token.

(this is the else branch of a negated condition, consider swapping the branches 
to avoid double-negative)



Comment at: clang/lib/Format/MacroCallReconstructor.cpp:114
+
+// Adjusts the stack of active reconstructed liens so we're ready to push
+// tokens. The tokens to be pushed are children of ExpandedParent in the

liens -> lines

(unless there's a *really* weird metaphor going on here!)



Comment at: clang/lib/Format/MacroCallReconstructor.cpp:232
+} else if (!currentLine()->Tokens.empty()) {
+  // FIXME:assert(!currentLine()->Tokens.empty());
+  // Map all hidden tokens to the last visible token in the output.

this FIXME looks obsolete?



Comment at: clang/lib/Format/Macros.h:190
+  /// that needs to be processed to finish an macro call.
+  /// Only when \c finished() is true, \c getResult() can be called to retrieve
+  /// the resulting \c UnwrappedLine.

nit: getResult()->takeResult() in comment now



Comment at: clang/lib/Format/Macros.h:201
+  /// Generally, this line tries to have the same structure as the expanded,
+  /// formatted unwrapped lines handed in via \c addLine(), with the exception
+  /// that for multiple top-level lines, each subsequent line will be the

you could give this a name like "tail form", and then refer to it in docs of 
MacroCallReconstructor::Result, in MacroCallReconstructor.cpp:482, etc.

Up to you.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88299/new/

https://reviews.llvm.org/D88299

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


[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-07-11 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

In D126189#3642820 , @iains wrote:

> JFTR, I did not get any notification from green dragon (which is odd, AFAIR 
> it's sent email before) or I would have looked right away  - kicked off a 
> build will take a look as soon as that's done.

Yes, the bot was already red because of a different issue.

FWIW I tried reverting ac507102d258b6fc0cb57eb60c9dfabd57ff562f 
 and 
4328b960176f4394416093e640ad4265bde65ad7 
 locally 
and I'm still getting a linker error about missing symbols:

  Undefined symbols for architecture arm64:
"vtable for std::__1::format_error", referenced from:
std::__1::format_error::format_error(char const*) in main.o
std::__1::format_error::format_error(std::__1::basic_string, std::__1::allocator > const&) in main.o


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126189/new/

https://reviews.llvm.org/D126189

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


[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-07-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D109701#3642786 , @vaibhav.y wrote:

> In D109701#3642748 , @aaron.ballman 
> wrote:
>
>> Unfortunately, it still seems to be causing failures (I had to revert again):
>>
>> https://lab.llvm.org/buildbot/#/builders/91/builds/11840
>>
>> It looks to be the same failure as before 
>> (https://lab.llvm.org/buildbot/#/builders/91/builds/11328). :-(
>
> Thanks, this seems to be reproducible. Perhaps there's something special 
> about my environment making it work. I'll try to pare down more (possibly try 
> to build inside a container).

Hopefully!

> The buildbot properties say its Linux aurora is there an official container / 
> build spec I can use to mimic the environment?

I don't know that there is such a thing, unfortunately. (Many of the bots are 
bots hosted by various different companies with different views on access to 
servers, I'd imagine.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109701/new/

https://reviews.llvm.org/D109701

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


[PATCH] D128465: [llvm] cmake config groundwork to have ZSTD in LLVM

2022-07-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

As I mentioned, the proper approach is to add zstd functionality along with the 
CMake change, instead of adding CMake to all llvm-project components without a 
way to test them.




Comment at: lld/test/lit.site.cfg.py.in:21
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.have_zstd = @LLVM_ENABLE_ZSTD@
 config.have_libxar = @LLVM_HAVE_LIBXAR@

ckissane wrote:
> ckissane wrote:
> > MaskRay wrote:
> > > MaskRay wrote:
> > > > This needs a change in lld/test/CMakeLists.txt
> > > > 
> > > > Looks like you haven't run `ninja check-lld` as I mentioned.
> > > Actually I am preparing a lld patch and you probably should drop 
> > > have_zstd from lld/ for this patch.
> > I get this when I try to run that:
> > `ninja: error: unknown target 'check-lld', did you mean 'check-lit'?`
> Got it
During cmake, ensure that LLVM_ENABLE_PROJECTS contains `lld`

I posted the patch link to another patch of yours: 
https://reviews.llvm.org/D129406




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

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


[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-07-11 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D126189#3642992 , @JDevlieghere 
wrote:

> In D126189#3642820 , @iains wrote:
>
>> JFTR, I did not get any notification from green dragon (which is odd, AFAIR 
>> it's sent email before) or I would have looked right away  - kicked off a 
>> build will take a look as soon as that's done.
>
> Yes, the bot was already red because of a different issue.
>
> FWIW I tried reverting ac507102d258b6fc0cb57eb60c9dfabd57ff562f 
>  and 
> 4328b960176f4394416093e640ad4265bde65ad7 
>  locally 
> and I'm still getting a linker error about missing symbols:

those refs come up as 'bad object' for me .. can you identify the upstream 
changes?

>   Undefined symbols for architecture arm64:
> "vtable for std::__1::format_error", referenced from:
> std::__1::format_error::format_error(char const*) in main.o
> std::__1::format_error::format_error(std::__1::basic_string std::__1::char_traits, std::__1::allocator > const&) in main.o

That seems also unrelated to the modules code, but I could always be surprised 
:)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126189/new/

https://reviews.llvm.org/D126189

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


[PATCH] D129448: [CodeGen][Asan] Emit lifetime intrinsic for bypassed label

2022-07-11 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/test/CodeGen/lifetime2.c:78
 break;
   case 2:
 bar(&x, 1);

vitalybuka wrote:
> Please check for lifetime markers, I assume case 2 will have a new one
> Please check for lifetime markers, I assume case 2 will have a new one
Please check for *all* lifetime markers

you can add use "FileCheck --implicit-check-not llvm.lifetime" so it will fail 
if something has no corresponding match



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129448/new/

https://reviews.llvm.org/D129448

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


[PATCH] D129413: [InstrProf] Allow compiler generated functions in SCL

2022-07-11 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:3894-3896
+  if (getCodeGenOpts().getProfileInstr() != CodeGenOptions::ProfileNone)
+if (isProfileInstrExcluded(F, SourceLocation()))
+  F->addFnAttr(llvm::Attribute::NoProfile);

Do we still need 
https://github.com/llvm/llvm-project/blob/759e5e0096f650515799805828f9ac5b7d4a7303/clang/lib/CodeGen/CodeGenFunction.cpp#L856
 if we set the attribute here?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129413/new/

https://reviews.llvm.org/D129413

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


[PATCH] D129504: [libclang][ObjC] Inherit availability attribute from containing decls or interface decls

2022-07-11 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added reviewers: arphaman, benlangmuir.
ahatanak added a project: clang.
Herald added a project: All.
ahatanak requested review of this revision.

This patch teaches `getCursorPlatformAvailabilityForDecl` to look for 
availability attributes on the containing decls or interface decls if the 
current decl doesn't have any availability attributes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129504

Files:
  clang/test/Index/availability.mm
  clang/tools/libclang/CIndex.cpp

Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -8258,8 +8258,34 @@
   deprecated_message, always_unavailable, unavailable_message,
   AvailabilityAttrs);
 
-  if (AvailabilityAttrs.empty())
+  // If no availability attributes are found, inherit the attribute from the
+  // containing decl or, if the current decl is an implementation, the class or
+  // category interface.
+  if (AvailabilityAttrs.empty()) {
+const ObjCContainerDecl *CD = nullptr;
+const DeclContext *DC = D->getDeclContext();
+
+if (auto *IMD = dyn_cast(D))
+  CD = IMD->getClassInterface();
+else if (auto *IMD = dyn_cast(D))
+  CD = IMD->getCategoryDecl();
+else if (auto *ID = dyn_cast(DC))
+  CD = ID;
+else if (auto *CatD = dyn_cast(DC))
+  CD = CatD;
+else if (auto *IMD = dyn_cast(DC))
+  CD = IMD->getClassInterface();
+else if (auto *IMD = dyn_cast(DC))
+  CD = IMD->getCategoryDecl();
+else if (auto *PD = dyn_cast(DC))
+  CD = PD;
+
+if (CD)
+  getCursorPlatformAvailabilityForDecl(
+  CD, always_deprecated, deprecated_message, always_unavailable,
+  unavailable_message, AvailabilityAttrs);
 return;
+  }
 
   llvm::sort(
   AvailabilityAttrs, [](AvailabilityAttr *LHS, AvailabilityAttr *RHS) {
Index: clang/test/Index/availability.mm
===
--- /dev/null
+++ clang/test/Index/availability.mm
@@ -0,0 +1,70 @@
+__attribute__((availability(macosx, introduced = 8.0)))
+@interface C {
+  int i0;
+  int i1 __attribute__((availability(macosx, introduced = 9.0)));
+}
+@property int p0;
+@property int p1 __attribute__((availability(macosx, introduced=9.0)));
+- (void)m0;
+- (void)m1 __attribute__((availability(macosx, introduced = 9.0)));
+@end
+
+@implementation C
+- (void)m0 {
+}
+- (void)m1 {
+}
+@end
+
+__attribute__((availability(macosx, introduced = 10.0)))
+@interface C(Cat)
+@property int p2;
+@property int p3 __attribute__((availability(macosx, introduced=11.0)));
+- (void)m2;
+- (void)m3 __attribute__((availability(macosx, introduced = 11.0)));
+@end
+
+@implementation C(Cat)
+- (void)m2 {
+}
+- (void)m3 {
+}
+@end
+
+__attribute__((availability(macosx, introduced = 10.0)))
+@protocol P
+@property int p4;
+@property int p5 __attribute__((availability(macosx, introduced=11.0)));
+- (void)m4;
+- (void)m5 __attribute__((availability(macosx, introduced = 11.0)));
+@end
+
+// RUN: c-index-test -test-print-type --std=c++11 %s | FileCheck %s
+
+// CHECK: ObjCInterfaceDecl=C:2:12  (macos, introduced=8.0)
+// CHECK: ObjCIvarDecl=i0:3:7 (Definition)  (macos, introduced=8.0)
+// CHECK: ObjCIvarDecl=i1:4:7 (Definition)  (macos, introduced=9.0)
+// CHECK: ObjCPropertyDecl=p0:6:15  (macos, introduced=8.0)
+// CHECK: ObjCPropertyDecl=p1:7:15  (macos, introduced=9.0)
+// CHECK: ObjCInstanceMethodDecl=m0:8:9  (macos, introduced=8.0)
+// CHECK: ObjCInstanceMethodDecl=m1:9:9  (macos, introduced=9.0)
+
+// CHECK: ObjCImplementationDecl=C:12:17 (Definition)  (macos, introduced=8.0)
+// CHECK: ObjCInstanceMethodDecl=m0:13:9 (Definition)  (macos, introduced=8.0)
+// CHECK: ObjCInstanceMethodDecl=m1:15:9 (Definition)  (macos, introduced=9.0)
+
+// CHECK: ObjCCategoryDecl=Cat:20:12  (macos, introduced=10.0)
+// CHECK: ObjCPropertyDecl=p2:21:15  (macos, introduced=10.0)
+// CHECK: ObjCPropertyDecl=p3:22:15  (macos, introduced=11.0)
+// CHECK: ObjCInstanceMethodDecl=m2:23:9  (macos, introduced=10.0)
+// CHECK: ObjCInstanceMethodDecl=m3:24:9  (macos, introduced=11.0)
+
+// CHECK: ObjCCategoryImplDecl=Cat:27:17 (Definition)  (macos, introduced=10.0)
+// CHECK: ObjCInstanceMethodDecl=m2:28:9 (Definition)  (macos, introduced=10.0)
+// CHECK: ObjCInstanceMethodDecl=m3:30:9 (Definition)  (macos, introduced=11.0)
+
+// CHECK: ObjCProtocolDecl=P:35:11 (Definition)  (macos, introduced=10.0)
+// CHECK: ObjCPropertyDecl=p4:36:15  (macos, introduced=10.0)
+// CHECK: ObjCPropertyDecl=p5:37:15  (macos, introduced=11.0)
+// CHECK: ObjCInstanceMethodDecl=m4:38:9  (macos, introduced=10.0)
+// CHECK: ObjCInstanceMethodDecl=m5:39:9  (macos, introduced=11.0)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-07-11 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

In D126189#3643001 , @iains wrote:

> In D126189#3642992 , @JDevlieghere 
> wrote:
>
>> In D126189#3642820 , @iains wrote:
>>
>>> JFTR, I did not get any notification from green dragon (which is odd, AFAIR 
>>> it's sent email before) or I would have looked right away  - kicked off a 
>>> build will take a look as soon as that's done.
>>
>> Yes, the bot was already red because of a different issue.
>>
>> FWIW I tried reverting ac507102d258b6fc0cb57eb60c9dfabd57ff562f 
>>  and 
>> 4328b960176f4394416093e640ad4265bde65ad7 
>>  
>> locally and I'm still getting a linker error about missing symbols:
>
> those refs come up as 'bad object' for me .. can you identify the upstream 
> changes?

That's odd, both Github and Phab think those are the canonical hashes:

https://github.com/llvm/llvm-project/commit/ac507102d258b6fc0cb57eb60c9dfabd57ff562f
https://github.com/llvm/llvm-project/commit/4328b960176f4394416093e640ad4265bde65ad7

>>   Undefined symbols for architecture arm64:
>> "vtable for std::__1::format_error", referenced from:
>> std::__1::format_error::format_error(char const*) in main.o
>> std::__1::format_error::format_error(std::__1::basic_string> std::__1::char_traits, std::__1::allocator > const&) in main.o
>
> That seems also unrelated to the modules code, but I could always be 
> surprised :)




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126189/new/

https://reviews.llvm.org/D126189

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


[PATCH] D129413: [InstrProf] Allow compiler generated functions in SCL

2022-07-11 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:3894-3896
+  if (getCodeGenOpts().getProfileInstr() != CodeGenOptions::ProfileNone)
+if (isProfileInstrExcluded(F, SourceLocation()))
+  F->addFnAttr(llvm::Attribute::NoProfile);

phosek wrote:
> Do we still need 
> https://github.com/llvm/llvm-project/blob/759e5e0096f650515799805828f9ac5b7d4a7303/clang/lib/CodeGen/CodeGenFunction.cpp#L856
>  if we set the attribute here?
Both are needed. Here the attribute is added in `GetOrCreateLLVMFunction()` 
which I believe only creates compiler generated functions. Where you linked is 
called when normal functions are generated.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129413/new/

https://reviews.llvm.org/D129413

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


[PATCH] D129413: [InstrProf] Allow compiler generated functions in SCL

2022-07-11 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129413/new/

https://reviews.llvm.org/D129413

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


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-07-11 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:906
   // member, only a T[0] or T[] member gets that treatment.
+  // Under StrictFlexArraysLevel, obey c99+ that disallows FAM in union, 
see
+  // C11 6.7.2.1 §18

serge-sans-paille wrote:
> jyknight wrote:
> > I believe this bit is incorrect -- it should just go back to 'return 
> > true;'. The StrictFlexArraysLevel check above already eliminates the cases 
> > we want to eliminate (size==1 in strictness-level 2.)
> Well, if we are in strictness-level 2, with an undefined size or size = 0, we 
> can still reach that path, and don't want to return 'true' because FAM in 
> union are in invalid per the standard.
Yes, we can reach this path, which is why the change is incorrect. We should 
not be changing the FAMness of undefined size, or size == 0, in any of the 
modes. To be more specific -- 

`union X { int x[0]; };` should still be a FAM in all strictness modes. (if you 
don't want zero-length-arrays, use `-Werror=zero-length-array`).

For `union X { int x[]; };`: this ought to be a compiler error. It's likely 
just an oversight that we currently accept it;  I'd be OK with a (separate) 
patch to fix that. (GCC emits an error, so there's unlikely to be compatibility 
issues with such a change.)



Comment at: clang/lib/Sema/SemaChecking.cpp:15972
 
+// FIXME: this check should belong to the IsTailPaddedMemberArray call
+// below.

What I meant to say is that both the IsTailPaddedMemberArray call, and this 
code, should be moved up above, in order to set IsUnboundedArray to true, so we 
will get the checks from that block.

(But doesn't need to be in this patch, fine to just leave a comment to that 
effect).



Comment at: clang/lib/Sema/SemaChecking.cpp:15804
+
+  // FIXME: we should also allow Size = 0 here per the definition of
+  // StrictFlexArraysLevel, but that's backward incompatible with previous 
clang

jyknight wrote:
> serge-sans-paille wrote:
> > jyknight wrote:
> > > Presumably the size-zero/unsized cases are already being taken care of 
> > > elsewhere in the code? I find it hard to believe we are currently 
> > > emitting diagnostics for size-0 FAM which we don't emit for size-1 FAM?
> > correct
> The FIXME comment isn't correct, since only nonzero sizes ever reach this 
> function. The code can be simplified too. Also -- there is another FIXME that 
> should be here, regarding the behavior of size>1 FAMs.
> 
> I suggest (with rewrapped comment of course):
> ```
> if (!ND) return false;
> // FIXME: While the default -fstrict-flex-arrays=0 permits Size>1 trailing 
> arrays to be treated as flexible-array-members, we still emit diagnostics as 
> if they are not. Pending further discussion...
> if (StrictFlexArraysLevel >= 2 || Size != 1) return false;`
> ```
> 
You didn't like the code change I suggested there?



Comment at: clang/lib/Sema/SemaChecking.cpp:15969
 // access which precedes the array bounds.
 if (BaseType->isIncompleteType())
   return;

jyknight wrote:
> serge-sans-paille wrote:
> > And here
> Looks like actually the `int x[]` case is handled with the large 
> "IsUnboundedArray" condition above not here...
> 
> And, actually, all of that code to generate warnings for 
> larger-than-addrspace offsets OUGHT to be getting used for `int x[0]` and 
> `int x[1]` flexible arrays, too. Needs another FIXME for that...
Is it redundant? This check is for an _incomplete_ type as the array element 
type, which doesn't seem directly related to unbounded array sizes. (though it 
also prevents knowing the size of the array)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126864/new/

https://reviews.llvm.org/D126864

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


[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-07-11 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D126189#3643021 , @JDevlieghere 
wrote:

> In D126189#3643001 , @iains wrote:
>
>> In D126189#3642992 , @JDevlieghere 
>> wrote:
>>
>>> In D126189#3642820 , @iains wrote:
>>>
 JFTR, I did not get any notification from green dragon (which is odd, 
 AFAIR it's sent email before) or I would have looked right away  - kicked 
 off a build will take a look as soon as that's done.
>>>
>>> Yes, the bot was already red because of a different issue.
>>>
>>> FWIW I tried reverting ac507102d258b6fc0cb57eb60c9dfabd57ff562f 
>>>  and 
>>> 4328b960176f4394416093e640ad4265bde65ad7 
>>>  
>>> locally and I'm still getting a linker error about missing symbols:
>>
>> those refs come up as 'bad object' for me .. can you identify the upstream 
>> changes?
>
> That's odd, both Github and Phab think those are the canonical hashes:
>
> https://github.com/llvm/llvm-project/commit/ac507102d258b6fc0cb57eb60c9dfabd57ff562f
> https://github.com/llvm/llvm-project/commit/4328b960176f4394416093e640ad4265bde65ad7

pilot error (pasto...)

>>>   Undefined symbols for architecture arm64:
>>> "vtable for std::__1::format_error", referenced from:
>>> std::__1::format_error::format_error(char const*) in main.o
>>> std::__1::format_error::format_error(std::__1::basic_string>> std::__1::char_traits, std::__1::allocator > const&) in main.o
>>
>> That seems also unrelated to the modules code, but I could always be 
>> surprised :)

OK - so if I cannot figure out what is happening in the next couple or hours, I 
can revert those two commits (that's 9PM for me so I probably cannot do much 
more today).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126189/new/

https://reviews.llvm.org/D126189

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


[PATCH] D118350: [Clang][Sema][AIX][PowerPC] Emit byval alignment warning only when struct is passed to a function

2022-07-11 Thread Sean Fertile via Phabricator via cfe-commits
sfertile accepted this revision.
sfertile added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: steakhal.

LGTM Zarko, sorry about taking so long to review this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118350/new/

https://reviews.llvm.org/D118350

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


[PATCH] D129377: [lldb/Fuzzer] Add fuzzer for expression evaluator

2022-07-11 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

The review shows the diff with the previous iteration of the patch. Can you 
generate a diff with the current top-of-tree?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129377/new/

https://reviews.llvm.org/D129377

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


[PATCH] D104647: [analyzer] Support SVal::getType for pointer-to-member values

2022-07-11 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.
Herald added a project: All.

@vsavchenko Is this alive?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104647/new/

https://reviews.llvm.org/D104647

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


[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-11 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 443699.
cor3ntin added a comment.

Fix crash on PowerPC

(I forgot to removed a non-sense line that
could cause the CurPtr to move incorrectly 
past a / in the ALTIVEC code path).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128059/new/

https://reviews.llvm.org/D128059

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/lib/Lex/Lexer.cpp
  clang/test/Lexer/comment-invalid-utf8.c
  clang/test/Lexer/comment-utf8.c
  clang/test/SemaCXX/static-assert.cpp
  llvm/include/llvm/Support/ConvertUTF.h
  llvm/lib/Support/ConvertUTF.cpp

Index: llvm/lib/Support/ConvertUTF.cpp
===
--- llvm/lib/Support/ConvertUTF.cpp
+++ llvm/lib/Support/ConvertUTF.cpp
@@ -417,6 +417,16 @@
 return isLegalUTF8(source, length);
 }
 
+/*
+ * Exported function to return the size of the first utf-8 code unit sequence,
+ * Or 0 if the sequence is not valid;
+ */
+unsigned getUTF8SequenceSize(const UTF8 *source, const UTF8 *sourceEnd) {
+  int length = trailingBytesForUTF8[*source] + 1;
+  return (length <= sourceEnd - source && isLegalUTF8(source, length)) ? length
+   : 0;
+}
+
 /* - */
 
 static unsigned
Index: llvm/include/llvm/Support/ConvertUTF.h
===
--- llvm/include/llvm/Support/ConvertUTF.h
+++ llvm/include/llvm/Support/ConvertUTF.h
@@ -181,6 +181,8 @@
 
 Boolean isLegalUTF8String(const UTF8 **source, const UTF8 *sourceEnd);
 
+unsigned getUTF8SequenceSize(const UTF8 *source, const UTF8 *sourceEnd);
+
 unsigned getNumBytesForUTF8(UTF8 firstByte);
 
 /*/
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -pedantic -triple=x86_64-linux-gnu
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -pedantic -triple=x86_64-linux-gnu -Wno-invalid-utf8
 
 int f(); // expected-note {{declared here}}
 
Index: clang/test/Lexer/comment-utf8.c
===
--- /dev/null
+++ clang/test/Lexer/comment-utf8.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only %s -Winvalid-utf8 -verify
+// expected-no-diagnostics
+
+
+//§ § § 😀 你好 ©
+
+/*§ § § 😀 你好 ©*/
+
+/*
+§ § § 😀 你好 ©©©
+*/
+
+/* § § § 😀 你好 © */
+/*
+a longer comment to exerce the vectorized code path
+
+αααααααααααααααααααααα  // here is some unicode
+
+
+*/
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -2392,13 +2392,37 @@
   //
   // This loop terminates with CurPtr pointing at the newline (or end of buffer)
   // character that ends the line comment.
+
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (C != 0 &&// Potentially EOF.
-   C != '\n' && C != '\r')  // Newline or DOS-style newline.
+while (isASCII(C) && C != 0 &&   // Potentially EOF.
+   C != '\n' && C != '\r') { // Newline or DOS-style newline.
   C = *++CurPtr;
+  UnicodeDecodingAlreadyDiagnosed = false;
+}
+
+if (!isASCII(C)) {
+  unsigned Length = llvm::getUTF8SequenceSize(
+  (const llvm::UTF8 *)CurPtr, (const llvm::UTF8 *)BufferEnd);
+  if (Length == 0) {
+if (!UnicodeDecodingAlreadyDiagnosed && !isLexingRawMode())
+  Diag(CurPtr, diag::warn_invalid_utf8_in_comment);
+UnicodeDecodingAlreadyDiagnosed = true;
+++CurPtr;
+  } else {
+UnicodeDecodingAlreadyDiagnosed = false;
+CurPtr += Length;
+  }
+  continue;
+}
 
 const char *NextLine = CurPtr;
 if (C != 0) {
@@ -2665,6 +2689,12 @@
   if (C == '/')
 C = *CurPtr++;
 
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/r

[PATCH] D128672: Update DynInit generation for ASan globals.

2022-07-11 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/CodeGen/SanitizerMetadata.cpp:67-68
 
-  if (FsanitizeArgument.has(SanitizerKind::Address)) {
-// TODO(hctim): Make this conditional when we migrate off 
llvm.asan.globals.
-IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
- SanitizerKind::KernelAddress,
- GV, Loc, Ty, "init");
-Meta.IsDynInit = IsDynInit;
-  }
+  Meta.IsDynInit = FsanitizeArgument.has(SanitizerKind::Address) && IsDynInit 
&&
+   !Meta.NoAddress &&
+   !CGM.isInNoSanitizeList(SanitizerKind::Address |

maybe a little bit nicer


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128672/new/

https://reviews.llvm.org/D128672

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


[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-07-11 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

In D126189#3643045 , @iains wrote:

> In D126189#3643021 , @JDevlieghere 
> wrote:
>
>> In D126189#3643001 , @iains wrote:
>>
>>> In D126189#3642992 , 
>>> @JDevlieghere wrote:
>>>
 In D126189#3642820 , @iains 
 wrote:

> JFTR, I did not get any notification from green dragon (which is odd, 
> AFAIR it's sent email before) or I would have looked right away  - kicked 
> off a build will take a look as soon as that's done.

 Yes, the bot was already red because of a different issue.

 FWIW I tried reverting ac507102d258b6fc0cb57eb60c9dfabd57ff562f 
  and 
 4328b960176f4394416093e640ad4265bde65ad7 
  
 locally and I'm still getting a linker error about missing symbols:
>>>
>>> those refs come up as 'bad object' for me .. can you identify the upstream 
>>> changes?
>>
>> That's odd, both Github and Phab think those are the canonical hashes:
>>
>> https://github.com/llvm/llvm-project/commit/ac507102d258b6fc0cb57eb60c9dfabd57ff562f
>> https://github.com/llvm/llvm-project/commit/4328b960176f4394416093e640ad4265bde65ad7
>
> pilot error (pasto...)
>
   Undefined symbols for architecture arm64:
 "vtable for std::__1::format_error", referenced from:
 std::__1::format_error::format_error(char const*) in main.o
 std::__1::format_error::format_error(std::__1::basic_string>>> std::__1::char_traits, std::__1::allocator > const&) in main.o
>>>
>>> That seems also unrelated to the modules code, but I could always be 
>>> surprised :)
>
> OK - so if I cannot figure out what is happening in the next couple or hours, 
> I can revert those two commits (that's 9PM for me so I probably cannot do 
> much more today).

Thanks, if the bot reproduces the other issue I mentioned I'll bisect it down 
to see if there's another commit that's causing issues. I should've mentioned 
that that failures only happens when building with `-gmodules`, so it does 
sound somewhat related.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126189/new/

https://reviews.llvm.org/D126189

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


[PATCH] D129398: [ASTMatchers] Add a new matcher for callee declarations of Obj-C message expressions

2022-07-11 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:3853
+/// objcMessageExpr(objcMessageCallee(objcMethodDecl(hasName("foo"
+AST_MATCHER_P(ObjCMessageExpr, objcMessageCallee,
+  internal::Matcher, InnerMatcher) {

aaron.ballman wrote:
> Is there a reason why we want a separate matcher here instead of overloading 
> `callee()`?
This is a good question!  

`callee` has already been overloaded to accept both `Matcher` and 
`Matcher` as the parameter.   In my case, I will need `callee` to be 
polymorphic in returning both `Matcher` and 
`Matcher` types.   So that will end up in 4 definitions of 
`callee`, one of which has different return type and parameter type from one of 
the others.   

Is this achievable?  I know I can overload parameters or make return types 
polymorphic, but can I mix them together? 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129398/new/

https://reviews.llvm.org/D129398

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


[PATCH] D128672: Update DynInit generation for ASan globals.

2022-07-11 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 443702.
hctim marked an inline comment as done.
hctim added a comment.

Integrate Vitaly's suggestion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128672/new/

https://reviews.llvm.org/D128672

Files:
  clang/lib/CodeGen/SanitizerMetadata.cpp


Index: clang/lib/CodeGen/SanitizerMetadata.cpp
===
--- clang/lib/CodeGen/SanitizerMetadata.cpp
+++ clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -64,13 +64,11 @@
   Meta.NoMemtag |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
 
-  if (FsanitizeArgument.has(SanitizerKind::Address)) {
-// TODO(hctim): Make this conditional when we migrate off 
llvm.asan.globals.
-IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
- SanitizerKind::KernelAddress,
- GV, Loc, Ty, "init");
-Meta.IsDynInit = IsDynInit;
-  }
+  Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
+   FsanitizeArgument.has(SanitizerKind::Address) &&
+   !CGM.isInNoSanitizeList(SanitizerKind::Address |
+   SanitizerKind::KernelAddress,
+   GV, Loc, Ty, "init");
 
   GV->setSanitizerMetadata(Meta);
 }


Index: clang/lib/CodeGen/SanitizerMetadata.cpp
===
--- clang/lib/CodeGen/SanitizerMetadata.cpp
+++ clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -64,13 +64,11 @@
   Meta.NoMemtag |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
 
-  if (FsanitizeArgument.has(SanitizerKind::Address)) {
-// TODO(hctim): Make this conditional when we migrate off llvm.asan.globals.
-IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
- SanitizerKind::KernelAddress,
- GV, Loc, Ty, "init");
-Meta.IsDynInit = IsDynInit;
-  }
+  Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
+   FsanitizeArgument.has(SanitizerKind::Address) &&
+   !CGM.isInNoSanitizeList(SanitizerKind::Address |
+   SanitizerKind::KernelAddress,
+   GV, Loc, Ty, "init");
 
   GV->setSanitizerMetadata(Meta);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-07-11 Thread Kees Cook via Phabricator via cfe-commits
kees added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:906
   // member, only a T[0] or T[] member gets that treatment.
+  // Under StrictFlexArraysLevel, obey c99+ that disallows FAM in union, 
see
+  // C11 6.7.2.1 §18

jyknight wrote:
> serge-sans-paille wrote:
> > jyknight wrote:
> > > I believe this bit is incorrect -- it should just go back to 'return 
> > > true;'. The StrictFlexArraysLevel check above already eliminates the 
> > > cases we want to eliminate (size==1 in strictness-level 2.)
> > Well, if we are in strictness-level 2, with an undefined size or size = 0, 
> > we can still reach that path, and don't want to return 'true' because FAM 
> > in union are in invalid per the standard.
> Yes, we can reach this path, which is why the change is incorrect. We should 
> not be changing the FAMness of undefined size, or size == 0, in any of the 
> modes. To be more specific -- 
> 
> `union X { int x[0]; };` should still be a FAM in all strictness modes. (if 
> you don't want zero-length-arrays, use `-Werror=zero-length-array`).
> 
> For `union X { int x[]; };`: this ought to be a compiler error. It's likely 
> just an oversight that we currently accept it;  I'd be OK with a (separate) 
> patch to fix that. (GCC emits an error, so there's unlikely to be 
> compatibility issues with such a change.)
> `union X { int x[0]; };` should still be a FAM in all strictness modes. (if 
> you don't want zero-length-arrays, use `-Werror=zero-length-array`).

The Linux kernel cannot use `-Wzero-length-array` because we have cases of 
userspace APIs being stuck with them. (i.e. they are part of the struct 
declaration, even though the kernel code doesn't use them.) For example:

```
In file included from ../kernel/bounds.c:13:
In file included from ../include/linux/log2.h:12:
In file included from ../include/linux/bitops.h:9:
In file included from ../include/uapi/linux/kernel.h:5:
../include/uapi/linux/sysinfo.h:22:10: error: zero size arrays are an extension 
[-Werror,-Wzero-length-array]
char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)];   /* Padding: 
libc5 uses this.. */
^~~
```



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126864/new/

https://reviews.llvm.org/D126864

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


[clang] e7c8ded - Revert "[C++20][Modules] Fix two tests for CTORs that return pointers [NFC]."

2022-07-11 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-07-11T19:49:48+01:00
New Revision: e7c8ded6df6d38b019a1de268535d2dd73e7adaf

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

LOG: Revert "[C++20][Modules] Fix two tests for CTORs that return pointers 
[NFC]."

This reverts commit 4328b960176f4394416093e640ad4265bde65ad7.

reverting while we figure out why one of the Greendragon lldb tests fails.

Added: 


Modified: 
clang/test/CodeGen/module-intializer-pmf.cpp
clang/test/CodeGen/module-intializer.cpp

Removed: 




diff  --git a/clang/test/CodeGen/module-intializer-pmf.cpp 
b/clang/test/CodeGen/module-intializer-pmf.cpp
index e513b280b0a75..082dda19fea09 100644
--- a/clang/test/CodeGen/module-intializer-pmf.cpp
+++ b/clang/test/CodeGen/module-intializer-pmf.cpp
@@ -29,11 +29,11 @@ struct InPMF {
 InPMF P;
 
 // CHECK: define internal void @__cxx_global_var_init
-// CHECK: call {{.*}} @_ZN4GlobC1Ev
+// CHECK: call void @_ZN4GlobC1Ev
 // CHECK: define internal void @__cxx_global_var_init
-// CHECK: call {{.*}} @_ZNW6HasPMF5InPMFC1Ev
+// CHECK: call void @_ZNW6HasPMF5InPMFC1Ev
 // CHECK: define internal void @__cxx_global_var_init
-// CHECK: call {{.*}} @_ZNW6HasPMF5InModC1Ev
+// CHECK: call void @_ZNW6HasPMF5InModC1Ev
 // CHECK: define void @_ZGIW6HasPMF
 // CHECK: store i8 1, ptr @_ZGIW6HasPMF__in_chrg
 // CHECK: call void @__cxx_global_var_init

diff  --git a/clang/test/CodeGen/module-intializer.cpp 
b/clang/test/CodeGen/module-intializer.cpp
index 0b48e87f9ea7c..df2f0a5d17da6 100644
--- a/clang/test/CodeGen/module-intializer.cpp
+++ b/clang/test/CodeGen/module-intializer.cpp
@@ -53,9 +53,9 @@ export struct Quack {
 export Quack Duck;
 
 // CHECK-N: define internal void @__cxx_global_var_init
-// CHECK-N: call {{.*}} @_ZN4OinkC1Ev
+// CHECK-N: call void @_ZN4OinkC1Ev
 // CHECK-N: define internal void @__cxx_global_var_init
-// CHECK-N: call {{.*}} @_ZNW1N5QuackC1Ev
+// CHECK-N: call void @_ZNW1N5QuackC1Ev
 // CHECK-N: define void @_ZGIW1N
 // CHECK-N: store i8 1, ptr @_ZGIW1N__in_chrg
 // CHECK-N: call void @__cxx_global_var_init
@@ -83,9 +83,9 @@ export struct Bark {
 export Bark Dog;
 
 // CHECK-O: define internal void @__cxx_global_var_init
-// CHECK-O: call {{.*}} @_ZN4MeowC2Ev
+// CHECK-O: call void @_ZN4MeowC2Ev
 // CHECK-O: define internal void @__cxx_global_var_init
-// CHECK-O: call {{.*}} @_ZNW1O4BarkC1Ev
+// CHECK-O: call void @_ZNW1O4BarkC1Ev
 // CHECK-O: define void @_ZGIW1O
 // CHECK-O: store i8 1, ptr @_ZGIW1O__in_chrg
 // CHECK-O: call void @__cxx_global_var_init
@@ -113,9 +113,9 @@ struct Squawk {
 Squawk parrot;
 
 // CHECK-P: define internal void @__cxx_global_var_init
-// CHECK-P: call {{.*}} @_ZN5CroakC1Ev
+// CHECK-P: call void @_ZN5CroakC1Ev
 // CHECK-P: define internal void @__cxx_global_var_init
-// CHECK-P: call {{.*}} @_ZNW1M6SquawkC1Ev
+// CHECK-P: call void @_ZNW1M6SquawkC1Ev
 // CHECK-P: define void @_ZGIW1MWP4Part
 // CHECK-P: store i8 1, ptr @_ZGIW1MWP4Part__in_chrg
 // CHECK-P: call void @__cxx_global_var_init
@@ -149,9 +149,9 @@ export struct Baa {
 export Baa Sheep(10);
 
 // CHECK-M: define internal void @__cxx_global_var_init
-// CHECK-M: call {{.*}} @_ZN3MooC1Ev
+// CHECK-M: call void @_ZN3MooC1Ev
 // CHECK-M: define internal void @__cxx_global_var_init
-// CHECK-M: call {{.*}} @_ZNW1M3BaaC1Ei
+// CHECK-M: call void @_ZNW1M3BaaC1Ei
 // CHECK-M: declare void @_ZGIW1O()
 // CHECK-M: declare void @_ZGIW1N()
 // CHECK-M: declare void @_ZGIW1MWP4Part()



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


[clang] b19d3ee - Revert "[C++20][Modules] Build module static initializers per P1874R1."

2022-07-11 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-07-11T19:50:31+01:00
New Revision: b19d3ee7120bff4a84db7c9fa8f86c9b6ec3b1cf

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

LOG: Revert "[C++20][Modules] Build module static initializers per P1874R1."

This reverts commit ac507102d258b6fc0cb57eb60c9dfabd57ff562f.

reverting while we figuere out why one of the green dragon lldb test fails.

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/Basic/Module.h
clang/include/clang/Sema/Sema.h
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/Parse/ParseAST.cpp
clang/lib/Sema/SemaModule.cpp

Removed: 
clang/test/CodeGen/module-intializer-pmf.cpp
clang/test/CodeGen/module-intializer.cpp



diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index db7ae9a0b55c9..87b5a6053f1f2 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -472,9 +472,6 @@ class ASTContext : public RefCountedBase {
   };
   llvm::DenseMap ModuleInitializers;
 
-  /// For module code-gen cases, this is the top-level module we are building.
-  Module *TopLevelModule = nullptr;
-
   static constexpr unsigned ConstantArrayTypesLog2InitSize = 8;
   static constexpr unsigned GeneralTypesLog2InitSize = 9;
   static constexpr unsigned FunctionProtoTypesLog2InitSize = 12;
@@ -1078,12 +1075,6 @@ class ASTContext : public RefCountedBase {
   /// Get the initializations to perform when importing a module, if any.
   ArrayRef getModuleInitializers(Module *M);
 
-  /// Set the (C++20) module we are building.
-  void setModuleForCodeGen(Module *M) { TopLevelModule = M; }
-
-  /// Get module under construction, nullptr if this is not a C++20 module.
-  Module *getModuleForCodeGen() const { return TopLevelModule; }
-
   TranslationUnitDecl *getTranslationUnitDecl() const {
 return TUDecl->getMostRecentDecl();
   }

diff  --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 47d736a3b4557..a1778baa04530 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -665,18 +665,6 @@ class Module {
   Module *findSubmodule(StringRef Name) const;
   Module *findOrInferSubmodule(StringRef Name);
 
-  /// Get the Global Module Fragment (sub-module) for this module, it there is
-  /// one.
-  ///
-  /// \returns The GMF sub-module if found, or NULL otherwise.
-  Module *getGlobalModuleFragment() { return findSubmodule(""); }
-
-  /// Get the Private Module Fragment (sub-module) for this module, it there is
-  /// one.
-  ///
-  /// \returns The PMF sub-module if found, or NULL otherwise.
-  Module *getPrivateModuleFragment() { return findSubmodule(""); }
-
   /// Determine whether the specified module would be visible to
   /// a lookup at the end of this module.
   ///

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 7dafb1b84af07..75a2e7eb31d19 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2281,11 +2281,6 @@ class Sema final {
 return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module;
   }
 
-  /// Is the module scope we are an interface?
-  bool currentModuleIsInterface() const {
-return ModuleScopes.empty() ? false : ModuleScopes.back().ModuleInterface;
-  }
-
   /// Get the module owning an entity.
   Module *getOwningModule(const Decl *Entity) {
 return Entity->getOwningModule();

diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 98b630617f26f..de5cb913220a0 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -618,127 +618,6 @@ void CodeGenModule::EmitCXXThreadLocalInitFunc() {
   CXXThreadLocals.clear();
 }
 
-/* Build the initializer for a C++20 module:
-   This is arranged to be run only once regardless of how many times the module
-   might be included transitively.  This arranged by using a control variable.
-
-   First we call any initializers for imported modules.
-   We then call initializers for the Global Module Fragment (if present)
-   We then call initializers for the current module.
-   We then call initializers for the Private Module Fragment (if present)
-*/
-
-void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
-  while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
-CXXGlobalInits.pop_back();
-
-  // We create the function, even if it is empty, since an importer of this
-  // module will refer to it unconditionally (for the current implementation
-  // there is no way for the importer to know that an importee does not need
-  // an initializer to be run).
-
-  // Module initializers 

  1   2   >