global decl defined in this TU that hasn't been touched yet, then
the initial value of REG can be taken from the initialization value
of the decl. */
- if ((called_from_main_p () && !DECL_EXTERNAL (decl))
- || TREE_READONLY (decl))
+ if (called_from_main_p () || TREE_READONLY (decl))
{
/* Attempt to get the initializer value for base_reg. */
if (const svalue *base_reg_init
tree init = DECL_INITIAL (m_decl);
if (!init)
{
+ /* If we have an "extern" decl then there may be an initializer in
+ another TU. */
+ if (DECL_EXTERNAL (m_decl))
+ return NULL;
+
/* Implicit initialization to zero; use a compound_svalue for it.
Doing so requires that we have a concrete binding for this region,
which can fail if we have a region with unknown size
--- /dev/null
+#include "analyzer-decls.h"
+
+#define NULL ((void *)0)
+
+extern int *const p1;
+
+int *const p2;
+
+int v3;
+extern int *const p3 = &v3; /* { dg-warning "'p3' initialized and declared 'extern'" } */
+
+int v4;
+int *const p4 = &v4;
+
+int main (void)
+{
+ __analyzer_describe (0, p1); /* { dg-message "INIT_VAL\\(p1\\)" } */
+ __analyzer_eval (p1 == NULL); /* { dg-message "UNKNOWN" } */
+
+ __analyzer_eval (p2 == NULL); /* { dg-message "TRUE" } */
+
+ __analyzer_describe (0, p3); /* { dg-message "&v3" } */
+ __analyzer_eval (p3 == NULL); /* { dg-message "FALSE" } */
+
+ __analyzer_describe (0, p4); /* { dg-message "&v4" } */
+ __analyzer_eval (p4 == NULL); /* { dg-message "FALSE" } */
+
+ return p1[0];
+}