cverif 0.0.7

Verifies that compiled machine code faithfully matches its C source
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
//! What the compiler that built the binary predefines.
//!
//! Real headers (the toolchain's own `stdint.h`, newlib, vendor SDKs) are written against
//! the compiler's predefined macros: the types behind `int32_t`, the limits, the compiler
//! family and version, the architecture.  The source must be read the way the compiler read
//! it, so these follow what the binary records about its build; `-D` and `-U` override them.

use crate::image::Image;

/// The compiler family and version (major, minor, patch).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum Compiler {
    #[default]
    Unknown,
    Gcc(u32, u32, u32),
    Clang(u32, u32, u32),
}

/// Target description for the preprocessor.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Target {
    pub compiler: Compiler,
    /// ARMv6-M or ARMv8-M Baseline: Thumb-1 only.
    pub thumb1: bool,
    /// `Tag_CPU_arch` of the build attributes, e.g. "v7E-M", when recorded.
    pub arch: Option<String>,
    /// Optimisation recorded in debug info: `Some(false)` for `-O0`.
    pub optimize: Option<bool>,
    pub optimize_size: bool,
    /// `-std=` recorded in debug info, as a `__STDC_VERSION__` value.
    pub stdc_version: Option<u32>,
    /// A hosted implementation (no `-ffreestanding` recorded).
    pub hosted: Option<bool>,
    pub hard_float: bool,
}

impl Target {
    /// What the source was read as, for the report: the image's own records decide which
    /// compiler's predefined macros the preprocessor provides, and so which branches of
    /// `#ifdef __clang__` and the like are verified.  Those records are not authenticated.
    pub fn describe(&self) -> String {
        let compiler = match self.compiler {
            Compiler::Unknown => "an unidentified compiler (GCC's macros)".to_string(),
            Compiler::Gcc(a, b, c) => format!("GCC {a}.{b}.{c}"),
            Compiler::Clang(a, b, c) => format!("clang {a}.{b}.{c}"),
        };
        let mut s = format!(
            "{compiler}, {}",
            self.arch
                .as_deref()
                .unwrap_or(if self.thumb1 { "Thumb-1" } else { "Thumb-2" })
        );
        match self.optimize {
            Some(false) => s.push_str(", not optimising"),
            Some(true) if self.optimize_size => s.push_str(", optimising for size"),
            Some(true) => s.push_str(", optimising"),
            None => {}
        }
        if let Some(v) = self.stdc_version {
            s.push_str(&format!(", __STDC_VERSION__ {v}"));
        }
        match self.hosted {
            Some(true) => s.push_str(", hosted (library functions keep their standard contracts)"),
            Some(false) => s.push_str(", freestanding"),
            None => {}
        }
        if self.hard_float {
            s.push_str(", hard float");
        }
        s
    }
}

