Skip to content

Determine type of _For_any polymorphic function from the callee #991

Open
@secure-sw-dev-bot

Description

@secure-sw-dev-bot

This issue was copied from checkedc/checkedc-clang#991


In Checked C, we can have functions with _For_any specified. For such functions, the function type should be taken from the callee (not the caller). For example:

For_any(T) void f(_Ptr<T> x); // type of callee: void(i8*).
int n;
f<int>(&n); // type of caller: void(i32*).

As we can see there is a mismatch in the types of the caller and the callee. So in clang/lib/CodeGen/CGCall.cpp we would hit the assert: assert(IRFuncTy == TypeFromVal);

In clang/lib/CodeGen/CGCall.cpp, we used to take the type from the callee prior to upgrade to release_90:
llvm::FunctionType *IRFuncTy = Callee.getFunctionType();

But upstream has changed to this:
llvm::FunctionType *IRFuncTy = getTypes().GetFunctionType(CallInfo);

Now, CallInfo will get us the caller's type and we would hit the above assert.

The correct fix here is to detect _For_any on the function and then use the callee type. But we do not currently seem to propagate the info about _For_any in clang/lib/CodeGen.

NOTE: We may also need to handle _Itype_for_any.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions