[PATCH] D111971: [clang] Allocate 2 bits to store the constexpr specifier kind when serializing

2021-11-13 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 387057.
nridge added a comment.

Reworked test to use the framework in clang/test/AST


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111971

Files:
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/AST/ast-dump-constant-expr.cpp

Index: clang/test/AST/ast-dump-constant-expr.cpp
===
--- clang/test/AST/ast-dump-constant-expr.cpp
+++ clang/test/AST/ast-dump-constant-expr.cpp
@@ -6,6 +6,7 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -x c++ -std=c++20 -triple x86_64-unknown-unknown -include-pch %t \
 // RUN: -ast-dump-all -ast-dump-filter Test /dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
 
 // FIXME: ASTRecordReader::readAPValue and ASTRecordWriter::AddAPValue
@@ -39,47 +40,54 @@
 // FIXME: consteval U test_Union() { return U(); }
 // FIXME: consteval SU test_SU() { return SU(); }
 
-void Test() {
-  (void) test_Int();
-  (void) test_Float();
-  (void) test_ComplexInt();
-  (void) test_ComplexFloat();
-  (void) test_Int128();
-  //(void) test_Array();
-  //(void) test_Struct();
-  //(void) test_Union();
-  //(void) test_SU();
-}
+struct Test {
+  void test() {
+(void)test_Int();
+(void)test_Float();
+(void)test_ComplexInt();
+(void)test_ComplexFloat();
+(void)test_Int128();
+//(void) test_Array();
+//(void) test_Struct();
+//(void) test_Union();
+//(void) test_SU();
+  }
+
+  consteval void consteval_method() {}
+};
+
 // CHECK:Dumping Test:
