Index: llvm/test/tools/llvm-ar/mri-create-overwrite.test =================================================================== --- /dev/null +++ llvm/test/tools/llvm-ar/mri-create-overwrite.test @@ -0,0 +1,100 @@ +## Show that CREATE/CREATETHIN overwrite existing files appropriately. + +# RUN: rm -rf %t && mkdir -p %t +# RUN: touch %t/archive.a +# RUN: touch %t/1.txt +# RUN: touch %t/2.txt + +## Show that an existing file that is not an archive is overwritten by CREATE. +# RUN: echo "CREATE %t/archive.a" > %t/test.mri +# RUN: echo "ADDMOD %t/1.txt" >> %t/test.mri +# RUN: echo "SAVE" >> %t/test.mri +# RUN: llvm-ar -M < %t/test.mri +# RUN: llvm-ar tv %t/archive.a | \ +# RUN: FileCheck %s --check-prefix=CREATE +CREATE: 1.txt + +## Show that an existing file that is not an archive is overwritten by CREATETHIN. +# RUN: rm -f %t/archive.a +# RUN: touch %t/archive.a +# RUN: echo "CREATETHIN %t/archive.a" > %t/test.mri +# RUN: echo "ADDMOD %t/1.txt" >> %t/test.mri +# RUN: echo "SAVE" >> %t/test.mri +# RUN: llvm-ar -M < %t/test.mri +# RUN: llvm-ar tv %t/archive.a | \ +# RUN: FileCheck %s --check-prefix=CREATETHIN +CREATETHIN: 1.txt + +## Show that an existing full archive is overwritten by CREATE. +# RUN: rm -f %t/archive.a +# RUN: llvm-ar cr %t/archive.a %t/1.txt +# RUN: echo "CREATE %t/archive.a" > %t/test.mri +# RUN: echo "ADDMOD %t/2.txt" >> %t/test.mri +# RUN: echo "SAVE" >> %t/test.mri +# RUN: llvm-ar -M < %t/test.mri +# RUN: llvm-ar tv %t/archive.a +# RUN: FileCheck -input-file=%t/archive.a %s --check-prefix=FULL_CREATE --implicit-check-not=1.txt +FULL_CREATE: ! +FULL_CREATE: 2.txt + +## Show that an existing full archive is overwritten by CREATETHIN. +# RUN: rm -f %t/archive.a +# RUN: llvm-ar cr %t/archive.a %t/1.txt +# RUN: echo "CREATETHIN %t/archive.a" > %t/test.mri +# RUN: echo "ADDMOD %t/2.txt" >> %t/test.mri +# RUN: echo "SAVE" >> %t/test.mri +# RUN: llvm-ar -M < %t/test.mri +# RUN: llvm-ar tv %t/archive.a +# RUN: FileCheck -input-file=%t/archive.a %s --check-prefix=FULL_CREATETHIN --implicit-check-not=1.txt +FULL_CREATETHIN: ! +FULL_CREATETHIN: 2.txt + +## Show that an existing thin archive is overwritten by CREATE. +# RUN: rm -f %t/archive.a +# RUN: llvm-ar crT %t/archive.a %t/1.txt +# RUN: echo "CREATE %t/archive.a" > %t/test.mri +# RUN: echo "ADDMOD %t/2.txt" >> %t/test.mri +# RUN: echo "SAVE" >> %t/test.mri +# RUN: llvm-ar -M < %t/test.mri +# RUN: llvm-ar tv %t/archive.a +# RUN: FileCheck -input-file=%t/archive.a %s --check-prefix=THIN_CREATE --implicit-check-not=1.txt +THIN_CREATE: ! +THIN_CREATE: 2.txt + +## Show that an existing thin archive is overwritten by CREATETHIN. +# RUN: rm -f %t/archive.a +# RUN: llvm-ar crT %t/archive.a %t/1.txt +# RUN: echo "CREATETHIN %t/archive.a" > %t/test.mri +# RUN: echo "ADDMOD %t/2.txt" >> %t/test.mri +# RUN: echo "SAVE" >> %t/test.mri +# RUN: llvm-ar -M < %t/test.mri +# RUN: llvm-ar tv %t/archive.a +# RUN: FileCheck -input-file=%t/archive.a %s --check-prefix=THIN_CREATETHIN --implicit-check-not=1.txt +THIN_CREATETHIN: ! +THIN_CREATETHIN: 2.txt + +## Make archive read-only. +# RUN: chmod 444 %t/archive.a + +## Show that the output is not overwritten without a SAVE. +# RUN: echo "CREATE %t/archive.a" > %t/test.mri +# RUN: echo "ADDMOD %t/2.txt" >> %t/test.mri +# RUN: llvm-ar -M < %t/test.mri + +## Show that a read-only file is not overwritten. +# RUN: echo "SAVE" >> %t/test.mri +# RUN: not llvm-ar -M < %t/test.mri 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ERROR -DFILE=%t/archive.a +# ERROR: error: [[FILE]]: permission denied + +## Show that only the last mentioned file is overwritten. +# RUN: echo "CREATE %t/archive.a" > %t/test.mri +# RUN: echo "ADDMOD %t/1.txt" >> %t/test.mri +# RUN: echo "CREATETHIN %t/second.a" > %t/test.mri +# RUN: echo "ADDMOD %t/2.txt" >> %t/test.mri +# RUN: echo "SAVE" >> %t/test.mri +# RUN: llvm-ar -M < %t/test.mri +# RUN: llvm-ar tv %t/second.a | \ +# RUN: FileCheck %s --check-prefix=SECOND +SECOND: 2.txt + Index: llvm/tools/llvm-ar/llvm-ar.cpp =================================================================== --- llvm/tools/llvm-ar/llvm-ar.cpp +++ llvm/tools/llvm-ar/llvm-ar.cpp @@ -1134,7 +1134,7 @@ // Nothing to do if not saved. if (Saved) - performOperation(ReplaceOrInsert, &NewMembers); + performOperation(ReplaceOrInsert, nullptr, nullptr, &NewMembers); exit(0); }