fix warning with newer g++ compilers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

fix warning with newer g++ compilers

Mike Stump
Newer g++ compilers can emit:

/Volumes/mrs5/net/llvm/llvm/llvm/lib/AsmParser/LLLexer.cpp: In member  
function 'int llvm::LLLexer::LexAt()':
/Volumes/mrs5/net/llvm/llvm/llvm/lib/AsmParser/LLLexer.cpp:287:  
warning: suggest a space before ';' or explicit braces around empty  
body in 'for' statement
/Volumes/mrs5/net/llvm/llvm/llvm/lib/AsmParser/LLLexer.cpp: In member  
function 'int llvm::LLLexer::LexPercent()':
/Volumes/mrs5/net/llvm/llvm/llvm/lib/AsmParser/LLLexer.cpp:338:  
warning: suggest a space before ';' or explicit braces around empty  
body in 'for' statement
/Volumes/mrs5/net/llvm/llvm/llvm/lib/AsmParser/LLLexer.cpp: In member  
function 'int llvm::LLLexer::LexDigitOrNegative()':
/Volumes/mrs5/net/llvm/llvm/llvm/lib/AsmParser/LLLexer.cpp:720:  
warning: suggest a space before ';' or explicit braces around empty  
body in 'for' statement
/Volumes/mrs5/net/llvm/llvm/llvm/lib/AsmParser/LLLexer.cpp: In member  
function 'int llvm::LLLexer::LexPositive()':
/Volumes/mrs5/net/llvm/llvm/llvm/lib/AsmParser/LLLexer.cpp:789:  
warning: suggest a space before ';' or explicit braces around empty  
body in 'for' statement

The usual style is to put a space before the ;, or put the ; on a new  
line to visually separate the ; from the for statement, so that the  
follow like doesn't look like it goes with the for.

Thoughts?


Index: lib/AsmParser/LLLexer.cpp
===================================================================
--- lib/AsmParser/LLLexer.cpp (revision 45058)
+++ lib/AsmParser/LLLexer.cpp (working copy)
@@ -284,7 +284,7 @@

    // Handle GlobalVarID: @[0-9]+
    if (isdigit(CurPtr[0])) {
-    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
+    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) ;

      uint64_t Val = atoull(TokStart+1, CurPtr);
      if ((unsigned)Val != Val)
@@ -335,7 +335,7 @@

    // Handle LocalVarID: %[0-9]+
    if (isdigit(CurPtr[0])) {
-    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
+    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) ;

      uint64_t Val = atoull(TokStart+1, CurPtr);
      if ((unsigned)Val != Val)
@@ -717,7 +717,7 @@
    // At this point, it is either a label, int or fp constant.

    // Skip digits, we have at least one.
-  for (; isdigit(CurPtr[0]); ++CurPtr);
+  for (; isdigit(CurPtr[0]); ++CurPtr) ;

    // Check to see if this really is a label afterall, e.g. "-1:".
    if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
@@ -786,7 +786,7 @@
      return CurPtr[-1];

    // Skip digits.
-  for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
+  for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) ;

    // At this point, we need a '.'.
    if (CurPtr[0] != '.') {

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: fix warning with newer g++ compilers

Duncan Sands
Hi,

> -    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
> +    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) ;

personally I like

        for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) {}

better since it is more explicit.

Ciao,

Duncan.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: fix warning with newer g++ compilers

Ralph Corderoy
In reply to this post by Mike Stump

Hi Mike,

> The usual style is to put a space before the ;, or put the ; on a new
> line to visually separate the ; from the for statement, so that the
> follow like doesn't look like it goes with the for.

The "usual" styles I'm used to seeing, dating back almost 20 years, are
the semi-colon up tight to the closing parenthesis, as LLLexer.cpp has,
or

    for (fee(); fie(); foe()) {
        /* Do nothing. */
    }

However, I see indent(1) has a -ss option to insert a single space
before the semi-colon so the convention must have been around a while.

Personally, I think the lack of a following indented statement or block
makes it clear to look for the semi-colon if it hasn't already been
spotted and the warning's overkill.

Cheers,


Ralph.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: fix warning with newer g++ compilers

Chris Lattner
In reply to this post by Mike Stump

On Dec 14, 2007, at 11:10 PM, Mike Stump wrote:

> Newer g++ compilers can emit:
>
> /Volumes/mrs5/net/llvm/llvm/llvm/lib/AsmParser/LLLexer.cpp:789:
> warning: suggest a space before ';' or explicit braces around empty
> body in 'for' statement
>
> The usual style is to put a space before the ;, or put the ; on a new
> line to visually separate the ; from the for statement, so that the
> follow like doesn't look like it goes with the for.

Hey Mike,

Thanks for the patch.  It doesn't apply because your mailer included  
it inline.  If you're using the apple mailer, putting a .patch suffix  
on it (instead of .txt) might help.

w.r.t the debate, I'd prefer:

  for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
    /*empty*/;

but I really don't care that much :)

-Chris

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: fix warning with newer g++ compilers

Dale Johannesen
In reply to this post by Duncan Sands

