This is an archive of the discontinued LLVM Phabricator instance.

No memcpy for copy ctor with -fsanitize-address-field-padding=1
ClosedPublic

Authored by kcc on Dec 3 2014, 4:12 PM.

Details

Diff Detail

Event Timeline

kcc updated this revision to Diff 16898.Dec 3 2014, 4:12 PM
kcc retitled this revision from to No memcpy for copy ctor with -fsanitize-address-field-padding=1.
kcc updated this object.
kcc edited the test plan for this revision. (Show Details)
kcc added a reviewer: thakis.
kcc added a subscriber: Unknown Object (MLST).
kcc added a subscriber: rsmith.Dec 5 2014, 4:56 PM

+rsmith

rsmith accepted this revision.Dec 5 2014, 5:16 PM
rsmith added a reviewer: rsmith.

LGTM

This revision is now accepted and ready to land.Dec 5 2014, 5:16 PM
kcc closed this revision.Dec 5 2014, 5:23 PM
thakis edited edge metadata.EditedDec 10 2014, 4:44 PM

Sorry about the slow review.

Rather than adding all these checks before calling EmitAggregateCopy(), is it maybe possible to do this check in EmitAggregateCopy() itself? Else there will always be cases that you miss. For example:

$ cat foo.cc
struct ClassWithTrivialCopy {
  ClassWithTrivialCopy();
  ~ClassWithTrivialCopy();
  void *a;
 private:
  void *c;
};

struct NontrivialCopy { 
  NontrivialCopy(const NontrivialCopy&); 
};

struct pair {
  NontrivialCopy nc;
  ClassWithTrivialCopy second[4];
  pair(const pair&) = default;
};

void MakeTrivialCopy( const pair &p) {
  pair p2(p);
}
$ bin/clang -c foo.cc -std=c++11 -fsanitize=address -fsanitize-address-field-padding=1  -emit-llvm -S -o - | grep memcpy
  %68 = call i8* @__asan_memcpy(i8* %66, i8* %67, i64 128)
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1) #4
declare i8* @__asan_memcpy(i8*, i8*, i64)