[PATCH] D35438: CodeGen: Ensure there is basic block when performing address space cast

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 17 07:56:44 PDT 2017


yaxunl added a comment.

In https://reviews.llvm.org/D35438#810385, @rjmccall wrote:

> Oh, of course.  Sadly, in C/C++ the declaration point of a variable does not necessarily dominate all uses of the variable, so you need to emit the cast immediately after the alloca.  Just temporarily move CGF.Builder to that point; hopefully we can assume that this function will never try to add control flow.
>
> Test case:
>
>   extern void use(int*);
>   void foo() {
>     goto later;
>     int x;
>     later:
>     use(&x);
>   }


Right. performAddressSpaceCast could be used in general cases. We only need to change insert position when emitting automatic or temporary variables. I will move this logic to CodeGenFunction::CreateTempAlloca.


https://reviews.llvm.org/D35438





More information about the cfe-commits mailing list