]> granicus.if.org Git - clang/commitdiff
Always allocate room for a ModuleDecl on the TranslationUnitDecl.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 5 Sep 2017 00:50:19 +0000 (00:50 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 5 Sep 2017 00:50:19 +0000 (00:50 +0000)
Sometimes we create the ASTContext and thus the TranslationUnitDecl before we know the LangOptions. This should fix the asan buildbot failures after r312467.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312506 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclBase.cpp

index cd2c83a02f5999d79314d5776f9e6dda2b9ce172..abe17b5a84046a5c59eae7c664889c9b1fe570d7 100644 (file)
@@ -74,8 +74,9 @@ void *Decl::operator new(std::size_t Size, const ASTContext &Ctx,
                          DeclContext *Parent, std::size_t Extra) {
   assert(!Parent || &Parent->getParentASTContext() == &Ctx);
   // With local visibility enabled, we track the owning module even for local
-  // declarations.
-  if (Ctx.getLangOpts().trackLocalOwningModule()) {
+  // declarations. We create the TU decl early and may not yet know what the
+  // LangOpts are, so conservatively allocate the storage.
+  if (Ctx.getLangOpts().trackLocalOwningModule() || !Parent) {
     // Ensure required alignment of the resulting object by adding extra
     // padding at the start if required.
     size_t ExtraAlign =