[clang] 6434dce - [Clang][Interp] Fix the location of uninitialized base warning (#100761)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 31 02:22:48 PDT 2024
Author: yronglin
Date: 2024-07-31T17:22:44+08:00
New Revision: 6434dce85df21aabd5669dd9fbe8fa582e40c6ee
URL: https://github.com/llvm/llvm-project/commit/6434dce85df21aabd5669dd9fbe8fa582e40c6ee
DIFF: https://github.com/llvm/llvm-project/commit/6434dce85df21aabd5669dd9fbe8fa582e40c6ee.diff
LOG: [Clang][Interp] Fix the location of uninitialized base warning (#100761)
Fix the location of `diag::note_constexpr_uninitialized_base`, make it
same as current interpreter.
This PR does not print type name with namespacethat was used to improve
the current interpreter's type dump of base class type.
---------
Signed-off-by: yronglin <yronglin777 at gmail.com>
Added:
Modified:
clang/lib/AST/Interp/EvaluationResult.cpp
clang/test/AST/Interp/constexpr-subobj-initialization.cpp
clang/test/C/C23/n3018.c
clang/test/CodeGen/pr3518.c
clang/test/Preprocessor/embed_weird.cpp
clang/test/SemaCXX/constexpr-subobj-initialization.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/EvaluationResult.cpp b/clang/lib/AST/Interp/EvaluationResult.cpp
index 1b255711c7b36..bdebd19af9f94 100644
--- a/clang/lib/AST/Interp/EvaluationResult.cpp
+++ b/clang/lib/AST/Interp/EvaluationResult.cpp
@@ -10,7 +10,9 @@
#include "InterpState.h"
#include "Record.h"
#include "clang/AST/ExprCXX.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
+#include <iterator>
namespace clang {
namespace interp {
@@ -122,19 +124,18 @@ static bool CheckFieldsInitialized(InterpState &S, SourceLocation Loc,
}
// Check Fields in all bases
- for (const Record::Base &B : R->bases()) {
+ for (auto [I, B] : llvm::enumerate(R->bases())) {
Pointer P = BasePtr.atField(B.Offset);
if (!P.isInitialized()) {
const Descriptor *Desc = BasePtr.getDeclDesc();
- if (Desc->asDecl())
- S.FFDiag(BasePtr.getDeclDesc()->asDecl()->getLocation(),
- diag::note_constexpr_uninitialized_base)
+ if (const auto *CD = dyn_cast_if_present<CXXRecordDecl>(R->getDecl())) {
+ const auto &BS = *std::next(CD->bases_begin(), I);
+ S.FFDiag(BS.getBaseTypeLoc(), diag::note_constexpr_uninitialized_base)
+ << B.Desc->getType() << BS.getSourceRange();
+ } else {
+ S.FFDiag(Desc->getLocation(), diag::note_constexpr_uninitialized_base)
<< B.Desc->getType();
- else
- S.FFDiag(BasePtr.getDeclDesc()->asExpr()->getExprLoc(),
- diag::note_constexpr_uninitialized_base)
- << B.Desc->getType();
-
+ }
return false;
}
Result &= CheckFieldsInitialized(S, Loc, P, B.R);
diff --git a/clang/test/AST/Interp/constexpr-subobj-initialization.cpp b/clang/test/AST/Interp/constexpr-subobj-initialization.cpp
index 4976b165468bd..1a35994944190 100644
--- a/clang/test/AST/Interp/constexpr-subobj-initialization.cpp
+++ b/clang/test/AST/Interp/constexpr-subobj-initialization.cpp
@@ -5,8 +5,6 @@
/// Differences:
/// 1) The type of the uninitialized base class is printed WITH the namespace,
/// i.e. 'baseclass_uninit::DelBase' instead of just 'DelBase'.
-/// 2) The location is not the base specifier declaration, but the call site
-/// of the constructor.
namespace baseclass_uninit {
@@ -14,33 +12,29 @@ struct DelBase {
constexpr DelBase() = delete; // expected-note {{'DelBase' has been explicitly marked deleted here}}
};
-struct Foo : DelBase {
+struct Foo : DelBase { // expected-note 2{{constructor of base class 'baseclass_uninit::DelBase' is not called}}
constexpr Foo() {}; // expected-error {{call to deleted constructor of 'DelBase'}}
};
-constexpr Foo f; // expected-error {{must be initialized by a constant expression}} \
- // expected-note {{constructor of base class 'baseclass_uninit::DelBase' is not called}}
+constexpr Foo f; // expected-error {{must be initialized by a constant expression}}
struct Bar : Foo {
constexpr Bar() {};
};
-constexpr Bar bar; // expected-error {{must be initialized by a constant expression}} \
- // expected-note {{constructor of base class 'baseclass_uninit::DelBase' is not called}}
+constexpr Bar bar; // expected-error {{must be initialized by a constant expression}}
struct Base {};
-struct A : Base {
+struct A : Base { // expected-note {{constructor of base class 'baseclass_uninit::Base' is not called}}
constexpr A() : value() {} // expected-error {{member initializer 'value' does not name a non-static data member or base class}}
};
-constexpr A a; // expected-error {{must be initialized by a constant expression}} \
- // expected-note {{constructor of base class 'baseclass_uninit::Base' is not called}}
+constexpr A a; // expected-error {{must be initialized by a constant expression}}
-struct B : Base {
+struct B : Base { // expected-note {{constructor of base class 'baseclass_uninit::Base' is not called}}
constexpr B() : {} // expected-error {{expected class member or base class name}}
};
-constexpr B b; // expected-error {{must be initialized by a constant expression}} \
- // expected-note {{constructor of base class 'baseclass_uninit::Base' is not called}}
+constexpr B b; // expected-error {{must be initialized by a constant expression}}
} // namespace baseclass_uninit
diff --git a/clang/test/C/C23/n3018.c b/clang/test/C/C23/n3018.c
index 0d54d53b7499f..4ad2fffbfde80 100644
--- a/clang/test/C/C23/n3018.c
+++ b/clang/test/C/C23/n3018.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -std=c23 -verify -triple x86_64 -pedantic -Wno-conversion -Wno-constant-conversion %s
+// RUN: %clang_cc1 -std=c23 -verify -triple x86_64 -pedantic -Wno-conversion -Wno-constant-conversion -fexperimental-new-constant-interpreter %s
/* WG14 N3018: Full
* The constexpr specifier for object definitions
diff --git a/clang/test/CodeGen/pr3518.c b/clang/test/CodeGen/pr3518.c
index f888add986258..a3cd866e92201 100644
--- a/clang/test/CodeGen/pr3518.c
+++ b/clang/test/CodeGen/pr3518.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -fexperimental-new-constant-interpreter -emit-llvm -o - | FileCheck %s
// PR 3518
// Some of the objects were coming out as uninitialized (external) before 3518
// was fixed. Internal names are
diff erent between llvm-gcc and clang so they
diff --git a/clang/test/Preprocessor/embed_weird.cpp b/clang/test/Preprocessor/embed_weird.cpp
index 90180e2d3cc70..9a984e40d4aa2 100644
--- a/clang/test/Preprocessor/embed_weird.cpp
+++ b/clang/test/Preprocessor/embed_weird.cpp
@@ -4,6 +4,8 @@
// RUN: printf "\0" > %t/null_byte.bin
// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%t -verify=expected,cxx -Wno-c23-extensions
// RUN: %clang_cc1 -x c -std=c23 %s -fsyntax-only --embed-dir=%t -verify=expected,c
+// RUN: %clang_cc1 %s -fsyntax-only -fexperimental-new-constant-interpreter --embed-dir=%t -verify=expected,cxx -Wno-c23-extensions
+// RUN: %clang_cc1 -x c -std=c23 %s -fsyntax-only -fexperimental-new-constant-interpreter --embed-dir=%t -verify=expected,c
#embed <media/empty>
;
diff --git a/clang/test/SemaCXX/constexpr-subobj-initialization.cpp b/clang/test/SemaCXX/constexpr-subobj-initialization.cpp
index cd096a9270937..f0252df1e2ce1 100644
--- a/clang/test/SemaCXX/constexpr-subobj-initialization.cpp
+++ b/clang/test/SemaCXX/constexpr-subobj-initialization.cpp
@@ -1,11 +1,12 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
namespace baseclass_uninit {
struct DelBase {
constexpr DelBase() = delete; // expected-note {{'DelBase' has been explicitly marked deleted here}}
};
-struct Foo : DelBase { // expected-note 2{{constructor of base class 'DelBase' is not called}}
+struct Foo : DelBase { // expected-note-re 2{{constructor of base class '{{.*}}DelBase' is not called}}
constexpr Foo() {}; // expected-error {{call to deleted constructor of 'DelBase'}}
};
constexpr Foo f; // expected-error {{must be initialized by a constant expression}}
@@ -15,13 +16,13 @@ struct Bar : Foo {
constexpr Bar bar; // expected-error {{must be initialized by a constant expression}}
struct Base {};
-struct A : Base { // expected-note {{constructor of base class 'Base' is not called}}
+struct A : Base { // expected-note-re {{constructor of base class '{{.*}}Base' is not called}}
constexpr A() : value() {} // expected-error {{member initializer 'value' does not name a non-static data member or base class}}
};
constexpr A a; // expected-error {{must be initialized by a constant expression}}
-struct B : Base { // expected-note {{constructor of base class 'Base' is not called}}
+struct B : Base { // expected-note-re {{constructor of base class '{{.*}}Base' is not called}}
constexpr B() : {} // expected-error {{expected class member or base class name}}
};
More information about the cfe-commits
mailing list