This is an archive of the discontinued LLVM Phabricator instance.

[Clang][Sema] Avoid crashing for `__builtin_memcpy_inline` with an array argument
ClosedPublic

Authored by egorzhdan on Mar 11 2022, 10:01 AM.

Details

Summary

This change teaches the Sema logic for __builtin_memcpy_inline to implicitly convert arrays passed as arguments to pointers, similarly to regular memcpy.

This code will no longer cause a compiler crash:

void f(char *p) {
    char s[1] = {0};
    __builtin_memcpy_inline(p, s, 1);
}

rdar://88147527

Diff Detail

Event Timeline

egorzhdan created this revision.Mar 11 2022, 10:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2022, 10:02 AM
egorzhdan requested review of this revision.Mar 11 2022, 10:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2022, 10:02 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
gchatelet accepted this revision.Mar 14 2022, 2:19 AM

Thx for the patch, please address the comment before submitting.

clang/lib/Sema/SemaChecking.cpp
1946–1953

[nit] It's unclear looking at the function name that it's failing when returning true - one has to read the code to understand. It may be fine now but could become messy with time and refactoring.
Either change the lambda's name FailArgArrayConversion or negate everything.

This revision is now accepted and ready to land.Mar 14 2022, 2:19 AM
egorzhdan updated this revision to Diff 415069.Mar 14 2022, 5:11 AM

Rename a lambda to improve readability

egorzhdan marked an inline comment as done.Mar 14 2022, 5:12 AM
gchatelet accepted this revision.Mar 14 2022, 5:34 AM

Much better, thank you.