Hi Tobias,

On Wed, Sep 17, 2025 at 3:33 AM Tobias Burnus <tbur...@baylibre.com> wrote:
>
> Hi Yuao,
>
> Yuao Ma wrote:
>
> On Tue, Sep 16, 2025 at 5:11 PM Tobias Burnus <tbur...@baylibre.com> wrote:
>
> PS: Already with the current code, we may run into the issue of passing
> an actual argument like '(cond ? "abc" : "cdfg")' to 'class(*)' – and I
> am not sure whether we handle this correctly or not.
>
> That is a great test case, and I apologize for not testing against the
> cond-arg part. The current patch doesn't work well with cond-arg,
> whether or not class(*) is involved. To avoid introducing new ICE,
> I'll hold off on this patch until we can properly use character types
> in both cond-expr and cond-arg. Part of the root of the problem seems
> to be here: 
> https://github.com/gcc-mirror/gcc/blob/857c742e7bb8b24a05180e1cfee62efa417a48fe/gcc/fortran/trans-expr.cc#L10652.
> When the expression's type is found to be a character, it uses
> gfc_conv_string_parameter and returns immediately. Handling
> EXPR_CONDITIONAL first would solve part of the issue, allowing two
> character variables to be passed without a problem. However, passing
> two STRING_CST still causes an ICE, failing in fold_convert_loc within
> GIMPLE. I'm currently investigating why this is happening.
>
> If you want me to have a look as well, it helps if you sent a minimal patch 
> plus example. Otherwise, I quickly acknowledge that there is an issue – 
> without knowing much more nor digging into it.
>
> Regarding the const, I wonder whether something gets wrong with the type 
> declaration?
>

My apologies for not providing the full context earlier! The good news
is, I've managed to figure it out : )

I've made two key updates in this version:
1. In gfc_conv_expr_reference, the previous logic handled BT_CHARACTER
first. This caused a failure when we had a cond-arg with a character
type, as the cond-expr logic wasn't being handled correctly. I've
simply reordered the check case to handle the cond-expr first.
2. The previous gfc_conv_constant function didn't handle want_pointer,
whereas gfc_conv_variable did. This explains why two string variables
worked correctly, but two string constants resulted in an ICE.

Both of these issues are now fixed, and I've added test cases to
confirm the fixes.

Thanks,
Yuao

Attachment: 0001-fortran-allow-character-in-conditional-expression.patch
Description: Binary data

Reply via email to