Home Dashboard Directory Help
Search

Macro Compile Error by baexps_pr1


Status: 

Closed
 as By Design Help for as By Design


1
0
Sign in
to vote
Type: Bug
ID: 780128
Opened: 2/27/2013 9:10:12 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

Unable to Compile the following code snippet :
------------------------------------------------------------------------------
#include <stdio.h>

#define FALSE 0
#define TRUE !FALSE

typedef unsigned int unsigned32_T;
typedef unsigned short int unsigned16_T;
typedef unsigned32_T u32_fixed_point_T;

typedef unsigned16_T u18pm2_T;     /* bbbbbbbbbbbbbbbb00.0 */
#define BPP_u18pm2_T -2
#define SIGNED_u18pm2_T FALSE

#define Init_Fixed_Point(value, to_type) \
( \
( (BPP_##to_type) >= 0U ) ? \
     ( ( (value) >= 0U ) ? \
         ( (SIGNED_##to_type) ? \
            ( ( (value) >= ( ( ( (u32_fixed_point_T)1U << ( 8U*sizeof(to_type)-1U ) ) - 1.0 ) / ( (u32_fixed_point_T)1U << (BPP_##to_type) ) ) ) ? \
             /* return max. signed counts on overflow for signed type */ \
             ( (to_type)( ( (to_type)1U << ( 8U*sizeof(to_type)-1U ) ) - 1 ) ): \
             ( (to_type)( ( (value) * ( (u32_fixed_point_T)1U << (BPP_##to_type) ) ) + 0.5 ) ) \
            ): \
            ( ( (value) >= ( ( (to_type)0xFFFFFFFFU + 0.0 ) / ( (u32_fixed_point_T)1U << (BPP_##to_type) ) ) ) ? \
             /* "+ 0.0" in above expression to force decimal arithmetic to get engineering limit */ \
             /* return max. unsigned counts on overflow for unsigned type */ \
             ( (to_type)0xFFFFFFFFU ): \
             ( (to_type)( ( (value) * ( (u32_fixed_point_T)1 << (BPP_##to_type) ) ) + 0.5 ) ) \
            ) \
         ): \
         ( (SIGNED_##to_type) ? \
            ( ( (value) <= -( ( ( (u32_fixed_point_T)1U << ( 8U*sizeof(to_type)-1U ) ) + 0.0 ) / ( (u32_fixed_point_T)1U << (BPP_##to_type) ) ) )? \
             /* "+ 0.0" in above expression to force decimal arithmetic to get engineering limit */ \
             /* return min. signed counts on underflow for signed type */ \
             ( (to_type)( -( (to_type)1U << ( 8U*sizeof(to_type)-1U ) ) ) ): \
             ( (to_type)( (double)(value)* ( (u32_fixed_point_T)1U << (BPP_##to_type) ) - 0.5) ) \
            ): \
            /* return min. unsigned counts on underflow for unsigned type */ \
            ((to_type)0U) \
         ) \
     ): \
     ( ( (value) >= 0U ) ? \
         ( (SIGNED_##to_type) ? \
            ( ( (value) >= ( ( ( (u32_fixed_point_T)1U << ( 8U*sizeof(to_type)-1U ) ) - 1U ) * ( (u32_fixed_point_T)1U << ( -(BPP_##to_type) ) ) ) ) ? \
             /* return max. signed counts on overflow for signed type */ \
             ( (to_type)( ( (to_type)1U << ( 8U*sizeof(to_type)-1U ) ) - 1U ) ): \
             ( (to_type)( ( ( (value) * ( 0x00010000U >> ( -(BPP_##to_type) ) ) ) + 32768U ) / 65536U ) ) \
            ): \
            ( ( (value) >= ( ( (to_type)0xFFFFFFFFU ) * ( (u32_fixed_point_T)1U << ( -(BPP_##to_type) ) ) ) ) ? \
             /* return max. unsigned counts on overflow for unsigned type */ \
             ( (to_type)0xFFFFFFFFU ): \
             ( (to_type)( /* ( ( (u32_fixed_point_T)(value) * ( 0x00010000U >> ( -(BPP_##to_type) ) ) ) + 32768 ) */ 1U /* / 65536 */ ) ) \
            ) \
         ): \
         ( (SIGNED_##to_type) ? \
            ( ( ( (signed int)( ( (value) / ( ( 1U << ( -(BPP_##to_type) ) ) + 0.0 ) ) - ( -( 1U << ( 8U*sizeof(to_type)-1U ) ) ) ) ) <= 0U ) ? \
             /* return min. signed counts on underflow for signed type */ \
             ( (to_type)( -( (to_type)1U << ( 8U*sizeof(to_type)-1U ) ) ) ): \
             ( (to_type)( ( ( (value) * ( 0x00010000U >> ( -(BPP_##to_type) ) ) ) - 32768U ) / 65536U ) ) \
            ): \
            /* return min. unsigned counts on underflow for unsigned type */ \
            ((to_type)0U) \
         ) \
     ) \
)



#define MAX_T_DELTA             Init_Fixed_Point( 262140U, u18pm2_T )

int volatile test_data = 5;

void main(void)
{

printf("Hello World\n");

if (test_data > MAX_T_DELTA)
{
     printf("Data Error\n");
}
}



--------------------------------------------------------
Details
Sign in to post a comment.
Posted by baexps_pr1 on 3/16/2013 at 7:36 PM
Hello Support,

Sorry for the wrong comment in the last mail.
Ignore my last comment.

So within C standard, during the First phase of constant folding within Compile Phase, the non-executable code is checked for NEGATIVE SHIFT even though CPU will never see that code due to CONSTANT FOLDING of the expression.

Thank you.
Regards
Posted by baexps_pr1 on 3/16/2013 at 7:11 PM
Hello Support,
Shift bit is not negative.
It is -(-2) = 2 during the [preprocessor phase].

Can you please tell me which line during the Preprocessor phase is becoming NEGATIVE SHIFT?

Thank you.
Regards
Posted by Microsoft on 3/12/2013 at 2:45 PM
Hi,
    Thanks for reporting the issue.
    It is by design. Accordong to the standard, the shift bits should be non-negative (even if the code is unreachable), otherwise the behavior is undefined. For example,

int main()
{
    (-2 > 0) ? 1 / (1 << -2) : 0;
}
Posted by Microsoft on 2/27/2013 at 10:58 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 2/27/2013 at 9:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
compile.zip 2/27/2013 1 KB