Resolver: Fix UB with nullptr method calls

Change-Id: Iaa098d7851ffaf01aac384fe623c94809948fe2e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51182
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc
index e21e22f..d5166d9 100644
--- a/src/resolver/resolver.cc
+++ b/src/resolver/resolver.cc
@@ -501,14 +501,19 @@
   // TODO(crbug.com/tint/802): Temporary while ast::AccessControl exits.
   auto find_first_access_control =
       [this](ast::Type* ty) -> ast::AccessControl* {
-    ast::AccessControl* ac = ty->As<ast::AccessControl>();
-    if (ac) {
+    if (ty == nullptr) {
+      return nullptr;
+    }
+    if (ast::AccessControl* ac = ty->As<ast::AccessControl>()) {
       return ac;
     }
     while (auto* tn = ty->As<ast::TypeName>()) {
-      ty = name_to_ast_type_[tn->name()];
-      ac = ty->As<ast::AccessControl>();
-      if (ac) {
+      auto it = name_to_ast_type_.find(tn->name());
+      if (it == name_to_ast_type_.end()) {
+        break;
+      }
+      ty = it->second;
+      if (auto* ac = ty->As<ast::AccessControl>()) {
         return ac;
       }
     }