In r276159, we started to defer emitting initializers for VarDecls, but
forgot to add the initializers for non-C++ language.
rdar://
28740482
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284142
91177308-0d34-0410-b5e6-
96231b3b80d8
}
// All the following checks are C++ only.
- if (!getLangOpts().CPlusPlus) return;
+ if (!getLangOpts().CPlusPlus) {
+ // If this variable must be emitted, add it as an initializer for the
+ // current module.
+ if (Context.DeclMustBeEmitted(var) && !ModuleScopes.empty())
+ Context.addModuleInitializer(ModuleScopes.back().Module, var);
+ return;
+ }
if (auto *DD = dyn_cast<DecompositionDecl>(var))
CheckCompleteDecompositionDeclaration(DD);
--- /dev/null
+@interface NSString
+@end
+static const NSString * const kSimDeviceIOGetInterface = @"simdeviceio_get_interface";
--- /dev/null
+module X {
+ header "X.h"
+ export *
+}
--- /dev/null
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/objc-initializer %s -emit-llvm -o - -fobjc-arc | FileCheck %s
+// CHECK: kSimDeviceIOGetInterface = internal constant {{.*}} bitcast
+
+#import <X.h>
+void test2(const NSString*);
+void test() {
+ test2(kSimDeviceIOGetInterface);
+}