llvm.org GIT mirror llvm / f196208
DWARF type hashing: pointers to members Includes a test case/FIXME demonstrating a bug/limitation in pointer to member hashing. To be honest I'm not sure why we don't just always use summary hashing for referenced types... but perhaps I'm missing something. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193175 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 7 years ago
2 changed file(s) with 193 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
191191 void DIEHash::hashAttribute(AttrEntry Attr, dwarf::Tag Tag) {
192192 const DIEValue *Value = Attr.Val;
193193 const DIEAbbrevData *Desc = Attr.Desc;
194 dwarf::Attribute Attribute = Desc->getAttribute();
194195
195196 // 7.27 Step 3
196197 // ... An attribute that refers to another type entry T is processed as
199200 DIE *Entry = EntryAttr->getEntry();
200201
201202 // Step 5
202 // If the tag in Step 3 is one of ...
203 if (Tag == dwarf::DW_TAG_pointer_type ||
204 Tag == dwarf::DW_TAG_reference_type ||
205 Tag == dwarf::DW_TAG_rvalue_reference_type) {
206 // ... and the referenced type (via the DW_AT_type or DW_AT_friend
207 // attribute) ...
208 assert(Desc->getAttribute() == dwarf::DW_AT_type ||
209 Desc->getAttribute() == dwarf::DW_AT_friend);
203 // If the tag in Step 3 is one of [the below tags]
204 if ((Tag == dwarf::DW_TAG_pointer_type ||
205 Tag == dwarf::DW_TAG_reference_type ||
206 Tag == dwarf::DW_TAG_rvalue_reference_type ||
207 Tag == dwarf::DW_TAG_ptr_to_member_type) &&
208 // and the referenced type (via the [below attributes])
209 // FIXME: This seems overly restrictive, and causes hash mismatches
210 // there's a decl/def difference in the containing type of a
211 // ptr_to_member_type.
212 Attribute == dwarf::DW_AT_type) {
210213 // [FIXME] ... has a DW_AT_name attribute,
211214 // append the letter 'N'
212215 addULEB128('N');
237240 // 'R' as the marker
238241 addULEB128('R');
239242
240 addULEB128(Desc->getAttribute());
243 addULEB128(Attribute);
241244
242245 // and use the unsigned LEB128 encoding of [the index of T in the
243246 // list] as the attribute value;
248251 // otherwise, b) use the letter 'T' as a the marker, ...
249252 addULEB128('T');
250253
251 addULEB128(Desc->getAttribute());
254 addULEB128(Attribute);
252255
253256 // ... process the type T recursively by performing Steps 2 through 7, and
254257 // use the result as the attribute value.
260263 // Other attribute values use the letter 'A' as the marker, ...
261264 addULEB128('A');
262265
263 addULEB128(Desc->getAttribute());
266 addULEB128(Attribute);
264267
265268 // ... and the value consists of the form code (encoded as an unsigned LEB128
266269 // value) followed by the encoding of the value according to the form code. To
263263
264264 ASSERT_EQ(0xad211c8c3b31e57ULL, MD5Res);
265265 }
266 }
266
267 // struct foo { foo foo::*mem; };
268 TEST(DIEHashTest, PtrToMember) {
269 DIE Foo(dwarf::DW_TAG_structure_type);
270 DIEInteger Eight(8);
271 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
272 DIEString FooStr(&Eight, "foo");
273 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
274
275 DIE *Mem = new DIE(dwarf::DW_TAG_member);
276 DIEString MemStr(&Eight, "mem");
277 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
278 DIEInteger Zero(0);
279 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero);
280
281 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
282 DIEEntry FooEntry(&Foo);
283 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooEntry);
284 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4, &FooEntry);
285
286 DIEEntry PtrToFooMemRef(&PtrToFooMem);
287 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
288
289 Foo.addChild(Mem);
290
291 uint64_t MD5Res = DIEHash().computeTypeSignature(&Foo);
292
293 ASSERT_EQ(0x852e0c9ff7c04ebULL, MD5Res);
294 }
295
296 // Check that the hash for a pointer-to-member matches regardless of whether the
297 // pointed-to type is a declaration or a definition.
298 //
299 // struct bar; // { };
300 // struct foo { bar foo::*mem; };
301 TEST(DIEHashTest, PtrToMemberDeclDefMatch) {
302 DIEInteger Zero(0);
303 DIEInteger One(1);
304 DIEInteger Eight(8);
305 DIEString FooStr(&Eight, "foo");
306 DIEString BarStr(&Eight, "bar");
307 DIEString MemStr(&Eight, "mem");
308 uint64_t MD5ResDecl;
309 {
310 DIE Bar(dwarf::DW_TAG_structure_type);
311 Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &BarStr);
312 Bar.addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
313
314 DIE Foo(dwarf::DW_TAG_structure_type);
315 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
316 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
317
318 DIE *Mem = new DIE(dwarf::DW_TAG_member);
319 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
320 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
321 &Zero);
322
323 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
324 DIEEntry BarEntry(&Bar);
325 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &BarEntry);
326 DIEEntry FooEntry(&Foo);
327 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
328 &FooEntry);
329
330 DIEEntry PtrToFooMemRef(&PtrToFooMem);
331 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
332
333 Foo.addChild(Mem);
334
335 MD5ResDecl = DIEHash().computeTypeSignature(&Foo);
336 }
337 uint64_t MD5ResDef;
338 {
339 DIE Bar(dwarf::DW_TAG_structure_type);
340 Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &BarStr);
341 Bar.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
342
343 DIE Foo(dwarf::DW_TAG_structure_type);
344 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
345 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
346
347 DIE *Mem = new DIE(dwarf::DW_TAG_member);
348 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
349 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
350 &Zero);
351
352 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
353 DIEEntry BarEntry(&Bar);
354 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &BarEntry);
355 DIEEntry FooEntry(&Foo);
356 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
357 &FooEntry);
358
359 DIEEntry PtrToFooMemRef(&PtrToFooMem);
360 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
361
362 Foo.addChild(Mem);
363
364 MD5ResDef = DIEHash().computeTypeSignature(&Foo);
365 }
366 ASSERT_EQ(MD5ResDef, MD5ResDecl);
367 }
368
369 // Check that the hash for a pointer-to-member matches regardless of whether the
370 // pointed-to type is a declaration or a definition.
371 //
372 // struct bar; // { };
373 // struct foo { bar bar::*mem; };
374 TEST(DIEHashTest, PtrToMemberDeclDefMisMatch) {
375 DIEInteger Zero(0);
376 DIEInteger One(1);
377 DIEInteger Eight(8);
378 DIEString FooStr(&Eight, "foo");
379 DIEString BarStr(&Eight, "bar");
380 DIEString MemStr(&Eight, "mem");
381 uint64_t MD5ResDecl;
382 {
383 DIE Bar(dwarf::DW_TAG_structure_type);
384 Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &BarStr);
385 Bar.addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
386
387 DIE Foo(dwarf::DW_TAG_structure_type);
388 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
389 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
390
391 DIE *Mem = new DIE(dwarf::DW_TAG_member);
392 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
393 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
394 &Zero);
395
396 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
397 DIEEntry BarEntry(&Bar);
398 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &BarEntry);
399 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
400 &BarEntry);
401
402 DIEEntry PtrToFooMemRef(&PtrToFooMem);
403 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
404
405 Foo.addChild(Mem);
406
407 MD5ResDecl = DIEHash().computeTypeSignature(&Foo);
408 }
409 uint64_t MD5ResDef;
410 {
411 DIE Bar(dwarf::DW_TAG_structure_type);
412 Bar.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &BarStr);
413 Bar.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
414
415 DIE Foo(dwarf::DW_TAG_structure_type);
416 Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
417 Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr);
418
419 DIE *Mem = new DIE(dwarf::DW_TAG_member);
420 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
421 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1,
422 &Zero);
423
424 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
425 DIEEntry BarEntry(&Bar);
426 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &BarEntry);
427 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
428 &BarEntry);
429
430 DIEEntry PtrToFooMemRef(&PtrToFooMem);
431 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
432
433 Foo.addChild(Mem);
434
435 MD5ResDef = DIEHash().computeTypeSignature(&Foo);
436 }
437 // FIXME: This seems to be a bug in the DWARF type hashing specification that
438 // only uses the brief name hashing for types referenced via DW_AT_type. In
439 // this case the type is referenced via DW_AT_containing_type and full hashing
440 // causes a hash to differ when the containing type is a declaration in one TU
441 // and a definition in another.
442 ASSERT_NE(MD5ResDef, MD5ResDecl);
443 }
444 }