This is an archive of the discontinued LLVM Phabricator instance.

[ubsan] Fix crash on __builtin_assume_aligned
AbandonedPublic

Authored by MaskRay on Nov 23 2020, 9:27 PM.

Details

Summary

Fixes PR45813

Diff Detail

Event Timeline

orivej created this revision.Nov 23 2020, 9:27 PM
orivej requested review of this revision.Nov 23 2020, 9:27 PM
orivej updated this revision to Diff 307239.

Sorry, I don't understand the issue and can't write a better description.
Since this test triggers an assert in getCommonPtr that it "Cannot retrieve a NULL type pointer" of Ty->getPointeeType(), the fix just checks that the pointee is not null before using isVolatileQualified.

orivej added a comment.Dec 2 2020, 9:02 AM

Could somebody review this?

vsk added a subscriber: vsk.Dec 2 2020, 9:49 AM
vsk added inline comments.
clang/lib/CodeGen/CodeGenFunction.cpp
2524

Is the pointee type associated with a PointerType QualType ever supposed to be null? I wonder why this happens, and whether it can cause problems in other places.

lebedev.ri added inline comments.Dec 2 2020, 9:51 AM
clang/lib/CodeGen/CodeGenFunction.cpp
2524

Basically, we can't just use getPointeeType() here, but i'm not sure what should be used instead.

aaron.ballman added inline comments.Dec 2 2020, 1:13 PM
clang/lib/CodeGen/CodeGenFunction.cpp
2524

I'm not super familiar with __builtin_assume_aligned but from the GCC docs, it looks like the code from the test case is valid code (so we don't need to add semantic checking that would ensure we don't reach this code path). However, it seems a bit odd to me that we'd get an array type here as opposed to a decayed type which would actually be a pointer.

I think the issue is further up the call chain, perhaps. EmitBuiltinExpr() gets the argument expression and passes it to emitAlignmentAssumption() which pulls the type directly out of the expression. It seems like there's an lvalue to rvalue conversion step missing to adjust the type.

lebedev.ri requested changes to this revision.Dec 3 2020, 1:56 PM

@orivej please can you look where we create AST nodes for these builtins and ensure that the "pointer" argument is actually converted into a pointer beforehand?
I'm afraid i can't readily point at the examples, but it should be easy-ish..

clang/lib/CodeGen/CodeGenFunction.cpp
2524

Aha, yes, that does sound like the underying problem.
I was thinking about that beforehand, but wasn't sure.

This revision now requires changes to proceed.Dec 3 2020, 1:56 PM
lebedev.ri resigned from this revision.Jan 12 2023, 4:46 PM

This review seems to be stuck/dead, consider abandoning if no longer relevant.

This revision now requires review to proceed.Jan 12 2023, 4:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 4:46 PM
Herald added a subscriber: StephenFan. · View Herald Transcript

-fsanitize=alignment -c a.c -O[012] no longer crashes for the test. From the comment that the problem was up the call chain, I think we can close this revision now.

MaskRay commandeered this revision.Jan 12 2023, 6:01 PM
MaskRay abandoned this revision.
MaskRay added a reviewer: orivej.