This is an archive of the discontinued LLVM Phabricator instance.

[Bug 25404] Fix crash on typedef in OpenCL 2.0
ClosedPublic

Authored by Anastasia on Mar 27 2017, 6:56 AM.

Details

Summary

Fixing the assertion due to absence of source location for implicitly defined types (using addImplicitTypedef()). During Sema checks the source location is being expected and therefore an assertion is triggered.

The change is not specific to OpenCL. But it is particular common for OpenCL types to be declared implicitly in Clang to support the mode without standard header.

Link to the bug reported: https://bugs.llvm.org//show_bug.cgi?id=25404

Diff Detail

Repository
rL LLVM

Event Timeline

Anastasia created this revision.Mar 27 2017, 6:56 AM
Anastasia edited the summary of this revision. (Show Details)Mar 27 2017, 6:57 AM
ahatanak added inline comments.
lib/Sema/SemaDecl.cpp
2157 ↗(On Diff #93126)

Is it necessary to check whether New is implicit? I was just wondering when or how an implicit definition would redefine a typedef.

bader edited edge metadata.Mar 28 2017, 3:08 AM

Anastasia, could you generate patch with full context, please?

Anastasia updated this revision to Diff 93225.Mar 28 2017, 4:43 AM

Updated with the full diff.

Anastasia added inline comments.Mar 28 2017, 4:46 AM
lib/Sema/SemaDecl.cpp
2157 ↗(On Diff #93126)

I had a thought on it too, and I am not sure actually. This can happen if we implicitly define something from the standard headers. But I believe the Sema initialization should always happen before parsing the standard header or even loading them from the PCH. So I guess this shouldn't ever happen really? Perhaps, I should just remove this?

Anastasia added inline comments.Mar 28 2017, 5:06 AM
lib/Sema/SemaDecl.cpp
2157 ↗(On Diff #93126)

Actually in case of implicit typedefs we don't seem to follow this program path at all. So I am removing this.

Anastasia updated this revision to Diff 93226.Mar 28 2017, 5:07 AM

Removed check of implicit for new type.

bader added inline comments.Mar 28 2017, 5:20 AM
lib/Sema/SemaDecl.cpp
2157 ↗(On Diff #93126)

So something like this will also work?

typedef float float4 __attribute((ext_vector_type(4)));
typedef float4 atomic_int;
test/SemaOpenCL/types.cl
6 ↗(On Diff #93226)

Can we check that -Wtypedef-redefinition will emit a warning for this expression?
This typedef seems to be unnecessary since clang implicitly defines atomic_flag for OpenCL. User is not supposed to re-define it, so warning would be helpful here.

Anastasia added inline comments.Mar 28 2017, 7:56 AM
lib/Sema/SemaDecl.cpp
2157 ↗(On Diff #93126)

An error will be given for this because the definitions are conflicting (incompatible).

test/SemaOpenCL/types.cl
6 ↗(On Diff #93226)

A warning is given only with -Wsystem-headers in this case. I don't modify this change here. But I can add a test if necessary. Verify wouldn't work here though because a note about the old location of the typedef will be given without source information. But I can add a FileCheck test.

bader accepted this revision.Mar 28 2017, 8:35 AM

I think my topics are not related to the bug 25404 and can be handled separately.
Thanks!

This revision is now accepted and ready to land.Mar 28 2017, 8:35 AM
This revision was automatically updated to reflect the committed changes.