Skip to content

[CN-Exec] Invalid_argument("Bytes.create") during source injection #80

Closed

Description

@peterohanley-galois

You don't need the argument for b but you do need the increment on a.

int a;
void b(int x) { ++a; }
% cn test cred_in.c
cn: internal error, uncaught exception:
    Invalid_argument("Bytes.create")
    Raised by primitive operation at Stdlib.really_input_string in file "stdlib.ml", line 439, characters 10-26
    Called from Cn__Fulminate__Source_injection.move_to.aux in file "lib/fulminate/source_injection.ml", line 132, characters 10-49
    Called from Cn__Fulminate__Source_injection.inject in file "lib/fulminate/source_injection.ml", line 195, characters 18-78
... 8< ... 
% cn --version
git-da48cddb0-dirty [2025-04-15 17:09:21 +0100]

Activity

  1. peterohanley-galois commented on Apr 17, 2025

    @peterohanley-galois
    ContributorAuthor

    I tried to patch around it and I got this error:

    % cn test cred_in.c
    ./cred_in-exec.c:18:30: error: too few arguments provided to function-like macro invocation
       18 |    ++CN_STORE(CN_LOAD(a, ++a)); 
          |                              ^
    /Users/guso/.opam/default/lib/cn/runtime/include/cn-executable/utils.h:597:9: note: macro 'CN_STORE' defined here
      597 | #define CN_STORE(LV, X) CN_STORE_OP(LV, , X)
          |         ^
    ./cred_in-exec.c:18:6: error: use of undeclared identifier 'CN_STORE'
       18 |    ++CN_STORE(CN_LOAD(a, ++a)); 
          |      ^
    2 errors generated.
    

    It looks like this should first be written ++CN_STORE(CN_LOAD(a), ++a); and after a bit of comparison, second actually be CN_PREFIX(++,a); which doesn't exist yet.

  2. peterohanley-galois commented on Apr 17, 2025

    @peterohanley-galois
    ContributorAuthor

    Actually AIL doesn't have a Prefix construct and the AIL for this example is already rewritten to a = a + 1, so the error is in the templating

  3. peterohanley-galois commented on Apr 17, 2025

    @peterohanley-galois
    ContributorAuthor

    The approach of using bbox here

    let pos2, e = pos_bbox (loc_of_expr expr) in
    and slurping source from the input file is wrong for AIL expressions because they may contain synthesized terms.

    It doesn't always preserve comments anyway:

    int a;
    void b(int x) {
      // test
      a /* am I in here? */ ++ /*or me*/;
      a ++ // or me?
            ;
      // hello
    }
    
      // test
      CN_POSTFIX(a, ++) /*or me*/;
      CN_POSTFIX(a, ++) // or me?
            ;
      // hello
    
    
    
  4. peterohanley-galois commented on Apr 17, 2025

    @peterohanley-galois
    ContributorAuthor

    I have a hack that fixes this, I'll post it as a draft PR.

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