Giter Club home page Giter Club logo

Comments (5)

rcseacord avatar rcseacord commented on June 5, 2024 1

In the example, while the array is trivially copyable it is likely larger than 2 * sizeof(void*) which is an implementation-defined value so this clearly seems to be a false positive. A larger question is if this required rule should be enforced at all.

from codeql-coding-standards.

rcseacord avatar rcseacord commented on June 5, 2024

For background, this AUTOSAR rule seems poorly conceived. The rule is strictly a performance rule. The rule states that "passing an argument by value documents that the argument won't be modified" but unlike passing by reference to cost eliminates indirection in the function body. From a safety perspective, there is no real advantage in passing by value over passing by reference to const. I'm not sure enforcing this rule adds much if any value, and of course, changing code to comply with a rule always costs efforts and may introduce additional defects.

from codeql-coding-standards.

rcseacord avatar rcseacord commented on June 5, 2024

The enforcement guidance on which this rule is based "F.16: For β€œin” parameters, pass cheaply-copied types by value and others by reference to const" says:

  • (Simple) ((Foundation)) Warn when a parameter being passed by value has a size greater than 2 * sizeof(void*). Suggest using a reference to const instead.
  • (Simple) ((Foundation)) Warn when a parameter passed by reference to const has a size less than 2 * sizeof(void*). Suggest passing by value instead.
  • (Simple) ((Foundation)) Warn when a parameter passed by reference to const is moved.

This is fairly different enforcement from what we currently have.

from codeql-coding-standards.

jsinglet avatar jsinglet commented on June 5, 2024

Agreed @rcseacord. Testing locally the computed size is 20 bytes and the word size is 8 bytes. So since it is longer than 2 words it is not eligible to be passed by value (under this rule) so it is clearly a false positive, trivially copyable or not.

Some more notes on what needs to be fixed:

  • Needs to factor in definition of trivial to copy / identify the cases where that makes a difference.
  • The calculation of size needs a call to v.getType().stripType().getSize() to ensure that the correct size is begin calculated.

Example:
Calling getType().getSize() on const A8_4_7 &a847 will yield 8, when what is expected is 20.

  • Reference types are explicitly excluded in the query -- There is an edge case that was introduced (the catch block clause) but the exclusion of all reference types is too broad since some will need to be flagged. For example:
struct A { std::uint32_t a; };

void f1(const A &a){} // this should be flagged 

from codeql-coding-standards.

knewbury01 avatar knewbury01 commented on June 5, 2024

this might have been solved in this PR , will check

from codeql-coding-standards.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.