/// Macros every ARM bare-metal compiler defines the same way, with GCC's choice of types.
const COMMON: &str = "\
#define __APCS_32__ 1\n\
#define __ARM_32BIT_STATE 1\n\
#define __ARM_SIZEOF_WCHAR_T 4\n\
#define __ATOMIC_ACQUIRE 2\n\
#define __ATOMIC_ACQ_REL 4\n\
#define __ATOMIC_CONSUME 1\n\
#define __ATOMIC_RELAXED 0\n\
#define __ATOMIC_RELEASE 3\n\
#define __ATOMIC_SEQ_CST 5\n\
#define __BIGGEST_ALIGNMENT__ 8\n\
#define __CHAR16_TYPE__ short unsigned int\n\
#define __CHAR32_TYPE__ long unsigned int\n\
#define __CHAR8_TYPE__ unsigned char\n\
#define __DBL_DECIMAL_DIG__ 17\n\
#define __DBL_DENORM_MIN__ ((double)4.9406564584124654e-324L)\n\
#define __DBL_DIG__ 15\n\
#define __DBL_EPSILON__ ((double)2.2204460492503131e-16L)\n\
#define __DBL_MANT_DIG__ 53\n\
#define __DBL_MAX_10_EXP__ 308\n\
#define __DBL_MAX_EXP__ 1024\n\
#define __DBL_MAX__ ((double)1.7976931348623157e+308L)\n\
#define __DBL_MIN_10_EXP__ (-307)\n\
#define __DBL_MIN_EXP__ (-1021)\n\
#define __DBL_MIN__ ((double)2.2250738585072014e-308L)\n\
#define __DBL_NORM_MAX__ ((double)1.7976931348623157e+308L)\n\
#define __DECIMAL_DIG__ 17\n\
#define __ELF__ 1\n\
#define __FINITE_MATH_ONLY__ 0\n\
#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__\n\
#define __FLT_DECIMAL_DIG__ 9\n\
#define __FLT_DENORM_MIN__ 1.4012984643248171e-45F\n\
#define __FLT_DIG__ 6\n\
#define __FLT_EPSILON__ 1.1920928955078125e-7F\n\
#define __FLT_EVAL_METHOD_TS_18661_3__ 0\n\
#define __FLT_EVAL_METHOD__ 0\n\
#define __FLT_MANT_DIG__ 24\n\
#define __FLT_MAX_10_EXP__ 38\n\
#define __FLT_MAX_EXP__ 128\n\
#define __FLT_MAX__ 3.4028234663852886e+38F\n\
#define __FLT_MIN_10_EXP__ (-37)\n\
#define __FLT_MIN_EXP__ (-125)\n\
#define __FLT_MIN__ 1.1754943508222875e-38F\n\
#define __FLT_NORM_MAX__ 3.4028234663852886e+38F\n\
#define __FLT_RADIX__ 2\n\
#define __GCC_ATOMIC_BOOL_LOCK_FREE 2\n\
#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2\n\
#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2\n\
#define __GCC_ATOMIC_CHAR8_T_LOCK_FREE 2\n\
#define __GCC_ATOMIC_CHAR_LOCK_FREE 2\n\
#define __GCC_ATOMIC_INT_LOCK_FREE 2\n\
#define __GCC_ATOMIC_LLONG_LOCK_FREE 1\n\
#define __GCC_ATOMIC_LONG_LOCK_FREE 2\n\
#define __GCC_ATOMIC_POINTER_LOCK_FREE 2\n\
#define __GCC_ATOMIC_SHORT_LOCK_FREE 2\n\
#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1\n\
#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2\n\
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1\n\
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1\n\
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1\n\
#define __GCC_IEC_559 0\n\
#define __GCC_IEC_559_COMPLEX 0\n\
#define __GXX_ABI_VERSION 1021\n\
#define __INT16_C(c) c\n\
#define __INT16_MAX__ 0x7fff\n\
#define __INT16_TYPE__ short int\n\
#define __INT32_C(c) c ## L\n\
#define __INT32_MAX__ 0x7fffffffL\n\
#define __INT64_C(c) c ## LL\n\
#define __INT64_MAX__ 0x7fffffffffffffffLL\n\
#define __INT64_TYPE__ long long int\n\
#define __INT8_C(c) c\n\
#define __INT8_MAX__ 0x7f\n\
#define __INT8_TYPE__ signed char\n\
#define __INTMAX_C(c) c ## LL\n\
#define __INTMAX_MAX__ 0x7fffffffffffffffLL\n\
#define __INTMAX_TYPE__ long long int\n\
#define __INTMAX_WIDTH__ 64\n\
#define __INTPTR_MAX__ 0x7fffffff\n\
#define __INTPTR_WIDTH__ 32\n\
#define __INT_FAST16_MAX__ 0x7fffffff\n\
#define __INT_FAST16_TYPE__ int\n\
#define __INT_FAST16_WIDTH__ 32\n\
#define __INT_FAST32_MAX__ 0x7fffffff\n\
#define __INT_FAST32_TYPE__ int\n\
#define __INT_FAST32_WIDTH__ 32\n\
#define __INT_FAST64_MAX__ 0x7fffffffffffffffLL\n\
#define __INT_FAST64_TYPE__ long long int\n\
#define __INT_FAST64_WIDTH__ 64\n\
#define __INT_FAST8_MAX__ 0x7fffffff\n\
#define __INT_FAST8_TYPE__ int\n\
#define __INT_FAST8_WIDTH__ 32\n\
#define __INT_LEAST16_MAX__ 0x7fff\n\
#define __INT_LEAST16_TYPE__ short int\n\
#define __INT_LEAST16_WIDTH__ 16\n\
#define __INT_LEAST32_MAX__ 0x7fffffffL\n\
#define __INT_LEAST32_TYPE__ long int\n\
#define __INT_LEAST32_WIDTH__ 32\n\
#define __INT_LEAST64_MAX__ 0x7fffffffffffffffLL\n\
#define __INT_LEAST64_TYPE__ long long int\n\
#define __INT_LEAST64_WIDTH__ 64\n\
#define __INT_LEAST8_MAX__ 0x7f\n\
#define __INT_LEAST8_TYPE__ signed char\n\
#define __INT_LEAST8_WIDTH__ 8\n\
#define __INT_WIDTH__ 32\n\
#define __LDBL_DECIMAL_DIG__ 17\n\
#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L\n\
#define __LDBL_DIG__ 15\n\
#define __LDBL_EPSILON__ 2.2204460492503131e-16L\n\
#define __LDBL_MANT_DIG__ 53\n\
#define __LDBL_MAX_10_EXP__ 308\n\
#define __LDBL_MAX_EXP__ 1024\n\
#define __LDBL_MAX__ 1.7976931348623157e+308L\n\
#define __LDBL_MIN_10_EXP__ (-307)\n\
#define __LDBL_MIN_EXP__ (-1021)\n\
#define __LDBL_MIN__ 2.2250738585072014e-308L\n\
#define __LDBL_NORM_MAX__ 1.7976931348623157e+308L\n\
#define __LONG_LONG_WIDTH__ 64\n\
#define __LONG_WIDTH__ 32\n\
#define __ORDER_PDP_ENDIAN__ 3412\n\
#define __PTRDIFF_MAX__ 0x7fffffff\n\
#define __PTRDIFF_WIDTH__ 32\n\
#define __REGISTER_PREFIX__ \n\
#define __SCHAR_MAX__ 0x7f\n\
#define __SCHAR_WIDTH__ 8\n\
#define __SHRT_MAX__ 0x7fff\n\
#define __SHRT_WIDTH__ 16\n\
#define __SIG_ATOMIC_MAX__ 0x7fffffff\n\
#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)\n\
#define __SIG_ATOMIC_TYPE__ int\n\
#define __SIG_ATOMIC_WIDTH__ 32\n\
#define __SIZEOF_DOUBLE__ 8\n\
#define __SIZEOF_FLOAT__ 4\n\
#define __SIZEOF_LONG_DOUBLE__ 8\n\
#define __SIZEOF_PTRDIFF_T__ 4\n\
#define __SIZEOF_WCHAR_T__ 4\n\
#define __SIZEOF_WINT_T__ 4\n\
#define __SIZE_MAX__ 0xffffffffU\n\
#define __SIZE_WIDTH__ 32\n\
#define __THUMBEL__ 1\n\
#define __UINT16_C(c) c\n\
#define __UINT16_MAX__ 0xffff\n\
#define __UINT16_TYPE__ short unsigned int\n\
#define __UINT32_C(c) c ## UL\n\
#define __UINT32_MAX__ 0xffffffffUL\n\
#define __UINT64_C(c) c ## ULL\n\
#define __UINT64_MAX__ 0xffffffffffffffffULL\n\
#define __UINT64_TYPE__ long long unsigned int\n\
#define __UINT8_C(c) c\n\
#define __UINT8_MAX__ 0xff\n\
#define __UINT8_TYPE__ unsigned char\n\
#define __UINTMAX_C(c) c ## ULL\n\
#define __UINTMAX_MAX__ 0xffffffffffffffffULL\n\
#define __UINTMAX_TYPE__ long long unsigned int\n\
#define __UINTPTR_MAX__ 0xffffffffU\n\
#define __UINT_FAST16_MAX__ 0xffffffffU\n\
#define __UINT_FAST16_TYPE__ unsigned int\n\
#define __UINT_FAST32_MAX__ 0xffffffffU\n\
#define __UINT_FAST32_TYPE__ unsigned int\n\
#define __UINT_FAST64_MAX__ 0xffffffffffffffffULL\n\
#define __UINT_FAST64_TYPE__ long long unsigned int\n\
#define __UINT_FAST8_MAX__ 0xffffffffU\n\
#define __UINT_FAST8_TYPE__ unsigned int\n\
#define __UINT_LEAST16_MAX__ 0xffff\n\
#define __UINT_LEAST16_TYPE__ short unsigned int\n\
#define __UINT_LEAST32_MAX__ 0xffffffffUL\n\
#define __UINT_LEAST32_TYPE__ long unsigned int\n\
#define __UINT_LEAST64_MAX__ 0xffffffffffffffffULL\n\
#define __UINT_LEAST64_TYPE__ long long unsigned int\n\
#define __UINT_LEAST8_MAX__ 0xff\n\
#define __UINT_LEAST8_TYPE__ unsigned char\n\
#define __USER_LABEL_PREFIX__ \n\
#define __VFP_FP__ 1\n\
#define __WCHAR_MAX__ 0xffffffffU\n\
#define __WCHAR_MIN__ 0U\n\
#define __WCHAR_TYPE__ unsigned int\n\
#define __WCHAR_WIDTH__ 32\n\
#define __WINT_MAX__ 0xffffffffU\n\
#define __WINT_MIN__ 0U\n\
#define __WINT_TYPE__ unsigned int\n\
#define __WINT_WIDTH__ 32\n\
";

