Menu ▾ ▴

#574 Newline in macro

closed-fixed
bug (5)
2024-06-30
2024-05-30
wanjibadan
No
#define G(r,i,a,b,c,d) \
    a += b + m[sigma[2*i+0]];  d ^= a; d = rotr32(d, 16);  c += d;  b ^= c; b = rotr32(b, 12); \
    a += b + m[sigma[2*i+1]];  d ^= a; d = rotr32(d,  8);  c += d;  b ^= c; b = rotr32(b,  7); \

#define R(r) \
    G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
    G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
    G(r,2,v[ 2],v[ 6],v[10],v[14]); \
    G(r,3,v[ 3],v[ 7],v[11],v[15]); \
    G(r,4,v[ 0],v[ 5],v[10],v[15]); \
    G(r,5,v[ 1],v[ 6],v[11],v[12]); \
    G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
    G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \

    {

after:

#define G(r,i,a,b,c,d) \
    a += b + m[sigma[2*i+0]];  d ^= a; d = rotr32(d, 16);  c += d;  b ^= c; b = rotr32(b, 12); \
    a += b + m[sigma[2*i+1]];  d ^= a; d = rotr32(d,  8);  c += d;  b ^= c; b = rotr32(b,  7); \
#define R(r) \
    G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
    G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
    G(r,2,v[ 2],v[ 6],v[10],v[14]); \
    G(r,3,v[ 3],v[ 7],v[11],v[15]); \
    G(r,4,v[ 0],v[ 5],v[10],v[15]); \
    G(r,5,v[ 1],v[ 6],v[11],v[12]); \
    G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
    G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
    {

fix for ver 3.4.16:
file: src\ASFormatter.cpp
find "if (currentLine.length() == 0)" in function

bool ASFormatter::getNextLine(bool emptyLineWasDeleted /*false*/)
    if (currentLine.length() == 0)
    {
        isInContinuedPreProc = false;
        currentLine = std::string(" ");        // a null is inserted if this is not done
    }

change to:

    if (currentLine.length() == 0)
    {
        if (!isInComment && previousNonWSChar == '\\')
        {
            isInPreprocessor = true;
            isInPreprocessorDefineDef = true;
            return false;
        }
        isInContinuedPreProc = false;
        currentLine = std::string(" ");        // a null is inserted if this is not done
    }

Discussion

  • André Simon

    André Simon - 2024-05-31
    • labels: --> bug
    • summary: a bug --> Newline in macro
    • status: open --> open-accepted
    • assigned_to: André Simon
     
  • André Simon

    André Simon - 2024-06-03

    Hi, could you please give a bit more context here (options)? I am not able to replicate this.

     
  • André Simon

    André Simon - 2024-06-03

    Ignore my last message, it happens when defined within a block.

     
  • André Simon

    André Simon - 2024-06-06

    Should be fixed in 3.5

     
  • wanjibadan

    wanjibadan - 2024-06-17
    AStyle.exe *.cpp *.h *.c --suffix=none --recursive --style=bsd --convert-tabs --indent=spaces=4 --attach-closing-while --indent-switches --indent-namespaces --indent-continuation=4 --indent-preproc-block --indent-preproc-define --indent-preproc-cond --indent-col1-comments --pad-oper --pad-paren-in --delete-empty-lines --align-pointer=name --align-reference=name --add-braces
    

    use the bat above formatting the following code will crash in 3.5

    /* XzCrc64.c -- CRC64 calculation
    2015-03-01 : Igor Pavlov : Public domain */
    
    #include "Precomp.h"
    
    #include "XzCrc64.h"
    #include "CpuArch.h"
    
    #define kCrc64Poly UINT64_CONST(0xC96C5795D7870F42)
    
    #ifdef MY_CPU_LE
    #define CRC_NUM_TABLES 4
    #else
    #define CRC_NUM_TABLES 5
    #define CRC_UINT64_SWAP(v) \
        | ((v >> 40) & ((UInt64)0xFF <<  8)) \
        | ((v >>  8) & ((UInt64)0xFF << 24)) \
        | ((v << 24) & ((UInt64)0xFF << 40)) \
        | ((v << 56)))
    
    UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4( UInt64 v, const void *data, size_t size, const UInt64 *table );
    #endif
    
    #ifndef MY_CPU_BE
    ( ( v >> 56 ) \
      | ( ( v >> 24 ) & ( ( UInt64 )0xFF << 16 ) ) \
      | ( ( v <<  8 ) & ( ( UInt64 )0xFF << 32 ) ) \
      | ( ( v << 40 ) & ( ( UInt64 )0xFF << 48 ) ) \
    
      UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4( UInt64 v, const void *data, size_t size, const UInt64 *table );
    #endif
    
    #ifndef MY_CPU_BE
        UInt64 MY_FAST_CALL XzCrc64UpdateT4( UInt64 v, const void *data, size_t size, const UInt64 *table );
    #endif
    
      typedef UInt64 ( MY_FAST_CALL *CRC_FUNC )( UInt64 v, const void *data, size_t size, const UInt64 *table );
    
      static CRC_FUNC g_Crc64Update;
      UInt64 g_Crc64Table[256 * CRC_NUM_TABLES];
    
      UInt64 MY_FAST_CALL Crc64Update( UInt64 v, const void *data, size_t size )
    {
        return g_Crc64Update( v, data, size, g_Crc64Table );
    }
    
    UInt64 MY_FAST_CALL Crc64Calc( const void *data, size_t size )
    {
        return g_Crc64Update( CRC64_INIT_VAL, data, size, g_Crc64Table ) ^CRC64_INIT_VAL;
    }
    
    void MY_FAST_CALL Crc64GenerateTable()
    {
        UInt32 i;
        for ( i = 0; i < 256; i++ )
        {
            UInt64 r = i;
            unsigned j;
            for ( j = 0; j < 8; j++ )
            {
                r = ( r >> 1 ) ^ ( kCrc64Poly & ~( ( r & 1 ) - 1 ) );
            }
            g_Crc64Table[i] = r;
        }
        for ( ; i < 256 * CRC_NUM_TABLES; i++ )
        {
            UInt64 r = g_Crc64Table[i - 256];
            g_Crc64Table[i] = g_Crc64Table[r & 0xFF] ^ ( r >> 8 );
        }
        #ifdef MY_CPU_LE
        g_Crc64Update = XzCrc64UpdateT4;
        #else
        {
            #ifndef MY_CPU_BE
            UInt32 k = 1;
            if ( *( const Byte * ) &k == 1 )
            {
                g_Crc64Update = XzCrc64UpdateT4;
            }
            else
            #endif
            {
                for ( i = 256 * CRC_NUM_TABLES - 1; i >= 256; i-- )
                {
                    UInt64 x = g_Crc64Table[i - 256];
                    g_Crc64Table[i] = CRC_UINT64_SWAP( x );
                }
                g_Crc64Update = XzCrc64UpdateT1_BeT4;
            }
        }
        #endif
    }
    

    simple fix

            //#574 avoid deletion of empüty lines after continuation
            if (!isInComment && previousNonWSChar == '\\')
            {
                return false;
            }
    

    change to

            //#574 avoid deletion of empüty lines after continuation
            if (!isInComment && previousNonWSChar == '\\')
            {
                isInPreprocessor = true;
                return false;
            }
    
     
  • André Simon

    André Simon - 2024-06-18

    I have applied this to 3.5.1. In the original version I have not encountered any problems so it was not clear why the other status variables should be changed. In case you use Win32 astyle there is a compiled version here:
    https://sourceforge.net/projects/astyle/files/astyle/beta/

     
    • wanjibadan

      wanjibadan - 2024-06-19

      I haven't studied the cause of this problem carefully. thanks to the author. This software is very useful.

       
  • André Simon

    André Simon - 2024-06-30
    • status: open-accepted --> closed-fixed
     

Log in to post a comment.