[Lldb-commits] [PATCH] Fix type detection for 'char' when it is unsigned

Tamas Berghammer tberghammer at google.com
Thu Mar 26 14:25:39 PDT 2015


I agree that we don't want to parse any unnecessary dwarf information, but my problem is that the current implementation is inconsistent with the C++ standard. Currently we use "char" only in the case when it is a signed type (I think this is the more common case), but it is just an arbitrary choice as the standard don't specify it (leave it to the implementation). The problem what you are describing is already in the code for the case when "char" is signed as it is using almost the same logic what I plan to add here (Line 956-969).

I think if the dwarf file say that the a variable have a type named "char" then we should treat it as CharTy and ensure that it will be initialized correctly. If we reach this point then we are parsing some dwarf  information about a "char" so clang ASTContext should contain the right value or if not then we should update it accordingly (not sure if possible to update it in ClangASTContext).

Fixing the test cases are a possible option but I really hate that idea as the test cases are correct and the implementation is broken. Your suggestion (using "unsigned char") will work in most of the case but it can be a bit confusing for the user when we display wrong type information and can break expression evaluation in the following (edge) case:

Given this program (perfectly valid C++):

  #include <cstdio>
  
  void foo(char c) {
    printf("normal\n");
  }
  
  void foo(unsigned char c) {
    printf("unsigned\n");
  }
  
  void foo(signed char c) {
    printf("signed\n");
  }
  
  int main() {
    char c = 0;
    unsigned char uc = 0;
    signed char sc = 0;
    foo(c);
    foo(uc);
    foo(sc);
  }

Stop at the end and evaluate the following expressions on a machine where char is an unsigned type (will use UnsignedCharTy based on your suggestion):

  foo(c);
  foo(uc);
  foo(sc);

The first one will output "unsigned" while it should output normal (it will work as intended when char is signed because of the logic in Line 965-969). I think the only way to fix it is to use the real type of the variable what is char (CharTy)
(P.S.: Haven't tested it but pretty sure this is what will happen)


http://reviews.llvm.org/D8636

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the lldb-commits mailing list