/// Where clang's choices differ from GCC's (also used when the compiler is unknown, as the
/// built-in headers always did: `int32_t` is `int`).
const CLANG_TYPES: &str = "\
#define __INT32_TYPE__ int\n\
#define __UINT32_TYPE__ unsigned int\n\
#define __INT_LEAST32_TYPE__ int\n\
#define __UINT_LEAST32_TYPE__ unsigned int\n\
#define __INT32_MAX__ 2147483647\n\
#define __UINT32_MAX__ 4294967295U\n\
#define __INT_LEAST32_MAX__ 2147483647\n\
#define __UINT_LEAST32_MAX__ 4294967295U\n\
#define __INT32_C(c) c\n\
#define __UINT32_C(c) c ## U\n\
#define __INT_FAST8_TYPE__ signed char\n\
#define __UINT_FAST8_TYPE__ unsigned char\n\
#define __INT_FAST8_MAX__ 127\n\
#define __UINT_FAST8_MAX__ 255\n\
#define __INT_FAST8_WIDTH__ 8\n\
#define __INT_FAST16_TYPE__ short\n\
#define __UINT_FAST16_TYPE__ unsigned short\n\
#define __INT_FAST16_MAX__ 32767\n\
#define __UINT_FAST16_MAX__ 65535\n\
#define __INT_FAST16_WIDTH__ 16\n\
#define __CHAR32_TYPE__ unsigned int\n\
#define __WINT_TYPE__ int\n\
#define __WINT_MAX__ 2147483647\n\
#define __WINT_MIN__ (-__WINT_MAX__ - 1)\n";

