Sonar-scanner: '__malloc__' attribute takes no arguments

Must-share information (formatted with Markdown):

  • SonarQube 9.9 LTS
  • how is SonarQube deployed: Helm
  • what are you trying to achieve: run sonar-scanner on Ubuntu 22.04 without errors

I installed the new sonar-scanner 5.0.1 which said it has a lot of bugfixes on linux. We use GCC as compiler. The compile_commands reflect that.

When running sonar-scanner I get the message “‘__malloc__’ attribute takes no arguments” repeatedly. This is wrong, since for GCC the malloc attribute does have (optional) arguments.

This is additional to the “use of undeclared identifier __builtin_ia32_.*” warnings we got with the previous version 4.8, which still pop up btw. So if you have a solution for those now that would be great, too.

Hello @Carl,

Thank you for your feedback. Indeed, the clang’s front end does not support yet the attribute malloc with parameters.

I have created a ticket https://sonarsource.atlassian.net/browse/CPP-4686

I think it should be a benign warning and not influence the analysis, however.

As for missing __builtin_ia32_, they are internal GCC functions, and not all are supported.
I have added a ticket for following up on this [CPP-4687] - Jira

As far as I can tell, intrinsics declared inside headers like immintrin.h are more portable than using GCC’s builtins (which are more of an implementation detail), and clang even provides a script to do some of the changes. This would remove the errors and make the code more portable as a nice side effect, but I imagine this is far from a trivial change.

2 Likes

Thank you @aalvarez ,

Is there any way we can use immintrin.h only for analysis purposes? As you say these are just implementation details, but I don’t know how to replace them with something useful for analysis.

Best regards,

Carl

From what I see at Compiler Explorer, declaring a prototype for the builtins is safe for GCC (you still get the builtin), but it is still possible for the CFamily analyzer to get a valid AST that it can reason about.

It may be worth trying.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.