Giter Club home page Giter Club logo

Comments (11)

mgudemann avatar mgudemann commented on July 22, 2024 1

Replacing '.' in the variable names will be necessary in java test case generation, as it is not allowed in java identfiers. Doing it already before would reduce work there, too.

from cbmc.

kroening avatar kroening commented on July 22, 2024

I have added regression/cbmc-java/recursion1 for this.

from cbmc.

tautschnig avatar tautschnig commented on July 22, 2024

I'm afraid recursion is still broken: see #163.

from cbmc.

mgudemann avatar mgudemann commented on July 22, 2024

tail recursion does work:

public class recursion1
{
  static int f(int n)
  {
    if(n <= 0)
      return 1;
    else
      return n * f(n-1);
  }

  static int g(int n, int acc)
  {
    if(n <= 0)
      return acc;
    else
      return g(n-1, n*acc);
  }

  public static void main(String[] args)
  {
    assert f(1)==1;
    assert g(1, 1) == 1;
  }
}

from cbmc.

smowton avatar smowton commented on July 22, 2024

Seems likely that the cause is Java locals not getting declared or added to the symtab (while temp variables are registered), so goto_symext::locality doesn't spot it as a thing to rename at inlining sites. However straightforwardly adding symbol registration and variable declaration in the same way as new_tmp_symbol doesn't seem to fix matters.

from cbmc.

smowton avatar smowton commented on July 22, 2024

Doh. ssa_exprt.h:73 assumes that identifiers can't contain periods, but Java package names do, leading to symbol identifiers like package.function::arg0, leading to a bad l1 object identifier and use of the wrong version of a variable.

Solutions:
(1) Escape Java package identifiers (I bet there are some sites looking for last-instance-of-period to find a class name that'll need finding and fixing)
(2) Allow periods in identifier names. Likely there are more places in the codebase that don't like them?

(1) sounds like marginally less pain. Put an assert in the symtab / symbol_exprt code to check for a legal name on registration / lookup.

In the meantime flipping #if 0 at line 67 results in correct behaviour. @kroening want to give an opinion of god on this?

Note that the fix for locality above is still required however, but it takes a slightly different test case to show it.

from cbmc.

smowton avatar smowton commented on July 22, 2024

smowton@48118d5: Local variable registration
smowton@3f8bab9: Workaround to tolerate Java IDs
smowton@75e46e8: Test case exhibiting need for local registration (otherwise int arg_copy gets overwritten by the recursive call)

from cbmc.

smowton avatar smowton commented on July 22, 2024

@mgudemann at the symtab level we'll need to use something illegal in Java IDs anyhow though, otherwise the uniqueing to avoid clashes between e.g. java_lang_Object_equals and a local that actually has that name will drive us insane

I won't make the change right now since I'm about to go on holiday and it'd seem rude to do it and leave everyone to find all the knock-on consequences, so for now just noting it needs doing :)

from cbmc.

smowton avatar smowton commented on July 22, 2024

Fixed in Cristina's test_gen branch

from cbmc.

smowton avatar smowton commented on July 22, 2024

@kroening having taken a fresh look at this today, possible options:

  • Mangle Java (and other language) names to remove syntactic ambiguity for struct member vs. namespace (i.e. s/./::/) (substantial cleanup of every instance using . to find the class/namespace boundary)
  • Change ssa_exprt::build_identifier to use a different character for the object/member boundary (less natural, risk of code assuming that . is used)
  • Change ssa_exprt::build_identifier to store the L1 object identifier, or its offset, as a separate attribute of ssa_exprt (extra memory usage)

Any preference?

from cbmc.

smowton avatar smowton commented on July 22, 2024

No comment being forthcoming, how about just doing this: https://github.com/smowton/cbmc/tree/ssa_l1_id

from cbmc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.