/// The first `a.b.c` version number in `s`.
fn version(s: &str) -> Option<(u32, u32, u32)> {
    s.split(|c: char| !(c.is_ascii_digit() || c == '.')).find_map(|w| {
        let mut it = w.split('.');
        let v = (
            it.next()?.parse().ok()?,
            it.next()?.parse().ok()?,
            it.next()?.parse().ok()?,
        );
        it.next().is_none().then_some(v)
    })
}

fn compiler_of(text: &str) -> Compiler {
    if let Some(i) = text.find("clang version ") {
        return match version(&text[i..]) {
            Some((a, b, c)) => Compiler::Clang(a, b, c),
            None => Compiler::Unknown,
        };
    }
    // ".comment": "GCC: (vendor text) 13.2.1 20231009"; producer: "GNU C17 13.2.1 20231009 -mcpu=...".
    let rest = if let Some(i) = text.find("GCC: (") {
        text[i..].split_once(')').map(|x| x.1)
    } else if let Some(i) = text.find("GNU C") {
        text[i + 5..].split_once(' ').map(|x| x.1)
    } else {
        None
    };
    match rest.and_then(version) {
        Some((a, b, c)) => Compiler::Gcc(a, b, c),
        None => Compiler::Unknown,
    }
}

impl Target {
    /// What the binary records about the compiler and options that built it.
    pub fn for_image(image: &Image) -> Target {
        let mut t = Target {
            hard_float: image.hard_float,
            ..Target::default()
        };
        // Debug info describes the compilation of the user's code; `.comment` may also name
        // the compiler of a library that was linked in.
        let texts = image.producer.iter().chain(&image.meta.producers).chain(&image.comment);
        for text in texts {
            if t.compiler == Compiler::Unknown {
                t.compiler = compiler_of(text);
            }
        }
        let flags: Vec<&str> = image
            .producer
            .iter()
            .chain(&image.meta.producers)
            .filter(|p| p.contains(" -"))
            .flat_map(|p| p.split_whitespace())
            .collect();
        for f in &flags {
            match *f {
                "-O0" => t.optimize = Some(false),
                "-Os" | "-Oz" => (t.optimize, t.optimize_size) = (Some(true), true),
                "-O" | "-O1" | "-O2" | "-O3" | "-Og" | "-Ofast" => (t.optimize, t.optimize_size) = (Some(true), false),
                _ => {}
            }
            if let Some(std) = f.strip_prefix("-std=") {
                t.stdc_version = stdc_version(std.trim_start_matches("gnu").trim_start_matches('c'));
            }
        }
        // Freestanding only if every unit that records its flags was built that way: one
        // producer string is not known to be the one of the unit being read.
        let mut recorded = (image.producer.iter().chain(&image.meta.producers)).filter(|p| p.contains(" -"));
        if !flags.is_empty() {
            t.hosted = Some(!recorded.all(|p| {
                p.split_whitespace()
                    .any(|f| f == "-ffreestanding" || f == "-fno-builtin")
            }));
        }
        // GCC names the language in the producer string even without -std: "GNU C99 ...".
        if t.stdc_version.is_none() {
            t.stdc_version = image
                .producer
                .iter()
                .chain(&image.meta.producers)
                .find_map(|p| p.strip_prefix("GNU C"))
                .and_then(|r| stdc_version(r.split(' ').next().unwrap_or("")));
        }
        let attrs = crate::detect::build_attributes(&image.meta.attributes);
        t.arch = attrs.iter().find(|a| a.0 == "Tag_CPU_arch").map(|a| a.1.clone());
        t.thumb1 = matches!(t.arch.as_deref(), Some("v6-M" | "v6S-M" | "v8-M.baseline"));
        t
    }

