[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-07-16 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 updated this revision to Diff 278399.
gargvaibhav64 added a comment.

The tests weren't failing for me. So, we are possibly missing test coverage. I 
have made the change now.

Also, I would like to add that the current test present in this diff does not 
fail in the existing system but it was the best I and Vassil could come up with 
to replicate our problem.


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

https://reviews.llvm.org/D83174

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/inherit-attribute/a.h
  clang/test/Modules/Inputs/inherit-attribute/b.h
  clang/test/Modules/Inputs/inherit-attribute/c.h
  clang/test/Modules/Inputs/inherit-attribute/module.modulemap
  clang/test/Modules/inherit-attribute.cpp

Index: clang/test/Modules/inherit-attribute.cpp
===
--- /dev/null
+++ clang/test/Modules/inherit-attribute.cpp
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -ast-dump -I%S/Inputs/inherit-attribute -fmodules-cache-path=%t -fimplicit-module-maps -verify %s -fmodules-local-submodule-visibility
+
+#include "b.h"
+#include "c.h"
+
+class Foo;
+
+Foo f;
+// expected-no-diagnostics
Index: clang/test/Modules/Inputs/inherit-attribute/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/module.modulemap
@@ -0,0 +1,3 @@
+module "b" { header "b.h" }
+
+module "c" { header "c.h" }
Index: clang/test/Modules/Inputs/inherit-attribute/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/c.h
@@ -0,0 +1,7 @@
+#include "a.h"
+
+class Foo;
+class C {
+public:
+  C();
+};
Index: clang/test/Modules/Inputs/inherit-attribute/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/b.h
@@ -0,0 +1,12 @@
+#include "a.h"
+
+class Foo;
+
+void bar() {
+  &Foo::step;
+}
+
+class B {
+public:
+  B();
+};
Index: clang/test/Modules/Inputs/inherit-attribute/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/a.h
@@ -0,0 +1,10 @@
+#ifndef FOO
+#define FOO
+
+class Foo {
+public:
+  void step(int v);
+  Foo();
+};
+
+#endif
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -281,6 +281,9 @@
 static Decl *getMostRecentDeclImpl(...);
 static Decl *getMostRecentDecl(Decl *D);
 
+static void mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+   Decl *Previous);
+
 template 
 static void attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D, Decl *Previous,
@@ -3531,6 +3534,19 @@
   return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
 }
 
+void ASTDeclReader::mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+   Decl *Previous) {
+  InheritableAttr *NewAttr = nullptr;
+  ASTContext &Context = Reader.getContext();
+  const auto *IA = Previous->getAttr();
+
+  if (IA && !D->hasAttr()) {
+NewAttr = cast(IA->clone(Context));
+NewAttr->setInherited(true);
+D->addAttr(NewAttr);
+  }
+}
+
 template
 void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D,
@@ -3689,6 +3705,12 @@
   if (auto *TD = dyn_cast(D))
 inheritDefaultTemplateArguments(Reader.getContext(),
 cast(Previous), TD);
+
+  // If any of the declaration in the chain contains an Inheritable attribute,
+  // it needs to be added to all the declarations in the redeclarable chain.
+  // FIXME: Only the logic of merging MSInheritableAttr is present, it should
+  // be extended for all inheritable attributes.
+  mergeInheritableAttributes(Reader, D, Previous);
 }
 
 template
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-07-26 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 added a comment.

Hi everyone, are there any more changes required to this review?


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

https://reviews.llvm.org/D83174



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


[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-07-05 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 created this revision.
gargvaibhav64 added reviewers: rsmith, v.g.vassilev.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This commit attaches teaches ASTDeclReader::attachPreviousDecl to successfully 
merge two Decl's when one contains an inheritable attribute like the 
MSInheritanceAttr. Usually, attributes that are needed to present along the 
redeclaration chain are attached during ASTReading from 
ASTDeclReader::attachPreviousDecl, but no such thing is done for inheritable 
attributes. Currently, only the logic for merging MSInheritanceAttr is provided.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83174

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/inherit-attribute/a.h
  clang/test/Modules/Inputs/inherit-attribute/b.h
  clang/test/Modules/Inputs/inherit-attribute/c.h
  clang/test/Modules/Inputs/inherit-attribute/module.modulemap
  clang/test/Modules/inherit-attribute.cpp

Index: clang/test/Modules/inherit-attribute.cpp
===
--- /dev/null
+++ clang/test/Modules/inherit-attribute.cpp
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -ast-dump -I%S/Inputs/inherit-attribute -fmodules-cache-path=%t -fimplicit-module-maps -verify %s -fmodules-local-submodule-visibility
+
+#include "b.h"
+#include "c.h"
+
+class Foo;
+
+Foo f;
+// expected-no-diagnostics
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/module.modulemap
@@ -0,0 +1,3 @@
+module "b" { header "b.h" }
+
+module "c" { header "c.h" }
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/c.h
@@ -0,0 +1,7 @@
+#include "a.h"
+
+class Foo;
+class C {
+public:
+  C();
+};
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/b.h
@@ -0,0 +1,12 @@
+#include "a.h"
+
+class Foo;
+
+void bar() {
+  &Foo::step;
+}
+
+class B {
+public:
+  B();
+};
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/a.h
@@ -0,0 +1,10 @@
+#ifndef FOO
+#define FOO
+
+class Foo {
+public:
+  void step(int v);
+  Foo();
+};
+
+#endif
\ No newline at end of file
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -281,6 +281,8 @@
 static Decl *getMostRecentDeclImpl(...);
 static Decl *getMostRecentDecl(Decl *D);
 
+static void mergeInheritableAttributes(Decl *D, Decl *Previous);
+
 template 
 static void attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D, Decl *Previous,
@@ -3531,6 +3533,18 @@
   return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
 }
 
