]> granicus.if.org Git - clang/commit
[CodeGen][ObjC] Fix assert on calling `__builtin_constant_p` with ObjC objects.
authorVolodymyr Sapsai <vsapsai@apple.com>
Fri, 8 Feb 2019 23:02:13 +0000 (23:02 +0000)
committerVolodymyr Sapsai <vsapsai@apple.com>
Fri, 8 Feb 2019 23:02:13 +0000 (23:02 +0000)
commitaf0dd52c675f0b743a1567a9a4ebcd6c03185eb8
tree03dfe6be7156a0090973d4d57ffea38d2e054784
parentc15c1c3a2e19df41895228622417a3ac43ae0176
[CodeGen][ObjC] Fix assert on calling `__builtin_constant_p` with ObjC objects.

When we are calling `__builtin_constant_p` with ObjC objects of
different classes, we hit the assertion

> Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file include/llvm/Support/Casting.h, line 254.

It happens because LLVM types for `ObjCInterfaceType` are opaque and
have no name (see `CodeGenTypes::ConvertType`). As the result, for
different ObjC classes we have different `is_constant` intrinsics with
the same name `llvm.is.constant.p0s_s`. When we try to reuse an
intrinsic with the same name, we fail because of type mismatch.

Fix by bitcasting `ObjCObjectPointerType` to `id` prior to passing as an
argument to `__builtin_constant_p`. This results in using intrinsic
`llvm.is.constant.p0i8` and correct types.

rdar://problem/47499250

Reviewers: rjmccall, ahatanak, void

Reviewed By: void, ahatanak

Subscribers: ddunbar, jkorous, hans, dexonsmith, cfe-commits

Differential Revision: https://reviews.llvm.org/D57427

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@353577 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGBuiltin.cpp
test/CodeGenObjC/builtin-constant-p.m [new file with mode: 0644]