    /// The predefined macros of this target, as preprocessor text.
    pub fn predefines(&self) -> String {
        use std::fmt::Write;
        let mut o = String::from(COMMON);
        let mut def = |name: &str, value: &dyn std::fmt::Display| {
            let _ = writeln!(o, "#undef {name}\n#define {name} {value}");
        };
        match self.compiler {
            Compiler::Gcc(a, b, c) => {
                def("__GNUC__", &a);
                def("__GNUC_MINOR__", &b);
                def("__GNUC_PATCHLEVEL__", &c);
                def("__VERSION__", &format_args!("\"{a}.{b}.{c}\""));
                def("__GNUC_STDC_INLINE__", &1);
                def("__INT32_TYPE__", &"long int");
                def("__UINT32_TYPE__", &"long unsigned int");
            }
            Compiler::Clang(a, b, c) => {
                def("__clang__", &1);
                def("__clang_major__", &a);
                def("__clang_minor__", &b);
                def("__clang_patchlevel__", &c);
                def("__clang_version__", &format_args!("\"{a}.{b}.{c} \""));
                def("__VERSION__", &format_args!("\"Clang {a}.{b}.{c}\""));
                def("__GNUC__", &4);
                def("__GNUC_MINOR__", &2);
                def("__GNUC_PATCHLEVEL__", &1);
                def("__GNUC_STDC_INLINE__", &1);
            }
            Compiler::Unknown => {}
        }
        if !matches!(self.compiler, Compiler::Gcc(..)) {
            for line in CLANG_TYPES.lines() {
                let name = line["#define ".len()..].split([' ', '(']).next().unwrap_or("");
                let _ = writeln!(o, "#undef {name}\n{line}");
            }
        }
        let mut def = |name: &str, value: &dyn std::fmt::Display| {
            let _ = writeln!(o, "#undef {name}\n#define {name} {value}");
        };
        if self.optimize != Some(false) && self.compiler != Compiler::Unknown {
            def("__OPTIMIZE__", &1);
            if self.optimize_size {
                def("__OPTIMIZE_SIZE__", &1);
            }
        }
        if let Some(v) = self.stdc_version {
            def("__STDC_VERSION__", &format_args!("{v}L"));
        }
        if let Some(h) = self.hosted {
            def("__STDC_HOSTED__", &(h as u32));
        }
        if self.hard_float {
            def("__ARM_PCS_VFP", &1);
        } else {
            def("__SOFTFP__", &1);
            def("__ARM_PCS", &1);
        }
        def("__ARM_ARCH_PROFILE", &77);
        if self.thumb1 {
            let _ = writeln!(o, "#undef __thumb2__");
        }
        let mut def = |name: &str, value: &dyn std::fmt::Display| {
            let _ = writeln!(o, "#undef {name}\n#define {name} {value}");
        };
        def("__ARM_ARCH_ISA_THUMB", &(if self.thumb1 { 1 } else { 2 }));
        match self.arch.as_deref() {
            Some("v6-M" | "v6S-M") => {
                def("__ARM_ARCH", &6);
                def("__ARM_ARCH_6M__", &1);
            }
            Some("v7") => {
                def("__ARM_ARCH", &7);
                def("__ARM_ARCH_7M__", &1);
            }
            Some("v7E-M") => {
                def("__ARM_ARCH", &7);
                def("__ARM_ARCH_7EM__", &1);
            }
            Some("v8-M.baseline") => {
                def("__ARM_ARCH", &8);
                def("__ARM_ARCH_8M_BASE__", &1);
            }
            Some("v8-M.mainline" | "v8.1-M.mainline") => {
                def("__ARM_ARCH", &8);
                def("__ARM_ARCH_8M_MAIN__", &1);
            }
            _ => {}
        }
        o
    }
}

fn stdc_version(std: &str) -> Option<u32> {
    Some(match std {
        "89" | "90" => return None,
        "99" | "9x" => 199901,
        "11" | "1x" => 201112,
        "17" | "18" => 201710,
        "23" | "2x" => 202311,
        _ => return None,
    })
}