Skip to content

Commit d69e9f9

Browse files
committed
[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
1 parent cc6788a commit d69e9f9

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@ CODEGENOPT(SkipRaxSetup, 1, 0)
469469
ENUM_CODEGENOPT(ZeroCallUsedRegs, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind,
470470
5, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind::Skip)
471471

472+
/// Whether to use opaque pointers.
473+
CODEGENOPT(OpaquePointers, 1, 0)
474+
472475
#undef CODEGENOPT
473476
#undef ENUM_CODEGENOPT
474477
#undef VALUE_CODEGENOPT

clang/include/clang/Driver/Options.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5504,6 +5504,13 @@ defm enable_noundef_analysis : BoolOption<"",
55045504
PosFlag<SetTrue, [], "Enable">,
55055505
NegFlag<SetFalse, [], "Disable">,
55065506
BothFlags<[], " analyzing function argument and return types for mandatory definedness">>;
5507+
defm opaque_pointers : BoolOption<"",
5508+
"opaque-pointers",
5509+
CodeGenOpts<"OpaquePointers">,
5510+
DefaultFalse,
5511+
PosFlag<SetTrue, [], "Enable">,
5512+
NegFlag<SetFalse, [], "Disable">,
5513+
BothFlags<[], " opaque pointers">>;
55075514
def discard_value_names : Flag<["-"], "discard-value-names">,
55085515
HelpText<"Discard value names in LLVM IR">,
55095516
MarshallingInfoFlag<CodeGenOpts<"DiscardValueNames">>;

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,9 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
983983
if (BA != Backend_EmitNothing && !OS)
984984
return nullptr;
985985

986+
if (CI.getCodeGenOpts().OpaquePointers)
987+
VMContext->enableOpaquePointers();
988+
986989
// Load bitcode modules to link with, if we need to.
987990
if (LinkModules.empty())
988991
for (const CodeGenOptions::BitcodeFileToLink &F :
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2+
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=TYPED
3+
// RUN: %clang_cc1 -opaque-pointers -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=OPAQUE
4+
// The current default is typed pointers:
5+
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=TYPED
6+
7+
// TYPED-LABEL: @test(
8+
// TYPED-NEXT: entry:
9+
// TYPED-NEXT: [[P_ADDR:%.*]] = alloca i32*, align 8
10+
// TYPED-NEXT: store i32* [[P:%.*]], i32** [[P_ADDR]], align 8
11+
// TYPED-NEXT: [[TMP0:%.*]] = load i32*, i32** [[P_ADDR]], align 8
12+
// TYPED-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[TMP0]], i64 1
13+
// TYPED-NEXT: [[TMP1:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
14+
// TYPED-NEXT: ret i32 [[TMP1]]
15+
//
16+
// OPAQUE-LABEL: @test(
17+
// OPAQUE-NEXT: entry:
18+
// OPAQUE-NEXT: [[P_ADDR:%.*]] = alloca ptr, align 8
19+
// OPAQUE-NEXT: store ptr [[P:%.*]], ptr [[P_ADDR]], align 8
20+
// OPAQUE-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P_ADDR]], align 8
21+
// OPAQUE-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[TMP0]], i64 1
22+
// OPAQUE-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
23+
// OPAQUE-NEXT: ret i32 [[TMP1]]
24+
//
25+
int test(int *p) {
26+
return p[1];
27+
}

0 commit comments

Comments
 (0)