JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


LANG.STRUCT.ALIGNAS.IAS : Inconsistent Alignment Specifications

Summary

An object (variable or a field) is declared with multiple alignment specifications that are not consistent.

For the sake of this check:

This class is a strict subset of Use of Alignas.

See also Too Many Alignment Specifiers.

Properties

Class Name Inconsistent Alignment Specifications
Significance reliability
Mnemonic LANG.STRUCT.ALIGNAS.IAS
Categories
MisraC2025 MisraC2025:1.4 Emergent language features shall not be used
  MisraC2025:8.15 All declarations of an object with an explicit alignment specification shall specify the same alignment
MisraC2023 MisraC2023:1.4 Emergent language features shall not be used
  MisraC2023:8.15 All declarations of an object with an explicit alignment specification shall specify the same alignment
Misra2012 Misra2012:1.4 Emergent language features shall not be used
  Misra2012:8.15 All declarations of an object with an explicit alignment specification shall specify the same alignment
CERT-C CERT-C:MSC23-C Beware of vendor-specific library and language differences
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Inconsistent Alignment Specifications"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

/* LANG.STRUCT.ALIGNAS.IAS.c */

#include "LANG.STRUCT.ALIGNAS.IAS.h"

alignas(8) int hc_same_const;                        /* ('Use of Alignas' warning issued when enabled) */
alignas(4) int hc_diff_const;                        /* ('Use of Alignas' warning issued when enabled) */
alignas(2*4) int hc_same_const_exp;                  /* ('Use of Alignas' warning issued when enabled) */
int hc_one_spec;                                /* 'Inconsistent Alignment Specifications' warning issued here:
                                                 * - explicit alignment specified in .h file, but none here
                                                 */
alignas(4) int hc_type_const;                        /* ('Use of Alignas' warning issued when enabled) */
alignas(alignof(int)) int hc_type_alignof_type;      /* ('Use of Alignas' and 'Use of Alignof' warnings issued when enabled) */
/* LANG.STRUCT.ALIGNAS.IAS.h */

#include <stdalign.h>

extern alignas(8) int h_one_spec;                      /* ok: single declaration; single alignas specification
                                                        * ('Use of Alignas' warning issued when enabled)
                                                        */
extern alignas(8) alignas(4) int h_diff_const; /* 'Inconsistent Alignment Specifications' warning issued here
                                                * - two different alignments in the same declaration
                                                * ('Too Many Alignment Specifiers' and 'Use of Alignas' warnings
                                                * also issued when enabled)
                                                */
extern alignas(8) int hc_same_const;                   /* ok: alignment specified in .c file is 8
                                                        * ('Use of Alignas' warning issued when enabled)
                                                        */
extern alignas(8) int hc_diff_const;           /* 'Inconsistent Alignment Specifications' warning issued here
                                                * - alignment specified in .c file is 4
                                                * ('Use of Alignas' warning also issued when enabled)
                                                */
extern alignas(8) int hc_same_const_exp;               /* ok: alignment specified in .c file is 2*4 (==8)
                                                        * ('Use of Alignas' warning issued when enabled)
                                                        */
extern alignas(8) int hc_one_spec;

extern alignas(int) int hc_type_const;         /* 'Inconsistent Alignment Specifications' warning issued here
                                                * - alignment specified in .c file is 4
                                                * - a warning is issued even if the alignment of int is 4
                                                * ('Use of Alignas' warning also issued when enabled)
                                                */
extern alignas(int) int hc_type_alignof_type;  /* 'Inconsistent Alignment Specifications' warning issued here
                                                * - alignment specified in .c file is alignof(int)
                                                * ('Use of Alignas' warning also issued when enabled)
                                                */

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.