This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix Complex x Float x Int conversions so it handles type sugar
AbandonedPublic

Authored by mizvekov on Sep 8 2022, 1:51 PM.

Details

Reviewers
rsmith
Group Reviewers
Restricted Project
Summary

The included test case was broken by D111509 since now
those types can have sugar.

Replace dyn_casts / cast and small refactor to preserve sugar by
not stripping it down when type is already Complex.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Diff Detail

Event Timeline

mizvekov created this revision.Sep 8 2022, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 8 2022, 1:51 PM
mizvekov requested review of this revision.Sep 8 2022, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 8 2022, 1:51 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
MaskRay added a reviewer: tra.Sep 8 2022, 1:57 PM
mizvekov updated this revision to Diff 458877.Sep 8 2022, 2:36 PM
mizvekov retitled this revision from [clang] Fix Complex x Float conversions so it handles type sugar to [clang] Fix Complex x Float x Int conversions so it handles type sugar.
mizvekov edited the summary of this revision. (Show Details)
mizvekov updated this revision to Diff 458881.Sep 8 2022, 2:40 PM

I just included a similar fix for another problem I found inspecting nearby code for the same kind of bug:

typedef __complex__ float ComplexFloat;
int cc = 1 + (ComplexFloat)(1.0iF);

hopefully will fix this ?
invalid cast kind for complex value
UNREACHABLE executed at /clang/lib/AST/ExprConstant.cpp:14263!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and as
sociated run script.

hopefully will fix this ?
invalid cast kind for complex value
UNREACHABLE executed at /clang/lib/AST/ExprConstant.cpp:14263!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and as
sociated run script.

That looks like a different problem, haven't seen a reproducer yet. Are you able to share it?

emailed a hopeful reproducer to you

emailed a hopeful reproducer to you

Thanks, seen!

Going to start running creduce on it.

tra resigned from this revision.Sep 8 2022, 3:52 PM

I can confirm that this patch does address the compiler crash seen on CUDA build bots. I'm not familiar enough with the code to review it otherwise.

mizvekov edited reviewers, added: Restricted Project; removed: tra.Sep 8 2022, 4:07 PM

Since the affected patch just got reverted, I will squash these fixes in the original MR instead.

emailed a hopeful reproducer to you

I reduced it and confirm it was also fixed by this patch.

shafik added a subscriber: shafik.Sep 8 2022, 7:09 PM
shafik added inline comments.
clang/lib/Sema/SemaExpr.cpp
1135

Can you collapse this check with the next line? It just looks weird checking RHSComplexType twice and having RHSType on the opposite side of each one. It took me a while to understand what was going on.

This comment also applies a few lines down.

mizvekov abandoned this revision.Sep 9 2022, 8:23 AM
mizvekov added inline comments.
clang/lib/Sema/SemaExpr.cpp
1135

I have refactored the whole thing, but at D111509

The present patch was intended to be a quick fix to that one, to avoid reverting it, but that is moot now since it ended up reverted and we can't test what is in here without the other one.