This revision was automatically updated to reflect the committed changes. Closed by commit rGd69e9f9d8978: [OpaquePtrs][Clang] Add -opaque-pointers/-no-opaque-pointers cc1 options (authored by nikic). Herald added a project: clang. Herald added a subscriber: cfe-commits.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123034/new/ https://reviews.llvm.org/D123034 Files: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/lib/CodeGen/CodeGenAction.cpp clang/test/CodeGen/opaque-pointers-flag.c Index: clang/test/CodeGen/opaque-pointers-flag.c =================================================================== --- /dev/null +++ clang/test/CodeGen/opaque-pointers-flag.c @@ -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]; +} Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -983,6 +983,9 @@ 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 : Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -5504,6 +5504,13 @@ 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">>; Index: clang/include/clang/Basic/CodeGenOptions.def =================================================================== --- clang/include/clang/Basic/CodeGenOptions.def +++ clang/include/clang/Basic/CodeGenOptions.def @@ -469,6 +469,9 @@ 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
Index: clang/test/CodeGen/opaque-pointers-flag.c =================================================================== --- /dev/null +++ clang/test/CodeGen/opaque-pointers-flag.c @@ -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]; +} Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -983,6 +983,9 @@ 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 : Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -5504,6 +5504,13 @@ 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">>; Index: clang/include/clang/Basic/CodeGenOptions.def =================================================================== --- clang/include/clang/Basic/CodeGenOptions.def +++ clang/include/clang/Basic/CodeGenOptions.def @@ -469,6 +469,9 @@ 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits