Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

__builtin_FUNCTION() is inconsistent on path separator on Windows #44701

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR45731
Status NEW
Importance P normal
Reported by Daniel Marshall (xandan@gmail.com)
Reported on 2020-04-29 05:21:09 -0700
Last modified on 2020-05-05 10:41:04 -0700
Version 10.0
Hardware PC Windows NT
CC aaron@aaronballman.com, amccarth@google.com, blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk, rnk@google.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Given the following

src/main.cpp
src/header.h

And the following code:

//header.h
#include <iostream>

void test()
{
    std::cout << __builtin_FILE() << '\n';
}

=====

//main.cpp
#include "header.h"

int main()
{
    test();
    std::cout << __builtin_FILE() << '\n';
}

======

I get the following output

src/header.h
src\main.cpp

Discovered this when implementing srd::source_location for Microsoft here

https://github.com/microsoft/STL/pull/664#issuecomment-621063583
Quuxplusone commented 4 years ago

Clang internally does as little path canonicalization as possible, although I've forgotten precisely why, and this behavior is a reflection of that. FILE has the same issue. This results in user-supplied paths often containing backslashes (-IC:\my~8.3\sdk\path) being concatenated with portable separators (forward slashes) and traversal components (..). It has long been suggested that this is not what users want to see in FILE, but changing FILE is of course fraught with peril.