You copied the Doc URL to your clipboard.

Arm Compiler Migration and Compatibility Guide : Diagnostic messages

Diagnostic messages

In general, armclang provides more precise and detailed diagnostic messages compared to armcc. Therefore you can expect to see more information about your code when using Arm® Compiler 6, which can help you understand and fix your source more quickly.

armclang and armcc differ in the quality of diagnostic information they provide about your code. The following sections demonstrate some of the differences.

Assignment in condition

The following code is an example of armclang providing more precise information about your code. The error in this example is that the assignment operator, =, must be changed to the equality operator, ==.

main.cpp: 

#include <stdio.h>

int main() 
{
  int a = 0, b = 0;
  if (a = b) 
  {
    printf("Right\n");
  }
  else
  {
    printf("Wrong\n");
  }
  return 0;
}

Compiling this example with Arm Compiler 5 gives the message:

"main.cpp", line 6: Warning: #1293-D: assignment in condition
if (a = b)
    ^

Compiling this example with Arm Compiler 6 gives the message:

main.cpp:6:7: warning: using the result of an assignment as a condition without parentheses[-Wparentheses]
 if (a = b)
      ~^~

main.cpp:6:7: note: place parentheses around the assignment to silence this warning    
 if (a = b) 
       ^
      (  )

main.cpp:6:7: note: use '==' to turn this assignment into an equality comparison
 if (a = b) 
       ^    
       ==

armclang highlights the error in the code, and also suggests two different ways to resolve the error. The warning messages highlight the specific part which requires attention from the user.

Note

When using armclang, it is possible to enable or disable specific warning messages. In the example above, you can enable this warning message using the -Wparentheses option, or disable it using the -Wno-parentheses option.

Automatic macro expansion

Another very useful feature of diagnostic messages in Arm Compiler 6, is the inclusion of notes about macro expansion. These notes provide useful context to help you understand diagnostic messages resulting from automatic macro expansion.

Consider the following code:

main.cpp: 

#include <stdio.h>

#define LOG(PREFIX, MESSAGE) fprintf(stderr, "%s: %s", PREFIX, MESSAGE)
#define LOG_WARNING(MESSAGE) LOG("Warning", MESSAGE)

int main(void)
{
    LOG_WARNING(123);
}

The macro LOG_WARNING has been called with an integer argument. However, expanding the two macros, you can see that the fprintf function expects a string. When the macros are close together in the code it is easy to spot these errors. These errors are not easy to spot if they are defined in different part of the source code, or in other external libraries.

Compiling this example with Arm Compiler 5 armcc main.cpp gives the message:

main.cpp", line 8: Warning:  #181-D: argument is incompatible with corresponding format string conversion
      LOG_WARNING(123);
      ^

Compiling this example with Arm Compiler 6 armclang --target=arm-arm-none-eabi -march=armv8-a gives the message:

main.cpp:8:14: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
 LOG_WARNING(123);
 ~~~~~~~~~~~~^~~

main.cpp:4:45: note: expanded from macro 'LOG_WARNING'
#define LOG_WARNING(MESSAGE) LOG("Warning", MESSAGE)
                             ~~~~~~~~~~~~~~~^~~~~~~

main.cpp:3:64: note: expanded from macro 'LOG'
#define LOG(PREFIX, MESSAGE) fprintf(stderr, "%s: %s", PREFIX, MESSAGE)
                                                  ~~           ^~~~~~~

For more information, see Diagnostics for pragma compatibility.

Note

When starting the migration from Arm Compiler 5 to Arm Compiler 6, you can expect additional diagnostic messages because armclang does not recognize some of the pragmas, keywords, and attributes that were specific to armcc. When you replace the pragmas, keywords, and attributes from Arm Compiler 5 with their Arm Compiler 6 equivalents, the majority of these diagnostic messages disappear. You might require additional code changes if there is no direct equivalent for Arm Compiler 6. For more information see Chapter 4 Compiler Source Code Compatibility.
Was this page helpful? Yes No