This is an archive of the discontinued LLVM Phabricator instance.

[clang][ExprConst] Handle 0 type size in builtin_memcpy etc.
ClosedPublic

Authored by tbaeder on Aug 7 2023, 12:08 AM.

Diff Detail

Event Timeline

tbaeder created this revision.Aug 7 2023, 12:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2023, 12:08 AM
tbaeder requested review of this revision.Aug 7 2023, 12:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2023, 12:08 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
shafik added a subscriber: shafik.Aug 22 2023, 1:52 PM
shafik added inline comments.
clang/lib/AST/ExprConstant.cpp
9512

I think we should issue a diagnostic, we don't have any indication that this is failing, let alone because the destination object size is zero.

tbaeder added inline comments.Aug 31 2023, 8:34 PM
clang/lib/AST/ExprConstant.cpp
9512

You mean in addition to the one we are emitting?

aaron.ballman added inline comments.
clang/test/Sema/builtin-memcpy.c
4–8

The only other test I'd like to see is one like:

constexpr int b() {
  struct {      } a[10];
  __builtin_memcpy(&a[2], a, 2); // UB here should be caught, right?
  return 0;
}

static_assert(b() == 0, "");

(if that's follow-up work, that's fine too, just leave a test with a FIXME comment.)

tbaeder added inline comments.Oct 21 2023, 9:53 AM
clang/test/Sema/builtin-memcpy.c
4–8

Nope, clang accepts that and GCC rejects the function when calling.

tbaeder updated this revision to Diff 557826.Oct 21 2023, 10:04 AM
aaron.ballman accepted this revision.Oct 23 2023, 6:38 AM

LGTM with a fixme comment added.

clang/test/Sema/builtin-memcpy.c
4–8

Amusingly, Clang and EDG (GNU mode) accept and GCC rejects. GCC is correct, so it's worth adding a FIXME to the case below so we know this isn't intentional behavior.

This revision is now accepted and ready to land.Oct 23 2023, 6:38 AM
This revision was landed with ongoing or failed builds.Oct 23 2023, 9:48 PM
This revision was automatically updated to reflect the committed changes.