123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- // Copyright (c) 2020 Nordic Semiconductor ASA
- // SPDX-License-Identifer: Apache-2.0
- // Enforce preservation of const qualifier on config_info casts
- //
- // Drivers cast the device config_info pointer to a driver-specific
- // structure. The object is const-qualified; make sure the cast
- // doesn't inadvertently remove that qualifier.
- //
- // Also add the qualifier to pointer definitions where it's missing.
- //
- // Note that this patch may produce incorrect results if config_info
- // appears as a tag in non-device aggregate types.
- //
- // Options: --include-headers
- virtual patch
- virtual report
- // bare: (struct T*)E
- @r_cci_bare_patch
- depends on patch
- disable optional_qualifier
- @
- identifier T;
- expression E;
- @@
- (
- +const
- struct T*)E->config_info
- // bare const: (struct T* const)E
- @r_cci_bare_lc_patch
- depends on patch
- disable optional_qualifier
- @
- identifier T;
- expression E;
- @@
- (
- +const
- struct T * const)E->config_info
- // asg: struct T *D = (const struct T*)
- @r_cci_asg_patch
- depends on patch
- disable optional_qualifier
- @
- identifier T;
- identifier D;
- expression E;
- @@
- +const
- struct T * D = (const struct T*)E->config_info;
- // asg to const local: struct T * const D = (const struct T*)
- @r_cci_lc_asg_patch
- depends on patch
- disable optional_qualifier
- @
- identifier T;
- identifier D;
- expression E;
- @@
- +const
- struct T * const D = (const struct T*)E->config_info;
- // asg via macro: struct T * D = DEV_CFG()
- @r_cci_asg_macro_patch
- depends on patch
- disable optional_qualifier
- @
- identifier T;
- identifier D;
- expression E;
- @@
- +const
- struct T * D = DEV_CFG(E);
- // asg via macro to const local: struct T * const D = DEV_CFG()
- @r_cci_lc_asg_macro_patch
- depends on patch
- disable optional_qualifier
- @
- identifier T;
- identifier D;
- expression E;
- @@
- +const
- struct T * const D = DEV_CFG(E);
- // asg via macro: struct T * D; ... ; D = (const struct T*)CI;
- @r_cci_delayed_asg_patch
- depends on patch
- disable optional_qualifier
- @
- identifier T;
- identifier D;
- expression E;
- @@
- +const
- struct T * D;
- ...
- D = (const struct T*)E->config_info;
- // delayed asg via macro: struct T * D; ... ; D = DEV_CFG();
- @r_cci_delayed_asg_macro_patch
- depends on patch
- disable optional_qualifier
- @
- identifier T;
- identifier D;
- expression E;
- @@
- +const
- struct T * D;
- ...
- D = DEV_CFG(E);
- @r_cci_report
- depends on report
- disable optional_qualifier
- @
- identifier T;
- expression E;
- position p;
- @@
- (struct T*)E->config_info@p
- @script:python
- depends on report
- @
- t << r_cci_report.T;
- p << r_cci_report.p;
- @@
- msg = "WARNING: cast of config_info to struct {} requires 'const'".format(t)
- coccilib.report.print_report(p[0], msg)
|