0

I have following c++ code for an embedded system:

//LIBRARY code:

typedef struct {                                    /*!< (@ 0x48028100) PORT1 Structure                                        */
  __IO uint32_t  OUT;                               /*!< (@ 0x48028100) Port 1 Output Register                                 */
  __O  uint32_t  OMR;                               /*!< (@ 0x48028104) Port 1 Output Modification Register                    */
  __I  uint32_t  RESERVED[2];
  __IO uint32_t  IOCR0;                             /*!< (@ 0x48028110) Port 1 Input/Output Control Register 0                 */
  __IO uint32_t  IOCR4;                             /*!< (@ 0x48028114) Port 1 Input/Output Control Register 4                 */
  __IO uint32_t  IOCR8;                             /*!< (@ 0x48028118) Port 1 Input/Output Control Register 8                 */
  __IO uint32_t  IOCR12;                            /*!< (@ 0x4802811C) Port 1 Input/Output Control Register 12                */
  __I  uint32_t  RESERVED1;
  __I  uint32_t  IN;                                /*!< (@ 0x48028124) Port 1 Input Register                                  */
  __I  uint32_t  RESERVED2[6];
  __IO uint32_t  PDR0;                              /*!< (@ 0x48028140) Port 1 Pad Driver Mode 0 Register                      */
  __IO uint32_t  PDR1;                              /*!< (@ 0x48028144) Port 1 Pad Driver Mode 1 Register                      */
  __I  uint32_t  RESERVED3[6];
  __I  uint32_t  PDISC;                             /*!< (@ 0x48028160) Port 1 Pin Function Decision Control Register          */
  __I  uint32_t  RESERVED4[3];
  __IO uint32_t  PPS;                               /*!< (@ 0x48028170) Port 1 Pin Power Save Register                         */
  __IO uint32_t  HWSEL;                             /*!< (@ 0x48028174) Port 1 Pin Hardware Select Register                    */
} PORT1_Type;

#define PORT1_BASE                      0x48028100UL
#define PORT1                           ((PORT1_Type              *) PORT1_BASE)

// MY MINIMAL EXAMPLE CODE:
...
uint32_t u32SourceAddress = (uint32_t)(&(PORT1->IN)), // error: expected unqualified-id
                                              //  ^
...

This code works just fine when I compile it with GCC or ARMCC. When I use clang-tidy, I get an error: expected unqualified-id [clang-diagnostic-error] on it. What am I doing wrong and how can I fix it?

Thanks, Moritz

edit: Added comments regarding library based code and my code.

Moritz
  • 41
  • 4
  • 1
    Looks a lot more like C than C++. – sweenish Nov 04 '20 at 13:41
  • Any reason why you not make `u32SourceAddress` a `uint32_t*`? – Ted Lyngmo Nov 04 '20 at 13:41
  • @sweenish yeah :/ that's the problem with the libraries of the BSP. The higher layers of the code is pretty much c++ @TedLyngmo yes, because the address is later on assigned to another register. ``` GPDMA0_CH_TypeDef* m_pChannel->SAR = u32SourceAddress``` – Moritz Nov 04 '20 at 13:51
  • 1
    Are `__I`/`__IO`/`__O` compiler intrinsics? If so, it's possible that `clang-tidy` doesn't understand what those prefixes are, and thus improperly parsed the `struct` definition resulting in `IN` being seen as an invalid name. You might be able to fix this by explicitly defining those symbols to be empty during the `clang-tidy` pass, e.g. by passing `-D__I= -D__O= -D__IO=` – Human-Compiler Nov 04 '20 at 14:14
  • Thanks for the idea @Human-Compiler, but `__I`/`__IO`/`__O` are no compiler intrinsics and are already defined within [CMSIS/core_cm4.h](https://github.com/ARM-software/CMSIS/blob/master/CMSIS/Include/core_cm4.h#L265) – Moritz Nov 04 '20 at 14:33
  • @Moritz One other thought: is `IN` for some reason defined with `clang-tidy`? I have seen some cases of things like `IN` and `OUT` being defined to nothing being used to "document" in and out parameters; so I'm wondering if `clang-tidy` for some reason sees this already defined (possibly a conditional compilation path causing it to be added). If that's the case, an `#undef` might fix this issue (and in which case, you might need to choose a different name). – Human-Compiler Nov 04 '20 at 15:58
  • @Human-Compiler This seems to work. I renamed "IN" to "IN1" for experimental purposes and it compiles. This seems to resolve the problem. Thank you! – Moritz Nov 05 '20 at 08:27
  • Unfortunately the "IN" is declared within the BSP library headers, which I don't want to edit. Is there maybe another way to work around this? – Moritz Nov 05 '20 at 08:28
  • @Moritz Just hardcode it in your makefile where `clang-tidy` is executed. You _should **not**_ remove `volatile` when actually compiling the program. – Ted Lyngmo Nov 05 '20 at 12:01
  • I overread the idea of using `#undef IN`. This actually worked. – Moritz Nov 05 '20 at 13:27

0 Answers0