Allocate builtins table earlier to fix bug found by ubsan
authorReid Kleckner <rnk@google.com>
Mon, 18 Nov 2019 18:37:54 +0000 (10:37 -0800)
committerReid Kleckner <rnk@google.com>
Mon, 18 Nov 2019 18:41:30 +0000 (10:41 -0800)
Follow up to 979da9a4c3ba

clang/lib/Lex/Preprocessor.cpp

index 496eae9..0e9be39 100644 (file)
@@ -113,6 +113,8 @@ Preprocessor::Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
   // We haven't read anything from the external source.
   ReadMacrosFromExternalSource = false;
 
+  BuiltinInfo = std::make_unique<Builtin::Context>();
+
   // "Poison" __VA_ARGS__, __VA_OPT__ which can only appear in the expansion of
   // a macro. They get unpoisoned where it is allowed.
   (Ident__VA_ARGS__ = getIdentifierInfo("__VA_ARGS__"))->setIsPoisoned();
@@ -203,7 +205,6 @@ void Preprocessor::Initialize(const TargetInfo &Target,
   this->AuxTarget = AuxTarget;
 
   // Initialize information about built-ins.
-  BuiltinInfo = std::make_unique<Builtin::Context>();
   BuiltinInfo->InitializeTarget(Target, AuxTarget);
   HeaderInfo.setTarget(Target);