-// CHECK-NEXT:FunctionDecl {{.*}} <{{.*}}ast-dump-constant-expr.cpp:42:1, line:52:1> line:42:6{{( imported)?}} Test 'void ()'
-// CHECK-NEXT:`-CompoundStmt {{.*}} 
-// CHECK-NEXT:  |-CStyleCastExpr {{.*}}  'void' 
-// CHECK-NEXT:  | `-ConstantExpr {{.*}}  'int'
-// CHECK-NEXT:  |   |-value: Int 42
-// CHECK-NEXT:  |   `-CallExpr {{.*}}  'int'
-// CHECK-NEXT:  | `-ImplicitCastExpr {{.*}}  'int (*)()' 
-// CHECK-NEXT:  |   `-DeclRefExpr {{.*}}  'int ()' lvalue Function {{.*}} 'test_Int' 'int ()'
-// CHECK-NEXT:  |-CStyleCastExpr {{.*}}  'void' 
-// CHECK-NEXT:  | `-ConstantExpr {{.*}}  'float'
-// CHECK-NEXT:  |   |-value: Float 1.00e+00
-// CHECK-NEXT:  |   `-CallExpr {{.*}}  'float'
-// CHECK-NEXT:  | `-ImplicitCastExpr {{.*}}  'float (*)()' 
-// CHECK-NEXT:  |   `-DeclRefExpr {{.*}}  'float ()' lvalue Function {{.*}} 'test_Float' 'float ()'
-// CHECK-NEXT:  |-CStyleCastExpr {{.*}}  'void' 
-// CHECK-NEXT:  | `-ConstantExpr {{.*}}  '_Complex int'
-// CHECK-NEXT:  |   |-value: ComplexInt 1 + 2i
-// CHECK-NEXT:  |   `-CallExpr {{.*}}  '_Complex int'
-// CHECK-NEXT:  | `-ImplicitCastExpr {{.*}}  '_Complex int (*)()' 
-// CHECK-NEXT:  |   `-DeclRefExpr {{.*}}  '_Complex int ()' lvalue Function {{.*}} 'test_ComplexInt' '_Complex int ()'
-// CHECK-NEXT:  |-CStyleCastExpr {{.*}}  'void' 
-// CHECK-NEXT:  | `-ConstantExpr {{.*}}  '_Complex float'
-// CHECK-NEXT:  |   |-value: ComplexFloat 1.20e+00 + 3.40e+00i
-// CHECK-NEXT:  |   `-CallExpr {{.*}}  '_Complex float'
-// CHECK-NEXT:  | `-ImplicitCastExpr {{.*}}  '_Complex float (*)()' 
-// CHECK-NEXT:  |   `-DeclRefExpr {{.*}}  '_Complex float ()' lvalue Function {{.*}} 'test_ComplexFloat' '_Complex float ()'
-// CHECK-NEXT:  `-CStyleCastExpr {{.*}}  'void' 
-// CHECK-NEXT:`-ConstantExpr {{.*}}  '__int128'
-// CHECK-NEXT:  |-value: Int 18446744073709551616
-// CHECK-NEXT:  `-CallExpr {{.*}}  '__int128'
-// CHECK-NEXT:`-ImplicitCastExpr {{.*}}  '__int128 (*)()' 
-// CHECK-NEXT:  `-DeclRefExpr {{.*}}  '__int128 ()' lvalue Function {{.*}} 'test_Int128' '__int128 ()'
+// CHECK-NEXT:CXXRecordDecl {{.*}} <{{.*}}ast-dump-constant-expr.cpp:43:1, line:57:1> line:43:8 struct Test definition
+// CHECK:|-CXXMethodDecl {{.*}}  line:44:8 test 'void ()'
+// CHECK-NEXT:| `-CompoundStmt {{.*}} 
+// CHECK-NEXT:|   |-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT:|   | `-ConstantExpr {{.*}}  'int'
+// CHECK-NEXT:|   |   |-value: Int 42
+// CHECK-NEXT:|   |   `-CallExpr {{.*}}  'int'
+// CHECK-NEXT:|   | `-ImplicitCastExpr {{.*}}  'int (*)()' 
+// CHECK-NEXT:|   |   `-DeclRefExpr {{.*}}  'int ()' lvalue Function {{.*}} 'test_Int' 'int ()'
+// CHECK-NEXT:|   |-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT:|   | `-ConstantExpr {{.*}}  'float'
+// CHECK-NEXT:|   |   |-value: Float 1.00e+00
+// CHECK-NEXT:|   |   `-CallExpr {{.*}}  'float'
+// CHECK-NEXT:|   | `-ImplicitCastExpr {{.*}}  'float (*)()' 
+// CHECK-NEXT:|   |   `-DeclRefExpr {{.*}}  'float ()' lvalue Function {{.*}} 'test_Float' 'float ()'
+// CHECK-NEXT:|   |-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT:|   | `-ConstantExpr {{.*}}  '_Complex int'
+// CHECK-NEXT:|   |   |-value: ComplexInt 1 + 2i
+// CHECK-NEXT:|   |   `-CallExpr {{.*}}  '_Com

[PATCH] D111971: [clang] Allocate 2 bits to store the constexpr specifier kind when serializing

2021-11-13 Thread Nathan Ridge via Phabricator via cfe-commits
nridge requested review of this revision.
nridge added a comment.

Sorry for the delay here.

@adamcz could you kindly have another look to make sure the test changes look 
ok?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111971

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


[PATCH] D111971: [clang] Allocate 2 bits to store the constexpr specifier kind when serializing

2021-11-17 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz accepted this revision.
adamcz added a comment.
This revision is now accepted and ready to land.

Looks good. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111971

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


[PATCH] D111971: [clang] Allocate 2 bits to store the constexpr specifier kind when serializing

