<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56499>56499</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang incorrectly succeeds when outputting to full NFS disk
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mblythe86
      </td>
    </tr>
</table>

<pre>
    ### Necessary ingredients
1. `clang` outputs to stdout
3. stdout is redirected to a file
4. file is on an NFS disk
5. NFS disk is full or has hit a quota

### Expected outcome
Print an error message to stderr, and exit with a non-0 status (as shown by the `gcc` compiler here):
```
> g++ -E test.cc > /path/to/nfs/mount/out0
> g++ -E test.cc > /path/to/nfs/mount/out1
...repeat until disk fills...
> g++ -E test.cc > /path/to/nfs/mount/out10
<built-in>: fatal error: when writing output to : No space left on device
compilation terminated.
> echo $?
1
```

### Actual outcome
`clang` prints no error message, exits with a 0/success status, and produces partial or 0-length files:
```
> clang++ -E test.cc > /path/to/nfs/mount/out0
> clang++ -E test.cc > /path/to/nfs/mount/out1
...repeat until disk fills...
> clang++ -E test.cc > /path/to/nfs/mount/out10
> clang++ -E test.cc > /path/to/nfs/mount/out11
> clang++ -E test.cc > /path/to/nfs/mount/out12
> echo $?
0
> ls -l /path/to/nfs/mount/
-rw-rw-r-- 1 matt matt 763518 Jul 12 15:17 out0
-rw-rw-r-- 1 matt matt 763518 Jul 12 15:17 out1
...
-rw-rw-r-- 1 matt matt 763518 Jul 12 15:17 out10
-rw-rw-r-- 1 matt matt  20480 Jul 12 15:17 out11
-rw-rw-r-- 1 matt matt      0 Jul 12 15:17 out12
```

This also happens when output is explicitly set to stdout, which is then redirected:
```
> clang++ -c test.cc -o - > /path/to/nfs/mount/out6.o
> clang++ -c test.cc -o - > /path/to/nfs/mount/out7.o
> echo $?
0
> ls -l /path/to/nfs/mount/
-rw-rw-r-- 1 matt matt 2.6K Jul 12 15:28 out6.o
-rw-rw-r-- 1 matt matt    0 Jul 12 15:29 out7.o
```
I can't demonstrate this in `gcc` because it doesn't work at all:
```
> g++ test.cc -c -o - > test.o
Assembler messages:
Fatal error: can't open a bfd on stdout -
```

### OS details
```
> lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:        22.04
Codename:       jammy
```

### Clang version
installed from Ubuntu repos
```
> clang -v
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
```
### Steps to reproduce

1. Create a ridiculously undersized disk for testing (probably on a different machine)
```
> dd if=/dev/zero of=disk_image bs=1024 count=10240
> mkfs -t ext3 disk_image
> mkdir tmp_mount
> sudo mount -t ext3 -o loop disk_image tmp_mount
> sudo chmod a+rwx tmp_mount
```
2. Mount small disk over NFS
3. Create simple source file
```
//test.cc
#include <iostream>

int main(){
  std::cout << "Hello, World!" << std::endl;
}
```
4. Run commands, and observe they don't fail
```
> clang++ -E test.cc > /path/to/nfs/mount/out0
> clang++ -E test.cc > /path/to/nfs/mount/out1
...repeat until disk fills...
> clang++ -E test.cc > /path/to/nfs/mount/out10
> clang++ -E test.cc > /path/to/nfs/mount/out11
> clang++ -E test.cc > /path/to/nfs/mount/out12
> echo $?
0
> ls -l /path/to/nfs/mount/
-rw-rw-r-- 1 matt matt 763518 Jul 12 15:17 out0
-rw-rw-r-- 1 matt matt 763518 Jul 12 15:17 out1
...
-rw-rw-r-- 1 matt matt 763518 Jul 12 15:17 out10
-rw-rw-r-- 1 matt matt  20480 Jul 12 15:17 out11
-rw-rw-r-- 1 matt matt      0 Jul 12 15:17 out12
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llv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