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

    <tr>
        <th>Summary</th>
        <td>
            Some macros cause -Wunused-value if -save-temps is used
        </td>
    </tr>

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

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

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

<pre>
    When compiling this simplified verifier

```c
#define a() 0
int main() { a(); }
```
with `clang -Werror -Wunused-value -save-temps` we get an error:
```
test-init.c:2:14: error: expression result unused [-Werror,-Wunused-value]
int main() { 0; }
             ^
1 error generated.
```
However, no error is produced for `clang -Werror -Wunused-value`  (i.e. **without** `-save-temps`).

While that example is obviously not useful, a more realistic example would be a macro that uses a compound statement and evaluates to a value that is optional to consume. For instance the following:

```c
#include <stdlib.h>

typedef struct element_t element_t;
struct element_t {
        void *value;
        element_t *next;
};

#define INIT(this, ...) ({ (this) = malloc(sizeof(*(this))); \
                           *(this) = (typeof(*(this))){ __VA_ARGS__ }; (this); }) 

element_t *element_create(void *value)
{
        element_t *this;
        INIT(this,
                .value = value,
        );
        return this;
}

int main(int argc, char **argv)
{
    return 0;
}
```
That definition of the macro also allows `element_create()` to be written as:
```c
        return INIT(this,
                .value = value,
        );
```

Again, only when compiling with `-save-temps` is there an error. The clang version doesn't matter (I tried 3.0 up to the current trunk, see [here for the above example on compiler explorer](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,selection:(endColumn:14,endLineNumber:5,positionColumn:14,positionLineNumber:5,selectionStartColumn:14,selectionStartLineNumber:5,startColumn:14,startLineNumber:5),source:'%23include+%3Cstdlib.h%3E%0A%0Atypedef+struct+element_t+element_t%3B%0Astruct+element_t+%7B%0A%09void+*value%3B%0A%09element_t+*next%3B%0A%7D%3B%0A%0A%23define+INIT(this,+...)+(%7B+(this)+%3D+malloc(sizeof(*(this)))%3B+%5C%0A%09%09%09%09%09%09+++*(this)+%3D+(typeof(*(this)))%7B+__VA_ARGS__+%7D%3B+(this)%3B+%7D)+%0A%0Aelement_t+*element_create(void+*value)%0A%7B%0A%09element_t+*this%3B%0A%09INIT(this,%0A%09%09.value+%3D+value,%0A%09)%3B%0A%09return+this%3B%0A%7D%0A%0Aint+main(int+argc,+char+**argv)%0A%7B%0A++++return+0%3B%0A%7D'),l:'5',n:'0',o:'C+source+%231',t:'0')),k:34.18113235186407,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:cclang_trunk,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,libs:!(),options:'-Werror+-Wunused-value+-save-temps',selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1,tree:'1'),l:'5',n:'0',o:'x86-64+clang+(trunk)+(C,+Editor+%231,+Compiler+%231)',t:'0')),k:32.48553431480261,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'x86-64+gcc+8.3',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+(trunk)+(Compiler+%231)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)).

Is this just something that's to be expected because the information about the original macro is lost due to `-save-temps`? Or could this be improved somehow?






</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytWNuS2jgQ_RrzohqXL5jLAw_AZHZTtZVs7WSTR0rYApQ1FmXJMLNfv6cl29hcZpKtTDFgtVqtvp6WvFbZ6-zbThQsVfuDzGWxZWYnNdNyf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