Issue 58163
Summary Some macros cause -Wunused-value if -save-temps is used
Labels new issue
Assignees
Reporter tobiasbrunner
    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?






_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to