r306065 - PR33002: When we instantiate the definition of a static data member, we might
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 22 15:18:47 PDT 2017
Author: rsmith
Date: Thu Jun 22 17:18:46 2017
New Revision: 306065
URL: http://llvm.org/viewvc/llvm-project?rev=306065&view=rev
Log:
PR33002: When we instantiate the definition of a static data member, we might
have attached an initializer to the in-class declaration. If so, include the
initializer in the update record for the instantiation.
Added:
cfe/trunk/test/Modules/const-var-init-update.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=306065&r1=306064&r2=306065&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Jun 22 17:18:46 2017
@@ -4290,9 +4290,6 @@ void Sema::InstantiateVariableDefinition
InstantiateVariableInitializer(Var, PatternDecl, TemplateArgs);
PreviousContext.pop();
- // FIXME: Need to inform the ASTConsumer that we instantiated the
- // initializer?
-
// This variable may have local implicit instantiations that need to be
// instantiated within this scope.
LocalInstantiations.perform();
@@ -4402,7 +4399,6 @@ void Sema::InstantiateVariableDefinition
if (Def->isStaticDataMember() && !Def->isOutOfLine()) {
// We're instantiating an inline static data member whose definition was
// provided inside the class.
- // FIXME: Update record?
InstantiateVariableInitializer(Var, Def, TemplateArgs);
} else if (!VarSpec) {
Var = cast_or_null<VarDecl>(SubstDecl(Def, Var->getDeclContext(),
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=306065&r1=306064&r2=306065&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Jun 22 17:18:46 2017
@@ -3934,10 +3934,21 @@ void ASTDeclReader::UpdateDecl(Decl *D)
break;
}
- case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
- cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
+ case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: {
+ VarDecl *VD = cast<VarDecl>(D);
+ VD->getMemberSpecializationInfo()->setPointOfInstantiation(
ReadSourceLocation());
+ uint64_t Val = Record.readInt();
+ if (Val && !VD->getInit()) {
+ VD->setInit(Record.readExpr());
+ if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3
+ EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
+ Eval->CheckedICE = true;
+ Eval->IsICE = Val == 3;
+ }
+ }
break;
+ }
case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: {
auto Param = cast<ParmVarDecl>(D);
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=306065&r1=306064&r2=306065&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Jun 22 17:18:46 2017
@@ -5033,9 +5033,18 @@ void ASTWriter::WriteDeclUpdatesBlocks(R
case UPD_CXX_ADDED_FUNCTION_DEFINITION:
break;
- case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
+ case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: {
+ const VarDecl *VD = cast<VarDecl>(D);
Record.AddSourceLocation(Update.getLoc());
+ if (VD->getInit()) {
+ Record.push_back(!VD->isInitKnownICE() ? 1
+ : (VD->isInitICE() ? 3 : 2));
+ Record.AddStmt(const_cast<Expr*>(VD->getInit()));
+ } else {
+ Record.push_back(0);
+ }
break;
+ }
case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT:
Record.AddStmt(const_cast<Expr *>(
Added: cfe/trunk/test/Modules/const-var-init-update.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/const-var-init-update.cpp?rev=306065&view=auto
==============================================================================
--- cfe/trunk/test/Modules/const-var-init-update.cpp (added)
+++ cfe/trunk/test/Modules/const-var-init-update.cpp Thu Jun 22 17:18:46 2017
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -std=c++1z -fmodules %s -verify
+// expected-no-diagnostics
+
+#pragma clang module build std
+module std { module limits {} module other {} }
+#pragma clang module contents
+#pragma clang module begin std.limits
+template<typename T> struct numeric_limits {
+ static constexpr T __max = 5;
+ static constexpr T max() { return __max; }
+};
+#pragma clang module end
+#pragma clang module begin std.other
+inline void f() { numeric_limits<int> nl; }
+#pragma clang module end
+#pragma clang module endbuild
+
+#pragma clang module build module_b
+module module_b {}
+#pragma clang module contents
+#pragma clang module begin module_b
+#pragma clang module import std.limits
+constexpr int a = numeric_limits<int>::max();
+#pragma clang module end
+#pragma clang module endbuild
+
+#pragma clang module import std.limits
+#pragma clang module import module_b
+constexpr int b = a;
+static_assert(b == 5);
More information about the cfe-commits
mailing list