[PATCH] D156461: [clang][ASTImporter] Merge implicit ctors with definition

2023-08-17 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D156461#4583806 , @balazske wrote:

> Normally what should happen is that a new move constructor is imported (with 
> a definition) and linked after the existing one (and the existing is not 
> modified).

Does this violate the constraint that ctor shouldn't be re-declared?

> We get an AST that does not occur after a normal compile, I do not know if 
> this causes problems or if this is the real reason for this patch.

Agreed. The original AST should not be touched.

> What should be done is find the existing constructor and update it with the 
> definition and return it from the import. This can be done with any type of 
> constructor.

So does this mean that importer might be improved on this part?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156461

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


[PATCH] D155627: [clang][Interp] Handle SourceLocExprs

2023-08-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@tbaeder Maybe you could land the dependencies of this patch so that we can 
progress it. Thanks!


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

https://reviews.llvm.org/D155627

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


[PATCH] D158145: [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

2023-08-17 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

> Can you an an entry in `clang/docs/ReleaseNotes.rst` (mentioning the github 
> issue)

No problem!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158145

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


[PATCH] D158145: [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

2023-08-17 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:7836
+TEST_P(ASTImporterOptionSpecificTestBase,
+ImportFunctionDeclBitShouldNotStampingOnCtorDeclBits) {
+  Decl *From, *To;

cor3ntin wrote:
> `ImportFunctionDeclBitShouldNotOverwriteCtorDeclBits`
I added the case into `DeclTest.cpp` because i think it can cover the root 
cause for both testcases.

How about remove the somewhat repeated one in `ASTImporterTest.cpp`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158145

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


[clang] 6f7812f - [clang][Interp][NFC] Improve Pointer::print()

2023-08-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-17T09:21:51+02:00
New Revision: 6f7812fdabd9df282d1a9b4e42c17aa3aa77d431

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

LOG: [clang][Interp][NFC] Improve Pointer::print()

Print the symbolic values of Base and Offset if appropriate.

Added: 


Modified: 
clang/lib/AST/Interp/Pointer.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index a5e7ad8af81898..f8e3802d4a2299 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -350,7 +350,17 @@ class Pointer {
 
   /// Prints the pointer.
   void print(llvm::raw_ostream &OS) const {
-OS << Pointee << " {" << Base << ", " << Offset << ", ";
+OS << Pointee << " {";
+if (Base == RootPtrMark)
+  OS << "rootptr, ";
+else
+  OS << Base << ", ";
+
+if (Offset == PastEndMark)
+  OS << "pastend, ";
+else
+  OS << Offset << ", ";
+
 if (Pointee)
   OS << Pointee->getSize();
 else



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


[clang] 3cd8196 - [clang][Interp][NFC] Declare Pointer::operator<< earlier

2023-08-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-17T09:21:51+02:00
New Revision: 3cd8196bc38c406329e9395f4cbb7cbb29a92d27

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

LOG: [clang][Interp][NFC] Declare Pointer::operator<< earlier

So we can use it in Pointer.h as well when debugging.

Added: 


Modified: 
clang/lib/AST/Interp/Pointer.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index f8e3802d4a2299..8385b032c207b0 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -29,6 +29,9 @@ class DeadBlock;
 class Pointer;
 enum PrimType : unsigned;
 
+class Pointer;
+inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Pointer &P);
+
 /// A pointer to a memory block, live or dead.
 ///
 /// This object can be allocated into interpreter stack frames. If pointing to



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


[PATCH] D152504: [clang][ThreadSafety] Analyze cleanup functions

2023-08-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

I split out the CFG parts as https://reviews.llvm.org/D152504


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

https://reviews.llvm.org/D152504

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


[PATCH] D157596: [clang][Interp] Handle mixed floating/integral compound assign operators

2023-08-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


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

https://reviews.llvm.org/D157596

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


[PATCH] D144457: [clang][Interp] Handle global composite temporaries

2023-08-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144457

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


[PATCH] D157596: [clang][Interp] Handle mixed floating/integral compound assign operators

2023-08-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:2676
+
+if (ToT == PT_Float) {
+  const llvm::fltSemantics *ToSem = &Ctx.getFloatSemantics(ToQT);

Might as well leave a comment here too, for symmetry 


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

https://reviews.llvm.org/D157596

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


[PATCH] D157963: [clang-format] Annotate constructor/destructor names

2023-08-17 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 551019.
owenpan added a comment.

Rebased to D158104  and simplified 
`getFunctionName` and `isCtorOrDtorName` a little.


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

https://reviews.llvm.org/D157963

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1589,6 +1589,54 @@
   Tokens = annotate("void f [[noreturn]] () {}");
   ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("class Foo { public: Foo(); };");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("class Foo { public: ~Foo(); };");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("struct Foo { [[deprecated]] Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { [[deprecated]] ~Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { Foo() [[deprecated]] {} };");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { ~Foo() [[deprecated]] {} };");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { [[deprecated]] explicit Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { virtual [[deprecated]] ~Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("Foo::Foo() {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("Foo::~Foo() {}");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_FunctionLBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsC11GenericSelection) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16537,7 +16537,7 @@
 
   verifyFormat("int f();", SpaceFuncDef);
   verifyFormat("void f (int a, T b) {}", SpaceFuncDef);
-  verifyFormat("A::A() : a(1) {}", SpaceFuncDef);
+  verifyFormat("A::A () : a(1) {}", SpaceFuncDef);
   verifyFormat("void f() __attribute__((asdf));", SpaceFuncDef);
   verifyFormat("#define A(x) x", SpaceFuncDef);
   verifyFormat("#define A (x) x", SpaceFuncDef);
@@ -16562,7 +16562,7 @@
   // verifyFormat("T A::operator() () {}", SpaceFuncDef);
   verifyFormat("auto lambda = [] () { return 0; };", SpaceFuncDef);
   verifyFormat("int x = int(y);", SpaceFuncDef);
-  verifyFormat("M(std::size_t R, std::size_t C) : C(C), data(R) {}",
+  verifyFormat("M (std::size_t R, std::size_t C) : C(C), data(R) {}",
SpaceFuncDef);
 
   FormatStyle SpaceIfMacros = getLLVMStyle();
@@ -26220,18 +26220,18 @@
   FormatStyle Style = getLLVMStyle();
   EXPECT_EQ(Style.BreakAfterAttributes, FormatStyle::ABS_Never);
 
-  const StringRef Code("[[nodiscard]] inline int f(int &i);\n"
-   "[[foo([[]])]] [[nodiscard]]\n"
-   "int g(int &i);\n"
-   "[[nodiscard]]\n"
-   "inline int f(int &i) {\n"
-   "  i = 1;\n"
-   "  return 0;\n"
-   "}\n"
-   "[[foo([[]])]] [[nodiscard]] int g(int &i) {\n"
-   "  i = 0;\n"
-   "  return 1;\n"
-   "}");
+  constexpr StringRef Code("[[nodiscard]] inline int f(int &i);\n"
+   "[[foo([[]])]] [[nodis

[PATCH] D158145: [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

2023-08-17 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

I also investigated whether we could count those bits at compile time and 
statically assert on them,
because a small typo or missed update could spend us a lot of time to dig for 
the cause.

My first step is trying to count number of bits for a single bitfield, this is 
promising based on this 
 but
with a restriction, it only works on `struct` (default public fields), not 
`class` (default to private fields).

If we can implement this `bitsizeof` then we could have:

  enum { NumFunctionDeclBits = offsetof(FunctionDeclBitfields, SClass)
 + offsetof(FunctionDeclBitfields, IsInline)
 + ... };

This can automatically update total number of bits if any of the existing one 
is updated.

The second step is trying to enumerate all bit fields at compile time so that 
we can totally fix this kind
of issue, but it seems not possible.

Any suggestions or advices? Is it even worth it to do it like this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158145

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


[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-17 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang-tools-extra.

  struct XY {
int *x;
int *y;
  };
  void recordInitList(int *x) {
XY xy = {x, nullptr};
  }

x cannot be const int* becase it in a initialize list which only accept int*


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3568976 - Reland^2 "Fix __cfi_check not aligned to 4k on relocatable files with no executable code"

2023-08-17 Thread Yi Kong via cfe-commits

Author: Yi Kong
Date: 2023-08-17T16:33:46+09:00
New Revision: 3568976375e305a7a41d62b9164ede7571ee16c5

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

LOG: Reland^2 "Fix __cfi_check not aligned to 4k on relocatable files with no 
executable code"

This reverts commit 043d03d25bd7eadef66685de298342b35fe6b466.

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp
clang/test/CodeGen/cfi-check-fail.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 0f06f3d4089ad8..76bbeba468db64 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3430,14 +3430,12 @@ void CodeGenFunction::EmitCfiCheckStub() {
   llvm::Function *F = llvm::Function::Create(
   llvm::FunctionType::get(VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false),
   llvm::GlobalValue::WeakAnyLinkage, "__cfi_check", M);
+  F->setAlignment(llvm::Align(4096));
   CGM.setDSOLocal(F);
   llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F);
-  // FIXME: consider emitting an intrinsic call like
-  // call void @llvm.cfi_check(i64 %0, i8* %1, i8* %2)
-  // which can be lowered in CrossDSOCFI pass to the actual contents of
-  // __cfi_check. This would allow inlining of __cfi_check calls.
-  llvm::CallInst::Create(
-  llvm::Intrinsic::getDeclaration(M, llvm::Intrinsic::trap), "", BB);
+  // CrossDSOCFI pass is not executed if there is no executable code.
+  SmallVector Args{F->getArg(2), F->getArg(1)};
+  llvm::CallInst::Create(M->getFunction("__cfi_check_fail"), Args, "", BB);
   llvm::ReturnInst::Create(Ctx, nullptr, BB);
 }
 

diff  --git a/clang/test/CodeGen/cfi-check-fail.c 
b/clang/test/CodeGen/cfi-check-fail.c
index a4d940641090e5..2f12cee9dec602 100644
--- a/clang/test/CodeGen/cfi-check-fail.c
+++ b/clang/test/CodeGen/cfi-check-fail.c
@@ -72,7 +72,7 @@ void caller(void (*f)(void)) {
 // CHECK: [[CONT5]]:
 // CHECK:   ret void
 
-// CHECK: define weak void @__cfi_check(i64 %0, ptr %1, ptr %2)
+// CHECK: define weak void @__cfi_check(i64 %[[TYPE:.*]], ptr %[[ADDR:.*]], 
ptr %[[DATA:.*]]) align 4096
 // CHECK-NOT: }
-// CHECK: call void @llvm.trap()
+// CHECK: call void @__cfi_check_fail(ptr %[[DATA]], ptr %[[ADDR]])
 // CHECK-NEXT: ret void



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


[PATCH] D158145: [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

2023-08-17 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D158145#4594549 , @danix800 wrote:

> I also investigated whether we could count those bits at compile time and 
> statically assert on them,
> because a small typo or missed update could spend us a lot of time to dig for 
> the cause.
>
> My first step is trying to count number of bits for a single bitfield, this 
> is promising based on this 
>  but
> with a restriction, it only works on `struct` (default public fields), not 
> `class` (default to private fields).
>
> If we can implement this `bitsizeof` then we could have:
>
>   enum { NumFunctionDeclBits = offsetof(FunctionDeclBitfields, SClass)
>  + offsetof(FunctionDeclBitfields, IsInline)
>  + ... };
>
> This can automatically update total number of bits if any of the existing one 
> is updated.
>
> The second step is trying to enumerate all bit fields at compile time so that 
> we can totally fix this kind
> of issue, but it seems not possible.
>
> Any suggestions or advices? Is it even worth it to do it like this?

It would be great to be able to stattic_assert these sort of bugs. I think 
@aaron did some research in this area, it might be worth asking him how far he 
got!




Comment at: clang/unittests/AST/ASTImporterTest.cpp:7836
+TEST_P(ASTImporterOptionSpecificTestBase,
+ImportFunctionDeclBitShouldNotStampingOnCtorDeclBits) {
+  Decl *From, *To;

danix800 wrote:
> cor3ntin wrote:
> > `ImportFunctionDeclBitShouldNotOverwriteCtorDeclBits`
> I added the case into `DeclTest.cpp` because i think it can cover the root 
> cause for both testcases.
> 
> How about remove the somewhat repeated one in `ASTImporterTest.cpp`?
Now that you have written it, we can leave both tests i think.
Afaik one test serialization so they complement each other


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158145

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


[PATCH] D156320: [Flang][Driver] Add support for Rpass and related options

2023-08-17 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Victor, this is proving quite tricky to review. There's already been a lot of 
updates and many of them are summarized as either "code refactor" or 
"clean-up". Please reduce traffic/noise and use more descriptive summaries.

Also, rather than adding new features in this already large change (I am 
referring to e.g. `DK_MachineOptimizationRemarkMissed`), please try to identify 
ways to split this patch further. Here are some suggestions (I've also made 
comments inline):

1. In the first iteration (like you effectively do now), focus on  OPT_R_Joined 

 options (e.g. `-Rpass`, `Rpass-analysis`, `-Rpass-missed`). Focus on basic 
functionality that demonstrates that correct information is returned from the 
backend. No need to fine tune the remarks with e.g. full file path or relevant 
remark option.
2. Next, add support for -Rpass=/-Rpass-missed=/-Rpass-analysis= 
.
 That's when e.g. `llvm::opt::OptSpecifier optEq` in `parseOptimizationRemark` 
would be needed (but not in Step 1).
3. Fine tune how the report is printed (e.g. improve file name by adding full 
path, add valid remark option at the end etc).
4. Add support for machine optimisations, e.g. 
`DK_MachineOptimizationRemarkMissed`.

This is easily 4 patches ;-)




Comment at: flang/lib/Frontend/CompilerInvocation.cpp:158
+parseOptimizationRemark(clang::DiagnosticsEngine &diags,
+llvm::opt::ArgList &args, llvm::opt::OptSpecifier 
optEq,
+llvm::StringRef name) {

`optEq` is not used, but it should be.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:244-246
+  // Get -Rpass option regex. If empty, "".*"" is used. From all successful
+  // optimization passes applied, the regex will return only pass names that
+  // match it.

This is for `-Rpass=`, which is not tested. And the comment is inaccurate.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:250-252
+  // Get -Rpass-missed option regex. If empty, "".*"" is used. From all
+  // optimization passes that failed to be applied, the regex will return only
+  // pass names that match it.

This is for `-Rpass-missed=`, which is not tested. And the comment is 
inaccurate.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:256-257
+
+  // Specify which passes, with additional information,
+  // should be reported using a regex.
+  opts.OptimizationRemarkAnalysis = parseOptimizationRemark(

This is for `-Rpass-analysis=`, which is not tested. And the comment is 
inaccurate.



Comment at: flang/lib/Frontend/FrontendActions.cpp:1032-1043
+case llvm::DK_MachineOptimizationRemark:
+  optimizationRemarkHandler(
+  llvm::cast(di));
+  break;
+case llvm::DK_MachineOptimizationRemarkMissed:
+  optimizationRemarkHandler(
+  llvm::cast(di));

victorkingi wrote:
> This cases should handle back-end passes as the previous cases only handled 
> middle-end
Please move this to a dedicated patch with a test for each of these cases.



Comment at: flang/lib/Frontend/TextDiagnosticPrinter.cpp:19
 #include "flang/Frontend/TextDiagnostic.h"
+#include "string"
 #include "clang/Basic/DiagnosticOptions.h"

https://llvm.org/docs/CodingStandards.html#include-style
 
>   1.  Main Module Header
>   2.  Local/Private Headers
>   3.  LLVM project/subproject headers (clang/..., lldb/..., llvm/..., etc)
>   4.  System #includes




Comment at: flang/lib/Frontend/TextDiagnosticPrinter.cpp:39-54
+static void printRemarkOption(llvm::raw_ostream &os,
+  clang::DiagnosticsEngine::Level level,
+  const clang::Diagnostic &info) {
+  llvm::StringRef opt =
+  clang::DiagnosticIDs::getWarningOptionForDiag(info.getID());
+  if (!opt.empty()) {
+// We still need to check if the level is a Remark since, an unknown option

Move to a dedicated patch.



Comment at: flang/lib/Frontend/TextDiagnosticPrinter.cpp:76-105
+  // split incoming string to get the absolute path and filename in the
+  // case we are receiving optimization remarks from BackendRemarkConsumer
+  std::string diagMsg = std::string(diagMessageStream.str());
+  std::string delimiter = ";;";
+
+  size_t pos = 0;
+  llvm::SmallVector tokens;

Move to a dedicated patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156320

___
cfe-commits mailing lis

[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-17 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 551030.
HerrCai0907 added a comment.

add release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158152

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be 
pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -231,6 +231,10 @@
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore
+  false-positives in initializer list of record.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp
@@ -222,6 +222,18 @@
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+void recordInitList(int *x) {
+  XY xy = {x, nullptr};
+}
+
+struct XYConst {
+  int const *x;
+};
+// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const
+void recordInitListDiag(int *x) {
+  // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}}
+  XYConst xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -231,6 +231,10 @@
   ` check to
   identify calls to static member functions with out-of-class inline definitions.
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore
+  false-positives in initializer list of record.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -103,7 +103,7 @@
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
-T->isArrayType())
+T->isArrayType() || T->isRecordType())
   markCanNotBeConst(VD->getInit(), true);
 else if (T->isLValueReferenceType() &&
  !T->getPointeeType().isConstQualified())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6a06682 - [clang][NFC] fix several malformed links in ReleaseNotes.rst

2023-08-17 Thread via cfe-commits

Author: dingfei
Date: 2023-08-17T15:50:29+08:00
New Revision: 6a06682806a7cea6a2b7b0e12091d19de74d9764

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

LOG: [clang][NFC] fix several malformed links in ReleaseNotes.rst

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2c4131ad7b4c89..61272838a68b8c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -87,7 +87,7 @@ C++2c Feature Support
 
 - Attributes now expect unevaluated strings in attributes parameters that are 
string literals.
   This is applied to both C++ standard attributes, and other attributes 
supported by Clang.
-  This completes the implementation of `P2361R6 Unevaluated Strings 
_`
+  This completes the implementation of `P2361R6 Unevaluated Strings 
`_
 
 
 Resolutions to C++ Defect Reports
@@ -140,7 +140,7 @@ Bug Fixes in This Version
   module may end up with members associated with the wrong declaration of the
   class, which can result in miscompiles in some cases.
 - Fix crash on use of a variadic overloaded operator.
-  (`#42535 _`)
+  (`#42535 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
@@ -158,17 +158,17 @@ Bug Fixes to C++ Support
 
 - Fix a crash caused by some named unicode escape sequences designating
   a Unicode character whose name contains a ``-``.
-  (`Fixes #64161 _`)
+  (Fixes `#64161 `_)
 
 - Fix cases where we ignore ambiguous name lookup when looking up memebers.
-  (`#22413 _`),
-  (`#29942 _`),
-  (`#35574 _`) and
-  (`#27224 _`).
+  (`#22413 `_),
+  (`#29942 `_),
+  (`#35574 `_) and
+  (`#27224 `_).
 
 - Clang emits an error on substitution failure within lambda body inside a
   requires-expression. This fixes:
-  (`#64138 _`).
+  (`#64138 `_).
 
 Bug Fixes to AST Handling
 ^



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


[PATCH] D158145: [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

2023-08-17 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:7836
+TEST_P(ASTImporterOptionSpecificTestBase,
+ImportFunctionDeclBitShouldNotStampingOnCtorDeclBits) {
+  Decl *From, *To;

cor3ntin wrote:
> danix800 wrote:
> > cor3ntin wrote:
> > > `ImportFunctionDeclBitShouldNotOverwriteCtorDeclBits`
> > I added the case into `DeclTest.cpp` because i think it can cover the root 
> > cause for both testcases.
> > 
> > How about remove the somewhat repeated one in `ASTImporterTest.cpp`?
> Now that you have written it, we can leave both tests i think.
> Afaik one test serialization so they complement each other
OK! :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158145

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


[clang] eeac432 - Disable two tests without {arm, aarch64}-registered-target

2023-08-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-17T10:04:38+02:00
New Revision: eeac4321c517ee8afc30ebe62c5b1778efc1173d

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

LOG: Disable two tests without {arm,aarch64}-registered-target

Added: 


Modified: 
clang/test/Driver/fsplit-machine-functions.c
llvm/test/CodeGen/Generic/machine-function-splitter.ll

Removed: 




diff  --git a/clang/test/Driver/fsplit-machine-functions.c 
b/clang/test/Driver/fsplit-machine-functions.c
index 5ae72acfb04b64..e5f6a74763af23 100644
--- a/clang/test/Driver/fsplit-machine-functions.c
+++ b/clang/test/Driver/fsplit-machine-functions.c
@@ -1,3 +1,5 @@
+// REQUIRES: arm-registered-target
+
 // RUN: %clang -### -target x86_64 -fprofile-use=default.profdata 
-fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
 // RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c 2>&1 | 
FileCheck -check-prefix=CHECK-OPT %s
 // RUN: %clang -### -target x86_64 -fprofile-use=default.profdata 
-fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck 
-check-prefix=CHECK-NOOPT %s

diff  --git a/llvm/test/CodeGen/Generic/machine-function-splitter.ll 
b/llvm/test/CodeGen/Generic/machine-function-splitter.ll
index f9a972c124b129..03934434f3ceb7 100644
--- a/llvm/test/CodeGen/Generic/machine-function-splitter.ll
+++ b/llvm/test/CodeGen/Generic/machine-function-splitter.ll
@@ -1,3 +1,4 @@
+; REQUIRES: aarch64-registered-target
 ; REQUIRES: x86-registered-target
 
 ; COM: Machine function splitting with FDO profiles



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


[PATCH] D157750: Properly handle -fsplit-machine-functions for fatbinary compilation

2023-08-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

I dsabled two tests without `{arm,aarch64}-registered-target` in 
rGeeac4321c517ee8afc30ebe62c5b1778efc1173d 
; two 
post-commit comments inline




Comment at: llvm/test/CodeGen/Generic/machine-function-splitter.ll:18
+; MFS_ON: Machine Function Splitter Transformation
+; MFS_ON_NO: warning: -fsplit-machine-functions is not valid for
+;; Check that MFS is not on for non-X86 targets.

shouldn't this be `MFS_ON-NOT`?



Comment at: llvm/test/CodeGen/Generic/machine-function-splitter.ll:21
+; MFS_OFF: warning: -fsplit-machine-functions is not valid for
+; MFS_OFF_NO: Machine Function Splitter Transformation
 




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157750

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


[clang] b4e0589 - [clang][Verify] Show prefix in -verify error messages

2023-08-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-17T10:09:50+02:00
New Revision: b4e0589b2cd98a93aad449486bb2a52ab8790781

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

LOG: [clang][Verify] Show prefix in -verify error messages

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

Added: 


Modified: 
clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
clang/test/ARCMT/verify.m
clang/test/Frontend/verify-any-file.c
clang/test/Frontend/verify-fatal.c
clang/test/Frontend/verify-ignore-unexpected.c
clang/test/Frontend/verify-unknown-arg.c
clang/test/Frontend/verify.c
clang/test/Frontend/verify2.c
clang/test/Frontend/verify3.c
clang/test/Misc/diag-verify.cpp

Removed: 




diff  --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp 
b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
index d57b27e9e36fce..c811db86611e03 100644
--- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -876,8 +876,10 @@ static unsigned PrintUnexpected(DiagnosticsEngine &Diags, 
SourceManager *SourceM
 OS << ": " << I->second;
   }
 
+  std::string Prefix = *Diags.getDiagnosticOptions().VerifyPrefixes.begin();
+  std::string KindStr = Prefix + "-" + Kind;
   Diags.Report(diag::err_verify_inconsistent_diags).setForceEmit()
-<< Kind << /*Unexpected=*/true << OS.str();
+  << KindStr << /*Unexpected=*/true << OS.str();
   return std::distance(diag_begin, diag_end);
 }
 
@@ -907,8 +909,10 @@ static unsigned PrintExpected(DiagnosticsEngine &Diags,
 OS << ": " << D->Text;
   }
 
+  std::string Prefix = *Diags.getDiagnosticOptions().VerifyPrefixes.begin();
+  std::string KindStr = Prefix + "-" + Kind;
   Diags.Report(diag::err_verify_inconsistent_diags).setForceEmit()
-<< Kind << /*Unexpected=*/false << OS.str();
+  << KindStr << /*Unexpected=*/false << OS.str();
   return DL.size();
 }
 

diff  --git a/clang/test/ARCMT/verify.m b/clang/test/ARCMT/verify.m
index 7480e0dc9677cf..7d245fe80575e5 100644
--- a/clang/test/ARCMT/verify.m
+++ b/clang/test/ARCMT/verify.m
@@ -12,6 +12,6 @@
 // expected-error@-1 {{}}
 
 //  CHECK: error: no expected directives found: consider use of 
'expected-no-diagnostics'
-// CHECK-NEXT: error: 'error' diagnostics seen but not expected:
+// CHECK-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK-NEXT:   (frontend): error reading '{{.*}}verify.m.tmp.invalid'
 // CHECK-NEXT: 2 errors generated.

diff  --git a/clang/test/Frontend/verify-any-file.c 
b/clang/test/Frontend/verify-any-file.c
index d2c0d90b9db5a9..c5ca44fe87597e 100644
--- a/clang/test/Frontend/verify-any-file.c
+++ b/clang/test/Frontend/verify-any-file.c
@@ -7,8 +7,8 @@
 
 // expected-error@*:123 {{invalid line : "*" required}}
 //
-//  CHECK: error: 'error' diagnostics expected but not seen:
+//  CHECK: error: 'expected-error' diagnostics expected but not seen:
 // CHECK-NEXT:   File * Line * (directive at {{.*}}verify-any-file.c:6): 
missing error
-// CHECK-NEXT: error: 'error' diagnostics seen but not expected:
+// CHECK-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK-NEXT:   File {{.*}}verify-any-file.c Line 8: missing or invalid line 
number following '@' in expected '*'
 // CHECK-NEXT: 2 errors generated.

diff  --git a/clang/test/Frontend/verify-fatal.c 
b/clang/test/Frontend/verify-fatal.c
index 1a26196efa1b85..68fdf551717461 100644
--- a/clang/test/Frontend/verify-fatal.c
+++ b/clang/test/Frontend/verify-fatal.c
@@ -7,6 +7,6 @@
 // expected-error@-1 {{second fatal}}
 
 
-//  CHECK: error: 'error' diagnostics expected but not seen:
+//  CHECK: error: 'expected-error' diagnostics expected but not seen:
 // CHECK-NEXT:   Line 6 (directive at {{.*}}verify-fatal.c:7): second fatal
 // CHECK-NEXT: 1 error generated.

diff  --git a/clang/test/Frontend/verify-ignore-unexpected.c 
b/clang/test/Frontend/verify-ignore-unexpected.c
index bc3e0d16e686b8..085e23c8fcb9e7 100644
--- a/clang/test/Frontend/verify-ignore-unexpected.c
+++ b/clang/test/Frontend/verify-ignore-unexpected.c
@@ -3,7 +3,7 @@
 #ifdef TEST_SWITCH
 // expected-no-diagnostics
 #endif
-// CHECK-BAD-SWITCH: error: 'error' diagnostics seen but not expected:
+// CHECK-BAD-SWITCH: error: 'expected-error' diagnostics seen but not expected:
 // CHECK-BAD-SWITCH-NEXT: (frontend): invalid value 'aoeu' in 
'-verify-ignore-unexpected='
 
 // RUN: %clang_cc1 -DTEST1 -verify %s
@@ -31,32 +31,32 @@ int x;
 float x;
 #endif
 // CHECK-UNEXP: no expected directives found
-// CHECK-UNEXP-NEXT: 'error' diagnostics seen but not expected
+// CHECK-UNEXP-NEXT: 'expected-error' diagnostics seen but not expected
 // CHECK-UNEXP-NEXT: Line {{[0-9]+}}: redefinition of 'x'
-// CHECK-UNEXP-NEXT: 'warning' diagnostics s

[PATCH] D154688: [clang] Show verify prefix in error messages

2023-08-17 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb4e0589b2cd9: [clang][Verify] Show prefix in -verify error 
messages (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154688

Files:
  clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
  clang/test/ARCMT/verify.m
  clang/test/Frontend/verify-any-file.c
  clang/test/Frontend/verify-fatal.c
  clang/test/Frontend/verify-ignore-unexpected.c
  clang/test/Frontend/verify-unknown-arg.c
  clang/test/Frontend/verify.c
  clang/test/Frontend/verify2.c
  clang/test/Frontend/verify3.c
  clang/test/Misc/diag-verify.cpp

Index: clang/test/Misc/diag-verify.cpp
===
--- clang/test/Misc/diag-verify.cpp
+++ clang/test/Misc/diag-verify.cpp
@@ -25,7 +25,7 @@
   x = y; // expected-error{{use of undeclared identifier 'y' identifier 'y'}}
 }
 
-//CHECK: error: 'error' diagnostics expected but not seen: 
+//CHECK: error: 'expected-error' diagnostics expected but not seen: 
 //CHECK:   Line 17: use of undeclared identifier 'y' is fine
 //CHECK:   Line 18: abuse of undeclared identifier 'y'
 //CHECK:   Line 19: good use of undeclared identifier 'y' in code
@@ -35,7 +35,7 @@
 //CHECK:   Line 23: use of undeclared identifier 'y'; please declare y before use
 //CHECK:   Line 24: use of use of undeclared identifier 'y'
 //CHECK:   Line 25: use of undeclared identifier 'y' identifier 'y'
-//CHECK: error: 'error' diagnostics seen but not expected: 
+//CHECK: error: 'expected-error' diagnostics seen but not expected: 
 //CHECK:   Line 17: use of undeclared identifier 'y'
 //CHECK:   Line 18: use of undeclared identifier 'y'
 //CHECK:   Line 19: use of undeclared identifier 'y'
Index: clang/test/Frontend/verify3.c
===
--- clang/test/Frontend/verify3.c
+++ clang/test/Frontend/verify3.c
@@ -7,7 +7,7 @@
 // expected-no-diagnostics
 // expected-note {{}}
 
-//  CHECK1: error: 'error' diagnostics seen but not expected:
+//  CHECK1: error: 'expected-error' diagnostics seen but not expected:
 // CHECK1-NEXT:   Line 8: expected directive cannot follow 'expected-no-diagnostics' directive
 // CHECK1-NEXT: 1 error generated.
 #endif
@@ -18,7 +18,7 @@
 // expected-warning@-1 {{X}}
 // expected-no-diagnostics
 
-//  CHECK2: error: 'error' diagnostics seen but not expected:
+//  CHECK2: error: 'expected-error' diagnostics seen but not expected:
 // CHECK2-NEXT:   Line 19: 'expected-no-diagnostics' directive cannot follow other expected directives
 // CHECK2-NEXT: 1 error generated.
 #endif
Index: clang/test/Frontend/verify2.c
===
--- clang/test/Frontend/verify2.c
+++ clang/test/Frontend/verify2.c
@@ -13,7 +13,7 @@
 // expected-error {{should be ignored}}
 
 //  CHECK: error: no expected directives found: consider use of 'expected-no-diagnostics'
-// CHECK-NEXT: error: 'error' diagnostics seen but not expected:
+// CHECK-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK-NEXT:   Line 5: header
 // CHECK-NEXT:   Line 10: source
 // CHECK-NEXT: 3 errors generated.
@@ -31,9 +31,9 @@
 // expected-error@verify2.h:* {{header}}
 // expected-error@verify2.h:* {{unknown}}
 
-//  CHECK2: error: 'error' diagnostics expected but not seen:
+//  CHECK2: error: 'expected-error' diagnostics expected but not seen:
 // CHECK2-NEXT:   File {{.*}}verify2.h Line * (directive at {{.*}}verify2.c:32): unknown
-// CHECK2-NEXT: error: 'error' diagnostics seen but not expected:
+// CHECK2-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK2-NEXT:   File {{.*}}verify2.c Line 10: source
 // CHECK2-NEXT: 2 errors generated.
 #endif
Index: clang/test/Frontend/verify.c
===
--- clang/test/Frontend/verify.c
+++ clang/test/Frontend/verify.c
@@ -48,15 +48,15 @@
 // This is encapsulated in "#if 0" so that the expected-* checks below
 // are not inadvertently included in the diagnostic checking!
 
-//  CHECK2: error: 'error' diagnostics expected but not seen:
+//  CHECK2: error: 'expected-error' diagnostics expected but not seen:
 // CHECK2-NEXT:   Line 41: define_error
 // CHECK2-NEXT:   Line 43: line_error
-// CHECK2-NEXT: error: 'error' diagnostics seen but not expected:
+// CHECK2-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK2-NEXT:   Line 43: #line directive requires a positive integer argument
 // CHECK2-NEXT:   Line 44: AAA // expected-error {{[{][{]BBB[}][}]}} <- this shall be part of diagnostic
-// CHECK2-NEXT: error: 'warning' diagnostics expected but not seen:
+// CHECK2-NEXT: error: 'expected-warning' diagnostics expected but not seen:
 // CHECK2-NEXT:   Line 42: undef_error
-// CHECK2-NEXT: error: 'warning' diagnostics seen b

[PATCH] D158155: [clang-format] Exclude kw_decltype in RemoveParentheses

2023-08-17 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, MyDeveloperDay.
owenpan requested review of this revision.

>From https://en.cppreference.com/w/cpp/language/decltype:
Note that if the name of an object is parenthesized, it is treated as an 
ordinary lvalue expression, thus `decltype(x)` and `decltype((x))` are often 
different types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158155

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -26313,6 +26313,7 @@
 
   Style.RemoveParentheses = FormatStyle::RPS_MultipleParentheses;
   verifyFormat("int x __attribute__((aligned(16))) = 0;", Style);
+  verifyFormat("decltype((foo->bar)) baz;", Style);
   verifyFormat("class __declspec(dllimport) X {};",
"class __declspec((dllimport)) X {};", Style);
   verifyFormat("int x = (({ 0; }));", "int x = ((({ 0; })));", Style);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2472,7 +2472,7 @@
 const auto *PrevPrev = Prev ? Prev->getPreviousNonComment() : nullptr;
 const bool Blacklisted =
 PrevPrev &&
-(PrevPrev->is(tok::kw___attribute) ||
+(PrevPrev->isOneOf(tok::kw___attribute, tok::kw_decltype) ||
  (SeenEqual &&
   (PrevPrev->isOneOf(tok::kw_if, tok::kw_while) ||
PrevPrev->endsSequence(tok::kw_constexpr, tok::kw_if;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -26313,6 +26313,7 @@
 
   Style.RemoveParentheses = FormatStyle::RPS_MultipleParentheses;
   verifyFormat("int x __attribute__((aligned(16))) = 0;", Style);
+  verifyFormat("decltype((foo->bar)) baz;", Style);
   verifyFormat("class __declspec(dllimport) X {};",
"class __declspec((dllimport)) X {};", Style);
   verifyFormat("int x = (({ 0; }));", "int x = ((({ 0; })));", Style);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2472,7 +2472,7 @@
 const auto *PrevPrev = Prev ? Prev->getPreviousNonComment() : nullptr;
 const bool Blacklisted =
 PrevPrev &&
-(PrevPrev->is(tok::kw___attribute) ||
+(PrevPrev->isOneOf(tok::kw___attribute, tok::kw_decltype) ||
  (SeenEqual &&
   (PrevPrev->isOneOf(tok::kw_if, tok::kw_while) ||
PrevPrev->endsSequence(tok::kw_constexpr, tok::kw_if;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158145: [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

2023-08-17 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 551037.
danix800 added a comment.

1. Update ReleaseNotes.rst
2. Fix typos pointed out by @cor3ntin (thanks!)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158145

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclBase.h
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -353,6 +353,33 @@
   EXPECT_TRUE(getFooValue->isInlined());
 }
 
+TEST(Decl, FunctionDeclBitsShouldNotOverlapWithCXXConstructorDeclBits) {
+  llvm::Annotations Code(R"(
+struct A {
+  A() : m() {}
+  int m;
+};
+
+A f() { return A(); }
+)");
+
+  auto AST = tooling::buildASTFromCodeWithArgs(Code.code(), {"-std=c++14"});
+  ASTContext &Ctx = AST->getASTContext();
+  Ctx.getTranslationUnitDecl()->dump();
+
+  auto HasCtorInit =
+  hasAnyConstructorInitializer(cxxCtorInitializer(isMemberInitializer()));
+  auto ImpMoveCtor =
+  cxxConstructorDecl(isMoveConstructor(), isImplicit(), HasCtorInit)
+  .bind("MoveCtor");
+
+  auto *ToImpMoveCtor =
+  selectFirst("MoveCtor", match(ImpMoveCtor, Ctx));
+
+  EXPECT_TRUE(ToImpMoveCtor->getNumCtorInitializers() == 1);
+  EXPECT_FALSE(ToImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
+}
+
 TEST(Decl, NoProtoFunctionDeclAttributes) {
   llvm::Annotations Code(R"(
 void f();
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -7832,6 +7832,47 @@
   CheckAST(ToTU, ToC);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportFunctionDeclBitShouldNotOverwriteCtorDeclBits) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"s(
+struct A {
+  A() : m() {}
+  int m;
+};
+
+A foo() { A a; return a; }
+A bar() { return {}; }
+  )s",
+  Lang_CXX17,
+  R"s(
+struct A {
+  A() : m() {}
+  int m;
+};
+A baz() { return {}; }
+  )s",
+  Lang_CXX17, "A");
+
+  auto HasCtorInit =
+  hasAnyConstructorInitializer(cxxCtorInitializer(isMemberInitializer()));
+  auto ImpMoveCtor =
+  cxxConstructorDecl(isMoveConstructor(), isImplicit(), HasCtorInit);
+
+  auto *FromImpMoveCtor = FirstDeclMatcher().match(
+  From, ImpMoveCtor);
+  auto *ToImpMoveCtor = FirstDeclMatcher().match(
+  To, ImpMoveCtor);
+
+  EXPECT_TRUE(FromImpMoveCtor->getNumCtorInitializers() == 1);
+  EXPECT_FALSE(FromImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
+
+  EXPECT_TRUE(ToImpMoveCtor->getNumCtorInitializers() == 1);
+  EXPECT_FALSE(ToImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
+  EXPECT_TRUE(*ToImpMoveCtor->init_begin());
+}
+
 AST_MATCHER_P(UsingShadowDecl, hasIntroducerDecl, internal::Matcher,
   InnerMatcher) {
   return InnerMatcher.matches(*Node.getIntroducer(), Finder, Builder);
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -580,7 +580,7 @@
 }
 
 void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
-  static_assert(DeclContext::NumFunctionDeclBits == 30,
+  static_assert(DeclContext::NumFunctionDeclBits == 31,
 "You need to update the serializer after you change the "
 "FunctionDeclBits");
 
@@ -1495,7 +1495,7 @@
 }
 
 void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
-  static_assert(DeclContext::NumCXXConstructorDeclBits == 21,
+  static_assert(DeclContext::NumCXXConstructorDeclBits == 20,
 "You need to update the serializer after you change the "
 "CXXConstructorDeclBits");
 
Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1702,7 +1702,7 @@
   };
 
   /// Number of non-inherited bits in FunctionDeclBitfields.
-  enum { NumFunctionDeclBits = 30 };
+  enum { NumFunctionDeclBits = 31 };
 
   /// Stores the bits used by CXXConstructorDecl. If modified
   /// NumCXXConstructorDeclBits and the accessor
@@ -1714,12 +1714,12 @@
 /// For the bits in FunctionDeclBitfields.
 uint64_t : NumFunctionDeclBits;
 
-/// 21 bits to fit in the remaining available space.
+/// 20 bits to fit in the remaining available space.
 /// Note that this makes CXXConstructorDeclBitfields take
 /// exactly 64 bits and thus the width of NumCtorInitializers
 /// will need to

[PATCH] D158156: [analyzer] Add C++ array delete checker

2023-08-17 Thread Discookie via Phabricator via cfe-commits
Discookie created this revision.
Discookie added reviewers: NoQ, donat.nagy, balazske.
Discookie added projects: clang, All.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, dkrupp, 
Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Discookie requested review of this revision.
Herald added a subscriber: cfe-commits.

This checker reports cases where an array of polymorphic objects are deleted as 
their base class.
Deleting an array where the array's static type is different from its dynamic 
type is undefined.

Since the checker is similar to DeleteWithNonVirtualDtorChecker, I refactored 
that checker to support more detection types.

This checker corresponds to the SEI Cert rule EXP51-CPP: Do not delete an array 
through a pointer of the incorrect type 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158156

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/CXXDeleteChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
  clang/test/Analysis/ArrayDelete.cpp
  clang/www/analyzer/alpha_checks.html

Index: clang/www/analyzer/alpha_checks.html
===
--- clang/www/analyzer/alpha_checks.html
+++ clang/www/analyzer/alpha_checks.html
@@ -330,6 +330,27 @@
 
 
 
+
+alpha.cplusplus.ArrayDelete
+(C++)
+Reports destructions of arrays of polymorphic objects that are destructed as
+their base class
+
+
+
+Base *create() {
+  Base *x = new Derived[10]; // note: conversion from derived to base
+ //   happened here
+  return x;
+}
+
+void sink(Base *x) {
+  delete[] x; // warn: Deleting an array of polymorphic objects is undefined
+}
+
+
+
+
 
 alpha.cplusplus.DeleteWithNonVirtualDtor
 (C++)
Index: clang/test/Analysis/ArrayDelete.cpp
===
--- /dev/null
+++ clang/test/Analysis/ArrayDelete.cpp
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.cplusplus.ArrayDelete -std=c++11 -verify -analyzer-output=text %s
+
+struct Base {
+virtual ~Base() = default;
+};
+
+struct Derived : public Base {};
+
+struct DoubleDerived : public Derived {};
+
+Derived *get();
+
+Base *create() {
+Base *b = new Derived[3]; // expected-note{{Conversion from derived to base happened here}}
+return b;
+}
+
+void sink(Base *b) {
+delete[] b; // expected-warning{{Deleting an array of polymorphic objects is undefined}}
+// expected-note@-1{{Deleting an array of polymorphic objects is undefined}}
+}
+
+void sink_cast(Base *b) {
+delete[] reinterpret_cast(b); // no-warning
+}
+
+void sink_derived(Derived *d) {
+delete[] d; // no-warning
+}
+
+void same_function() {
+Base *sd = new Derived[10]; // expected-note{{Conversion from derived to base happened here}}
+delete[] sd; // expected-warning{{Deleting an array of polymorphic objects is undefined}}
+// expected-note@-1{{Deleting an array of polymorphic objects is undefined}}
+
+Base *dd = new DoubleDerived[10]; // expected-note{{Conversion from derived to base happened here}}
+delete[] dd; // expected-warning{{Deleting an array of polymorphic objects is undefined}}
+// expected-note@-1{{Deleting an array of polymorphic objects is undefined}}
+}
+
+void different_function() {
+Base *assigned = get(); // expected-note{{Conversion from derived to base happened here}}
+delete[] assigned; // expected-warning{{Deleting an array of polymorphic objects is undefined}}
+// expected-note@-1{{Deleting an array of polymorphic objects is undefined}}
+
+Base *indirect;
+indirect = get(); // expected-note{{Conversion from derived to base happened here}}
+delete[] indirect; // expected-warning{{Deleting an array of polymorphic objects is undefined}}
+// expected-note@-1{{Deleting an array of polymorphic objects is undefined}}
+
+Base *created = create(); // expected-note{{Calling 'create'}}
+// expected-note@-1{{Returning from 'create'}}
+delete[] created; // expected-warning{{Deleting an array of polymorphic objects is undefined}}
+// expected-note@-1{{Deleting an array of polymorphic objects is undefined}}
+
+Base *sb = new Derived[10]; // expected-note{{Conversion from derived to base happened here}}
+sink(sb); // expected-note{{Calling 'sink'}}
+}
+
+void safe_function() {
+Derived *d = new Derived[10];
+delete[] d; // no-warning
+
+Base *b = new Derived[10];
+delete[] reinterpret_cast(b); // no-warning
+
+Base *sb = new Derived[10];
+sink_cast(sb); // no-warning
+
+Derived *sd = new Derived[10];
+sink_derived(sd); // no-warning
+}
Index: clang/lib/Stati

[clang] 8a25145 - [clang][Interp] Pass CallExpr to builtin functions

2023-08-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-17T10:20:58+02:00
New Revision: 8a25145058d29fe0fa06cd3cdb90fea7e21228bb

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

LOG: [clang][Interp] Pass CallExpr to builtin functions

For some builtins, we need to do quite a bit of type checking ourselves,
so pass the call expression along. This way we can inspect arguments,
expected return value, etc.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/lib/AST/Interp/Opcodes.td

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 8a756e4fc2db42..1d528f642e10be 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1824,7 +1824,7 @@ bool ByteCodeExprGen::VisitBuiltinCallExpr(const 
CallExpr *E) {
   return false;
   }
 
-  if (!this->emitCallBI(Func, E))
+  if (!this->emitCallBI(Func, E, E))
 return false;
 
   QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index c278144a387130..560daca1de6eda 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -174,7 +174,8 @@ bool CheckFloatResult(InterpState &S, CodePtr OpPC, 
APFloat::opStatus Status);
 bool Interpret(InterpState &S, APValue &Result);
 
 /// Interpret a builtin function.
-bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F);
+bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
+  const CallExpr *Call);
 
 enum class ArithOp { Add, Sub };
 
@@ -1741,13 +1742,14 @@ inline bool CallVirt(InterpState &S, CodePtr OpPC, 
const Function *Func) {
   return Call(S, OpPC, Func);
 }
 
-inline bool CallBI(InterpState &S, CodePtr &PC, const Function *Func) {
+inline bool CallBI(InterpState &S, CodePtr &PC, const Function *Func,
+   const CallExpr *CE) {
   auto NewFrame = std::make_unique(S, Func, PC);
 
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 
-  if (InterpretBuiltin(S, PC, Func)) {
+  if (InterpretBuiltin(S, PC, Func, CE)) {
 NewFrame.release();
 return true;
   }

diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 2632ec7224379e..5277d05c82adfb 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -240,10 +240,9 @@ static bool interp__builtin_isnormal(InterpState &S, 
CodePtr OpPC,
 /// second one is an integral value.
 static bool interp__builtin_isfpclass(InterpState &S, CodePtr OpPC,
   const InterpFrame *Frame,
-  const Function *Func) {
-  const Expr *E = S.Current->getExpr(OpPC);
-  const CallExpr *CE = cast(E);
-  PrimType FPClassArgT = *S.getContext().classify(CE->getArgs()[1]->getType());
+  const Function *Func,
+  const CallExpr *Call) {
+  PrimType FPClassArgT = *S.getContext().classify(Call->getArg(1)->getType());
   APSInt FPClassArg = peekToAPSInt(S.Stk, FPClassArgT);
   const Floating &F =
   S.Stk.peek(align(primSize(FPClassArgT) + primSize(PT_Float)));
@@ -300,7 +299,8 @@ static bool interp__builtin_fabs(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
-bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
+bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
+  const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
 
@@ -394,7 +394,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F) {
   return Ret(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_isfpclass:
-if (interp__builtin_isfpclass(S, OpPC, Frame, F))
+if (interp__builtin_isfpclass(S, OpPC, Frame, F, Call))
   return Ret(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_fpclassify:

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 0f494c530b2568..a990d1ed976600 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -52,6 +52,7 @@ def ArgFltSemantics : ArgType { let Name = "const 
llvm::fltSemantics *"; }
 def ArgRoundingMode : ArgType { let Name = "llvm::RoundingMode"; }
 def ArgLETD: ArgType { let Name = "const LifetimeExtendedTemporaryDecl *"; }
 def ArgCastKind : ArgType { let Name = "CastKind"; }
+def ArgCallExpr : ArgType { let Name = "const CallExpr *"; }
 
 
//===

[PATCH] D155545: [clang][Interp] Pass CallExpr to builtin functions

2023-08-17 Thread Timm Bäder 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 rG8a25145058d2: [clang][Interp] Pass CallExpr to builtin 
functions (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D155545?vs=541834&id=551039#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155545

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/lib/AST/Interp/Opcodes.td

Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -52,6 +52,7 @@
 def ArgRoundingMode : ArgType { let Name = "llvm::RoundingMode"; }
 def ArgLETD: ArgType { let Name = "const LifetimeExtendedTemporaryDecl *"; }
 def ArgCastKind : ArgType { let Name = "CastKind"; }
+def ArgCallExpr : ArgType { let Name = "const CallExpr *"; }
 
 //===--===//
 // Classes of types instructions operate on.
@@ -188,7 +189,7 @@
 }
 
 def CallBI : Opcode {
-  let Args = [ArgFunction];
+  let Args = [ArgFunction, ArgCallExpr];
   let Types = [];
 }
 
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -240,10 +240,9 @@
 /// second one is an integral value.
 static bool interp__builtin_isfpclass(InterpState &S, CodePtr OpPC,
   const InterpFrame *Frame,
-  const Function *Func) {
-  const Expr *E = S.Current->getExpr(OpPC);
-  const CallExpr *CE = cast(E);
-  PrimType FPClassArgT = *S.getContext().classify(CE->getArgs()[1]->getType());
+  const Function *Func,
+  const CallExpr *Call) {
+  PrimType FPClassArgT = *S.getContext().classify(Call->getArg(1)->getType());
   APSInt FPClassArg = peekToAPSInt(S.Stk, FPClassArgT);
   const Floating &F =
   S.Stk.peek(align(primSize(FPClassArgT) + primSize(PT_Float)));
@@ -300,7 +299,8 @@
   return true;
 }
 
-bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
+bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
+  const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
 
@@ -394,7 +394,7 @@
   return Ret(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_isfpclass:
-if (interp__builtin_isfpclass(S, OpPC, Frame, F))
+if (interp__builtin_isfpclass(S, OpPC, Frame, F, Call))
   return Ret(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_fpclassify:
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -174,7 +174,8 @@
 bool Interpret(InterpState &S, APValue &Result);
 
 /// Interpret a builtin function.
-bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F);
+bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
+  const CallExpr *Call);
 
 enum class ArithOp { Add, Sub };
 
@@ -1741,13 +1742,14 @@
   return Call(S, OpPC, Func);
 }
 
-inline bool CallBI(InterpState &S, CodePtr &PC, const Function *Func) {
+inline bool CallBI(InterpState &S, CodePtr &PC, const Function *Func,
+   const CallExpr *CE) {
   auto NewFrame = std::make_unique(S, Func, PC);
 
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 
-  if (InterpretBuiltin(S, PC, Func)) {
+  if (InterpretBuiltin(S, PC, Func, CE)) {
 NewFrame.release();
 return true;
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1824,7 +1824,7 @@
   return false;
   }
 
-  if (!this->emitCallBI(Func, E))
+  if (!this->emitCallBI(Func, E, E))
 return false;
 
   QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c4becd5 - [clang][Interp] Support __null

2023-08-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-17T10:28:37+02:00
New Revision: c4becd50ad437b44a303e9a14780ce600dd95146

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

LOG: [clang][Interp] Support __null

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 1d528f642e10be..77d2b1131005d1 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1952,6 +1952,17 @@ bool 
ByteCodeExprGen::VisitCXXNullPtrLiteralExpr(
   return this->emitNullPtr(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitGNUNullExpr(const GNUNullExpr *E) {
+  if (DiscardResult)
+return true;
+
+  assert(E->getType()->isIntegerType());
+
+  PrimType T = classifyPrim(E->getType());
+  return this->emitZero(T, E);
+}
+
 template 
 bool ByteCodeExprGen::VisitCXXThisExpr(const CXXThisExpr *E) {
   if (DiscardResult)

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 6e134680d1fc5b..d28e03d571b1c6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +71,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
   bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
   bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
+  bool VisitGNUNullExpr(const GNUNullExpr *E);
   bool VisitCXXThisExpr(const CXXThisExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
   bool VisitDeclRefExpr(const DeclRefExpr *E);

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 2a31d11e72cce2..e78ae42eb6d431 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -12,9 +12,13 @@ typedef __INTPTR_TYPE__ intptr_t;
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
 static_assert(nullptr == nullptr, "");
+static_assert(__null == __null, "");
 static_assert(1 == 1, "");
 static_assert(1 == 3, ""); // expected-error{{failed}} ref-error{{failed}}
 
+constexpr void* v = nullptr;
+static_assert(__null == v, "");
+
 constexpr int number = 10;
 static_assert(number == 10, "");
 static_assert(number != 10, ""); // expected-error{{failed}} \
@@ -923,6 +927,7 @@ namespace DiscardExprs {
 
 (short)5;
 (bool)1;
+__null;
 
 return 0;
   }



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


[PATCH] D155552: [clang][Interp] Support __null

2023-08-17 Thread Timm Bäder 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 rGc4becd50ad43: [clang][Interp] Support __null (authored by 
tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D12?vs=541366&id=551042#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D12

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -12,9 +12,13 @@
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
 static_assert(nullptr == nullptr, "");
+static_assert(__null == __null, "");
 static_assert(1 == 1, "");
 static_assert(1 == 3, ""); // expected-error{{failed}} ref-error{{failed}}
 
+constexpr void* v = nullptr;
+static_assert(__null == v, "");
+
 constexpr int number = 10;
 static_assert(number == 10, "");
 static_assert(number != 10, ""); // expected-error{{failed}} \
@@ -923,6 +927,7 @@
 
 (short)5;
 (bool)1;
+__null;
 
 return 0;
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +71,7 @@
   bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
   bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
   bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
+  bool VisitGNUNullExpr(const GNUNullExpr *E);
   bool VisitCXXThisExpr(const CXXThisExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
   bool VisitDeclRefExpr(const DeclRefExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1952,6 +1952,17 @@
   return this->emitNullPtr(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitGNUNullExpr(const GNUNullExpr *E) {
+  if (DiscardResult)
+return true;
+
+  assert(E->getType()->isIntegerType());
+
+  PrimType T = classifyPrim(E->getType());
+  return this->emitZero(T, E);
+}
+
 template 
 bool ByteCodeExprGen::VisitCXXThisExpr(const CXXThisExpr *E) {
   if (DiscardResult)


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -12,9 +12,13 @@
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
 static_assert(nullptr == nullptr, "");
+static_assert(__null == __null, "");
 static_assert(1 == 1, "");
 static_assert(1 == 3, ""); // expected-error{{failed}} ref-error{{failed}}
 
+constexpr void* v = nullptr;
+static_assert(__null == v, "");
+
 constexpr int number = 10;
 static_assert(number == 10, "");
 static_assert(number != 10, ""); // expected-error{{failed}} \
@@ -923,6 +927,7 @@
 
 (short)5;
 (bool)1;
+__null;
 
 return 0;
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +71,7 @@
   bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
   bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
   bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
+  bool VisitGNUNullExpr(const GNUNullExpr *E);
   bool VisitCXXThisExpr(const CXXThisExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
   bool VisitDeclRefExpr(const DeclRefExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1952,6 +1952,17 @@
   return this->emitNullPtr(E);
 }
 
+template 
+bool ByteCodeExprGen::VisitGNUNullExpr(const GNUNullExpr *E) {
+  if (DiscardResult)
+return true;
+
+  assert(E->getType()->isIntegerType());
+
+  PrimType T = classifyPrim(E->getType());
+  return this->emitZero(T, E);
+}
+
 template 
 bool ByteCodeExprGen::VisitCXXThisExpr(const CXXThisExpr *E) {
   if (DiscardResult)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158157: [clang-tidy] Disable implicit search for a compilation db in some tests

2023-08-17 Thread Justin Bogner via Phabricator via cfe-commits
bogner created this revision.
bogner added reviewers: njames93, PiotrZSL, carlosgalvezp.
Herald added subscribers: xazax.hun, mcrosier.
Herald added a project: All.
bogner requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

These tests were failing for me on windows with a very curious error:

  error: argument unused during compilation: '/Zc:preprocessor'

It turns out that they were walking up the directory structure and
finding the compilation DB in my top level llvm-project directory.

Add `--` to the ends of the clang-tidy command lines so that they
don't go looking for random compilation databases. Also replace args
specified with `-extra-arg` with directly specifying them to the
FixedCompilationDatabase.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158157

Files:
  clang-tools-extra/test/clang-tidy/checkers/cert/mem57-cpp-cpp17.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-pp-no-crash.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-violation.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-multiple-TUs.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/use-color.cpp


Index: clang-tools-extra/test/clang-tidy/infrastructure/use-color.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/use-color.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/use-color.cpp
@@ -5,9 +5,9 @@
 // RUN: clang-tidy -config='UseColor: false' -dump-config | FileCheck 
-check-prefix=CHECK-CONFIG-NO-COLOR %s
 // RUN: clang-tidy -help | FileCheck -check-prefix=CHECK-OPT-PRESENT %s
 
-// RUN: clang-tidy -checks='-*, modernize-use-override' -extra-arg=-std=c++11 
-use-color=false %s | FileCheck -check-prefix=CHECK-NO-COLOR %s
-// RUN: clang-tidy -checks='-*, modernize-use-override' -extra-arg=-std=c++11 
%s | FileCheck -check-prefix=CHECK-NO-COLOR %s
-// RUN: clang-tidy -checks='-*, modernize-use-override' -extra-arg=-std=c++11 
-use-color %s | FileCheck -check-prefix=CHECK-COLOR %s
+// RUN: clang-tidy -checks='-*, modernize-use-override' -use-color=false %s -- 
-std=c++11 | FileCheck -check-prefix=CHECK-NO-COLOR %s
+// RUN: clang-tidy -checks='-*, modernize-use-override' %s -- -std=c++11 | 
FileCheck -check-prefix=CHECK-NO-COLOR %s
+// RUN: clang-tidy -checks='-*, modernize-use-override' -use-color %s -- 
-std=c++11 | FileCheck -check-prefix=CHECK-COLOR %s
 
 // CHECK-NOT: UseColor
 // CHECK-CONFIG-NO-COLOR: UseColor: false
Index: 
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-multiple-TUs.cpp
===
--- 
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-multiple-TUs.cpp
+++ 
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-multiple-TUs.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy %S/Inputs/nolintbeginend/1st-translation-unit.cpp 
%S/Inputs/nolintbeginend/2nd-translation-unit.cpp 
--checks='-*,google-explicit-constructor' 2>&1 | FileCheck %s
+// RUN: clang-tidy %S/Inputs/nolintbeginend/1st-translation-unit.cpp 
%S/Inputs/nolintbeginend/2nd-translation-unit.cpp 
--checks='-*,google-explicit-constructor' -- 2>&1 | FileCheck %s
 
 // CHECK-NOT: 1st-translation-unit.cpp:2:11: warning: single-argument 
constructors must be marked explicit
 // CHECK: 1st-translation-unit.cpp:5:11: warning: single-argument constructors 
must be marked explicit
Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-violation.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-violation.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-case-violation.cpp
@@ -5,7 +5,7 @@
 // RUN:   readability-identifier-naming.ClassCase: UUPER_CASE, \
 // RUN:   readability-identifier-naming.StructCase: CAMEL, \
 // RUN:   readability-identifier-naming.EnumCase: AnY_cASe, \
-// RUN:   }}" 2>&1 | FileCheck %s --implicit-check-not="{{warning|error}}:"
+// RUN:   }}" -- 2>&1 | FileCheck %s --implicit-check-not="{{warning|error}}:"
 
 // CHECK-DAG: warning: invalid configuration value 'camelback' for option 
'readability-identifier-naming.FunctionCase'; did you mean 'camelBack'? 
[clang-tidy-config]
 // CHECK-DAG: warning: invalid configuration value 'UUPER_CASE' for option 
'readability-identifier-naming.ClassCase'; did you mean 'UPPER_CASE'? 
[clang-tidy-config]
Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-pp-no-crash.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-pp-no-crash.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return-pp-no-crash.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-tidy %s -

[clang] 91af0d0 - [clang][Interp] Make sure we push integers of the correct size

2023-08-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-17T10:36:06+02:00
New Revision: 91af0d0a669880918eda2d2bd2d6185b2903a402

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

LOG: [clang][Interp] Make sure we push integers of the correct size

Integers might not be 32 bits wide, so check the TargetInfo for their
size.

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

Added: 


Modified: 
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index de588ab8c9f191..8d5edbb5b764ed 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -94,6 +94,7 @@ template  class Integral final {
   explicit operator unsigned() const { return V; }
   explicit operator int64_t() const { return V; }
   explicit operator uint64_t() const { return V; }
+  explicit operator int32_t() const { return V; }
 
   APSInt toAPSInt() const {
 return APSInt(APInt(Bits, static_cast(V), Signed), !Signed);

diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 5277d05c82adfb..5702859996dca2 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -32,6 +32,30 @@ static APSInt peekToAPSInt(InterpStack &Stk, PrimType T) {
   return R;
 }
 
+/// Pushes \p Val to the stack, as a target-dependent 'int'.
+static void pushInt(InterpState &S, int32_t Val) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+S.Stk.push>(Integral<32, true>::from(Val));
+  else if (IntWidth == 16)
+S.Stk.push>(Integral<16, true>::from(Val));
+  else
+llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
+static bool retInt(InterpState &S, CodePtr OpPC, APValue &Result) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+return Ret(S, OpPC, Result);
+  else if (IntWidth == 16)
+return Ret(S, OpPC, Result);
+  llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame) {
   const Pointer &A = getParam(Frame, 0);
@@ -67,7 +91,7 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr 
OpPC,
   break;
   }
 
-  S.Stk.push>(Integral<32, true>::from(Result));
+  pushInt(S, Result);
   return true;
 }
 
@@ -200,7 +224,7 @@ static bool interp__builtin_isnan(InterpState &S, CodePtr 
OpPC,
   const InterpFrame *Frame, const Function *F) 
{
   const Floating &Arg = S.Stk.peek();
 
-  S.Stk.push>(Integral<32, true>::from(Arg.isNan()));
+  pushInt(S, Arg.isNan());
   return true;
 }
 
@@ -211,10 +235,9 @@ static bool interp__builtin_isinf(InterpState &S, CodePtr 
OpPC,
   bool IsInf = Arg.isInf();
 
   if (CheckSign)
-S.Stk.push>(
-Integral<32, true>::from(IsInf ? (Arg.isNegative() ? -1 : 1) : 0));
+pushInt(S, IsInf ? (Arg.isNegative() ? -1 : 1) : 0);
   else
-S.Stk.push>(Integral<32, true>::from(Arg.isInf()));
+pushInt(S, Arg.isInf());
   return true;
 }
 
@@ -223,7 +246,7 @@ static bool interp__builtin_isfinite(InterpState &S, 
CodePtr OpPC,
  const Function *F) {
   const Floating &Arg = S.Stk.peek();
 
-  S.Stk.push>(Integral<32, true>::from(Arg.isFinite()));
+  pushInt(S, Arg.isFinite());
   return true;
 }
 
@@ -232,7 +255,7 @@ static bool interp__builtin_isnormal(InterpState &S, 
CodePtr OpPC,
  const Function *F) {
   const Floating &Arg = S.Stk.peek();
 
-  S.Stk.push>(Integral<32, true>::from(Arg.isNormal()));
+  pushInt(S, Arg.isNormal());
   return true;
 }
 
@@ -249,12 +272,12 @@ static bool interp__builtin_isfpclass(InterpState &S, 
CodePtr OpPC,
 
   int32_t Result =
   static_cast((F.classify() & FPClassArg).getZExtValue());
-  S.Stk.push>(Integral<32, true>::from(Result));
+  pushInt(S, Result);
 
   return true;
 }
 
-/// Five int32 values followed by one floating value.
+/// Five int values followed by one floating value.
 static bool interp__builtin_fpclassify(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func) {
@@ -280,8 +303,9 @@ static bool interp__builtin_fpclassify(InterpState &S, 
CodePtr OpPC,
   unsigned Offset = align(primSize(PT_Float)) +
 ((1 + (4 - Index)) * align(primSize(PT_Sint32)));
 
+  // FIXME: The size of the value we're peeking here is target-dependent.
   const Integral<32, true> &I = S.Stk.peek>(Offset);
-

[PATCH] D155568: [clang][Interp] Make sure we push integers of the correct size

2023-08-17 Thread Timm Bäder 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 rG91af0d0a6698: [clang][Interp] Make sure we push integers of 
the correct size (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D155568?vs=545349&id=551043#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155568

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/AST/Interp/builtin-functions.cpp

Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
 // RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter %s -verify
 // RUN: %clang_cc1 -std=c++20 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -triple avr -std=c++20 -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -triple avr -std=c++20 -verify=ref %s -Wno-constant-evaluated
 
 
 namespace strcmp {
@@ -96,10 +98,12 @@
   char isfpclass_pos_1[!__builtin_isfpclass(1.0f, 0x0008) ? 1 : -1]; // fcNegNormal
   char isfpclass_pos_2[__builtin_isfpclass(1.0L, 0x01F8) ? 1 : -1]; // fcFinite
   char isfpclass_pos_3[!__builtin_isfpclass(1.0, 0x0003) ? 1 : -1]; // fcSNan|fcQNan
+#ifndef __AVR__
   char isfpclass_pdenorm_0[__builtin_isfpclass(1.0e-40f, 0x0080) ? 1 : -1]; // fcPosSubnormal
   char isfpclass_pdenorm_1[__builtin_isfpclass(1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite
   char isfpclass_pdenorm_2[!__builtin_isfpclass(1.0e-40f, 0x003C) ? 1 : -1]; // fcNegative
   char isfpclass_pdenorm_3[!__builtin_isfpclass(1.0e-310, 0x0207) ? 1 : -1]; // ~fcFinite
+#endif
   char isfpclass_pzero_0  [__builtin_isfpclass(0.0f, 0x0060) ? 1 : -1]; // fcZero
   char isfpclass_pzero_1  [__builtin_isfpclass(0.0, 0x01F8) ? 1 : -1]; // fcFinite
   char isfpclass_pzero_2  [!__builtin_isfpclass(0.0L, 0x0020) ? 1 : -1]; // fcNegZero
@@ -109,9 +113,11 @@
   char isfpclass_nzero_2  [!__builtin_isfpclass(-0.0L, 0x0040) ? 1 : -1]; // fcPosZero
   char isfpclass_nzero_3  [!__builtin_isfpclass(-0.0, 0x0003) ? 1 : -1]; // fcNan
   char isfpclass_ndenorm_0[__builtin_isfpclass(-1.0e-40f, 0x0010) ? 1 : -1]; // fcNegSubnormal
-  char isfpclass_ndenorm_1[__builtin_isfpclass(-1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite
   char isfpclass_ndenorm_2[!__builtin_isfpclass(-1.0e-40f, 0x03C0) ? 1 : -1]; // fcPositive
+#ifndef __AVR__
+  char isfpclass_ndenorm_1[__builtin_isfpclass(-1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite
   char isfpclass_ndenorm_3[!__builtin_isfpclass(-1.0e-310, 0x0207) ? 1 : -1]; // ~fcFinite
+#endif
   char isfpclass_neg_0[__builtin_isfpclass(-1.0, 0x0008) ? 1 : -1]; // fcNegNormal
   char isfpclass_neg_1[!__builtin_isfpclass(-1.0f, 0x00100) ? 1 : -1]; // fcPosNormal
   char isfpclass_neg_2[__builtin_isfpclass(-1.0L, 0x01F8) ? 1 : -1]; // fcFinite
@@ -136,9 +142,11 @@
   char classify_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, __builtin_inf())];
   char classify_neg_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, -__builtin_inf())];
   char classify_normal  [__builtin_fpclassify(-1, -1, +1, -1, -1, 1.539)];
+#ifndef __AVR__
   char classify_normal2 [__builtin_fpclassify(-1, -1, +1, -1, -1, 1e-307)];
   char classify_denorm  [__builtin_fpclassify(-1, -1, -1, +1, -1, 1e-308)];
   char classify_denorm2 [__builtin_fpclassify(-1, -1, -1, +1, -1, -1e-308)];
+#endif
   char classify_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, 0.0)];
   char classify_neg_zero[__builtin_fpclassify(-1, -1, -1, -1, +1, -0.0)];
   char classify_subnorm [__builtin_fpclassify(-1, -1, -1, +1, -1, 1.0e-38f)];
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -32,6 +32,30 @@
   return R;
 }
 
+/// Pushes \p Val to the stack, as a target-dependent 'int'.
+static void pushInt(InterpState &S, int32_t Val) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+S.Stk.push>(Integral<32, true>::from(Val));
+  else if (IntWidth == 16)
+S.Stk.push>(Integral<16, true>::from(Val));
+  else
+llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
+static bool retInt(InterpState &S, CodePtr OpPC, APValue &Result) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+return Ret(S, OpPC, Result);
+  else if (IntWidth == 16)
+return Ret(S, OpPC, Result);
+  llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame

[PATCH] D158046: [X86] Support -march=gracemont

2023-08-17 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/lib/Basic/Targets/X86.cpp:551
   case CK_Lunarlake:
+  case CK_Gracemont:
   case CK_Sierraforest:

Why not handle this above (below tremont) as the next in the *mont series?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158046

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


[PATCH] D158158: [clang] Set FP options in Sema when instantiating CompoundStmt

2023-08-17 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff created this revision.
sepavloff added reviewers: rjmccall, aaron.ballman, efriedma, zahiraam.
Herald added a project: All.
sepavloff requested review of this revision.
Herald added a project: clang.

When an expression is instantiated, TreeTransform skips ImplicitCastExpr
nodes, assuming they are recreated when the instantiated expression is
built. It breaks functions that use non-default floating-point options,
because they are kept in these ImplicitCastExprs. In this case the
recreated ImplicitCastExpr takes FP options from the current Sema state
and not from AST node.

To fix this issue FP options in Sema object are set when a compound
statement is cloned in TreeTransform.

This change fixes https://github.com/llvm/llvm-project/issues/64605
([Regression 16 -> 17] Template instantiation ignores FENV_ACCESS being
ON for both definition and instantiation).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158158

Files:
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/template-64605.cpp


Index: clang/test/SemaCXX/template-64605.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/template-64605.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -ast-dump -ast-dump-filter=b_64605 %s | FileCheck %s
+
+// https://github.com/llvm/llvm-project/issues/64605
+
+#pragma STDC FENV_ACCESS ON
+template 
+int b_64605() {
+  int x;
+  if ((float)0x != (float)0x1) {
+x = 1;
+  }
+  return x;
+}
+int f() { return b_64605(); }
+
+// CHECK:  ImplicitCastExpr {{.*}} 'float'  
RoundingMath=1 AllowFEnvAccess=1
+// CHECK-NEXT: IntegerLiteral {{.*}} 4294967295
+
+// CHECK:  FunctionDecl {{.*}} b_64605 'int ()' implicit_instantiation
+// CHECK-NEXT: TemplateArgument type 'void'
+
+// CHECK:  ImplicitCastExpr {{.*}} 'float'  
RoundingMath=1 AllowFEnvAccess=1 
+// CHECK-NEXT: IntegerLiteral {{.*}} 4294967295
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -7491,6 +7491,10 @@
 TreeTransform::TransformCompoundStmt(CompoundStmt *S,
   bool IsStmtExpr) {
   Sema::CompoundScopeRAII CompoundScope(getSema());
+  Sema::FPFeaturesStateRAII FPSave(getSema());
+  if (S->hasStoredFPFeatures())
+getSema().resetFPOptions(
+S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
 
   const Stmt *ExprResult = S->getStmtExprResult();
   bool SubStmtInvalid = false;


Index: clang/test/SemaCXX/template-64605.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/template-64605.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -ast-dump -ast-dump-filter=b_64605 %s | FileCheck %s
+
+// https://github.com/llvm/llvm-project/issues/64605
+
+#pragma STDC FENV_ACCESS ON
+template 
+int b_64605() {
+  int x;
+  if ((float)0x != (float)0x1) {
+x = 1;
+  }
+  return x;
+}
+int f() { return b_64605(); }
+
+// CHECK:  ImplicitCastExpr {{.*}} 'float'  RoundingMath=1 AllowFEnvAccess=1
+// CHECK-NEXT: IntegerLiteral {{.*}} 4294967295
+
+// CHECK:  FunctionDecl {{.*}} b_64605 'int ()' implicit_instantiation
+// CHECK-NEXT: TemplateArgument type 'void'
+
+// CHECK:  ImplicitCastExpr {{.*}} 'float'  RoundingMath=1 AllowFEnvAccess=1 
+// CHECK-NEXT: IntegerLiteral {{.*}} 4294967295
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -7491,6 +7491,10 @@
 TreeTransform::TransformCompoundStmt(CompoundStmt *S,
   bool IsStmtExpr) {
   Sema::CompoundScopeRAII CompoundScope(getSema());
+  Sema::FPFeaturesStateRAII FPSave(getSema());
+  if (S->hasStoredFPFeatures())
+getSema().resetFPOptions(
+S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
 
   const Stmt *ExprResult = S->getStmtExprResult();
   bool SubStmtInvalid = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b719e41 - [CodeGen] Clean up access to EmittedDeferredDecls, NFCI.

2023-08-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-17T10:39:47+02:00
New Revision: b719e410781ce9f3a2b316afea31c156bf99e036

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

LOG: [CodeGen] Clean up access to EmittedDeferredDecls, NFCI.

GlobalDecls should only be added to EmittedDeferredDecls if they
need reemission. This is checked in addEmittedDeferredDecl, which
is called via addDeferredDeclToEmit. Extend these checks to also
handle VarDecls (for lambdas, as tested in Interpreter/lambda.cpp)
and remove the direct access of EmittedDeferredDecls in EmitGlobal
that may actually end up duplicating FunctionDecls.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 2a7a36e53d8189..517af514d9c998 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3677,7 +3677,6 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
 // The value must be emitted, but cannot be emitted eagerly.
 assert(!MayBeEmittedEagerly(Global));
 addDeferredDeclToEmit(GD);
-EmittedDeferredDecls[MangledName] = GD;
   } else {
 // Otherwise, remember that we saw a deferred decl with this name.  The
 // first use of the mangled name will cause it to move into
@@ -4417,7 +4416,6 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
   // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
   // don't need it anymore).
   addDeferredDeclToEmit(DDI->second);
-  EmittedDeferredDecls[DDI->first] = DDI->second;
   DeferredDecls.erase(DDI);
 
   // Otherwise, there are cases we have to worry about where we're
@@ -4677,7 +4675,6 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 // Move the potentially referenced deferred decl to the DeferredDeclsToEmit
 // list, and remove it from DeferredDecls (since we don't need it anymore).
 addDeferredDeclToEmit(DDI->second);
-EmittedDeferredDecls[DDI->first] = DDI->second;
 DeferredDecls.erase(DDI);
   }
 

diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index ef90eaca59a4e0..7301109fb04409 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -361,10 +361,15 @@ class CodeGenModule : public CodeGenTypeCache {
   llvm::DenseMap EmittedDeferredDecls;
 
   void addEmittedDeferredDecl(GlobalDecl GD) {
-if (!llvm::isa(GD.getDecl()))
-  return;
-llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD);
-if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+// Assume a linkage by default that does not need reemission.
+auto L = llvm::GlobalValue::ExternalLinkage;
+if (llvm::isa(GD.getDecl()))
+  L = getFunctionLinkage(GD);
+else if (auto *VD = llvm::dyn_cast(GD.getDecl()))
+  L = getLLVMLinkageVarDefinition(VD);
+
+if (llvm::GlobalValue::isInternalLinkage(L) ||
+llvm::GlobalValue::isLinkOnceLinkage(L) ||
 llvm::GlobalValue::isWeakLinkage(L)) {
   EmittedDeferredDecls[getMangledName(GD)] = GD;
 }



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


[PATCH] D156897: [CodeGen] Clean up access to EmittedDeferredDecls, NFCI.

2023-08-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb719e410781c: [CodeGen] Clean up access to 
EmittedDeferredDecls, NFCI. (authored by Hahnfeld).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156897

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h


Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -361,10 +361,15 @@
   llvm::DenseMap EmittedDeferredDecls;
 
   void addEmittedDeferredDecl(GlobalDecl GD) {
-if (!llvm::isa(GD.getDecl()))
-  return;
-llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD);
-if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+// Assume a linkage by default that does not need reemission.
+auto L = llvm::GlobalValue::ExternalLinkage;
+if (llvm::isa(GD.getDecl()))
+  L = getFunctionLinkage(GD);
+else if (auto *VD = llvm::dyn_cast(GD.getDecl()))
+  L = getLLVMLinkageVarDefinition(VD);
+
+if (llvm::GlobalValue::isInternalLinkage(L) ||
+llvm::GlobalValue::isLinkOnceLinkage(L) ||
 llvm::GlobalValue::isWeakLinkage(L)) {
   EmittedDeferredDecls[getMangledName(GD)] = GD;
 }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3677,7 +3677,6 @@
 // The value must be emitted, but cannot be emitted eagerly.
 assert(!MayBeEmittedEagerly(Global));
 addDeferredDeclToEmit(GD);
-EmittedDeferredDecls[MangledName] = GD;
   } else {
 // Otherwise, remember that we saw a deferred decl with this name.  The
 // first use of the mangled name will cause it to move into
@@ -4417,7 +4416,6 @@
   // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
   // don't need it anymore).
   addDeferredDeclToEmit(DDI->second);
-  EmittedDeferredDecls[DDI->first] = DDI->second;
   DeferredDecls.erase(DDI);
 
   // Otherwise, there are cases we have to worry about where we're
@@ -4677,7 +4675,6 @@
 // Move the potentially referenced deferred decl to the DeferredDeclsToEmit
 // list, and remove it from DeferredDecls (since we don't need it anymore).
 addDeferredDeclToEmit(DDI->second);
-EmittedDeferredDecls[DDI->first] = DDI->second;
 DeferredDecls.erase(DDI);
   }
 


Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -361,10 +361,15 @@
   llvm::DenseMap EmittedDeferredDecls;
 
   void addEmittedDeferredDecl(GlobalDecl GD) {
-if (!llvm::isa(GD.getDecl()))
-  return;
-llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD);
-if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+// Assume a linkage by default that does not need reemission.
+auto L = llvm::GlobalValue::ExternalLinkage;
+if (llvm::isa(GD.getDecl()))
+  L = getFunctionLinkage(GD);
+else if (auto *VD = llvm::dyn_cast(GD.getDecl()))
+  L = getLLVMLinkageVarDefinition(VD);
+
+if (llvm::GlobalValue::isInternalLinkage(L) ||
+llvm::GlobalValue::isLinkOnceLinkage(L) ||
 llvm::GlobalValue::isWeakLinkage(L)) {
   EmittedDeferredDecls[getMangledName(GD)] = GD;
 }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3677,7 +3677,6 @@
 // The value must be emitted, but cannot be emitted eagerly.
 assert(!MayBeEmittedEagerly(Global));
 addDeferredDeclToEmit(GD);
-EmittedDeferredDecls[MangledName] = GD;
   } else {
 // Otherwise, remember that we saw a deferred decl with this name.  The
 // first use of the mangled name will cause it to move into
@@ -4417,7 +4416,6 @@
   // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
   // don't need it anymore).
   addDeferredDeclToEmit(DDI->second);
-  EmittedDeferredDecls[DDI->first] = DDI->second;
   DeferredDecls.erase(DDI);
 
   // Otherwise, there are cases we have to worry about where we're
@@ -4677,7 +4675,6 @@
 // Move the potentially referenced deferred decl to the DeferredDeclsToEmit
 // list, and remove it from DeferredDecls (since we don't need it anymore).
 addDeferredDeclToEmit(DDI->second);
-EmittedDeferredDecls[DDI->first] = DDI->second;
 DeferredDecls.erase(DDI);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b3469ce - [clang][Analysis] Handle && and || against variable and its negation as tautology

2023-08-17 Thread Takuya Shimizu via cfe-commits

Author: Takuya Shimizu
Date: 2023-08-17T17:55:48+09:00
New Revision: b3469ce6f80bce2b0a86026fd6867c4b04853466

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

LOG: [clang][Analysis] Handle && and || against variable and its negation as 
tautology

This patch introduces a new warning flag -Wtautological-negation-compare 
grouped in -Wtautological-compare that warns on the use of && or || operators 
against a variable and its negation.
e.g. x || !x and !x && x
This also makes the -Winfinite-recursion diagnose more cases.

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

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

Added: 
clang/test/SemaCXX/tautological-negation-compare.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Analysis/CFG.h
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Analysis/CFG.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/test/Analysis/temp-obj-dtors-cfg-output.cpp
clang/test/Misc/warning-wall.c
clang/test/SemaCXX/warn-infinite-recursion.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 61272838a68b8c..02b897bcd0a68e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -132,6 +132,10 @@ Improvements to Clang's diagnostics
   of a base class is not called in the constructor of its derived class.
 - Clang no longer emits ``-Wmissing-variable-declarations`` for variables 
declared
   with the ``register`` storage class.
+- Clang's ``-Wtautological-negation-compare`` flag now diagnoses logical
+  tautologies like ``x && !x`` and ``!x || x`` in expressions. This also
+  makes ``-Winfinite-recursion`` diagnose more cases.
+  (`#56035: `_).
 
 Bug Fixes in This Version
 -

diff  --git a/clang/include/clang/Analysis/CFG.h 
b/clang/include/clang/Analysis/CFG.h
index eacebe176dda4c..cf4fa2da2a358e 100644
--- a/clang/include/clang/Analysis/CFG.h
+++ b/clang/include/clang/Analysis/CFG.h
@@ -1162,6 +1162,7 @@ class CFGCallback {
   CFGCallback() = default;
   virtual ~CFGCallback() = default;
 
+  virtual void logicAlwaysTrue(const BinaryOperator *B, bool isAlwaysTrue) {}
   virtual void compareAlwaysTrue(const BinaryOperator *B, bool isAlwaysTrue) {}
   virtual void compareBitwiseEquality(const BinaryOperator *B,
   bool isAlwaysTrue) {}

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6f8386cd10922f..d1aa51393ef357 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -678,13 +678,15 @@ def TautologicalOverlapCompare : 
DiagGroup<"tautological-overlap-compare">;
 def TautologicalBitwiseCompare : DiagGroup<"tautological-bitwise-compare">;
 def TautologicalUndefinedCompare : DiagGroup<"tautological-undefined-compare">;
 def TautologicalObjCBoolCompare : DiagGroup<"tautological-objc-bool-compare">;
+def TautologicalNegationCompare : DiagGroup<"tautological-negation-compare">;
 def TautologicalCompare : DiagGroup<"tautological-compare",
 [TautologicalConstantCompare,
  TautologicalPointerCompare,
  TautologicalOverlapCompare,
  TautologicalBitwiseCompare,
  TautologicalUndefinedCompare,
- TautologicalObjCBoolCompare]>;
+ TautologicalObjCBoolCompare,
+ TautologicalNegationCompare]>;
 def HeaderHygiene : DiagGroup<"header-hygiene">;
 def DuplicateDeclSpecifier : DiagGroup<"duplicate-decl-specifier">;
 def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 632be32cfddd5a..8c629aad89f48a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9796,6 +9796,12 @@ def warn_comparison_bitwise_always : Warning<
 def warn_comparison_bitwise_or : Warning<
   "bitwise or with non-zero value always evaluates to true">,
   InGroup, DefaultIgnore;
+def warn_tautological_negation_and_compare: Warning<
+  "'&&' of a value and its negation always evaluates to false">,
+  InGroup, DefaultIgnore;
+def warn_tautological_negation_or_compare: Warning<
+  "'||' of a value and its negation always evaluates to true">,
+  InGroup, DefaultIgnore;
 def warn_tautological_overlap_compariso

[PATCH] D152093: [clang][Analysis] Handle && and || against variable and its negation as tautology

2023-08-17 Thread Takuya Shimizu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hazohelet marked an inline comment as done.
Closed by commit rGb3469ce6f80b: [clang][Analysis] Handle && and || 
against variable and its negation as… (authored by hazohelet).

Changed prior to commit:
  https://reviews.llvm.org/D152093?vs=545213&id=551047#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152093

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Analysis/CFG.h
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Analysis/CFG.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/Analysis/temp-obj-dtors-cfg-output.cpp
  clang/test/Misc/warning-wall.c
  clang/test/SemaCXX/tautological-negation-compare.cpp
  clang/test/SemaCXX/warn-infinite-recursion.cpp

Index: clang/test/SemaCXX/warn-infinite-recursion.cpp
===
--- clang/test/SemaCXX/warn-infinite-recursion.cpp
+++ clang/test/SemaCXX/warn-infinite-recursion.cpp
@@ -203,3 +203,13 @@
   (void)typeid(unevaluated_recursive_function());
   return 0;
 }
+
+void func1(int i) { // expected-warning {{call itself}}
+  if (i || !i)
+func1(i);
+}
+void func2(int i) { // expected-warning {{call itself}}
+  if (!i && i) {}
+  else
+func2(i);
+}
Index: clang/test/SemaCXX/tautological-negation-compare.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/tautological-negation-compare.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-negation-compare -Wno-constant-logical-operand %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-compare -Wno-constant-logical-operand %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall -Wno-unused -Wno-loop-analysis -Wno-constant-logical-operand %s
+
+#define COPY(x) x
+
+void test_int(int x) {
+  if (x || !x) {} // expected-warning {{'||' of a value and its negation always evaluates to true}}
+  if (!x || x) {} // expected-warning {{'||' of a value and its negation always evaluates to true}}
+  if (x && !x) {} // expected-warning {{'&&' of a value and its negation always evaluates to false}}
+  if (!x && x) {} // expected-warning {{'&&' of a value and its negation always evaluates to false}}
+
+  // parentheses are ignored
+  if (x || (!x)) {} // expected-warning {{'||' of a value and its negation always evaluates to true}}
+  if (!(x) || x) {} // expected-warning {{'||' of a value and its negation always evaluates to true}}
+
+  // don't warn on macros
+  if (COPY(x) || !x) {}
+  if (!x || COPY(x)) {}
+  if (x && COPY(!x)) {}
+  if (COPY(!x && x)) {}
+
+  // dont' warn on literals
+  if (1 || !1) {}
+  if (!42 && 42) {}
+
+
+  // don't warn on overloads
+  struct Foo{
+int val;
+Foo operator!() const { return Foo{!val}; }
+bool operator||(const Foo other) const { return val || other.val; }
+bool operator&&(const Foo other) const { return val && other.val; }
+  };
+
+  Foo f{3};
+  if (f || !f) {}
+  if (!f || f) {}
+  if (f.val || !f.val) {} // expected-warning {{'||' of a value and its negation always evaluates to true}}
+  if (!f.val && f.val) {} // expected-warning {{'&&' of a value and its negation always evaluates to false}}
+}
Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -55,6 +55,7 @@
 CHECK-NEXT:  -Wtautological-bitwise-compare
 CHECK-NEXT:  -Wtautological-undefined-compare
 CHECK-NEXT:  -Wtautological-objc-bool-compare
+CHECK-NEXT:  -Wtautological-negation-compare
 CHECK-NEXT:-Wtrigraphs
 CHECK-NEXT:-Wuninitialized
 CHECK-NEXT:  -Wsometimes-uninitialized
Index: clang/test/Analysis/temp-obj-dtors-cfg-output.cpp
===
--- clang/test/Analysis/temp-obj-dtors-cfg-output.cpp
+++ clang/test/Analysis/temp-obj-dtors-cfg-output.cpp
@@ -1393,13 +1393,13 @@
 // CHECK: Succs (2): B2 B1
 // CHECK:   [B4 (NORETURN)]
 // CHECK: 1: ~NoReturn() (Temporary object destructor)
-// CHECK: Preds (1): B5
+// CHECK: Preds (1): B5(Unreachable)
 // CHECK: Succs (1): B0
 // CHECK:   [B5]
 // CHECK: 1: [B8.3] || [B7.2] || [B6.7]
 // CHECK: T: (Temp Dtor) [B6.4]
 // CHECK: Preds (3): B6 B7 B8
-// CHECK: Succs (2): B4 B3
+// CHECK: Succs (2): B4(Unreachable) B3
 // CHECK:   [B6]
 // CHECK: 1: check
 // CHECK: 2: [B6.1] (ImplicitCastExpr, FunctionToPointerDecay, _Bool (*)(const NoReturn &))
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -158,6 +158,17 @@
 re

[PATCH] D158008: [AArch64] Add patterns for FMADD, FMSUB

2023-08-17 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs accepted this revision.
samtebbs added a comment.
This revision is now accepted and ready to land.

Thanks, this looks good to me with any extra tests required by David's comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158008

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


[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-17 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 551051.
Fznamznon added a comment.

Add a release note, apply feedback:

- Do not report invalid initializers as missing
- Fix wrong warning if record has bitfields


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp

Index: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
===
--- clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,reorder -Wno-c99-designator -Werror=reorder-init-list -Wno-initializer-overrides
 // RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,override -Wno-c99-designator -Wno-reorder-init-list -Werror=initializer-overrides
 // RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected -Wno-c99-designator -Wno-reorder-init-list -Wno-initializer-overrides
+// RUN: %clang_cc1 -std=c++20 %s -verify=cxx20,expected,wmissing -Wmissing-field-initializers -Wno-c99-designator -Wno-reorder-init-list -Wno-initializer-overrides
 
 
 namespace class_with_ctor {
@@ -49,15 +50,17 @@
 A a4 = {
   .x = 1, // override-note {{previous}}
   .x = 1 // override-error {{overrides prior initialization}}
-};
+}; // wmissing-warning {{missing field 'y' initializer}}
 A a5 = {
   .y = 1, // override-note {{previous}}
   .y = 1 // override-error {{overrides prior initialization}}
-};
+}; // wmissing-warning {{missing field 'x' initializer}}
 B b2 = {.a = 1}; // pedantic-error {{brace elision for designated initializer is a C99 extension}}
+ // wmissing-warning@-1 {{missing field 'y' initializer}}
 B b3 = {.a = 1, 2}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}}
 B b4 = {.a = 1, 2, 3}; // pedantic-error {{mixture of designated and non-designated}} pedantic-note {{first non-designated}} pedantic-error {{brace elision}} expected-error {{excess elements}}
 B b5 = {.a = nullptr}; // expected-error {{cannot initialize}}
+   // wmissing-warning@-1 {{missing field 'y' initializer}}
 struct C { int :0, x, :0, y, :0; };
 C c = {
   .x = 1, // override-note {{previous}}
@@ -67,6 +70,13 @@
   .x = 1, // reorder-error {{declaration order}} override-error {{overrides prior initialization}} override-note {{previous}}
   .x = 1, // override-error {{overrides prior initialization}}
 };
+
+struct Foo { int a, b; };
+
+struct Foo foo0 = { 1 }; // wmissing-warning {{missing field 'b' initializer}}
+struct Foo foo1 = { .a = 1 }; // wmissing-warning {{missing field 'b' initializer}}
+struct Foo foo2 = { .b = 1 }; // wmissing-warning {{missing field 'a' initializer}}
+
 }
 
 namespace base_class {
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2252,6 +2252,8 @@
 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
   bool HasDesignatedInit = false;
 
+  llvm::SmallPtrSet InitializedFields;
+
   while (Index < IList->getNumInits()) {
 Expr *Init = IList->getInit(Index);
 SourceLocation InitLoc = Init->getBeginLoc();
@@ -2267,20 +2269,23 @@
 
   // Handle this designated initializer. Field will be updated to
   // the next field that we'll be initializing.
-  if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
- DeclType, &Field, nullptr, Index,
- StructuredList, StructuredIndex,
- true, TopLevelObject))
+  bool DesignatedInitFailed = CheckDesignatedInitializer(
+  Entity, IList, DIE, 0, DeclType, &Field, nullptr, Index,
+  StructuredList, StructuredIndex, true, TopLevelObject);
+  if (DesignatedInitFailed)
 hadError = true;
-  else if (!VerifyOnly) {
-// Find the field named by the designated initializer.
-RecordDecl::field_iterator F = RD->field_begin();
-while (std::next(F) != Field)
-  ++F;
-QualType ET = SemaRef.Context.getBaseElementType(F->getType());
-if (checkDestructorReference(ET, InitLoc, SemaRef)) {
-  hadError = true;
-  return;
+
+  // Find the field named by the designated initializer.
+  DesignatedInitExpr::Designator *D = DIE->getDesignator(0);
+  if (!VerifyOnly && D->isFieldDesignator()) {
+FieldDecl *F = D->getFieldDecl();
+InitializedFields.insert(F);
+if (!DesignatedInitFailed) {
+  QualType ET = SemaRef.Context.getBaseElementType(F->getType());
+  if (checkDestructorReference(ET, InitLoc, SemaRef)) {
+hadError = true;
+retu

[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-17 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon marked 3 inline comments as done.
Fznamznon added a comment.

> Thank you for working on this! The changes should come with a release note.

Thanks for feedback, I added a release note.

> Can we silence the diagnostic in these cases?

And this is done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

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


[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Tangentially related: Now that we have this `InitializedFields` set, would it 
be easy to add a warning for double-initialization of fields (that would also 
trigger in C)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

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


[PATCH] D158145: [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

2023-08-17 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/unittests/AST/DeclTest.cpp:368
+  ASTContext &Ctx = AST->getASTContext();
+  Ctx.getTranslationUnitDecl()->dump();
+

This dump is not needed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158145

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


[PATCH] D158145: [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

2023-08-17 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/unittests/AST/DeclTest.cpp:368
+  ASTContext &Ctx = AST->getASTContext();
+  Ctx.getTranslationUnitDecl()->dump();
+

balazske wrote:
> This dump is not needed?
Yeah it's for debug only, I'll remove it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158145

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


[clang] d43a3d6 - [CodeGen] Restrict addEmittedDeferredDecl to incremental extensions

2023-08-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-17T11:54:05+02:00
New Revision: d43a3d6346961e639e29b8083b262416889e78ec

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

LOG: [CodeGen] Restrict addEmittedDeferredDecl to incremental extensions

Reemission is only needed in incremental mode. With this early return,
we avoid overhead from addEmittedDeferredDecl in non-incremental mode.

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.h

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index 7301109fb04409..c22dd8486270a0 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -361,6 +361,10 @@ class CodeGenModule : public CodeGenTypeCache {
   llvm::DenseMap EmittedDeferredDecls;
 
   void addEmittedDeferredDecl(GlobalDecl GD) {
+// Reemission is only needed in incremental mode.
+if (!Context.getLangOpts().IncrementalExtensions)
+  return;
+
 // Assume a linkage by default that does not need reemission.
 auto L = llvm::GlobalValue::ExternalLinkage;
 if (llvm::isa(GD.getDecl()))



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


[PATCH] D157379: [CodeGen] Restrict addEmittedDeferredDecl to incremental extensions

2023-08-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd43a3d634696: [CodeGen] Restrict addEmittedDeferredDecl to 
incremental extensions (authored by Hahnfeld).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157379

Files:
  clang/lib/CodeGen/CodeGenModule.h


Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -361,6 +361,10 @@
   llvm::DenseMap EmittedDeferredDecls;
 
   void addEmittedDeferredDecl(GlobalDecl GD) {
+// Reemission is only needed in incremental mode.
+if (!Context.getLangOpts().IncrementalExtensions)
+  return;
+
 // Assume a linkage by default that does not need reemission.
 auto L = llvm::GlobalValue::ExternalLinkage;
 if (llvm::isa(GD.getDecl()))


Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -361,6 +361,10 @@
   llvm::DenseMap EmittedDeferredDecls;
 
   void addEmittedDeferredDecl(GlobalDecl GD) {
+// Reemission is only needed in incremental mode.
+if (!Context.getLangOpts().IncrementalExtensions)
+  return;
+
 // Assume a linkage by default that does not need reemission.
 auto L = llvm::GlobalValue::ExternalLinkage;
 if (llvm::isa(GD.getDecl()))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158055: [clang][AST] Added some missing setter methods

2023-08-17 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

Yes, I have a need for these setters :) but I cannot decide if the LLVM project 
in general or other people could profit from it.

I am working on a C++-to-C transpiler based on clang. Other clang-based tool 
typically modify the intput file based on FileLocation information. In 
contrast, I follow a constructive approach with AST print. The transpiler is 
organized in many small passes that transform the clang AST until at the end I 
can output the C code via AST print. Some notable passes are

- Remove unused AST decls (simplifies AST for non-trivial input)
- Resolve templates (is also useful standalone to remove templates from a C++ 
program)
- Resolve namespaces
- Move nested records
- Convert methods to functions
- etc.

For transforming the AST, I often need to replace Types and regenerate the 
corresponding TypeLoc. I tried for over one year to recreate AST nodes when a 
setter methods that was missing but that caused a lot of work and instabilities 
for maintaining cross references. For that reason, I now insert a new setter 
method when needed and until now surprising less setter methods are missing.

For me it takes 5-10 min per version upgrade to port the changes, so it is not 
a big deal for me if you refuse them. I have some other AST modification in 
place for removing templates information but nothing complex...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158055

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


[PATCH] D153695: [clang][Interp] Fix passing parameters of composite type

2023-08-17 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
tbaeder marked 3 inline comments as done.
Closed by commit rG89361e2b98a9: [clang][Interp] Fix passing parameters of 
composite type (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D153695?vs=534187&id=551066#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153695

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeEmitter.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Context.h
  clang/lib/AST/Interp/EvalEmitter.h

Index: clang/lib/AST/Interp/EvalEmitter.h
===
--- clang/lib/AST/Interp/EvalEmitter.h
+++ clang/lib/AST/Interp/EvalEmitter.h
@@ -75,10 +75,9 @@
   }
 
   /// Parameter indices.
-  llvm::DenseMap Params;
+  llvm::DenseMap Params;
   /// Lambda captures.
-  /// Map from Decl* to [Offset, IsReference] pair.
-  llvm::DenseMap> LambdaCaptures;
+  llvm::DenseMap LambdaCaptures;
   unsigned LambdaThisCapture;
   /// Local descriptors.
   llvm::SmallVector, 2> Descriptors;
Index: clang/lib/AST/Interp/Context.h
===
--- clang/lib/AST/Interp/Context.h
+++ clang/lib/AST/Interp/Context.h
@@ -31,6 +31,11 @@
 class State;
 enum PrimType : unsigned;
 
+struct ParamOffset {
+  unsigned Offset;
+  bool IsPtr;
+};
+
 /// Holds all information required to evaluate constexpr code in a module.
 class Context final {
 public:
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -125,7 +125,7 @@
 // We do the lvalue-to-rvalue conversion manually here, so no need
 // to care about references.
 PrimType ParamType = this->classify(PVD->getType()).value_or(PT_Ptr);
-if (!this->emitGetParam(ParamType, It->second, MD))
+if (!this->emitGetParam(ParamType, It->second.Offset, MD))
   return false;
   }
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1195,7 +1195,7 @@
 llvm::function_ref Indirect) {
   auto It = this->Params.find(PD);
   if (It != this->Params.end()) {
-unsigned Idx = It->second;
+unsigned Idx = It->second.Offset;
 switch (AK) {
 case DerefKind::Read:
   return DiscardResult ? true : this->emitGetParam(T, Idx, LV);
@@ -2153,18 +2153,19 @@
 return this->emitGetPtrGlobal(*GlobalIndex, E);
   } else if (const auto *PVD = dyn_cast(D)) {
 if (auto It = this->Params.find(PVD); It != this->Params.end()) {
-  if (IsReference)
-return this->emitGetParamPtr(It->second, E);
-  return this->emitGetPtrParam(It->second, E);
+  if (IsReference || !It->second.IsPtr)
+return this->emitGetParamPtr(It->second.Offset, E);
+
+  return this->emitGetPtrParam(It->second.Offset, E);
 }
   }
 
   // Handle lambda captures.
   if (auto It = this->LambdaCaptures.find(D);
   It != this->LambdaCaptures.end()) {
-auto [Offset, IsReference] = It->second;
+auto [Offset, IsPtr] = It->second;
 
-if (IsReference)
+if (IsPtr)
   return this->emitGetThisFieldPtr(Offset, E);
 return this->emitGetPtrThisField(Offset, E);
   }
Index: clang/lib/AST/Interp/ByteCodeEmitter.h
===
--- clang/lib/AST/Interp/ByteCodeEmitter.h
+++ clang/lib/AST/Interp/ByteCodeEmitter.h
@@ -69,10 +69,9 @@
   Local createLocal(Descriptor *D);
 
   /// Parameter indices.
-  llvm::DenseMap Params;
+  llvm::DenseMap Params;
   /// Lambda captures.
-  /// Map from Decl* to [Offset, IsReference] pair.
-  llvm::DenseMap> LambdaCaptures;
+  llvm::DenseMap LambdaCaptures;
   unsigned LambdaThisCapture;
   /// Local descriptors.
   llvm::SmallVector, 2> Descriptors;
Index: clang/lib/AST/Interp/ByteCodeEmitter.cpp
===
--- clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -74,13 +74,14 @@
   // Assign descriptors to all parameters.
   // Composite objects are lowered to pointers.
   for (const ParmVarDecl *PD : FuncDecl->parameters()) {
-PrimType Ty = Ctx.classify(PD->getType()).value_or(PT_Ptr);
-Descriptor *Desc = P.createDescriptor(PD, Ty);
-ParamDescriptors.insert({ParamOffset, {Ty, Desc}});
-Params.insert({PD, ParamOffset});
+std::optional T = Ctx.classify(PD->getType());
+PrimType PT = T.value_or(PT_Ptr);
+Descriptor *Desc = P.createDescriptor(PD, PT);
+ParamDescriptors.insert({ParamOffset, {PT, Des

[clang] 89361e2 - [clang][Interp] Fix passing parameters of composite type

2023-08-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-17T12:08:10+02:00
New Revision: 89361e2b98a9ce355bdde0ae02425ecbe5f9c06d

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

LOG: [clang][Interp] Fix passing parameters of composite type

We pass these as pointers, so we need to be careful not to emit pointers
to pointers when we emit visit DeclRefExprs pointing to parameters.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/ByteCodeEmitter.h
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/Context.h
clang/lib/AST/Interp/EvalEmitter.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index c33c9bd37e031c..ba0668ed9c940b 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -74,13 +74,14 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
   // Assign descriptors to all parameters.
   // Composite objects are lowered to pointers.
   for (const ParmVarDecl *PD : FuncDecl->parameters()) {
-PrimType Ty = Ctx.classify(PD->getType()).value_or(PT_Ptr);
-Descriptor *Desc = P.createDescriptor(PD, Ty);
-ParamDescriptors.insert({ParamOffset, {Ty, Desc}});
-Params.insert({PD, ParamOffset});
+std::optional T = Ctx.classify(PD->getType());
+PrimType PT = T.value_or(PT_Ptr);
+Descriptor *Desc = P.createDescriptor(PD, PT);
+ParamDescriptors.insert({ParamOffset, {PT, Desc}});
+Params.insert({PD, {ParamOffset, T != std::nullopt}});
 ParamOffsets.push_back(ParamOffset);
-ParamOffset += align(primSize(Ty));
-ParamTypes.push_back(Ty);
+ParamOffset += align(primSize(PT));
+ParamTypes.push_back(PT);
   }
 
   // Create a handle over the emitted code.

diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.h 
b/clang/lib/AST/Interp/ByteCodeEmitter.h
index 795534696d92ff..c917622a1864fa 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.h
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.h
@@ -69,10 +69,9 @@ class ByteCodeEmitter {
   Local createLocal(Descriptor *D);
 
   /// Parameter indices.
-  llvm::DenseMap Params;
+  llvm::DenseMap Params;
   /// Lambda captures.
-  /// Map from Decl* to [Offset, IsReference] pair.
-  llvm::DenseMap> LambdaCaptures;
+  llvm::DenseMap LambdaCaptures;
   unsigned LambdaThisCapture;
   /// Local descriptors.
   llvm::SmallVector, 2> Descriptors;

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 77d2b1131005d1..f9a7cf7b743ef0 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1195,7 +1195,7 @@ bool ByteCodeExprGen::dereferenceParam(
 llvm::function_ref Indirect) {
   auto It = this->Params.find(PD);
   if (It != this->Params.end()) {
-unsigned Idx = It->second;
+unsigned Idx = It->second.Offset;
 switch (AK) {
 case DerefKind::Read:
   return DiscardResult ? true : this->emitGetParam(T, Idx, LV);
@@ -2153,18 +2153,19 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
 return this->emitGetPtrGlobal(*GlobalIndex, E);
   } else if (const auto *PVD = dyn_cast(D)) {
 if (auto It = this->Params.find(PVD); It != this->Params.end()) {
-  if (IsReference)
-return this->emitGetParamPtr(It->second, E);
-  return this->emitGetPtrParam(It->second, E);
+  if (IsReference || !It->second.IsPtr)
+return this->emitGetParamPtr(It->second.Offset, E);
+
+  return this->emitGetPtrParam(It->second.Offset, E);
 }
   }
 
   // Handle lambda captures.
   if (auto It = this->LambdaCaptures.find(D);
   It != this->LambdaCaptures.end()) {
-auto [Offset, IsReference] = It->second;
+auto [Offset, IsPtr] = It->second;
 
-if (IsReference)
+if (IsPtr)
   return this->emitGetThisFieldPtr(Offset, E);
 return this->emitGetPtrThisField(Offset, E);
   }

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index e54805cd931aef..f048b2c218a4ca 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -125,7 +125,7 @@ bool ByteCodeStmtGen::emitLambdaStaticInvokerBody(
 // We do the lvalue-to-rvalue conversion manually here, so no need
 // to care about references.
 PrimType ParamType = this->classify(PVD->getType()).value_or(PT_Ptr);
-if (!this->emitGetParam(ParamType, It->second, MD))
+if (!this->emitGetParam(ParamType, It->second.Offset, MD))
   return false;
   }
 

diff  --git a/clang/lib/AST/Interp/Context.h b/clang/lib/AST/Interp/Context.h
index 19d480d912116

[PATCH] D158165: [clang][AST] TextNodeDumper learned to output instantiated_from information

2023-08-17 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158165

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-decl.cpp

Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -316,173 +316,173 @@
   template class TT> struct TestTemplateTemplateDefaultType { };
 }
 
-// CHECK:   ClassTemplateDecl 0x{{.+}} <{{.+}}:[[@LINE-40]]:3, line:[[@LINE-34]]:3> line:[[@LINE-40]]:30 TestClassTemplate
-// CHECK-NEXT:  |-TemplateTypeParmDecl 0x{{.+}}  col:21 typename depth 0 index 0 T
-// CHECK-NEXT:  |-CXXRecordDecl 0x{{.+}}  line:[[@LINE-42]]:30 class TestClassTemplate definition
-// CHECK-NEXT:  | |-DefinitionData standard_layout has_user_declared_ctor can_const_default_init
-// CHECK-NEXT:  | | |-DefaultConstructor exists non_trivial user_provided
-// CHECK-NEXT:  | | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveConstructor
-// CHECK-NEXT:  | | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveAssignment
-// CHECK-NEXT:  | | `-Destructor
-// CHECK-NEXT:  | |-CXXRecordDecl 0x{{.+}}  col:30 implicit referenced class TestClassTemplate
-// CHECK-NEXT:  | |-AccessSpecDecl 0x{{.+}}  col:3 public
-// CHECK-NEXT:  | |-CXXConstructorDecl 0x{{.+}}  col:5 TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXDestructorDecl 0x{{.+}}  col:5 ~TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXMethodDecl 0x{{.+}}  col:9 j 'int ()'
-// CHECK-NEXT:  | `-FieldDecl 0x{{.+}}  col:9 i 'int'
-// CHECK-NEXT:  |-ClassTemplateSpecializationDecl 0x{{.+}}  line:[[@LINE-56]]:30 class TestClassTemplate definition
-// CHECK-NEXT:  | |-DefinitionData standard_layout has_user_declared_ctor can_const_default_init
-// CHECK-NEXT:  | | |-DefaultConstructor exists non_trivial user_provided
-// CHECK-NEXT:  | | |-CopyConstructor simple trivial has_const_param implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveConstructor
-// CHECK-NEXT:  | | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveAssignment
-// CHECK-NEXT:  | | `-Destructor non_trivial user_declared
-// CHECK-NEXT:  | |-TemplateArgument type 'testClassTemplateDecl::A'
-// CHECK-NEXT:  | | `-RecordType 0{{.+}} 'testClassTemplateDecl::A'
-// CHECK-NEXT:  | |   `-CXXRecord 0x{{.+}} 'A'
-// CHECK-NEXT:  | |-CXXRecordDecl 0x{{.+}}  col:30 implicit class TestClassTemplate
-// CHECK-NEXT:  | |-AccessSpecDecl 0x{{.+}}  col:3 public
-// CHECK-NEXT:  | |-CXXConstructorDecl 0x{{.+}}  col:5 used TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXDestructorDecl 0x{{.+}}  col:5 used ~TestClassTemplate 'void () noexcept'
-// CHECK-NEXT:  | |-CXXMethodDecl 0x{{.+}}  col:9 j 'int ()'
-// CHECK-NEXT:  | |-FieldDecl 0x{{.+}}  col:9 i 'int'
-// CHECK-NEXT:  | `-CXXConstructorDecl 0x{{.+}}  col:30 implicit constexpr TestClassTemplate 'void (const TestClassTemplate &)' inline default trivial noexcept-unevaluated 0x{{.+}}
-// CHECK-NEXT:  |   `-ParmVarDecl 0x{{.+}}  col:30 'const TestClassTemplate &'
-// CHECK-NEXT:  |-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-// CHECK-NEXT:  |-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-// CHECK-NEXT:  `-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-
-// CHECK:   ClassTemplateSpecializationDecl 0x{{.+}} <{{.+}}:[[@LINE-67]]:3, line:[[@LINE-65]]:3> line:[[@LINE-67]]:20 class TestClassTemplate definition
-// CHECK-NEXT:  |-DefinitionData pass_in_registers standard_layout trivially_copyable trivial literal
-// CHECK-NEXT:  | |-DefaultConstructor exists trivial needs_implicit
-// CHECK-NEXT:  | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | |-MoveConstructor exists simple trivial needs_implicit
-// CHECK-NEXT:  | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | |-MoveAssignment exists simple trivial needs_implicit
-// CHECK-NEXT:  | `-Destructor simple irrelevant trivial needs_implicit
-// CHECK-NEXT:  |-TemplateArgument type 'testClassTemplateDecl::B'
-// CHECK-NEXT:  | `-RecordType 0{{.+}} 'testClassTemplateDecl::B'
-// CHECK-NEXT:  |   `-CXXRecord 0x{{.+}} 'B'
-// CHECK-NEXT:  |-CXXRecordDecl 0x{{.+}}  col:20 implicit class TestClassTemplate
-// CHECK-NEXT:  `-FieldDecl 0x{{.+}}  col:9 j 'int'
-
-// CHECK:   ClassTemplateSpecializationDecl 0x{{.+}} <{{.+}}:{{.*}}:3, col:44> col:25 class TestClassTemplate definition
-// CHECK-NEXT:  |-DefinitionData standard_layout has_user_declared_ctor can_const_default_init
-// CHECK-NEXT:  | |-DefaultC

[PATCH] D156821: [CodeGen] [ubsan] Respect integer overflow handling in abs builtin

2023-08-17 Thread Artem Labazov via Phabricator via cfe-commits
artem added a comment.

Ping


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

https://reviews.llvm.org/D156821

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


[clang] cf10061 - [clang][Interp] Fully serialize Floating values to bytes

2023-08-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-17T12:41:39+02:00
New Revision: cf10061da75e41286c28690e45eee6ee70dad766

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

LOG: [clang][Interp] Fully serialize Floating values to bytes

The Floating class wraps a APFloat, which might heap allocate memory to
represent large floating values. When writing those to bytecode, we
would free() the heap allocation after writing, when destroying the
actual APFloat we wrote.

Fix this by seralizing a Floating as Semantics + APInt.

This will be neccessary in more cases later, when we support
arbitrary-precision integers or _BitInt.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/Disasm.cpp
clang/lib/AST/Interp/Floating.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Source.h
clang/test/AST/Interp/floats.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index ba0668ed9c940b..9f0a2dfb47c9e7 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -207,6 +207,25 @@ static void emit(Program &P, std::vector &Code, 
const T &Val,
   }
 }
 
+template <>
+void emit(Program &P, std::vector &Code, const Floating &Val,
+  bool &Success) {
+  size_t Size = Val.bytesToSerialize();
+
+  if (Code.size() + Size > std::numeric_limits::max()) {
+Success = false;
+return;
+  }
+
+  // Access must be aligned!
+  size_t ValPos = align(Code.size());
+  Size = align(Size);
+  assert(aligned(ValPos + Size));
+  Code.resize(ValPos + Size);
+
+  Val.serialize(Code.data() + ValPos);
+}
+
 template 
 bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &... Args, const SourceInfo 
&SI) {
   bool Success = true;

diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 35ed5d12869719..d276df8f292622 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -31,6 +31,12 @@ template  inline T ReadArg(Program &P, CodePtr 
&OpPC) {
   }
 }
 
+template <> inline Floating ReadArg(Program &P, CodePtr &OpPC) {
+  Floating F = Floating::deserialize(*OpPC);
+  OpPC += align(F.bytesToSerialize());
+  return F;
+}
+
 LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }
 
 LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {

diff  --git a/clang/lib/AST/Interp/Floating.h b/clang/lib/AST/Interp/Floating.h
index b0fae4562b7830..9a8fd34ec93489 100644
--- a/clang/lib/AST/Interp/Floating.h
+++ b/clang/lib/AST/Interp/Floating.h
@@ -119,6 +119,36 @@ class Floating final {
 return Status;
   }
 
+  static Floating bitcastFromMemory(const std::byte *Buff,
+const llvm::fltSemantics &Sem) {
+size_t Size = APFloat::semanticsSizeInBits(Sem);
+llvm::APInt API(Size, true);
+llvm::LoadIntFromMemory(API, (const uint8_t *)Buff, Size / 8);
+
+return Floating(APFloat(Sem, API));
+  }
+
+  // === Serialization support ===
+  size_t bytesToSerialize() const {
+return sizeof(llvm::fltSemantics *) +
+   (APFloat::semanticsSizeInBits(F.getSemantics()) / 8);
+  }
+
+  void serialize(std::byte *Buff) const {
+// Semantics followed by an APInt.
+*reinterpret_cast(Buff) = &F.getSemantics();
+
+llvm::APInt API = F.bitcastToAPInt();
+llvm::StoreIntToMemory(API, (uint8_t *)(Buff + sizeof(void *)),
+   bitWidth() / 8);
+  }
+
+  static Floating deserialize(const std::byte *Buff) {
+const llvm::fltSemantics *Sem;
+std::memcpy((void *)&Sem, Buff, sizeof(void *));
+return bitcastFromMemory(Buff + sizeof(void *), *Sem);
+  }
+
   static Floating abs(const Floating &F) {
 APFloat V = F.F;
 if (V.isNegative())

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 560daca1de6eda..aebab9023a3580 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1806,6 +1806,12 @@ template  inline T ReadArg(InterpState &S, 
CodePtr &OpPC) {
   }
 }
 
+template <> inline Floating ReadArg(InterpState &S, CodePtr &OpPC) {
+  Floating F = Floating::deserialize(*OpPC);
+  OpPC += align(F.bytesToSerialize());
+  return F;
+}
+
 } // namespace interp
 } // namespace clang
 

diff  --git a/clang/lib/AST/Interp/Source.h b/clang/lib/AST/Interp/Source.h
index 6ffc7763587747..a93b103b3f9012 100644
--- a/clang/lib/AST/Interp/Source.h
+++ b/clang/lib/AST/Interp/Source.h
@@ -43,6 +43,7 @@ class CodePtr final {
   }
 
   bool operator!=(const CodePtr &RHS) const { return Ptr != RHS.Ptr; }
+  const std::byte *operator*() const { return Ptr; }
 
   operator bool() const { return Ptr; }
 

diff  --git a/clang

[PATCH] D155165: [clang][Interp] Fully serialize Floatings to bytes

2023-08-17 Thread Timm Bäder 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 rGcf10061da75e: [clang][Interp] Fully serialize Floating 
values to bytes (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D155165?vs=545353&id=551077#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155165

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/Disasm.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Source.h
  clang/test/AST/Interp/floats.cpp

Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -144,6 +144,22 @@
 
 namespace LongDouble {
   constexpr long double ld = 3.1425926539;
+
+  constexpr long double f() {
+const long double L = __LDBL_MAX__;
+
+return L;
+  };
+  static_assert(f() == __LDBL_MAX__);
+
+#ifdef __FLOAT128__
+  constexpr __float128 f128() {
+const __float128 L = __LDBL_MAX__;
+
+return L;
+  };
+  static_assert(f128() == __LDBL_MAX__);
+#endif
 }
 
 namespace Compare {
Index: clang/lib/AST/Interp/Source.h
===
--- clang/lib/AST/Interp/Source.h
+++ clang/lib/AST/Interp/Source.h
@@ -43,6 +43,7 @@
   }
 
   bool operator!=(const CodePtr &RHS) const { return Ptr != RHS.Ptr; }
+  const std::byte *operator*() const { return Ptr; }
 
   operator bool() const { return Ptr; }
 
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1806,6 +1806,12 @@
   }
 }
 
+template <> inline Floating ReadArg(InterpState &S, CodePtr &OpPC) {
+  Floating F = Floating::deserialize(*OpPC);
+  OpPC += align(F.bytesToSerialize());
+  return F;
+}
+
 } // namespace interp
 } // namespace clang
 
Index: clang/lib/AST/Interp/Floating.h
===
--- clang/lib/AST/Interp/Floating.h
+++ clang/lib/AST/Interp/Floating.h
@@ -119,6 +119,36 @@
 return Status;
   }
 
+  static Floating bitcastFromMemory(const std::byte *Buff,
+const llvm::fltSemantics &Sem) {
+size_t Size = APFloat::semanticsSizeInBits(Sem);
+llvm::APInt API(Size, true);
+llvm::LoadIntFromMemory(API, (const uint8_t *)Buff, Size / 8);
+
+return Floating(APFloat(Sem, API));
+  }
+
+  // === Serialization support ===
+  size_t bytesToSerialize() const {
+return sizeof(llvm::fltSemantics *) +
+   (APFloat::semanticsSizeInBits(F.getSemantics()) / 8);
+  }
+
+  void serialize(std::byte *Buff) const {
+// Semantics followed by an APInt.
+*reinterpret_cast(Buff) = &F.getSemantics();
+
+llvm::APInt API = F.bitcastToAPInt();
+llvm::StoreIntToMemory(API, (uint8_t *)(Buff + sizeof(void *)),
+   bitWidth() / 8);
+  }
+
+  static Floating deserialize(const std::byte *Buff) {
+const llvm::fltSemantics *Sem;
+std::memcpy((void *)&Sem, Buff, sizeof(void *));
+return bitcastFromMemory(Buff + sizeof(void *), *Sem);
+  }
+
   static Floating abs(const Floating &F) {
 APFloat V = F.F;
 if (V.isNegative())
Index: clang/lib/AST/Interp/Disasm.cpp
===
--- clang/lib/AST/Interp/Disasm.cpp
+++ clang/lib/AST/Interp/Disasm.cpp
@@ -31,6 +31,12 @@
   }
 }
 
+template <> inline Floating ReadArg(Program &P, CodePtr &OpPC) {
+  Floating F = Floating::deserialize(*OpPC);
+  OpPC += align(F.bytesToSerialize());
+  return F;
+}
+
 LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }
 
 LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
Index: clang/lib/AST/Interp/ByteCodeEmitter.cpp
===
--- clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -207,6 +207,25 @@
   }
 }
 
+template <>
+void emit(Program &P, std::vector &Code, const Floating &Val,
+  bool &Success) {
+  size_t Size = Val.bytesToSerialize();
+
+  if (Code.size() + Size > std::numeric_limits::max()) {
+Success = false;
+return;
+  }
+
+  // Access must be aligned!
+  size_t ValPos = align(Code.size());
+  Size = align(Size);
+  assert(aligned(ValPos + Size));
+  Code.resize(ValPos + Size);
+
+  Val.serialize(Code.data() + ValPos);
+}
+
 template 
 bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &... Args, const SourceInfo &SI) {
   bool Success = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158145: [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

2023-08-17 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 551078.
danix800 added a comment.

Remove debug code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158145

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclBase.h
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -353,6 +353,32 @@
   EXPECT_TRUE(getFooValue->isInlined());
 }
 
+TEST(Decl, FunctionDeclBitsShouldNotOverlapWithCXXConstructorDeclBits) {
+  llvm::Annotations Code(R"(
+struct A {
+  A() : m() {}
+  int m;
+};
+
+A f() { return A(); }
+)");
+
+  auto AST = tooling::buildASTFromCodeWithArgs(Code.code(), {"-std=c++14"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto HasCtorInit =
+  hasAnyConstructorInitializer(cxxCtorInitializer(isMemberInitializer()));
+  auto ImpMoveCtor =
+  cxxConstructorDecl(isMoveConstructor(), isImplicit(), HasCtorInit)
+  .bind("MoveCtor");
+
+  auto *ToImpMoveCtor =
+  selectFirst("MoveCtor", match(ImpMoveCtor, Ctx));
+
+  EXPECT_TRUE(ToImpMoveCtor->getNumCtorInitializers() == 1);
+  EXPECT_FALSE(ToImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
+}
+
 TEST(Decl, NoProtoFunctionDeclAttributes) {
   llvm::Annotations Code(R"(
 void f();
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -7832,6 +7832,47 @@
   CheckAST(ToTU, ToC);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportFunctionDeclBitShouldNotOverwriteCtorDeclBits) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"s(
+struct A {
+  A() : m() {}
+  int m;
+};
+
+A foo() { A a; return a; }
+A bar() { return {}; }
+  )s",
+  Lang_CXX17,
+  R"s(
+struct A {
+  A() : m() {}
+  int m;
+};
+A baz() { return {}; }
+  )s",
+  Lang_CXX17, "A");
+
+  auto HasCtorInit =
+  hasAnyConstructorInitializer(cxxCtorInitializer(isMemberInitializer()));
+  auto ImpMoveCtor =
+  cxxConstructorDecl(isMoveConstructor(), isImplicit(), HasCtorInit);
+
+  auto *FromImpMoveCtor = FirstDeclMatcher().match(
+  From, ImpMoveCtor);
+  auto *ToImpMoveCtor = FirstDeclMatcher().match(
+  To, ImpMoveCtor);
+
+  EXPECT_TRUE(FromImpMoveCtor->getNumCtorInitializers() == 1);
+  EXPECT_FALSE(FromImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
+
+  EXPECT_TRUE(ToImpMoveCtor->getNumCtorInitializers() == 1);
+  EXPECT_FALSE(ToImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
+  EXPECT_TRUE(*ToImpMoveCtor->init_begin());
+}
+
 AST_MATCHER_P(UsingShadowDecl, hasIntroducerDecl, internal::Matcher,
   InnerMatcher) {
   return InnerMatcher.matches(*Node.getIntroducer(), Finder, Builder);
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -580,7 +580,7 @@
 }
 
 void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
-  static_assert(DeclContext::NumFunctionDeclBits == 30,
+  static_assert(DeclContext::NumFunctionDeclBits == 31,
 "You need to update the serializer after you change the "
 "FunctionDeclBits");
 
@@ -1495,7 +1495,7 @@
 }
 
 void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
-  static_assert(DeclContext::NumCXXConstructorDeclBits == 21,
+  static_assert(DeclContext::NumCXXConstructorDeclBits == 20,
 "You need to update the serializer after you change the "
 "CXXConstructorDeclBits");
 
Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1702,7 +1702,7 @@
   };
 
   /// Number of non-inherited bits in FunctionDeclBitfields.
-  enum { NumFunctionDeclBits = 30 };
+  enum { NumFunctionDeclBits = 31 };
 
   /// Stores the bits used by CXXConstructorDecl. If modified
   /// NumCXXConstructorDeclBits and the accessor
@@ -1714,12 +1714,12 @@
 /// For the bits in FunctionDeclBitfields.
 uint64_t : NumFunctionDeclBits;
 
-/// 21 bits to fit in the remaining available space.
+/// 20 bits to fit in the remaining available space.
 /// Note that this makes CXXConstructorDeclBitfields take
 /// exactly 64 bits and thus the width of NumCtorInitializers
 /// will need to be shrunk if some bit is added to NumDeclContextBitfields,
 /// NumFunctionDeclBitfields or 

[PATCH] D157547: Arm64EC entry/exit thunks, consolidated.

2023-08-17 Thread Jacek Caban via Phabricator via cfe-commits
jacek added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64MCInstLower.cpp:51-54
+// For ARM64EC, symbol lookup in the MSVC linker has limited awareness
+// of ARM64EC mangling ("#"/"$$h"). So object files need to refer to both
+// the mangled and unmangled names of ARM64EC symbols, even if they aren't
+// actually used by any relocations. Emit the necessary references here.

efriedma wrote:
> jacek wrote:
> > I think that mangled weak symbol should link to another kind exit thunk, 
> > not to unmangled symbol directly.
> > 
> > When an extern code symbol is resolved by an unmangled name, it means that 
> > we have ARM64EC->X64 call and we need to use an exit thunk. Linker doesn't 
> > need a special logic for that: on MSVC it seems to be achieved by pointing 
> > the antidependency symbol to yet another exit thunk. That other exit thunk 
> > loads the target exit thunk and X64 (unmangled) symbol into x10, x11 and 
> > uses __os_arm64x_dispatch_icall to call emulator. I guess we may worry 
> > about that later, but in that case maybe it's better not to emit mangled 
> > antidependency symbol at all for now?
> From what I recall, I wrote the code here primarily to deal with issues 
> trying to take the address of a function; even if the function is defined in 
> arm64ec code, the address is the unmangled symbol.  So there's some weirdness 
> there involving symbol lookup even before there's any actual x64 code 
> involved.
> 
> If you have a better idea of how external symbol references are supposed to 
> be emitted, I'd appreciate a brief writeup, since all the information I have 
> comes from trying to read dumpbin dumps of MSVC output.
Yes, when EC code takes an address of a function, it needs to use unmangled 
symbols, because mangled symbols may point to a thunk (in cases when the 
implementation is in X64 or __declspec(hybrid_patchable) is used) and we still 
want an address of the real implementation. Here is an example how MSVC sets it 
up:

$ cat test.c
extern int otherfunc(void);
int myfunc(void) { return otherfunc(); }
$ llvm-readobj --symbols test.obj
...
  Symbol {
Name: #otherfunc$exit_thunk
Value: 0
Section: .wowthk$aa (4)
BaseType: Null (0x0)
ComplexType: Function (0x2)
StorageClass: External (0x2)
AuxSymbolCount: 0
  }
...
  Symbol {
Name: #otherfunc
Value: 0
Section: IMAGE_SYM_UNDEFINED (0)
BaseType: Null (0x0)
ComplexType: Function (0x2)
StorageClass: WeakExternal (0x69)
AuxSymbolCount: 1
AuxWeakExternal {
  Linked: #otherfunc$exit_thunk (14)
  Search: AntiDependency (0x4)
}
  }
  Symbol {
Name: #myfunc
Value: 0
Section: .text$mn (3)
BaseType: Null (0x0)
ComplexType: Function (0x2)
StorageClass: External (0x2)
AuxSymbolCount: 0
  }
  Symbol {
Name: otherfunc
Value: 0
Section: IMAGE_SYM_UNDEFINED (0)
BaseType: Null (0x0)
ComplexType: Function (0x2)
StorageClass: WeakExternal (0x69)
AuxSymbolCount: 1
AuxWeakExternal {
  Linked: #otherfunc (19)
  Search: AntiDependency (0x4)
}
  }
  Symbol {
Name: myfunc
Value: 0
Section: IMAGE_SYM_UNDEFINED (0)
BaseType: Null (0x0)
ComplexType: Function (0x2)
StorageClass: WeakExternal (0x69)
AuxSymbolCount: 1
AuxWeakExternal {
  Linked: #myfunc (21)
  Search: AntiDependency (0x4)
}
  }

In this example myfunc links to #myfunc (and similarly otherfunc->#otherfunc). 
That's enough because even if we pass a pointer of #myfunc to actual X64 code 
which will try to call this address, emulator will have a chance to figure it 
out and use entry thunk as needed.

However, #otherfunc points to #otherfunc$exit_thunk (which then references 
otherfunc and $iexit_thunk$cdecl$i8$v in its implementation). If otherfunc is 
implemented in ARM64EC, #otherfunc symbol will be replaced by the object file 
implementing it. If it will not be replaced, it means that symbol is resolved 
to X64 implementation and the linked thunk will be used to call it.

My information are based on experimentation with MSVC as well, so those are 
only my best guesses. I mostly experimented with it in a context of linker 
support and I have those aspects of linker working in my tree. I will work on 
more comprehensive description of those things.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157547

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


[clang] 1740cf3 - [clang][Interp][NFC] Use std::byte to refer to Block data

2023-08-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-17T13:04:05+02:00
New Revision: 1740cf34533756befd06e878340b69ca1885041c

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

LOG: [clang][Interp][NFC] Use std::byte to refer to Block data

Added: 


Modified: 
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/Descriptor.h
clang/lib/AST/Interp/InterpBlock.h
clang/lib/AST/Interp/Program.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index ccd2a993e9f7d3..521ad16e367195 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -18,24 +18,26 @@ using namespace clang;
 using namespace clang::interp;
 
 template 
-static void ctorTy(Block *, char *Ptr, bool, bool, bool, const Descriptor *) {
+static void ctorTy(Block *, std::byte *Ptr, bool, bool, bool,
+   const Descriptor *) {
   new (Ptr) T();
 }
 
 template 
-static void dtorTy(Block *, char *Ptr, const Descriptor *) {
+static void dtorTy(Block *, std::byte *Ptr, const Descriptor *) {
   reinterpret_cast(Ptr)->~T();
 }
 
 template 
-static void moveTy(Block *, const char *Src, char *Dst, const Descriptor *) {
+static void moveTy(Block *, const std::byte *Src, std::byte *Dst,
+   const Descriptor *) {
   const auto *SrcPtr = reinterpret_cast(Src);
   auto *DstPtr = reinterpret_cast(Dst);
   new (DstPtr) T(std::move(*SrcPtr));
 }
 
 template 
-static void ctorArrayTy(Block *, char *Ptr, bool, bool, bool,
+static void ctorArrayTy(Block *, std::byte *Ptr, bool, bool, bool,
 const Descriptor *D) {
   for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) {
 new (&reinterpret_cast(Ptr)[I]) T();
@@ -43,7 +45,7 @@ static void ctorArrayTy(Block *, char *Ptr, bool, bool, bool,
 }
 
 template 
-static void dtorArrayTy(Block *, char *Ptr, const Descriptor *D) {
+static void dtorArrayTy(Block *, std::byte *Ptr, const Descriptor *D) {
   InitMap *IM = *reinterpret_cast(Ptr);
   if (IM != (InitMap *)-1)
 free(IM);
@@ -55,7 +57,7 @@ static void dtorArrayTy(Block *, char *Ptr, const Descriptor 
*D) {
 }
 
 template 
-static void moveArrayTy(Block *, const char *Src, char *Dst,
+static void moveArrayTy(Block *, const std::byte *Src, std::byte *Dst,
 const Descriptor *D) {
   for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) {
 const auto *SrcPtr = &reinterpret_cast(Src)[I];
@@ -64,8 +66,8 @@ static void moveArrayTy(Block *, const char *Src, char *Dst,
   }
 }
 
-static void ctorArrayDesc(Block *B, char *Ptr, bool IsConst, bool IsMutable,
-  bool IsActive, const Descriptor *D) {
+static void ctorArrayDesc(Block *B, std::byte *Ptr, bool IsConst,
+  bool IsMutable, bool IsActive, const Descriptor *D) {
   const unsigned NumElems = D->getNumElems();
   const unsigned ElemSize =
   D->ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
@@ -74,7 +76,7 @@ static void ctorArrayDesc(Block *B, char *Ptr, bool IsConst, 
bool IsMutable,
   for (unsigned I = 0; I < NumElems; ++I, ElemOffset += ElemSize) {
 auto *ElemPtr = Ptr + ElemOffset;
 auto *Desc = reinterpret_cast(ElemPtr);
-auto *ElemLoc = reinterpret_cast(Desc + 1);
+auto *ElemLoc = reinterpret_cast(Desc + 1);
 auto *SD = D->ElemDesc;
 
 Desc->Offset = ElemOffset + sizeof(InlineDescriptor);
@@ -90,7 +92,7 @@ static void ctorArrayDesc(Block *B, char *Ptr, bool IsConst, 
bool IsMutable,
   }
 }
 
-static void dtorArrayDesc(Block *B, char *Ptr, const Descriptor *D) {
+static void dtorArrayDesc(Block *B, std::byte *Ptr, const Descriptor *D) {
   const unsigned NumElems = D->getNumElems();
   const unsigned ElemSize =
   D->ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
@@ -99,13 +101,13 @@ static void dtorArrayDesc(Block *B, char *Ptr, const 
Descriptor *D) {
   for (unsigned I = 0; I < NumElems; ++I, ElemOffset += ElemSize) {
 auto *ElemPtr = Ptr + ElemOffset;
 auto *Desc = reinterpret_cast(ElemPtr);
-auto *ElemLoc = reinterpret_cast(Desc + 1);
+auto *ElemLoc = reinterpret_cast(Desc + 1);
 if (auto Fn = D->ElemDesc->DtorFn)
   Fn(B, ElemLoc, D->ElemDesc);
   }
 }
 
-static void moveArrayDesc(Block *B, const char *Src, char *Dst,
+static void moveArrayDesc(Block *B, const std::byte *Src, std::byte *Dst,
   const Descriptor *D) {
   const unsigned NumElems = D->getNumElems();
   const unsigned ElemSize =
@@ -117,9 +119,9 @@ static void moveArrayDesc(Block *B, const char *Src, char 
*Dst,
 auto *DstPtr = Dst + ElemOffset;
 
 const auto *SrcDesc = reinterpret_cast(SrcPtr);
-const auto *SrcElemLoc = reinterpret_cast(SrcDesc + 1);
+const auto *SrcElemLoc = reinterpret_cas

[clang] d425720 - [clang][Interp] Implement __builtin_strlen

2023-08-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-08-17T13:10:46+02:00
New Revision: d425720aed48fd2c058a126ac961576d48c9732b

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

LOG: [clang][Interp] Implement __builtin_strlen

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

Added: 


Modified: 
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 5702859996dca2..b4e75593dc4a5f 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -56,6 +56,41 @@ static bool retInt(InterpState &S, CodePtr OpPC, APValue 
&Result) {
   llvm_unreachable("Int isn't 16 or 32 bit?");
 }
 
+static void pushSizeT(InterpState &S, uint64_t Val) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned SizeTWidth = TI.getTypeWidth(TI.getSizeType());
+
+  switch (SizeTWidth) {
+  case 64:
+S.Stk.push>(Integral<64, false>::from(Val));
+break;
+  case 32:
+S.Stk.push>(Integral<32, false>::from(Val));
+break;
+  case 16:
+S.Stk.push>(Integral<16, false>::from(Val));
+break;
+  default:
+llvm_unreachable("We don't handle this size_t size.");
+  }
+}
+
+static bool retSizeT(InterpState &S, CodePtr OpPC, APValue &Result) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned SizeTWidth = TI.getTypeWidth(TI.getSizeType());
+
+  switch (SizeTWidth) {
+  case 64:
+return Ret(S, OpPC, Result);
+  case 32:
+return Ret(S, OpPC, Result);
+  case 16:
+return Ret(S, OpPC, Result);
+  }
+
+  llvm_unreachable("size_t isn't 64 or 32 bit?");
+}
+
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame) {
   const Pointer &A = getParam(Frame, 0);
@@ -95,6 +130,34 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
+static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC,
+   const InterpFrame *Frame) {
+  const Pointer &StrPtr = getParam(Frame, 0);
+
+  if (!CheckArray(S, OpPC, StrPtr))
+return false;
+
+  if (!CheckLive(S, OpPC, StrPtr, AK_Read))
+return false;
+
+  assert(StrPtr.getFieldDesc()->isPrimitiveArray());
+
+  size_t Len = 0;
+  for (size_t I = StrPtr.getIndex();; ++I, ++Len) {
+const Pointer &ElemPtr = StrPtr.atIndex(I);
+
+if (!CheckRange(S, OpPC, ElemPtr, AK_Read))
+  return false;
+
+uint8_t Val = ElemPtr.deref();
+if (Val == 0)
+  break;
+  }
+
+  pushSizeT(S, Len);
+  return true;
+}
+
 static bool interp__builtin_nan(InterpState &S, CodePtr OpPC,
 const InterpFrame *Frame, const Function *F,
 bool Signaling) {
@@ -338,6 +401,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
 if (interp__builtin_strcmp(S, OpPC, Frame))
   return retInt(S, OpPC, Dummy);
 break;
+  case Builtin::BI__builtin_strlen:
+if (interp__builtin_strlen(S, OpPC, Frame))
+  return retSizeT(S, OpPC, Dummy);
+break;
   case Builtin::BI__builtin_nan:
   case Builtin::BI__builtin_nanf:
   case Builtin::BI__builtin_nanl:

diff  --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index 3fd04759e67996..55ebab1122d58e 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -1,9 +1,11 @@
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
-// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
-// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter %s 
-verify
-// RUN: %clang_cc1 -std=c++20 -verify=ref %s -Wno-constant-evaluated
-// RUN: %clang_cc1 -triple avr -std=c++20 
-fexperimental-new-constant-interpreter %s -verify
-// RUN: %clang_cc1 -triple avr -std=c++20 -verify=ref %s 
-Wno-constant-evaluated
+// RUN: %clang_cc1 -Wno-string-plus-int 
-fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -Wno-string-plus-int 
-fexperimental-new-constant-interpreter -triple i686 %s -verify
+// RUN: %clang_cc1 -Wno-string-plus-int -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int 
-fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int 
-fexperimental-new-constant-interpreter -triple i686 %s -verify
+// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -verify=ref %s 
-Wno-constant-evaluated
+// RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int 
-fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int -verify=ref %s 
-Wno

[PATCH] D156042: [clang][Interp] Implement __builtin_strlen

2023-08-17 Thread Timm Bäder 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 rGd425720aed48: [clang][Interp] Implement __builtin_strlen 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D156042?vs=543414&id=551084#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156042

Files:
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/AST/Interp/builtin-functions.cpp

Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -1,9 +1,11 @@
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
-// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
-// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter %s -verify
-// RUN: %clang_cc1 -std=c++20 -verify=ref %s -Wno-constant-evaluated
-// RUN: %clang_cc1 -triple avr -std=c++20 -fexperimental-new-constant-interpreter %s -verify
-// RUN: %clang_cc1 -triple avr -std=c++20 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -Wno-string-plus-int -fexperimental-new-constant-interpreter -triple i686 %s -verify
+// RUN: %clang_cc1 -Wno-string-plus-int -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter -triple i686 %s -verify
+// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int -verify=ref %s -Wno-constant-evaluated
 
 
 namespace strcmp {
@@ -40,6 +42,70 @@
 // ref-note {{dereferenced one-past-the-end}}
 }
 
+/// Copied from constant-expression-cxx11.cpp
+namespace strlen {
+constexpr const char *a = "foo\0quux";
+  constexpr char b[] = "foo\0quux";
+  constexpr int f() { return 'u'; }
+  constexpr char c[] = { 'f', 'o', 'o', 0, 'q', f(), 'u', 'x', 0 };
+
+  static_assert(__builtin_strlen("foo") == 3, "");
+  static_assert(__builtin_strlen("foo\0quux") == 3, "");
+  static_assert(__builtin_strlen("foo\0quux" + 4) == 4, "");
+
+  constexpr bool check(const char *p) {
+return __builtin_strlen(p) == 3 &&
+   __builtin_strlen(p + 1) == 2 &&
+   __builtin_strlen(p + 2) == 1 &&
+   __builtin_strlen(p + 3) == 0 &&
+   __builtin_strlen(p + 4) == 4 &&
+   __builtin_strlen(p + 5) == 3 &&
+   __builtin_strlen(p + 6) == 2 &&
+   __builtin_strlen(p + 7) == 1 &&
+   __builtin_strlen(p + 8) == 0;
+  }
+
+  static_assert(check(a), "");
+  static_assert(check(b), "");
+  static_assert(check(c), "");
+
+  constexpr int over1 = __builtin_strlen(a + 9); // expected-error {{constant expression}} \
+ // expected-note {{one-past-the-end}} \
+ // expected-note {{in call to}} \
+ // ref-error {{constant expression}} \
+ // ref-note {{one-past-the-end}}
+  constexpr int over2 = __builtin_strlen(b + 9); // expected-error {{constant expression}} \
+ // expected-note {{one-past-the-end}} \
+ // expected-note {{in call to}} \
+ // ref-error {{constant expression}} \
+ // ref-note {{one-past-the-end}}
+  constexpr int over3 = __builtin_strlen(c + 9); // expected-error {{constant expression}} \
+ // expected-note {{one-past-the-end}} \
+ // expected-note {{in call to}} \
+ // ref-error {{constant expression}} \
+ // ref-note {{one-past-the-end}}
+
+  constexpr int under1 = __builtin_strlen(a - 1); // expected-error {{constant expression}} \
+  // expected-note {{cannot refer to element -1}} \
+  // ref-error {{constant expression}} \
+  // ref-note {{cannot refer to element -1}}
+  constexpr int under2 = __builtin_strlen(b - 1); // expected-error {{constant expression}} \
+  

[clang] 7b8f5f7 - No longer hang on typeof of a function type

2023-08-17 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-08-17T07:15:30-04:00
New Revision: 7b8f5f7df71c48b281163e88054c84c06364023d

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

LOG: No longer hang on typeof of a function type

We were calling `isFunctionProtoType()` on a `ParsedType` rather than
creating a valid semantic type first and calling the function on that.
The call to `isFunctionProtoType()` would eventually call
`getUnqualifiedDesugaredType()`, which loops indefinitely until we get
a desugared type and a `ParsedType` will never finish desugaring.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/C/C2x/n2927.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02b897bcd0a68e..064b4556f354a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -144,7 +144,10 @@ Bug Fixes in This Version
   module may end up with members associated with the wrong declaration of the
   class, which can result in miscompiles in some cases.
 - Fix crash on use of a variadic overloaded operator.
-  (`#42535 `_)
+  (`#42535 _`)
+- Fix a hang on valid C code passing a function type as an argument to
+  ``typeof`` to form a function declaration.
+  (`#64713 _`)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3c2c7575ed9980..8e5920b8babeb2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9235,7 +9235,8 @@ static FunctionDecl *CreateNewFunctionDecl(Sema &SemaRef, 
Declarator &D,
 bool HasPrototype =
 (D.isFunctionDeclarator() && D.getFunctionTypeInfo().hasPrototype) ||
 (D.getDeclSpec().isTypeRep() &&
- D.getDeclSpec().getRepAsType().get()->isFunctionProtoType()) ||
+ SemaRef.GetTypeFromParser(D.getDeclSpec().getRepAsType(), nullptr)
+ ->isFunctionProtoType()) ||
 (!R->getAsAdjusted() && R->isFunctionProtoType());
 assert(
 (HasPrototype || !SemaRef.getLangOpts().requiresStrictPrototypes()) &&

diff  --git a/clang/test/C/C2x/n2927.c b/clang/test/C/C2x/n2927.c
index 0ece6da88c5c6a..57a77f841025cd 100644
--- a/clang/test/C/C2x/n2927.c
+++ b/clang/test/C/C2x/n2927.c
@@ -90,3 +90,7 @@ extern typeof(D) C;// C has type "double[2]"
 typeof(D) D = { 5, 8.9, 0.1, 99 }; // D is now completed to "double[4]"
 extern double E[4];
 extern typeof(D) E;// E has type "double[4]" from D’s 
completed type
+
+// GH64713 -- this used to trigger an infinite loop when creating the function
+// declaration for F from the function designator specified by typeof.
+typeof(int(int)) F;// F has type "int(int)"



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


[PATCH] D157879: [clang] Report missing designated initializers in C++

2023-08-17 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

In D157879#4594790 , @tbaeder wrote:

> Tangentially related: Now that we have this `InitializedFields` set, would it 
> be easy to add a warning for double-initialization of fields (that would also 
> trigger in C)?

Isn't a warning like this already in place - https://godbolt.org/z/E1dGsY3ze ? 
Or you meant something else?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157879

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


[PATCH] D152132: [clang][Interp] Fix lifetime diagnostics for dead records

2023-08-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Interp.cpp:241
 bool CheckMutable(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
-  assert(Ptr.isLive() && "Pointer is not live");
   if (!Ptr.isMutable()) {

aaron.ballman wrote:
> I understand that we were hitting this assertion, but why is removing the 
> assertion the correct approach? I thought it made sense to check for pointer 
> liveness here.
I re-checked and I think I removed this only for testing and it should stay in. 
The test succeeds like this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152132

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


[PATCH] D152132: [clang][Interp] Fix lifetime diagnostics for dead records

2023-08-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 551087.

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

https://reviews.llvm.org/D152132

Files:
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/InterpBlock.h
  clang/lib/AST/Interp/InterpState.cpp
  clang/test/AST/Interp/lifetimes.cpp


Index: clang/test/AST/Interp/lifetimes.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/lifetimes.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+struct Foo {
+  int a;
+};
+
+constexpr int dead1() { // expected-error {{never produces a constant 
expression}}
+
+  Foo *F2 = nullptr;
+  {
+Foo F{12}; // expected-note 2{{declared here}}
+F2 = &F;
+  } // Ends lifetime of F.
+
+  return F2->a; // expected-note 2{{read of variable whose lifetime has 
ended}} \
+// ref-note {{read of object outside its lifetime is not 
allowed in a constant expression}}
+}
+static_assert(dead1() == 1, ""); // expected-error {{not an integral constant 
expression}} \
+ // expected-note {{in call to}} \
+ // ref-error {{not an integral constant 
expression}} \
+ // ref-note {{in call to}} \
+
+
Index: clang/lib/AST/Interp/InterpState.cpp
===
--- clang/lib/AST/Interp/InterpState.cpp
+++ clang/lib/AST/Interp/InterpState.cpp
@@ -58,9 +58,13 @@
 reinterpret_cast(std::malloc(sizeof(DeadBlock) + Size));
 auto *D = new (Memory) DeadBlock(DeadBlocks, B);
 
-// Move data from one block to another.
-if (Desc->MoveFn)
+// Move data and metadata from the old block to the new (dead)block.
+if (Desc->MoveFn) {
   Desc->MoveFn(B, B->data(), D->data(), Desc);
+  if (Desc->getMetadataSize() > 0)
+std::memcpy(D->rawData(), B->rawData(), Desc->getMetadataSize());
+}
+
   } else {
 // Free storage, if necessary.
 if (Desc->DtorFn)
Index: clang/lib/AST/Interp/InterpBlock.h
===
--- clang/lib/AST/Interp/InterpBlock.h
+++ clang/lib/AST/Interp/InterpBlock.h
@@ -156,6 +156,7 @@
 
   /// Returns a pointer to the stored data.
   std::byte *data() { return B.data(); }
+  std::byte *rawData() { return B.rawData(); }
 
 private:
   friend class Block;
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -170,9 +170,8 @@
const Descriptor *D) {
   for (const auto &F : D->ElemRecord->fields()) {
 auto FieldOff = F.Offset;
-auto FieldDesc = F.Desc;
+auto *FieldDesc = F.Desc;
 
-*(reinterpret_cast(Dst + FieldOff) - 1) = FieldDesc;
 if (auto Fn = FieldDesc->MoveFn)
   Fn(B, Src + FieldOff, Dst + FieldOff, FieldDesc);
   }


Index: clang/test/AST/Interp/lifetimes.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/lifetimes.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+struct Foo {
+  int a;
+};
+
+constexpr int dead1() { // expected-error {{never produces a constant expression}}
+
+  Foo *F2 = nullptr;
+  {
+Foo F{12}; // expected-note 2{{declared here}}
+F2 = &F;
+  } // Ends lifetime of F.
+
+  return F2->a; // expected-note 2{{read of variable whose lifetime has ended}} \
+// ref-note {{read of object outside its lifetime is not allowed in a constant expression}}
+}
+static_assert(dead1() == 1, ""); // expected-error {{not an integral constant expression}} \
+ // expected-note {{in call to}} \
+ // ref-error {{not an integral constant expression}} \
+ // ref-note {{in call to}} \
+
+
Index: clang/lib/AST/Interp/InterpState.cpp
===
--- clang/lib/AST/Interp/InterpState.cpp
+++ clang/lib/AST/Interp/InterpState.cpp
@@ -58,9 +58,13 @@
 reinterpret_cast(std::malloc(sizeof(DeadBlock) + Size));
 auto *D = new (Memory) DeadBlock(DeadBlocks, B);
 
-// Move data from one block to another.
-if (Desc->MoveFn)
+// Move data and metadata from the old block to the new (dead)block.
+if (Desc->MoveFn) {
   Desc->MoveFn(B, B->data(), D->data(), Desc);
+  if (Desc->getMetadataSize() > 0)
+std::memcpy(D->rawData(), B->rawData(), Desc->getMetadataSize());
+}
+
   } else {
 // Free storage, if necessary.
 if (Desc->DtorFn)
Index: clang/lib/AST/Interp/InterpBlock.h
===
--- clang/lib/AST/Interp/InterpBlock.h
+++ clang/l

[PATCH] D155430: [clang][Interp] Implement __arithmethic_fence for floating types

2023-08-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping @lzaron


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155430

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


[PATCH] D155627: [clang][Interp] Handle SourceLocExprs

2023-08-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Having https://reviews.llvm.org/D144457 and https://reviews.llvm.org/D144457 
approved would make rebasing easier :)


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

https://reviews.llvm.org/D155627

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


[PATCH] D147217: [OpenMP][OMPIRBuilder] OpenMPIRBuilder support for requires directive

2023-08-17 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 551088.
skatrak added a comment.
Herald added subscribers: gysit, Dinistro.

Update patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147217

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1306,8 +1306,11 @@
 // TODO: set the flags when available
 llvm::OpenMPIRBuilderConfig config(
 isTargetDevice, isGPU,
-/* HasRequiresUnifiedSharedMemory */ false,
-/* OpenMPOffloadMandatory */ false);
+/* OpenMPOffloadMandatory = */ false,
+/* HasRequiresReverseOffload = */ false,
+/* HasRequiresUnifiedAddress = */ false,
+/* HasRequiresUnifiedSharedMemory = */ false,
+/* HasRequiresDynamicAllocators = */ false);
 ompBuilder->setConfig(config);
   }
   return ompBuilder.get();
Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -5128,7 +5128,7 @@
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
   OpenMPIRBuilder OMPBuilder(*M);
   OMPBuilder.initialize();
-  OpenMPIRBuilderConfig Config(false, false, false, false);
+  OpenMPIRBuilderConfig Config(false, false, false, false, false, false, false);
   OMPBuilder.setConfig(Config);
   F->setName("func");
   IRBuilder<> Builder(BB);
@@ -5206,7 +5206,8 @@
 
 TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.setConfig(OpenMPIRBuilderConfig(true, false, false, false));
+  OMPBuilder.setConfig(
+  OpenMPIRBuilderConfig(true, false, false, false, false, false, false));
   OMPBuilder.initialize();
 
   F->setName("func");
@@ -5896,7 +5897,8 @@
 
 TEST_F(OpenMPIRBuilderTest, OffloadEntriesInfoManager) {
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.setConfig(OpenMPIRBuilderConfig(true, false, false, false));
+  OMPBuilder.setConfig(
+  OpenMPIRBuilderConfig(true, false, false, false, false, false, false));
   OffloadEntriesInfoManager &InfoManager = OMPBuilder.OffloadInfoManager;
   TargetRegionEntryInfo EntryInfo("parent", 1, 2, 4, 0);
   InfoManager.initializeTargetRegionEntryInfo(EntryInfo, 0);
@@ -5919,7 +5921,7 @@
 TEST_F(OpenMPIRBuilderTest, registerTargetGlobalVariable) {
   OpenMPIRBuilder OMPBuilder(*M);
   OMPBuilder.initialize();
-  OpenMPIRBuilderConfig Config(false, false, false, false);
+  OpenMPIRBuilderConfig Config(false, false, false, false, false, false, false);
   OMPBuilder.setConfig(Config);
 
   std::vector TargetTriple;
@@ -5996,8 +5998,11 @@
   OMPBuilder.initialize();
   OpenMPIRBuilderConfig Config(/* IsTargetDevice = */ true,
/* IsGPU = */ true,
+   /* OpenMPOffloadMandatory = */ false,
+   /* HasRequiresReverseOffload = */ false,
+   /* HasRequiresUnifiedAddress = */ false,
/* HasRequiresUnifiedSharedMemory = */ false,
-   /* OpenMPOffloadMandatory = */ false);
+   /* HasRequiresDynamicAllocators = */ false);
   OMPBuilder.setConfig(Config);
 
   FunctionCallee FnTypeAndCallee =
@@ -6033,4 +6038,44 @@
   EXPECT_TRUE(Fn->hasFnAttribute(Attribute::MustProgress));
 }
 
+TEST_F(OpenMPIRBuilderTest, CreateRegisterRequires) {
+  OpenMPIRBuilder OMPBuilder(*M);
+  OMPBuilder.initialize();
+
+  OpenMPIRBuilderConfig Config(/* IsTargetDevice = */ false,
+   /* IsGPU = */ false,
+   /* OpenMPOffloadMandatory = */ false,
+   /* HasRequiresReverseOffload = */ true,
+   /* HasRequiresUnifiedAddress = */ false,
+   /* HasRequiresUnifiedSharedMemory = */ true,
+   /* HasRequiresDynamicAllocators = */ false);
+  OMPBuilder.setConfig(Config);
+
+  auto FName =
+  OMPBuilder.createPlatformSpecificName({"omp_offloading", "requires_reg"});
+  EXPECT_EQ(FName, ".omp_offloading.requires_reg");
+
+  Function *Fn = OMPBuilder.createRegisterRequires(FName);
+  EXPECT_NE(Fn, nullptr);
+  EXPECT_EQ(FName, Fn->getName());
+
+  EXPECT_EQ(Fn->getSection(), ".text.startup");
+  EXPECT_TRUE(Fn->hasInternalLinkage());
+  EXPECT_TRUE(Fn->hasFnAttribute(Attribute::NoInline));
+  EXPECT_TRUE(Fn->hasFnAttribute(Attribute::NoUnwi

[clang] f8dadef - [CodeGen] Keep track of eagerly emitted globals

2023-08-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-17T13:26:22+02:00
New Revision: f8dadefd4afc8e1b7b9a1e69a0ba8df051e03328

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

LOG: [CodeGen] Keep track of eagerly emitted globals

An inline virtual function must be emitted, but we need to remember
it and emit the same definition again in the future in case later
LLVM optimizations stripped it from the Module. The added test case
shows the problem; before this patch, it would fail with:
Symbols not found: [ _ZN1AD0Ev, _ZN1AD1Ev ]

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

Added: 
clang/test/Interpreter/inline-virtual.cpp

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 517af514d9c998..440fb040a43cc5 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3658,6 +3658,7 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
   if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
 // Emit the definition if it can't be deferred.
 EmitGlobalDefinition(GD);
+addEmittedDeferredDecl(GD);
 return;
   }
 

diff  --git a/clang/test/Interpreter/inline-virtual.cpp 
b/clang/test/Interpreter/inline-virtual.cpp
new file mode 100644
index 00..ace7a0a73d82a1
--- /dev/null
+++ b/clang/test/Interpreter/inline-virtual.cpp
@@ -0,0 +1,21 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+
+extern "C" int printf(const char *, ...);
+
+struct A { int a; A(int a) : a(a) {} virtual ~A(); };
+
+// Then define the virtual destructor as inline out-of-line, in a separate
+// PartialTranslationUnit.
+inline A::~A() { printf("~A(%d)\n", a); }
+
+// Create one instance with new and delete it.
+A *a1 = new A(1);
+delete a1;
+// CHECK: ~A(1)
+
+// Also create one global that will be auto-destructed.
+A a2(2);
+// CHECK: ~A(2)



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


[PATCH] D156537: [CodeGen] Keep track of eagerly emitted globals

2023-08-17 Thread Jonas Hahnfeld 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 rGf8dadefd4afc: [CodeGen] Keep track of eagerly emitted 
globals (authored by Hahnfeld).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156537

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Interpreter/inline-virtual.cpp


Index: clang/test/Interpreter/inline-virtual.cpp
===
--- /dev/null
+++ clang/test/Interpreter/inline-virtual.cpp
@@ -0,0 +1,21 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+
+extern "C" int printf(const char *, ...);
+
+struct A { int a; A(int a) : a(a) {} virtual ~A(); };
+
+// Then define the virtual destructor as inline out-of-line, in a separate
+// PartialTranslationUnit.
+inline A::~A() { printf("~A(%d)\n", a); }
+
+// Create one instance with new and delete it.
+A *a1 = new A(1);
+delete a1;
+// CHECK: ~A(1)
+
+// Also create one global that will be auto-destructed.
+A a2(2);
+// CHECK: ~A(2)
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3658,6 +3658,7 @@
   if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
 // Emit the definition if it can't be deferred.
 EmitGlobalDefinition(GD);
+addEmittedDeferredDecl(GD);
 return;
   }
 


Index: clang/test/Interpreter/inline-virtual.cpp
===
--- /dev/null
+++ clang/test/Interpreter/inline-virtual.cpp
@@ -0,0 +1,21 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+
+extern "C" int printf(const char *, ...);
+
+struct A { int a; A(int a) : a(a) {} virtual ~A(); };
+
+// Then define the virtual destructor as inline out-of-line, in a separate
+// PartialTranslationUnit.
+inline A::~A() { printf("~A(%d)\n", a); }
+
+// Create one instance with new and delete it.
+A *a1 = new A(1);
+delete a1;
+// CHECK: ~A(1)
+
+// Also create one global that will be auto-destructed.
+A a2(2);
+// CHECK: ~A(2)
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3658,6 +3658,7 @@
   if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
 // Emit the definition if it can't be deferred.
 EmitGlobalDefinition(GD);
+addEmittedDeferredDecl(GD);
 return;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156320: [Flang][Driver] Add support for Rpass and related options

2023-08-17 Thread victorkingi via Phabricator via cfe-commits
victorkingi added a comment.

In D156320#4594584 , @awarzynski 
wrote:

> Victor, this is proving quite tricky to review. There's already been a lot of 
> updates and many of them are summarized as either "code refactor" or 
> "clean-up". Please reduce traffic/noise and use more descriptive summaries.
>
> Also, rather than adding new features in this already large change (I am 
> referring to e.g. `DK_MachineOptimizationRemarkMissed`), please try to 
> identify ways to split this patch further. Here are some suggestions (I've 
> also made comments inline):
>
> 1. In the first iteration (like you effectively do now), focus on  
> OPT_R_Joined 
> 
>  options (e.g. `-Rpass`, `Rpass-analysis`, `-Rpass-missed`). Focus on basic 
> functionality that demonstrates that correct information is returned from the 
> backend. No need to fine tune the remarks with e.g. full file path or 
> relevant remark option.
> 2. Next, add support for -Rpass=/-Rpass-missed=/-Rpass-analysis= 
> .
>  That's when e.g. `llvm::opt::OptSpecifier optEq` in 
> `parseOptimizationRemark` would be needed (but not in Step 1).
> 3. Fine tune how the report is printed (e.g. improve file name by adding full 
> path, add valid remark option at the end etc).
> 4. Add support for machine optimisations, e.g. 
> `DK_MachineOptimizationRemarkMissed`.
>
> This is easily 4 patches ;-)

Hi Andrzej, splitting into 4 patches seems like a good idea. Here's the first 
patch that only handles the backend implementation 
https://reviews.llvm.org/D158174


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156320

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


[PATCH] D157750: Properly handle -fsplit-machine-functions for fatbinary compilation

2023-08-17 Thread Dmitry Chernenkov via Phabricator via cfe-commits
steelannelida added inline comments.



Comment at: clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c:16
+// causes a warning.
+// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s 2>&1 
\

Unfortunately these commands fail in our sandbox due to writing files to 
readonly directories:

 `unable to open output file 'fsplit-machine-functions-with-cuda-nvptx.s': 
'Permission denied'`

Could you please specify the output files via `%t` substitutions? I'm not sure 
how to do this for cuda compilation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157750

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


[PATCH] D158145: [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

2023-08-17 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.

In D158145#4594569 , @cor3ntin wrote:

> In D158145#4594549 , @danix800 
> wrote:
>
>> I also investigated whether we could count those bits at compile time and 
>> statically assert on them,
>> because a small typo or missed update could spend us a lot of time to dig 
>> for the cause.
>>
>> My first step is trying to count number of bits for a single bitfield, this 
>> is promising based on this 
>>  but
>> with a restriction, it only works on `struct` (default public fields), not 
>> `class` (default to private fields).
>>
>> If we can implement this `bitsizeof` then we could have:
>>
>>   enum { NumFunctionDeclBits = offsetof(FunctionDeclBitfields, SClass)
>>  + offsetof(FunctionDeclBitfields, IsInline)
>>  + ... };
>>
>> This can automatically update total number of bits if any of the existing 
>> one is updated.
>>
>> The second step is trying to enumerate all bit fields at compile time so 
>> that we can totally fix this kind
>> of issue, but it seems not possible.
>>
>> Any suggestions or advices? Is it even worth it to do it like this?
>
> It would be great to be able to stattic_assert these sort of bugs. I think 
> @aaron did some research in this area, it might be worth asking him how far 
> he got!

I was never able to find a conforming way to do it without implementing 
something like a "bitwidth of" operator, which is something I was planning to 
propose to WG14 anyway for use with `_BitInt`. I've not implemented the 
extension yet though, and even if I did, it wouldn't help us with non-Clang 
host compilers, so I eventually gave up trying to automatically calculate the 
values.

Changes LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158145

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


[PATCH] D157750: Properly handle -fsplit-machine-functions for fatbinary compilation

2023-08-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added inline comments.



Comment at: clang/test/Driver/fsplit-machine-functions-with-cuda-nvptx.c:16
+// causes a warning.
+// RUN:   %clang --target=x86_64-unknown-linux-gnu -nogpulib -nogpuinc \
+// RUN: --cuda-gpu-arch=sm_70 -x cuda -fsplit-machine-functions -S %s 2>&1 
\

steelannelida wrote:
> Unfortunately these commands fail in our sandbox due to writing files to 
> readonly directories:
> 
>  `unable to open output file 'fsplit-machine-functions-with-cuda-nvptx.s': 
> 'Permission denied'`
> 
> Could you please specify the output files via `%t` substitutions? I'm not 
> sure how to do this for cuda compilation.
IIRC the file names are generated based on what you specify with `-o`. Did you 
try this already?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157750

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


[PATCH] D157526: [clang][Sema] Remove irrelevant diagnostics from constraint satisfaction failure

2023-08-17 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157526

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


[clang] 0e17372 - Revert "[CodeGen] Keep track of eagerly emitted globals"

2023-08-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-17T14:21:39+02:00
New Revision: 0e17372b380467ac8339afdec992fbf887a11feb

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

LOG: Revert "[CodeGen] Keep track of eagerly emitted globals"

The added test doesn't work on Windows:
https://lab.llvm.org/buildbot/#/builders/216/builds/25769

This reverts commit f8dadefd4afc8e1b7b9a1e69a0ba8df051e03328.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 
clang/test/Interpreter/inline-virtual.cpp



diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 440fb040a43cc5..517af514d9c998 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3658,7 +3658,6 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
   if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
 // Emit the definition if it can't be deferred.
 EmitGlobalDefinition(GD);
-addEmittedDeferredDecl(GD);
 return;
   }
 

diff  --git a/clang/test/Interpreter/inline-virtual.cpp 
b/clang/test/Interpreter/inline-virtual.cpp
deleted file mode 100644
index ace7a0a73d82a1..00
--- a/clang/test/Interpreter/inline-virtual.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-// REQUIRES: host-supports-jit
-// UNSUPPORTED: system-aix
-// RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
-
-extern "C" int printf(const char *, ...);
-
-struct A { int a; A(int a) : a(a) {} virtual ~A(); };
-
-// Then define the virtual destructor as inline out-of-line, in a separate
-// PartialTranslationUnit.
-inline A::~A() { printf("~A(%d)\n", a); }
-
-// Create one instance with new and delete it.
-A *a1 = new A(1);
-delete a1;
-// CHECK: ~A(1)
-
-// Also create one global that will be auto-destructed.
-A a2(2);
-// CHECK: ~A(2)



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


[PATCH] D158157: [clang-tidy] Disable implicit search for a compilation db in some tests

2023-08-17 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL 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/D158157/new/

https://reviews.llvm.org/D158157

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


[clang] 91c4b55 - [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

2023-08-17 Thread via cfe-commits

Author: dingfei
Date: 2023-08-17T20:28:41+08:00
New Revision: 91c4b5550ecfbb7afe7275c341b73a6d3a1bbd78

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

LOG: [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

NumFunctionDeclBits is not updated when DeductionCandidateKind is
incremented.

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

Reviewed By: cor3ntin, balazske, aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclBase.h
clang/lib/Serialization/ASTWriterDecl.cpp
clang/unittests/AST/ASTImporterTest.cpp
clang/unittests/AST/DeclTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 064b4556f354a2..1bfca926bf92a9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -177,6 +177,9 @@ Bug Fixes to C++ Support
   requires-expression. This fixes:
   (`#64138 `_).
 
+- Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes:
+  (`#64171 `_).
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.

diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 1b99709ca90d99..12137387b676a7 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1702,7 +1702,7 @@ class DeclContext {
   };
 
   /// Number of non-inherited bits in FunctionDeclBitfields.
-  enum { NumFunctionDeclBits = 30 };
+  enum { NumFunctionDeclBits = 31 };
 
   /// Stores the bits used by CXXConstructorDecl. If modified
   /// NumCXXConstructorDeclBits and the accessor
@@ -1714,12 +1714,12 @@ class DeclContext {
 /// For the bits in FunctionDeclBitfields.
 uint64_t : NumFunctionDeclBits;
 
-/// 21 bits to fit in the remaining available space.
+/// 20 bits to fit in the remaining available space.
 /// Note that this makes CXXConstructorDeclBitfields take
 /// exactly 64 bits and thus the width of NumCtorInitializers
 /// will need to be shrunk if some bit is added to NumDeclContextBitfields,
 /// NumFunctionDeclBitfields or CXXConstructorDeclBitfields.
-uint64_t NumCtorInitializers : 18;
+uint64_t NumCtorInitializers : 17;
 uint64_t IsInheritingConstructor : 1;
 
 /// Whether this constructor has a trail-allocated explicit specifier.

diff  --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index 59dbc36d24e8c9..8dd78152bd6870 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -580,7 +580,7 @@ void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
 }
 
 void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
-  static_assert(DeclContext::NumFunctionDeclBits == 30,
+  static_assert(DeclContext::NumFunctionDeclBits == 31,
 "You need to update the serializer after you change the "
 "FunctionDeclBits");
 
@@ -1495,7 +1495,7 @@ void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
 }
 
 void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
-  static_assert(DeclContext::NumCXXConstructorDeclBits == 21,
+  static_assert(DeclContext::NumCXXConstructorDeclBits == 20,
 "You need to update the serializer after you change the "
 "CXXConstructorDeclBits");
 

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 06b64b9f8efb47..057701dea2c51d 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -7832,6 +7832,47 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportConstructorUsingShadow) {
   CheckAST(ToTU, ToC);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportFunctionDeclBitShouldNotOverwriteCtorDeclBits) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"s(
+struct A {
+  A() : m() {}
+  int m;
+};
+
+A foo() { A a; return a; }
+A bar() { return {}; }
+  )s",
+  Lang_CXX17,
+  R"s(
+struct A {
+  A() : m() {}
+  int m;
+};
+A baz() { return {}; }
+  )s",
+  Lang_CXX17, "A");
+
+  auto HasCtorInit =
+  hasAnyConstructorInitializer(cxxCtorInitializer(isMemberInitializer()));
+  auto ImpMoveCtor =
+  cxxConstructorDecl(isMoveConstructor(), isImplicit(), HasCtorInit);
+
+  auto *FromImpMoveCtor = FirstDeclMatcher().match(
+  From, ImpMoveCtor);
+  auto *ToImpMoveCtor = FirstDeclMatcher().match(
+  To, ImpMoveC

[PATCH] D158145: [clang] Update NumFunctionDeclBits for FunctionDeclBitfields

2023-08-17 Thread 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 rG91c4b5550ecf: [clang] Update NumFunctionDeclBits for 
FunctionDeclBitfields (authored by dingfei ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158145

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclBase.h
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/DeclTest.cpp

Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -353,6 +353,32 @@
   EXPECT_TRUE(getFooValue->isInlined());
 }
 
+TEST(Decl, FunctionDeclBitsShouldNotOverlapWithCXXConstructorDeclBits) {
+  llvm::Annotations Code(R"(
+struct A {
+  A() : m() {}
+  int m;
+};
+
+A f() { return A(); }
+)");
+
+  auto AST = tooling::buildASTFromCodeWithArgs(Code.code(), {"-std=c++14"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto HasCtorInit =
+  hasAnyConstructorInitializer(cxxCtorInitializer(isMemberInitializer()));
+  auto ImpMoveCtor =
+  cxxConstructorDecl(isMoveConstructor(), isImplicit(), HasCtorInit)
+  .bind("MoveCtor");
+
+  auto *ToImpMoveCtor =
+  selectFirst("MoveCtor", match(ImpMoveCtor, Ctx));
+
+  EXPECT_TRUE(ToImpMoveCtor->getNumCtorInitializers() == 1);
+  EXPECT_FALSE(ToImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
+}
+
 TEST(Decl, NoProtoFunctionDeclAttributes) {
   llvm::Annotations Code(R"(
 void f();
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -7832,6 +7832,47 @@
   CheckAST(ToTU, ToC);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportFunctionDeclBitShouldNotOverwriteCtorDeclBits) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"s(
+struct A {
+  A() : m() {}
+  int m;
+};
+
+A foo() { A a; return a; }
+A bar() { return {}; }
+  )s",
+  Lang_CXX17,
+  R"s(
+struct A {
+  A() : m() {}
+  int m;
+};
+A baz() { return {}; }
+  )s",
+  Lang_CXX17, "A");
+
+  auto HasCtorInit =
+  hasAnyConstructorInitializer(cxxCtorInitializer(isMemberInitializer()));
+  auto ImpMoveCtor =
+  cxxConstructorDecl(isMoveConstructor(), isImplicit(), HasCtorInit);
+
+  auto *FromImpMoveCtor = FirstDeclMatcher().match(
+  From, ImpMoveCtor);
+  auto *ToImpMoveCtor = FirstDeclMatcher().match(
+  To, ImpMoveCtor);
+
+  EXPECT_TRUE(FromImpMoveCtor->getNumCtorInitializers() == 1);
+  EXPECT_FALSE(FromImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
+
+  EXPECT_TRUE(ToImpMoveCtor->getNumCtorInitializers() == 1);
+  EXPECT_FALSE(ToImpMoveCtor->FriendConstraintRefersToEnclosingTemplate());
+  EXPECT_TRUE(*ToImpMoveCtor->init_begin());
+}
+
 AST_MATCHER_P(UsingShadowDecl, hasIntroducerDecl, internal::Matcher,
   InnerMatcher) {
   return InnerMatcher.matches(*Node.getIntroducer(), Finder, Builder);
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -580,7 +580,7 @@
 }
 
 void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
-  static_assert(DeclContext::NumFunctionDeclBits == 30,
+  static_assert(DeclContext::NumFunctionDeclBits == 31,
 "You need to update the serializer after you change the "
 "FunctionDeclBits");
 
@@ -1495,7 +1495,7 @@
 }
 
 void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
-  static_assert(DeclContext::NumCXXConstructorDeclBits == 21,
+  static_assert(DeclContext::NumCXXConstructorDeclBits == 20,
 "You need to update the serializer after you change the "
 "CXXConstructorDeclBits");
 
Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1702,7 +1702,7 @@
   };
 
   /// Number of non-inherited bits in FunctionDeclBitfields.
-  enum { NumFunctionDeclBits = 30 };
+  enum { NumFunctionDeclBits = 31 };
 
   /// Stores the bits used by CXXConstructorDecl. If modified
   /// NumCXXConstructorDeclBits and the accessor
@@ -1714,12 +1714,12 @@
 /// For the bits in FunctionDeclBitfields.
 uint64_t : NumFunctionDeclBits;
 
-/// 21 bits to fit in the remaining available space.
+/// 20 bits to fit in the remaining available space.
 /// Note that this makes CXXConstructorDeclBitfields take
 /// exac

[PATCH] D158137: Change -ffp-model= related warn_drv_overriding_flag_option to warn_drv_overriding_option

2023-08-17 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

> Thanks! I agree. d9ad0681fad9a98f43d9baddb95d505b37153c48 (2013) renamed 
> `warn_drv_overriding_t_option` to `warn_drv_overriding_flag_option`.
> Perhaps the original name `warn_drv_overriding_t_option` should be restored.

That change also started using it for overriding `/MD` and `/MT`. I think the 
intention then was to make the flag more general, but it forgot to rename the 
flag spelling. Perhaps the fix is really to 
s/overriding-t-option/overriding-option/ ? (If we're concerned about the 
interface change, we could retain an alias with the old spelling.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158137

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


[PATCH] D157526: [clang][Sema] Remove irrelevant diagnostics from constraint satisfaction failure

2023-08-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Sorry for the delay in review, I'm still on vacation.  However, I don't like 
the idea of removing the satisfaction.  I have to think about it more, but 
optimally we'd just not add the detail until we knew what the RHS value was, 
though our design doesn't particularly support that currently.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157526

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


[PATCH] D112921: [clang] Enable sized deallocation by default in C++14 onwards

2023-08-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112921

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


[PATCH] D156054: [Clang][Sema] DR722 (nullptr and varargs) and missing -Wvarargs diagnostics

2023-08-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Precommit CI still has a related failure, it seems.




Comment at: clang/lib/Sema/SemaExpr.cpp:17317-17319
+if (TInfo->getType()->isSpecificBuiltinType(BuiltinType::Float) ||
+TInfo->getType()->isSpecificBuiltinType(BuiltinType::Half))
   PromoteType = Context.DoubleTy;

jcranmer-intel wrote:
> aaron.ballman wrote:
> > Hmmm... the existing code seems wrong to me because it's not paying any 
> > attention to `FLT_EVAL_METHOD`, but I think it probably should? CC 
> > @jcranmer-intel @zahiraam for opinions.
> > 
> > Actually, I wonder if the correct approach here is to split 
> > `Sema::DefaultArgumentPromotion()` up so that we can calculate what the 
> > default argument promoted type is of the expression independent of 
> > performing the actual promotion, and call the promotion type calculation 
> > logic here?
> C23 6.5.2.2p6 [draft N3096] says "trailing arguments that have type `float` 
> are promoted to `double`". `FLT_EVAL_METHOD` shouldn't need to apply here, 
> since it's largely about reflecting that things like x87 using 80-bit 
> precision internally, and not actual argument passing.
Ah that's good to know, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156054

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


[PATCH] D158165: [clang][AST] TextNodeDumper learned to output instantiated_from information

2023-08-17 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 a small nit.




Comment at: clang/lib/AST/TextNodeDumper.cpp:1896
+
+  if (auto *Instance = D->getInstantiatedFromMemberFunction()) {
+OS << " instantiated_from";




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158165

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


[PATCH] D147218: [OpenMP][Flang][MLIR] Lowering of OpenMP requires directive from parse tree to MLIR

2023-08-17 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 551113.
skatrak added a comment.

Change parent and update patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147218

Files:
  flang/include/flang/Lower/OpenMP.h
  flang/lib/Lower/Bridge.cpp
  flang/lib/Lower/OpenMP.cpp
  flang/test/Lower/OpenMP/requires-notarget.f90
  flang/test/Lower/OpenMP/requires.f90

Index: flang/test/Lower/OpenMP/requires.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires.f90
@@ -0,0 +1,13 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks the lowering of requires into MLIR
+
+!CHECK:  module attributes {
+!CHECK-SAME: omp.requires = #omp
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
+
+subroutine f
+  !$omp declare target
+end subroutine f
Index: flang/test/Lower/OpenMP/requires-notarget.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires-notarget.f90
@@ -0,0 +1,11 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks that requires lowering into MLIR skips creating the
+! omp.requires attribute with target-related clauses if there are no device
+! functions in the compilation unit
+
+!CHECK:  module attributes {
+!CHECK-NOT:  omp.requires
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
Index: flang/lib/Lower/OpenMP.cpp
===
--- flang/lib/Lower/OpenMP.cpp
+++ flang/lib/Lower/OpenMP.cpp
@@ -2407,6 +2407,44 @@
  reductionDeclSymbols));
 }
 
+/// Extract the list of function and variable symbols affected by the given
+/// 'declare target' directive and return the intended device type for them.
+static mlir::omp::DeclareTargetDeviceType getDeclareTargetInfo(
+Fortran::lower::AbstractConverter &converter,
+Fortran::lower::pft::Evaluation &eval,
+const Fortran::parser::OpenMPDeclareTargetConstruct &declareTargetConstruct,
+llvm::SmallVectorImpl &symbolAndClause) {
+
+  // The default capture type
+  mlir::omp::DeclareTargetDeviceType deviceType =
+  mlir::omp::DeclareTargetDeviceType::any;
+  const auto &spec = std::get(
+  declareTargetConstruct.t);
+
+  if (const auto *objectList{
+  Fortran::parser::Unwrap(spec.u)}) {
+// Case: declare target(func, var1, var2)
+gatherFuncAndVarSyms(*objectList, mlir::omp::DeclareTargetCaptureClause::to,
+ symbolAndClause);
+  } else if (const auto *clauseList{
+ Fortran::parser::Unwrap(
+ spec.u)}) {
+if (clauseList->v.empty()) {
+  // Case: declare target, implicit capture of function
+  symbolAndClause.emplace_back(
+  mlir::omp::DeclareTargetCaptureClause::to,
+  eval.getOwningProcedure()->getSubprogramSymbol());
+}
+
+ClauseProcessor cp(converter, *clauseList);
+cp.processTo(symbolAndClause);
+cp.processLink(symbolAndClause);
+cp.processDeviceType(deviceType);
+  }
+
+  return deviceType;
+}
+
 //===--===//
 // genOMP() Code generation helper functions
 //===--===//
@@ -3306,32 +3344,8 @@
&declareTargetConstruct) {
   llvm::SmallVector symbolAndClause;
   mlir::ModuleOp mod = converter.getFirOpBuilder().getModule();
-
-  // The default capture type
-  mlir::omp::DeclareTargetDeviceType deviceType =
-  mlir::omp::DeclareTargetDeviceType::any;
-  const auto &spec = std::get(
-  declareTargetConstruct.t);
-  if (const auto *objectList{
-  Fortran::parser::Unwrap(spec.u)}) {
-// Case: declare target(func, var1, var2)
-gatherFuncAndVarSyms(*objectList, mlir::omp::DeclareTargetCaptureClause::to,
- symbolAndClause);
-  } else if (const auto *clauseList{
- Fortran::parser::Unwrap(
- spec.u)}) {
-if (clauseList->v.empty()) {
-  // Case: declare target, implicit capture of function
-  symbolAndClause.emplace_back(
-  mlir::omp::DeclareTargetCaptureClause::to,
-  eval.getOwningProcedure()->getSubprogramSymbol());
-}
-
-ClauseProcessor cp(converter, *clauseList);
-cp.processTo(symbolAndClause);
-cp.processLink(symbolAndClause);
-cp.processDeviceType(deviceType);
-  }
+  mlir::omp::DeclareTargetDeviceType deviceType = getDeclareTargetInfo(
+  converter, eval, declareTargetConstruct, symbolAndClause);
 
   for (const DeclareTargetCapturePair &symClause : symbolAndClause) {
 mlir::Operation *op = mod.lookupSymbol(
@@ -3435,6 +34

[PATCH] D153114: [clangd] [C++20] [Modules] Support C++20 modules for clangd

2023-08-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Sorry for the long radio silence here. There's a lot to chew on, and I put it 
off too long. Thanks for your patience!

I agree we should get experimental modules support landed in some form on the 
LLVM 18 timeline.
It's fine if this doesn't have extension points for large projects, or for 
header modules, and if it'll take some refactoring later to get there. Still, I 
think we should consider them in the architecture (partly because a second impl 
helps reason about interfaces).

I do think it's important we play nicely with the rest of clangd 
infrastructure: things like threading/context, VFS clean-ness, ability to 
easily write gtests for modules-enabled ASTs.

This initial pass probably mostly comes across as a list of complaints... I'd 
like to be more constructive & provide ideas, but this is long already so I'll 
follow up with that.

I've tried to limit to mostly high-level comments (or at least details that 
require a bit of thought!)
A couple more that don't fit anywhere:

---

Indexing


Much of clangd's functionality relies on having an up-to-date index of the 
transitively included headers (and now, modules).
While we're more relaxed about having a full-project index, this preamble index 
really is essential.

It's infeasible to build this index from the PCM files themselves: this means 
fully deserializing them and is too expensive (we tried this with PCH).
Traditionally we indexed the preamble the ASTContext before serializing the 
PCH, though recently this is optionally async.
(You can see this in `onPreambleAST` in ClangdServer.cpp and trace from there.)

I think indexing can be left out of this initial patch, but we should work out 
where/how it fits and leave a comment!

---

Scope and incremental development
-

There are a lot of moving pieces to this. That's useful to understand how they 
all fit together (which is necessary whether they're in the same patch or not).
However it makes difficult to review, and to drive a review to a conclusion. I 
think we should change the scope of the initial patch to establish a small 
subset that works and we understand well:

**Don't attempt any cross-file or cross-version coordination**: i.e. don't try 
to reuse BMIs between different files, don't try to reuse BMIs between 
(preamble) reparses of the same file, don't try to persist the module graph. 
Instead, when building a preamble, synchronously scan for the module graph, 
build the required PCMs on the single preamble thread with filenames private to 
that preamble, and then proceed to build the preamble.

Obviously this no longer provides any performance benefits from modules! But it 
gets us to a modules-based build that works, and these aspects can be added on 
top in a relatively clear way.
It avoids a lot of tricky problems:

- scheduling
- (lack of) transactionality of reads/writes from the module graph
- the possibility of BMI version conflicts
- various events that can invalidate the module graph
- rebuilding of BMIs when source files change (the current patch deliberately 
doesn't do this to keep the scope down, but that means the result is both 
complex and incorrect, which is a difficult situation to get out of)

I think this also encourages us to unbundle some of the "ModulesManager"'s 
responsibilities and will lead to a better API there.

**Do consider the lifecycle/namespacing of BMI files on disk**

While we may eventually want to reuse BMIs between (sequential or concurrent) 
clangd instances, this is complicated and IMO won't happen soon (needs to deal 
with source versioning, I believe).

Therefore for now we should treat the BMIs as transient, conceptually like 
in-memory objects. In practice we want to store them on disk for size reasons, 
but these should have transient tempfile names that will never conflict, should 
be deleted on shutdown etc. (It's fine to do basic delete-on-destruction and 
leave crash-handling etc out for now).




Comment at: clang-tools-extra/clangd/ModulesManager.cpp:50
+
+  DependencyScanningTool ScanningTool(Service);
+

the docs suggest this tool is going to spawn threads.

clangd needs to retain control of thread spawning, e.g. to ensure 
clangd::Context is propagated (required for config, tracing and others), thread 
priorities are set appropriately etc.



Comment at: clang-tools-extra/clangd/ModulesManager.cpp:55
+  llvm::Expected P1689Rule =
+  ScanningTool.getP1689ModuleDependencyFile(
+  *Cmd, Cmd->Directory, MakeformatOutput, MakeformatOutputPath);

It looks like this performs IO for the dependency scanning.
The files may not be on a real filesystem, IO on source files should go through 
the configured VFS (see ThreadsafeFS from which you can obtain a concrete FS 
for the desired operation).



Comment at: clang-tools-extra/clangd/ModulesManager.cpp:56
+  ScanningTool.getP1

[clang] ca1295c - [DebugInfo] Alternate (more efficient) MD5 fix

2023-08-17 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2023-08-17T07:03:47-07:00
New Revision: ca1295c5a15f03ede2fe620cc80d6a1e6e6735b8

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

LOG: [DebugInfo] Alternate (more efficient) MD5 fix

D155991 changed the file lookup to do a full string compare on the
filename; however, this added ~0.5% to compile time with -g.
Go back to the previous pointer-based lookup, but capture the main
file's checksum as well as its name to use when creating the extra
DIFile entry. This causes all entries to be consistent and also
avoids computing the checksum twice.

Differential revision: https://reviews.llvm.org/D156571

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/test/CodeGenCXX/debug-info-function-context.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 54e31bec0cc5bc..e782b7f906e6e6 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -391,12 +391,14 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation 
Loc) {
   SourceManager &SM = CGM.getContext().getSourceManager();
   StringRef FileName;
   FileID FID;
+  std::optional> CSInfo;
 
   if (Loc.isInvalid()) {
 // The DIFile used by the CU is distinct from the main source file. Call
 // createFile() below for canonicalization if the source file was specified
 // with an absolute path.
 FileName = TheCU->getFile()->getFilename();
+CSInfo = TheCU->getFile()->getChecksum();
   } else {
 PresumedLoc PLoc = SM.getPresumedLoc(Loc);
 FileName = PLoc.getFilename();
@@ -417,13 +419,13 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation 
Loc) {
   return cast(V);
   }
 
-  SmallString<64> Checksum;
-
-  std::optional CSKind =
+  if (!CSInfo) {
+SmallString<64> Checksum;
+std::optional CSKind =
   computeChecksum(FID, Checksum);
-  std::optional> CSInfo;
-  if (CSKind)
-CSInfo.emplace(*CSKind, Checksum);
+if (CSKind)
+  CSInfo.emplace(*CSKind, Checksum);
+  }
   return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc)));
 }
 

diff  --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index ec843793deea6c..b47a4934f0b1ba 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -148,7 +148,7 @@ class CGDebugInfo {
   llvm::BumpPtrAllocator DebugInfoNames;
   StringRef CWDName;
 
-  llvm::StringMap DIFileCache;
+  llvm::DenseMap DIFileCache;
   llvm::DenseMap SPCache;
   /// Cache declarations relevant to DW_TAG_imported_declarations (C++
   /// using declarations and global alias variables) that aren't covered

diff  --git a/clang/test/CodeGenCXX/debug-info-function-context.cpp 
b/clang/test/CodeGenCXX/debug-info-function-context.cpp
index 8d3309f42748dc..63fdf877fdb7db 100644
--- a/clang/test/CodeGenCXX/debug-info-function-context.cpp
+++ b/clang/test/CodeGenCXX/debug-info-function-context.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple 
x86_64-pc-linux-gnu %s \
-// RUN: -dwarf-version=5 -main-file-name %s  -o - | FileCheck %s
+// RUN: -dwarf-version=5 -main-file-name debug-info-function-context.cpp  
-o - | FileCheck %s
 
 struct C {
   void member_function();
@@ -31,8 +31,8 @@ int global_initialized_variable = C::static_member_function();
 
 // The first DIFile is for the CU, the second is what everything else uses.
 // We're using DWARF v5 so both should have MD5 checksums.
-// CHECK: !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5
-// CHECK: ![[FILE:[0-9]+]] = !DIFile(filename: "{{.*}}context.cpp",{{.*}} 
checksumkind: CSK_MD5
+// CHECK: !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5, 
checksum: [[CKSUM:".*"]]
+// CHECK: ![[FILE:[0-9]+]] = !DIFile(filename: "{{.*}}context.cpp",{{.*}} 
checksumkind: CSK_MD5, checksum: [[CKSUM]]
 // CHECK: ![[C:[0-9]+]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type, name: "C",
 // CHECK: ![[NS:.*]] = !DINamespace(name: "ns"
 // CHECK: !DISubprogram(name: "member_function",{{.*}} scope: ![[C]],{{.*}} 
DISPFlagDefinition



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


[PATCH] D156571: [DebugInfo] Alternate MD5 fix, NFC

2023-08-17 Thread Paul Robinson 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 rGca1295c5a15f: [DebugInfo] Alternate (more efficient) MD5 fix 
(authored by probinson).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156571

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGenCXX/debug-info-function-context.cpp


Index: clang/test/CodeGenCXX/debug-info-function-context.cpp
===
--- clang/test/CodeGenCXX/debug-info-function-context.cpp
+++ clang/test/CodeGenCXX/debug-info-function-context.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple 
x86_64-pc-linux-gnu %s \
-// RUN: -dwarf-version=5 -main-file-name %s  -o - | FileCheck %s
+// RUN: -dwarf-version=5 -main-file-name debug-info-function-context.cpp  
-o - | FileCheck %s
 
 struct C {
   void member_function();
@@ -31,8 +31,8 @@
 
 // The first DIFile is for the CU, the second is what everything else uses.
 // We're using DWARF v5 so both should have MD5 checksums.
-// CHECK: !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5
-// CHECK: ![[FILE:[0-9]+]] = !DIFile(filename: "{{.*}}context.cpp",{{.*}} 
checksumkind: CSK_MD5
+// CHECK: !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5, 
checksum: [[CKSUM:".*"]]
+// CHECK: ![[FILE:[0-9]+]] = !DIFile(filename: "{{.*}}context.cpp",{{.*}} 
checksumkind: CSK_MD5, checksum: [[CKSUM]]
 // CHECK: ![[C:[0-9]+]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type, name: "C",
 // CHECK: ![[NS:.*]] = !DINamespace(name: "ns"
 // CHECK: !DISubprogram(name: "member_function",{{.*}} scope: ![[C]],{{.*}} 
DISPFlagDefinition
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -148,7 +148,7 @@
   llvm::BumpPtrAllocator DebugInfoNames;
   StringRef CWDName;
 
-  llvm::StringMap DIFileCache;
+  llvm::DenseMap DIFileCache;
   llvm::DenseMap SPCache;
   /// Cache declarations relevant to DW_TAG_imported_declarations (C++
   /// using declarations and global alias variables) that aren't covered
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -391,12 +391,14 @@
   SourceManager &SM = CGM.getContext().getSourceManager();
   StringRef FileName;
   FileID FID;
+  std::optional> CSInfo;
 
   if (Loc.isInvalid()) {
 // The DIFile used by the CU is distinct from the main source file. Call
 // createFile() below for canonicalization if the source file was specified
 // with an absolute path.
 FileName = TheCU->getFile()->getFilename();
+CSInfo = TheCU->getFile()->getChecksum();
   } else {
 PresumedLoc PLoc = SM.getPresumedLoc(Loc);
 FileName = PLoc.getFilename();
@@ -417,13 +419,13 @@
   return cast(V);
   }
 
-  SmallString<64> Checksum;
-
-  std::optional CSKind =
+  if (!CSInfo) {
+SmallString<64> Checksum;
+std::optional CSKind =
   computeChecksum(FID, Checksum);
-  std::optional> CSInfo;
-  if (CSKind)
-CSInfo.emplace(*CSKind, Checksum);
+if (CSKind)
+  CSInfo.emplace(*CSKind, Checksum);
+  }
   return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc)));
 }
 


Index: clang/test/CodeGenCXX/debug-info-function-context.cpp
===
--- clang/test/CodeGenCXX/debug-info-function-context.cpp
+++ clang/test/CodeGenCXX/debug-info-function-context.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-pc-linux-gnu %s \
-// RUN: -dwarf-version=5 -main-file-name %s  -o - | FileCheck %s
+// RUN: -dwarf-version=5 -main-file-name debug-info-function-context.cpp  -o - | FileCheck %s
 
 struct C {
   void member_function();
@@ -31,8 +31,8 @@
 
 // The first DIFile is for the CU, the second is what everything else uses.
 // We're using DWARF v5 so both should have MD5 checksums.
-// CHECK: !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5
-// CHECK: ![[FILE:[0-9]+]] = !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5
+// CHECK: !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5, checksum: [[CKSUM:".*"]]
+// CHECK: ![[FILE:[0-9]+]] = !DIFile(filename: "{{.*}}context.cpp",{{.*}} checksumkind: CSK_MD5, checksum: [[CKSUM]]
 // CHECK: ![[C:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "C",
 // CHECK: ![[NS:.*]] = !DINamespace(name: "ns"
 // CHECK: !DISubprogram(name: "member_function",{{.*}} scope: ![[C]],{{.*}} DISPFlagDefinition
Index: clang/lib/CodeGen/CGDebugInfo.h
=

[PATCH] D156571: [DebugInfo] Alternate MD5 fix, NFC

2023-08-17 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

Detail added in the commit message, good idea!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156571

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


[clang] d7f7fb6 - [clang][AST] TextNodeDumper learned to output instantiated_from information

2023-08-17 Thread Timo Stripf via cfe-commits

Author: Timo Stripf
Date: 2023-08-17T14:11:16Z
New Revision: d7f7fb6c1d9745f4d760962d2e572b861f730459

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

LOG: [clang][AST] TextNodeDumper learned to output instantiated_from information

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/lib/AST/TextNodeDumper.cpp
clang/test/AST/ast-dump-decl.cpp

Removed: 




diff  --git a/clang/lib/AST/TextNodeDumper.cpp 
b/clang/lib/AST/TextNodeDumper.cpp
index e1e3ab9667ae8f..c2e86404b90036 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1892,6 +1892,11 @@ void TextNodeDumper::VisitFunctionDecl(const 
FunctionDecl *D) {
   // ParmVarDecls yet.
   if (!D->param_empty() && !D->param_begin())
 OS << " <>>";
+
+  if (const auto *Instance = D->getInstantiatedFromMemberFunction()) {
+OS << " instantiated_from";
+dumpPointer(Instance);
+  }
 }
 
 void TextNodeDumper::VisitLifetimeExtendedTemporaryDecl(
@@ -2107,6 +2112,10 @@ void TextNodeDumper::VisitTypeAliasTemplateDecl(
 
 void TextNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
   VisitRecordDecl(D);
+  if (const auto *Instance = D->getInstantiatedFromMemberClass()) {
+OS << " instantiated_from";
+dumpPointer(Instance);
+  }
   if (const auto *CTSD = dyn_cast(D))
 dumpTemplateSpecializationKind(CTSD->getSpecializationKind());
 

diff  --git a/clang/test/AST/ast-dump-decl.cpp 
b/clang/test/AST/ast-dump-decl.cpp
index 0486de69f620bf..e5da2c58fe185f 100644
--- a/clang/test/AST/ast-dump-decl.cpp
+++ b/clang/test/AST/ast-dump-decl.cpp
@@ -316,173 +316,173 @@ namespace testClassTemplateDecl {
   template class TT> struct TestTemplateTemplateDefaultType 
{ };
 }
 
-// CHECK:   ClassTemplateDecl 0x{{.+}} <{{.+}}:[[@LINE-40]]:3, 
line:[[@LINE-34]]:3> line:[[@LINE-40]]:30 TestClassTemplate
-// CHECK-NEXT:  |-TemplateTypeParmDecl 0x{{.+}}  col:21 
typename depth 0 index 0 T
-// CHECK-NEXT:  |-CXXRecordDecl 0x{{.+}}  
line:[[@LINE-42]]:30 class TestClassTemplate definition
-// CHECK-NEXT:  | |-DefinitionData standard_layout has_user_declared_ctor 
can_const_default_init
-// CHECK-NEXT:  | | |-DefaultConstructor exists non_trivial user_provided
-// CHECK-NEXT:  | | |-CopyConstructor simple trivial has_const_param 
needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveConstructor
-// CHECK-NEXT:  | | |-CopyAssignment simple trivial has_const_param 
needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveAssignment
-// CHECK-NEXT:  | | `-Destructor
-// CHECK-NEXT:  | |-CXXRecordDecl 0x{{.+}}  col:30 implicit 
referenced class TestClassTemplate
-// CHECK-NEXT:  | |-AccessSpecDecl 0x{{.+}}  col:3 
public
-// CHECK-NEXT:  | |-CXXConstructorDecl 0x{{.+}}  
col:5 TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXDestructorDecl 0x{{.+}}  
col:5 ~TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXMethodDecl 0x{{.+}}  col:9 
j 'int ()'
-// CHECK-NEXT:  | `-FieldDecl 0x{{.+}}  col:9 i 
'int'
-// CHECK-NEXT:  |-ClassTemplateSpecializationDecl 0x{{.+}} 
 line:[[@LINE-56]]:30 class 
TestClassTemplate definition
-// CHECK-NEXT:  | |-DefinitionData standard_layout has_user_declared_ctor 
can_const_default_init
-// CHECK-NEXT:  | | |-DefaultConstructor exists non_trivial user_provided
-// CHECK-NEXT:  | | |-CopyConstructor simple trivial has_const_param 
implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveConstructor
-// CHECK-NEXT:  | | |-CopyAssignment simple trivial has_const_param 
needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveAssignment
-// CHECK-NEXT:  | | `-Destructor non_trivial user_declared
-// CHECK-NEXT:  | |-TemplateArgument type 'testClassTemplateDecl::A'
-// CHECK-NEXT:  | | `-RecordType 0{{.+}} 'testClassTemplateDecl::A'
-// CHECK-NEXT:  | |   `-CXXRecord 0x{{.+}} 'A'
-// CHECK-NEXT:  | |-CXXRecordDecl 0x{{.+}}  col:30 implicit 
class TestClassTemplate
-// CHECK-NEXT:  | |-AccessSpecDecl 0x{{.+}}  col:3 
public
-// CHECK-NEXT:  | |-CXXConstructorDecl 0x{{.+}}  
col:5 used TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXDestructorDecl 0x{{.+}}  
col:5 used ~TestClassTemplate 'void () noexcept'
-// CHECK-NEXT:  | |-CXXMethodDecl 0x{{.+}}  col:9 
j 'int ()'
-// CHECK-NEXT:  | |-FieldDecl 0x{{.+}}  col:9 i 
'int'
-// CHECK-NEXT:  | `-CXXConstructorDecl 0x{{.+}}  col:30 
implicit constexpr TestClassTemplate 'void (const TestClassTemplate &)' 
inline default trivial noexcept-unevaluated 0x{{.+}}
-// CHECK-NEXT:  |   `-ParmVarDecl 0x{{.+}}  col:30 'const 
TestClassTemplate &'
-// CHECK-NEXT:  |-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-// CHECK-NEXT:  |-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-// CHECK-NEXT:  `-ClassTempla

[PATCH] D158165: [clang][AST] TextNodeDumper learned to output instantiated_from information

2023-08-17 Thread Timo Stripf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd7f7fb6c1d97: [clang][AST] TextNodeDumper learned to output 
instantiated_from information (authored by strimo378).

Changed prior to commit:
  https://reviews.llvm.org/D158165?vs=551068&id=551124#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158165

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-decl.cpp

Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -316,173 +316,173 @@
   template class TT> struct TestTemplateTemplateDefaultType { };
 }
 
-// CHECK:   ClassTemplateDecl 0x{{.+}} <{{.+}}:[[@LINE-40]]:3, line:[[@LINE-34]]:3> line:[[@LINE-40]]:30 TestClassTemplate
-// CHECK-NEXT:  |-TemplateTypeParmDecl 0x{{.+}}  col:21 typename depth 0 index 0 T
-// CHECK-NEXT:  |-CXXRecordDecl 0x{{.+}}  line:[[@LINE-42]]:30 class TestClassTemplate definition
-// CHECK-NEXT:  | |-DefinitionData standard_layout has_user_declared_ctor can_const_default_init
-// CHECK-NEXT:  | | |-DefaultConstructor exists non_trivial user_provided
-// CHECK-NEXT:  | | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveConstructor
-// CHECK-NEXT:  | | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveAssignment
-// CHECK-NEXT:  | | `-Destructor
-// CHECK-NEXT:  | |-CXXRecordDecl 0x{{.+}}  col:30 implicit referenced class TestClassTemplate
-// CHECK-NEXT:  | |-AccessSpecDecl 0x{{.+}}  col:3 public
-// CHECK-NEXT:  | |-CXXConstructorDecl 0x{{.+}}  col:5 TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXDestructorDecl 0x{{.+}}  col:5 ~TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXMethodDecl 0x{{.+}}  col:9 j 'int ()'
-// CHECK-NEXT:  | `-FieldDecl 0x{{.+}}  col:9 i 'int'
-// CHECK-NEXT:  |-ClassTemplateSpecializationDecl 0x{{.+}}  line:[[@LINE-56]]:30 class TestClassTemplate definition
-// CHECK-NEXT:  | |-DefinitionData standard_layout has_user_declared_ctor can_const_default_init
-// CHECK-NEXT:  | | |-DefaultConstructor exists non_trivial user_provided
-// CHECK-NEXT:  | | |-CopyConstructor simple trivial has_const_param implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveConstructor
-// CHECK-NEXT:  | | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveAssignment
-// CHECK-NEXT:  | | `-Destructor non_trivial user_declared
-// CHECK-NEXT:  | |-TemplateArgument type 'testClassTemplateDecl::A'
-// CHECK-NEXT:  | | `-RecordType 0{{.+}} 'testClassTemplateDecl::A'
-// CHECK-NEXT:  | |   `-CXXRecord 0x{{.+}} 'A'
-// CHECK-NEXT:  | |-CXXRecordDecl 0x{{.+}}  col:30 implicit class TestClassTemplate
-// CHECK-NEXT:  | |-AccessSpecDecl 0x{{.+}}  col:3 public
-// CHECK-NEXT:  | |-CXXConstructorDecl 0x{{.+}}  col:5 used TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXDestructorDecl 0x{{.+}}  col:5 used ~TestClassTemplate 'void () noexcept'
-// CHECK-NEXT:  | |-CXXMethodDecl 0x{{.+}}  col:9 j 'int ()'
-// CHECK-NEXT:  | |-FieldDecl 0x{{.+}}  col:9 i 'int'
-// CHECK-NEXT:  | `-CXXConstructorDecl 0x{{.+}}  col:30 implicit constexpr TestClassTemplate 'void (const TestClassTemplate &)' inline default trivial noexcept-unevaluated 0x{{.+}}
-// CHECK-NEXT:  |   `-ParmVarDecl 0x{{.+}}  col:30 'const TestClassTemplate &'
-// CHECK-NEXT:  |-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-// CHECK-NEXT:  |-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-// CHECK-NEXT:  `-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-
-// CHECK:   ClassTemplateSpecializationDecl 0x{{.+}} <{{.+}}:[[@LINE-67]]:3, line:[[@LINE-65]]:3> line:[[@LINE-67]]:20 class TestClassTemplate definition
-// CHECK-NEXT:  |-DefinitionData pass_in_registers standard_layout trivially_copyable trivial literal
-// CHECK-NEXT:  | |-DefaultConstructor exists trivial needs_implicit
-// CHECK-NEXT:  | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | |-MoveConstructor exists simple trivial needs_implicit
-// CHECK-NEXT:  | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | |-MoveAssignment exists simple trivial needs_implicit
-// CHECK-NEXT:  | `-Destructor simple irrelevant trivial needs_implicit
-// CHECK-NEXT:  |-TemplateArgument type 'testClassTemplateDecl::B'
-// CHECK-NEXT:  | `-RecordType 0{{.+}} 'testClassTemplateDecl::B'
-// CHECK-NEXT:  |   `-CXXRecord 0x{{.+}} 'B'
-// CHECK-NEXT:  |-CXXRecordDecl 0x{{.+}}  col:20 implicit class TestClassTemplate
-// CHECK-NEXT:  `-FieldDecl 0x{{.+}}  col:9 j 'int'
-
-// CHECK:   ClassTemplateSpecializationDecl 0x{{.+}} <{{.+}}:{{.*}}:3, col:44> col:25 class TestClassTempl

[clang] 6244e38 - [Sema] Add tests for handling of decls hidden by invalid decls

2023-08-17 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-08-17T15:25:53+01:00
New Revision: 6244e3840694e513ef885e8505e7744de8c9b959

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

LOG: [Sema] Add tests for handling of decls hidden by invalid decls

These tests check that invalid declarations don't hide any other
declarations, but valid declarations do hide invalid declarations.

Added: 
clang/test/SemaCXX/invalid-decl-hiding.cpp

Modified: 


Removed: 




diff  --git a/clang/test/SemaCXX/invalid-decl-hiding.cpp 
b/clang/test/SemaCXX/invalid-decl-hiding.cpp
new file mode 100644
index 00..a8c2e8ece06432
--- /dev/null
+++ b/clang/test/SemaCXX/invalid-decl-hiding.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Member Test1 hides class Test1
+class Test1 {
+  static int Test1; // expected-error {{member 'Test1' has the same name as 
its class}}
+// expected-note@-1 {{class 'Test1' is hidden by a 
non-type declaration of 'Test1' here}}
+  void fn1() {
+Test1 x; // expected-error {{must use 'class' tag to refer to type 'Test1' 
in this scope}}
+  }
+  int fn2() {
+return Test1;
+  }
+};
+
+// Member Test2 doesn't hide class Test2 as its declaration is invalid
+class Test2 { // expected-note {{declared here}}
+  static NoSuchType Test2; // expected-error {{unknown type name 'NoSuchType'}}
+   // expected-error@-1 {{member 'Test2' has the same 
name as its class}}
+  void fn1() {
+Test2 x;
+  }
+  int fn2() {
+return Test2; // expected-error {{'Test2' does not refer to a value}}
+  }
+};
+
+// Test3a::x doesn't hide Test3b::x as its declaration is invalid
+namespace Test3a {
+  NoSuchType x() { return 0; } // expected-error {{unknown type name 
'NoSuchType'}}
+}
+namespace Test3b {
+  class x; // expected-note {{declared here}}
+}
+using Test3a::x;
+using Test3b::x;
+int test3_fn() {
+  return x; // expected-error {{'x' does not refer to a value}}
+}
+
+// Function Test4 hides class Test4, whose declaration is invalid
+class Test4 : public NoSuchType { // expected-error {{expected class name}}
+
+};
+int Test4() { return 0; }
+
+int test4_fn() {
+  return Test4();
+}
+
+// Function Test5 doesn't hide class Test5 when both are invalid
+class Test5 : public NoSuchType { // expected-error {{expected class name}}
+
+};
+NoSuchType Test5() { return 0; } // expected-error {{unknown type name 
'NoSuchType'}}
+
+Test5 test5_fn() {
+  Test5 x;
+  return x;
+}



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


[PATCH] D158046: [X86] Support -march=gracemont

2023-08-17 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe marked an inline comment as done.
FreddyYe added inline comments.



Comment at: clang/lib/Basic/Targets/X86.cpp:551
   case CK_Lunarlake:
+  case CK_Gracemont:
   case CK_Sierraforest:

RKSimon wrote:
> Why not handle this above (below tremont) as the next in the *mont series?
Good catch. This isn't a short story... In short words, it was to save codes in 
predefined-arch-macros.c.
If set gracemont as a series of atom processors, macros like 
`corei7`(predefined-arch-macros.c:2061-2062) won't be generated by 
`-march=gracemont`, and for history reasons, atom series processors defined 
some extra macros of their names, like "tremont", "goldmont", ... but these 
macros are not used any longer IIRC. So I decided to define gracemont as a 
non-atom series one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158046

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


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-08-17 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.

I've committed a test for the behaviour when we have invalid decls in 
https://reviews.llvm.org/rG6244e3840694.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154503

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


[PATCH] D157385: [clang][CFG] Cleanup functions

2023-08-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 551131.

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

https://reviews.llvm.org/D157385

Files:
  clang/include/clang/Analysis/CFG.h
  clang/lib/Analysis/CFG.cpp
  clang/lib/Analysis/ThreadSafety.cpp
  clang/test/Analysis/scopes-cfg-output.cpp

Index: clang/test/Analysis/scopes-cfg-output.cpp
===
--- clang/test/Analysis/scopes-cfg-output.cpp
+++ clang/test/Analysis/scopes-cfg-output.cpp
@@ -1419,3 +1419,15 @@
 }
   }
 }
+
+// CHECK:  [B1]
+// CHECK-NEXT:   1: CFGScopeBegin(i)
+// CHECK-NEXT:   2: int i __attribute__((cleanup(cleanup_int)));
+// CHECK-NEXT:   3: CleanupFunction (cleanup_int)
+// CHECK-NEXT:   4: CFGScopeEnd(i)
+void cleanup_int(int *i) {
+}
+
+void test_cleanup_functions() {
+  int i __attribute__((cleanup(cleanup_int)));
+}
Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -2426,6 +2426,16 @@
 AD.getTriggerStmt()->getEndLoc());
   break;
 }
+
+case CFGElement::CleanupFunction: {
+  const CFGCleanupFunction &CF = BI.castAs();
+
+  LocksetBuilder.handleCall(nullptr, CF.getFunctionDecl(),
+SxBuilder.createVariable(CF.getVarDecl()),
+CF.getVarDecl()->getLocation());
+  break;
+}
+
 case CFGElement::TemporaryDtor: {
   auto TD = BI.castAs();
 
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -881,6 +881,10 @@
 B->appendAutomaticObjDtor(VD, S, cfg->getBumpVectorContext());
   }
 
+  void appendCleanupFunction(CFGBlock *B, VarDecl *VD) {
+B->appendCleanupFunction(VD, cfg->getBumpVectorContext());
+  }
+
   void appendLifetimeEnds(CFGBlock *B, VarDecl *VD, Stmt *S) {
 B->appendLifetimeEnds(VD, S, cfg->getBumpVectorContext());
   }
@@ -1346,7 +1350,8 @@
 return {};
   }
 
-  bool hasTrivialDestructor(VarDecl *VD);
+  bool hasTrivialDestructor(VarDecl *VD) const;
+  bool needsAutomaticDestruction(const VarDecl *VD) const;
 };
 
 } // namespace
@@ -1865,7 +1870,7 @@
   DeclsNonTrivial.reserve(B.distance(E));
 
   for (VarDecl* D : llvm::make_range(B, E))
-if (!hasTrivialDestructor(D))
+if (needsAutomaticDestruction(D))
   DeclsNonTrivial.push_back(D);
 
   for (VarDecl *VD : llvm::reverse(DeclsNonTrivial)) {
@@ -1879,18 +1884,24 @@
 Ty = getReferenceInitTemporaryType(VD->getInit());
   Ty = Context->getBaseElementType(Ty);
 
-  if (Ty->getAsCXXRecordDecl()->isAnyDestructorNoReturn())
+  bool IsCXXRecordType = (Ty->getAsCXXRecordDecl() != nullptr);
+  if (IsCXXRecordType &&
+  Ty->getAsCXXRecordDecl()->isAnyDestructorNoReturn())
 Block = createNoReturnBlock();
 }
 
 autoCreateBlock();
 
+bool HasCleanupAttr = VD->hasAttr();
+
 // Add LifetimeEnd after automatic obj with non-trivial destructors,
 // as they end their lifetime when the destructor returns. For trivial
 // objects, we end lifetime with scope end.
 if (BuildOpts.AddLifetime)
   appendLifetimeEnds(Block, VD, S);
-if (BuildOpts.AddImplicitDtors)
+if (HasCleanupAttr)
+  appendCleanupFunction(Block, VD);
+if (BuildOpts.AddImplicitDtors && !hasTrivialDestructor(VD))
   appendAutomaticObjDtor(Block, VD, S);
   }
 }
@@ -2095,7 +2106,12 @@
   return Scope;
 }
 
-bool CFGBuilder::hasTrivialDestructor(VarDecl *VD) {
+bool CFGBuilder::needsAutomaticDestruction(const VarDecl *VD) const {
+  return !hasTrivialDestructor(const_cast(VD)) ||
+ VD->hasAttr();
+}
+
+bool CFGBuilder::hasTrivialDestructor(VarDecl *VD) const {
   // Check for const references bound to temporary. Set type to pointee.
   QualType QT = VD->getType();
   if (QT->isReferenceType()) {
@@ -2149,7 +2165,7 @@
 return Scope;
 
   if (!BuildOpts.AddLifetime && !BuildOpts.AddScopes &&
-  hasTrivialDestructor(VD)) {
+  !needsAutomaticDestruction(VD)) {
 assert(BuildOpts.AddImplicitDtors);
 return Scope;
   }
@@ -5287,8 +5303,9 @@
 case CFGElement::CXXRecordTypedCall:
 case CFGElement::ScopeBegin:
 case CFGElement::ScopeEnd:
-  llvm_unreachable("getDestructorDecl should only be used with "
-   "ImplicitDtors");
+case CFGElement::CleanupFunction:
+llvm_unreachable("getDestructorDecl should only be used with "
+ "ImplicitDtors");
 case CFGElement::AutomaticObjectDtor: {
   const VarDecl *var = castAs().getVarDecl();
   QualType ty = var->getType();
@@ -5830,6 +5847,12 @@
 break;
   }
 
+  case CFGElement::Kind::CleanupFunction: {
+OS << "CleanupFunction ("
+   << E.castAs().getFunctionDecl()->getNam

[PATCH] D157596: [clang][Interp] Handle mixed floating/integral compound assign operators

2023-08-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 551132.

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

https://reviews.llvm.org/D157596

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/floats.cpp

Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -102,6 +102,38 @@
 return a[1];
   }
   static_assert(ff() == 3, "");
+
+  constexpr float intPlusDouble() {
+   int a = 0;
+   a += 2.0;
+
+   return a;
+  }
+  static_assert(intPlusDouble() == 2, "");
+
+  constexpr double doublePlusInt() {
+   double a = 0.0;
+   a += 2;
+
+   return a;
+  }
+  static_assert(doublePlusInt() == 2, "");
+
+  constexpr float boolPlusDouble() {
+   bool a = 0;
+   a += 1.0;
+
+   return a;
+  }
+  static_assert(boolPlusDouble(), "");
+
+  constexpr bool doublePlusbool() {
+   double a = 0.0;
+   a += true;
+
+   return a;
+  }
+  static_assert(doublePlusbool() == 1.0, "");
 }
 
 namespace unary {
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -276,6 +276,7 @@
 return FPO.getRoundingMode();
   }
 
+  bool emitPrimCast(PrimType FromT, PrimType ToT, QualType ToQT, const Expr *E);
   bool emitRecordDestruction(const Descriptor *Desc);
   bool emitDerivedToBaseCasts(const RecordType *DerivedType,
   const RecordType *BaseType, const Expr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -986,19 +986,22 @@
 template 
 bool ByteCodeExprGen::VisitFloatCompoundAssignOperator(
 const CompoundAssignOperator *E) {
-  assert(E->getType()->isFloatingType());
 
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
-  llvm::RoundingMode RM = getRoundingMode(E);
+  QualType LHSType = LHS->getType();
   QualType LHSComputationType = E->getComputationLHSType();
   QualType ResultType = E->getComputationResultType();
   std::optional LT = classify(LHSComputationType);
   std::optional RT = classify(ResultType);
 
+  assert(ResultType->isFloatingType());
+
   if (!LT || !RT)
 return false;
 
+  PrimType LHST = classifyPrim(LHSType);
+
   // C++17 onwards require that we evaluate the RHS first.
   // Compute RHS and save it in a temporary variable so we can
   // load it again later.
@@ -1012,21 +1015,19 @@
   // First, visit LHS.
   if (!visit(LHS))
 return false;
-  if (!this->emitLoad(*LT, E))
+  if (!this->emitLoad(LHST, E))
 return false;
 
   // If necessary, convert LHS to its computation type.
-  if (LHS->getType() != LHSComputationType) {
-const auto *TargetSemantics = &Ctx.getFloatSemantics(LHSComputationType);
-
-if (!this->emitCastFP(TargetSemantics, RM, E))
-  return false;
-  }
+  if (!this->emitPrimCast(LHST, classifyPrim(LHSComputationType),
+  LHSComputationType, E))
+return false;
 
   // Now load RHS.
   if (!this->emitGetLocal(*RT, TempOffset, E))
 return false;
 
+  llvm::RoundingMode RM = getRoundingMode(E);
   switch (E->getOpcode()) {
   case BO_AddAssign:
 if (!this->emitAddf(RM, E))
@@ -1048,17 +1049,12 @@
 return false;
   }
 
-  // If necessary, convert result to LHS's type.
-  if (LHS->getType() != ResultType) {
-const auto *TargetSemantics = &Ctx.getFloatSemantics(LHS->getType());
-
-if (!this->emitCastFP(TargetSemantics, RM, E))
-  return false;
-  }
+  if (!this->emitPrimCast(classifyPrim(ResultType), LHST, LHS->getType(), E))
+return false;
 
   if (DiscardResult)
-return this->emitStorePop(*LT, E);
-  return this->emitStore(*LT, E);
+return this->emitStorePop(LHST, E);
+  return this->emitStore(LHST, E);
 }
 
 template 
@@ -1100,14 +1096,6 @@
 bool ByteCodeExprGen::VisitCompoundAssignOperator(
 const CompoundAssignOperator *E) {
 
-  // Handle floating point operations separately here, since they
-  // require special care.
-  if (E->getType()->isFloatingType())
-return VisitFloatCompoundAssignOperator(E);
-
-  if (E->getType()->isPointerType())
-return VisitPointerCompoundAssignOperator(E);
-
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
   std::optional LHSComputationT =
@@ -1120,6 +1108,15 @@
   if (!LT || !RT || !RHST || !ResultT || !LHSComputationT)
 return false;
 
+  // Handle floating point operations separately here, since they
+  // require special care.
+
+  if (ResultT == PT_Float || RT == PT_Float)
+return VisitFloatCompoundAssignOperator(E);
+
+  if (E->getType()->isPointerType())
+return VisitPointerCompoundAssignOperator(E);
+
   assert(!E->getType()->isPointerType() && "Handled above");
   assert

[PATCH] D158152: [clang-tidy]mark record initList as non-const param

2023-08-17 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:234
 
+- Improved :doc:`readability-non-const-parameter.cpp
+  ` check to ignore

Please keep alphabetical order (by check name) in this section.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158152

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


[PATCH] D153156: [Clang] CWG1473: do not err on the lack of space after operator""

2023-08-17 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao updated this revision to Diff 551138.
rZhBoYao marked 2 inline comments as done.
rZhBoYao added a comment.

Thank Aaron and Vlad for reviewing this! Just updating the diff to reflect the 
final version.


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

https://reviews.llvm.org/D153156

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Lex/Lexer.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/drs/dr17xx.cpp
  clang/test/CXX/drs/dr25xx.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p1.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p10.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p11.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p3.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p4.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p5.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p6.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p7.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p8.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p9.cpp
  clang/test/CXX/over/over.oper/over.literal/p2.cpp
  clang/test/CXX/over/over.oper/over.literal/p3.cpp
  clang/test/CXX/over/over.oper/over.literal/p5.cpp
  clang/test/CXX/over/over.oper/over.literal/p6.cpp
  clang/test/CXX/over/over.oper/over.literal/p7.cpp
  clang/test/CXX/over/over.oper/over.literal/p8.cpp
  clang/test/CodeGenCXX/cxx11-user-defined-literal.cpp
  clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
  clang/test/FixIt/fixit-c++11.cpp
  clang/test/OpenMP/amdgcn_ldbl_check.cpp
  clang/test/PCH/cxx11-user-defined-literals.cpp
  clang/test/Parser/cxx0x-literal-operators.cpp
  clang/test/Parser/cxx11-user-defined-literals.cpp
  clang/test/SemaCXX/cxx11-ast-print.cpp
  clang/test/SemaCXX/cxx11-user-defined-literals-unused.cpp
  clang/test/SemaCXX/cxx11-user-defined-literals.cpp
  clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
  clang/test/SemaCXX/cxx1z-user-defined-literals.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  clang/test/SemaCXX/cxx98-compat.cpp
  clang/test/SemaCXX/literal-operators.cpp
  clang/test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
  clang/test/SemaCXX/reserved-identifier.cpp
  clang/test/SemaCXX/warn-xor-as-pow.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -8645,7 +8645,7 @@
 https://cplusplus.github.io/CWG/issues/1473.html";>1473
 CD3
 Syntax of literal-operator-id
-Unknown
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/1474.html";>1474
Index: clang/test/SemaCXX/warn-xor-as-pow.cpp
===
--- clang/test/SemaCXX/warn-xor-as-pow.cpp
+++ clang/test/SemaCXX/warn-xor-as-pow.cpp
@@ -19,10 +19,10 @@
 #define flexor 7
 
 #ifdef __cplusplus
-constexpr long long operator"" _xor(unsigned long long v) { return v; }
+constexpr long long operator""_xor(unsigned long long v) { return v; }
 
-constexpr long long operator"" _0b(unsigned long long v) { return v; }
-constexpr long long operator"" _0X(unsigned long long v) { return v; }
+constexpr long long operator""_0b(unsigned long long v) { return v; }
+constexpr long long operator""_0X(unsigned long long v) { return v; }
 #else
 #define xor ^ // iso646.h
 #endif
Index: clang/test/SemaCXX/reserved-identifier.cpp
===
--- clang/test/SemaCXX/reserved-identifier.cpp
+++ clang/test/SemaCXX/reserved-identifier.cpp
@@ -89,7 +89,6 @@
 long double sacrebleu = operator"" _SacreBleu(1.2); // expected-warning {{identifier '_SacreBleu' is reserved because it starts with '_' followed by a capital letter}}
 long double sangbleu = operator""_SacreBleu(1.2);   // no-warning
 
-void operator"" _lowercase(unsigned long long); // no-warning
 void operator""_lowercase(unsigned long long); // no-warning
 
 struct _BarbeRouge { // expected-warning {{identifier '_BarbeRouge' is reserved because it starts with '_' followed by a capital letter}}
Index: clang/test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
===
--- clang/test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
+++ clang/test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
@@ -2,4 +2,4 @@
 
 #include 
 
-void operator "" bar(long double); // expected-warning{{user-defined literal suffixes not starting with '_' are reserved}}
+void operator ""bar(long double); // expected-warning{{user-defined literal suffixes not starting with '_' are reserved}}
Index: clang/test/SemaCXX/literal-operators.cpp
===
--- clang/test/SemaCXX/literal-operators.cpp
+++ clang/test/SemaCXX/literal-operators.cpp
@@ -3,46 +3,46 @@
 #include 
 
 struct tag {
-  void operator "" _tag_bad (const char *); 

[PATCH] D153156: [Clang] CWG1473: do not err on the lack of space after operator""

2023-08-17 Thread PoYao Chang 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 rGf2583f3acf59: [Clang] CWG1473: do not err on the lack of 
space after operator"" (authored by rZhBoYao).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153156

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Lex/Lexer.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/drs/dr17xx.cpp
  clang/test/CXX/drs/dr25xx.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p1.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p10.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p11.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p3.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p4.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p5.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p6.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p7.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p8.cpp
  clang/test/CXX/lex/lex.literal/lex.ext/p9.cpp
  clang/test/CXX/over/over.oper/over.literal/p2.cpp
  clang/test/CXX/over/over.oper/over.literal/p3.cpp
  clang/test/CXX/over/over.oper/over.literal/p5.cpp
  clang/test/CXX/over/over.oper/over.literal/p6.cpp
  clang/test/CXX/over/over.oper/over.literal/p7.cpp
  clang/test/CXX/over/over.oper/over.literal/p8.cpp
  clang/test/CodeGenCXX/cxx11-user-defined-literal.cpp
  clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
  clang/test/FixIt/fixit-c++11.cpp
  clang/test/OpenMP/amdgcn_ldbl_check.cpp
  clang/test/PCH/cxx11-user-defined-literals.cpp
  clang/test/Parser/cxx0x-literal-operators.cpp
  clang/test/Parser/cxx11-user-defined-literals.cpp
  clang/test/SemaCXX/cxx11-ast-print.cpp
  clang/test/SemaCXX/cxx11-user-defined-literals-unused.cpp
  clang/test/SemaCXX/cxx11-user-defined-literals.cpp
  clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
  clang/test/SemaCXX/cxx1z-user-defined-literals.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  clang/test/SemaCXX/cxx98-compat.cpp
  clang/test/SemaCXX/literal-operators.cpp
  clang/test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
  clang/test/SemaCXX/reserved-identifier.cpp
  clang/test/SemaCXX/warn-xor-as-pow.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -8645,7 +8645,7 @@
 https://cplusplus.github.io/CWG/issues/1473.html";>1473
 CD3
 Syntax of literal-operator-id
-Unknown
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/1474.html";>1474
Index: clang/test/SemaCXX/warn-xor-as-pow.cpp
===
--- clang/test/SemaCXX/warn-xor-as-pow.cpp
+++ clang/test/SemaCXX/warn-xor-as-pow.cpp
@@ -19,10 +19,10 @@
 #define flexor 7
 
 #ifdef __cplusplus
-constexpr long long operator"" _xor(unsigned long long v) { return v; }
+constexpr long long operator""_xor(unsigned long long v) { return v; }
 
-constexpr long long operator"" _0b(unsigned long long v) { return v; }
-constexpr long long operator"" _0X(unsigned long long v) { return v; }
+constexpr long long operator""_0b(unsigned long long v) { return v; }
+constexpr long long operator""_0X(unsigned long long v) { return v; }
 #else
 #define xor ^ // iso646.h
 #endif
Index: clang/test/SemaCXX/reserved-identifier.cpp
===
--- clang/test/SemaCXX/reserved-identifier.cpp
+++ clang/test/SemaCXX/reserved-identifier.cpp
@@ -89,7 +89,6 @@
 long double sacrebleu = operator"" _SacreBleu(1.2); // expected-warning {{identifier '_SacreBleu' is reserved because it starts with '_' followed by a capital letter}}
 long double sangbleu = operator""_SacreBleu(1.2);   // no-warning
 
-void operator"" _lowercase(unsigned long long); // no-warning
 void operator""_lowercase(unsigned long long); // no-warning
 
 struct _BarbeRouge { // expected-warning {{identifier '_BarbeRouge' is reserved because it starts with '_' followed by a capital letter}}
Index: clang/test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
===
--- clang/test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
+++ clang/test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
@@ -2,4 +2,4 @@
 
 #include 
 
-void operator "" bar(long double); // expected-warning{{user-defined literal suffixes not starting with '_' are reserved}}
+void operator ""bar(long double); // expected-warning{{user-defined literal suffixes not starting with '_' are reserved}}
Index: clang/test/SemaCXX/literal-operators.cpp
===
--- clang/test/SemaCXX/literal-operators.cpp
+++ clang/test/SemaCXX/literal-operators.cpp
@@ -3,46 +

[clang] f2583f3 - [Clang] CWG1473: do not err on the lack of space after operator""

2023-08-17 Thread Po-yao Chang via cfe-commits

Author: Po-yao Chang
Date: 2023-08-17T23:10:37+08:00
New Revision: f2583f3acf596cc545c8c0e3cb28e712f4ebf21b

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

LOG: [Clang] CWG1473: do not err on the lack of space after operator""

In addition:
  1. Fix tests for CWG2521 deprecation warning.
  2. Enable -Wdeprecated-literal-operator by default.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr17xx.cpp
clang/test/CXX/drs/dr25xx.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p1.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p10.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p11.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p3.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p4.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p5.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p6.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p7.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p8.cpp
clang/test/CXX/lex/lex.literal/lex.ext/p9.cpp
clang/test/CXX/over/over.oper/over.literal/p2.cpp
clang/test/CXX/over/over.oper/over.literal/p3.cpp
clang/test/CXX/over/over.oper/over.literal/p5.cpp
clang/test/CXX/over/over.oper/over.literal/p6.cpp
clang/test/CXX/over/over.oper/over.literal/p7.cpp
clang/test/CXX/over/over.oper/over.literal/p8.cpp
clang/test/CodeGenCXX/cxx11-user-defined-literal.cpp
clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
clang/test/FixIt/fixit-c++11.cpp
clang/test/OpenMP/amdgcn_ldbl_check.cpp
clang/test/PCH/cxx11-user-defined-literals.cpp
clang/test/Parser/cxx0x-literal-operators.cpp
clang/test/Parser/cxx11-user-defined-literals.cpp
clang/test/SemaCXX/cxx11-ast-print.cpp
clang/test/SemaCXX/cxx11-user-defined-literals-unused.cpp
clang/test/SemaCXX/cxx11-user-defined-literals.cpp
clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
clang/test/SemaCXX/cxx1z-user-defined-literals.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
clang/test/SemaCXX/cxx98-compat.cpp
clang/test/SemaCXX/literal-operators.cpp
clang/test/SemaCXX/no-warn-user-defined-literals-in-system-headers.cpp
clang/test/SemaCXX/reserved-identifier.cpp
clang/test/SemaCXX/warn-xor-as-pow.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1bfca926bf92a9..62c4ecdb32d8b7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -92,6 +92,10 @@ C++2c Feature Support
 
 Resolutions to C++ Defect Reports
 ^
+- Implemented `CWG1473 `_ which allows spaces after 
``operator""``.
+  Clang used to err on the lack of space when the literal suffix identifier 
was invalid in
+  all the language modes, which contradicted the deprecation of the 
whitespaces.
+  Also turn on ``-Wdeprecated-literal-operator`` by default in all the 
language modes.
 
 C Language Changes
 --

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 940cca67368492..c5da98c4f0001e 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -276,12 +276,6 @@ def warn_cxx11_compat_reserved_user_defined_literal : 
Warning<
   "identifier after literal will be treated as a reserved user-defined literal 
"
   "suffix in C++11">,
   InGroup, DefaultIgnore;
-def ext_reserved_user_defined_literal : ExtWarn<
-  "invalid suffix on literal; C++11 requires a space between literal and "
-  "identifier">, InGroup, DefaultError;
-def ext_ms_reserved_user_defined_literal : ExtWarn<
-  "invalid suffix on literal; C++11 requires a space between literal and "
-  "identifier">, InGroup;
 def err_unsupported_string_concat : Error<
   "unsupported non-standard concatenation of string literals">;
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8c629aad89f48a..a30266d09dca7c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -411,7 +411,7 @@ def warn_reserved_extern_symbol: Warning<
   InGroup, DefaultIgnore;
 def warn_deprecated_literal_operator_id: Warning<
   "identifier %0 preceded by whitespace in a literal operator declaration "
-  "is deprecated">, InGroup, DefaultIgnore;
+  "is deprecated">, InGroup;
 def warn_reserved_module_name : Warning<
   "%0 is a reserved name for a module">, InGroup;
 

diff  --git a/clang/lib/Le

[PATCH] D156571: [DebugInfo] Alternate MD5 fix, NFC

2023-08-17 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

Thanks! Can confirm that this recovers the compile-time regression.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156571

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


[PATCH] D158188: [clang][AST] TextNodeDumper learned to output friend information for functions

2023-08-17 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158188

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/CXX/class/class.friend/p7-cxx20.cpp


Index: clang/test/CXX/class/class.friend/p7-cxx20.cpp
===
--- clang/test/CXX/class/class.friend/p7-cxx20.cpp
+++ clang/test/CXX/class/class.friend/p7-cxx20.cpp
@@ -19,7 +19,7 @@
 // CHECK-NM: `-CXXRecordDecl {{.*}}  line:2:7 
class X definition
 // CHECK-NM:   |-CXXRecordDecl {{.*}}  col:7 implicit class X
 // CHECK-NM-NEXT: `-FriendDecl {{.*}}  col:15
-// CHECK-NM-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 x 
'void ()' implicit-inline
+// CHECK-NM-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 
friend_undeclared x 'void ()' implicit-inline
 
 //--- header-unit.h
 
@@ -30,7 +30,7 @@
 // CHECK-HU: `-CXXRecordDecl {{.*}} <./header-unit.h:2:1, line:4:1> line:2:7 
class Y definition
 // CHECK-HU: |-CXXRecordDecl {{.*}}  col:7 implicit class Y
 // CHECK-HU-NEXT: `-FriendDecl {{.*}}  col:15
-// CHECK-HU-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 y 
'void ()' implicit-inline
+// CHECK-HU-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 
friend_undeclared y 'void ()' implicit-inline
 
 // A textually-included header
 //--- header.h
@@ -51,9 +51,9 @@
 // CHECK-MOD: |-CXXRecordDecl {{.*}} <./header.h:2:1, line:4:1> line:2:7 in 
M. hidden class A definition
 // CHECK-MOD: | |-CXXRecordDecl {{.*}}  col:7 in M. 
hidden implicit class A
 // CHECK-MOD-NEXT: | `-FriendDecl {{.*}}  col:15 in 
M.
-// CHECK-MOD-NEXT: |   `-FunctionDecl {{.*}} parent {{.*}}  
col:15 in M. hidden a 'void ()' implicit-inline
+// CHECK-MOD-NEXT: |   `-FunctionDecl {{.*}} parent {{.*}}  
col:15 in M. hidden friend_undeclared a 'void ()' implicit-inline
 
 // CHECK-MOD: `-CXXRecordDecl {{.*}}  line:6:7 in M 
hidden class Z{{( ReachableWhenImported)?}} definition
 // CHECK-MOD: |-CXXRecordDecl {{.*}}  col:7 in M hidden implicit 
class Z{{( ReachableWhenImported)?}}
 // CHECK-MOD-NEXT: `-FriendDecl {{.*}}  col:15 in M{{( 
ReachableWhenImported)?}}
-// CHECK-MOD-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 
in M hidden z 'void ()'{{( ReachableWhenImported)?}}
+// CHECK-MOD-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 
in M hidden friend_undeclared z 'void ()'{{( ReachableWhenImported)?}}
Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -525,7 +525,7 @@
   // CHECK-NEXT: | | `-Destructor simple irrelevant trivial needs_implicit{{$}}
   // CHECK-NEXT: | |-CXXRecordDecl 0x{{.+}}  col:31 implicit 
class TestClassTemplate{{$}}
   // CHECK-NEXT: | `-FriendDecl 0x{{.+}}  
col:40{{$}}
-  // CHECK-NEXT: |   `-ClassTemplateDecl 0x{{.+}} parent 0x{{.+}}  col:40 TestClassTemplate{{$}}
+  // CHECK-NEXT: |   `-ClassTemplateDecl 0x{{.+}} parent 0x{{.+}}  col:40 friend_undeclared TestClassTemplate{{$}}
   // CHECK-NEXT: | |-TemplateTypeParmDecl 0x{{.+}}  col:23 
typename depth 1 index 0 T2{{$}}
   // CHECK-NEXT: | `-CXXRecordDecl 0x{{.+}} parent 0x{{.+}}  col:40 class TestClassTemplate{{$}}
   // CHECK-NEXT: `-ClassTemplateSpecializationDecl 0x{{.+}} 
 line:[[@LINE-19]]:31 class 
TestClassTemplate definition implicit_instantiation{{$}}
@@ -541,7 +541,7 @@
   // CHECK-NEXT:   |   `-CXXRecord 0x{{.+}} 'A'{{$}}
   // CHECK-NEXT:   |-CXXRecordDecl 0x{{.+}}  col:31 implicit 
class TestClassTemplate{{$}}
   // CHECK-NEXT:   |-FriendDecl 0x{{.+}}  
col:40{{$}}
-  // CHECK-NEXT:   | `-ClassTemplateDecl 0x{{.+}} parent 0x{{.+}} prev 
0x{{.+}}  col:40 TestClassTemplate{{$}}
+  // CHECK-NEXT:   | `-ClassTemplateDecl 0x{{.+}} parent 0x{{.+}} prev 
0x{{.+}}  col:40 friend TestClassTemplate{{$}}
   // CHECK-NEXT:   |   |-TemplateTypeParmDecl 0x{{.+}}  col:23 
typename depth 0 index 0 T2{{$}}
   // CHECK-NEXT:   |   |-CXXRecordDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} 
 col:40 class TestClassTemplate{{$}}
   // CHECK-NEXT:   |   `-ClassTemplateSpecialization 0x{{.+}} 
'TestClassTemplate'{{$}}
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -300,6 +300,17 @@
 }
   }
 
+  switch (D->getFriendObjectKind()) {
+  case Decl::FOK_None:
+break;
+  case Decl::FOK_Declared:
+OS << " friend";
+break;
+  case Decl::FOK_Undeclared:
+OS << " friend_undeclared";
+break;
+  }
+
   ConstDeclVisitor::Visit(D);
 }
 


Index: clang/test/CXX/class/class.friend/p7-cxx20.cpp
===
--- clang/test/CXX/class/class.friend/p7-cxx20.cpp
+++ c

  1   2   3   >