llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Constantin Kronbichler (ccrownhill)

<details>
<summary>Changes</summary>

This fixes issue #<!-- -->39558 which mentions the problem when compiling the 
following code with `-pedantic-errors` flag (it also mentions `-Wall -Wextra` 
but those shouldn't change the output, which is also the case in GCC):

```c
static void f();

int main()
{
    f;
}
```

Clang only outputs an `undefined-internal` warning on the first line, but 
according to 6.9/3

```
"... Moreover, if an identifier declared with internal linkage is used in an
 expression (other than as a part of the operand of a sizeof or _Alignof
 operator whose result is an integer constant), there shall be exactly one
 external definition for the identifier in the translation unit."
```

this should be illegal and hence an error.

I fixed this by changing the warning type from `Warning` to `ExtWarn` and by 
adding a suitable test.



---
Full diff: https://github.com/llvm/llvm-project/pull/98016.diff


2 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1) 
- (added) clang/test/Sema/undefined_internal.c (+11) 


``````````diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 44fd51ec9abc9..ae3dbedd01693 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6013,7 +6013,7 @@ def note_deleted_assign_field : Note<
   "because field %2 is of %select{reference|const-qualified}4 type %3">;
 
 // These should be errors.
-def warn_undefined_internal : Warning<
+def warn_undefined_internal : ExtWarn<
   "%select{function|variable}0 %q1 has internal linkage but is not defined">,
   InGroup<DiagGroup<"undefined-internal">>;
 def err_undefined_internal_type : Error<
diff --git a/clang/test/Sema/undefined_internal.c 
b/clang/test/Sema/undefined_internal.c
new file mode 100644
index 0000000000000..1b6c3a4b76e05
--- /dev/null
+++ b/clang/test/Sema/undefined_internal.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors
+
+static void f(void); // expected-error {{function 'f' has internal linkage but 
is not defined}}
+
+int main(void)
+{
+    f;
+    // expected-note@-1 {{used here}}
+    // expected-warning@-2 {{expression result unused}}
+}
+

``````````

</details>


https://github.com/llvm/llvm-project/pull/98016
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to