+void ASTDeclReader::mergeInheritableAttributes(Decl *D, Decl *Previous) {
+  if (Previous->hasAttr() &&
+  !D->hasAttr()) {
+Attr *IA = Previous->getAttr();
+D->addAttr(IA);
+  } else if (!Previous->hasAttr() &&
+ D->hasAttr()) {
+Attr *IA = D->getAttr();
+Previous->addAttr(IA);
+  }
+}
+
 template
 void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D,
@@ -3689,6 +3703,10 @@
   if (auto *TD = dyn_cast(D))
 inheritDefaultTemplateArguments(Reader.getContext(),
 cast(Previous), TD);
+
+  // If any of the declaration in the chain contains an Inheritable attribute,
+  // it needs to be added to all the declarations in the redeclarable chain.
+  mergeInheritableAttributes(D, Previous);
 }
 
 template
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-07-08 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 updated this revision to Diff 276351.
gargvaibhav64 edited the summary of this revision.
gargvaibhav64 added a comment.

I incorporated the changes


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

https://reviews.llvm.org/D83174

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/inherit-attribute/a.h
  clang/test/Modules/Inputs/inherit-attribute/b.h
  clang/test/Modules/Inputs/inherit-attribute/c.h
  clang/test/Modules/Inputs/inherit-attribute/module.modulemap
  clang/test/Modules/inherit-attribute.cpp

Index: clang/test/Modules/inherit-attribute.cpp
===
--- /dev/null
+++ clang/test/Modules/inherit-attribute.cpp
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -ast-dump -I%S/Inputs/inherit-attribute -fmodules-cache-path=%t -fimplicit-module-maps -verify %s -fmodules-local-submodule-visibility
+
+#include "b.h"
+#include "c.h"
+
+class Foo;
+
+Foo f;
+// expected-no-diagnostics
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/module.modulemap
@@ -0,0 +1,3 @@
+module "b" { header "b.h" }
+
+module "c" { header "c.h" }
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/c.h
@@ -0,0 +1,7 @@
+#include "a.h"
+
+class Foo;
+class C {
+public:
+  C();
+};
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/b.h
@@ -0,0 +1,12 @@
+#include "a.h"
+
+class Foo;
+
+void bar() {
+  &Foo::step;
+}
+
+class B {
+public:
+  B();
+};
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/a.h
@@ -0,0 +1,10 @@
+#ifndef FOO
+#define FOO
+
+class Foo {
+public:
+  void step(int v);
+  Foo();
+};
+
+#endif
\ No newline at end of file
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -281,6 +281,8 @@
 static Decl *getMostRecentDeclImpl(...);
 static Decl *getMostRecentDecl(Decl *D);
 
+static void mergeInheritableAttributes(Decl *D, Decl *Previous);
+
 template 
 static void attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D, Decl *Previous,
@@ -3531,6 +3533,17 @@
   return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
 }
 
+void ASTDeclReader::mergeInheritableAttributes(Decl *D, Decl *Previous) {
+  InheritableAttr *IA = nullptr;
+  if (Previous->hasAttr() &&
+  !D->hasAttr()) {
+IA = cast(
+(Previous->getAttr())->clone(D->getASTContext()));
+IA->setInherited(true);
+D->addAttr(IA);
+  }
+}
+
 template
 void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D,
@@ -3689,6 +3702,12 @@
   if (auto *TD = dyn_cast(D))
 inheritDefaultTemplateArguments(Reader.getContext(),
 cast(Previous), TD);
+
+  // If any of the declaration in the chain contains an Inheritable attribute,
+  // it needs to be added to all the declarations in the redeclarable chain.
+  // FIXME: Only the logic of merging MSInheritableAttr is present, it should
+  // be extended for all inheritable attributes.
+  mergeInheritableAttributes(D, Previous);
 }
 
 template
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-07-09 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 updated this revision to Diff 276680.
gargvaibhav64 marked 3 inline comments as done.
gargvaibhav64 added a comment.

Added a new attribute instead of using the previous one


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

https://reviews.llvm.org/D83174

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/inherit-attribute/a.h
  clang/test/Modules/Inputs/inherit-attribute/b.h
  clang/test/Modules/Inputs/inherit-attribute/c.h
  clang/test/Modules/Inputs/inherit-attribute/module.modulemap
  clang/test/Modules/inherit-attribute.cpp

Index: clang/test/Modules/inherit-attribute.cpp
===
--- /dev/null
+++ clang/test/Modules/inherit-attribute.cpp
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -ast-dump -I%S/Inputs/inherit-attribute -fmodules-cache-path=%t -fimplicit-module-maps -verify %s -fmodules-local-submodule-visibility
+
+#include "b.h"
+#include "c.h"
+
+class Foo;
+
+Foo f;
+// expected-no-diagnostics
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/module.modulemap
@@ -0,0 +1,3 @@
+module "b" { header "b.h" }
+
+module "c" { header "c.h" }
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/c.h
@@ -0,0 +1,7 @@
+#include "a.h"
+
+class Foo;
+class C {
+public:
+  C();
+};
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/b.h
@@ -0,0 +1,12 @@
+#include "a.h"
+
+class Foo;
+
+void bar() {
+  &Foo::step;
+}
+
+class B {
+public:
+  B();
+};
\ No newline at end of file
Index: clang/test/Modules/Inputs/inherit-attribute/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/a.h
@@ -0,0 +1,10 @@
+#ifndef FOO
+#define FOO
+
+class Foo {
+public:
+  void step(int v);
+  Foo();
+};
+
+#endif
\ No newline at end of file
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -281,6 +281,9 @@
 static Decl *getMostRecentDeclImpl(...);
 static Decl *getMostRecentDecl(Decl *D);
 
