r240571 - [Preprocessor] Iterating over all macros should include those from modules.
Justin Bogner
mail at justinbogner.com
Thu Jun 25 11:54:06 PDT 2015
Jordan Rose <jordan_rose at apple.com> writes:
> Author: jrose
> Date: Wed Jun 24 14:27:02 2015
> New Revision: 240571
>
> URL: http://llvm.org/viewvc/llvm-project?rev=240571&view=rev
> Log:
> [Preprocessor] Iterating over all macros should include those from modules.
>
> So, iterate over the list of macros mentioned in modules, and make sure those
> are in the master table.
This introduces a null dereference in Preprocessor::findDirectiveAtLoc.
It triggers in clang/test/Modules/crashes.m, so you can find it by
adding an assert next to the very relevant sounding FIXME like so:
--- a/include/clang/Lex/Preprocessor.h
+++ b/include/clang/Lex/Preprocessor.h
@@ -454,6 +454,7 @@ class Preprocessor : public RefCountedBase<Preprocessor> {
MacroDirective::DefInfo findDirectiveAtLoc(SourceLocation Loc,
SourceManager &SourceMgr) const {
// FIXME: Incorporate module macros into the result of this.
+ assert(getLatest() != nullptr);
return getLatest()->findDirectiveAtLoc(Loc, SourceMgr);
}
I found this with ubsan, but I still need a couple of clang patches
reviewed before I can make a bot to catch such things. For anyone
interested:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150622/131431.html
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150622/131432.html
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150622/131433.html
> This isn't particularly efficient, but hopefully it's something that isn't
> done too often.
>
> PR23929 and rdar://problem/21480635
>
> Added:
> cfe/trunk/test/CodeCompletion/macros-in-modules.c
> cfe/trunk/test/CodeCompletion/macros-in-modules.m
> Modified:
> cfe/trunk/lib/Lex/Preprocessor.cpp
>
> Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=240571&r1=240570&r2=240571&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
> +++ cfe/trunk/lib/Lex/Preprocessor.cpp Wed Jun 24 14:27:02 2015
> @@ -286,6 +286,10 @@ Preprocessor::macro_begin(bool IncludeEx
> ExternalSource->ReadDefinedMacros();
> }
>
> + // Make sure we cover all macros in visible modules.
> + for (const ModuleMacro &Macro : ModuleMacros)
> + CurSubmoduleState->Macros.insert(std::make_pair(Macro.II, MacroState()));
> +
> return CurSubmoduleState->Macros.begin();
> }
>
>
> Added: cfe/trunk/test/CodeCompletion/macros-in-modules.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/macros-in-modules.c?rev=240571&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeCompletion/macros-in-modules.c (added)
> +++ cfe/trunk/test/CodeCompletion/macros-in-modules.c Wed Jun 24 14:27:02 2015
> @@ -0,0 +1,11 @@
> +// RUN: rm -rf %t && mkdir %t
> +// RUN: echo 'module Foo { header "foo.h" }' > %t/module.modulemap
> +// RUN: echo '#define FOO_MACRO 42' > %t/foo.h
> +// RUN: c-index-test -code-completion-at=%s:9:1 -I %t %s | FileCheck %s
> +// RUN: c-index-test -code-completion-at=%s:9:1 -I %t -fmodules %s | FileCheck %s
> +
> +#include "foo.h"
> +int x =
> +/*here*/1;
> +
> +// CHECK: FOO_MACRO
>
> Added: cfe/trunk/test/CodeCompletion/macros-in-modules.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/macros-in-modules.m?rev=240571&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeCompletion/macros-in-modules.m (added)
> +++ cfe/trunk/test/CodeCompletion/macros-in-modules.m Wed Jun 24 14:27:02 2015
> @@ -0,0 +1,10 @@
> +// RUN: rm -rf %t && mkdir %t
> +// RUN: echo 'module Foo { header "foo.h" }' > %t/module.modulemap
> +// RUN: echo '#define FOO_MACRO 42' > %t/foo.h
> +// RUN: c-index-test -code-completion-at=%s:8:1 -I %t -fmodules %s | FileCheck %s
> +
> + at import Foo;
> +int x =
> +/*here*/1;
> +
> +// CHECK: FOO_MACRO
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list