[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
Thu Jun 23 23:50:00 PDT 2022


ahatanak updated this revision to Diff 439636.
ahatanak added a comment.

Change the type of `memset`'s length parameter to silence warnings on windows.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128373/new/

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,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));
+}
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -10323,11 +10323,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.439636.patch
Type: text/x-patch
Size: 1098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220624/2d409b75/attachment-0001.bin>


More information about the cfe-commits mailing list