+static void mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+   Decl *Previous);
+
 template 
 static void attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D, Decl *Previous,
@@ -3531,6 +3534,23 @@
   return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
 }
 
+void ASTDeclReader::mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+   Decl *Previous) {
+  InheritableAttr *NewAttr = nullptr;
+  ASTContext &Context = Reader.getContext();
+  if (Previous->hasAttr() &&
+  !D->hasAttr()) {
+const auto *IA =
+dyn_cast(Previous->getAttr());
+
+NewAttr = new (Context) MSInheritanceAttr(
+IA->getRange(), Context, IA->getBestCase(), IA->getSpellingListIndex());
+
+NewAttr->setInherited(true);
+D->addAttr(NewAttr);
+  }
+}
+
 template
 void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D,
@@ -3689,6 +3709,12 @@
   if (auto *TD = dyn_cast(D))
 inheritDefaultTemplateArguments(Reader.getContext(),
 cast(Previous), TD);
+
+  // If any of the declaration in the chain contains an Inheritable attribute,
+  // it needs to be added to all the declarations in the redeclarable chain.
+  // FIXME: Only the logic of merging MSInheritableAttr is present, it should
+  // be extended for all inheritable attributes.
+  mergeInheritableAttributes(Reader, D, Previous);
 }
 
 template
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-07-10 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 updated this revision to Diff 277022.
gargvaibhav64 marked 3 inline comments as done.
gargvaibhav64 added a comment.

Incorporated the changes


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

https://reviews.llvm.org/D83174

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/inherit-attribute/a.h
  clang/test/Modules/Inputs/inherit-attribute/b.h
  clang/test/Modules/Inputs/inherit-attribute/c.h
  clang/test/Modules/Inputs/inherit-attribute/module.modulemap
  clang/test/Modules/inherit-attribute.cpp

Index: clang/test/Modules/inherit-attribute.cpp
===
--- /dev/null
+++ clang/test/Modules/inherit-attribute.cpp
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -ast-dump -I%S/Inputs/inherit-attribute -fmodules-cache-path=%t -fimplicit-module-maps -verify %s -fmodules-local-submodule-visibility
+
+#include "b.h"
+#include "c.h"
+
+class Foo;
+
+Foo f;
+// expected-no-diagnostics
Index: clang/test/Modules/Inputs/inherit-attribute/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/module.modulemap
@@ -0,0 +1,3 @@
+module "b" { header "b.h" }
+
+module "c" { header "c.h" }
Index: clang/test/Modules/Inputs/inherit-attribute/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/c.h
@@ -0,0 +1,7 @@
+#include "a.h"
+
+class Foo;
+class C {
+public:
+  C();
+};
Index: clang/test/Modules/Inputs/inherit-attribute/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/b.h
@@ -0,0 +1,12 @@
+#include "a.h"
+
+class Foo;
+
+void bar() {
+  &Foo::step;
+}
+
+class B {
+public:
+  B();
+};
Index: clang/test/Modules/Inputs/inherit-attribute/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/a.h
@@ -0,0 +1,10 @@
+#ifndef FOO
+#define FOO
+
+class Foo {
+public:
+  void step(int v);
+  Foo();
+};
+
+#endif
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -281,6 +281,9 @@
 static Decl *getMostRecentDeclImpl(...);
 static Decl *getMostRecentDecl(Decl *D);
 
+static void mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+   Decl *Previous);
+
 template 
 static void attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D, Decl *Previous,
@@ -3531,6 +3534,19 @@
   return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
 }
 
+void ASTDeclReader::mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+   Decl *Previous) {
+  InheritableAttr *NewAttr = nullptr;
+  ASTContext &Context = Reader.getContext();
+  const auto *IA = Previous->getAttr();
+
+  if (IA && Previous->hasAttr()) {
+NewAttr = cast(IA->clone(Context));
+NewAttr->setInherited(true);
+D->addAttr(NewAttr);
+  }
+}
+
 template
 void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D,
@@ -3689,6 +3705,12 @@
   if (auto *TD = dyn_cast(D))
 inheritDefaultTemplateArguments(Reader.getContext(),
 cast(Previous), TD);
+
+  // If any of the declaration in the chain contains an Inheritable attribute,
+  // it needs to be added to all the declarations in the redeclarable chain.
+  // FIXME: Only the logic of merging MSInheritableAttr is present, it should
+  // be extended for all inheritable attributes.
+  mergeInheritableAttributes(Reader, D, Previous);
 }
 
 template
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-08-20 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 updated this revision to Diff 286786.
gargvaibhav64 added a comment.

The test is now working properly.


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

https://reviews.llvm.org/D83174

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/inherit-attribute/a.h
  clang/test/Modules/Inputs/inherit-attribute/b.h
  clang/test/Modules/Inputs/inherit-attribute/c.h
  clang/test/Modules/Inputs/inherit-attribute/module.modulemap
  clang/test/Modules/inherit-attribute.cpp

