Skip to content

Sema: the "unsafe global access … single-thread proof" warning is located in whatever file was current (a <facade …> line) and fires on <c_import …> translations #1590

Closed

Description

@ehartford

Repro

A header with a mutable static written by an inline function, imported by a program that also declares a c facade (any resource):

// buf.h
static char err_buf[32] = "no error";
static inline int set_err(int code) { err_buf[0] = (char)('0' + code % 10); err_buf[1] = 0; return code; }
static inline const char *last_err(void) { return err_buf; }
use c_import("buf.h")
c facade x:
    fn last_err
        lend
fn main:
    print("ok")

with check prints:

warning: unsafe global access is currently covered by the single-thread proof; keep `unsafe` only if future concurrency is intended
 --> <facade x>:10:1
10 | 
  | ^^^^^^^^^^^^^^

Expected

Either no warning — the access is in the c_import translation of set_err, not in a user source; sema_path_is_user_lint_source treats <c_import …> translations as user lint sources — or a warning located at the access in <c_import buf.h>.

Actual

The span is read in whatever source file was current when the deferred pass ran (SemaCheck.w validate_global_data_race_accesses emits from recorded nodes without restoring each access's source context; with facades the last context is a rendered <facade …> file, so the location is an empty line of a synthetic file).

The pass already keeps each access's path (global_race_access_paths[i]); update_source_context_path(path) before the emit locates it. Found while writing the modeled C stage 7 fixtures (test/behavior/c_facade_text.h).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions