[llvm-bugs] [Bug 45711] New: AUTOSAR rules for range loops

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 28 05:25:28 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45711

            Bug ID: 45711
           Summary: AUTOSAR rules for range loops
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: michael.krasnyk at gmail.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

Hello,


i am working on a project that uses clang and an AUTOSAR compliance tool.
I would like to file not a bug but an issue that two AUTOSAR rules are
counter-exclusive for code generated by llvm.

Namely,

Rule A6-5-1 (required, implementation, automated)
A for-loop that loops through all elements of the container and does not use
its loop-counter shall not be used.

The rules implies that following code has to be used

#include <vector>

void f(std::vector<int> values)
{
    for (auto value : values)
    {

    }
}

The clang generates the following code

#include <vector>

void f(std::vector<int, std::allocator<int> > values)
{
  {
    std::vector<int, std::allocator<int> > & __range1 = values;
    __gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int> >
> __begin1 = __range1.begin();
    __gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int> >
> __end1 = __range1.end();
    for(; __gnu_cxx::operator!=(__begin1, __end1); __begin1.operator++())
    {
      int value = __begin1.operator*();
    }

  }
}

and the AUTOSAR compliance tool shows violations of another rule

Rule A8-5-2 (required, implementation, automated)
Braced-initialization {}, without equals sign, shall be used for variable
initialization

as AUTOSAR C++14 Declarators (AUTOSAR C++14 A8-5-2)1.
autosar_cpp14_a8_5_2_violation: Initializing variable __range1 without using
braced-initialization {}.

Would it be beneficial for llvm to change implementation of initialization of
__range, __begin, __end in range-based loops in Sema::ActOnCXXForRangeStmt from

T & ref = object ;

to

T & ref { object } ;

so the code above will be

      std::vector<int, std::allocator<int> > & __range1{values};
      __gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int>
> > __begin1{__range1.begin()};
      __gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int>
> > __end1{__range1.end()};


Regards,
Michael Krasnyk

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200428/76f9cbb9/attachment-0001.html>


More information about the llvm-bugs mailing list