Index: clang/test/Modules/inherit-attribute.cpp
===
--- /dev/null
+++ clang/test/Modules/inherit-attribute.cpp
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -triple x86_64-pc-windows-msvc-unknown -I%S\Inputs\inherit-attribute -fmodules-cache-path=%t \
+// RUN: -fimplicit-module-maps -fmodules-local-submodule-visibility -verify %s -ast-dump-all \
+// RUN: | FileCheck %s
+
+#include "b.h"
+#include "c.h"
+
+class Foo;
+
+Foo f;
+
+// CHECK:   CXXRecordDecl{{.*}}prev{{.*}}Foo
+// CHECK:   {{.*}}`-MSInheritanceAttr{{[^()]*$}}
+
+// CHECK:   CXXRecordDecl{{.*}}prev{{.*}}Foo
+// CHECK:   {{.*}}-MSInheritanceAttr{{[^()]*$}}
+
+// CHECK:   CXXRecordDecl{{.*}}prev{{.*}}Foo
+// CHECK:   {{.*}}`-MSInheritanceAttr{{[^()]*$}}
+
+// expected-no-diagnostics
Index: clang/test/Modules/Inputs/inherit-attribute/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/module.modulemap
@@ -0,0 +1,3 @@
+module "b" { header "b.h" }
+
+module "c" { header "c.h" }
Index: clang/test/Modules/Inputs/inherit-attribute/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/c.h
@@ -0,0 +1 @@
+#include "a.h"
Index: clang/test/Modules/Inputs/inherit-attribute/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/b.h
@@ -0,0 +1,7 @@
+#include "a.h"
+
+class Foo;
+
+void bar() {
+  &Foo::step;
+}
Index: clang/test/Modules/Inputs/inherit-attribute/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/a.h
@@ -0,0 +1,10 @@
+#ifndef FOO
+#define FOO
+
+class Foo {
+public:
+  void step(int v);
+  Foo();
+};
+
+#endif
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -281,6 +281,9 @@
 static Decl *getMostRecentDeclImpl(...);
 static Decl *getMostRecentDecl(Decl *D);
 
+static void mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+   Decl *Previous);
+
 template 
 static void attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D, Decl *Previous,
@@ -3531,6 +3534,19 @@
   return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
 }
 
+void ASTDeclReader::mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+   Decl *Previous) {
+  InheritableAttr *NewAttr = nullptr;
+  ASTContext &Context = Reader.getContext();
+  const auto *IA = Previous->getAttr();
+
+  if (IA && !D->hasAttr()) {
+NewAttr = cast(IA->clone(Context));
+NewAttr->setInherited(true);
+D->addAttr(NewAttr);
+  }
+}
+
 template
 void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D,
@@ -3689,6 +3705,12 @@
   if (auto *TD = dyn_cast(D))
 inheritDefaultTemplateArguments(Reader.getContext(),
 cast(Previous), TD);
+
+  // If any of the declaration in the chain contains an Inheritable attribute,
+  // it needs to be added to all the declarations in the redeclarable chain.
+  // FIXME: Only the logic of merging MSInheritableAttr is present, it should
+  // be extended for all inheritable attributes.
+  mergeInheritableAttributes(Reader, D, Previous);
 }
 
 template
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-08-21 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 updated this revision to Diff 287004.
gargvaibhav64 marked an inline comment as done.
gargvaibhav64 added a comment.

Updated the regex to be less-greedy.


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

https://reviews.llvm.org/D83174

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/inherit-attribute/a.h
  clang/test/Modules/Inputs/inherit-attribute/b.h
  clang/test/Modules/Inputs/inherit-attribute/c.h
  clang/test/Modules/Inputs/inherit-attribute/module.modulemap
  clang/test/Modules/inherit-attribute.cpp

Index: clang/test/Modules/inherit-attribute.cpp
===
--- /dev/null
+++ clang/test/Modules/inherit-attribute.cpp
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -triple x86_64-pc-windows-msvc-unknown -I%S\Inputs\inherit-attribute -fmodules-cache-path=%t \
+// RUN: -fimplicit-module-maps -fmodules-local-submodule-visibility %s -ast-dump-all \
+// RUN: | FileCheck %s
+
+#include "b.h"
+#include "c.h"
+
+class Foo;
+
+Foo f;
+
+// CHECK:   CXXRecordDecl {{.*}} imported in b {{.*}} Foo
+// CHECK:   MSInheritanceAttr {{[^()]*$}}
+
+// CHECK:   CXXRecordDecl {{.*}} prev {{.*}} imported in c {{.*}} Foo
+// CHECK:   MSInheritanceAttr {{.*}} Inherited {{[^()]*$}}
+
+// CHECK:   CXXRecordDecl {{.*}}  col:7 referenced class Foo
+// CHECK:   MSInheritanceAttr {{.*}} Inherited {{[^()]*$}}
Index: clang/test/Modules/Inputs/inherit-attribute/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/module.modulemap
@@ -0,0 +1,3 @@
+module "b" { header "b.h" }
+
+module "c" { header "c.h" }
Index: clang/test/Modules/Inputs/inherit-attribute/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/c.h
@@ -0,0 +1 @@
+#include "a.h"
Index: clang/test/Modules/Inputs/inherit-attribute/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/b.h
@@ -0,0 +1,5 @@
+#include "a.h"
+
+void bar() {
+  &Foo::step;
+}
Index: clang/test/Modules/Inputs/inherit-attribute/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/a.h
@@ -0,0 +1,10 @@
+#ifndef FOO
+#define FOO
+
+class Foo {
+public:
+  void step(int v);
+  Foo();
+};
+
+#endif
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -281,6 +281,9 @@
 static Decl *getMostRecentDeclImpl(...);
 static Decl *getMostRecentDecl(Decl *D);
 
