aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-12-08 16:22:06 +0100
committerNikita Popov <npopov@redhat.com>2023-12-08 16:28:23 +0100
commit3bba53854a21177b5423f9212343ecec6316e4bf (patch)
tree810c680944f7683daaa81f7496b341723c15c2fe /llvm/lib/IR
parent11dfb3cb3237a081ad711b06f1e8efbc7fff7a81 (diff)
downloadllvm-3bba53854a21177b5423f9212343ecec6316e4bf.zip
llvm-3bba53854a21177b5423f9212343ecec6316e4bf.tar.gz
llvm-3bba53854a21177b5423f9212343ecec6316e4bf.tar.bz2
[AsmWriter] Use unsigned char more consistently
On platforms where char is signed, the ">> 4" shift will produce incorrect results. We were already working on unsigned char for most characters, but not for the first one. Fixes https://github.com/llvm/llvm-project/issues/74732.
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/AsmWriter.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index bff64e3..95cdec7 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -3520,15 +3520,15 @@ static void printMetadataIdentifier(StringRef Name,
if (Name.empty()) {
Out << "<empty name> ";
} else {
- if (isalpha(static_cast<unsigned char>(Name[0])) || Name[0] == '-' ||
- Name[0] == '$' || Name[0] == '.' || Name[0] == '_')
- Out << Name[0];
+ unsigned char FirstC = static_cast<unsigned char>(Name[0]);
+ if (isalpha(FirstC) || FirstC == '-' || FirstC == '$' || FirstC == '.' ||
+ FirstC == '_')
+ Out << FirstC;
else
- Out << '\\' << hexdigit(Name[0] >> 4) << hexdigit(Name[0] & 0x0F);
+ Out << '\\' << hexdigit(FirstC >> 4) << hexdigit(FirstC & 0x0F);
for (unsigned i = 1, e = Name.size(); i != e; ++i) {
unsigned char C = Name[i];
- if (isalnum(static_cast<unsigned char>(C)) || C == '-' || C == '$' ||
- C == '.' || C == '_')
+ if (isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_')
Out << C;
else
Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);