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

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 22 12:34:12 PDT 2022


ahatanak created this revision.
ahatanak added a reviewer: aaron.ballman.
ahatanak added a project: clang.
Herald added a project: All.
ahatanak requested review of this revision.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128373

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/Sema/warn-memset-bad-sizeof.c


Index: clang/test/Sema/warn-memset-bad-sizeof.c
===================================================================
--- /dev/null
+++ clang/test/Sema/warn-memset-bad-sizeof.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+void *memset(void *, int, unsigned long);
+
+typedef struct {
+  int a;
+} S;
+
+void test() {
+  S s;
+  __auto_type dstptr = &s;
+  memset(dstptr, 0, sizeof(s));
+}
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -10314,11 +10314,11 @@
     // 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 {};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128373.439129.patch
Type: text/x-patch
Size: 1075 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220622/c3b6635d/attachment.bin>


More information about the cfe-commits mailing list