+static void mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+   Decl *Previous);
+
 template 
 static void attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D, Decl *Previous,
@@ -3531,6 +3534,19 @@
   return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
 }
 
+void ASTDeclReader::mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+   Decl *Previous) {
+  InheritableAttr *NewAttr = nullptr;
+  ASTContext &Context = Reader.getContext();
+  const auto *IA = Previous->getAttr();
+
+  if (IA && !D->hasAttr()) {
+NewAttr = cast(IA->clone(Context));
+NewAttr->setInherited(true);
+D->addAttr(NewAttr);
+  }
+}
+
 template
 void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D,
@@ -3689,6 +3705,12 @@
   if (auto *TD = dyn_cast(D))
 inheritDefaultTemplateArguments(Reader.getContext(),
 cast(Previous), TD);
+
+  // If any of the declaration in the chain contains an Inheritable attribute,
+  // it needs to be added to all the declarations in the redeclarable chain.
+  // FIXME: Only the logic of merging MSInheritableAttr is present, it should
+  // be extended for all inheritable attributes.
+  mergeInheritableAttributes(Reader, D, Previous);
 }
 
 template
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-08-21 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 added a comment.

In D83174#2230546 , @aaron.ballman 
wrote:

> LGTM, thank you for the fix! Do you need someone to commit on your behalf? If 
> so, please be sure you're fine with the license agreement and let us know 
> what name and email address you would like associated with the commit. Thanks!

Hi, 
Yes, I am fine with the license agreement.
Name: Vaibhav Garg
E-Mail: gargvaibha...@gmail.com

Thanks a lot!


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

https://reviews.llvm.org/D83174

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


[PATCH] D83174: Teach AttachPreviousImpl to inherit MSInheritanceAttr attribute

2020-08-21 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 updated this revision to Diff 287060.
gargvaibhav64 added a comment.

I updated the -triple option to x86_64-pc-windows-msvc (as it was more 
consistent with current tests). I also updated the path to Unix style in the -I 
option.


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

https://reviews.llvm.org/D83174

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/Inputs/inherit-attribute/a.h
  clang/test/Modules/Inputs/inherit-attribute/b.h
  clang/test/Modules/Inputs/inherit-attribute/c.h
  clang/test/Modules/Inputs/inherit-attribute/module.modulemap
  clang/test/Modules/inherit-attribute.cpp

Index: clang/test/Modules/inherit-attribute.cpp
===
--- /dev/null
+++ clang/test/Modules/inherit-attribute.cpp
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -triple x86_64-pc-windows-msvc -I%S/Inputs/inherit-attribute -fmodules-cache-path=%t \
+// RUN: -fimplicit-module-maps -fmodules-local-submodule-visibility %s -ast-dump-all \
+// RUN: | FileCheck %s
+
+#include "b.h"
+#include "c.h"
+
+class Foo;
+
+Foo f;
+
+// CHECK:   CXXRecordDecl {{.*}} imported in b {{.*}} Foo
+// CHECK:   MSInheritanceAttr {{[^()]*$}}
+
+// CHECK:   CXXRecordDecl {{.*}} prev {{.*}} imported in c {{.*}} Foo
+// CHECK:   MSInheritanceAttr {{.*}} Inherited {{[^()]*$}}
+
+// CHECK:   CXXRecordDecl {{.*}}  col:7 referenced class Foo
+// CHECK:   MSInheritanceAttr {{.*}} Inherited {{[^()]*$}}
Index: clang/test/Modules/Inputs/inherit-attribute/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/module.modulemap
@@ -0,0 +1,3 @@
+module "b" { header "b.h" }
+
+module "c" { header "c.h" }
Index: clang/test/Modules/Inputs/inherit-attribute/c.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/c.h
@@ -0,0 +1 @@
+#include "a.h"
Index: clang/test/Modules/Inputs/inherit-attribute/b.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/b.h
@@ -0,0 +1,5 @@
+#include "a.h"
+
+void bar() {
+  &Foo::step;
+}
Index: clang/test/Modules/Inputs/inherit-attribute/a.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/inherit-attribute/a.h
@@ -0,0 +1,10 @@
+#ifndef FOO
+#define FOO
+
+class Foo {
+public:
+  void step(int v);
+  Foo();
+};
+
+#endif
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -281,6 +281,9 @@
 static Decl *getMostRecentDeclImpl(...);
 static Decl *getMostRecentDecl(Decl *D);
 
+static void mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+   Decl *Previous);
+
 template 
 static void attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D, Decl *Previous,
@@ -3531,6 +3534,19 @@
   return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
 }
 
+void ASTDeclReader::mergeInheritableAttributes(ASTReader &Reader, Decl *D,
+   Decl *Previous) {
+  InheritableAttr *NewAttr = nullptr;
+  ASTContext &Context = Reader.getContext();
+  const auto *IA = Previous->getAttr();
+
+  if (IA && !D->hasAttr()) {
+NewAttr = cast(IA->clone(Context));
+NewAttr->setInherited(true);
+D->addAttr(NewAttr);
+  }
+}
+
 template
 void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Redeclarable *D,
@@ -3689,6 +3705,12 @@
   if (auto *TD = dyn_cast(D))
 inheritDefaultTemplateArguments(Reader.getContext(),
 cast(Previous), TD);