2021-11-17 Thread Nathan Ridge 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 rG7a8c7946fc3a: [clang] Allocate 2 bits to store the constexpr 
specifier kind when serializing (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111971

Files:
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/AST/ast-dump-constant-expr.cpp

Index: clang/test/AST/ast-dump-constant-expr.cpp
===
--- clang/test/AST/ast-dump-constant-expr.cpp
+++ clang/test/AST/ast-dump-constant-expr.cpp
@@ -6,6 +6,7 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -x c++ -std=c++20 -triple x86_64-unknown-unknown -include-pch %t \
 // RUN: -ast-dump-all -ast-dump-filter Test /dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
 
 // FIXME: ASTRecordReader::readAPValue and ASTRecordWriter::AddAPValue
@@ -39,47 +40,54 @@
 // FIXME: consteval U test_Union() { return U(); }
 // FIXME: consteval SU test_SU() { return SU(); }
 
-void Test() {
-  (void) test_Int();
-  (void) test_Float();
-  (void) test_ComplexInt();
-  (void) test_ComplexFloat();
-  (void) test_Int128();
-  //(void) test_Array();
-  //(void) test_Struct();
-  //(void) test_Union();
-  //(void) test_SU();
-}
+struct Test {
+  void test() {
+(void)test_Int();
+(void)test_Float();
+(void)test_ComplexInt();
+(void)test_ComplexFloat();
+(void)test_Int128();
+//(void) test_Array();
+//(void) test_Struct();
+//(void) test_Union();
+//(void) test_SU();
+  }
+
+  consteval void consteval_method() {}
+};
+
 // CHECK:Dumping Test:
-// CHECK-NEXT:FunctionDecl {{.*}} <{{.*}}ast-dump-constant-expr.cpp:42:1, line:52:1> line:42:6{{( imported)?}} Test 'void ()'
-// CHECK-NEXT:`-CompoundStmt {{.*}} 
-// CHECK-NEXT:  |-CStyleCastExpr {{.*}}  'void' 
-// CHECK-NEXT:  | `-ConstantExpr {{.*}}  'int'
-// CHECK-NEXT:  |   |-value: Int 42
-// CHECK-NEXT:  |   `-CallExpr {{.*}}  'int'
-// CHECK-NEXT:  | `-ImplicitCastExpr {{.*}}  'int (*)()' 
-// CHECK-NEXT:  |   `-DeclRefExpr {{.*}}  'int ()' lvalue Function {{.*}} 'test_Int' 'int ()'
-// CHECK-NEXT:  |-CStyleCastExpr {{.*}}  'void' 
-// CHECK-NEXT:  | `-ConstantExpr {{.*}}  'float'
-// CHECK-NEXT:  |   |-value: Float 1.00e+00
-// CHECK-NEXT:  |   `-CallExpr {{.*}}  'float'
-// CHECK-NEXT:  | `-ImplicitCastExpr {{.*}}  'float (*)()' 
-// CHECK-NEXT:  |   `-DeclRefExpr {{.*}}  'float ()' lvalue Function {{.*}} 'test_Float' 'float ()'
-// CHECK-NEXT:  |-CStyleCastExpr {{.*}}  'void' 
-// CHECK-NEXT:  | `-ConstantExpr {{.*}}  '_Complex int'
-// CHECK-NEXT:  |   |-value: ComplexInt 1 + 2i
-// CHECK-NEXT:  |   `-CallExpr {{.*}}  '_Complex int'
-// CHECK-NEXT:  | `-ImplicitCastExpr {{.*}}  '_Complex int (*)()' 
-// CHECK-NEXT:  |   `-DeclRefExpr {{.*}}  '_Complex int ()' lvalue Function {{.*}} 'test_ComplexInt' '_Complex int ()'
-// CHECK-NEXT:  |-CStyleCastExpr {{.*}}  'void' 
-// CHECK-NEXT:  | `-ConstantExpr {{.*}}  '_Complex float'
-// CHECK-NEXT:  |   |-value: ComplexFloat 1.20e+00 + 3.40e+00i
-// CHECK-NEXT:  |   `-CallExpr {{.*}}  '_Complex float'
-// CHECK-NEXT:  | `-ImplicitCastExpr {{.*}}  '_Complex float (*)()' 
-// CHECK-NEXT:  |   `-DeclRefExpr {{.*}}  '_Complex float ()' lvalue Function {{.*}} 'test_ComplexFloat' '_Complex float ()'
-// CHECK-NEXT:  `-CStyleCastExpr {{.*}}  'void' 
-// CHECK-NEXT:`-ConstantExpr {{.*}}  '__int128'
-// CHECK-NEXT:  |-value: Int 18446744073709551616
-// CHECK-NEXT:  `-CallExpr {{.*}}  '__int128'
-// CHECK-NEXT:`-ImplicitCastExpr {{.*}}  '__int128 (*)()' 
-// CHECK-NEXT:  `-DeclRefExpr {{.*}}  '__int128 ()' lvalue Function {{.*}} 'test_Int128' '__int128 ()'
+// CHECK-NEXT:CXXRecordDecl {{.*}} <{{.*}}ast-dump-constant-expr.cpp:43:1, line:57:1> line:43:8 struct Test definition
+// CHECK:|-CXXMethodDecl {{.*}}  line:44:8 test 'void ()'
+// CHECK-NEXT:| `-CompoundStmt {{.*}} 
+// CHECK-NEXT:|   |-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT:|   | `-ConstantExpr {{.*}}  'int'
+// CHECK-NEXT:|   |   |-value: Int 42
+// CHECK-NEXT:|   |   `-CallExpr {{.*}}  'int'
+// CHECK-NEXT:|   | `-ImplicitCastExpr {{.*}}  'int (*)()' 
+// CHECK-NEXT:|   |   `-DeclRefExpr {{.*}}  'int ()' lvalue Function {{.*}} 'test_Int' 'int ()'
+// CHECK-NEXT:|   |-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT:|   | `-ConstantExpr {{.*}}  'float'
+// CHECK-NEXT:|   |   |-value: Float 1.00e+00
+// CHECK-NEXT:|   |   `-CallExpr {{.*}}  'float'
+// CHECK-NEXT:|   | `-ImplicitCastExpr {{.*}}  'float (*)()' 
+// CHECK-NEXT:|   |   `-DeclRefExpr {{.*}}  'float ()' lvalue Function {{.*}} 'test_Float' 'float ()'
+// CHECK-NEXT:|   |-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT:

[PATCH] D111971: [clang] Allocate 2 bits to store the constexpr specifier kind when serializing

2021-10-17 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
nridge requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

Now that consteval and constinit are possible values, 1 bit
is no longer enough.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111971

Files:
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp


Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2260,7 +2260,7 @@
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
-  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Constexpr
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // UsesSEHTry
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // MultiVersion
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -672,6 +672,24 @@
   ElementsAre(AllOf(Diag(Test.range(), "'main' must return 'int'"),
 Not(WithFix(_);
 }
+TEST(DiagnosticsTest, Consteval) {
+  Annotations Header(R"cpp(
+struct Container {
+  consteval Container() {
+Push();
+  }
+  consteval void Push() {}
+};
+  )cpp");
+  Annotations Main(R"cpp(
+#include "a.h"
+constexpr Container c = Container();
+  )cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.ExtraArgs.push_back("-std=c++20");
+  TU.AdditionalFiles = {{"a.h", std::string(Header.code())}};
+  EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
+}
 
 TEST(ClangdTest, MSAsm) {
   // Parsing MS assembly tries to use the target MCAsmInfo, which we don't 
link.


Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2260,7 +2260,7 @@
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
-  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Constexpr
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // UsesSEHTry
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // MultiVersion
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -672,6 +672,24 @@
   ElementsAre(AllOf(Diag(Test.range(), "'main' must return 'int'"),
 Not(WithFix(_);
 }
+TEST(DiagnosticsTest, Consteval) {
+  Annotations Header(R"cpp(
+struct Container {
+  consteval Container() {
+Push();
+  }
+  consteval void Push() {}
+};
+  )cpp");
+  Annotations Main(R"cpp(
+#include "a.h"
+constexpr Container c = Container();
+  )cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.ExtraArgs.push_back("-std=c++20");
+  TU.AdditionalFiles = {{"a.h", std::string(Header.code())}};
+  EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
+}
 
 TEST(ClangdTest, MSAsm) {
   // Parsing MS assembly tries to use the target MCAsmInfo, which we don't link.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111971: [clang] Allocate 2 bits to store the constexpr specifier kind when serializing

2021-10-17 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Not sure if clangd is the best place to test this. I'm open to other 
suggestions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111971

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


[PATCH] D111971: [clang] Allocate 2 bits to store the constexpr specifier kind when serializing

2021-10-18 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz accepted this revision.
adamcz added a comment.
This revision is now accepted and ready to land.

Fix LGTM

As for the test, I suggest putting it in clang/test/AST/, maybe in 
ast-dump-constant-expr? You can write a CHECK-NEXT: thingy to verify that 
consteval is preserved. The test already runs both with and without AST 
reader/writer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111971

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