[OpaquePtrs][Clang] Add -opaque-pointers/-no-opaque-pointers cc1 options

This adds cc1 options for enabling and disabling opaque pointers
on the clang side. This is not super useful now (because
-mllvm -opaque-pointers and -Xclang -opaque-pointers have the same
visible effect) but will be important once opaque pointers are
enabled by default in clang. In that case, it will only be
possible to disable them using the cc1 -no-opaque-pointers option.

Differential Revision: https://reviews.llvm.org/D123034
This commit is contained in:
Nikita Popov 2022-04-04 16:58:42 +02:00
parent cc6788aece
commit d69e9f9d89
4 changed files with 40 additions and 0 deletions

View File

@ -469,6 +469,9 @@ CODEGENOPT(SkipRaxSetup, 1, 0)
ENUM_CODEGENOPT(ZeroCallUsedRegs, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind,
5, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind::Skip)
/// Whether to use opaque pointers.
CODEGENOPT(OpaquePointers, 1, 0)
#undef CODEGENOPT
#undef ENUM_CODEGENOPT
#undef VALUE_CODEGENOPT

View File

@ -5504,6 +5504,13 @@ defm enable_noundef_analysis : BoolOption<"",
PosFlag<SetTrue, [], "Enable">,
NegFlag<SetFalse, [], "Disable">,
BothFlags<[], " analyzing function argument and return types for mandatory definedness">>;
defm opaque_pointers : BoolOption<"",
"opaque-pointers",
CodeGenOpts<"OpaquePointers">,
DefaultFalse,
PosFlag<SetTrue, [], "Enable">,
NegFlag<SetFalse, [], "Disable">,
BothFlags<[], " opaque pointers">>;
def discard_value_names : Flag<["-"], "discard-value-names">,
HelpText<"Discard value names in LLVM IR">,
MarshallingInfoFlag<CodeGenOpts<"DiscardValueNames">>;

View File

@ -983,6 +983,9 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
if (BA != Backend_EmitNothing && !OS)
return nullptr;
if (CI.getCodeGenOpts().OpaquePointers)
VMContext->enableOpaquePointers();
// Load bitcode modules to link with, if we need to.
if (LinkModules.empty())
for (const CodeGenOptions::BitcodeFileToLink &F :

View File

@ -0,0 +1,27 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=TYPED
// RUN: %clang_cc1 -opaque-pointers -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=OPAQUE
// The current default is typed pointers:
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=TYPED
// TYPED-LABEL: @test(
// TYPED-NEXT: entry:
// TYPED-NEXT: [[P_ADDR:%.*]] = alloca i32*, align 8
// TYPED-NEXT: store i32* [[P:%.*]], i32** [[P_ADDR]], align 8
// TYPED-NEXT: [[TMP0:%.*]] = load i32*, i32** [[P_ADDR]], align 8
// TYPED-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[TMP0]], i64 1
// TYPED-NEXT: [[TMP1:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
// TYPED-NEXT: ret i32 [[TMP1]]
//
// OPAQUE-LABEL: @test(
// OPAQUE-NEXT: entry:
// OPAQUE-NEXT: [[P_ADDR:%.*]] = alloca ptr, align 8
// OPAQUE-NEXT: store ptr [[P:%.*]], ptr [[P_ADDR]], align 8
// OPAQUE-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P_ADDR]], align 8
// OPAQUE-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP0]], i64 1
// OPAQUE-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
// OPAQUE-NEXT: ret i32 [[TMP1]]
//
int test(int *p) {
return p[1];
}