+
+  // If any of the declaration in the chain contains an Inheritable attribute,
+  // it needs to be added to all the declarations in the redeclarable chain.
+  // FIXME: Only the logic of merging MSInheritableAttr is present, it should
+  // be extended for all inheritable attributes.
+  mergeInheritableAttributes(Reader, D, Previous);
 }
 
 template
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86514: Correctly parse LateParsedTemplates in case of multiple dependent modules

2020-08-25 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 created this revision.
gargvaibhav64 added reviewers: rsmith, v.g.vassilev.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
gargvaibhav64 requested review of this revision.

While parsing LateParsedTemplates, Clang assumes that the Global DeclID matches 
with the Local DeclID of a Decl. This is not the case when we have multiple 
dependent modules have their own LateParsedTemplate section. In such a case, a 
Local/Global DeclID confusion occurs which leads to improper casting of 
Functions.

This commit creates a MapVector to map the LateParsedTemplate section of each 
Module with their module file and therefore resolving the Global/Local DeclID 
confusion.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86514

Files:
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Serialization/ASTReader.cpp


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3721,6 +3721,9 @@
 
 case LATE_PARSED_TEMPLATE:
   LateParsedTemplates.append(Record.begin(), Record.end());
+  LateParsedTemplatesModulesMap.insert(
+  std::make_pair(&F, std::move(LateParsedTemplates)));
+  LateParsedTemplates.clear();
   break;
 
 case OPTIMIZE_PRAGMA_OPTIONS:
@@ -8386,25 +8389,28 @@
 void ASTReader::ReadLateParsedTemplates(
 llvm::MapVector>
 &LPTMap) {
-  for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N;
-   /* In loop */) {
-FunctionDecl *FD = cast(GetDecl(LateParsedTemplates[Idx++]));
+  for (auto &LPT : LateParsedTemplatesModulesMap) {
+ModuleFile *FMod = LPT.first;
+SmallVector LateParsed(LPT.second);
+for (unsigned Idx = 0, N = LateParsed.size(); Idx < N;
+ /* In loop */) {
+  FunctionDecl *FD =
+  cast(GetLocalDecl(*FMod, LateParsed[Idx++]));
 
-auto LT = std::make_unique();
-LT->D = GetDecl(LateParsedTemplates[Idx++]);
+  auto LT = llvm::make_unique();
+  LT->D = GetLocalDecl(*FMod, LateParsed[Idx++]);
 
-ModuleFile *F = getOwningModuleFile(LT->D);
-assert(F && "No module");
+  ModuleFile *F = getOwningModuleFile(LT->D);
+  assert(F && "No module");
 
-unsigned TokN = LateParsedTemplates[Idx++];
-LT->Toks.reserve(TokN);
-for (unsigned T = 0; T < TokN; ++T)
-  LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx));
+  unsigned TokN = LateParsed[Idx++];
+  LT->Toks.reserve(TokN);
+  for (unsigned T = 0; T < TokN; ++T)
+LT->Toks.push_back(ReadToken(*F, LateParsed, Idx));
 
-LPTMap.insert(std::make_pair(FD, std::move(LT)));
+  LPTMap.insert(std::make_pair(FD, std::move(LT)));
+}
   }
