llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Devajith (devajithvs)

<details>
<summary>Changes</summary>

In clang-repl (using in-memory buffers), redefinitions were incorrectly 
diagnosed with "included multiple times" notes instead of "previous definition 
is here".

This occurred because the check in `Sema::notePreviousDefinition` compared null 
FileEntry pointers, treating all in-memory buffers as the same file.

Before:
```
clang-repl&gt; int a;
clang-repl&gt; int a;
In file included from &lt;&lt;&lt; inputs &gt;&gt;&gt;:1:
input_line_2:1:5: error: redefinition of 'a'
    1 | int a;
      |     ^
&lt;&lt;&lt; inputs &gt;&gt;&gt;:1:1: note: '' included multiple times, 
additional include site here
&lt;&lt;&lt; inputs &gt;&gt;&gt;:1:1: note: '' included multiple times, 
additional include site here
error: Parsing failed.
```

After:
```
clang-repl&gt; int a;
clang-repl&gt; int a;
In file included from &lt;&lt;&lt; inputs &gt;&gt;&gt;:1:
input_line_2:1:5: error: redefinition of 'a'
    1 | int a;
      |     ^
input_line_1:1:5: note: previous definition is here
    1 | int a;
      |     ^
error: Parsing failed.
```

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaDecl.cpp (+1-1) 
- (modified) clang/test/Interpreter/execute.c (+3) 


``````````diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4dfde4bf8cedf..9fbb8729d649a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4949,7 +4949,7 @@ void Sema::notePreviousDefinition(const NamedDecl *Old, 
SourceLocation New) {
 
   // Is it the same file and same offset? Provide more information on why
   // this leads to a redefinition error.
-  if (FNew == FOld && FNewDecLoc.second == FOldDecLoc.second) {
+  if (FNew && FNew == FOld && FNewDecLoc.second == FOldDecLoc.second) {
     SourceLocation OldIncLoc = SrcMgr.getIncludeLoc(FOldDecLoc.first);
     SourceLocation NewIncLoc = SrcMgr.getIncludeLoc(FNewDecLoc.first);
     bool EmittedDiag =
diff --git a/clang/test/Interpreter/execute.c b/clang/test/Interpreter/execute.c
index ca8f83cf6e374..4b34a27380a48 100644
--- a/clang/test/Interpreter/execute.c
+++ b/clang/test/Interpreter/execute.c
@@ -17,4 +17,7 @@ run();
 // CHECK: i = 42
 // CHECK-NEXT: S[f=1.000000, m=0x0]
 
+const char* a = "test"; // expected-note {{previous definition is here}}
+const char* a = ""; // expected-error {{redefinition of 'a'}}
+
 %quit

``````````

</details>


https://github.com/llvm/llvm-project/pull/182070
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to