New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 774167 link

Starred by 1 user

Issue metadata

Status: Untriaged
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug



Sign in to add a comment

clang-format quality problem: badly formatted x-macros

Project Member Reported by p...@chromium.org, Oct 12 2017

Issue description

clang-format produced code that (choose all that apply): 
- Doesn't match Chromium style
- Doesn't match blink style
- Riles my finely honed stylistic dander
- No sane human would ever choose

Here's the code before formatting:

long WINAPI StackDumpExceptionFilter(EXCEPTION_POINTERS* info) {
  DWORD exc_code = info->ExceptionRecord->ExceptionCode;
  std::cerr << "Received fatal exception ";
  switch (exc_code) {
#define EXC_CODE(x) \
    case x: \
      std::cerr << #x; \
      break;
    EXC_CODE(EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
    EXC_CODE(EXCEPTION_BREAKPOINT)
    EXC_CODE(EXCEPTION_DATATYPE_MISALIGNMENT)
    EXC_CODE(EXCEPTION_FLT_DENORMAL_OPERAND)
    EXC_CODE(EXCEPTION_FLT_DIVIDE_BY_ZERO)
    EXC_CODE(EXCEPTION_FLT_INEXACT_RESULT)
    EXC_CODE(EXCEPTION_FLT_INVALID_OPERATION)
    EXC_CODE(EXCEPTION_FLT_OVERFLOW)
    EXC_CODE(EXCEPTION_FLT_STACK_CHECK)
    EXC_CODE(EXCEPTION_FLT_UNDERFLOW)
    EXC_CODE(EXCEPTION_ILLEGAL_INSTRUCTION)
    EXC_CODE(EXCEPTION_IN_PAGE_ERROR)
    EXC_CODE(EXCEPTION_INT_DIVIDE_BY_ZERO)
    EXC_CODE(EXCEPTION_INT_OVERFLOW)
    EXC_CODE(EXCEPTION_INVALID_DISPOSITION)
    EXC_CODE(EXCEPTION_NONCONTINUABLE_EXCEPTION)
    EXC_CODE(EXCEPTION_PRIV_INSTRUCTION)
    EXC_CODE(EXCEPTION_SINGLE_STEP)
    EXC_CODE(EXCEPTION_STACK_OVERFLOW)
#undef EXC_CODE
    default:
      std::cerr << "0x" << std::hex << exc_code;
      break;
  }
  std::cerr << "\n";

  debug::StackTrace(info).Print();
  if (g_previous_filter)
    return g_previous_filter(info);
  return EXCEPTION_CONTINUE_SEARCH;
}


Here's the code after formatting:

long WINAPI StackDumpExceptionFilter(EXCEPTION_POINTERS* info) {
   DWORD exc_code = info->ExceptionRecord->ExceptionCode;
   std::cerr << "Received fatal exception ";
   switch (exc_code) {
#define EXC_CODE(x)     \
     case x : \
      std::cerr << #x; \
       break;
       EXC_CODE(EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
    EXC_CODE(EXCEPTION_BREAKPOINT)
    EXC_CODE(EXCEPTION_DATATYPE_MISALIGNMENT)
    EXC_CODE(EXCEPTION_FLT_DENORMAL_OPERAND)
    EXC_CODE(EXCEPTION_FLT_DIVIDE_BY_ZERO)
    EXC_CODE(EXCEPTION_FLT_INEXACT_RESULT)
    EXC_CODE(EXCEPTION_FLT_INVALID_OPERATION)
    EXC_CODE(EXCEPTION_FLT_OVERFLOW)
    EXC_CODE(EXCEPTION_FLT_STACK_CHECK)
    EXC_CODE(EXCEPTION_FLT_UNDERFLOW)
    EXC_CODE(EXCEPTION_ILLEGAL_INSTRUCTION)
    EXC_CODE(EXCEPTION_IN_PAGE_ERROR)
    EXC_CODE(EXCEPTION_INT_DIVIDE_BY_ZERO)
    EXC_CODE(EXCEPTION_INT_OVERFLOW)
    EXC_CODE(EXCEPTION_INVALID_DISPOSITION)
    EXC_CODE(EXCEPTION_NONCONTINUABLE_EXCEPTION)
    EXC_CODE(EXCEPTION_PRIV_INSTRUCTION)
    EXC_CODE(EXCEPTION_SINGLE_STEP)
    EXC_CODE(EXCEPTION_STACK_OVERFLOW)
#undef EXC_CODE
    default :
      std::cerr << "0x" << std::hex << exc_code;
         break;
     
  }
   std::cerr << "\n";

  debug::StackTrace(info).Print();
  if (g_previous_filter)
    return g_previous_filter(info);
  return EXCEPTION_CONTINUE_SEARCH;
}


Here's how it ought to look:

as original

Code review link for full files/context:

https://chromium-review.googlesource.com/c/chromium/src/+/714642
 

Comment 1 by thakis@chromium.org, Oct 12 2017

Formats it like so for me, which seems reasonable to me:

long WINAPI StackDumpExceptionFilter(EXCEPTION_POINTERS* info) {
  DWORD exc_code = info->ExceptionRecord->ExceptionCode;
  std::cerr << "Received fatal exception ";
  switch (exc_code) {
#define EXC_CODE(x)  \
  case x:            \
    std::cerr << #x; \
    break;
    EXC_CODE(EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
    EXC_CODE(EXCEPTION_BREAKPOINT)
    EXC_CODE(EXCEPTION_DATATYPE_MISALIGNMENT)
    EXC_CODE(EXCEPTION_FLT_DENORMAL_OPERAND)
    EXC_CODE(EXCEPTION_FLT_DIVIDE_BY_ZERO)
    EXC_CODE(EXCEPTION_FLT_INEXACT_RESULT)
    EXC_CODE(EXCEPTION_FLT_INVALID_OPERATION)
    EXC_CODE(EXCEPTION_FLT_OVERFLOW)
    EXC_CODE(EXCEPTION_FLT_STACK_CHECK)
    EXC_CODE(EXCEPTION_FLT_UNDERFLOW)
    EXC_CODE(EXCEPTION_ILLEGAL_INSTRUCTION)
    EXC_CODE(EXCEPTION_IN_PAGE_ERROR)
    EXC_CODE(EXCEPTION_INT_DIVIDE_BY_ZERO)
    EXC_CODE(EXCEPTION_INT_OVERFLOW)
    EXC_CODE(EXCEPTION_INVALID_DISPOSITION)
    EXC_CODE(EXCEPTION_NONCONTINUABLE_EXCEPTION)
    EXC_CODE(EXCEPTION_PRIV_INSTRUCTION)
    EXC_CODE(EXCEPTION_SINGLE_STEP)
    EXC_CODE(EXCEPTION_STACK_OVERFLOW)
#undef EXC_CODE
    default:
      std::cerr << "0x" << std::hex << exc_code;
      break;
  }
  std::cerr << "\n";

  debug::StackTrace(info).Print();
  if (g_previous_filter)
    return g_previous_filter(info);
  return EXCEPTION_CONTINUE_SEARCH;
}


But worst-case, `//clang-format off` ... `//clang-format off`.

Comment 2 by thakis@chromium.org, Oct 12 2017

Labels: clang-format

Comment 3 by p...@chromium.org, Oct 12 2017

Do you also get that formatting if you copy the function into base/debug/stack_trace_win.cc? I can reproduce your result only if I create a standalone file with that function.

Comment 4 by thakis@chromium.org, Oct 12 2017

Works there too. Maybe you have a different clang-format from chromium's on your PATH before depot_tools?

Comment 5 by p...@chromium.org, Oct 12 2017

There's a /usr/bin/clang-format on my path before chromium's, but I can also reproduce by invoking the clang-format in depot_tools, and by invoking buildtools/linux64/clang-format directly.
Components: Tools
Jumping on to this issue since it's fairly recent and I've been irked by weird macro formatting issues with my X macros, but more generally for any multi-line macro.

Example:

#define ANGLE_IMPL_TYPE_HELPER_GL(OBJ) \
template<>                             \
struct ImplTypeHelper<gl::OBJ>         \
{                                      \
        using ImplType = OBJ##Vk;      \
};

Result:

#define ANGLE_IMPL_TYPE_HELPER_GL(OBJ) \
  \
template<>                             \
      \
struct ImplTypeHelper<gl::OBJ> \
{    \
    using ImplType = OBJ##Vk;          \
  \
};

Seems pretty weird that it got this confused.

Comment 8 by thakis@chromium.org, Oct 30 2017

I can't repro that either. This is formatted like

#define ANGLE_IMPL_TYPE_HELPER_GL(OBJ) \
  template <>                          \
  struct ImplTypeHelper<gl::OBJ> {     \
    using ImplType = OBJ##Vk;          \
  };


on my system. If I put the code in a file in third_party/angle/src/libANGLE instead of in base/, it gets formatted like so:

#define ANGLE_IMPL_TYPE_HELPER_GL(OBJ) \
    template <>                        \
    struct ImplTypeHelper<gl::OBJ>     \
    {                                  \
        using ImplType = OBJ##Vk;      \
    };

OK, this is probably due to parsing of EOL differences on Windows CRLF files vs Unix LF files. It might be an easy fix for someone who is familiar with the code. Nico's away for a while, is there anyone who can offer some guidance?
Cc: jmad...@chromium.org
Labels: Pri-2
Issue has a component, but no priority. Updating to have default priority (Pri-2)

Sign in to add a comment