-
-  LateParsedTemplates.clear();
 }
 
 void ASTReader::LoadSelector(Selector Sel) {
Index: clang/include/clang/Serialization/ASTReader.h
===
--- clang/include/clang/Serialization/ASTReader.h
+++ clang/include/clang/Serialization/ASTReader.h
@@ -903,6 +903,10 @@
   // A list of late parsed template function data.
   SmallVector LateParsedTemplates;
 
+  // A list of LateParsedTemplates paired with their module files.
+  llvm::MapVector>
+  LateParsedTemplatesModulesMap;
+
   /// The IDs of all decls to be checked for deferred diags.
   ///
   /// Sema tracks these to emit deferred diags.


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3721,6 +3721,9 @@
 
 case LATE_PARSED_TEMPLATE:
   LateParsedTemplates.append(Record.begin(), Record.end());
+  LateParsedTemplatesModulesMap.insert(
+  std::make_pair(&F, std::move(LateParsedTemplates)));
+  LateParsedTemplates.clear();
   break;
 
 case OPTIMIZE_PRAGMA_OPTIONS:
@@ -8386,25 +8389,28 @@
 void ASTReader::ReadLateParsedTemplates(
 llvm::MapVector>
 &LPTMap) {
-  for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N;
-   /* In loop */) {
-FunctionDecl *FD = cast(GetDecl(LateParsedTemplates[Idx++]));
+  for (auto &LPT : LateParsedTemplatesModulesMap) {
+ModuleFile *FMod = LPT.first;
+SmallVector LateParsed(LPT.second);
+for (unsigned Idx = 0, N = LateParsed.size(); Idx < N;
+ /* In loop */) {
+  FunctionDecl *FD =
+  cast(GetLocalDecl(*FMod, LateParsed[Idx++]));
 
-auto LT = std::make_unique();
-LT->D = GetDecl(LateParsedTemplates[Idx++]);
+  auto LT = llvm::make_unique();
+  LT->D = GetLocalDecl(*FMod, LateParsed[Idx++]);
 
-ModuleFile *F = getOwningModuleFile(LT->D);
-assert(F && "No module");
+  ModuleFile *F = getOwningModuleFile(LT->D);
+  assert(F && "No module");
 
-unsigned TokN = LateParsedTemplates[Idx++];
-LT->Toks.reserve(TokN);
-for (unsigned T = 0; T < TokN; 

[PATCH] D86514: Correctly parse LateParsedTemplates in case of multiple dependent modules

2020-08-25 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 updated this revision to Diff 287609.
gargvaibhav64 edited the summary of this revision.
gargvaibhav64 added a comment.

Resolve a typo.


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

https://reviews.llvm.org/D86514

Files:
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Serialization/ASTReader.cpp


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3721,6 +3721,9 @@
 
 case LATE_PARSED_TEMPLATE:
   LateParsedTemplates.append(Record.begin(), Record.end());
+  LateParsedTemplatesModulesMap.insert(
+  std::make_pair(&F, std::move(LateParsedTemplates)));
+  LateParsedTemplates.clear();
   break;
 
 case OPTIMIZE_PRAGMA_OPTIONS:
@@ -8386,25 +8389,28 @@
 void ASTReader::ReadLateParsedTemplates(
 llvm::MapVector>
 &LPTMap) {
-  for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N;
-   /* In loop */) {
-FunctionDecl *FD = cast(GetDecl(LateParsedTemplates[Idx++]));
+  for (auto &LPT : LateParsedTemplatesModulesMap) {
+ModuleFile *FMod = LPT.first;
+SmallVector LateParsed(LPT.second);
+for (unsigned Idx = 0, N = LateParsed.size(); Idx < N;
+ /* In loop */) {
+  FunctionDecl *FD =
+  cast(GetLocalDecl(*FMod, LateParsed[Idx++]));
 
-auto LT = std::make_unique();
-LT->D = GetDecl(LateParsedTemplates[Idx++]);
+  auto LT = std::make_unique();
+  LT->D = GetLocalDecl(*FMod, LateParsed[Idx++]);
 
-ModuleFile *F = getOwningModuleFile(LT->D);
-assert(F && "No module");
+  ModuleFile *F = getOwningModuleFile(LT->D);
+  assert(F && "No module");
 
-unsigned TokN = LateParsedTemplates[Idx++];
-LT->Toks.reserve(TokN);
-for (unsigned T = 0; T < TokN; ++T)
-  LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx));
+  unsigned TokN = LateParsed[Idx++];
+  LT->Toks.reserve(TokN);
+  for (unsigned T = 0; T < TokN; ++T)
+LT->Toks.push_back(ReadToken(*F, LateParsed, Idx));
 
-LPTMap.insert(std::make_pair(FD, std::move(LT)));
+  LPTMap.insert(std::make_pair(FD, std::move(LT)));
+}
   }
-
-  LateParsedTemplates.clear();
 }
 
 void ASTReader::LoadSelector(Selector Sel) {
Index: clang/include/clang/Serialization/ASTReader.h
===
--- clang/include/clang/Serialization/ASTReader.h
+++ clang/include/clang/Serialization/ASTReader.h
@@ -903,6 +903,10 @@
   // A list of late parsed template function data.
   SmallVector LateParsedTemplates;
 
+  // A list of LateParsedTemplates paired with their module files.
+  llvm::MapVector>
+  LateParsedTemplatesModulesMap;
+
   /// The IDs of all decls to be checked for deferred diags.
   ///
   /// Sema tracks these to emit deferred diags.


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3721,6 +3721,9 @@
 
 case LATE_PARSED_TEMPLATE:
   LateParsedTemplates.append(Record.begin(), Record.end());
+  LateParsedTemplatesModulesMap.insert(
+  std::make_pair(&F, std::move(LateParsedTemplates)));
+  LateParsedTemplates.clear();
   break;
 
 case OPTIMIZE_PRAGMA_OPTIONS:
@@ -8386,25 +8389,28 @@
 void ASTReader::ReadLateParsedTemplates(
 llvm::MapVector>
 &LPTMap) {
-  for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N;
-   /* In loop */) {
-FunctionDecl *FD = cast(GetDecl(LateParsedTemplates[Idx++]));
+  for (auto &LPT : LateParsedTemplatesModulesMap) {
+ModuleFile *FMod = LPT.first;
+SmallVector LateParsed(LPT.second);
+for (unsigned Idx = 0, N = LateParsed.size(); Idx < N;
+ /* In loop */) {
+  FunctionDecl *FD =
+  cast(GetLocalDecl(*FMod, LateParsed[Idx++]));
 
-auto LT = std::make_unique();
-LT->D = GetDecl(LateParsedTemplates[Idx++]);
+  auto LT = std::make_unique();
+  LT->D = GetLocalDecl(*FMod, LateParsed[Idx++]);
 
-ModuleFile *F = getOwningModuleFile(LT->D);
-assert(F && "No module");
+  ModuleFile *F = getOwningModuleFile(LT->D);
+  assert(F && "No module");
 
-unsigned TokN = LateParsedTemplates[Idx++];
-LT->Toks.reserve(TokN);
-for (unsigned T = 0; T < TokN; ++T)
-  LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx));
+  unsigned TokN = LateParsed[Idx++];
+  LT->Toks.reserve(TokN);
+  for (unsigned T = 0; T < TokN; ++T)
+LT->Toks.push_back(ReadToken(*F, LateParsed, Idx));
 
-LPTMap.insert(std::make_pair(FD, std::move(LT)));
+  LPTMap.insert(std::make_pair(FD, std::move(LT)));
+}
   }
-
-  LateParsedTemplates.clear();
 }
 
 void ASTReader::LoadSelector(Selector Sel) {
Index: clang/include/clang/Serialization/ASTReader.h
=

[PATCH] D86514: Correctly parse LateParsedTemplates in case of multiple dependent modules

2020-08-26 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 updated this revision to Diff 288186.
gargvaibhav64 marked 5 inline comments as done.
gargvaibhav64 edited the summary of this revision.

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

https://reviews.llvm.org/D86514

Files:
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Serialization/ASTReader.cpp


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3720,7 +3720,9 @@
 }
 
 case LATE_PARSED_TEMPLATE:
-  LateParsedTemplates.append(Record.begin(), Record.end());
+  LateParsedTemplates.emplace_back(
+  std::piecewise_construct, std::forward_as_tuple(&F),
+  std::forward_as_tuple(Record.begin(), Record.end()));
   break;
 
 case OPTIMIZE_PRAGMA_OPTIONS:
@@ -8386,25 +8388,28 @@
 void ASTReader::ReadLateParsedTemplates(
 llvm::MapVector>
 &LPTMap) {
-  for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N;
-   /* In loop */) {
-FunctionDecl *FD = cast(GetDecl(LateParsedTemplates[Idx++]));
+  for (auto &LPT : LateParsedTemplates) {
+ModuleFile *FMod = LPT.first;
+RecordDataImpl &LateParsed = LPT.second;
+for (unsigned Idx = 0, N = LateParsed.size(); Idx < N;
+ /* In loop */) {
+  FunctionDecl *FD =
+  cast(GetLocalDecl(*FMod, LateParsed[Idx++]));
 
-auto LT = std::make_unique();
-LT->D = GetDecl(LateParsedTemplates[Idx++]);
+  auto LT = std::make_unique();
+  LT->D = GetLocalDecl(*FMod, LateParsed[Idx++]);
 
-ModuleFile *F = getOwningModuleFile(LT->D);
-assert(F && "No module");
+  ModuleFile *F = getOwningModuleFile(LT->D);
+  assert(F && "No module");
 
-unsigned TokN = LateParsedTemplates[Idx++];
-LT->Toks.reserve(TokN);
-for (unsigned T = 0; T < TokN; ++T)
-  LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx));
+  unsigned TokN = LateParsed[Idx++];
+  LT->Toks.reserve(TokN);
+  for (unsigned T = 0; T < TokN; ++T)
+LT->Toks.push_back(ReadToken(*F, LateParsed, Idx));
 
-LPTMap.insert(std::make_pair(FD, std::move(LT)));
+  LPTMap.insert(std::make_pair(FD, std::move(LT)));
+}
   }
-
-  LateParsedTemplates.clear();
 }
 
 void ASTReader::LoadSelector(Selector Sel) {
Index: clang/include/clang/Serialization/ASTReader.h
===
--- clang/include/clang/Serialization/ASTReader.h
+++ clang/include/clang/Serialization/ASTReader.h
@@ -900,8 +900,9 @@
   /// Delete expressions to analyze at the end of translation unit.
   SmallVector DelayedDeleteExprs;
 
-  // A list of late parsed template function data.
-  SmallVector LateParsedTemplates;
+  // A list of late parsed template function data with their module files.
+  SmallVector>, 4>
+  LateParsedTemplates;
 
   /// The IDs of all decls to be checked for deferred diags.
   ///


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -3720,7 +3720,9 @@
 }
 
 case LATE_PARSED_TEMPLATE:
