@@ -184,8 +184,8 @@ def __init__(self, engine, module_name, target, function_map, object_map, type_m
184
184
self .tbaa_tree = self .llmodule .add_metadata ([
185
185
ll .MetaDataString (self .llmodule , "ARTIQ TBAA" )
186
186
])
187
- self .tbaa_noalias_call = self .llmodule .add_metadata ([
188
- ll .MetaDataString (self .llmodule , "non-aliasing function call" ),
187
+ self .tbaa_nowrite_call = self .llmodule .add_metadata ([
188
+ ll .MetaDataString (self .llmodule , "ref-only function call" ),
189
189
self .tbaa_tree ,
190
190
ll .Constant (lli64 , 1 )
191
191
])
@@ -401,6 +401,9 @@ def llbuiltin(self, name):
401
401
llglobal = ll .Function (self .llmodule , llty , name )
402
402
if name in ("__artiq_raise" , "__artiq_reraise" , "llvm.trap" ):
403
403
llglobal .attributes .add ("noreturn" )
404
+ if name in ("rtio_log" , "send_rpc" , "watchdog_set" , "watchdog_clear" ,
405
+ self .target .print_function ):
406
+ llglobal .attributes .add ("nounwind" )
404
407
else :
405
408
llglobal = ll .GlobalVariable (self .llmodule , llty , name )
406
409
@@ -1117,6 +1120,8 @@ def _prepare_ffi_call(self, insn):
1117
1120
byvals = [i + 1 for i in byvals ]
1118
1121
for i in byvals :
1119
1122
llfun .args [i ].add_attribute ('byval' )
1123
+ if 'nounwind' in insn .target_function ().type .flags :
1124
+ llfun .attributes .add ('nounwind' )
1120
1125
1121
1126
return llfun , list (llargs )
1122
1127
@@ -1282,14 +1287,14 @@ def process_Call(self, insn):
1282
1287
else :
1283
1288
llcall = llresult = self .llbuilder .call (llfun , llargs , name = insn .name )
1284
1289
1290
+ # Never add TBAA nowrite metadata to a functon with sret!
1291
+ # This leads to miscompilations.
1292
+ if types .is_c_function (functiontyp ) and 'nowrite' in functiontyp .flags :
1293
+ llcall .metadata ['tbaa' ] = self .tbaa_nowrite_call
1294
+
1285
1295
if insn .is_cold :
1286
1296
llcall .cconv = 'coldcc'
1287
1297
1288
- if types .is_c_function (functiontyp ):
1289
- # All our global state is confined to our compilation unit,
1290
- # so by definition no FFI call can mutate it.
1291
- llcall .metadata ['tbaa' ] = self .tbaa_noalias_call
1292
-
1293
1298
return llresult
1294
1299
1295
1300
def process_Invoke (self , insn ):
0 commit comments