llvm.org GIT mirror llvm / 87d0b9e
Add static cast to unsigned char whenever a character classification function is called with a signed char argument, in order to avoid assertions in Windows Debug configuration. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175006 91177308-0d34-0410-b5e6-96231b3b80d8 Guy Benyei 7 years ago
18 changed file(s) with 80 addition(s) and 56 deletion(s). Raw diff Collapse all Expand all
118118 if (BIn < EndBuffer-1 && BIn[1] == '\\') {
119119 *BOut++ = '\\'; // Two \ becomes one
120120 BIn += 2;
121 } else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
121 } else if (BIn < EndBuffer-2 &&
122 isxdigit(static_cast(BIn[1])) &&
123 isxdigit(static_cast(BIn[2]))) {
122124 *BOut = hexDigitValue(BIn[1]) * 16 + hexDigitValue(BIn[2]);
123125 BIn += 3; // Skip over handled chars
124126 ++BOut;
134136
135137 /// isLabelChar - Return true for [-a-zA-Z$._0-9].
136138 static bool isLabelChar(char C) {
137 return isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_';
139 return isalnum(static_cast(C)) || C == '-' || C == '$' ||
140 C == '.' || C == '_';
138141 }
139142
140143
187190 switch (CurChar) {
188191 default:
189192 // Handle letters: [a-zA-Z_]
190 if (isalpha(CurChar) || CurChar == '_')
193 if (isalpha(static_cast(CurChar)) || CurChar == '_')
191194 return LexIdentifier();
192195
193196 return lltok::Error;
281284 return lltok::GlobalVar;
282285
283286 // Handle GlobalVarID: @[0-9]+
284 if (isdigit(CurPtr[0])) {
285 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
287 if (isdigit(static_cast(CurPtr[0]))) {
288 for (++CurPtr; isdigit(static_cast(CurPtr[0])); ++CurPtr)
286289 /*empty*/;
287290
288291 uint64_t Val = atoull(TokStart+1, CurPtr);
316319 /// ReadVarName - Read the rest of a token containing a variable name.
317320 bool LLLexer::ReadVarName() {
318321 const char *NameStart = CurPtr;
319 if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
322 if (isalpha(static_cast(CurPtr[0])) ||
323 CurPtr[0] == '-' || CurPtr[0] == '$' ||
320324 CurPtr[0] == '.' || CurPtr[0] == '_') {
321325 ++CurPtr;
322 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
326 while (isalnum(static_cast(CurPtr[0])) ||
327 CurPtr[0] == '-' || CurPtr[0] == '$' ||
323328 CurPtr[0] == '.' || CurPtr[0] == '_')
324329 ++CurPtr;
325330
345350 return lltok::LocalVar;
346351
347352 // Handle LocalVarID: %[0-9]+
348 if (isdigit(CurPtr[0])) {
349 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
353 if (isdigit(static_cast(CurPtr[0]))) {
354 for (++CurPtr; isdigit(static_cast(CurPtr[0])); ++CurPtr)
350355 /*empty*/;
351356
352357 uint64_t Val = atoull(TokStart+1, CurPtr);
380385 /// !
381386 lltok::Kind LLLexer::LexExclaim() {
382387 // Lex a metadata name as a MetadataVar.
383 if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
388 if (isalpha(static_cast(CurPtr[0])) ||
389 CurPtr[0] == '-' || CurPtr[0] == '$' ||
384390 CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\') {
385391 ++CurPtr;
386 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
392 while (isalnum(static_cast(CurPtr[0])) ||
393 CurPtr[0] == '-' || CurPtr[0] == '$' ||
387394 CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\')
388395 ++CurPtr;
389396
398405 /// AttrGrpID ::= #[0-9]+
399406 lltok::Kind LLLexer::LexHash() {
400407 // Handle AttrGrpID: #[0-9]+
401 if (isdigit(CurPtr[0])) {
402 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
408 if (isdigit(static_cast(CurPtr[0]))) {
409 for (++CurPtr; isdigit(static_cast(CurPtr[0])); ++CurPtr)
403410 /*empty*/;
404411
405412 uint64_t Val = atoull(TokStart+1, CurPtr);
424431
425432 for (; isLabelChar(*CurPtr); ++CurPtr) {
426433 // If we decide this is an integer, remember the end of the sequence.
427 if (!IntEnd && !isdigit(*CurPtr)) IntEnd = CurPtr;
428 if (!KeywordEnd && !isalnum(*CurPtr) && *CurPtr != '_') KeywordEnd = CurPtr;
434 if (!IntEnd && !isdigit(static_cast(*CurPtr)))
435 IntEnd = CurPtr;
436 if (!KeywordEnd && !isalnum(static_cast(*CurPtr)) &&
437 *CurPtr != '_')
438 KeywordEnd = CurPtr;
429439 }
430440
431441 // If we stopped due to a colon, this really is a label.
675685 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
676686 // the CFE to avoid forcing it to deal with 64-bit numbers.
677687 if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
678 TokStart[1] == '0' && TokStart[2] == 'x' && isxdigit(TokStart[3])) {
688 TokStart[1] == '0' && TokStart[2] == 'x' &&
689 isxdigit(static_cast(TokStart[3]))) {
679690 int len = CurPtr-TokStart-3;
680691 uint32_t bits = len * 4;
681692 APInt Tmp(bits, StringRef(TokStart+3, len), 16);
715726 Kind = 'J';
716727 }
717728
718 if (!isxdigit(CurPtr[0])) {
729 if (!isxdigit(static_cast(CurPtr[0]))) {
719730 // Bad token, return it as an error.
720731 CurPtr = TokStart+1;
721732 return lltok::Error;
722733 }
723734
724 while (isxdigit(CurPtr[0]))
735 while (isxdigit(static_cast(CurPtr[0])))
725736 ++CurPtr;
726737
727738 if (Kind == 'J') {
768779 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
769780 lltok::Kind LLLexer::LexDigitOrNegative() {
770781 // If the letter after the negative is not a number, this is probably a label.
771 if (!isdigit(TokStart[0]) && !isdigit(CurPtr[0])) {
782 if (!isdigit(static_cast(TokStart[0])) &&
783 !isdigit(static_cast(CurPtr[0]))) {
772784 // Okay, this is not a number after the -, it's probably a label.
773785 if (const char *End = isLabelTail(CurPtr)) {
774786 StrVal.assign(TokStart, End-1);
782794 // At this point, it is either a label, int or fp constant.
783795
784796 // Skip digits, we have at least one.
785 for (; isdigit(CurPtr[0]); ++CurPtr)
797 for (; isdigit(static_cast(CurPtr[0])); ++CurPtr)
786798 /*empty*/;
787799
788800 // Check to see if this really is a label afterall, e.g. "-1:".
819831 ++CurPtr;
820832
821833 // Skip over [0-9]*([eE][-+]?[0-9]+)?
822 while (isdigit(CurPtr[0])) ++CurPtr;
834 while (isdigit(static_cast(CurPtr[0]))) ++CurPtr;
823835
824836 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
825 if (isdigit(CurPtr[1]) ||
826 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
837 if (isdigit(static_cast(CurPtr[1])) ||
838 ((CurPtr[1] == '-' || CurPtr[1] == '+') &&
839 isdigit(static_cast(CurPtr[2])))) {
827840 CurPtr += 2;
828 while (isdigit(CurPtr[0])) ++CurPtr;
841 while (isdigit(static_cast(CurPtr[0]))) ++CurPtr;
829842 }
830843 }
831844
837850 lltok::Kind LLLexer::LexPositive() {
838851 // If the letter after the negative is a number, this is probably not a
839852 // label.
840 if (!isdigit(CurPtr[0]))
853 if (!isdigit(static_cast(CurPtr[0])))
841854 return lltok::Error;
842855
843856 // Skip digits.
844 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
857 for (++CurPtr; isdigit(static_cast(CurPtr[0])); ++CurPtr)
845858 /*empty*/;
846859
847860 // At this point, we need a '.'.
853866 ++CurPtr;
854867
855868 // Skip over [0-9]*([eE][-+]?[0-9]+)?
856 while (isdigit(CurPtr[0])) ++CurPtr;
869 while (isdigit(static_cast(CurPtr[0]))) ++CurPtr;
857870
858871 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
859 if (isdigit(CurPtr[1]) ||
860 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
872 if (isdigit(static_cast(CurPtr[1])) ||
873 ((CurPtr[1] == '-' || CurPtr[1] == '+') &&
874 isdigit(static_cast(CurPtr[2])))) {
861875 CurPtr += 2;
862 while (isdigit(CurPtr[0])) ++CurPtr;
876 while (isdigit(static_cast(CurPtr[0]))) ++CurPtr;
863877 }
864878 }
865879
20372037 /// a matching constraint like "4".
20382038 bool TargetLowering::AsmOperandInfo::isMatchingInputConstraint() const {
20392039 assert(!ConstraintCode.empty() && "No known constraint!");
2040 return isdigit(ConstraintCode[0]);
2040 return isdigit(static_cast(ConstraintCode[0]));
20412041 }
20422042
20432043 /// getMatchedOperand - If this is an input matching constraint, this method
7979 if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(),
8080 strlen(MAI.getSeparatorString())) == 0)
8181 atInsnStart = true;
82 if (atInsnStart && !std::isspace(*Str)) {
82 if (atInsnStart && !std::isspace(static_cast(*Str))) {
8383 Length += MAI.getMaxInstLength();
8484 atInsnStart = false;
8585 }
116116 }
117117
118118 // Scan the name to see if it needs quotes first.
119 bool NeedsQuotes = isdigit(Name[0]);
119 bool NeedsQuotes = isdigit(static_cast(Name[0]));
120120 if (!NeedsQuotes) {
121121 for (unsigned i = 0, e = Name.size(); i != e; ++i) {
122122 // By making this unsigned, the value passed in to isalnum will always be
124124 // its implementation will assert. This situation can arise when dealing
125125 // with UTF-8 multibyte characters.
126126 unsigned char C = Name[i];
127 if (!isalnum(C) && C != '-' && C != '.' && C != '_') {
127 if (!isalnum(static_cast(C)) && C != '-' && C != '.' &&
128 C != '_') {
128129 NeedsQuotes = true;
129130 break;
130131 }
13911392 if (Name.empty()) {
13921393 Out << " ";
13931394 } else {
1394 if (isalpha(Name[0]) || Name[0] == '-' || Name[0] == '$' ||
1395 if (isalpha(static_cast(Name[0])) ||
1396 Name[0] == '-' || Name[0] == '$' ||
13951397 Name[0] == '.' || Name[0] == '_')
13961398 Out << Name[0];
13971399 else
13981400 Out << '\\' << hexdigit(Name[0] >> 4) << hexdigit(Name[0] & 0x0F);
13991401 for (unsigned i = 1, e = Name.size(); i != e; ++i) {
14001402 unsigned char C = Name[i];
1401 if (isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_')
1403 if (isalnum(static_cast(C)) || C == '-' || C == '$' ||
1404 C == '.' || C == '_')
14021405 Out << C;
14031406 else
14041407 Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);
150150 if (ConstraintEnd == E) return true; // "{foo"
151151 pCodes->push_back(std::string(I, ConstraintEnd+1));
152152 I = ConstraintEnd+1;
153 } else if (isdigit(*I)) { // Matching Constraint
153 } else if (isdigit(static_cast(*I))) { // Matching Constraint
154154 // Maximal munch numbers.
155155 StringRef::iterator NumStart = I;
156 while (I != E && isdigit(*I))
156 while (I != E && isdigit(static_cast(*I)))
157157 ++I;
158158 pCodes->push_back(std::string(NumStart, I));
159159 unsigned N = atoi(pCodes->back().c_str());
129129 if (MDName.empty())
130130 return false;
131131
132 if (!std::isalpha(MDName[0]))
132 if (!std::isalpha(static_cast(MDName[0])))
133133 return false;
134134
135135 for (StringRef::iterator I = MDName.begin() + 1, E = MDName.end(); I != E;
136136 ++I) {
137 if (!std::isalnum(*I) && *I != '_' && *I != '-' && *I != '.')
137 if (!std::isalnum(static_cast(*I)) && *I != '_' &&
138 *I != '-' && *I != '.')
138139 return false;
139140 }
140141 return true;
605605 // Check to see if there is a dot in the name followed by a digit.
606606 size_t DotPos = ST->getName().rfind('.');
607607 if (DotPos == 0 || DotPos == StringRef::npos ||
608 ST->getName().back() == '.' || !isdigit(ST->getName()[DotPos+1]))
608 ST->getName().back() == '.' ||
609 !isdigit(static_cast(ST->getName()[DotPos+1])))
609610 continue;
610611
611612 // Check to see if the destination module has a struct with the prefix name.
16211621 // we can't do that. AsmLexer.cpp should probably be changed to handle
16221622 // '@' as a special case when needed.
16231623 static bool isIdentifierChar(char c) {
1624 return isalnum(c) || c == '_' || c == '$' || c == '.';
1624 return isalnum(static_cast(c)) || c == '_' || c == '$' ||
1625 c == '.';
16251626 }
16261627
16271628 bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
16451646 continue;
16461647
16471648 char Next = Body[Pos + 1];
1648 if (Next == '$' || Next == 'n' || isdigit(Next))
1649 if (Next == '$' || Next == 'n' ||
1650 isdigit(static_cast(Next)))
16491651 break;
16501652 } else {
16511653 // This macro has parameters, look for \foo, \bar, etc.
30933095 if (Body[Pos] != '$' || Pos + 1 == End)
30943096 continue;
30953097 char Next = Body[Pos + 1];
3096 if (Next == '$' || Next == 'n' || isdigit(Next))
3098 if (Next == '$' || Next == 'n' ||
3099 isdigit(static_cast(Next)))
30973100 break;
30983101 }
30993102
164164
165165 /// StripSpaces - This removes leading and trailing spaces from the StringRef.
166166 static void StripSpaces(StringRef &Str) {
167 while (!Str.empty() && isspace(Str[0]))
167 while (!Str.empty() && isspace(static_cast(Str[0])))
168168 Str = Str.substr(1);
169 while (!Str.empty() && isspace(Str.back()))
169 while (!Str.empty() && isspace(static_cast(Str.back())))
170170 Str = Str.substr(0, Str.size()-1);
171171 }
172172
266266 }
267267
268268 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL)
269 ret = ::toupper(ret);
269 ret = ::toupper(static_cast(ret));
270270
271271 Result = ret;
272272 return object_error::success;
272272 }
273273
274274 if (Flags & (macho::STF_External | macho::STF_PrivateExtern))
275 Char = toupper(Char);
275 Char = toupper(static_cast(Char));
276276 Result = Char;
277277 return object_error::success;
278278 }
8686
8787 // If one of the positions is at a space and the other isn't, chomp up 'til
8888 // the end of the space.
89 while (isspace(*F1P) && F1P != F1End)
89 while (isspace(static_cast(*F1P)) && F1P != F1End)
9090 ++F1P;
91 while (isspace(*F2P) && F2P != F2End)
91 while (isspace(static_cast(*F2P)) && F2P != F2End)
9292 ++F2P;
9393
9494 // If we stop on numbers, compare their difference.
4343
4444 #ifdef LLVM_ON_WIN32
4545 // C:
46 if (path.size() >= 2 && std::isalpha(path[0]) && path[1] == ':')
46 if (path.size() >= 2 && std::isalpha(static_cast(path[0])) &&
47 path[1] == ':')
4748 return path.substr(0, 2);
4849 #endif
4950
8181 pos = path.rfind(':',len);
8282 size_t rootslash = 0;
8383 if (pos != std::string::npos) {
84 if (pos != 1 || !isalpha(path[0]) || len < 3)
84 if (pos != 1 || !isalpha(static_cast(path[0])) || len < 3)
8585 return false;
8686 rootslash = 2;
8787 }
240240 if (cs == '+' || cs == '-') {
241241 int c1 = buf[len - 2];
242242 int c0 = buf[len - 1];
243 if (isdigit(c1) && isdigit(c0)) {
243 if (isdigit(static_cast(c1)) &&
244 isdigit(static_cast(c0))) {
244245 // Trim leading '0': "...e+012" -> "...e+12\0"
245246 buf[len - 3] = c1;
246247 buf[len - 2] = c0;
449449 outs() << " blob data = ";
450450 bool BlobIsPrintable = true;
451451 for (unsigned i = 0, e = Blob.size(); i != e; ++i)
452 if (!isprint(Blob[i])) {
452 if (!isprint(static_cast(Blob[i]))) {
453453 BlobIsPrintable = false;
454454 break;
455455 }
480480 // Print ascii.
481481 outs() << " ";
482482 for (std::size_t i = 0; i < 16 && addr + i < end; ++i) {
483 if (std::isprint(Contents[addr + i] & 0xFF))
483 if (std::isprint(static_cast(Contents[addr + i]) & 0xFF))
484484 outs() << Contents[addr + i];
485485 else
486486 outs() << ".";
241241 }
242242
243243 // Name can't start with a digit.
244 if (isdigit(Name[0])) {
244 if (isdigit(static_cast(Name[0]))) {
245245 SM.PrintMessage(SMLoc::getFromPointer(Name.data()), SourceMgr::DK_Error,
246246 "invalid name in named regex");
247247 return true;