llvm.org GIT mirror llvm / 5ff4b20
Add support for DW_FORM_flag and DW_FORM_flag_present to the DIE hashing algorithm. Sink the 'A' + Attribute hash into each form so we don't have to check valid forms before deciding whether or not we're going to hash which will let the default be to return without doing anything. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200571 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 6 years ago
2 changed file(s) with 51 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
283283 return;
284284 }
285285
286 // Other attribute values use the letter 'A' as the marker, ...
287 addULEB128('A');
288
289 addULEB128(Attribute);
290
291 // ... and the value consists of the form code (encoded as an unsigned LEB128
292 // value) followed by the encoding of the value according to the form code. To
293 // ensure reproducibility of the signature, the set of forms used in the
294 // signature computation is limited to the following: DW_FORM_sdata,
295 // DW_FORM_flag, DW_FORM_string, and DW_FORM_block.
286 // Other attribute values use the letter 'A' as the marker, and the value
287 // consists of the form code (encoded as an unsigned LEB128 value) followed by
288 // the encoding of the value according to the form code. To ensure
289 // reproducibility of the signature, the set of forms used in the signature
290 // computation is limited to the following: DW_FORM_sdata, DW_FORM_flag,
291 // DW_FORM_string, and DW_FORM_block.
296292 switch (Desc->getForm()) {
297293 case dwarf::DW_FORM_string:
298294 llvm_unreachable(
299295 "Add support for DW_FORM_string if we ever start emitting them again");
300296 case dwarf::DW_FORM_GNU_str_index:
301297 case dwarf::DW_FORM_strp:
298 addULEB128('A');
299 addULEB128(Attribute);
302300 addULEB128(dwarf::DW_FORM_string);
303301 addString(cast(Value)->getString());
304302 break;
307305 case dwarf::DW_FORM_data4:
308306 case dwarf::DW_FORM_data8:
309307 case dwarf::DW_FORM_udata:
308 addULEB128('A');
309 addULEB128(Attribute);
310310 addULEB128(dwarf::DW_FORM_sdata);
311311 addSLEB128((int64_t)cast(Value)->getValue());
312 break;
313 // DW_FORM_flag_present is just flag with a value of one. We still give it a
314 // value so just use the value.
315 case dwarf::DW_FORM_flag_present:
316 case dwarf::DW_FORM_flag:
317 addULEB128('A');
318 addULEB128(Attribute);
319 addULEB128(dwarf::DW_FORM_flag);
320 addULEB128((int64_t)cast(Value)->getValue());
312321 break;
313322 default:
314323 llvm_unreachable("Add support for additional forms");
513513 // The exact same hash GCC produces for this DIE.
514514 ASSERT_EQ(0xd36a1b6dfb604ba0ULL, MD5Res);
515515 }
516 }
516
517 // struct A {
518 // static void func();
519 // };
520 TEST(DIEHashTest, MemberFuncFlag) {
521 DIE A(dwarf::DW_TAG_structure_type);
522 DIEInteger One(1);
523 DIEString AStr(&One, "A");
524 A.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &AStr);
525 A.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
526 A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
527 A.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
528
529 DIE *Func = new DIE(dwarf::DW_TAG_subprogram);
530 DIEString FuncStr(&One, "func");
531 DIEString FuncLinkage(&One, "_ZN1A4funcEv");
532 DIEInteger Two(2);
533 Func->addValue(dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, &One);
534 Func->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FuncStr);
535 Func->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
536 Func->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &Two);
537 Func->addValue(dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp, &FuncLinkage);
538 Func->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
539
540 A.addChild(Func);
541
542 uint64_t MD5Res = DIEHash().computeTypeSignature(A);
543
544 // The exact same hash GCC produces for this DIE.
545 ASSERT_EQ(0x8f78211ddce3df10ULL, MD5Res);
546 }
547 }