GithubHelp home page GithubHelp logo

Comments (5)

marco-c avatar marco-c commented on June 3, 2024

Yep, this is probably a bug in the C grammar (maybe related to the preprocessor stuff).

Are you able to reduce the test case to the minimum?

from rust-code-analysis.

MartinLwx avatar MartinLwx commented on June 3, 2024

Yep, this is probably a bug in the C grammar (maybe related to the preprocessor stuff).

Are you able to reduce the test case to the minimum?

I made some revisions to the code by removing certain preprocessor parts and code lines. I'm not entirely certain if this was the correct approach, but I hope that it will be helpful.

static YYACTIONTYPE
yy_find_shift_action(YYCODETYPE iLookAhead, /* The look-ahead token */
                     YYACTIONTYPE stateno   /* Current state number */
) {
  do {
    if (i >= YY_NLOOKAHEAD || yy_lookahead[i] != iLookAhead) {
#ifdef YYWILDCARD
      {
        if (
#if YY_SHIFT_MAX + YYWILDCARD >= YY_ACTTAB_COUNT
            j < YY_ACTTAB_COUNT &&
#endif
            j < (int)(sizeof(yy_lookahead) / sizeof(yy_lookahead[0])) &&
            yy_lookahead[j] == YYWILDCARD && iLookAhead > 0) {
#ifndef NDEBUG
          if (yyTraceFILE) {
            fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", yyTracePrompt,
                    yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]);
          }
#endif /* NDEBUG */
          return yy_action[j];
        }
      }
#endif /* YYWILDCARD */
      return yy_default[stateno];
    }
  } while (1);
}

from rust-code-analysis.

marco-c avatar marco-c commented on June 3, 2024

Are you sure this is the minimum amount of code to make it fail?
Could you try removing more and more until you get to something that doesn't fail? Then you can show us the snippet of code right before the last modification that makes it fail, and the snippet of code after that modification.

from rust-code-analysis.

MartinLwx avatar MartinLwx commented on June 3, 2024

Are you sure this is the minimum amount of code to make it fail? Could you try removing more and more until you get to something that doesn't fail? Then you can show us the snippet of code right before the last modification that makes it fail, and the snippet of code after that modification.

Hi, sorry for that. This time I made more eager modification through trial and error. I believe that the code has been reduced to the most minimal amount possible.

The code before last modification that makes it fail:

static YYACTIONTYPE yy_find_shift_action() {
  do {
    if (yy_lookahead[i] != iLookAhead) {
#ifdef YYWILDCARD
      {
        if (
#if YY_SHIFT_MAX + YYWILDCARD >= YY_ACTTAB_COUNT
            j < YY_ACTTAB_COUNT &&
#endif
            yy_lookahead[j] == YYWILDCARD) {
#ifndef NDEBUG
          if (yyTraceFILE) {
            fprintf(yyTraceFILE, "%sWILDCARD %s", yyTracePrompt,
                    yyTokenName[iLookAhead]);
          }
#endif
        }
      }
#endif
    }
  } while (1);
}

Possible fix: Delete any inner #if... pairs(additional code has been omitted for brevity).

...
#ifdef YYWILDCARD
      {
        if (
            yy_lookahead[j] == YYWILDCARD) {
#ifndef NDEBUG
          if (yyTraceFILE) {
            fprintf(yyTraceFILE, "%sWILDCARD %s", yyTracePrompt,
                    yyTokenName[iLookAhead]);
          }
#endif
        }
      }
#endif
...

Possible fix: Remove the brackets(i.e {})

...
          if (yyTraceFILE) 
            fprintf(yyTraceFILE, "%sWILDCARD %s", yyTracePrompt,
                    yyTokenName[iLookAhead]);
...

Possible fix: Condense the function call into a single line

...
          if (yyTraceFILE) {
            fprintf(yyTraceFILE, "%sWILDCARD %s", yyTracePrompt, yyTokenName[iLookAhead]);
          }
...

Possible fix: Change the condition of if statement.

...
#if YY_SHIFT_MAX + YYWILDCARD >= YY_ACTTAB_COUNT
            j < YY_ACTTAB_COUNT
#endif
            ) {
...

from rust-code-analysis.

marco-c avatar marco-c commented on June 3, 2024

Thanks, that's better. I guess we could further reduce it by simplifying the statements (e.g. fprintf(yyTraceFILE, "%sWILDCARD %s", yyTracePrompt, yyTokenName[iLookAhead]); could be a single statement like int x = 0; or similar).

There is probably a but in the handling of macros.

from rust-code-analysis.

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.