[llvm-bugs] [Bug 46383] New: clang-format breaks stringized macro argument

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 18 08:54:41 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46383

            Bug ID: 46383
           Summary: clang-format breaks stringized macro argument
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: chris.hamilton at ericsson.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

Created attachment 23627
  --> https://bugs.llvm.org/attachment.cgi?id=23627&action=edit
sample source that is mishandled by clang-format

clang-format breaks a stringized macro argument into tokens, which changes the
output of the formatted code.  Here's an example:

  [flextools-llvm/clang-tools-extra/clang-tidy]$ $builddir/bin/clang --version
  clang version 11.0.0  (xxxxxxxxx)
  Target: x86_64-unknown-linux-gnu
  Thread model: posix
  InstalledDir: /repo/eahcmrh/flextools-llvm/build-debug/bin

  [flextools-llvm/clang-tools-extra/clang-tidy]$ cat trythis.c 
  #include <stdio.h>

  #define WRITETHIS(a,b)  do { printf(a, "TAG:" #b); } while (0)

  int main(void)
  {
    WRITETHIS("Output: %s\n\n", String-ized&Messy+But:  :Still=Intentional);
  }

  [flextools-llvm/clang-tools-extra/clang-tidy]$ $builddir/bin/clang trythis.c
-o trythis

  [flextools-llvm/clang-tools-extra/clang-tidy]$ ./trythis 
  Output: TAG:String-ized&Messy+But: :Still=Intentional


  [flextools-llvm/clang-tools-extra/clang-tidy]$ $builddir/bin/clang-format
trythis.c > formatted.c

  [flextools-llvm/clang-tools-extra/clang-tidy]$ cat formatted.c 
  #include <stdio.h>

  #define WRITETHIS(a, b)                                                      
 \
    do {                                                                       
 \
      printf(a, "TAG:" #b);                                                    
 \
    } while (0)

  int main(void) {
    WRITETHIS("Output: %s\n\n", String - ized &Messy + But
              :
              : Still = Intentional);
  }

  [flextools-llvm/clang-tools-extra/clang-tidy]$ $builddir/bin/clang
formatted.c -o formatted

  [flextools-llvm/clang-tools-extra/clang-tidy]$ ./formatted 
  Output: TAG:String - ized &Messy + But : : Still = Intentional

This functional difference in clang-formatted code is incorrect.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200618/00db34a9/attachment.html>


More information about the llvm-bugs mailing list