]> granicus.if.org Git - clang/commitdiff
When building a module from the command line via -emit-module, add an entry to
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 5 Mar 2014 20:55:36 +0000 (20:55 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 5 Mar 2014 20:55:36 +0000 (20:55 +0000)
the module build stack for the module being built, so we can correctly detect
recursive module builds.

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

lib/Frontend/DiagnosticRenderer.cpp
lib/Frontend/FrontendActions.cpp
test/Modules/recursive.c

index 4eee59548c82130262d86fd28885047264c16a4e..b52f0103e6b004f7f2af4cf6fe3b800d36122b84 100644 (file)
@@ -499,8 +499,11 @@ DiagnosticNoteRenderer::emitBuildingModuleLocation(SourceLocation Loc,
   // Generate a note indicating the include location.
   SmallString<200> MessageStorage;
   llvm::raw_svector_ostream Message(MessageStorage);
-  Message << "while building module '" << ModuleName << "' imported from "
-          << PLoc.getFilename() << ':' << PLoc.getLine() << ":";
+  if (PLoc.getFilename())
+    Message << "while building module '" << ModuleName << "' imported from "
+            << PLoc.getFilename() << ':' << PLoc.getLine() << ":";
+  else
+    Message << "while building module '" << ModuleName << ":";
   emitNote(Loc, Message.str(), &SM);
 }
 
index f587d829b396c9403c01fde86760c85c1c7fa7d1..4ed2df3a25ced8f796a336822a2c9895f6b909f6 100644 (file)
@@ -240,7 +240,15 @@ bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI,
     // map with a single module (the common case).
     return false;
   }
-  
+
+  // If we're being run from the command-line, the module build stack will not
+  // have been filled in yet, so complete it now in order to allow us to detect
+  // module cycles.
+  SourceManager &SourceMgr = CI.getSourceManager();
+  if (SourceMgr.getModuleBuildStack().empty())
+    SourceMgr.pushModuleBuildStack(CI.getLangOpts().CurrentModule,
+                                   FullSourceLoc(SourceLocation(), SourceMgr));
+
   // Dig out the module definition.
   Module = HS.lookupModule(CI.getLangOpts().CurrentModule, 
                            /*AllowSearch=*/false);
index 668ba38dffaf70dfae96abd60f3d8ee76f980879..7941df684054fee5d52520e4c53a4bb36103eedd 100644 (file)
@@ -2,8 +2,8 @@
 // RUN: not %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -I %S/Inputs %s 2>&1 | FileCheck %s
 #include "recursive1.h"
 
-// FIXME: rm -rf %t
-// FIXME: not %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -emit-module -fmodule-name=recursive1 %S/Inputs/module.map 2>&1 | FileCheck %s
+// RUN: rm -rf %t
+// RUN: not %clang_cc1 -fmodules -x objective-c -fmodules-cache-path=%t -emit-module -fmodule-name=recursive1 %S/Inputs/module.map 2>&1 | FileCheck %s
 
 // CHECK:      While building module 'recursive1'{{( imported from .*/recursive.c:3)?}}:
 // CHECK-NEXT: While building module 'recursive2' imported from {{.*}}Inputs/recursive1.h:1: