@@ -5964,11 +5964,31 @@ fn (mut g Gen) expr(node_ ast.Expr) {
59645964 }
59655965 is_safe_inc := g.do_int_overflow_checks && node.op == .inc
59665966 is_safe_dec := g.do_int_overflow_checks && node.op == .dec
5967+ is_atomic_postfix := node.typ.has_flag (.atomic_f) && node.op in [.inc, .dec]
5968+ && g.pref.ccompiler_type != .msvc
59675969 g.inside_map_postfix = true
5968- if node.is_c2 v_prefix {
5970+ if is_atomic_postfix {
5971+ atomic_op := if node.op == .inc {
5972+ '__atomic_fetch_add'
5973+ } else {
5974+ '__atomic_fetch_sub'
5975+ }
5976+ atomic_value_styp := g.styp (node.typ.clear_flag (.atomic_f))
5977+ g.write ('${atomic_op }((${atomic_value_styp }*)&(' )
5978+ if node.expr.is_auto_deref_var () {
5979+ g.write ('*' )
5980+ }
5981+ g.expr (node.expr)
5982+ if node.typ.has_flag (.shared_f) {
5983+ g.write ('->val' )
5984+ }
5985+ g.write ('), 1, 5)' )
5986+ } else if node.is_c2 v_prefix {
59695987 g.write (node.op.str ())
59705988 }
5971- if node.expr.is_auto_deref_var () {
5989+ if is_atomic_postfix {
5990+ // already emitted above
5991+ } else if node.expr.is_auto_deref_var () {
59725992 g.write ('(*' )
59735993 g.expr (node.expr)
59745994 g.write (')' )
@@ -6023,7 +6043,9 @@ fn (mut g Gen) expr(node_ ast.Expr) {
60236043 }
60246044 }
60256045 g.inside_map_postfix = false
6026- if ! node.is_c2 v_prefix && node.op != .question && ! is_safe_inc && ! is_safe_dec {
6046+ if is_atomic_postfix {
6047+ // already emitted above
6048+ } else if ! node.is_c2 v_prefix && node.op != .question && ! is_safe_inc && ! is_safe_dec {
60276049 g.write (node.op.str ())
60286050 } else if is_safe_inc || is_safe_dec {
60296051 overflow_styp := g.styp (get_overflow_fn_type (node.typ))
@@ -12898,7 +12920,7 @@ return ${cast_shared_struct_str};
1289812920 }
1289912921 iin_idx := already_generated_mwrappers[interface_index_name] - iinidx_minimum_base + 1
1290012922 if g.pref.build_mode != .build_module {
12901- sb.writeln ('${ g . static_modifier }const u32 ${interface_index_name } = ${iin_idx };' )
12923+ sb.writeln ('enum { ${interface_index_name } = ${iin_idx } };' )
1290212924 } else {
1290312925 sb.writeln ('extern const u32 ${interface_index_name };' )
1290412926 }
@@ -13005,9 +13027,13 @@ fn (mut g Gen) panic_debug_info(pos token.Pos) (int, string, string, string) {
1300513027 return paline, pafile, pamod, pafn
1300613028}
1300713029
13030+ // get_guarded_include_text returns C preprocessor code that includes `iname`
13031+ // when available, or emits `imessage` through a C error otherwise.
1300813032pub fn get_guarded_include_text (iname string , imessage string ) string {
1300913033 res := '
13010- |#if defined(__has_include)
13034+ |#if defined(__TINYC__)
13035+ |#include ${iname }
13036+ |#elif defined(__has_include)
1301113037 |#if __has_include(${iname })
1301213038 |#include ${iname }
1301313039 |#else
@@ -13020,9 +13046,13 @@ pub fn get_guarded_include_text(iname string, imessage string) string {
1302013046 return res
1302113047}
1302213048
13049+ // get_inttypes_or_stdint_include_text returns C preprocessor code that includes
13050+ // the best available integer types header, or emits `imessage` otherwise.
1302313051pub fn get_inttypes_or_stdint_include_text (imessage string ) string {
1302413052 res := '
13025- |#if defined(__has_include)
13053+ |#if defined(__TINYC__)
13054+ |#include <stdint.h>
13055+ |#elif defined(__has_include)
1302613056 |#if __has_include(<inttypes.h>)
1302713057 |#include <inttypes.h>
1302813058 |#elif __has_include(<stdint.h>)
0 commit comments