Bugzilla – Bug 89
[C++] Catch blocks make unparsable labels
Last modified: 2003-11-04 23:51:45
You need to log in before you can comment on or make changes to this bug.
This testcase: ---- #include <string> void bar(); void test() { try { bar(); } catch (std::string) {} } --- Produces a label named '%caught.basic_string<char,std::char_traits<char>,std::allocator<char> >', which is causing parse errors. Testcase is test/Regression/C++Frontend/2003-11-04-CatchLabelName.cpp -Chris
Fixed like so: $ diff -u llvm-representation.c~ llvm-representation.c --- llvm-representation.c~ 2003-10-29 13:19:23.000000000 -0600 +++ llvm-representation.c 2003-11-04 23:46:44.000000000 -0600 @@ -720,8 +720,26 @@ llvm_basicblock *llvm_basicblock_new(const char *Name) { llvm_basicblock *BB = (llvm_basicblock*)xcalloc(sizeof(llvm_basicblock), 1); - llvm_value_construct(D2V(BB), LabelTy, Name, BasicBlock); + const char *NewName = xstrdup(Name), *R, *W; + + /* We can't tolerate wierd characters in label names yet, so just strip them + * out mercilessly! + */ + for (R = W = NewName; *R; ++R) { + char C = *R; + /* Only copy the char over if it is known good. */ + if ((C >= 'a' && C <= 'z') || + (C >= 'A' && C <= 'Z') || + (C >= '0' && C <= '9') || + C == '.' || C == '_') { + *W++ = C; + } + } + *W = *R; /* Copy the null terminator */ + + llvm_value_construct(D2V(BB), LabelTy, NewName, BasicBlock); llvm_ilist_construct(llvm_instruction, BB->Instructions); + free(NewName); return BB; }