Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -1983,9 +1983,15 @@ llvm::Constant *C = GetOrCreateLLVMFunction(Name, FTy, GlobalDecl(), /*ForVTable=*/false, /*DontDefer=*/false, /*IsThunk=*/false, ExtraAttrs); - if (auto *F = dyn_cast(C)) + if (auto *F = dyn_cast(C)) { + // Mark runtime functions with reserved names as unnamed_addr, as user + // programs shouldn't be able to observe their addresses without invoking + // undefined behavior. + if (Name[0] == '_') + F->setUnnamedAddr(true); if (F->empty()) F->setCallingConv(getRuntimeCC()); + } return C; } Index: test/CodeGenCXX/dynamic-cast.cpp =================================================================== --- test/CodeGenCXX/dynamic-cast.cpp +++ test/CodeGenCXX/dynamic-cast.cpp @@ -18,7 +18,7 @@ return fail; } -// CHECK: declare i8* @__dynamic_cast(i8*, i8*, i8*, i64) [[NUW_RO:#[0-9]+]] +// CHECK: declare i8* @__dynamic_cast(i8*, i8*, i8*, i64) unnamed_addr [[NUW_RO:#[0-9]+]] // CHECK: attributes [[NUW_RO]] = { nounwind readonly } // CHECK: attributes [[NR]] = { noreturn } Index: test/CodeGenCXX/exceptions.cpp =================================================================== --- test/CodeGenCXX/exceptions.cpp +++ test/CodeGenCXX/exceptions.cpp @@ -74,7 +74,7 @@ // rdar://11904428 // Terminate landing pads should call __cxa_begin_catch first. - // CHECK: define linkonce_odr hidden void @__clang_call_terminate(i8*) [[NI_NR_NUW:#[0-9]+]] comdat + // CHECK: define linkonce_odr hidden void @__clang_call_terminate(i8*) unnamed_addr [[NI_NR_NUW:#[0-9]+]] comdat // CHECK-NEXT: [[T0:%.*]] = call i8* @__cxa_begin_catch(i8* %0) [[NUW:#[0-9]+]] // CHECK-NEXT: call void @_ZSt9terminatev() [[NR_NUW:#[0-9]+]] // CHECK-NEXT: unreachable Index: test/CodeGenCXX/runtimecc.cpp =================================================================== --- test/CodeGenCXX/runtimecc.cpp +++ test/CodeGenCXX/runtimecc.cpp @@ -26,7 +26,7 @@ // CHECK-NEXT: ret void } -// CHECK: declare i32 @__cxa_atexit(void (i8*)*, i8*, i8*) [[NOUNWIND]] +// CHECK: declare i32 @__cxa_atexit(void (i8*)*, i8*, i8*) unnamed_addr [[NOUNWIND]] namespace test1 { void test() {