Index: llvm/lib/Support/Path.cpp =================================================================== --- llvm/lib/Support/Path.cpp +++ llvm/lib/Support/Path.cpp @@ -351,6 +351,7 @@ bool has_net = b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0]; bool has_drive = is_style_windows(style) && b->endswith(":"); + bool has_tilde = is_style_posix(style) && b->startswith("~"); if (has_net || has_drive) { if ((++pos != e) && is_separator((*pos)[0], style)) { @@ -362,7 +363,7 @@ } // POSIX style root directory. - if (is_separator((*b)[0], style)) { + if (has_tilde || is_separator((*b)[0], style)) { return *b; } } @@ -393,6 +394,7 @@ bool has_net = b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0]; bool has_drive = is_style_windows(style) && b->endswith(":"); + bool has_tilde = is_style_posix(style) && b->startswith("~"); if ((has_net || has_drive) && // {C:,//net}, skip to the next component. @@ -401,7 +403,7 @@ } // POSIX style root directory. - if (!has_net && is_separator((*b)[0], style)) { + if (!has_net && (has_tilde || is_separator((*b)[0], style))) { return *b; } } Index: llvm/test/tools/llvm-dwarfdump/AArch64/tilde.s =================================================================== --- /dev/null +++ llvm/test/tools/llvm-dwarfdump/AArch64/tilde.s @@ -0,0 +1,175 @@ +# RUN: llvm-mc %s -filetype obj -triple arm64-apple-darwin -o - \ +# RUN: | llvm-dwarfdump - \ +# RUN: | FileCheck %s +# CHECK: DW_AT_decl_file ("~user/foo/t.c") +.section __TEXT,__text,regular,pure_instructions +.build_version macos, 12, 0 +.globl _f ; -- Begin function f +.p2align 2 +_f: ; @f +Lfunc_begin0: +.file 1 "~user/foo" "t.c" +.loc 1 1 0 ; ~user/foo/t.c:1:0 +.cfi_startproc +; %bb.0: ; %entry +.loc 1 1 11 prologue_end ; ~user/foo/t.c:1:11 +ret +Ltmp0: +Lfunc_end0: +.cfi_endproc + ; -- End function +.section __DWARF,__debug_abbrev,regular,debug +Lsection_abbrev: +.byte 1 ; Abbreviation Code +.byte 17 ; DW_TAG_compile_unit +.byte 1 ; DW_CHILDREN_yes +.byte 37 ; DW_AT_producer +.byte 14 ; DW_FORM_strp +.byte 19 ; DW_AT_language +.byte 5 ; DW_FORM_data2 +.byte 3 ; DW_AT_name +.byte 14 ; DW_FORM_strp +.ascii "\202|" ; DW_AT_LLVM_sysroot +.byte 14 ; DW_FORM_strp +.byte 16 ; DW_AT_stmt_list +.byte 23 ; DW_FORM_sec_offset +.byte 27 ; DW_AT_comp_dir +.byte 14 ; DW_FORM_strp +.byte 17 ; DW_AT_low_pc +.byte 1 ; DW_FORM_addr +.byte 18 ; DW_AT_high_pc +.byte 6 ; DW_FORM_data4 +.byte 0 ; EOM(1) +.byte 0 ; EOM(2) +.byte 2 ; Abbreviation Code +.byte 46 ; DW_TAG_subprogram +.byte 0 ; DW_CHILDREN_no +.byte 17 ; DW_AT_low_pc +.byte 1 ; DW_FORM_addr +.byte 18 ; DW_AT_high_pc +.byte 6 ; DW_FORM_data4 +.ascii "\347\177" ; DW_AT_APPLE_omit_frame_ptr +.byte 25 ; DW_FORM_flag_present +.byte 64 ; DW_AT_frame_base +.byte 24 ; DW_FORM_exprloc +.byte 3 ; DW_AT_name +.byte 14 ; DW_FORM_strp +.byte 58 ; DW_AT_decl_file +.byte 11 ; DW_FORM_data1 +.byte 59 ; DW_AT_decl_line +.byte 11 ; DW_FORM_data1 +.byte 63 ; DW_AT_external +.byte 25 ; DW_FORM_flag_present +.byte 0 ; EOM(1) +.byte 0 ; EOM(2) +.byte 0 ; EOM(3) +.section __DWARF,__debug_info,regular,debug +Lsection_info: +Lcu_begin0: +.set Lset0, Ldebug_info_end0-Ldebug_info_start0 ; Length of Unit +.long Lset0 +Ldebug_info_start0: +.short 4 ; DWARF version number +.set Lset1, Lsection_abbrev-Lsection_abbrev ; Offset Into Abbrev. Section +.long Lset1 +.byte 8 ; Address Size (in bytes) +.byte 1 ; Abbrev [1] 0xb:0x39 DW_TAG_compile_unit +.long 0 ; DW_AT_producer +.short 12 ; DW_AT_language +.long 97 ; DW_AT_name +.long 111 ; DW_AT_LLVM_sysroot +.set Lset2, Lline_table_start0-Lsection_line ; DW_AT_stmt_list +.long Lset2 +.long 113 ; DW_AT_comp_dir +.quad Lfunc_begin0 ; DW_AT_low_pc +.set Lset3, Lfunc_end0-Lfunc_begin0 ; DW_AT_high_pc +.long Lset3 +.byte 2 ; Abbrev [2] 0x2e:0x15 DW_TAG_subprogram +.quad Lfunc_begin0 ; DW_AT_low_pc +.set Lset4, Lfunc_end0-Lfunc_begin0 ; DW_AT_high_pc +.long Lset4 + ; DW_AT_APPLE_omit_frame_ptr +.byte 1 ; DW_AT_frame_base +.byte 111 +.long 123 ; DW_AT_name +.byte 1 ; DW_AT_decl_file +.byte 1 ; DW_AT_decl_line + ; DW_AT_external +.byte 0 ; End Of Children Mark +Ldebug_info_end0: +.section __DWARF,__debug_str,regular,debug +Linfo_string: +.asciz "clang version 14.0.0 (git@github.com:llvm/llvm-project d56b171ee965eba9ba30f4a479a9f2e1703105cf)" ; string offset=0 +.asciz "~user/foo/t.c" ; string offset=97 +.asciz "/" ; string offset=111 +.asciz "~user/foo" ; string offset=113 +.asciz "f" ; string offset=123 +.section __DWARF,__apple_names,regular,debug +Lnames_begin: +.long 1212240712 ; Header Magic +.short 1 ; Header Version +.short 0 ; Header Hash Function +.long 1 ; Header Bucket Count +.long 1 ; Header Hash Count +.long 12 ; Header Data Length +.long 0 ; HeaderData Die Offset Base +.long 1 ; HeaderData Atom Count +.short 1 ; DW_ATOM_die_offset +.short 6 ; DW_FORM_data4 +.long 0 ; Bucket 0 +.long 177675 ; Hash in Bucket 0 +.set Lset5, LNames0-Lnames_begin ; Offset in Bucket 0 +.long Lset5 +LNames0: +.long 123 ; f +.long 1 ; Num DIEs +.long 46 +.long 0 +.section __DWARF,__apple_objc,regular,debug +Lobjc_begin: +.long 1212240712 ; Header Magic +.short 1 ; Header Version +.short 0 ; Header Hash Function +.long 1 ; Header Bucket Count +.long 0 ; Header Hash Count +.long 12 ; Header Data Length +.long 0 ; HeaderData Die Offset Base +.long 1 ; HeaderData Atom Count +.short 1 ; DW_ATOM_die_offset +.short 6 ; DW_FORM_data4 +.long -1 ; Bucket 0 +.section __DWARF,__apple_namespac,regular,debug +Lnamespac_begin: +.long 1212240712 ; Header Magic +.short 1 ; Header Version +.short 0 ; Header Hash Function +.long 1 ; Header Bucket Count +.long 0 ; Header Hash Count +.long 12 ; Header Data Length +.long 0 ; HeaderData Die Offset Base +.long 1 ; HeaderData Atom Count +.short 1 ; DW_ATOM_die_offset +.short 6 ; DW_FORM_data4 +.long -1 ; Bucket 0 +.section __DWARF,__apple_types,regular,debug +Ltypes_begin: +.long 1212240712 ; Header Magic +.short 1 ; Header Version +.short 0 ; Header Hash Function +.long 1 ; Header Bucket Count +.long 0 ; Header Hash Count +.long 20 ; Header Data Length +.long 0 ; HeaderData Die Offset Base +.long 3 ; HeaderData Atom Count +.short 1 ; DW_ATOM_die_offset +.short 6 ; DW_FORM_data4 +.short 3 ; DW_ATOM_die_tag +.short 5 ; DW_FORM_data2 +.short 4 ; DW_ATOM_type_flags +.short 11 ; DW_FORM_data1 +.long -1 ; Bucket 0 +.subsections_via_symbols +.section __DWARF,__debug_line,regular,debug +Lsection_line: +Lline_table_start0: + Index: llvm/unittests/Support/Path.cpp =================================================================== --- llvm/unittests/Support/Path.cpp +++ llvm/unittests/Support/Path.cpp @@ -117,6 +117,14 @@ EXPECT_EQ(path::get_separator(path::Style::windows_slash), "/"); } +TEST(is_absolute, Works) { + EXPECT_FALSE(path::is_absolute("./foo", path::Style::posix)); + EXPECT_FALSE(path::is_absolute("~user", path::Style::windows)); + EXPECT_FALSE(path::is_absolute("~/home", path::Style::windows)); + EXPECT_TRUE(path::is_absolute("~user", path::Style::posix)); + EXPECT_TRUE(path::is_absolute("~/home", path::Style::posix)); +} + TEST(is_absolute_gnu, Works) { // Test tuple . const std::tuple Paths[] = { @@ -271,11 +279,15 @@ ASSERT_EQ(path::root_name("c:/hello", path::Style::posix).str(), ""); ASSERT_EQ(path::root_name("c:/hello", path::Style::windows).str(), "c:"); ASSERT_EQ(path::root_name("/hello", path::Style::posix).str(), ""); + ASSERT_EQ(path::root_name("~/hello", path::Style::posix).str(), ""); + ASSERT_EQ(path::root_name("~hello", path::Style::posix).str(), ""); ASSERT_EQ(path::root_directory("/goo/hello", path::Style::posix).str(), "/"); ASSERT_EQ(path::root_directory("c:/hello", path::Style::windows).str(), "/"); ASSERT_EQ(path::root_directory("d/file.txt", path::Style::posix).str(), ""); ASSERT_EQ(path::root_directory("d/file.txt", path::Style::windows).str(), ""); + ASSERT_EQ(path::root_directory("~/hello", path::Style::posix).str(), "~"); + ASSERT_EQ(path::root_directory("~hello", path::Style::posix).str(), "~hello"); SmallVector paths; paths.push_back("");