[clang] 5fa4629 - [Sema] Check whether `__auto_type` has been deduced before merging

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 24 09:50:13 PDT 2022


Author: Akira Hatanaka
Date: 2022-06-24T09:49:07-07:00
New Revision: 5fa4629581f6938cc175be5d4a3fccdfbf9fc227

URL: https://github.com/llvm/llvm-project/commit/5fa4629581f6938cc175be5d4a3fccdfbf9fc227
DIFF: https://github.com/llvm/llvm-project/commit/5fa4629581f6938cc175be5d4a3fccdfbf9fc227.diff

LOG: [Sema] Check whether `__auto_type` has been deduced before merging

This fixes a bug in clang where it emits the following diagnostic when
compiling the test case:

"argument to 'sizeof' in 'memset' call is the same pointer type 'S' as
the destination"

The code that merges __auto_type with other types was committed in
https://reviews.llvm.org/D122029.

Differential Revision: https://reviews.llvm.org/D128373

Added: 
    clang/test/Sema/warn-memset-bad-sizeof.c

Modified: 
    clang/lib/AST/ASTContext.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index fe1ef6799048..cb2a3e23acb8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -10323,11 +10323,11 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS,
     // Allow __auto_type to match anything; it merges to the type with more
     // information.
     if (const auto *AT = LHS->getAs<AutoType>()) {
-      if (AT->isGNUAutoType())
+      if (!AT->isDeduced() && AT->isGNUAutoType())
         return RHS;
     }
     if (const auto *AT = RHS->getAs<AutoType>()) {
-      if (AT->isGNUAutoType())
+      if (!AT->isDeduced() && AT->isGNUAutoType())
         return LHS;
     }
     return {};

diff  --git a/clang/test/Sema/warn-memset-bad-sizeof.c b/clang/test/Sema/warn-memset-bad-sizeof.c
new file mode 100644
index 000000000000..c4768d8d0edd
--- /dev/null
+++ b/clang/test/Sema/warn-memset-bad-sizeof.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+typedef __SIZE_TYPE__ size_t;
+void *memset(void *, int, size_t);
+
+typedef struct {
+  int a;
+} S;
+
+void test() {
+  S s;
+  __auto_type dstptr = &s;
+  memset(dstptr, 0, sizeof(s));
+}


        


More information about the cfe-commits mailing list