Skip to content

Commit c0a6f7a

Browse files
authored
Use precise types in DWARF BestForm methods (#126309)
I noticed that DIEInteger::BestForm used a cast to char: if ((char)Int == SignedInt) If 'char' happens to be unsigned, this will not behave correctly. Then I also noticed that this code assumes the size of 'short' and 'int'. This patch changes this code to use more precise types. No functional change should be visible on ordinary hosts.
1 parent 123dca9 commit c0a6f7a

File tree

1 file changed

+12
-12
lines changed
  • llvm/include/llvm/CodeGen

1 file changed

+12
-12
lines changed

llvm/include/llvm/CodeGen/DIE.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,18 @@ class DIEInteger {
175175
static dwarf::Form BestForm(bool IsSigned, uint64_t Int) {
176176
if (IsSigned) {
177177
const int64_t SignedInt = Int;
178-
if ((char)Int == SignedInt)
178+
if ((int8_t)Int == SignedInt)
179179
return dwarf::DW_FORM_data1;
180-
if ((short)Int == SignedInt)
180+
if ((int16_t)Int == SignedInt)
181181
return dwarf::DW_FORM_data2;
182-
if ((int)Int == SignedInt)
182+
if ((int32_t)Int == SignedInt)
183183
return dwarf::DW_FORM_data4;
184184
} else {
185-
if ((unsigned char)Int == Int)
185+
if ((uint8_t)Int == Int)
186186
return dwarf::DW_FORM_data1;
187-
if ((unsigned short)Int == Int)
187+
if ((uint16_t)Int == Int)
188188
return dwarf::DW_FORM_data2;
189-
if ((unsigned int)Int == Int)
189+
if ((uint32_t)Int == Int)
190190
return dwarf::DW_FORM_data4;
191191
}
192192
return dwarf::DW_FORM_data8;
@@ -1025,11 +1025,11 @@ class DIELoc : public DIEValueList {
10251025
if (DwarfVersion > 3)
10261026
return dwarf::DW_FORM_exprloc;
10271027
// Pre-DWARF4 location expressions were blocks and not exprloc.
1028-
if ((unsigned char)Size == Size)
1028+
if ((uint8_t)Size == Size)
10291029
return dwarf::DW_FORM_block1;
1030-
if ((unsigned short)Size == Size)
1030+
if ((uint16_t)Size == Size)
10311031
return dwarf::DW_FORM_block2;
1032-
if ((unsigned int)Size == Size)
1032+
if ((uint32_t)Size == Size)
10331033
return dwarf::DW_FORM_block4;
10341034
return dwarf::DW_FORM_block;
10351035
}
@@ -1058,11 +1058,11 @@ class DIEBlock : public DIEValueList {
10581058
/// BestForm - Choose the best form for data.
10591059
///
10601060
dwarf::Form BestForm() const {
1061-
if ((unsigned char)Size == Size)
1061+
if ((uint8_t)Size == Size)
10621062
return dwarf::DW_FORM_block1;
1063-
if ((unsigned short)Size == Size)
1063+
if ((uint16_t)Size == Size)
10641064
return dwarf::DW_FORM_block2;
1065-
if ((unsigned int)Size == Size)
1065+
if ((uint32_t)Size == Size)
10661066
return dwarf::DW_FORM_block4;
10671067
return dwarf::DW_FORM_block;
10681068
}

0 commit comments

Comments
 (0)