diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1883,7 +1883,9 @@ case bitc::TYPE_CODE_OPAQUE_POINTER: { // OPAQUE_POINTER: [addrspace] if (Record.size() != 1) return error("Invalid opaque pointer record"); - if (Context.supportsTypedPointers()) + if (LLVM_UNLIKELY(!Context.hasSetOpaquePointersValue())) { + Context.enableOpaquePointers(); + } else if (Context.supportsTypedPointers()) return error( "Opaque pointers are only supported in -opaque-pointers mode"); unsigned AddressSpace = Record[0]; diff --git a/llvm/test/Other/force-opaque-ptrs.ll b/llvm/test/Other/force-opaque-ptrs.ll --- a/llvm/test/Other/force-opaque-ptrs.ll +++ b/llvm/test/Other/force-opaque-ptrs.ll @@ -1,6 +1,7 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature ; RUN: llvm-as --opaque-pointers < %s | llvm-dis --opaque-pointers | FileCheck %s ; RUN: llvm-as < %s | llvm-dis --opaque-pointers | FileCheck %s +; RUN: llvm-as --opaque-pointers < %s | llvm-dis | FileCheck %s ; RUN: opt --opaque-pointers < %s -S | FileCheck %s ; RUN: verify-uselistorder --opaque-pointers < %s