[PATCH] D43494: [Modules] Fix creating fake definition data for lambdas.

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 21 14:34:22 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rC328153: [Modules] Fix creating fake definition data for lambdas. (authored by vsapsai, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43494?vs=138059&id=139372#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43494

Files:
  lib/Serialization/ASTReaderDecl.cpp
  test/Modules/Inputs/self-referencing-lambda/a.h
  test/Modules/Inputs/self-referencing-lambda/module.modulemap
  test/Modules/self-referencing-lambda.cpp


Index: test/Modules/self-referencing-lambda.cpp
===================================================================
--- test/Modules/self-referencing-lambda.cpp
+++ test/Modules/self-referencing-lambda.cpp
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/self-referencing-lambda %s -verify -emit-obj -o %t2.o
+// expected-no-diagnostics
+
+#include "a.h"
Index: test/Modules/Inputs/self-referencing-lambda/module.modulemap
===================================================================
--- test/Modules/Inputs/self-referencing-lambda/module.modulemap
+++ test/Modules/Inputs/self-referencing-lambda/module.modulemap
@@ -0,0 +1,4 @@
+module "a.h" {
+  header "a.h"
+  export *
+}
Index: test/Modules/Inputs/self-referencing-lambda/a.h
===================================================================
--- test/Modules/Inputs/self-referencing-lambda/a.h
+++ test/Modules/Inputs/self-referencing-lambda/a.h
@@ -0,0 +1,4 @@
+void f() {
+  int x = 0;
+  auto q = [xm = x]{};
+}
Index: lib/Serialization/ASTReaderDecl.cpp
===================================================================
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -1784,29 +1784,31 @@
   else
     DD = new (C) struct CXXRecordDecl::DefinitionData(D);
 
+  CXXRecordDecl *Canon = D->getCanonicalDecl();
+  // Set decl definition data before reading it, so that during deserialization
+  // when we read CXXRecordDecl, it already has definition data and we don't
+  // set fake one.
+  if (!Canon->DefinitionData)
+    Canon->DefinitionData = DD;
+  D->DefinitionData = Canon->DefinitionData;
   ReadCXXDefinitionData(*DD, D);
 
-  // We might already have a definition for this record. This can happen either
-  // because we're reading an update record, or because we've already done some
-  // merging. Either way, just merge into it.
-  CXXRecordDecl *Canon = D->getCanonicalDecl();
-  if (Canon->DefinitionData) {
+  // We might already have a different definition for this record. This can
+  // happen either because we're reading an update record, or because we've
+  // already done some merging. Either way, just merge into it.
+  if (Canon->DefinitionData != DD) {
     MergeDefinitionData(Canon, std::move(*DD));
-    D->DefinitionData = Canon->DefinitionData;
     return;
   }
 
   // Mark this declaration as being a definition.
   D->IsCompleteDefinition = true;
-  D->DefinitionData = DD;
 
   // If this is not the first declaration or is an update record, we can have
   // other redeclarations already. Make a note that we need to propagate the
   // DefinitionData pointer onto them.
-  if (Update || Canon != D) {
-    Canon->DefinitionData = D->DefinitionData;
+  if (Update || Canon != D)
     Reader.PendingDefinitions.insert(D);
-  }
 }
 
 ASTDeclReader::RedeclarableResult


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43494.139372.patch
Type: text/x-patch
Size: 2885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180321/100dc6af/attachment.bin>


More information about the cfe-commits mailing list