Fixed a Bug Crashing Clang

An ill-formed C++ code snippet Before the fix, this following C++ snippet would crash Clang. From the bug report, we can see how a user might accidentally omit the function name when they meant to declare a member function on line 3. To many people’s surprise, line 3 is actually parsed as a member variable declaration. The parantheses are insignificant here unlike when declaring a pointer to function or array. So line 3 is essentially T A<T>{};. The template parameter there is ill-formed and is handled by 942c03910aef. ...

March 24, 2022 · 張博堯 (Po-Yao Chang)

C++ Trivia;

I was browsing 🫣 the latest working draft of the ISO C++ Standard (https://eel.is/c++draft/) and then I found that what a single semicolon is called grammatically depends on where it appears. Cool beans 😎! Here’s a screenshot illustrating my findings (engorgio): The top half is a piece of valid C++ code stored in sc.cpp and the bottom half is its Clang AST dump with unimportant parts removed. The ; in the global scope on line 1 of sc.cpp is an empty-declaration as noted in [decl.pre]p1. The grammar production goes: translation-unit -> declaration-seq -> declaration -> empty-declaration -> ; ...

March 1, 2022 · 張博堯 (Po-Yao Chang)

The Bug Strikes Back: LLDB Bugs Lurking for Over a Decade

The Issue One day, I was wondering how dynamic function call works. I thought I’d start with a simple puts call like in this C snippet. #include <stdio.h> int main(void) { puts("Hello\n"); } To see it going through the Procedure Linkage Table (PLT) in the context of lazy binding on x86_64 Linux LIVE, naturally, LLDB came to my mind. To my dismay, instead of something relevant to puts there were only these ugly and unidentifiable ___lldb_unnamed_symbol36 in the disaseembly on LLDB 13.0.0 🫠: In comparison, this is GDB 11.1: Let’s see how an older version of LLDB is doing. Here’s LLDB version 12.0.1 🫥: Apparently, something went wrong between the creation of LLVM version 12 and 13 release branch. It turned out that it was a patch landing in July 2021 that changed the behavior. Someone also filed a GitHub issue just a few days before I found this. I then commented my findings on the code review page of the seemingly problematic patch. ...

January 7, 2022 · 張博堯 (Po-Yao Chang)

ABI Incompatibility of libc++ and libstdc++ and C++ Inline Namespace

I ran into linker errors similar to the screenshot below in November 2021. After some close inspection, I realized this was a result of mixing 2 C++ standard libraries, namely libc++ and libstdc++. I was unkowningly 😱 compiling TVM with libc++’s headers while linking it against LLVM which was compiled with libstdc++’s headers and linked against libstdc++. A Simple Example Here is a simple example illustrating what’s happening. Source Files Given 2 C++ souce files: ...

January 6, 2022 · 張博堯 (Po-Yao Chang)

Set Up an SSD for Your Tesla on a Mac

Foreword Tesla intriduced custom light show in its holiday update, and I would like to put Tesla dash cam, music, boombox, and custom light show all in one storage device (assumed to be an SSD in this post). By doing this, I can put my SSD in the glove box, which is locked in the case of a breakin. This can be achieved by partitioning the storage device into 4 partitions, during which I found it was a PITA to do with file system other than APFS. Then, I recalled that there was this system utility on macOS called diskutil. Thankfully, the man page is easy to grasp. Nonetheless, I decided to compile a blog post after some light reading. ...

December 31, 2021 · 張博堯 (Po-Yao Chang)

Set up a blog using Hugo

本文紀錄如何用Hugo建立blog,並部署到GitHub Pages。 ...

March 7, 2020 · 張博堯 (Po-Yao Chang)