Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on literal strings #11

Open
Blei opened this issue Apr 28, 2012 · 2 comments
Open

Crash on literal strings #11

Blei opened this issue Apr 28, 2012 · 2 comments

Comments

@Blei
Copy link
Member

Blei commented Apr 28, 2012

The following program crashes while being parsed (?) by clang:

struct device_information {
  unsigned id_lo, id_hi;
  unsigned version;
  unsigned manufacturer_lo, manufacturer_hi;
};

void get_device_information(unsigned device_number,
                            struct device_information *info) {
  asm volatile (
      "HWQ %5\n"
      "SET %0, A\n"
      "SET %1, B\n"
      "SET %2, C\n"
      "SET %3, X\n"
      "SET %4, Y"
      :
      "=g" (info->id_lo),
      "=g" (info->id_hi),
      "=g" (info->version),
      "=g" (info->manufacturer_lo),
      "=g" (info->manufacturer_hi)
      :
      "r" (device_number)
      :
      // Clobbered registers
      "A", "B", "C", "X", "Y");
}

If the asm string is concatenated into one line ("HWQ %5\nSET %0, A\nSET %1, B\nSET %2, C\nSET %3, X\nSET %4, Y"), everything works as it should.

@bwesterb
Copy link

bwesterb commented May 5, 2012

I can confirm this.

This compiles:

int main(void) {
        int n = 37, a, b, c, x, y;
        asm("HWQ %2\n"
            "SET %0, A\n"
            "SET %1, B"
                : "=g" (a),
                  "=g" (b)
                : "r" (n)
                : "A", "B", "C", "X", "Y");
        return a;
}

However, this does not:

int main(void) {
        int n = 37, a, b, c, x, y;
        asm("HWQ %3\n"
            "SET %0, A\n"
            "SET %1, B\n"
            "SET %2, C"
                : "=g" (a),
                  "=g" (b),
                  "=g" (c)
                : "r" (n)
                : "A", "B", "C", "X", "Y");
        return a;
}

And the error is:

/home/bas/src/llvm-dcpu16/cbuild/bin/clang -ccc-host-triple dcpu16 -S \
        test.c -o test.s
clang-3.1: /home/bas/src/llvm-dcpu16/tools/clang/lib/Lex/LiteralSupport.cpp:1382: unsigned int clang::StringLiteralParser::getOffsetOfStringByte(const clang::Token&, unsigned int) const: Assertion `SpellingPtr < SpellingEnd && "Didn't find byte offset!"' failed.
Stack dump:
0.  Program arguments: /home/bas/src/llvm-dcpu16/cbuild/bin/clang-3.1 -cc1 -triple dcpu16 -S -disable-free -main-file-name test.c -mrelocation-model static -mdisable-fp-elim -mconstructor-aliases -momit-leaf-frame-pointer -coverage-file test.s -resource-dir /home/bas/src/llvm-dcpu16/cbuild/bin/../lib/clang/3.1 -fmodule-cache-path /var/tmp/clang-module-cache -fno-dwarf-directory-asm -fdebug-compilation-dir /home/bas/src/notch -ferror-limit 19 -fmessage-length 80 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fdiagnostics-show-option -fcolor-diagnostics -o test.s -x c test.c 
1.  <eof> parser at end of file
2.  test.c:2:5: LLVM IR generation of declaration 'main'
3.  test.c:2:5: Generating code for declaration 'main'
4.  test.c:2:16: LLVM IR generation of compound statement ('{}')
clang-3: error: unable to execute command: Aborted (core dumped)
clang-3: error: clang frontend command failed due to signal (use -v to see invocation)
clang-3: note: diagnostic msg: Please submit a bug report to  and include command line arguments and all diagnostic information.
clang-3: note: diagnostic msg: Preprocessed source(s) and associated run script(s) are located at:
clang-3: note: diagnostic msg: /tmp/test-zsKR55.i
clang-3: note: diagnostic msg: /tmp/test-zsKR55.sh
make: *** [test.s] Error 254

I am on llvm-dcpu commit f9c275e351529b37996e31e36444b43e6707bfeb, which I believe is the latest available.

@erisdev
Copy link

erisdev commented May 6, 2012

Came her to report this very same issue, with a code snippet that does the same thing, using aaf7a21 and llvm-dcpu16/llvm-dcpu16@f9c275e. Good to know it's a known issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants