[PATCH] D105155: [OpaquePtr] Support opaque pointers in intrinsic type check
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 30 08:56:58 PDT 2021
nikic updated this revision to Diff 355574.
nikic added a comment.
Add LLVMContext method.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105155/new/
https://reviews.llvm.org/D105155
Files:
llvm/include/llvm/IR/LLVMContext.h
llvm/lib/IR/Function.cpp
llvm/lib/IR/LLVMContext.cpp
llvm/test/Assembler/remangle-intrinsic-opaque-ptr.ll
llvm/test/Other/force-opaque-ptrs.ll
Index: llvm/test/Other/force-opaque-ptrs.ll
===================================================================
--- llvm/test/Other/force-opaque-ptrs.ll
+++ llvm/test/Other/force-opaque-ptrs.ll
@@ -48,3 +48,19 @@
;
unreachable
}
+
+define void @remangle_intrinsic() {
+; CHECK-LABEL: define {{[^@]+}}@remangle_intrinsic() {
+; CHECK-NEXT: [[A:%.*]] = alloca ptr, align 8
+; CHECK-NEXT: [[TMP1:%.*]] = call ptr @llvm.stacksave()
+; CHECK-NEXT: call void @llvm.stackprotector(ptr null, ptr [[A]])
+; CHECK-NEXT: ret void
+;
+ %a = alloca i8*
+ call i8* @llvm.stacksave()
+ call void @llvm.stackprotector(i8* null, i8** %a)
+ ret void
+}
+
+declare i8* @llvm.stacksave()
+declare void @llvm.stackprotector(i8*, i8**)
Index: llvm/test/Assembler/remangle-intrinsic-opaque-ptr.ll
===================================================================
--- /dev/null
+++ llvm/test/Assembler/remangle-intrinsic-opaque-ptr.ll
@@ -0,0 +1,15 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s --check-prefix=TYPED
+; RUN: llvm-as --force-opaque-pointers < %s | llvm-dis --force-opaque-pointers | FileCheck %s --check-prefix=OPAQUE
+
+; An opaque pointer type should not be accepted for an intrinsic that
+; specifies a fixed pointer type, outside of --force-opaque-pointers mode.
+
+; TYPED: Intrinsic has incorrect return type!
+; OPAQUE: call ptr @llvm.stacksave()
+
+define void @test() {
+ call ptr @llvm.stacksave()
+ ret void
+}
+
+declare ptr @llvm.stacksave()
Index: llvm/lib/IR/LLVMContext.cpp
===================================================================
--- llvm/lib/IR/LLVMContext.cpp
+++ llvm/lib/IR/LLVMContext.cpp
@@ -347,3 +347,7 @@
std::unique_ptr<DiagnosticHandler> LLVMContext::getDiagnosticHandler() {
return std::move(pImpl->DiagHandler);
}
+
+const LLVMContext::supportsTypedPointers() const {
+ return !pImpl->ForceOpaquePointers;
+}
Index: llvm/lib/IR/Function.cpp
===================================================================
--- llvm/lib/IR/Function.cpp
+++ llvm/lib/IR/Function.cpp
@@ -1404,9 +1404,21 @@
}
case IITDescriptor::Pointer: {
PointerType *PT = dyn_cast<PointerType>(Ty);
- return !PT || PT->getAddressSpace() != D.Pointer_AddressSpace ||
- matchIntrinsicType(PT->getElementType(), Infos, ArgTys,
- DeferredChecks, IsDeferredCheck);
+ if (!PT || PT->getAddressSpace() != D.Pointer_AddressSpace)
+ return true;
+ if (!PT->isOpaque())
+ return matchIntrinsicType(PT->getElementType(), Infos, ArgTys,
+ DeferredChecks, IsDeferredCheck);
+ // If typed pointers are supported, do not allow using opaque pointer in
+ // place of fixed pointer type. This would make the intrinsic signature
+ // non-unique.
+ if (Ty->getContext()->supportsTypedPointers())
+ return true;
+ // Consume IIT descriptors relating to the pointer element type.
+ while (Infos.front().Kind == IITDescriptor::Pointer)
+ Infos = Infos.slice(1);
+ Infos = Infos.slice(1);
+ return false;
}
case IITDescriptor::Struct: {
Index: llvm/include/llvm/IR/LLVMContext.h
===================================================================
--- llvm/include/llvm/IR/LLVMContext.h
+++ llvm/include/llvm/IR/LLVMContext.h
@@ -305,6 +305,9 @@
/// LLVMContext is used by compilation.
void setOptPassGate(OptPassGate&);
+ /// Whether typed pointers are supported. If false, all pointers are opaque.
+ bool supportsTypedPointers() const;
+
private:
// Module needs access to the add/removeModule methods.
friend class Module;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105155.355574.patch
Type: text/x-patch
Size: 3656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210630/e29a68a5/attachment.bin>
More information about the llvm-commits
mailing list