-  LateParsedTemplates.append(Record.begin(), Record.end());
+  LateParsedTemplates.emplace_back(
+  std::piecewise_construct, std::forward_as_tuple(&F),
+  std::forward_as_tuple(Record.begin(), Record.end()));
   break;
 
 case OPTIMIZE_PRAGMA_OPTIONS:
@@ -8386,25 +8388,28 @@
 void ASTReader::ReadLateParsedTemplates(
 llvm::MapVector>
 &LPTMap) {
-  for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N;
-   /* In loop */) {
-FunctionDecl *FD = cast(GetDecl(LateParsedTemplates[Idx++]));
+  for (auto &LPT : LateParsedTemplates) {
+ModuleFile *FMod = LPT.first;
+RecordDataImpl &LateParsed = LPT.second;
+for (unsigned Idx = 0, N = LateParsed.size(); Idx < N;
+ /* In loop */) {
+  FunctionDecl *FD =
+  cast(GetLocalDecl(*FMod, LateParsed[Idx++]));
 
-auto LT = std::make_unique();
-LT->D = GetDecl(LateParsedTemplates[Idx++]);
+  auto LT = std::make_unique();
+  LT->D = GetLocalDecl(*FMod, LateParsed[Idx++]);
 
-ModuleFile *F = getOwningModuleFile(LT->D);
-assert(F && "No module");
+  ModuleFile *F = getOwningModuleFile(LT->D);
+  assert(F && "No module");
 
-unsigned TokN = LateParsedTemplates[Idx++];
-LT->Toks.reserve(TokN);
-for (unsigned T = 0; T < TokN; ++T)
-  LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx));
+  unsigned TokN = LateParsed[Idx++];
+  LT->Toks.reserve(TokN);
+  for (unsigned T = 0; T < TokN; ++T)
+LT->Toks.push_back(ReadToken(*F, LateParsed, Idx));
 
-LPTMap.insert(std::make_pair(FD, std::move(LT)));
+  LPTMap.insert(std::make_pair(FD, std::move(LT)));
+}
   }
-
-  LateParsedTemplates.clear();
 }
 
 void A

[PATCH] D86514: Correctly parse LateParsedTemplates in case of multiple dependent modules

2020-08-26 Thread Vaibhav Garg via Phabricator via cfe-commits
gargvaibhav64 added a comment.

Thanks. I incorporated all the changes.


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

https://reviews.llvm.org/D86514

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