This is an archive of the discontinued LLVM Phabricator instance.

ADT: Remove misaligned pointeres from DenseMapInfo
Needs ReviewPublic

Authored by majnemer on Sep 21 2014, 5:25 AM.

Details

Summary

C++ requires that pointers point to sufficiently well aligned addresses.
getEmptyKey() and getTombstoneKey() would cast -1 and -2 to arbitrary
pointer types which would violate this requirement.

In an ideal world, we would query the alignment of the pointee type;
however, the pointee type might be incomplete (this is often the case in
LLVM/Clang). Instead, assume that no type is more aligned than 16383
bytes.

Diff Detail

Event Timeline

majnemer updated this revision to Diff 13909.Sep 21 2014, 5:25 AM
majnemer retitled this revision from to ADT: Remove misaligned pointeres from DenseMapInfo.
majnemer updated this object.
majnemer added a subscriber: Unknown Object (MLST).
samsonov edited edge metadata.Dec 23 2014, 3:45 PM

FTR, this is the last remaining major problem which keeps "check-llvm" command broken under UBSan bootstrap. This patch looks good to me, but I'm not sure if I can sign this off.

hfinkel edited edge metadata.Dec 24 2014, 5:59 AM

FTR, this is the last remaining major problem which keeps "check-llvm" command broken under UBSan bootstrap. This patch looks good to me, but I'm not sure if I can sign this off.

IIRC, the problem was that this is not actually undefined behavior. The resulting pointer value might be a "trap representation", but that's implementation-defined behavior, not undefined behavior. UBSan might need to be fixed here.

FTR, this is the last remaining major problem which keeps "check-llvm" command broken under UBSan bootstrap. This patch looks good to me, but I'm not sure if I can sign this off.

IIRC, the problem was that this is not actually undefined behavior. The resulting pointer value might be a "trap representation", but that's implementation-defined behavior, not undefined behavior. UBSan might need to be fixed here.

What fix do you suggest? UBSan prints an error report when the unaligned pointer T* is actually used, not when it's created. In LLVM, this "use" is usually an upcast to Value *. So, you may treat UBSan as the tool implementing this trapping behavior.

chandlerc resigned from this revision.Mar 29 2015, 1:38 PM
chandlerc removed a reviewer: chandlerc.

My memory is that this got fixed differently, but re-ping if needed.