On Dec 15, 2007, at 2:13 AM, Duncan Sands wrote:

> Hi,
>
>> -    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
>> +    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) ;
>
> personally I like
>
> for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) {}
>
> better since it is more explicit.

I think the bikeshed should be orange:

        for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
              ;

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: fix warning with newer g++ compilers

Eric Christopher-2

On Dec 15, 2007, at 12:45 PM, Dale Johannesen wrote:

> I think the bikeshed should be orange:
>
> for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
>              ;

FWIW I agree that orange is a great color.

-eric
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: fix warning with newer g++ compilers

Mike Stump
In reply to this post by Mike Stump
Ok, here is the patch again...  I also included fixes for the bits
that originally gave my mailer fits...

Two votes for orange, so I went with orange...

Doing diffs in .:
--- ./lib/AsmParser/LLLexer.cpp.~1~ 2007-12-14 22:09:06.000000000 -0800
+++ ./lib/AsmParser/LLLexer.cpp 2007-12-15 13:02:47.000000000 -0800
@@ -54,7 +54,7 @@ static uint64_t HexIntToVal(const char *
       Result += C-'A'+10;
     else if (C >= 'a' && C <= 'f')
       Result += C-'a'+10;
-    
+
     if (Result < OldRes) {   // Uh, oh, overflow detected!!!
       GenerateError("constant bigger than 64 bits detected!");
       return 0;
@@ -102,7 +102,7 @@ static void HexToIntPair(const char *Buf
 // appropriate character.
 static void UnEscapeLexed(std::string &Str) {
   if (Str.empty()) return;
-  
+
   char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
   char *BOut = Buffer;
   for (char *BIn = Buffer; BIn != EndBuffer; ) {
@@ -168,9 +168,9 @@ int LLLexer::getNextChar() {
     // a random nul in the file.  Disambiguate that here.
     if (CurPtr-1 != CurBuf->getBufferEnd())
       return 0;  // Just whitespace.
-        
+
     // Otherwise, return end of file.
-    --CurPtr;  // Another call to lex will return EOF again.  
+    --CurPtr;  // Another call to lex will return EOF again.
     return EOF;
   case '\n':
   case '\r':
@@ -180,24 +180,24 @@ int LLLexer::getNextChar() {
     if ((*CurPtr == '\n' || (*CurPtr == '\r')) &&
         *CurPtr != CurChar)
       ++CurPtr;  // Eat the two char newline sequence.
-      
+
     ++CurLineNo;
     return '\n';
-  }  
+  }
 }
 
 
 int LLLexer::LexToken() {
   TokStart = CurPtr;
-  
+
   int CurChar = getNextChar();
-  
+
   switch (CurChar) {
   default:
     // Handle letters: [a-zA-Z_]
     if (isalpha(CurChar) || CurChar == '_')
       return LexIdentifier();
-    
+
     return CurChar;
   case EOF: return YYEOF;
   case 0:
@@ -234,7 +234,7 @@ int LLLexer::LexToken() {
     return LexToken();
   case '0': case '1': case '2': case '3': case '4':
   case '5': case '6': case '7': case '8': case '9':
-  case '-':
+  case '-':
     return LexDigitOrNegative();
   }
 }
@@ -254,11 +254,11 @@ int LLLexer::LexAt() {
   // Handle AtStringConstant: @\"[^\"]*\"
   if (CurPtr[0] == '"') {
     ++CurPtr;
-    
+
     while (1) {
       int CurChar = getNextChar();
-    
-      if (CurChar == EOF) {
+
+      if (CurChar == EOF) {
         GenerateError("End of file in global variable name");
         return YYERROR;
       }
@@ -269,30 +269,31 @@ int LLLexer::LexAt() {
       }
     }
   }
-  
+
   // Handle GlobalVarName: @[-a-zA-Z$._][-a-zA-Z$._0-9]*
-  if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
+  if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
       CurPtr[0] == '.' || CurPtr[0] == '_') {
     ++CurPtr;
-    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
+    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
            CurPtr[0] == '.' || CurPtr[0] == '_')
       ++CurPtr;
 
     llvmAsmlval.StrVal = new std::string(TokStart+1, CurPtr);   // Skip @
     return GLOBALVAR;
   }
-  
+
   // Handle GlobalVarID: @[0-9]+
   if (isdigit(CurPtr[0])) {
-    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
-    
+    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
+      ;
+
     uint64_t Val = atoull(TokStart+1, CurPtr);
     if ((unsigned)Val != Val)
       GenerateError("Invalid value number (too large)!");
     llvmAsmlval.UIntVal = unsigned(Val);
     return GLOBALVAL_ID;
   }
-  
+
   return '@';
 }
 
@@ -305,11 +306,11 @@ int LLLexer::LexPercent() {
   // Handle PctStringConstant: %\"[^\"]*\"
   if (CurPtr[0] == '"') {
     ++CurPtr;
-    
+
     while (1) {
       int CurChar = getNextChar();
-      
-      if (CurChar == EOF) {
+
+      if (CurChar == EOF) {
         GenerateError("End of file in local variable name");
         return YYERROR;
       }
@@ -320,30 +321,31 @@ int LLLexer::LexPercent() {
       }
     }
   }
-  
+
   // Handle LocalVarName: %[-a-zA-Z$._][-a-zA-Z$._0-9]*
-  if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
+  if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
       CurPtr[0] == '.' || CurPtr[0] == '_') {
     ++CurPtr;
-    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
+    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
            CurPtr[0] == '.' || CurPtr[0] == '_')
       ++CurPtr;
-    
+
     llvmAsmlval.StrVal = new std::string(TokStart+1, CurPtr);   // Skip %
     return LOCALVAR;
   }
-  
+
   // Handle LocalVarID: %[0-9]+
   if (isdigit(CurPtr[0])) {
-    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
-    
+    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
+      ;
+
     uint64_t Val = atoull(TokStart+1, CurPtr);
     if ((unsigned)Val != Val)
       GenerateError("Invalid value number (too large)!");
     llvmAsmlval.UIntVal = unsigned(Val);
     return LOCALVAL_ID;
   }
-  
+
   return '%';
 }
 
@@ -353,12 +355,12 @@ int LLLexer::LexPercent() {
 int LLLexer::LexQuote() {
   while (1) {
     int CurChar = getNextChar();
-    
-    if (CurChar == EOF) {
+
+    if (CurChar == EOF) {
       GenerateError("End of file in quoted string");
       return YYERROR;
     }
-    
+
     if (CurChar != '"') continue;
 
     if (CurPtr[0] != ':') {
@@ -366,7 +368,7 @@ int LLLexer::LexQuote() {
       UnEscapeLexed(*llvmAsmlval.StrVal);
       return STRINGCONSTANT;
     }
-    
+
     ++CurPtr;
     llvmAsmlval.StrVal = new std::string(TokStart+1, CurPtr-2);
     UnEscapeLexed(*llvmAsmlval.StrVal);
@@ -395,26 +397,26 @@ int LLLexer::LexIdentifier() {
   const char *StartChar = CurPtr;
   const char *IntEnd = CurPtr[-1] == 'i' ? 0 : StartChar;
   const char *KeywordEnd = 0;
-  
+
   for (; isLabelChar(*CurPtr); ++CurPtr) {
     // If we decide this is an integer, remember the end of the sequence.
     if (!IntEnd && !isdigit(*CurPtr)) IntEnd = CurPtr;
     if (!KeywordEnd && !isalnum(*CurPtr) && *CurPtr != '_') KeywordEnd = CurPtr;
   }
-  
+
   // If we stopped due to a colon, this really is a label.
   if (*CurPtr == ':') {
     llvmAsmlval.StrVal = new std::string(StartChar-1, CurPtr++);
     return LABELSTR;
   }
-  
+
   // Otherwise, this wasn't a label.  If this was valid as an integer type,
   // return it.
   if (IntEnd == 0) IntEnd = CurPtr;
   if (IntEnd != StartChar) {
     CurPtr = IntEnd;
     uint64_t NumBits = atoull(StartChar, CurPtr);
-    if (NumBits < IntegerType::MIN_INT_BITS ||
+    if (NumBits < IntegerType::MIN_INT_BITS ||
         NumBits > IntegerType::MAX_INT_BITS) {
       GenerateError("Bitwidth for integer type out of range!");
       return YYERROR;
@@ -423,7 +425,7 @@ int LLLexer::LexIdentifier() {
     llvmAsmlval.PrimType = Ty;
     return INTTYPE;
   }
-  
+
   // Otherwise, this was a letter sequence.  See which keyword this is.
   if (KeywordEnd == 0) KeywordEnd = CurPtr;
   CurPtr = KeywordEnd;
@@ -440,7 +442,7 @@ int LLLexer::LexIdentifier() {
   KEYWORD("define",    DEFINE);
   KEYWORD("global",    GLOBAL);
   KEYWORD("constant",  CONSTANT);
-  
+
   KEYWORD("internal",  INTERNAL);
   KEYWORD("linkonce",  LINKONCE);
   KEYWORD("weak",      WEAK);
@@ -470,14 +472,14 @@ int LLLexer::LexIdentifier() {
   KEYWORD("asm", ASM_TOK);
   KEYWORD("sideeffect", SIDEEFFECT);
   KEYWORD("gc", GC);
-  
+
   KEYWORD("cc", CC_TOK);
   KEYWORD("ccc", CCC_TOK);
   KEYWORD("fastcc", FASTCC_TOK);
   KEYWORD("coldcc", COLDCC_TOK);
   KEYWORD("x86_stdcallcc", X86_STDCALLCC_TOK);
   KEYWORD("x86_fastcallcc", X86_FASTCALLCC_TOK);
-  
+
   KEYWORD("signext", SIGNEXT);
   KEYWORD("zeroext", ZEROEXT);
   KEYWORD("inreg", INREG);
@@ -489,7 +491,7 @@ int LLLexer::LexIdentifier() {
   KEYWORD("nest", NEST);
   KEYWORD("readnone", READNONE);
   KEYWORD("readonly", READONLY);
-  
+
   KEYWORD("type", TYPE);
   KEYWORD("opaque", OPAQUE);
 
@@ -539,7 +541,7 @@ int LLLexer::LexIdentifier() {
     if (JustWhitespaceNewLine(CurPtr))
       return ZEROEXT;
   }
-  
+
   // Keywords for instructions.
 #define INSTKEYWORD(STR, type, Enum, TOK) \
   if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
@@ -596,8 +598,8 @@ int LLLexer::LexIdentifier() {
   INSTKEYWORD("extractelement", OtherOpVal, ExtractElement, EXTRACTELEMENT);
   INSTKEYWORD("insertelement", OtherOpVal, InsertElement, INSERTELEMENT);
   INSTKEYWORD("shufflevector", OtherOpVal, ShuffleVector, SHUFFLEVECTOR);
-#undef INSTKEYWORD
-  
+#undef INSTKEYWORD
+
   // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
   // the CFE to avoid forcing it to deal with 64-bit numbers.
   if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
@@ -619,13 +621,13 @@ int LLLexer::LexIdentifier() {
       return EUINT64VAL;
     }
   }
-  
+
   // If this is "cc1234", return this as just "cc".
   if (TokStart[0] == 'c' && TokStart[1] == 'c') {
     CurPtr = TokStart+2;
     return CC_TOK;
   }
-  
+
   // If this starts with "call", return it as CALL.  This is to support old
   // broken .ll files.  FIXME: remove this with LLVM 3.0.
   if (CurPtr-TokStart > 4 && !memcmp(TokStart, "call", 4)) {
@@ -633,7 +635,7 @@ int LLLexer::LexIdentifier() {
     llvmAsmlval.OtherOpVal = Instruction::Call;
     return CALL;
   }
-  
+
   // Finally, if this isn't known, return just a single character.
   CurPtr = TokStart+1;
   return TokStart[0];
@@ -648,7 +650,7 @@ int LLLexer::LexIdentifier() {
 ///    HexPPC128Constant 0xM[0-9A-Fa-f]+
 int LLLexer::Lex0x() {
   CurPtr = TokStart + 2;
-  
+
   char Kind;
   if (CurPtr[0] >= 'K' && CurPtr[0] <= 'M') {
     Kind = *CurPtr++;
@@ -661,18 +663,18 @@ int LLLexer::Lex0x() {
     CurPtr = TokStart+1;
     return '0';
   }
-  
+
   while (isxdigit(CurPtr[0]))
     ++CurPtr;
-  
+
   if (Kind == 'J') {
     // HexFPConstant - Floating point constant represented in IEEE format as a
     // hexadecimal number for when exponential notation is not precise enough.
     // Float and double only.
-    llvmAsmlval.FPVal = new APFloat(HexToFP(TokStart+2, CurPtr));
+    llvmAsmlval.FPVal = new APFloat(HexToFP(TokStart+2, CurPtr));
     return FPVAL;
   }
-  
+
   uint64_t Pair[2];
   HexToIntPair(TokStart+3, CurPtr, Pair);
   switch (Kind) {
@@ -710,15 +712,16 @@ int LLLexer::LexDigitOrNegative() {
       CurPtr = End;
       return LABELSTR;
     }
-    
+
     return CurPtr[-1];
   }
-  
+
   // At this point, it is either a label, int or fp constant.
-  
+
   // Skip digits, we have at least one.
-  for (; isdigit(CurPtr[0]); ++CurPtr);
-    
+  for (; isdigit(CurPtr[0]); ++CurPtr)
+    ;
+
   // Check to see if this really is a label afterall, e.g. "-1:".
   if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
     if (const char *End = isLabelTail(CurPtr)) {
@@ -727,7 +730,7 @@ int LLLexer::LexDigitOrNegative() {
       return LABELSTR;
     }
   }
-    
+
   // If the next character is a '.', then it is a fp value, otherwise its
   // integer.
   if (CurPtr[0] != '.') {
@@ -753,7 +756,7 @@ int LLLexer::LexDigitOrNegative() {
         Tmp.trunc(activeBits);
       if (Tmp.getBitWidth() > 64) {
         llvmAsmlval.APIntVal = new APInt(Tmp);
-        return EUAPINTVAL;
+        return EUAPINTVAL;
       } else {
         llvmAsmlval.UInt64Val = Tmp.getZExtValue();
         return EUINT64VAL;
@@ -762,20 +765,20 @@ int LLLexer::LexDigitOrNegative() {
   }
 
   ++CurPtr;
-  
+
   // Skip over [0-9]*([eE][-+]?[0-9]+)?
   while (isdigit(CurPtr[0])) ++CurPtr;
-  
+
   if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
-    if (isdigit(CurPtr[1]) ||
+    if (isdigit(CurPtr[1]) ||
         ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
       CurPtr += 2;
       while (isdigit(CurPtr[0])) ++CurPtr;
     }
   }
-  
+
   llvmAsmlval.FPVal = new APFloat(atof(TokStart));
-  return FPVAL;
+  return FPVAL;
 }
 
 ///    FPConstant  [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
@@ -784,31 +787,32 @@ int LLLexer::LexPositive() {
   // label.
   if (!isdigit(CurPtr[0]))
     return CurPtr[-1];
-  
+
   // Skip digits.
-  for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
+  for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
+    ;
 
   // At this point, we need a '.'.
   if (CurPtr[0] != '.') {
     CurPtr = TokStart+1;
     return TokStart[0];
   }
-  
+
   ++CurPtr;
-  
+
   // Skip over [0-9]*([eE][-+]?[0-9]+)?
   while (isdigit(CurPtr[0])) ++CurPtr;
-  
+
   if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
-    if (isdigit(CurPtr[1]) ||
+    if (isdigit(CurPtr[1]) ||
         ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
       CurPtr += 2;
       while (isdigit(CurPtr[0])) ++CurPtr;
     }
   }
-  
+
   llvmAsmlval.FPVal = new APFloat(atof(TokStart));
-  return FPVAL;
+  return FPVAL;
 }
 
 
--------------
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: fix warning with newer g++ compilers

Bill Wendling
In reply to this post by Dale Johannesen
On Dec 15, 2007, at 12:45 PM, Dale Johannesen wrote:

> On Dec 15, 2007, at 2:13 AM, Duncan Sands wrote:
>
>> Hi,
>>
>>> -    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
>>> +    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) ;
>>
>> personally I like
>>
>> for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) {}
>>
>> better since it is more explicit.
>
> I think the bikeshed should be orange:
>
> for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
>               ;

You're ALL wrong!

   for (++CurPtr;
          isdigit(CurPtr[0]);
            ++CurPtr)
    {
     /* This space intentionally left empty */
    }

(Just kidding) ;-)

-bw
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: fix warning with newer g++ compilers

Bill Wendling
In reply to this post by Mike Stump
Applied. Thanks! :-)

-bw

On Dec 15, 2007, at 1:41 PM, Mike Stump wrote:

> Ok, here is the patch again...  I also included fixes for the bits
> that originally gave my mailer fits...
>
> Two votes for orange, so I went with orange...
>
> Doing diffs in .:
> --- ./lib/AsmParser/LLLexer.cpp.~1~ 2007-12-14 22:09:06.000000000  
> -0800
> +++ ./lib/AsmParser/LLLexer.cpp 2007-12-15 13:02:47.000000000 -0800
> @@ -54,7 +54,7 @@ static uint64_t HexIntToVal(const char *
>        Result += C-'A'+10;
>      else if (C >= 'a' && C <= 'f')
>        Result += C-'a'+10;
> -
> +
>      if (Result < OldRes) {   // Uh, oh, overflow detected!!!
>        GenerateError("constant bigger than 64 bits detected!");
>        return 0;
> @@ -102,7 +102,7 @@ static void HexToIntPair(const char *Buf
>  // appropriate character.
>  static void UnEscapeLexed(std::string &Str) {
>    if (Str.empty()) return;
> -
> +
>    char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
>    char *BOut = Buffer;
>    for (char *BIn = Buffer; BIn != EndBuffer; ) {
> @@ -168,9 +168,9 @@ int LLLexer::getNextChar() {
>      // a random nul in the file.  Disambiguate that here.
>      if (CurPtr-1 != CurBuf->getBufferEnd())
>        return 0;  // Just whitespace.
> -
> +
>      // Otherwise, return end of file.
> -    --CurPtr;  // Another call to lex will return EOF again.
> +    --CurPtr;  // Another call to lex will return EOF again.
>      return EOF;
>    case '\n':
>    case '\r':
> @@ -180,24 +180,24 @@ int LLLexer::getNextChar() {
>      if ((*CurPtr == '\n' || (*CurPtr == '\r')) &&
>          *CurPtr != CurChar)
>        ++CurPtr;  // Eat the two char newline sequence.
> -
> +
>      ++CurLineNo;
>      return '\n';
> -  }
> +  }
>  }
>
>
>  int LLLexer::LexToken() {
>    TokStart = CurPtr;
> -
> +
>    int CurChar = getNextChar();
> -
> +
>    switch (CurChar) {
>    default:
>      // Handle letters: [a-zA-Z_]
>      if (isalpha(CurChar) || CurChar == '_')
>        return LexIdentifier();
> -
> +
>      return CurChar;
>    case EOF: return YYEOF;
>    case 0:
> @@ -234,7 +234,7 @@ int LLLexer::LexToken() {
>      return LexToken();
>    case '0': case '1': case '2': case '3': case '4':
>    case '5': case '6': case '7': case '8': case '9':
> -  case '-':
> +  case '-':
>      return LexDigitOrNegative();
>    }
>  }
> @@ -254,11 +254,11 @@ int LLLexer::LexAt() {
>    // Handle AtStringConstant: @\"[^\"]*\"
>    if (CurPtr[0] == '"') {
>      ++CurPtr;
> -
> +
>      while (1) {
>        int CurChar = getNextChar();
> -
> -      if (CurChar == EOF) {
> +
> +      if (CurChar == EOF) {
>          GenerateError("End of file in global variable name");
>          return YYERROR;
>        }
> @@ -269,30 +269,31 @@ int LLLexer::LexAt() {
>        }
>      }
>    }
> -
> +
>    // Handle GlobalVarName: @[-a-zA-Z$._][-a-zA-Z$._0-9]*
> -  if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
> +  if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
>        CurPtr[0] == '.' || CurPtr[0] == '_') {
>      ++CurPtr;
> -    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] ==  
> '$' ||
> +    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] ==  
> '$' ||
>             CurPtr[0] == '.' || CurPtr[0] == '_')
>        ++CurPtr;
>
>      llvmAsmlval.StrVal = new std::string(TokStart+1, CurPtr);   //  
> Skip @
>      return GLOBALVAR;
>    }
> -
> +
>    // Handle GlobalVarID: @[0-9]+
>    if (isdigit(CurPtr[0])) {
> -    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
> -
> +    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
> +      ;
> +
>      uint64_t Val = atoull(TokStart+1, CurPtr);
>      if ((unsigned)Val != Val)
>        GenerateError("Invalid value number (too large)!");
>      llvmAsmlval.UIntVal = unsigned(Val);
>      return GLOBALVAL_ID;
>    }
> -
> +
>    return '@';
>  }
>
> @@ -305,11 +306,11 @@ int LLLexer::LexPercent() {
>    // Handle PctStringConstant: %\"[^\"]*\"
>    if (CurPtr[0] == '"') {
>      ++CurPtr;
> -
> +
>      while (1) {
>        int CurChar = getNextChar();
> -
> -      if (CurChar == EOF) {
> +
> +      if (CurChar == EOF) {
>          GenerateError("End of file in local variable name");
>          return YYERROR;
>        }
> @@ -320,30 +321,31 @@ int LLLexer::LexPercent() {
>        }
>      }
>    }
> -
> +
>    // Handle LocalVarName: %[-a-zA-Z$._][-a-zA-Z$._0-9]*
> -  if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
> +  if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
>        CurPtr[0] == '.' || CurPtr[0] == '_') {
>      ++CurPtr;
> -    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] ==  
> '$' ||
> +    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] ==  
> '$' ||
>             CurPtr[0] == '.' || CurPtr[0] == '_')
>        ++CurPtr;
> -
> +
>      llvmAsmlval.StrVal = new std::string(TokStart+1, CurPtr);   //  
> Skip %
>      return LOCALVAR;
>    }
> -
> +
>    // Handle LocalVarID: %[0-9]+
>    if (isdigit(CurPtr[0])) {
> -    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
> -
> +    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
> +      ;
> +
>      uint64_t Val = atoull(TokStart+1, CurPtr);
>      if ((unsigned)Val != Val)
>        GenerateError("Invalid value number (too large)!");
>      llvmAsmlval.UIntVal = unsigned(Val);
>      return LOCALVAL_ID;
>    }
> -
> +
>    return '%';
>  }
>
> @@ -353,12 +355,12 @@ int LLLexer::LexPercent() {
>  int LLLexer::LexQuote() {
>    while (1) {
>      int CurChar = getNextChar();
> -
> -    if (CurChar == EOF) {
> +
> +    if (CurChar == EOF) {
>        GenerateError("End of file in quoted string");
>        return YYERROR;
>      }
> -
> +
>      if (CurChar != '"') continue;
>
>      if (CurPtr[0] != ':') {
> @@ -366,7 +368,7 @@ int LLLexer::LexQuote() {
>        UnEscapeLexed(*llvmAsmlval.StrVal);
>        return STRINGCONSTANT;
>      }
> -
> +
>      ++CurPtr;
>      llvmAsmlval.StrVal = new std::string(TokStart+1, CurPtr-2);
>      UnEscapeLexed(*llvmAsmlval.StrVal);
> @@ -395,26 +397,26 @@ int LLLexer::LexIdentifier() {
>    const char *StartChar = CurPtr;
>    const char *IntEnd = CurPtr[-1] == 'i' ? 0 : StartChar;
>    const char *KeywordEnd = 0;
> -
> +
>    for (; isLabelChar(*CurPtr); ++CurPtr) {
>      // If we decide this is an integer, remember the end of the  
> sequence.
>      if (!IntEnd && !isdigit(*CurPtr)) IntEnd = CurPtr;
>      if (!KeywordEnd && !isalnum(*CurPtr) && *CurPtr != '_')  
> KeywordEnd = CurPtr;
>    }
> -
> +
>    // If we stopped due to a colon, this really is a label.
>    if (*CurPtr == ':') {
>      llvmAsmlval.StrVal = new std::string(StartChar-1, CurPtr++);
>      return LABELSTR;
>    }
> -
> +
>    // Otherwise, this wasn't a label.  If this was valid as an  
> integer type,
>    // return it.
>    if (IntEnd == 0) IntEnd = CurPtr;
>    if (IntEnd != StartChar) {
>      CurPtr = IntEnd;
>      uint64_t NumBits = atoull(StartChar, CurPtr);
> -    if (NumBits < IntegerType::MIN_INT_BITS ||
> +    if (NumBits < IntegerType::MIN_INT_BITS ||
>          NumBits > IntegerType::MAX_INT_BITS) {
>        GenerateError("Bitwidth for integer type out of range!");
>        return YYERROR;
> @@ -423,7 +425,7 @@ int LLLexer::LexIdentifier() {
>      llvmAsmlval.PrimType = Ty;
>      return INTTYPE;
>    }
> -
> +
>    // Otherwise, this was a letter sequence.  See which keyword  
> this is.
>    if (KeywordEnd == 0) KeywordEnd = CurPtr;
>    CurPtr = KeywordEnd;
> @@ -440,7 +442,7 @@ int LLLexer::LexIdentifier() {
>    KEYWORD("define",    DEFINE);
>    KEYWORD("global",    GLOBAL);
>    KEYWORD("constant",  CONSTANT);
> -
> +
>    KEYWORD("internal",  INTERNAL);
>    KEYWORD("linkonce",  LINKONCE);
>    KEYWORD("weak",      WEAK);
> @@ -470,14 +472,14 @@ int LLLexer::LexIdentifier() {
>    KEYWORD("asm", ASM_TOK);
>    KEYWORD("sideeffect", SIDEEFFECT);
>    KEYWORD("gc", GC);
> -
> +
>    KEYWORD("cc", CC_TOK);
>    KEYWORD("ccc", CCC_TOK);
>    KEYWORD("fastcc", FASTCC_TOK);
>    KEYWORD("coldcc", COLDCC_TOK);
>    KEYWORD("x86_stdcallcc", X86_STDCALLCC_TOK);
>    KEYWORD("x86_fastcallcc", X86_FASTCALLCC_TOK);
> -
> +
>    KEYWORD("signext", SIGNEXT);
>    KEYWORD("zeroext", ZEROEXT);
>    KEYWORD("inreg", INREG);
> @@ -489,7 +491,7 @@ int LLLexer::LexIdentifier() {
>    KEYWORD("nest", NEST);
>    KEYWORD("readnone", READNONE);
>    KEYWORD("readonly", READONLY);
> -
> +
>    KEYWORD("type", TYPE);
>    KEYWORD("opaque", OPAQUE);
>
> @@ -539,7 +541,7 @@ int LLLexer::LexIdentifier() {
>      if (JustWhitespaceNewLine(CurPtr))
>        return ZEROEXT;
>    }
> -
> +
>    // Keywords for instructions.
>  #define INSTKEYWORD(STR, type, Enum, TOK) \
>    if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
> @@ -596,8 +598,8 @@ int LLLexer::LexIdentifier() {
>    INSTKEYWORD("extractelement", OtherOpVal, ExtractElement,  
> EXTRACTELEMENT);
>    INSTKEYWORD("insertelement", OtherOpVal, InsertElement,  
> INSERTELEMENT);
>    INSTKEYWORD("shufflevector", OtherOpVal, ShuffleVector,  
> SHUFFLEVECTOR);
> -#undef INSTKEYWORD
> -
> +#undef INSTKEYWORD
> +
>    // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant  
> generated by
>    // the CFE to avoid forcing it to deal with 64-bit numbers.
>    if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
> @@ -619,13 +621,13 @@ int LLLexer::LexIdentifier() {
>        return EUINT64VAL;
>      }
>    }
> -
> +
>    // If this is "cc1234", return this as just "cc".
>    if (TokStart[0] == 'c' && TokStart[1] == 'c') {
>      CurPtr = TokStart+2;
>      return CC_TOK;
>    }
> -
> +
>    // If this starts with "call", return it as CALL.  This is to  
> support old
>    // broken .ll files.  FIXME: remove this with LLVM 3.0.
>    if (CurPtr-TokStart > 4 && !memcmp(TokStart, "call", 4)) {
> @@ -633,7 +635,7 @@ int LLLexer::LexIdentifier() {
>      llvmAsmlval.OtherOpVal = Instruction::Call;
>      return CALL;
>    }
> -
> +
>    // Finally, if this isn't known, return just a single character.
>    CurPtr = TokStart+1;
>    return TokStart[0];
> @@ -648,7 +650,7 @@ int LLLexer::LexIdentifier() {
>  ///    HexPPC128Constant 0xM[0-9A-Fa-f]+
>  int LLLexer::Lex0x() {
>    CurPtr = TokStart + 2;
> -
> +
>    char Kind;
>    if (CurPtr[0] >= 'K' && CurPtr[0] <= 'M') {
>      Kind = *CurPtr++;
> @@ -661,18 +663,18 @@ int LLLexer::Lex0x() {
>      CurPtr = TokStart+1;
>      return '0';
>    }
> -
> +
>    while (isxdigit(CurPtr[0]))
>      ++CurPtr;
> -
> +
>    if (Kind == 'J') {
>      // HexFPConstant - Floating point constant represented in IEEE  
> format as a
>      // hexadecimal number for when exponential notation is not  
> precise enough.
>      // Float and double only.
> -    llvmAsmlval.FPVal = new APFloat(HexToFP(TokStart+2, CurPtr));
> +    llvmAsmlval.FPVal = new APFloat(HexToFP(TokStart+2, CurPtr));
>      return FPVAL;
>    }
> -
> +
>    uint64_t Pair[2];
>    HexToIntPair(TokStart+3, CurPtr, Pair);
>    switch (Kind) {
> @@ -710,15 +712,16 @@ int LLLexer::LexDigitOrNegative() {
>        CurPtr = End;
>        return LABELSTR;
>      }
> -
> +
>      return CurPtr[-1];
>    }
> -
> +
>    // At this point, it is either a label, int or fp constant.
> -
> +
>    // Skip digits, we have at least one.
> -  for (; isdigit(CurPtr[0]); ++CurPtr);
> -
> +  for (; isdigit(CurPtr[0]); ++CurPtr)
> +    ;
> +
>    // Check to see if this really is a label afterall, e.g. "-1:".
>    if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
>      if (const char *End = isLabelTail(CurPtr)) {
> @@ -727,7 +730,7 @@ int LLLexer::LexDigitOrNegative() {
>        return LABELSTR;
>      }
>    }
> -
> +
>    // If the next character is a '.', then it is a fp value,  
> otherwise its
>    // integer.
>    if (CurPtr[0] != '.') {
> @@ -753,7 +756,7 @@ int LLLexer::LexDigitOrNegative() {
>          Tmp.trunc(activeBits);
>        if (Tmp.getBitWidth() > 64) {
>          llvmAsmlval.APIntVal = new APInt(Tmp);
> -        return EUAPINTVAL;
> +        return EUAPINTVAL;
>        } else {
>          llvmAsmlval.UInt64Val = Tmp.getZExtValue();
>          return EUINT64VAL;
> @@ -762,20 +765,20 @@ int LLLexer::LexDigitOrNegative() {
>    }
>
>    ++CurPtr;
> -
> +
>    // Skip over [0-9]*([eE][-+]?[0-9]+)?
>    while (isdigit(CurPtr[0])) ++CurPtr;
> -
> +
>    if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
> -    if (isdigit(CurPtr[1]) ||
> +    if (isdigit(CurPtr[1]) ||
>          ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr
> [2]))) {
>        CurPtr += 2;
>        while (isdigit(CurPtr[0])) ++CurPtr;
>      }
>    }
> -
> +
>    llvmAsmlval.FPVal = new APFloat(atof(TokStart));
> -  return FPVAL;
> +  return FPVAL;
>  }
>
>  ///    FPConstant  [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
> @@ -784,31 +787,32 @@ int LLLexer::LexPositive() {
>    // label.
>    if (!isdigit(CurPtr[0]))
>      return CurPtr[-1];
> -
> +
>    // Skip digits.
> -  for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
> +  for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
> +    ;
>
>    // At this point, we need a '.'.
>    if (CurPtr[0] != '.') {
>      CurPtr = TokStart+1;
>      return TokStart[0];
>    }
> -
> +
>    ++CurPtr;
> -
> +
>    // Skip over [0-9]*([eE][-+]?[0-9]+)?
>    while (isdigit(CurPtr[0])) ++CurPtr;
> -
> +
>    if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
> -    if (isdigit(CurPtr[1]) ||
> +    if (isdigit(CurPtr[1]) ||
>          ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr
> [2]))) {
>        CurPtr += 2;
>        while (isdigit(CurPtr[0])) ++CurPtr;
>      }
>    }
> -
> +
>    llvmAsmlval.FPVal = new APFloat(atof(TokStart));
> -  return FPVAL;
> +  return FPVAL;
>  }
>
>
> --------------
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: fix warning with newer g++ compilers

Chris Lattner
In reply to this post by Mike Stump

On Dec 15, 2007, at 1:41 PM, Mike Stump wrote:

> Ok, here is the patch again...  I also included fixes for the bits
> that originally gave my mailer fits...
>
> Two votes for orange, so I went with orange...

Hehe, thanks Mike, and thanks for applying it Bill!  One request in  
the future: please tweak your editor to not mess around with end-of-
line whitespace, so that the diff doesn't have extraneous gunk in it.  
Thanks!

-Chris

>
> Doing diffs in .:
> --- ./lib/AsmParser/LLLexer.cpp.~1~ 2007-12-14 22:09:06.000000000  
> -0800
> +++ ./lib/AsmParser/LLLexer.cpp 2007-12-15 13:02:47.000000000 -0800
> @@ -54,7 +54,7 @@ static uint64_t HexIntToVal(const char *
>       Result += C-'A'+10;
>     else if (C >= 'a' && C <= 'f')
>       Result += C-'a'+10;
> -
> +
>     if (Result < OldRes) {   // Uh, oh, overflow detected!!!
>       GenerateError("constant bigger than 64 bits detected!");
>       return 0;
> @@ -102,7 +102,7 @@ static void HexToIntPair(const char *Buf
> // appropriate character.
> static void UnEscapeLexed(std::string &Str) {
>   if (Str.empty()) return;
> -
> +
>   char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
>   char *BOut = Buffer;
>   for (char *BIn = Buffer; BIn != EndBuffer; ) {
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev